summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_by_ssh.c3
-rw-r--r--plugins/check_dig.c9
-rw-r--r--plugins/check_disk.c16
-rw-r--r--plugins/check_dns.c22
-rw-r--r--plugins/check_hpjd.c30
-rw-r--r--plugins/check_mysql.c22
-rw-r--r--plugins/check_ntp_peer.c58
-rw-r--r--plugins/check_ntp_time.c15
-rw-r--r--plugins/netutils.c15
-rw-r--r--plugins/sslutils.c9
-rw-r--r--plugins/t/NPTest.cache.travis2
-rw-r--r--plugins/t/check_dns.t14
-rw-r--r--plugins/t/check_hpjd.t35
-rw-r--r--plugins/t/check_ntp.t4
-rw-r--r--plugins/t/negate.t5
-rwxr-xr-xplugins/tests/check_http.t8
-rwxr-xr-xplugins/tests/check_snmp.t11
17 files changed, 217 insertions, 61 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 58f333d..a877f88 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -169,7 +169,8 @@ process_arguments (int argc, char **argv)
169 {"verbose", no_argument, 0, 'v'}, 169 {"verbose", no_argument, 0, 'v'},
170 {"fork", no_argument, 0, 'f'}, 170 {"fork", no_argument, 0, 'f'},
171 {"timeout", required_argument, 0, 't'}, 171 {"timeout", required_argument, 0, 't'},
172 {"host", required_argument, 0, 'H'}, 172 {"host", required_argument, 0, 'H'}, /* backward compatibility */
173 {"hostname", required_argument, 0, 'H'},
173 {"port", required_argument,0,'p'}, 174 {"port", required_argument,0,'p'},
174 {"output", required_argument, 0, 'O'}, 175 {"output", required_argument, 0, 'O'},
175 {"name", required_argument, 0, 'n'}, 176 {"name", required_argument, 0, 'n'},
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index d9481f2..d899b11 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -94,8 +94,8 @@ 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 -p %d %s -t %s %s %s +tries=%d +time=%d", 97 xasprintf (&command_line, "%s %s %s -p %d @%s %s %s +tries=%d +time=%d",
98 PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args, query_transport, 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);
101 gettimeofday (&tv, NULL); 101 gettimeofday (&tv, NULL);
@@ -296,7 +296,10 @@ process_arguments (int argc, char **argv)
296 dns_server = argv[c]; 296 dns_server = argv[c];
297 } 297 }
298 else { 298 else {
299 dns_server = strdup ("127.0.0.1"); 299 if (strcmp(query_transport,"-6") == 0)
300 dns_server = strdup("::1");
301 else
302 dns_server = strdup ("127.0.0.1");
300 } 303 }
301 } 304 }
302 305
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 925dfa8..0d73a4f 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -171,6 +171,7 @@ main (int argc, char **argv)
171 char *details; 171 char *details;
172 char *perf; 172 char *perf;
173 char *preamble; 173 char *preamble;
174 char *flag_header;
174 double inode_space_pct; 175 double inode_space_pct;
175 double warning_high_tide; 176 double warning_high_tide;
176 double critical_high_tide; 177 double critical_high_tide;
@@ -353,18 +354,23 @@ main (int argc, char **argv)
353 if (disk_result==STATE_OK && erronly && !verbose) 354 if (disk_result==STATE_OK && erronly && !verbose)
354 continue; 355 continue;
355 356
356 xasprintf (&output, "%s %s %.0f %s (%.0f%%", 357 if(disk_result && verbose >= 1) {
357 output, 358 xasprintf(&flag_header, " %s [", state_text (disk_result));
359 } else {
360 xasprintf(&flag_header, "");
361 }
362 xasprintf (&output, "%s%s %s %.0f %s (%.0f%%",
363 output, flag_header,
358 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 364 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
359 path->dfree_units, 365 path->dfree_units,
360 units, 366 units,
361 path->dfree_pct); 367 path->dfree_pct);
362 if (path->dused_inodes_percent < 0) { 368 if (path->dused_inodes_percent < 0) {
363 xasprintf(&output, "%s inode=-);", output); 369 xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
364 } else { 370 } else {
365 xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent ); 371 xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : ""));
366 } 372 }
367 373 free(flag_header);
368 /* TODO: Need to do a similar debug line 374 /* TODO: Need to do a similar debug line
369 xasprintf (&details, _("%s\n\ 375 xasprintf (&details, _("%s\n\
370%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), 376%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 31a953d..2212122 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -136,6 +136,28 @@ main (int argc, char **argv)
136 } 136 }
137 } 137 }
138 138
139 /* bug ID: 2946553 - Older versions of bind will use all available dns
140 servers, we have to match the one specified */
141 if (strstr (chld_out.line[i], "Server:") && strlen(dns_server) > 0) {
142 temp_buffer = strchr (chld_out.line[i], ':');
143 temp_buffer++;
144
145 /* Strip leading tabs */
146 for (; *temp_buffer != '\0' && *temp_buffer == '\t'; temp_buffer++)
147 /* NOOP */;
148
149 strip(temp_buffer);
150 if (temp_buffer==NULL || strlen(temp_buffer)==0) {
151 die (STATE_CRITICAL,
152 _("DNS CRITICAL - '%s' returned empty server string\n"),
153 NSLOOKUP_COMMAND);
154 }
155
156 if (strcmp(temp_buffer, dns_server) != 0) {
157 die (STATE_CRITICAL, _("DNS CRITICAL - No response from DNS %s\n"), dns_server);
158 }
159 }
160
139 /* the server is responding, we just got the host name... */ 161 /* the server is responding, we just got the host name... */
140 if (strstr (chld_out.line[i], "Name:")) 162 if (strstr (chld_out.line[i], "Name:"))
141 parse_address = TRUE; 163 parse_address = TRUE;
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index 1e7605b..5fe0698 100644
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
@@ -39,7 +39,7 @@ const char *email = "devel@monitoring-plugins.org";
39#include "netutils.h" 39#include "netutils.h"
40 40
41#define DEFAULT_COMMUNITY "public" 41#define DEFAULT_COMMUNITY "public"
42 42#define DEFAULT_PORT "161"
43 43
44const char *option_summary = "-H host [-C community]\n"; 44const char *option_summary = "-H host [-C community]\n";
45 45
@@ -66,6 +66,7 @@ void print_usage (void);
66 66
67char *community = NULL; 67char *community = NULL;
68char *address = NULL; 68char *address = NULL;
69char *port = NULL;
69 70
70int 71int
71main (int argc, char **argv) 72main (int argc, char **argv)
@@ -119,8 +120,8 @@ main (int argc, char **argv)
119 HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY); 120 HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY);
120 121
121 /* get the command to run */ 122 /* get the command to run */
122 sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s %s", PATH_TO_SNMPGET, community, 123 sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%hd %s", PATH_TO_SNMPGET, community,
123 address, query_string); 124 address, port, query_string);
124 125
125 /* run the command */ 126 /* run the command */
126 child_process = spopen (command_line); 127 child_process = spopen (command_line);
@@ -313,7 +314,7 @@ process_arguments (int argc, char **argv)
313 {"community", required_argument, 0, 'C'}, 314 {"community", required_argument, 0, 'C'},
314/* {"critical", required_argument,0,'c'}, */ 315/* {"critical", required_argument,0,'c'}, */
315/* {"warning", required_argument,0,'w'}, */ 316/* {"warning", required_argument,0,'w'}, */
316/* {"port", required_argument,0,'P'}, */ 317 {"port", required_argument,0,'p'},
317 {"version", no_argument, 0, 'V'}, 318 {"version", no_argument, 0, 'V'},
318 {"help", no_argument, 0, 'h'}, 319 {"help", no_argument, 0, 'h'},
319 {0, 0, 0, 0} 320 {0, 0, 0, 0}
@@ -324,7 +325,7 @@ process_arguments (int argc, char **argv)
324 325
325 326
326 while (1) { 327 while (1) {
327 c = getopt_long (argc, argv, "+hVH:C:", longopts, &option); 328 c = getopt_long (argc, argv, "+hVH:C:p:", longopts, &option);
328 329
329 if (c == -1 || c == EOF || c == 1) 330 if (c == -1 || c == EOF || c == 1)
330 break; 331 break;
@@ -341,6 +342,12 @@ process_arguments (int argc, char **argv)
341 case 'C': /* community */ 342 case 'C': /* community */
342 community = strscpy (community, optarg); 343 community = strscpy (community, optarg);
343 break; 344 break;
345 case 'p':
346 if (!is_intpos(optarg))
347 usage2 (_("Port must be a positive short integer"), optarg);
348 else
349 port = atoi(optarg);
350 break;
344 case 'V': /* version */ 351 case 'V': /* version */
345 print_revision (progname, NP_VERSION); 352 print_revision (progname, NP_VERSION);
346 exit (STATE_OK); 353 exit (STATE_OK);
@@ -369,6 +376,13 @@ process_arguments (int argc, char **argv)
369 community = strdup (DEFAULT_COMMUNITY); 376 community = strdup (DEFAULT_COMMUNITY);
370 } 377 }
371 378
379 if (port == NULL) {
380 if (argv[c] != NULL )
381 port = argv[c];
382 else
383 port = atoi (DEFAULT_PORT);
384 }
385
372 return validate_arguments (); 386 return validate_arguments ();
373} 387}
374 388
@@ -402,6 +416,10 @@ print_help (void)
402 printf (" %s", _("The SNMP community name ")); 416 printf (" %s", _("The SNMP community name "));
403 printf (_("(default=%s)"), DEFAULT_COMMUNITY); 417 printf (_("(default=%s)"), DEFAULT_COMMUNITY);
404 printf ("\n"); 418 printf ("\n");
419 printf (" %s\n", "-p, --port=STRING");
420 printf (" %s", _("Specify the port to check "));
421 printf (_("(default=%s)"), DEFAULT_PORT);
422 printf ("\n");
405 423
406 printf (UT_SUPPORT); 424 printf (UT_SUPPORT);
407} 425}
@@ -412,5 +430,5 @@ void
412print_usage (void) 430print_usage (void)
413{ 431{
414 printf ("%s\n", _("Usage:")); 432 printf ("%s\n", _("Usage:"));
415 printf ("%s -H host [-C community]\n", progname); 433 printf ("%s -H host [-C community] [-p port]\n", progname);
416} 434}
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 4f09e5f..216626b 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -42,6 +42,7 @@ const char *email = "devel@monitoring-plugins.org";
42#include "netutils.h" 42#include "netutils.h"
43 43
44#include <mysql.h> 44#include <mysql.h>
45#include <mysqld_error.h>
45#include <errmsg.h> 46#include <errmsg.h>
46 47
47char *db_user = NULL; 48char *db_user = NULL;
@@ -59,6 +60,7 @@ char *opt_file = NULL;
59char *opt_group = NULL; 60char *opt_group = NULL;
60unsigned int db_port = MYSQL_PORT; 61unsigned int db_port = MYSQL_PORT;
61int check_slave = 0, warn_sec = 0, crit_sec = 0; 62int check_slave = 0, warn_sec = 0, crit_sec = 0;
63int ignore_auth = 0;
62int verbose = 0; 64int verbose = 0;
63 65
64static double warning_time = 0; 66static double warning_time = 0;
@@ -136,7 +138,16 @@ main (int argc, char **argv)
136 mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers); 138 mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers);
137 /* establish a connection to the server and error checking */ 139 /* establish a connection to the server and error checking */
138 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { 140 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) {
139 if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) 141 if (ignore_auth && mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR)
142 {
143 printf("MySQL OK - Version: %s (protocol %d)\n",
144 mysql_get_server_info(&mysql),
145 mysql_get_proto_info(&mysql)
146 );
147 mysql_close (&mysql);
148 return STATE_OK;
149 }
150 else if (mysql_errno (&mysql) == CR_UNKNOWN_HOST)
140 die (STATE_WARNING, "%s\n", mysql_error (&mysql)); 151 die (STATE_WARNING, "%s\n", mysql_error (&mysql));
141 else if (mysql_errno (&mysql) == CR_VERSION_ERROR) 152 else if (mysql_errno (&mysql) == CR_VERSION_ERROR)
142 die (STATE_WARNING, "%s\n", mysql_error (&mysql)); 153 die (STATE_WARNING, "%s\n", mysql_error (&mysql));
@@ -341,6 +352,7 @@ process_arguments (int argc, char **argv)
341 {"critical", required_argument, 0, 'c'}, 352 {"critical", required_argument, 0, 'c'},
342 {"warning", required_argument, 0, 'w'}, 353 {"warning", required_argument, 0, 'w'},
343 {"check-slave", no_argument, 0, 'S'}, 354 {"check-slave", no_argument, 0, 'S'},
355 {"ignore-auth", no_argument, 0, 'n'},
344 {"verbose", no_argument, 0, 'v'}, 356 {"verbose", no_argument, 0, 'v'},
345 {"version", no_argument, 0, 'V'}, 357 {"version", no_argument, 0, 'V'},
346 {"help", no_argument, 0, 'h'}, 358 {"help", no_argument, 0, 'h'},
@@ -357,7 +369,7 @@ process_arguments (int argc, char **argv)
357 return ERROR; 369 return ERROR;
358 370
359 while (1) { 371 while (1) {
360 c = getopt_long (argc, argv, "hlvVSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option); 372 c = getopt_long (argc, argv, "hlvVnSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option);
361 373
362 if (c == -1 || c == EOF) 374 if (c == -1 || c == EOF)
363 break; 375 break;
@@ -419,6 +431,9 @@ process_arguments (int argc, char **argv)
419 case 'S': 431 case 'S':
420 check_slave = 1; /* check-slave */ 432 check_slave = 1; /* check-slave */
421 break; 433 break;
434 case 'n':
435 ignore_auth = 1; /* ignore-auth */
436 break;
422 case 'w': 437 case 'w':
423 warning = optarg; 438 warning = optarg;
424 warning_time = strtod (warning, NULL); 439 warning_time = strtod (warning, NULL);
@@ -506,6 +521,9 @@ print_help (void)
506 printf (UT_EXTRA_OPTS); 521 printf (UT_EXTRA_OPTS);
507 522
508 printf (UT_HOST_PORT, 'P', myport); 523 printf (UT_HOST_PORT, 'P', myport);
524 printf (" %s\n", "-n, --ignore-auth");
525 printf (" %s\n", _("Ignore authentication failure and check for mysql connectivity only"));
526
509 printf (" %s\n", "-s, --socket=STRING"); 527 printf (" %s\n", "-s, --socket=STRING");
510 printf (" %s\n", _("Use the specified socket (has no effect if -H is used)")); 528 printf (" %s\n", _("Use the specified socket (has no effect if -H is used)"));
511 529
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index 8dc1978..44424af 100644
--- a/plugins/check_ntp_peer.c
+++ b/plugins/check_ntp_peer.c
@@ -560,7 +560,7 @@ char *perfd_truechimers (int num_truechimers)
560} 560}
561 561
562int main(int argc, char *argv[]){ 562int main(int argc, char *argv[]){
563 int result, offset_result, stratum, num_truechimers; 563 int result, offset_result, stratum, num_truechimers, oresult, jresult, sresult, tresult;
564 double offset=0, jitter=0; 564 double offset=0, jitter=0;
565 char *result_line, *perfdata_line; 565 char *result_line, *perfdata_line;
566 566
@@ -597,15 +597,22 @@ int main(int argc, char *argv[]){
597 result = STATE_UNKNOWN; 597 result = STATE_UNKNOWN;
598 result = max_state_alt(result, get_status(fabs(offset), offset_thresholds)); 598 result = max_state_alt(result, get_status(fabs(offset), offset_thresholds));
599 } 599 }
600 oresult = result;
601
602 if(do_truechimers) {
603 tresult = get_status(num_truechimers, truechimer_thresholds);
604 result = max_state_alt(result, tresult);
605 }
600 606
601 if(do_truechimers) 607 if(do_stratum) {
602 result = max_state_alt(result, get_status(num_truechimers, truechimer_thresholds)); 608 sresult = get_status(stratum, stratum_thresholds);
603 609 result = max_state_alt(result, sresult);
604 if(do_stratum) 610 }
605 result = max_state_alt(result, get_status(stratum, stratum_thresholds));
606 611
607 if(do_jitter) 612 if(do_jitter) {
608 result = max_state_alt(result, get_status(jitter, jitter_thresholds)); 613 jresult = get_status(jitter, jitter_thresholds);
614 result = max_state_alt(result, jresult);
615 }
609 616
610 switch (result) { 617 switch (result) {
611 case STATE_CRITICAL : 618 case STATE_CRITICAL :
@@ -629,20 +636,43 @@ int main(int argc, char *argv[]){
629 if(offset_result == STATE_UNKNOWN){ 636 if(offset_result == STATE_UNKNOWN){
630 xasprintf(&result_line, "%s %s", result_line, _("Offset unknown")); 637 xasprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
631 xasprintf(&perfdata_line, ""); 638 xasprintf(&perfdata_line, "");
639 } else if (oresult == STATE_WARNING) {
640 xasprintf(&result_line, "%s %s %.10g secs (WARNING)", result_line, _("Offset"), offset);
641 } else if (oresult == STATE_CRITICAL) {
642 xasprintf(&result_line, "%s %s %.10g secs (CRITICAL)", result_line, _("Offset"), offset);
632 } else { 643 } else {
633 xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset); 644 xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset);
634 xasprintf(&perfdata_line, "%s", perfd_offset(offset)); 645 }
635 } 646 xasprintf(&perfdata_line, "%s", perfd_offset(offset));
647
636 if (do_jitter) { 648 if (do_jitter) {
637 xasprintf(&result_line, "%s, jitter=%f", result_line, jitter); 649 if (jresult == STATE_WARNING) {
650 xasprintf(&result_line, "%s, jitter=%f (WARNING)", result_line, jitter);
651 } else if (jresult == STATE_CRITICAL) {
652 xasprintf(&result_line, "%s, jitter=%f (CRITICAL)", result_line, jitter);
653 } else {
654 xasprintf(&result_line, "%s, jitter=%f", result_line, jitter);
655 }
638 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); 656 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter));
639 } 657 }
640 if (do_stratum) { 658 if (do_stratum) {
641 xasprintf(&result_line, "%s, stratum=%i", result_line, stratum); 659 if (sresult == STATE_WARNING) {
660 xasprintf(&result_line, "%s, stratum=%i (WARNING)", result_line, stratum);
661 } else if (sresult == STATE_CRITICAL) {
662 xasprintf(&result_line, "%s, stratum=%i (CRITICAL)", result_line, stratum);
663 } else {
664 xasprintf(&result_line, "%s, stratum=%i", result_line, stratum);
665 }
642 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum)); 666 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum));
643 } 667 }
644 if (do_truechimers) { 668 if (do_truechimers) {
645 xasprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers); 669 if (tresult == STATE_WARNING) {
670 xasprintf(&result_line, "%s, truechimers=%i (WARNING)", result_line, num_truechimers);
671 } else if (tresult == STATE_CRITICAL) {
672 xasprintf(&result_line, "%s, truechimers=%i (CRITICAL)", result_line, num_truechimers);
673 } else {
674 xasprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers);
675 }
646 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_truechimers(num_truechimers)); 676 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_truechimers(num_truechimers));
647 } 677 }
648 printf("%s|%s\n", result_line, perfdata_line); 678 printf("%s|%s\n", result_line, perfdata_line);
@@ -651,8 +681,6 @@ int main(int argc, char *argv[]){
651 return result; 681 return result;
652} 682}
653 683
654
655
656void print_help(void){ 684void print_help(void){
657 print_revision(progname, NP_VERSION); 685 print_revision(progname, NP_VERSION);
658 686
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c
index 72dffbd..e344f8b 100644
--- a/plugins/check_ntp_time.c
+++ b/plugins/check_ntp_time.c
@@ -48,6 +48,7 @@ static int verbose=0;
48static int quiet=0; 48static int quiet=0;
49static char *owarn="60"; 49static char *owarn="60";
50static char *ocrit="120"; 50static char *ocrit="120";
51static int time_offset=0;
51 52
52int process_arguments (int, char **); 53int process_arguments (int, char **);
53thresholds *offset_thresholds = NULL; 54thresholds *offset_thresholds = NULL;
@@ -400,7 +401,7 @@ double offset_request(const char *host, int *status){
400 gettimeofday(&recv_time, NULL); 401 gettimeofday(&recv_time, NULL);
401 DBG(print_ntp_message(&req[i])); 402 DBG(print_ntp_message(&req[i]));
402 respnum=servers[i].num_responses++; 403 respnum=servers[i].num_responses++;
403 servers[i].offset[respnum]=calc_offset(&req[i], &recv_time); 404 servers[i].offset[respnum]=calc_offset(&req[i], &recv_time)+time_offset;
404 if(verbose) { 405 if(verbose) {
405 printf("offset %.10g\n", servers[i].offset[respnum]); 406 printf("offset %.10g\n", servers[i].offset[respnum]);
406 } 407 }
@@ -455,6 +456,7 @@ int process_arguments(int argc, char **argv){
455 {"use-ipv4", no_argument, 0, '4'}, 456 {"use-ipv4", no_argument, 0, '4'},
456 {"use-ipv6", no_argument, 0, '6'}, 457 {"use-ipv6", no_argument, 0, '6'},
457 {"quiet", no_argument, 0, 'q'}, 458 {"quiet", no_argument, 0, 'q'},
459 {"time-offset", optional_argument, 0, 'o'},
458 {"warning", required_argument, 0, 'w'}, 460 {"warning", required_argument, 0, 'w'},
459 {"critical", required_argument, 0, 'c'}, 461 {"critical", required_argument, 0, 'c'},
460 {"timeout", required_argument, 0, 't'}, 462 {"timeout", required_argument, 0, 't'},
@@ -468,7 +470,7 @@ int process_arguments(int argc, char **argv){
468 usage ("\n"); 470 usage ("\n");
469 471
470 while (1) { 472 while (1) {
471 c = getopt_long (argc, argv, "Vhv46qw:c:t:H:p:", longopts, &option); 473 c = getopt_long (argc, argv, "Vhv46qw:c:t:H:p:o:", longopts, &option);
472 if (c == -1 || c == EOF || c == 1) 474 if (c == -1 || c == EOF || c == 1)
473 break; 475 break;
474 476
@@ -504,6 +506,9 @@ int process_arguments(int argc, char **argv){
504 case 't': 506 case 't':
505 socket_timeout=atoi(optarg); 507 socket_timeout=atoi(optarg);
506 break; 508 break;
509 case 'o':
510 time_offset=atoi(optarg);
511 break;
507 case '4': 512 case '4':
508 address_family = AF_INET; 513 address_family = AF_INET;
509 break; 514 break;
@@ -616,6 +621,8 @@ void print_help(void){
616 printf (" %s\n", _("Offset to result in warning status (seconds)")); 621 printf (" %s\n", _("Offset to result in warning status (seconds)"));
617 printf (" %s\n", "-c, --critical=THRESHOLD"); 622 printf (" %s\n", "-c, --critical=THRESHOLD");
618 printf (" %s\n", _("Offset to result in critical status (seconds)")); 623 printf (" %s\n", _("Offset to result in critical status (seconds)"));
624 printf (" %s\n", "-o, --time_offset=INTEGER");
625 printf (" %s\n", _("Expected offset of the ntp server relative to local server (seconds)"));
619 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 626 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
620 printf (UT_VERBOSE); 627 printf (UT_VERBOSE);
621 628
@@ -628,6 +635,8 @@ void print_help(void){
628 printf("%s\n", _("Notes:")); 635 printf("%s\n", _("Notes:"));
629 printf(" %s\n", _("If you'd rather want to monitor an NTP server, please use")); 636 printf(" %s\n", _("If you'd rather want to monitor an NTP server, please use"));
630 printf(" %s\n", _("check_ntp_peer.")); 637 printf(" %s\n", _("check_ntp_peer."));
638 printf(" %s\n", _("--time-offset is usefull for compensating for servers with known"));
639 printf(" %s\n", _("and expected clock skew."));
631 printf("\n"); 640 printf("\n");
632 printf(UT_THRESHOLDS_NOTES); 641 printf(UT_THRESHOLDS_NOTES);
633 642
@@ -642,6 +651,6 @@ void
642print_usage(void) 651print_usage(void)
643{ 652{
644 printf ("%s\n", _("Usage:")); 653 printf ("%s\n", _("Usage:"));
645 printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose]\n", progname); 654 printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose] [-o <time offset>]\n", progname);
646} 655}
647 656
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 0044046..83f8942 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -167,11 +167,12 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
167 char port_str[6], host[MAX_HOST_ADDRESS_LENGTH]; 167 char port_str[6], host[MAX_HOST_ADDRESS_LENGTH];
168 size_t len; 168 size_t len;
169 int socktype, result; 169 int socktype, result;
170 short is_socket = (host_name[0] == '/');
170 171
171 socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM; 172 socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
172 173
173 /* as long as it doesn't start with a '/', it's assumed a host or ip */ 174 /* as long as it doesn't start with a '/', it's assumed a host or ip */
174 if(host_name[0] != '/'){ 175 if (!is_socket){
175 memset (&hints, 0, sizeof (hints)); 176 memset (&hints, 0, sizeof (hints));
176 hints.ai_family = address_family; 177 hints.ai_family = address_family;
177 hints.ai_protocol = proto; 178 hints.ai_protocol = proto;
@@ -253,7 +254,11 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
253 return econn_refuse_state; 254 return econn_refuse_state;
254 break; 255 break;
255 case STATE_CRITICAL: /* user did not set econn_refuse_state */ 256 case STATE_CRITICAL: /* user did not set econn_refuse_state */
256 printf ("%s\n", strerror(errno)); 257 if (is_socket)
258 printf("connect to file socket %s: %s\n", host_name, strerror(errno));
259 else
260 printf("connect to address %s and port %d: %s\n",
261 host_name, port, strerror(errno));
257 return econn_refuse_state; 262 return econn_refuse_state;
258 break; 263 break;
259 default: /* it's a logic error if we do not end up in STATE_(OK|WARNING|CRITICAL) */ 264 default: /* it's a logic error if we do not end up in STATE_(OK|WARNING|CRITICAL) */
@@ -262,7 +267,11 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
262 } 267 }
263 } 268 }
264 else { 269 else {
265 printf ("%s\n", strerror(errno)); 270 if (is_socket)
271 printf("connect to file socket %s: %s\n", host_name, strerror(errno));
272 else
273 printf("connect to address %s and port %d: %s\n",
274 host_name, port, strerror(errno));
266 return STATE_CRITICAL; 275 return STATE_CRITICAL;
267 } 276 }
268} 277}
diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index 687bffb..d0ae474 100644
--- a/plugins/sslutils.c
+++ b/plugins/sslutils.c
@@ -153,7 +153,8 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
153 struct tm stamp; 153 struct tm stamp;
154 float time_left; 154 float time_left;
155 int days_left; 155 int days_left;
156 char timestamp[17] = ""; 156 char timestamp[50] = "";
157 time_t tm_t;
157 158
158 certificate=SSL_get_peer_certificate(s); 159 certificate=SSL_get_peer_certificate(s);
159 if (!certificate) { 160 if (!certificate) {
@@ -211,10 +212,8 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
211 212
212 time_left = difftime(timegm(&stamp), time(NULL)); 213 time_left = difftime(timegm(&stamp), time(NULL));
213 days_left = time_left / 86400; 214 days_left = time_left / 86400;
214 snprintf 215 tm_t = mktime (&stamp);
215 (timestamp, 17, "%02d/%02d/%04d %02d:%02d", 216 strftime(timestamp, 50, "%c", localtime(&tm_t));
216 stamp.tm_mon + 1,
217 stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
218 217
219 if (days_left > 0 && days_left <= days_till_exp_warn) { 218 if (days_left > 0 && days_left <= days_till_exp_warn) {
220 printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp); 219 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 c1007de..4ebfb90 100644
--- a/plugins/t/NPTest.cache.travis
+++ b/plugins/t/NPTest.cache.travis
@@ -14,6 +14,8 @@
14 'NP_HOST_SNMP' => '', 14 'NP_HOST_SNMP' => '',
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',
18 'NP_HOST_HPJD_PORT_VALID' => '',
17 'NP_HOST_TCP_HTTP' => 'localhost', 19 'NP_HOST_TCP_HTTP' => 'localhost',
18 'NP_HOST_TCP_HTTP2' => 'labs.consol.de', 20 'NP_HOST_TCP_HTTP2' => 'labs.consol.de',
19 'NP_HOST_TCP_IMAP' => 'imap.web.de', 21 'NP_HOST_TCP_IMAP' => 'imap.web.de',
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index 4ff553f..035e768 100644
--- a/plugins/t/check_dns.t
+++ b/plugins/t/check_dns.t
@@ -10,7 +10,7 @@ use NPTest;
10 10
11plan skip_all => "check_dns not compiled" unless (-x "check_dns"); 11plan skip_all => "check_dns not compiled" unless (-x "check_dns");
12 12
13plan tests => 14; 13plan tests => 16;
14 14
15my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/'; 15my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
16 16
@@ -43,6 +43,12 @@ my $dns_server = getTestParameter(
43 "A non default (remote) DNS server", 43 "A non default (remote) DNS server",
44 ); 44 );
45 45
46my $host_nonresponsive = getTestParameter(
47 "NP_HOST_NONRESPONSIVE",
48 "The hostname of system not responsive to network requests",
49 "10.0.0.1",
50 );
51
46my $res; 52my $res;
47 53
48$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5"); 54$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
@@ -54,7 +60,7 @@ cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
54 60
55$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5"); 61$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5");
56cmp_ok( $res->return_code, '==', 1, "Warning threshold passed"); 62cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
57like( $res->output, "/\|time=[\d\.]+s;0.0*;5\.0*;0\.0*/", "Output performance data OK" ); 63like( $res->output, '/\|time=[\d\.]+s;0.0*;5\.0*;0\.0*/', "Output performance data OK" );
58 64
59$res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1"); 65$res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
60cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid"); 66cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
@@ -66,6 +72,10 @@ like ( $res->output, $successOutput, "Output OK" );
66$res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1"); 72$res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
67cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server"); 73cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
68 74
75$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -s $host_nonresponsive -t 2");
76cmp_ok( $res->return_code, '==', 2, "Got no answer from unresponsive server");
77like ( $res->output, "/CRITICAL - /", "Output OK");
78
69$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5"); 79$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
70cmp_ok( $res->return_code, '==', 0, "Got expected address"); 80cmp_ok( $res->return_code, '==', 0, "Got expected address");
71 81
diff --git a/plugins/t/check_hpjd.t b/plugins/t/check_hpjd.t
index 10ded54..4d64852 100644
--- a/plugins/t/check_hpjd.t
+++ b/plugins/t/check_hpjd.t
@@ -10,7 +10,6 @@ use NPTest;
10 10
11plan skip_all => "check_hpjd not compiled" unless (-x "check_hpjd"); 11plan skip_all => "check_hpjd not compiled" unless (-x "check_hpjd");
12 12
13plan tests => 5;
14 13
15my $successOutput = '/^Printer ok - /'; 14my $successOutput = '/^Printer ok - /';
16my $failureOutput = '/Timeout: No [Rr]esponse from /'; 15my $failureOutput = '/Timeout: No [Rr]esponse from /';
@@ -20,31 +19,53 @@ my $host_tcp_hpjd = getTestParameter(
20 "A host (usually a printer) providing the HP-JetDirect Services" 19 "A host (usually a printer) providing the HP-JetDirect Services"
21 ); 20 );
22 21
22my $host_hpjd_port_invalid = getTestParameter(
23 "NP_HOST_HPJD_PORT_INVALID",
24 "A port that HP-JetDirect Services is not listening on",
25 "162"
26 );
27
28my $host_hpjd_port_valid = getTestParameter(
29 "NP_HOST_HPJD_PORT_VALID",
30 "The port that HP-JetDirect Services is currently listening on",
31 "161"
32 );
33
23my $host_nonresponsive = getTestParameter( 34my $host_nonresponsive = getTestParameter(
24 "NP_HOST_NONRESPONSIVE", 35 "NP_HOST_NONRESPONSIVE",
25 "The hostname of system not responsive to network requests", 36 "The hostname of system not responsive to network requests",
26 "10.0.0.1", 37 "10.0.0.1"
27 ); 38 );
28 39
29my $hostname_invalid = getTestParameter( 40my $hostname_invalid = getTestParameter(
30 "NP_HOSTNAME_INVALID", 41 "NP_HOSTNAME_INVALID",
31 "An invalid (not known to DNS) hostname", 42 "An invalid (not known to DNS) hostname",
32 "nosuchhost", 43 "nosuchhost"
33 ); 44 );
34 45
46my $tests = $host_tcp_hpjd ? 9 : 5;
47plan tests => $tests;
35my $res; 48my $res;
36 49
37SKIP: { 50SKIP: {
38 skip "No HP JetDirect defined", 2 unless $host_tcp_hpjd; 51 skip "No HP JetDirect defined", 2 unless $host_tcp_hpjd;
39 $res = NPTest->testCmd("./check_hpjd $host_tcp_hpjd"); 52 $res = NPTest->testCmd("./check_hpjd -H $host_tcp_hpjd");
40 cmp_ok( $res->return_code, '==', 0, "Jetdirect responding" ); 53 cmp_ok( $res->return_code, 'eq', 0, "Jetdirect responding" );
41 like ( $res->output, $successOutput, "Output correct" ); 54 like ( $res->output, $successOutput, "Output correct" );
55
56 $res = NPTest->testCmd("./check_hpjd -H $host_tcp_hpjd -p $host_hpjd_port_valid");
57 cmp_ok( $res->return_code, 'eq', 0, "Jetdirect responding on port $host_hpjd_port_valid" );
58 like ( $res->output, $successOutput, "Output correct" );
59
60 $res = NPTest->testCmd("./check_hpjd -H $host_tcp_hpjd -p $host_hpjd_port_invalid");
61 cmp_ok( $res->return_code, 'eq', 2, "Jetdirect not responding on port $host_hpjd_port_invalid" );
62 like ( $res->output, $failureOutput, "Output correct" );
42} 63}
43 64
44$res = NPTest->testCmd("./check_hpjd $host_nonresponsive"); 65$res = NPTest->testCmd("./check_hpjd -H $host_nonresponsive");
45cmp_ok( $res->return_code, 'eq', 2, "Host not responding"); 66cmp_ok( $res->return_code, 'eq', 2, "Host not responding");
46like ( $res->output, $failureOutput, "Output OK" ); 67like ( $res->output, $failureOutput, "Output OK" );
47 68
48$res = NPTest->testCmd("./check_hpjd $hostname_invalid"); 69$res = NPTest->testCmd("./check_hpjd -H $hostname_invalid");
49cmp_ok( $res->return_code, 'eq', 3, "Hostname invalid"); 70cmp_ok( $res->return_code, 'eq', 3, "Hostname invalid");
50 71
diff --git a/plugins/t/check_ntp.t b/plugins/t/check_ntp.t
index 74d890f..b8fc8fd 100644
--- a/plugins/t/check_ntp.t
+++ b/plugins/t/check_ntp.t
@@ -35,8 +35,8 @@ my $ntp_okmatch1 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/'
35my $ntp_warnmatch1 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/'; 35my $ntp_warnmatch1 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
36my $ntp_critmatch1 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/'; 36my $ntp_critmatch1 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
37my $ntp_okmatch2 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2},\struechimers=[0-9]+/'; 37my $ntp_okmatch2 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2},\struechimers=[0-9]+/';
38my $ntp_warnmatch2 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2},\struechimers=[0-9]+/'; 38my $ntp_warnmatch2 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2}\s\(WARNING\),\struechimers=[0-9]+/';
39my $ntp_critmatch2 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2},\struechimers=[0-9]+/'; 39my $ntp_critmatch2 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+\s\(CRITICAL\),\sstratum=[0-9]{1,2},\struechimers=[0-9]+/';
40my $ntp_noresponse = '/^(CRITICAL - Socket timeout after 3 seconds)|(NTP CRITICAL: No response from NTP server)$/'; 40my $ntp_noresponse = '/^(CRITICAL - Socket timeout after 3 seconds)|(NTP CRITICAL: No response from NTP server)$/';
41my $ntp_nosuchhost = '/^check_ntp.*: Invalid hostname/address - ' . $hostname_invalid . '/'; 41my $ntp_nosuchhost = '/^check_ntp.*: Invalid hostname/address - ' . $hostname_invalid . '/';
42 42
diff --git a/plugins/t/negate.t b/plugins/t/negate.t
index f18acc3..d96a109 100644
--- a/plugins/t/negate.t
+++ b/plugins/t/negate.t
@@ -6,6 +6,7 @@
6 6
7use strict; 7use strict;
8use Test::More; 8use Test::More;
9use Cwd;
9use NPTest; 10use NPTest;
10 11
11# 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops 12# 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops
@@ -13,7 +14,7 @@ plan tests => 88;
13 14
14my $res; 15my $res;
15 16
16my $PWD = $ENV{PWD}; 17my $PWD = getcwd();
17 18
18$res = NPTest->testCmd( "./negate" ); 19$res = NPTest->testCmd( "./negate" );
19is( $res->return_code, 3, "Not enough parameters"); 20is( $res->return_code, 3, "Not enough parameters");
@@ -50,7 +51,7 @@ is( $res->output, "OK: a dummy okay", "The quoted string is passed through to su
50$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" ); 51$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" );
51is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')"); 52is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')");
52 53
53$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' ); 54$res = NPTest->testCmd( './negate '.$PWD.'/check_dummy 0 \'$$ a dummy okay\'' );
54is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' ); 55is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' );
55 56
56my %state = ( 57my %state = (
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 225b449..d93a0ec 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -186,21 +186,21 @@ SKIP: {
186 186
187 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); 187 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
188 is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); 188 is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
189 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on 03/03/2019 21:41.', "output ok" ); 189 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:00 2019.', "output ok" );
190 190
191 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); 191 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" );
192 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); 192 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\) \(03/03/2019 21:41\)./', "output ok" ); 193 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:00 2019\)./', "output ok" );
194 194
195 # Expired cert tests 195 # Expired cert tests
196 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); 196 $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" ); 197 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\) \(03/03/2019 21:41\)./', "output ok" ); 198 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:00 2019\)./', "output ok" );
199 199
200 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); 200 $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" ); 201 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
202 is( $result->output, 202 is( $result->output,
203 'CRITICAL - Certificate \'Ton Voon\' expired on 03/05/2009 00:13.', 203 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:00 2009.',
204 "output ok" ); 204 "output ok" );
205 205
206} 206}
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
index aace9bc..2fd033d 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -20,7 +20,16 @@ if ($@) {
20 plan skip_all => "Missing required module for test: $@"; 20 plan skip_all => "Missing required module for test: $@";
21} else { 21} else {
22 if (-x "./check_snmp") { 22 if (-x "./check_snmp") {
23 plan tests => $tests; 23 # check if snmpd has perl support
24 my $test = `snmpd -c tests/conf/snmpd.conf -C -r -H 2>&1`;
25 if(!defined $test) {
26 plan skip_all => "snmpd required";
27 }
28 elsif($test =~ m/Warning: Unknown token: perl/) {
29 plan skip_all => "snmpd has no perl support";
30 } else {
31 plan tests => $tests;
32 }
24 } else { 33 } else {
25 plan skip_all => "No check_snmp compiled"; 34 plan skip_all => "No check_snmp compiled";
26 } 35 }