[nagiosplug] check_http: added test for warning thresholds

Nagios Plugin Development nagios-plugins at users.sourceforge.net
Mon Jun 25 13:01:04 CEST 2012


 Module: nagiosplug
 Branch: master
 Commit: 24242f6ab75adb2de617921e79fe6bece4b75612
 Author: Sven Nierlein <sven at nierlein.de>
   Date: Mon Jun 25 12:32:01 2012 +0200
    URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=24242f6

check_http: added test for warning thresholds

fixed typo in sslutils

---

 plugins/sslutils.c     |    4 ++--
 plugins/t/check_http.t |    6 +++++-
 plugins/t/check_tcp.t  |    4 ++++
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index fe31b56..a1ce560 100644
--- a/plugins/sslutils.c
+++ b/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
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 55a5a53..0a25c77 100644
--- a/plugins/t/check_http.t
+++ b/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" );
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t
index fd2b5dd..75c1e5f 100644
--- a/plugins/t/check_tcp.t
+++ b/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





More information about the Commits mailing list