Created
December 1, 2008 15:35
-
-
Save djmitche/30754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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