# HG changeset patch # User Katharina Sommer # Date 1370002548 -7200 # Node ID 9041108a535b546bf7d90a098fb9f2da6717accb # Parent 14408207746e73120edd019fadca1585601e5907 Incorrect date format in status.dat will now be recognized instead of being 'ok' diff -r 14408207746e -r 9041108a535b check_client_cert.pl --- 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 () { + 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"}; } diff -r 14408207746e -r 9041108a535b debian/changelog --- 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 Thu, 30 May 2013 14:04:34 +0200 + nagios-plugin-check-client-cert (0.1.2) stable; urgency=low * diff -r 14408207746e -r 9041108a535b debian/control --- 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 -Build-Depends: debhelper (>= 7) +Build-Depends: debhelper (>= 7), libdate-manip-perl Standards-Version: 3.7.3 Package: nagios-plugin-check-client-cert diff -r 14408207746e -r 9041108a535b debian/files --- 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