projects
/
mirror
/
dsa-nagios.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[project @ peter@palfrader.org-20080424195804-xh6bwo5xec2w4ada]
[mirror/dsa-nagios.git]
/
dsa-nagios-nrpe-config
/
dsa-check-dabackup
diff --git
a/dsa-nagios-nrpe-config/dsa-check-dabackup
b/dsa-nagios-nrpe-config/dsa-check-dabackup
index
d00dcf2
..
f400023
100755
(executable)
--- a/
dsa-nagios-nrpe-config/dsa-check-dabackup
+++ b/
dsa-nagios-nrpe-config/dsa-check-dabackup
@@
-30,7
+30,8
@@
use Getopt::Long;
use Fcntl qw(:seek);
my $DABACKUP_CONF = '/etc/da-backup.conf';
use Fcntl qw(:seek);
my $DABACKUP_CONF = '/etc/da-backup.conf';
-my $MAX_AGE = 24*60*60;
+my $MAX_AGE = 30*60*60;
+my $TOO_FRESH = 5*60;
my %CODE = (
'UNDEF' => -1,
'OK' => 0,
my %CODE = (
'UNDEF' => -1,
'OK' => 0,
@@
-45,11
+46,12
@@
$SIG{__DIE__ } = sub() {
my $EXITCODE = 'UNDEF';
my $EXITCODE = 'UNDEF';
-my
@
MESSAGE = ();
+my
%
MESSAGE = ();
-sub problem($$) {
- my ($code, $msg) = @_;
- push @MESSAGE, $msg;
+sub problem($$$) {
+ my ($code, $msg, $resource) = @_;
+ $MESSAGE{$msg} = [] unless defined $MESSAGE{$msg};
+ push @{$MESSAGE{$msg}}, $resource;
$EXITCODE = ($CODE{$code} > $CODE{$EXITCODE}) ? $code : $EXITCODE;
};
$EXITCODE = ($CODE{$code} > $CODE{$EXITCODE}) ? $code : $EXITCODE;
};
@@
-84,7
+86,7
@@
unless (-e $DABACKUP_CONF) {
print "WARNING: No $DABACKUP_CONF, but we have /var/log/da-backup/\n";
exit $CODE{'WARNING'};
};
print "WARNING: No $DABACKUP_CONF, but we have /var/log/da-backup/\n";
exit $CODE{'WARNING'};
};
- print "OK:
no backup configur
ed\n";
+ print "OK:
da-backup not install
ed\n";
exit $CODE{'OK'};
};
exit $CODE{'OK'};
};
@@
-104,31
+106,44
@@
die ("No confdir found in $DABACKUP_CONF") unless defined $confdir;
die ("No logdir found in $DABACKUP_CONF") unless defined $logdir;
opendir(DIR, $confdir) or die ("Cannot opendir $confdir: $!\n");
die ("No logdir found in $DABACKUP_CONF") unless defined $logdir;
opendir(DIR, $confdir) or die ("Cannot opendir $confdir: $!\n");
-my %conffiles = map {$_ => 1} grep { !/^\./ } readdir(DIR);
+my %conffiles = map {$_ => 1} grep { !/^\./
&& !/\.bak$/
} readdir(DIR);
closedir(DIR);
opendir(DIR, $logdir) or die ("Cannot opendir $logdir: $!\n");
my %logfiles = map {$_ => 1} grep { !/^\./ && !/\.[0-9]+(\.gz)?$/} readdir(DIR);
closedir(DIR);
closedir(DIR);
opendir(DIR, $logdir) or die ("Cannot opendir $logdir: $!\n");
my %logfiles = map {$_ => 1} grep { !/^\./ && !/\.[0-9]+(\.gz)?$/} readdir(DIR);
closedir(DIR);
+if (scalar keys %conffiles == 0) {
+ print "WARNING: da-backup installed but no backups configured\n";
+ exit $CODE{'WARNING'};
+};
+
for my $f (keys %conffiles) {
unless (exists $logfiles{$f}) {
for my $f (keys %conffiles) {
unless (exists $logfiles{$f}) {
- problem('WARNING',
"$f has no log"
);
+ problem('WARNING',
'no log', $f
);
}
}
}
}
-problem('WARNING', 'da-backup installed but no backups configured') if (scalar keys %conffiles == 0);
FILE:
for my $f (sort {$a cmp $b} keys %logfiles) {
unless (exists $conffiles{$f}) {
FILE:
for my $f (sort {$a cmp $b} keys %logfiles) {
unless (exists $conffiles{$f}) {
- problem('WARNING',
"log $f has no config"
);
+ problem('WARNING',
'no config', $f
);
next;
}
my @stat = stat("$logdir/$f") or die ("Cannot stat $logdir/$f: $!\n");
my $age = time - $stat[10];
next;
}
my @stat = stat("$logdir/$f") or die ("Cannot stat $logdir/$f: $!\n");
my $age = time - $stat[10];
+
+ if ($age < $TOO_FRESH) { # File is too new, let's use the old one
+ if (-e "$logdir/$f.0") {
+ $f .= ".0";
+ my @stat = stat("$logdir/$f") or die ("Cannot stat $logdir/$f: $!\n");
+ $age = time - $stat[10];
+ };
+ };
+
if ($age < 0) {
if ($age < 0) {
- problem('WARNING',
"%f is from the future"
);
+ problem('WARNING',
'future timestamp', $f
);
next;
} elsif ($age > $MAX_AGE) {
my $hage;
next;
} elsif ($age > $MAX_AGE) {
my $hage;
@@
-138,7
+153,7
@@
for my $f (sort {$a cmp $b} keys %logfiles) {
} else {
$hage = sprintf("%d hours", $age / 3600);
};
} else {
$hage = sprintf("%d hours", $age / 3600);
};
- problem('WARNING',
"$f is $hage old
");
+ problem('WARNING',
'old', "$f ($hage)
");
next;
};
next;
};
@@
-149,15
+164,16
@@
for my $f (sort {$a cmp $b} keys %logfiles) {
while (<FH>) {
chomp;
if (/^sent\s+\d+\s+bytes\s+received\s+\d+\s+bytes\s+[\d\.]+\s+bytes\/sec$/) {
while (<FH>) {
chomp;
if (/^sent\s+\d+\s+bytes\s+received\s+\d+\s+bytes\s+[\d\.]+\s+bytes\/sec$/) {
- problem('OK',
"$f probably ok"
);
+ problem('OK',
'probably ok', $f
);
close(FH);
next FILE;
};
$last2 = $last;
$last = $_;
};
close(FH);
next FILE;
};
$last2 = $last;
$last = $_;
};
- problem('CRITICAL',
"$f failed
($last2 $last)");
+ problem('CRITICAL',
'FAILED', "$f
($last2 $last)");
};
};
-print $EXITCODE,": ", join("; ", @MESSAGE), "\n";
+my $msg = join("; ", map {"$_: ".join(', ', @{$MESSAGE{$_}}) } (sort {$a cmp $b} keys %MESSAGE));
+print $EXITCODE, ": ", $msg, "\n";
exit $CODE{$EXITCODE};
exit $CODE{$EXITCODE};