Incorrect date format in status.dat will now be recognized instead of being 'ok'
authorKatharina Sommer <sommer@schlittermann.de>
Fri, 31 May 2013 14:15:48 +0200
changeset 5 9041108a535b
parent 4 14408207746e
child 6 4a2bbd6f9f04
Incorrect date format in status.dat will now be recognized instead of being 'ok'
check_client_cert.pl
debian/changelog
debian/control
debian/files
--- a/check_client_cert.pl	Mon Feb 21 15:14:42 2011 +0100
+++ b/check_client_cert.pl	Fri May 31 14:15:48 2013 +0200
@@ -41,7 +41,7 @@
 sub version($$);
 
 my %opt = (
-    file     => "/root/CLIENT-CERTS/status.dat",
+    file     => "status.dat",
     warning  => "1month",
     critical => "1week"
 );
@@ -67,7 +67,6 @@
     my %certs  = ();
     my $w_time = DateCalc( "today", "+ $opt{warning}" );
     my $c_time = DateCalc( "today", "+ $opt{critical}" );
-    my $rc     = 0;
 
     open( FILE, $file )
       or do {
@@ -76,24 +75,31 @@
       };
 
     while (<FILE>) {
+
         next if /^#/;
         next if /^\s+$/;
+
         my ( $client, $date ) = split( /;/, $_ );
-        my $pdate = ParseDate($date);
+
         chomp($date);
-        &Date_Cmp( $pdate, $w_time ) < 0 and $rc = 1;
-        &Date_Cmp( $pdate, $c_time ) < 0 and $rc = 2;
-        if ( $rc == 0 ) {
-            push( @{ $certs{$client} }, $date, "OK" );
+        my $pdate = ParseDate($date);
+
+	if (!$pdate) {
+	    push( @{$certs{$client} }, $date, "WRONG" );
+	    next;
+	}
+
+        if ( Date_Cmp($pdate, $c_time) <= 0) {
+            push( @{ $certs{$client} }, $date, "CRITICAL" );
+	    next;
         }
-        elsif ( $rc == 1 ) {
+
+        if ( Date_Cmp($pdate, $w_time) <= 0) {
             push( @{ $certs{$client} }, $date, "WARNING" );
-            $rc = 0;
+	    next;
         }
-        else {
-            push( @{ $certs{$client} }, $date, "CRITICAL" );
-            $rc = 0;
-        }
+
+        push( @{ $certs{$client} }, $date, "OK" );
     }
     close(FILE);
 
@@ -104,7 +110,7 @@
 
 sub report($) {
     my $certs = shift;
-    my ( @ok, @warning, @critical ) = ();
+    my ( @ok, @warning, @critical, @wrong ) = ();
 
     foreach ( sort keys %$certs ) {
         if ( $certs->{$_}[1] eq "WARNING" ) {
@@ -113,16 +119,24 @@
         elsif ( $certs->{$_}[1] eq "CRITICAL" ) {
             push( @critical, "$_ client certificate expires $certs->{$_}[0]" );
         }
+        elsif ( $certs->{$_}[1] eq "WRONG" ) {
+            push( @wrong, "$_ has a broken date in status.dat, please check:  $certs->{$_}[0]" );
+        }
         else {
             push( @ok, "$_ client certificate expires $certs->{$_}[0]" );
         }
     }
 
     ### @critical
+    ### @wrong
     ### @warning
     ### @ok
 
-    if (@critical) {
+    if (@wrong) {
+        print "WRONG DATE FORMAT: " . join( " ", @wrong );
+        exit $ERRORS{"CRITICAL"};
+    }
+    elsif (@critical) {
         print "CERT CRITICAL: " . join( " ", @critical );
         exit $ERRORS{"CRITICAL"};
     }
--- a/debian/changelog	Mon Feb 21 15:14:42 2011 +0100
+++ b/debian/changelog	Fri May 31 14:15:48 2013 +0200
@@ -1,3 +1,10 @@
+nagios-plugin-check-client-cert (0.1.3+nmu1) oldstable stable; urgency=low
+
+  * Non-maintainer upload.
+  * Incorrect date format in status.dat will now be recognized instead of being 'ok'
+
+ -- Katharina Sommer <sommer@schlittermann.de>  Thu, 30 May 2013 14:04:34 +0200
+
 nagios-plugin-check-client-cert (0.1.2) stable; urgency=low
 
   * 
--- a/debian/control	Mon Feb 21 15:14:42 2011 +0100
+++ b/debian/control	Fri May 31 14:15:48 2013 +0200
@@ -2,7 +2,7 @@
 Section: net
 Priority: extra
 Maintainer: Christian Arnold <arnold@schlittermann.de>
-Build-Depends: debhelper (>= 7)
+Build-Depends: debhelper (>= 7), libdate-manip-perl
 Standards-Version: 3.7.3
 
 Package: nagios-plugin-check-client-cert
--- a/debian/files	Mon Feb 21 15:14:42 2011 +0100
+++ b/debian/files	Fri May 31 14:15:48 2013 +0200
@@ -1,1 +1,1 @@
-nagios-plugin-check-client-cert_0.1.2_all.deb net extra
+nagios-plugin-check-client-cert_0.1.3+nmu1_all.deb net extra