Ver código fonte

check_http: added test for warning thresholds

fixed typo in sslutils
Sven Nierlein 13 anos atrás
pai
commit
24242f6ab7
3 arquivos alterados com 11 adições e 3 exclusões
  1. 2 2
      plugins/sslutils.c
  2. 5 1
      plugins/t/check_http.t
  3. 4 0
      plugins/t/check_tcp.t

+ 2 - 2
plugins/sslutils.c

@@ -203,7 +203,7 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
 		 stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
 
 	if (days_left > 0 && days_left <= days_till_exp_warn) {
-		printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"CRITICAL":"WARNING", cn, days_left, timestamp);
+		printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp);
 		if (days_left > days_till_exp_crit)
 			return STATE_WARNING;
 		else
@@ -212,7 +212,7 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
 		printf(_("CRITICAL - Certificate '%s' expired on %s.\n"), cn, timestamp);
 		status=STATE_CRITICAL;
 	} else if (days_left == 0) {
-		printf (_("%s - Certificate '%s' expires today (%s).\n"), (days_left>days_till_exp_crit)?"CRITICAL":"WARNING", cn, timestamp);
+		printf (_("%s - Certificate '%s' expires today (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, timestamp);
 		if (days_left > days_till_exp_crit)
 			return STATE_WARNING;
 		else

+ 5 - 1
plugins/t/check_http.t

@@ -8,7 +8,7 @@ use strict;
 use Test::More;
 use NPTest;
 
-plan tests => 26;
+plan tests => 28;
 
 my $successOutput = '/OK.*HTTP.*second/';
 
@@ -105,6 +105,10 @@ SKIP: {
         like  ( $res->output, "/Certificate 'www.verisign.com' will expire on/", "Output OK" );
         my $saved_cert_output = $res->output;
 
+        $res = NPTest->testCmd( "./check_http -C 8000,1 --ssl www.verisign.com" );
+        cmp_ok( $res->return_code, '==', 1, "Checking certificate for www.verisign.com");
+        like  ( $res->output, qr/WARNING - Certificate 'www.verisign.com' expires in \d+ day/, "Output Warning" );
+
         $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" );
         is( $res->return_code, 0, "Old syntax for cert checking okay" );
         is( $res->output, $saved_cert_output, "Same output as new syntax" );

+ 4 - 0
plugins/t/check_tcp.t

@@ -30,6 +30,10 @@ $t += checkCmd( "./check_tcp $host_tcp_http      -p 80 -wt 300 -ct 600",       0
 $t += checkCmd( "./check_tcp $host_tcp_http      -p 81 -wt   0 -ct   0 -to 1", 2 ); # use invalid port for this test
 $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt   0 -ct   0 -to 1", 2 );
 $t += checkCmd( "./check_tcp $hostname_invalid   -p 80 -wt   0 -ct   0 -to 1", 2 );
+$t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443",              0 );
+$t += checkCmd( "./check_tcp -S -D 9000,1    -H www.verisign.com -p 443",      0 );
+$t += checkCmd( "./check_tcp -S -D 9000      -H www.verisign.com -p 443",      1 );
+$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443",      2 );
 
 # Need the \r\n to make it more standards compliant with web servers. Need the various quotes
 # so that perl doesn't interpret the \r\n and is passed onto command line correctly