diff options
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_nagios.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c index 48629be3..72613f97 100644 --- a/plugins/check_nagios.c +++ b/plugins/check_nagios.c | |||
| @@ -87,8 +87,9 @@ int main(int argc, char **argv) { | |||
| 87 | /* Parse extra opts if any */ | 87 | /* Parse extra opts if any */ |
| 88 | argv = np_extra_opts(&argc, argv, progname); | 88 | argv = np_extra_opts(&argc, argv, progname); |
| 89 | 89 | ||
| 90 | if (process_arguments(argc, argv) == ERROR) | 90 | if (process_arguments(argc, argv) == ERROR) { |
| 91 | usage_va(_("Could not parse arguments")); | 91 | usage_va(_("Could not parse arguments")); |
| 92 | } | ||
| 92 | 93 | ||
| 93 | /* Set signal handling and alarm timeout */ | 94 | /* Set signal handling and alarm timeout */ |
| 94 | if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) { | 95 | if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) { |
| @@ -113,18 +114,21 @@ int main(int argc, char **argv) { | |||
| 113 | } | 114 | } |
| 114 | if ((temp_ptr = strtok(input_buffer, "]")) != NULL) { | 115 | if ((temp_ptr = strtok(input_buffer, "]")) != NULL) { |
| 115 | temp_entry_time = strtoul(temp_ptr + 1, NULL, 10); | 116 | temp_entry_time = strtoul(temp_ptr + 1, NULL, 10); |
| 116 | if (temp_entry_time > latest_entry_time) | 117 | if (temp_entry_time > latest_entry_time) { |
| 117 | latest_entry_time = temp_entry_time; | 118 | latest_entry_time = temp_entry_time; |
| 119 | } | ||
| 118 | } | 120 | } |
| 119 | } | 121 | } |
| 120 | fclose(fp); | 122 | fclose(fp); |
| 121 | 123 | ||
| 122 | if (verbose >= 2) | 124 | if (verbose >= 2) { |
| 123 | printf("command: %s\n", PS_COMMAND); | 125 | printf("command: %s\n", PS_COMMAND); |
| 126 | } | ||
| 124 | 127 | ||
| 125 | /* run the command to check for the Nagios process.. */ | 128 | /* run the command to check for the Nagios process.. */ |
| 126 | if ((result = np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0)) != 0) | 129 | if ((result = np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0)) != 0) { |
| 127 | result = STATE_WARNING; | 130 | result = STATE_WARNING; |
| 131 | } | ||
| 128 | 132 | ||
| 129 | /* count the number of matching Nagios processes... */ | 133 | /* count the number of matching Nagios processes... */ |
| 130 | for (i = 0; i < chld_out.lines; i++) { | 134 | for (i = 0; i < chld_out.lines; i++) { |
| @@ -159,8 +163,9 @@ int main(int argc, char **argv) { | |||
| 159 | } | 163 | } |
| 160 | 164 | ||
| 161 | /* If we get anything on stderr, at least set warning */ | 165 | /* If we get anything on stderr, at least set warning */ |
| 162 | if (chld_err.buflen) | 166 | if (chld_err.buflen) { |
| 163 | result = max_state(result, STATE_WARNING); | 167 | result = max_state(result, STATE_WARNING); |
| 168 | } | ||
| 164 | 169 | ||
| 165 | /* reset the alarm handler */ | 170 | /* reset the alarm handler */ |
| 166 | alarm(0); | 171 | alarm(0); |
| @@ -200,15 +205,17 @@ int process_arguments(int argc, char **argv) { | |||
| 200 | {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, | 205 | {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, |
| 201 | {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0}}; | 206 | {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0}}; |
| 202 | 207 | ||
| 203 | if (argc < 2) | 208 | if (argc < 2) { |
| 204 | return ERROR; | 209 | return ERROR; |
| 210 | } | ||
| 205 | 211 | ||
| 206 | if (!is_option(argv[1])) { | 212 | if (!is_option(argv[1])) { |
| 207 | status_log = argv[1]; | 213 | status_log = argv[1]; |
| 208 | if (is_intnonneg(argv[2])) | 214 | if (is_intnonneg(argv[2])) { |
| 209 | expire_minutes = atoi(argv[2]); | 215 | expire_minutes = atoi(argv[2]); |
| 210 | else | 216 | } else { |
| 211 | die(STATE_UNKNOWN, _("Expiration time must be an integer (seconds)\n")); | 217 | die(STATE_UNKNOWN, _("Expiration time must be an integer (seconds)\n")); |
| 218 | } | ||
| 212 | process_string = argv[3]; | 219 | process_string = argv[3]; |
| 213 | return OK; | 220 | return OK; |
| 214 | } | 221 | } |
| @@ -216,8 +223,9 @@ int process_arguments(int argc, char **argv) { | |||
| 216 | while (1) { | 223 | while (1) { |
| 217 | c = getopt_long(argc, argv, "+hVvF:C:e:t:", longopts, &option); | 224 | c = getopt_long(argc, argv, "+hVvF:C:e:t:", longopts, &option); |
| 218 | 225 | ||
| 219 | if (c == -1 || c == EOF || c == 1) | 226 | if (c == -1 || c == EOF || c == 1) { |
| 220 | break; | 227 | break; |
| 228 | } | ||
| 221 | 229 | ||
| 222 | switch (c) { | 230 | switch (c) { |
| 223 | case 'h': /* help */ | 231 | case 'h': /* help */ |
| @@ -233,16 +241,18 @@ int process_arguments(int argc, char **argv) { | |||
| 233 | process_string = optarg; | 241 | process_string = optarg; |
| 234 | break; | 242 | break; |
| 235 | case 'e': /* expiry time */ | 243 | case 'e': /* expiry time */ |
| 236 | if (is_intnonneg(optarg)) | 244 | if (is_intnonneg(optarg)) { |
| 237 | expire_minutes = atoi(optarg); | 245 | expire_minutes = atoi(optarg); |
| 238 | else | 246 | } else { |
| 239 | die(STATE_UNKNOWN, _("Expiration time must be an integer (seconds)\n")); | 247 | die(STATE_UNKNOWN, _("Expiration time must be an integer (seconds)\n")); |
| 248 | } | ||
| 240 | break; | 249 | break; |
| 241 | case 't': /* timeout */ | 250 | case 't': /* timeout */ |
| 242 | if (is_intnonneg(optarg)) | 251 | if (is_intnonneg(optarg)) { |
| 243 | timeout_interval = atoi(optarg); | 252 | timeout_interval = atoi(optarg); |
| 244 | else | 253 | } else { |
| 245 | die(STATE_UNKNOWN, _("Timeout must be an integer (seconds)\n")); | 254 | die(STATE_UNKNOWN, _("Timeout must be an integer (seconds)\n")); |
| 255 | } | ||
| 246 | break; | 256 | break; |
| 247 | case 'v': | 257 | case 'v': |
| 248 | verbose++; | 258 | verbose++; |
| @@ -252,11 +262,13 @@ int process_arguments(int argc, char **argv) { | |||
| 252 | } | 262 | } |
| 253 | } | 263 | } |
| 254 | 264 | ||
| 255 | if (status_log == NULL) | 265 | if (status_log == NULL) { |
| 256 | die(STATE_UNKNOWN, _("You must provide the status_log\n")); | 266 | die(STATE_UNKNOWN, _("You must provide the status_log\n")); |
| 267 | } | ||
| 257 | 268 | ||
| 258 | if (process_string == NULL) | 269 | if (process_string == NULL) { |
| 259 | die(STATE_UNKNOWN, _("You must provide a process string\n")); | 270 | die(STATE_UNKNOWN, _("You must provide a process string\n")); |
| 271 | } | ||
| 260 | 272 | ||
| 261 | return OK; | 273 | return OK; |
| 262 | } | 274 | } |
