X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=dsa-nagios-checks%2Fchecks%2Fdsa-check-udldap-freshness;h=9d85424274e0064b5586dadb7b5ba52a9d4ca74e;hb=318f0c66b33cb7472c817f6cc81a19c1804fdbd9;hp=be2a6daef3748e20f12fb42eb5fac242f2bec22c;hpb=42e99da9d896a33803e763c746e9a103183b6b34;p=mirror%2Fdsa-nagios.git diff --git a/dsa-nagios-checks/checks/dsa-check-udldap-freshness b/dsa-nagios-checks/checks/dsa-check-udldap-freshness index be2a6da..9d85424 100755 --- a/dsa-nagios-checks/checks/dsa-check-udldap-freshness +++ b/dsa-nagios-checks/checks/dsa-check-udldap-freshness @@ -16,35 +16,49 @@ $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); + }; + + if ($age > 60*60) { + return [$CODE{'WARNING'}, "WARNING: ud-ldap info is $hage old"]; }; + return [$CODE{'OK'}, "ud-ldap info is $hage old"]; }; -die "Could not find passwd.tdb" unless defined $f; +my @msg; +my @to_check = (); -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); +if (-f '/var/lib/misc/thishost/last_update.trace') { + # New style check + push @to_check, '/var/lib/misc/thishost/last_update.trace'; } else { - $hage = sprintf("%d minutes", $age / 60); -}; + # Old style + push @to_check, qw{/var/lib/misc/thishost/passwd.tdb /var/lib/misc/passwd.db}; +} -if ($age > 60*60) { - print "WARNING: ud-ldap info is $hage old\n"; - exit $CODE{'WARNING'}; +for $f (@to_check) { + 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;