From b71e036a6df95446cd501232f02ef42b61b2569d Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 6 Dec 2010 14:42:10 +0100 Subject: [PATCH] dsa-check-udldap-freshness: Also check age of /var/lib/misc/passwd.db in addition to /var/lib/misc/thishost/passwd.tdb. --- .../checks/dsa-check-udldap-freshness | 58 ++++++++++--------- dsa-nagios-checks/debian/changelog | 4 +- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/dsa-nagios-checks/checks/dsa-check-udldap-freshness b/dsa-nagios-checks/checks/dsa-check-udldap-freshness index be2a6da..6022746 100755 --- a/dsa-nagios-checks/checks/dsa-check-udldap-freshness +++ b/dsa-nagios-checks/checks/dsa-check-udldap-freshness @@ -16,35 +16,39 @@ $SIG{__DIE__ } = sub() { exit $CODE{'UNKNOWN'}; }; -if ( -e "/var/lib/misc/thishost/passwd.tdb" ) { - $f = "/var/lib/misc/thishost/passwd.tdb"; -} else { - my $hostname = `hostname -f`; - chomp $hostname; - $hostname =~ m/^([a-z]+(?:\.[a-z]+)+)$/; - die "Weird hostname '$hostname'\n" unless defined $1; - $hostname = $1; - if ( -e "/var/lib/misc/$hostname/passwd.tdb" ) { - $f = "/var/lib/misc/$hostname/passwd.tdb"; +sub check_age { + my ($f) = @_; + my @stat = stat($f) or die ("Cannot stat $f: $!\n"); + my $age = time - $stat[10]; + my $hage; + if ($age > 48 * 3600) { + $hage = sprintf("%.1f days", $age / 24 / 3600); + } elsif ($age > 3600) { + $hage = sprintf("%.1f hours", $age / 3600); + } else { + $hage = sprintf("%d minutes", $age / 60); }; -}; -die "Could not find passwd.tdb" unless defined $f; - -my @stat = stat($f) or die ("Cannot stat $f: $!\n"); -my $age = time - $stat[10]; -my $hage; -if ($age > 48 * 3600) { - $hage = sprintf("%.1f days", $age / 24 / 3600); -} elsif ($age > 3600) { - $hage = sprintf("%.1f hours", $age / 3600); -} else { - $hage = sprintf("%d minutes", $age / 60); + if ($age > 60*60) { + return [$CODE{'WARNING'}, "WARNING: ud-ldap info is $hage old"]; + }; + return [$CODE{'OK'}, "ud-ldap info is $hage old"]; }; -if ($age > 60*60) { - print "WARNING: ud-ldap info is $hage old\n"; - exit $CODE{'WARNING'}; +my @msg; +for $f (qw{/var/lib/misc/thishost/passwd.tdb /var/lib/misc/passwd.db}) { + unless (-e $f) { + print "WARNING: $f does not exist.\n"; + exit $CODE{'WARNING'}; + }; + + my $a = check_age($f); + if ($a->[0] != 0) { + print $a->[1], "\n"; + exit $a->[0]; + }; + push @msg, $a->[1]; }; -print "OK: ud-ldap info is $hage old\n"; -exit $CODE{'OK'}; + +print "OK: ", join(', ', @msg), "\n"; +exit 0; diff --git a/dsa-nagios-checks/debian/changelog b/dsa-nagios-checks/debian/changelog index 08bc29b..0559f57 100644 --- a/dsa-nagios-checks/debian/changelog +++ b/dsa-nagios-checks/debian/changelog @@ -14,8 +14,10 @@ dsa-nagios-checks (8x) xnstable; urgency=low * dsa-check-hpacucli: accept 6.0Gbps for SAS disks. * dsa-check-hpasm: Incorporate patch from Jan Wagner to ignore "N/A" DIMM status. + * dsa-check-udldap-freshness: Also check age of /var/lib/misc/passwd.db + in addition to /var/lib/misc/thishost/passwd.tdb. - -- Peter Palfrader Mon, 22 Nov 2010 13:56:04 +0100 + -- Peter Palfrader Mon, 06 Dec 2010 14:41:38 +0100 dsa-nagios-checks (87) unstable; urgency=low -- 2.20.1