diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_by_ssh.c | 7 | ||||
-rw-r--r-- | plugins/check_dig.c | 6 | ||||
-rw-r--r-- | plugins/check_disk.c | 9 | ||||
-rw-r--r-- | plugins/check_dns.c | 8 | ||||
-rw-r--r-- | plugins/check_http.c | 38 | ||||
-rw-r--r-- | plugins/check_ide_smart.c | 26 | ||||
-rw-r--r-- | plugins/check_load.c | 2 | ||||
-rw-r--r-- | plugins/check_ntp.c | 6 | ||||
-rw-r--r-- | plugins/check_ntp_time.c | 6 | ||||
-rw-r--r-- | plugins/check_snmp.c | 16 | ||||
-rw-r--r-- | plugins/check_users.c | 60 | ||||
-rw-r--r-- | plugins/negate.c | 4 | ||||
-rw-r--r-- | plugins/sslutils.c | 15 | ||||
-rw-r--r-- | plugins/t/NPTest.cache.travis | 4 | ||||
-rw-r--r-- | plugins/t/check_http.t | 34 | ||||
-rw-r--r-- | plugins/t/check_snmp.t | 8 | ||||
-rw-r--r-- | plugins/t/check_users.t | 4 | ||||
-rwxr-xr-x | plugins/tests/check_http.t | 10 | ||||
-rw-r--r-- | plugins/utils.c | 41 | ||||
-rw-r--r-- | plugins/utils.h | 34 |
20 files changed, 196 insertions, 142 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 04bce38d..13d8bc3b 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
@@ -100,6 +100,13 @@ main (int argc, char **argv) | |||
100 | 100 | ||
101 | result = cmd_run_array (commargv, &chld_out, &chld_err, 0); | 101 | result = cmd_run_array (commargv, &chld_out, &chld_err, 0); |
102 | 102 | ||
103 | if (verbose) { | ||
104 | for(i = 0; i < chld_out.lines; i++) | ||
105 | printf("stdout: %s\n", chld_out.line[i]); | ||
106 | for(i = 0; i < chld_err.lines; i++) | ||
107 | printf("stderr: %s\n", chld_err.line[i]); | ||
108 | } | ||
109 | |||
103 | if (skip_stdout == -1) /* --skip-stdout specified without argument */ | 110 | if (skip_stdout == -1) /* --skip-stdout specified without argument */ |
104 | skip_stdout = chld_out.lines; | 111 | skip_stdout = chld_out.lines; |
105 | if (skip_stderr == -1) /* --skip-stderr specified without argument */ | 112 | if (skip_stderr == -1) /* --skip-stderr specified without argument */ |
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index db4b20eb..da4f0ded 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c | |||
@@ -48,7 +48,7 @@ void print_usage (void); | |||
48 | 48 | ||
49 | #define UNDEFINED 0 | 49 | #define UNDEFINED 0 |
50 | #define DEFAULT_PORT 53 | 50 | #define DEFAULT_PORT 53 |
51 | #define DEFAULT_TRIES 3 | 51 | #define DEFAULT_TRIES 2 |
52 | 52 | ||
53 | char *query_address = NULL; | 53 | char *query_address = NULL; |
54 | char *record_type = "A"; | 54 | char *record_type = "A"; |
@@ -94,7 +94,7 @@ main (int argc, char **argv) | |||
94 | timeout_interval_dig = timeout_interval / number_tries + number_tries; | 94 | timeout_interval_dig = timeout_interval / number_tries + number_tries; |
95 | 95 | ||
96 | /* get the command to run */ | 96 | /* get the command to run */ |
97 | xasprintf (&command_line, "%s %s %s -p %d @%s %s %s +tries=%d +time=%d", | 97 | xasprintf (&command_line, "%s %s %s -p %d @%s %s %s +retry=%d +time=%d", |
98 | PATH_TO_DIG, dig_args, query_transport, server_port, dns_server, query_address, record_type, number_tries, timeout_interval_dig); | 98 | PATH_TO_DIG, dig_args, query_transport, server_port, dns_server, query_address, record_type, number_tries, timeout_interval_dig); |
99 | 99 | ||
100 | alarm (timeout_interval); | 100 | alarm (timeout_interval); |
@@ -125,7 +125,7 @@ main (int argc, char **argv) | |||
125 | if (verbose) | 125 | if (verbose) |
126 | printf ("%s\n", chld_out.line[i]); | 126 | printf ("%s\n", chld_out.line[i]); |
127 | 127 | ||
128 | if (strstr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) { | 128 | if (strcasestr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) { |
129 | msg = chld_out.line[i]; | 129 | msg = chld_out.line[i]; |
130 | result = STATE_OK; | 130 | result = STATE_OK; |
131 | 131 | ||
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 874a0ee0..e73a0083 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -58,9 +58,6 @@ const char *email = "devel@monitoring-plugins.org"; | |||
58 | # define ERROR -1 | 58 | # define ERROR -1 |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | /* If nonzero, show inode information. */ | ||
62 | static int inode_format = 1; | ||
63 | |||
64 | /* If nonzero, show even filesystems with zero size or | 61 | /* If nonzero, show even filesystems with zero size or |
65 | uninteresting types. */ | 62 | uninteresting types. */ |
66 | static int show_all_fs = 1; | 63 | static int show_all_fs = 1; |
@@ -178,7 +175,7 @@ main (int argc, char **argv) | |||
178 | int temp_result; | 175 | int temp_result; |
179 | 176 | ||
180 | struct mount_entry *me; | 177 | struct mount_entry *me; |
181 | struct fs_usage fsp, tmpfsp; | 178 | struct fs_usage fsp; |
182 | struct parameter_list *temp_list, *path; | 179 | struct parameter_list *temp_list, *path; |
183 | 180 | ||
184 | #ifdef __CYGWIN__ | 181 | #ifdef __CYGWIN__ |
@@ -423,9 +420,7 @@ process_arguments (int argc, char **argv) | |||
423 | int c, err; | 420 | int c, err; |
424 | struct parameter_list *se; | 421 | struct parameter_list *se; |
425 | struct parameter_list *temp_list = NULL, *previous = NULL; | 422 | struct parameter_list *temp_list = NULL, *previous = NULL; |
426 | struct parameter_list *temp_path_select_list = NULL; | 423 | struct mount_entry *me; |
427 | struct mount_entry *me, *temp_me; | ||
428 | int result = OK; | ||
429 | regex_t re; | 424 | regex_t re; |
430 | int cflags = REG_NOSUB | REG_EXTENDED; | 425 | int cflags = REG_NOSUB | REG_EXTENDED; |
431 | int default_cflags = cflags; | 426 | int default_cflags = cflags; |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index d6bd2c0f..54ce7d16 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
@@ -81,7 +81,6 @@ main (int argc, char **argv) | |||
81 | double elapsed_time; | 81 | double elapsed_time; |
82 | long microsec; | 82 | long microsec; |
83 | struct timeval tv; | 83 | struct timeval tv; |
84 | int multi_address; | ||
85 | int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ | 84 | int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ |
86 | output chld_out, chld_err; | 85 | output chld_out, chld_err; |
87 | size_t i; | 86 | size_t i; |
@@ -127,7 +126,7 @@ main (int argc, char **argv) | |||
127 | if (verbose) | 126 | if (verbose) |
128 | puts(chld_out.line[i]); | 127 | puts(chld_out.line[i]); |
129 | 128 | ||
130 | if (strstr (chld_out.line[i], ".in-addr.arpa")) { | 129 | if (strcasestr (chld_out.line[i], ".in-addr.arpa")) { |
131 | if ((temp_buffer = strstr (chld_out.line[i], "name = "))) | 130 | if ((temp_buffer = strstr (chld_out.line[i], "name = "))) |
132 | addresses[n_addresses++] = strdup (temp_buffer + 7); | 131 | addresses[n_addresses++] = strdup (temp_buffer + 7); |
133 | else { | 132 | else { |
@@ -249,11 +248,6 @@ main (int argc, char **argv) | |||
249 | elapsed_time = (double)microsec / 1.0e6; | 248 | elapsed_time = (double)microsec / 1.0e6; |
250 | 249 | ||
251 | if (result == STATE_OK) { | 250 | if (result == STATE_OK) { |
252 | if (strchr (address, ',') == NULL) | ||
253 | multi_address = FALSE; | ||
254 | else | ||
255 | multi_address = TRUE; | ||
256 | |||
257 | result = get_status(elapsed_time, time_thresholds); | 251 | result = get_status(elapsed_time, time_thresholds); |
258 | if (result == STATE_OK) { | 252 | if (result == STATE_OK) { |
259 | printf ("DNS %s: ", _("OK")); | 253 | printf ("DNS %s: ", _("OK")); |
diff --git a/plugins/check_http.c b/plugins/check_http.c index a2b76240..60fe4d52 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -91,10 +91,12 @@ struct timeval tv_temp; | |||
91 | 91 | ||
92 | int specify_port = FALSE; | 92 | int specify_port = FALSE; |
93 | int server_port = HTTP_PORT; | 93 | int server_port = HTTP_PORT; |
94 | int virtual_port = 0; | ||
94 | char server_port_text[6] = ""; | 95 | char server_port_text[6] = ""; |
95 | char server_type[6] = "http"; | 96 | char server_type[6] = "http"; |
96 | char *server_address; | 97 | char *server_address; |
97 | char *host_name; | 98 | char *host_name; |
99 | int host_name_length; | ||
98 | char *server_url; | 100 | char *server_url; |
99 | char *user_agent; | 101 | char *user_agent; |
100 | int server_url_length; | 102 | int server_url_length; |
@@ -391,11 +393,25 @@ process_arguments (int argc, char **argv) | |||
391 | case 'H': /* Host Name (virtual host) */ | 393 | case 'H': /* Host Name (virtual host) */ |
392 | host_name = strdup (optarg); | 394 | host_name = strdup (optarg); |
393 | if (host_name[0] == '[') { | 395 | if (host_name[0] == '[') { |
394 | if ((p = strstr (host_name, "]:")) != NULL) /* [IPv6]:port */ | 396 | if ((p = strstr (host_name, "]:")) != NULL) { /* [IPv6]:port */ |
395 | server_port = atoi (p + 2); | 397 | virtual_port = atoi (p + 2); |
398 | /* cut off the port */ | ||
399 | host_name_length = strlen (host_name) - strlen (p) - 1; | ||
400 | free (host_name); | ||
401 | host_name = strndup (optarg, host_name_length); | ||
402 | if (specify_port == FALSE) | ||
403 | server_port = virtual_port; | ||
404 | } | ||
396 | } else if ((p = strchr (host_name, ':')) != NULL | 405 | } else if ((p = strchr (host_name, ':')) != NULL |
397 | && strchr (++p, ':') == NULL) /* IPv4:port or host:port */ | 406 | && strchr (++p, ':') == NULL) { /* IPv4:port or host:port */ |
398 | server_port = atoi (p); | 407 | virtual_port = atoi (p); |
408 | /* cut off the port */ | ||
409 | host_name_length = strlen (host_name) - strlen (p) - 1; | ||
410 | free (host_name); | ||
411 | host_name = strndup (optarg, host_name_length); | ||
412 | if (specify_port == FALSE) | ||
413 | server_port = virtual_port; | ||
414 | } | ||
399 | break; | 415 | break; |
400 | case 'I': /* Server IP-address */ | 416 | case 'I': /* Server IP-address */ |
401 | server_address = strdup (optarg); | 417 | server_address = strdup (optarg); |
@@ -550,9 +566,12 @@ process_arguments (int argc, char **argv) | |||
550 | if (http_method == NULL) | 566 | if (http_method == NULL) |
551 | http_method = strdup ("GET"); | 567 | http_method = strdup ("GET"); |
552 | 568 | ||
553 | if (client_cert && !client_privkey) | 569 | if (client_cert && !client_privkey) |
554 | usage4 (_("If you use a client certificate you must also specify a private key file")); | 570 | usage4 (_("If you use a client certificate you must also specify a private key file")); |
555 | 571 | ||
572 | if (virtual_port == 0) | ||
573 | virtual_port = server_port; | ||
574 | |||
556 | return TRUE; | 575 | return TRUE; |
557 | } | 576 | } |
558 | 577 | ||
@@ -958,13 +977,13 @@ check_http (void) | |||
958 | * 14.23). Some server applications/configurations cause trouble if the | 977 | * 14.23). Some server applications/configurations cause trouble if the |
959 | * (default) port is explicitly specified in the "Host:" header line. | 978 | * (default) port is explicitly specified in the "Host:" header line. |
960 | */ | 979 | */ |
961 | if ((use_ssl == FALSE && server_port == HTTP_PORT) || | 980 | if ((use_ssl == FALSE && virtual_port == HTTP_PORT) || |
962 | (use_ssl == TRUE && server_port == HTTPS_PORT) || | 981 | (use_ssl == TRUE && virtual_port == HTTPS_PORT) || |
963 | (server_address != NULL && strcmp(http_method, "CONNECT") == 0 | 982 | (server_address != NULL && strcmp(http_method, "CONNECT") == 0 |
964 | && host_name != NULL && use_ssl == TRUE)) | 983 | && host_name != NULL && use_ssl == TRUE)) |
965 | xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); | 984 | xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); |
966 | else | 985 | else |
967 | xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); | 986 | xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, virtual_port); |
968 | } | 987 | } |
969 | } | 988 | } |
970 | 989 | ||
@@ -1425,6 +1444,9 @@ redir (char *pos, char *status_line) | |||
1425 | MAX_PORT, server_type, server_address, server_port, server_url, | 1444 | MAX_PORT, server_type, server_address, server_port, server_url, |
1426 | display_html ? "</A>" : ""); | 1445 | display_html ? "</A>" : ""); |
1427 | 1446 | ||
1447 | /* reset virtual port */ | ||
1448 | virtual_port = server_port; | ||
1449 | |||
1428 | if (verbose) | 1450 | if (verbose) |
1429 | printf (_("Redirection to %s://%s:%d%s\n"), server_type, | 1451 | printf (_("Redirection to %s://%s:%d%s\n"), server_type, |
1430 | host_name ? host_name : server_address, server_port, server_url); | 1452 | host_name ? host_name : server_address, server_port, server_url); |
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c index 8d540ca1..46621318 100644 --- a/plugins/check_ide_smart.c +++ b/plugins/check_ide_smart.c | |||
@@ -166,7 +166,6 @@ enum SmartCommand | |||
166 | 166 | ||
167 | char *get_offline_text (int); | 167 | char *get_offline_text (int); |
168 | int smart_read_values (int, values_t *); | 168 | int smart_read_values (int, values_t *); |
169 | int values_not_passed (values_t *, thresholds_t *); | ||
170 | int nagios (values_t *, thresholds_t *); | 169 | int nagios (values_t *, thresholds_t *); |
171 | void print_value (value_t *, threshold_t *); | 170 | void print_value (value_t *, threshold_t *); |
172 | void print_values (values_t *, thresholds_t *); | 171 | void print_values (values_t *, thresholds_t *); |
@@ -340,31 +339,6 @@ smart_read_values (int fd, values_t * values) | |||
340 | 339 | ||
341 | 340 | ||
342 | int | 341 | int |
343 | values_not_passed (values_t * p, thresholds_t * t) | ||
344 | { | ||
345 | value_t * value = p->values; | ||
346 | threshold_t * threshold = t->thresholds; | ||
347 | int failed = 0; | ||
348 | int passed = 0; | ||
349 | int i; | ||
350 | for (i = 0; i < NR_ATTRIBUTES; i++) { | ||
351 | if (value->id && threshold->id && value->id == threshold->id) { | ||
352 | if (value->value < threshold->threshold) { | ||
353 | ++failed; | ||
354 | } | ||
355 | else { | ||
356 | ++passed; | ||
357 | } | ||
358 | } | ||
359 | ++value; | ||
360 | ++threshold; | ||
361 | } | ||
362 | return (passed ? -failed : 2); | ||
363 | } | ||
364 | |||
365 | |||
366 | |||
367 | int | ||
368 | nagios (values_t * p, thresholds_t * t) | 342 | nagios (values_t * p, thresholds_t * t) |
369 | { | 343 | { |
370 | value_t * value = p->values; | 344 | value_t * value = p->values; |
diff --git a/plugins/check_load.c b/plugins/check_load.c index a96435f4..b1cc498f 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
@@ -160,7 +160,7 @@ main (int argc, char **argv) | |||
160 | sscanf (input_buffer, "%*[^l]load averages: %lf, %lf, %lf", &la1, &la5, &la15); | 160 | sscanf (input_buffer, "%*[^l]load averages: %lf, %lf, %lf", &la1, &la5, &la15); |
161 | } | 161 | } |
162 | else { | 162 | else { |
163 | printf (_("could not parse load from uptime: %s\n"), result, PATH_TO_UPTIME); | 163 | printf (_("could not parse load from uptime %s: %s\n"), PATH_TO_UPTIME, result); |
164 | return STATE_UNKNOWN; | 164 | return STATE_UNKNOWN; |
165 | } | 165 | } |
166 | 166 | ||
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 75efc289..5ac6c65b 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c | |||
@@ -297,7 +297,7 @@ void setup_request(ntp_message *p){ | |||
297 | * this is done by filtering servers based on stratum, dispersion, and | 297 | * this is done by filtering servers based on stratum, dispersion, and |
298 | * finally round-trip delay. */ | 298 | * finally round-trip delay. */ |
299 | int best_offset_server(const ntp_server_results *slist, int nservers){ | 299 | int best_offset_server(const ntp_server_results *slist, int nservers){ |
300 | int i=0, cserver=0, best_server=-1; | 300 | int cserver=0, best_server=-1; |
301 | 301 | ||
302 | /* for each server */ | 302 | /* for each server */ |
303 | for(cserver=0; cserver<nservers; cserver++){ | 303 | for(cserver=0; cserver<nservers; cserver++){ |
@@ -356,7 +356,7 @@ int best_offset_server(const ntp_server_results *slist, int nservers){ | |||
356 | * we have to do it in a way that our lazy macros don't handle currently :( */ | 356 | * we have to do it in a way that our lazy macros don't handle currently :( */ |
357 | double offset_request(const char *host, int *status){ | 357 | double offset_request(const char *host, int *status){ |
358 | int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; | 358 | int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; |
359 | int servers_completed=0, one_written=0, one_read=0, servers_readable=0, best_index=-1; | 359 | int servers_completed=0, one_read=0, servers_readable=0, best_index=-1; |
360 | time_t now_time=0, start_ts=0; | 360 | time_t now_time=0, start_ts=0; |
361 | ntp_message *req=NULL; | 361 | ntp_message *req=NULL; |
362 | double avg_offset=0.; | 362 | double avg_offset=0.; |
@@ -421,7 +421,6 @@ double offset_request(const char *host, int *status){ | |||
421 | * been touched in the past second or so and is still lacking | 421 | * been touched in the past second or so and is still lacking |
422 | * some responses. for each of these servers, send a new request, | 422 | * some responses. for each of these servers, send a new request, |
423 | * and update the "waiting" timestamp with the current time. */ | 423 | * and update the "waiting" timestamp with the current time. */ |
424 | one_written=0; | ||
425 | now_time=time(NULL); | 424 | now_time=time(NULL); |
426 | 425 | ||
427 | for(i=0; i<num_hosts; i++){ | 426 | for(i=0; i<num_hosts; i++){ |
@@ -431,7 +430,6 @@ double offset_request(const char *host, int *status){ | |||
431 | setup_request(&req[i]); | 430 | setup_request(&req[i]); |
432 | write(socklist[i], &req[i], sizeof(ntp_message)); | 431 | write(socklist[i], &req[i], sizeof(ntp_message)); |
433 | servers[i].waiting=now_time; | 432 | servers[i].waiting=now_time; |
434 | one_written=1; | ||
435 | break; | 433 | break; |
436 | } | 434 | } |
437 | } | 435 | } |
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c index 295f86f6..1cc8cbfb 100644 --- a/plugins/check_ntp_time.c +++ b/plugins/check_ntp_time.c | |||
@@ -244,7 +244,7 @@ void setup_request(ntp_message *p){ | |||
244 | * this is done by filtering servers based on stratum, dispersion, and | 244 | * this is done by filtering servers based on stratum, dispersion, and |
245 | * finally round-trip delay. */ | 245 | * finally round-trip delay. */ |
246 | int best_offset_server(const ntp_server_results *slist, int nservers){ | 246 | int best_offset_server(const ntp_server_results *slist, int nservers){ |
247 | int i=0, cserver=0, best_server=-1; | 247 | int cserver=0, best_server=-1; |
248 | 248 | ||
249 | /* for each server */ | 249 | /* for each server */ |
250 | for(cserver=0; cserver<nservers; cserver++){ | 250 | for(cserver=0; cserver<nservers; cserver++){ |
@@ -303,7 +303,7 @@ int best_offset_server(const ntp_server_results *slist, int nservers){ | |||
303 | * we have to do it in a way that our lazy macros don't handle currently :( */ | 303 | * we have to do it in a way that our lazy macros don't handle currently :( */ |
304 | double offset_request(const char *host, int *status){ | 304 | double offset_request(const char *host, int *status){ |
305 | int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; | 305 | int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; |
306 | int servers_completed=0, one_written=0, one_read=0, servers_readable=0, best_index=-1; | 306 | int servers_completed=0, one_read=0, servers_readable=0, best_index=-1; |
307 | time_t now_time=0, start_ts=0; | 307 | time_t now_time=0, start_ts=0; |
308 | ntp_message *req=NULL; | 308 | ntp_message *req=NULL; |
309 | double avg_offset=0.; | 309 | double avg_offset=0.; |
@@ -368,7 +368,6 @@ double offset_request(const char *host, int *status){ | |||
368 | * been touched in the past second or so and is still lacking | 368 | * been touched in the past second or so and is still lacking |
369 | * some responses. For each of these servers, send a new request, | 369 | * some responses. For each of these servers, send a new request, |
370 | * and update the "waiting" timestamp with the current time. */ | 370 | * and update the "waiting" timestamp with the current time. */ |
371 | one_written=0; | ||
372 | now_time=time(NULL); | 371 | now_time=time(NULL); |
373 | 372 | ||
374 | for(i=0; i<num_hosts; i++){ | 373 | for(i=0; i<num_hosts; i++){ |
@@ -378,7 +377,6 @@ double offset_request(const char *host, int *status){ | |||
378 | setup_request(&req[i]); | 377 | setup_request(&req[i]); |
379 | write(socklist[i], &req[i], sizeof(ntp_message)); | 378 | write(socklist[i], &req[i], sizeof(ntp_message)); |
380 | servers[i].waiting=now_time; | 379 | servers[i].waiting=now_time; |
381 | one_written=1; | ||
382 | break; | 380 | break; |
383 | } | 381 | } |
384 | } | 382 | } |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 9839d6e8..da9638c4 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -152,7 +152,7 @@ state_data *previous_state; | |||
152 | double *previous_value; | 152 | double *previous_value; |
153 | size_t previous_size = OID_COUNT_STEP; | 153 | size_t previous_size = OID_COUNT_STEP; |
154 | int perf_labels = 1; | 154 | int perf_labels = 1; |
155 | 155 | char* ip_version = ""; | |
156 | 156 | ||
157 | static char *fix_snmp_range(char *th) | 157 | static char *fix_snmp_range(char *th) |
158 | { | 158 | { |
@@ -680,6 +680,8 @@ process_arguments (int argc, char **argv) | |||
680 | {"offset", required_argument, 0, L_OFFSET}, | 680 | {"offset", required_argument, 0, L_OFFSET}, |
681 | {"invert-search", no_argument, 0, L_INVERT_SEARCH}, | 681 | {"invert-search", no_argument, 0, L_INVERT_SEARCH}, |
682 | {"perf-oids", no_argument, 0, 'O'}, | 682 | {"perf-oids", no_argument, 0, 'O'}, |
683 | {"ipv4", no_argument, 0, '4'}, | ||
684 | {"ipv6", no_argument, 0, '6'}, | ||
683 | {0, 0, 0, 0} | 685 | {0, 0, 0, 0} |
684 | }; | 686 | }; |
685 | 687 | ||
@@ -697,7 +699,7 @@ process_arguments (int argc, char **argv) | |||
697 | } | 699 | } |
698 | 700 | ||
699 | while (1) { | 701 | while (1) { |
700 | c = getopt_long (argc, argv, "nhvVOt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:", | 702 | c = getopt_long (argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:", |
701 | longopts, &option); | 703 | longopts, &option); |
702 | 704 | ||
703 | if (c == -1 || c == EOF) | 705 | if (c == -1 || c == EOF) |
@@ -922,6 +924,13 @@ process_arguments (int argc, char **argv) | |||
922 | case 'O': | 924 | case 'O': |
923 | perf_labels=0; | 925 | perf_labels=0; |
924 | break; | 926 | break; |
927 | case '4': | ||
928 | break; | ||
929 | case '6': | ||
930 | xasprintf(&ip_version, "udp6:"); | ||
931 | if(verbose>2) | ||
932 | printf("IPv6 detected! Will pass \"udp6:\" to snmpget.\n"); | ||
933 | break; | ||
925 | } | 934 | } |
926 | } | 935 | } |
927 | 936 | ||
@@ -1127,6 +1136,7 @@ print_help (void) | |||
1127 | 1136 | ||
1128 | printf (UT_HELP_VRSN); | 1137 | printf (UT_HELP_VRSN); |
1129 | printf (UT_EXTRA_OPTS); | 1138 | printf (UT_EXTRA_OPTS); |
1139 | printf (UT_IPv46); | ||
1130 | 1140 | ||
1131 | printf (UT_HOST_PORT, 'p', DEFAULT_PORT); | 1141 | printf (UT_HOST_PORT, 'p', DEFAULT_PORT); |
1132 | 1142 | ||
@@ -1245,5 +1255,5 @@ print_usage (void) | |||
1245 | printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n"); | 1255 | printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n"); |
1246 | printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n"); | 1256 | printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n"); |
1247 | printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n"); | 1257 | printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n"); |
1248 | printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd]\n"); | 1258 | printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd] [-4|6]\n"); |
1249 | } | 1259 | } |
diff --git a/plugins/check_users.c b/plugins/check_users.c index 54415a48..f6f4b362 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c | |||
@@ -54,15 +54,15 @@ int process_arguments (int, char **); | |||
54 | void print_help (void); | 54 | void print_help (void); |
55 | void print_usage (void); | 55 | void print_usage (void); |
56 | 56 | ||
57 | int wusers = -1; | 57 | char *warning_range = NULL; |
58 | int cusers = -1; | 58 | char *critical_range = NULL; |
59 | thresholds *thlds = NULL; | ||
59 | 60 | ||
60 | int | 61 | int |
61 | main (int argc, char **argv) | 62 | main (int argc, char **argv) |
62 | { | 63 | { |
63 | int users = -1; | 64 | int users = -1; |
64 | int result = STATE_UNKNOWN; | 65 | int result = STATE_UNKNOWN; |
65 | char *perf; | ||
66 | #if HAVE_WTSAPI32_H | 66 | #if HAVE_WTSAPI32_H |
67 | WTS_SESSION_INFO *wtsinfo; | 67 | WTS_SESSION_INFO *wtsinfo; |
68 | DWORD wtscount; | 68 | DWORD wtscount; |
@@ -77,8 +77,6 @@ main (int argc, char **argv) | |||
77 | bindtextdomain (PACKAGE, LOCALEDIR); | 77 | bindtextdomain (PACKAGE, LOCALEDIR); |
78 | textdomain (PACKAGE); | 78 | textdomain (PACKAGE); |
79 | 79 | ||
80 | perf = strdup (""); | ||
81 | |||
82 | /* Parse extra opts if any */ | 80 | /* Parse extra opts if any */ |
83 | argv = np_extra_opts (&argc, argv, progname); | 81 | argv = np_extra_opts (&argc, argv, progname); |
84 | 82 | ||
@@ -160,23 +158,15 @@ main (int argc, char **argv) | |||
160 | #endif | 158 | #endif |
161 | 159 | ||
162 | /* check the user count against warning and critical thresholds */ | 160 | /* check the user count against warning and critical thresholds */ |
163 | if (users > cusers) | 161 | result = get_status((double)users, thlds); |
164 | result = STATE_CRITICAL; | ||
165 | else if (users > wusers) | ||
166 | result = STATE_WARNING; | ||
167 | else if (users >= 0) | ||
168 | result = STATE_OK; | ||
169 | 162 | ||
170 | if (result == STATE_UNKNOWN) | 163 | if (result == STATE_UNKNOWN) |
171 | printf ("%s\n", _("Unable to read output")); | 164 | printf ("%s\n", _("Unable to read output")); |
172 | else { | 165 | else { |
173 | xasprintf (&perf, "%s", perfdata ("users", users, "", | 166 | printf (_("USERS %s - %d users currently logged in |%s\n"), |
174 | TRUE, wusers, | 167 | state_text(result), users, |
175 | TRUE, cusers, | 168 | sperfdata_int("users", users, "", warning_range, |
176 | TRUE, 0, | 169 | critical_range, TRUE, 0, FALSE, 0)); |
177 | FALSE, 0)); | ||
178 | printf (_("USERS %s - %d users currently logged in |%s\n"), state_text (result), | ||
179 | users, perf); | ||
180 | } | 170 | } |
181 | 171 | ||
182 | return result; | 172 | return result; |
@@ -215,33 +205,27 @@ process_arguments (int argc, char **argv) | |||
215 | print_revision (progname, NP_VERSION); | 205 | print_revision (progname, NP_VERSION); |
216 | exit (STATE_UNKNOWN); | 206 | exit (STATE_UNKNOWN); |
217 | case 'c': /* critical */ | 207 | case 'c': /* critical */ |
218 | if (!is_intnonneg (optarg)) | 208 | critical_range = optarg; |
219 | usage4 (_("Critical threshold must be a positive integer")); | ||
220 | else | ||
221 | cusers = atoi (optarg); | ||
222 | break; | 209 | break; |
223 | case 'w': /* warning */ | 210 | case 'w': /* warning */ |
224 | if (!is_intnonneg (optarg)) | 211 | warning_range = optarg; |
225 | usage4 (_("Warning threshold must be a positive integer")); | ||
226 | else | ||
227 | wusers = atoi (optarg); | ||
228 | break; | 212 | break; |
229 | } | 213 | } |
230 | } | 214 | } |
231 | 215 | ||
232 | c = optind; | 216 | c = optind; |
233 | if (wusers == -1 && argc > c) { | 217 | if (warning_range == NULL && argc > c) |
234 | if (is_intnonneg (argv[c]) == FALSE) | 218 | warning_range = argv[c++]; |
235 | usage4 (_("Warning threshold must be a positive integer")); | 219 | if (critical_range == NULL && argc > c) |
236 | else | 220 | critical_range = argv[c++]; |
237 | wusers = atoi (argv[c++]); | 221 | |
238 | } | 222 | /* this will abort in case of invalid ranges */ |
239 | if (cusers == -1 && argc > c) { | 223 | set_thresholds (&thlds, warning_range, critical_range); |
240 | if (is_intnonneg (argv[c]) == FALSE) | 224 | |
241 | usage4 (_("Warning threshold must be a positive integer")); | 225 | if (thlds->warning->end < 0) |
242 | else | 226 | usage4 (_("Warning threshold must be a positive integer")); |
243 | cusers = atoi (argv[c]); | 227 | if (thlds->critical->end < 0) |
244 | } | 228 | usage4 (_("Critical threshold must be a positive integer")); |
245 | 229 | ||
246 | return OK; | 230 | return OK; |
247 | } | 231 | } |
diff --git a/plugins/negate.c b/plugins/negate.c index beaed1ea..b320e356 100644 --- a/plugins/negate.c +++ b/plugins/negate.c | |||
@@ -59,8 +59,8 @@ static int state[4] = { | |||
59 | int | 59 | int |
60 | main (int argc, char **argv) | 60 | main (int argc, char **argv) |
61 | { | 61 | { |
62 | int found = 0, result = STATE_UNKNOWN; | 62 | int result = STATE_UNKNOWN; |
63 | char *buf, *sub; | 63 | char *sub; |
64 | char **command_line; | 64 | char **command_line; |
65 | output chld_out, chld_err; | 65 | output chld_out, chld_err; |
66 | int i; | 66 | int i; |
diff --git a/plugins/sslutils.c b/plugins/sslutils.c index 4f9c793c..b412ef3d 100644 --- a/plugins/sslutils.c +++ b/plugins/sslutils.c | |||
@@ -197,6 +197,7 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){ | |||
197 | X509_NAME *subj=NULL; | 197 | X509_NAME *subj=NULL; |
198 | char timestamp[50] = ""; | 198 | char timestamp[50] = ""; |
199 | char cn[MAX_CN_LENGTH]= ""; | 199 | char cn[MAX_CN_LENGTH]= ""; |
200 | char *tz; | ||
200 | 201 | ||
201 | int cnlen =-1; | 202 | int cnlen =-1; |
202 | int status=STATE_UNKNOWN; | 203 | int status=STATE_UNKNOWN; |
@@ -264,10 +265,18 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){ | |||
264 | (tm->data[10 + offset] - '0') * 10 + (tm->data[11 + offset] - '0'); | 265 | (tm->data[10 + offset] - '0') * 10 + (tm->data[11 + offset] - '0'); |
265 | stamp.tm_isdst = -1; | 266 | stamp.tm_isdst = -1; |
266 | 267 | ||
267 | time_left = difftime(timegm(&stamp), time(NULL)); | 268 | tm_t = timegm(&stamp); |
269 | time_left = difftime(tm_t, time(NULL)); | ||
268 | days_left = time_left / 86400; | 270 | days_left = time_left / 86400; |
269 | tm_t = mktime (&stamp); | 271 | tz = getenv("TZ"); |
270 | strftime(timestamp, 50, "%c", localtime(&tm_t)); | 272 | setenv("TZ", "GMT", 1); |
273 | tzset(); | ||
274 | strftime(timestamp, 50, "%c %z", localtime(&tm_t)); | ||
275 | if (tz) | ||
276 | setenv("TZ", tz, 1); | ||
277 | else | ||
278 | unsetenv("TZ"); | ||
279 | tzset(); | ||
271 | 280 | ||
272 | if (days_left > 0 && days_left <= days_till_exp_warn) { | 281 | if (days_left > 0 && days_left <= days_till_exp_warn) { |
273 | printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp); | 282 | printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp); |
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis index fe8aabdb..5d9c5ff7 100644 --- a/plugins/t/NPTest.cache.travis +++ b/plugins/t/NPTest.cache.travis | |||
@@ -11,7 +11,7 @@ | |||
11 | 'NP_HOST_NONRESPONSIVE' => '10.0.0.1', | 11 | 'NP_HOST_NONRESPONSIVE' => '10.0.0.1', |
12 | 'NP_HOST_RESPONSIVE' => 'localhost', | 12 | 'NP_HOST_RESPONSIVE' => 'localhost', |
13 | 'NP_HOST_SMB' => '', | 13 | 'NP_HOST_SMB' => '', |
14 | 'NP_HOST_SNMP' => '', | 14 | 'NP_HOST_SNMP' => 'localhost', |
15 | 'NP_HOST_TCP_FTP' => '', | 15 | 'NP_HOST_TCP_FTP' => '', |
16 | 'NP_HOST_TCP_HPJD' => '', | 16 | 'NP_HOST_TCP_HPJD' => '', |
17 | 'NP_HOST_HPJD_PORT_INVALID' => '161', | 17 | 'NP_HOST_HPJD_PORT_INVALID' => '161', |
@@ -39,7 +39,7 @@ | |||
39 | 'NP_SMB_SHARE_SPC' => '', | 39 | 'NP_SMB_SHARE_SPC' => '', |
40 | 'NP_SMB_VALID_USER' => '', | 40 | 'NP_SMB_VALID_USER' => '', |
41 | 'NP_SMB_VALID_USER_PASS' => '', | 41 | 'NP_SMB_VALID_USER_PASS' => '', |
42 | 'NP_SNMP_COMMUNITY' => '', | 42 | 'NP_SNMP_COMMUNITY' => 'public', |
43 | 'NP_SSH_CONFIGFILE' => '~/.ssh/config', | 43 | 'NP_SSH_CONFIGFILE' => '~/.ssh/config', |
44 | 'NP_SSH_HOST' => 'localhost', | 44 | 'NP_SSH_HOST' => 'localhost', |
45 | 'NP_SSH_IDENTITY' => '~/.ssh/id_dsa', | 45 | 'NP_SSH_IDENTITY' => '~/.ssh/id_dsa', |
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index c2caec60..5a90f02a 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
@@ -9,7 +9,7 @@ use Test::More; | |||
9 | use POSIX qw/mktime strftime/; | 9 | use POSIX qw/mktime strftime/; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | plan tests => 42; | 12 | plan tests => 49; |
13 | 13 | ||
14 | my $successOutput = '/OK.*HTTP.*second/'; | 14 | my $successOutput = '/OK.*HTTP.*second/'; |
15 | 15 | ||
@@ -64,6 +64,32 @@ cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); | |||
64 | # Is also possible to get a socket timeout if DNS is not responding fast enough | 64 | # Is also possible to get a socket timeout if DNS is not responding fast enough |
65 | like( $res->output, "/Unable to open TCP socket|Socket timeout after/", "Output OK"); | 65 | like( $res->output, "/Unable to open TCP socket|Socket timeout after/", "Output OK"); |
66 | 66 | ||
67 | # host header checks | ||
68 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http"); | ||
69 | like( $res->output, '/^Host: '.$host_tcp_http.'\s*$/ms', "Host Header OK" ); | ||
70 | |||
71 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http -p 80"); | ||
72 | like( $res->output, '/^Host: '.$host_tcp_http.'\s*$/ms', "Host Header OK" ); | ||
73 | |||
74 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http:8080 -p 80"); | ||
75 | like( $res->output, '/^Host: '.$host_tcp_http.':8080\s*$/ms', "Host Header OK" ); | ||
76 | |||
77 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http:8080 -p 80"); | ||
78 | like( $res->output, '/^Host: '.$host_tcp_http.':8080\s*$/ms', "Host Header OK" ); | ||
79 | |||
80 | SKIP: { | ||
81 | skip "No internet access", 3 if $internet_access eq "no"; | ||
82 | |||
83 | $res = NPTest->testCmd("./check_http -v -H www.verisign.com -S"); | ||
84 | like( $res->output, '/^Host: www.verisign.com\s*$/ms', "Host Header OK" ); | ||
85 | |||
86 | $res = NPTest->testCmd("./check_http -v -H www.verisign.com:8080 -S -p 443"); | ||
87 | like( $res->output, '/^Host: www.verisign.com:8080\s*$/ms', "Host Header OK" ); | ||
88 | |||
89 | $res = NPTest->testCmd("./check_http -v -H www.verisign.com:443 -S -p 443"); | ||
90 | like( $res->output, '/^Host: www.verisign.com\s*$/ms', "Host Header OK" ); | ||
91 | }; | ||
92 | |||
67 | SKIP: { | 93 | SKIP: { |
68 | skip "No host serving monitoring in index file", 7 unless $host_tcp_http2; | 94 | skip "No host serving monitoring in index file", 7 unless $host_tcp_http2; |
69 | 95 | ||
@@ -121,9 +147,9 @@ SKIP: { | |||
121 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 www.verisign.com"); | 147 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 www.verisign.com"); |
122 | like($res->output, qr/OK - Certificate 'www.verisign.com' will expire on/, "Catch cert output"); | 148 | like($res->output, qr/OK - Certificate 'www.verisign.com' will expire on/, "Catch cert output"); |
123 | is( $res->return_code, 0, "Catch cert output exit code" ); | 149 | is( $res->return_code, 0, "Catch cert output exit code" ); |
124 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)\./); | 150 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/); |
125 | if(!defined $year) { | 151 | if(!defined $year) { |
126 | die("parsing date failed from: ".$res); | 152 | die("parsing date failed from: ".$res->output); |
127 | } | 153 | } |
128 | my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}; | 154 | my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}; |
129 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); | 155 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); |
@@ -154,7 +180,7 @@ SKIP: { | |||
154 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 180 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
155 | 181 | ||
156 | $res = NPTest->testCmd( | 182 | $res = NPTest->testCmd( |
157 | "./check_http --ssl www.e-paycobalt.com" | 183 | "./check_http --ssl -H www.e-paycobalt.com" |
158 | ); | 184 | ); |
159 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); | 185 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); |
160 | 186 | ||
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index aefd872a..eff46ea1 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
@@ -10,7 +10,7 @@ use NPTest; | |||
10 | 10 | ||
11 | BEGIN { | 11 | BEGIN { |
12 | plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp"; | 12 | plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp"; |
13 | plan tests => 61; | 13 | plan tests => 63; |
14 | } | 14 | } |
15 | 15 | ||
16 | my $res; | 16 | my $res; |
@@ -45,7 +45,7 @@ is( $res->return_code, 3, "Invalid protocol" ); | |||
45 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); | 45 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); |
46 | 46 | ||
47 | SKIP: { | 47 | SKIP: { |
48 | skip "no snmp host defined", 48 if ( ! $host_snmp ); | 48 | skip "no snmp host defined", 50 if ( ! $host_snmp ); |
49 | 49 | ||
50 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | 50 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); |
51 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); | 51 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); |
@@ -153,6 +153,10 @@ SKIP: { | |||
153 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0"); | 153 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0"); |
154 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); | 154 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); |
155 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); | 155 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); |
156 | |||
157 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o HOST-RESOURCES-MIB::hrSWRunParameters.1"); | ||
158 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); | ||
159 | is( $res->output, 'SNMP OK - "" | ', "snmp response without datatype" ); | ||
156 | } | 160 | } |
157 | 161 | ||
158 | SKIP: { | 162 | SKIP: { |
diff --git a/plugins/t/check_users.t b/plugins/t/check_users.t index 39044bb5..088f3b52 100644 --- a/plugins/t/check_users.t +++ b/plugins/t/check_users.t | |||
@@ -13,7 +13,7 @@ use Test; | |||
13 | use NPTest; | 13 | use NPTest; |
14 | 14 | ||
15 | use vars qw($tests); | 15 | use vars qw($tests); |
16 | BEGIN {$tests = 4; plan tests => $tests} | 16 | BEGIN {$tests = 8; plan tests => $tests} |
17 | 17 | ||
18 | my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; | 18 | my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; |
19 | my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; | 19 | my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; |
@@ -22,6 +22,8 @@ my $t; | |||
22 | 22 | ||
23 | $t += checkCmd( "./check_users 1000 1000", 0, $successOutput ); | 23 | $t += checkCmd( "./check_users 1000 1000", 0, $successOutput ); |
24 | $t += checkCmd( "./check_users 0 0", 2, $failureOutput ); | 24 | $t += checkCmd( "./check_users 0 0", 2, $failureOutput ); |
25 | $t += checkCmd( "./check_users -w 0:1000 -c 0:1000", 0, $successOutput ); | ||
26 | $t += checkCmd( "./check_users -w 0:0 -c 0:0", 2, $failureOutput ); | ||
25 | 27 | ||
26 | exit(0) if defined($Test::Harness::VERSION); | 28 | exit(0) if defined($Test::Harness::VERSION); |
27 | exit($tests - $t); | 29 | exit($tests - $t); |
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index e72d243a..1bc0ecb7 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -17,6 +17,8 @@ use Test::More; | |||
17 | use NPTest; | 17 | use NPTest; |
18 | use FindBin qw($Bin); | 18 | use FindBin qw($Bin); |
19 | 19 | ||
20 | $ENV{'LC_TIME'} = "C"; | ||
21 | |||
20 | my $common_tests = 70; | 22 | my $common_tests = 70; |
21 | my $ssl_only_tests = 8; | 23 | my $ssl_only_tests = 8; |
22 | # Check that all dependent modules are available | 24 | # Check that all dependent modules are available |
@@ -186,21 +188,21 @@ SKIP: { | |||
186 | 188 | ||
187 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | 189 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); |
188 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | 190 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); |
189 | is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019.', "output ok" ); | 191 | is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019 +0000.', "output ok" ); |
190 | 192 | ||
191 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | 193 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); |
192 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | 194 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); |
193 | like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019\)./', "output ok" ); | 195 | like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); |
194 | 196 | ||
195 | # Expired cert tests | 197 | # Expired cert tests |
196 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | 198 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); |
197 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); | 199 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); |
198 | like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019\)./', "output ok" ); | 200 | like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); |
199 | 201 | ||
200 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | 202 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); |
201 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | 203 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); |
202 | is( $result->output, | 204 | is( $result->output, |
203 | 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009.', | 205 | 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009 +0000.', |
204 | "output ok" ); | 206 | "output ok" ); |
205 | 207 | ||
206 | } | 208 | } |
diff --git a/plugins/utils.c b/plugins/utils.c index a864e4aa..231af92b 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -668,3 +668,44 @@ char *sperfdata (const char *label, | |||
668 | 668 | ||
669 | return data; | 669 | return data; |
670 | } | 670 | } |
671 | |||
672 | char *sperfdata_int (const char *label, | ||
673 | int val, | ||
674 | const char *uom, | ||
675 | char *warn, | ||
676 | char *crit, | ||
677 | int minp, | ||
678 | int minv, | ||
679 | int maxp, | ||
680 | int maxv) | ||
681 | { | ||
682 | char *data = NULL; | ||
683 | if (strpbrk (label, "'= ")) | ||
684 | xasprintf (&data, "'%s'=", label); | ||
685 | else | ||
686 | xasprintf (&data, "%s=", label); | ||
687 | |||
688 | xasprintf (&data, "%s%d", data, val); | ||
689 | xasprintf (&data, "%s%s;", data, uom); | ||
690 | |||
691 | if (warn!=NULL) | ||
692 | xasprintf (&data, "%s%s", data, warn); | ||
693 | |||
694 | xasprintf (&data, "%s;", data); | ||
695 | |||
696 | if (crit!=NULL) | ||
697 | xasprintf (&data, "%s%s", data, crit); | ||
698 | |||
699 | xasprintf (&data, "%s;", data); | ||
700 | |||
701 | if (minp) | ||
702 | xasprintf (&data, "%s%d", data, minv); | ||
703 | |||
704 | if (maxp) { | ||
705 | xasprintf (&data, "%s;", data); | ||
706 | xasprintf (&data, "%s%d", data, maxv); | ||
707 | } | ||
708 | |||
709 | return data; | ||
710 | } | ||
711 | |||
diff --git a/plugins/utils.h b/plugins/utils.h index 4c4aaccc..a436e1ca 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -94,29 +94,17 @@ const char *state_text (int); | |||
94 | #define max(a,b) (((a)>(b))?(a):(b)) | 94 | #define max(a,b) (((a)>(b))?(a):(b)) |
95 | #define min(a,b) (((a)<(b))?(a):(b)) | 95 | #define min(a,b) (((a)<(b))?(a):(b)) |
96 | 96 | ||
97 | char *perfdata (const char *, | 97 | char *perfdata (const char *, long int, const char *, int, long int, |
98 | long int, | 98 | int, long int, int, long int, int, long int); |
99 | const char *, | 99 | |
100 | int, | 100 | char *fperfdata (const char *, double, const char *, int, double, |
101 | long int, | 101 | int, double, int, double, int, double); |
102 | int, | 102 | |
103 | long int, | 103 | char *sperfdata (const char *, double, const char *, char *, char *, |
104 | int, | 104 | int, double, int, double); |
105 | long int, | 105 | |
106 | int, | 106 | char *sperfdata_int (const char *, int, const char *, char *, char *, |
107 | long int); | 107 | int, int, int, int); |
108 | |||
109 | char *fperfdata (const char *, | ||
110 | double, | ||
111 | const char *, | ||
112 | int, | ||
113 | double, | ||
114 | int, | ||
115 | double, | ||
116 | int, | ||
117 | double, | ||
118 | int, | ||
119 | double); | ||
120 | 108 | ||
121 | /* The idea here is that, although not every plugin will use all of these, | 109 | /* The idea here is that, although not every plugin will use all of these, |
122 | most will or should. Therefore, for consistency, these very common | 110 | most will or should. Therefore, for consistency, these very common |