diff options
Diffstat (limited to 'plugins/negate.c')
-rw-r--r-- | plugins/negate.c | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/plugins/negate.c b/plugins/negate.c index 0520d298..a42a6c59 100644 --- a/plugins/negate.c +++ b/plugins/negate.c | |||
@@ -105,7 +105,8 @@ int main(int argc, char **argv) { | |||
105 | *sub = '\0'; | 105 | *sub = '\0'; |
106 | sub += strlen(state_text(result)); | 106 | sub += strlen(state_text(result)); |
107 | /* then put everything back together */ | 107 | /* then put everything back together */ |
108 | xasprintf(&chld_out.line[i], "%s%s%s", chld_out.line[i], state_text(config.state[result]), sub); | 108 | xasprintf(&chld_out.line[i], "%s%s%s", chld_out.line[i], |
109 | state_text(config.state[result]), sub); | ||
109 | } | 110 | } |
110 | } | 111 | } |
111 | printf("%s\n", chld_out.line[i]); | 112 | printf("%s\n", chld_out.line[i]); |
@@ -120,11 +121,12 @@ int main(int argc, char **argv) { | |||
120 | 121 | ||
121 | /* process command-line arguments */ | 122 | /* process command-line arguments */ |
122 | static negate_config_wrapper process_arguments(int argc, char **argv) { | 123 | static negate_config_wrapper process_arguments(int argc, char **argv) { |
123 | static struct option longopts[] = {{"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, | 124 | static struct option longopts[] = { |
124 | {"timeout", required_argument, 0, 't'}, {"timeout-result", required_argument, 0, 'T'}, | 125 | {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, |
125 | {"ok", required_argument, 0, 'o'}, {"warning", required_argument, 0, 'w'}, | 126 | {"timeout", required_argument, 0, 't'}, {"timeout-result", required_argument, 0, 'T'}, |
126 | {"critical", required_argument, 0, 'c'}, {"unknown", required_argument, 0, 'u'}, | 127 | {"ok", required_argument, 0, 'o'}, {"warning", required_argument, 0, 'w'}, |
127 | {"substitute", no_argument, 0, 's'}, {0, 0, 0, 0}}; | 128 | {"critical", required_argument, 0, 'c'}, {"unknown", required_argument, 0, 'u'}, |
129 | {"substitute", no_argument, 0, 's'}, {0, 0, 0, 0}}; | ||
128 | 130 | ||
129 | negate_config_wrapper result = { | 131 | negate_config_wrapper result = { |
130 | .errorcode = OK, | 132 | .errorcode = OK, |
@@ -159,31 +161,36 @@ static negate_config_wrapper process_arguments(int argc, char **argv) { | |||
159 | break; | 161 | break; |
160 | case 'T': /* Result to return on timeouts */ | 162 | case 'T': /* Result to return on timeouts */ |
161 | if ((timeout_state = mp_translate_state(optarg)) == ERROR) { | 163 | if ((timeout_state = mp_translate_state(optarg)) == ERROR) { |
162 | usage4(_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 164 | usage4(_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, " |
165 | "UNKNOWN) or integer (0-3).")); | ||
163 | } | 166 | } |
164 | break; | 167 | break; |
165 | case 'o': /* replacement for OK */ | 168 | case 'o': /* replacement for OK */ |
166 | if ((result.config.state[STATE_OK] = mp_translate_state(optarg)) == ERROR) { | 169 | if ((result.config.state[STATE_OK] = mp_translate_state(optarg)) == ERROR) { |
167 | usage4(_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 170 | usage4(_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or " |
171 | "integer (0-3).")); | ||
168 | } | 172 | } |
169 | permute = false; | 173 | permute = false; |
170 | break; | 174 | break; |
171 | 175 | ||
172 | case 'w': /* replacement for WARNING */ | 176 | case 'w': /* replacement for WARNING */ |
173 | if ((result.config.state[STATE_WARNING] = mp_translate_state(optarg)) == ERROR) { | 177 | if ((result.config.state[STATE_WARNING] = mp_translate_state(optarg)) == ERROR) { |
174 | usage4(_("Warning must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 178 | usage4(_("Warning must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or " |
179 | "integer (0-3).")); | ||
175 | } | 180 | } |
176 | permute = false; | 181 | permute = false; |
177 | break; | 182 | break; |
178 | case 'c': /* replacement for CRITICAL */ | 183 | case 'c': /* replacement for CRITICAL */ |
179 | if ((result.config.state[STATE_CRITICAL] = mp_translate_state(optarg)) == ERROR) { | 184 | if ((result.config.state[STATE_CRITICAL] = mp_translate_state(optarg)) == ERROR) { |
180 | usage4(_("Critical must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 185 | usage4(_("Critical must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or " |
186 | "integer (0-3).")); | ||
181 | } | 187 | } |
182 | permute = false; | 188 | permute = false; |
183 | break; | 189 | break; |
184 | case 'u': /* replacement for UNKNOWN */ | 190 | case 'u': /* replacement for UNKNOWN */ |
185 | if ((result.config.state[STATE_UNKNOWN] = mp_translate_state(optarg)) == ERROR) { | 191 | if ((result.config.state[STATE_UNKNOWN] = mp_translate_state(optarg)) == ERROR) { |
186 | usage4(_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 192 | usage4(_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or " |
193 | "integer (0-3).")); | ||
187 | } | 194 | } |
188 | permute = false; | 195 | permute = false; |
189 | break; | 196 | break; |
@@ -208,7 +215,8 @@ negate_config_wrapper validate_arguments(negate_config_wrapper config_wrapper) { | |||
208 | usage4(_("Could not parse arguments")); | 215 | usage4(_("Could not parse arguments")); |
209 | } | 216 | } |
210 | 217 | ||
211 | if (strncmp(config_wrapper.config.command_line[0], "/", 1) != 0 && strncmp(config_wrapper.config.command_line[0], "./", 2) != 0) { | 218 | if (strncmp(config_wrapper.config.command_line[0], "/", 1) != 0 && |
219 | strncmp(config_wrapper.config.command_line[0], "./", 2) != 0) { | ||
212 | usage4(_("Require path to command")); | 220 | usage4(_("Require path to command")); |
213 | } | 221 | } |
214 | 222 | ||
@@ -220,7 +228,8 @@ void print_help(void) { | |||
220 | 228 | ||
221 | printf(COPYRIGHT, copyright, email); | 229 | printf(COPYRIGHT, copyright, email); |
222 | 230 | ||
223 | printf("%s\n", _("Negates only the return code of a plugin (returns OK for CRITICAL and vice-versa) by default.")); | 231 | printf("%s\n", _("Negates only the return code of a plugin (returns OK for CRITICAL and " |
232 | "vice-versa) by default.")); | ||
224 | printf("%s\n", _("Additional switches can be used to control:\n")); | 233 | printf("%s\n", _("Additional switches can be used to control:\n")); |
225 | printf("\t - which state becomes what\n"); | 234 | printf("\t - which state becomes what\n"); |
226 | printf("\t - changing the plugin output text to match the return code"); | 235 | printf("\t - changing the plugin output text to match the return code"); |
@@ -250,17 +259,20 @@ void print_help(void) { | |||
250 | printf("%s\n", _("Examples:")); | 259 | printf("%s\n", _("Examples:")); |
251 | printf(" %s\n", "negate /usr/local/nagios/libexec/check_ping -H host"); | 260 | printf(" %s\n", "negate /usr/local/nagios/libexec/check_ping -H host"); |
252 | printf(" %s\n", _("Run check_ping and invert result. Must use full path to plugin")); | 261 | printf(" %s\n", _("Run check_ping and invert result. Must use full path to plugin")); |
253 | printf(" %s\n", "negate -w OK -c UNKNOWN /usr/local/nagios/libexec/check_procs -a 'vi negate.c'"); | 262 | printf(" %s\n", |
263 | "negate -w OK -c UNKNOWN /usr/local/nagios/libexec/check_procs -a 'vi negate.c'"); | ||
254 | printf(" %s\n", _("This will return OK instead of WARNING and UNKNOWN instead of CRITICAL")); | 264 | printf(" %s\n", _("This will return OK instead of WARNING and UNKNOWN instead of CRITICAL")); |
255 | printf("\n"); | 265 | printf("\n"); |
256 | printf("%s\n", _("Notes:")); | 266 | printf("%s\n", _("Notes:")); |
257 | printf(" %s\n", _("This plugin is a wrapper to take the output of another plugin and invert it.")); | 267 | printf(" %s\n", |
268 | _("This plugin is a wrapper to take the output of another plugin and invert it.")); | ||
258 | printf(" %s\n", _("The full path of the plugin must be provided.")); | 269 | printf(" %s\n", _("The full path of the plugin must be provided.")); |
259 | printf(" %s\n", _("If the wrapped plugin returns OK, the wrapper will return CRITICAL.")); | 270 | printf(" %s\n", _("If the wrapped plugin returns OK, the wrapper will return CRITICAL.")); |
260 | printf(" %s\n", _("If the wrapped plugin returns CRITICAL, the wrapper will return OK.")); | 271 | printf(" %s\n", _("If the wrapped plugin returns CRITICAL, the wrapper will return OK.")); |
261 | printf(" %s\n", _("Otherwise, the output state of the wrapped plugin is unchanged.")); | 272 | printf(" %s\n", _("Otherwise, the output state of the wrapped plugin is unchanged.")); |
262 | printf("\n"); | 273 | printf("\n"); |
263 | printf(" %s\n", _("Using timeout-result, it is possible to override the timeout behaviour or a")); | 274 | printf(" %s\n", |
275 | _("Using timeout-result, it is possible to override the timeout behaviour or a")); | ||
264 | printf(" %s\n", _("plugin by setting the negate timeout a bit lower.")); | 276 | printf(" %s\n", _("plugin by setting the negate timeout a bit lower.")); |
265 | 277 | ||
266 | printf(UT_SUPPORT); | 278 | printf(UT_SUPPORT); |