diff options
Diffstat (limited to 'plugins/negate.c')
-rw-r--r-- | plugins/negate.c | 48 |
1 files changed, 14 insertions, 34 deletions
diff --git a/plugins/negate.c b/plugins/negate.c index ef7d4e0..beaed1e 100644 --- a/plugins/negate.c +++ b/plugins/negate.c | |||
@@ -1,9 +1,9 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Nagios negate plugin | 3 | * Monitoring negate plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2002-2008 Nagios Plugins Development Team | 6 | * Copyright (c) 2002-2008 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
@@ -31,21 +31,20 @@ | |||
31 | 31 | ||
32 | const char *progname = "negate"; | 32 | const char *progname = "negate"; |
33 | const char *copyright = "2002-2008"; | 33 | const char *copyright = "2002-2008"; |
34 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 34 | const char *email = "devel@monitoring-plugins.org"; |
35 | 35 | ||
36 | #define DEFAULT_TIMEOUT 11 | 36 | #define DEFAULT_TIMEOUT 11 |
37 | 37 | ||
38 | #include <ctype.h> | ||
39 | |||
40 | #include "common.h" | 38 | #include "common.h" |
41 | #include "utils.h" | 39 | #include "utils.h" |
42 | #include "utils_cmd.h" | 40 | #include "utils_cmd.h" |
43 | 41 | ||
42 | #include <ctype.h> | ||
43 | |||
44 | /* char *command_line; */ | 44 | /* char *command_line; */ |
45 | 45 | ||
46 | static const char **process_arguments (int, char **); | 46 | static const char **process_arguments (int, char **); |
47 | int validate_arguments (char **); | 47 | void validate_arguments (char **); |
48 | int translate_state (char *); | ||
49 | void print_help (void); | 48 | void print_help (void); |
50 | void print_usage (void); | 49 | void print_usage (void); |
51 | int subst_text = FALSE; | 50 | int subst_text = FALSE; |
@@ -99,8 +98,7 @@ main (int argc, char **argv) | |||
99 | die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n")); | 98 | die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n")); |
100 | 99 | ||
101 | for (i = 0; i < chld_out.lines; i++) { | 100 | for (i = 0; i < chld_out.lines; i++) { |
102 | if (subst_text && result != state[result] && | 101 | if (subst_text && result >= 0 && result <= 4 && result != state[result]) { |
103 | result >= 0 && result <= 4) { | ||
104 | /* Loop over each match found */ | 102 | /* Loop over each match found */ |
105 | while ((sub = strstr (chld_out.line[i], state_text (result)))) { | 103 | while ((sub = strstr (chld_out.line[i], state_text (result)))) { |
106 | /* Terminate the first part and skip over the string we'll substitute */ | 104 | /* Terminate the first part and skip over the string we'll substitute */ |
@@ -166,27 +164,27 @@ process_arguments (int argc, char **argv) | |||
166 | timeout_interval = atoi (optarg); | 164 | timeout_interval = atoi (optarg); |
167 | break; | 165 | break; |
168 | case 'T': /* Result to return on timeouts */ | 166 | case 'T': /* Result to return on timeouts */ |
169 | if ((timeout_state = translate_state(optarg)) == ERROR) | 167 | if ((timeout_state = mp_translate_state(optarg)) == ERROR) |
170 | usage4 (_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 168 | usage4 (_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); |
171 | break; | 169 | break; |
172 | case 'o': /* replacement for OK */ | 170 | case 'o': /* replacement for OK */ |
173 | if ((state[STATE_OK] = translate_state(optarg)) == ERROR) | 171 | if ((state[STATE_OK] = mp_translate_state(optarg)) == ERROR) |
174 | usage4 (_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 172 | usage4 (_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); |
175 | permute = FALSE; | 173 | permute = FALSE; |
176 | break; | 174 | break; |
177 | 175 | ||
178 | case 'w': /* replacement for WARNING */ | 176 | case 'w': /* replacement for WARNING */ |
179 | if ((state[STATE_WARNING] = translate_state(optarg)) == ERROR) | 177 | if ((state[STATE_WARNING] = mp_translate_state(optarg)) == ERROR) |
180 | 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 integer (0-3).")); |
181 | permute = FALSE; | 179 | permute = FALSE; |
182 | break; | 180 | break; |
183 | case 'c': /* replacement for CRITICAL */ | 181 | case 'c': /* replacement for CRITICAL */ |
184 | if ((state[STATE_CRITICAL] = translate_state(optarg)) == ERROR) | 182 | if ((state[STATE_CRITICAL] = mp_translate_state(optarg)) == ERROR) |
185 | usage4 (_("Critical must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 183 | usage4 (_("Critical must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); |
186 | permute = FALSE; | 184 | permute = FALSE; |
187 | break; | 185 | break; |
188 | case 'u': /* replacement for UNKNOWN */ | 186 | case 'u': /* replacement for UNKNOWN */ |
189 | if ((state[STATE_UNKNOWN] = translate_state(optarg)) == ERROR) | 187 | if ((state[STATE_UNKNOWN] = mp_translate_state(optarg)) == ERROR) |
190 | usage4 (_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 188 | usage4 (_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); |
191 | permute = FALSE; | 189 | permute = FALSE; |
192 | break; | 190 | break; |
@@ -207,7 +205,7 @@ process_arguments (int argc, char **argv) | |||
207 | } | 205 | } |
208 | 206 | ||
209 | 207 | ||
210 | int | 208 | void |
211 | validate_arguments (char **command_line) | 209 | validate_arguments (char **command_line) |
212 | { | 210 | { |
213 | if (command_line[0] == NULL) | 211 | if (command_line[0] == NULL) |
@@ -218,24 +216,6 @@ validate_arguments (char **command_line) | |||
218 | } | 216 | } |
219 | 217 | ||
220 | 218 | ||
221 | int | ||
222 | translate_state (char *state_text) | ||
223 | { | ||
224 | char *temp_ptr; | ||
225 | for (temp_ptr = state_text; *temp_ptr; temp_ptr++) { | ||
226 | *temp_ptr = toupper(*temp_ptr); | ||
227 | } | ||
228 | if (!strcmp(state_text,"OK") || !strcmp(state_text,"0")) | ||
229 | return STATE_OK; | ||
230 | if (!strcmp(state_text,"WARNING") || !strcmp(state_text,"1")) | ||
231 | return STATE_WARNING; | ||
232 | if (!strcmp(state_text,"CRITICAL") || !strcmp(state_text,"2")) | ||
233 | return STATE_CRITICAL; | ||
234 | if (!strcmp(state_text,"UNKNOWN") || !strcmp(state_text,"3")) | ||
235 | return STATE_UNKNOWN; | ||
236 | return ERROR; | ||
237 | } | ||
238 | |||
239 | void | 219 | void |
240 | print_help (void) | 220 | print_help (void) |
241 | { | 221 | { |
@@ -252,7 +232,7 @@ print_help (void) | |||
252 | 232 | ||
253 | printf (UT_HELP_VRSN); | 233 | printf (UT_HELP_VRSN); |
254 | 234 | ||
255 | printf (UT_TIMEOUT, timeout_interval); | 235 | printf (UT_PLUG_TIMEOUT, timeout_interval); |
256 | printf (" %s\n", _("Keep timeout longer than the plugin timeout to retain CRITICAL status.")); | 236 | printf (" %s\n", _("Keep timeout longer than the plugin timeout to retain CRITICAL status.")); |
257 | printf (" -T, --timeout-result=STATUS\n"); | 237 | printf (" -T, --timeout-result=STATUS\n"); |
258 | printf (" %s\n", _("Custom result on Negate timeouts; see below for STATUS definition\n")); | 238 | printf (" %s\n", _("Custom result on Negate timeouts; see below for STATUS definition\n")); |