Skip to content

Instantly share code, notes, and snippets.

@djmitche
Created December 1, 2008 15:35
Show Gist options
  • Save djmitche/30754 to your computer and use it in GitHub Desktop.
Save djmitche/30754 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
# NRPE Script to report amanda backup errors found in the trace logs.
#
# Example Usage: perl check_amanda.pl PoolA
use strict;
use warnings;
use lib "@amperldir";
use Amanda::Config qw( :init :getconf config_dir_relative )
use Amanda::DB::Catalog;
use Amanda::Logfile qw( :logtype_t );
use File::Glob qw( :glob );
my $config_name = $ARGV[0] || die("usage: perl check_amanda.pl <Amanda-config> \n");
my %NAGIOS_API_ECODES = ( 'OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3 );
my $_intDegCount = 0;
config_init($CONFIG_INIT_EXPLICIT_NAME, $config_name);
my ($cfgerr_level, @cfgerr_errors) = config_errors();
if ($cfgerr_level >= $CFGERR_ERRORS) {
print "errors processing config file";
exit $NAGIOS_API_ECODES{CRITICAL};
}
my $logdir = config_dir_relative(getconf($CNF_LOGDIR));
my $latest = Amanda::DB::Catalog::get_latest_write_timestamp();
# get all logfiles matching this timestamp (for a multi-tape run)
my @logfiles = bsd_glob("$logdir/log.$latest*");
if (GLOB_ERROR != 0) {
print "errors processing trace logs: $!";
exit $NAGIOS_API_ECODES{CRITICAL};
}
my @errors;
for my $logfile (@logfiles) {
my $hdl = Amanda::Logfile::open_logfile($logfile);
while (my ($type, $prog, $str) = Amanda::Logfile::get_logline($hdl)) {
next unless ($type == $L_FATAL || $type == $L_FAIL || $type == $L_ERROR);
push @errors, $str;
}
}
if (@errors) {
print "Backup $config_name: ", join(" - ", @errors), "\n";
exit $NAGIOS_API_ECODES{CRITICAL};
} else {
print "Backup $config_name: All machines backed up.\n";
exit $NAGIOS_API_ECODES{OK};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment