Ram Smith wrote:
As a summary, write nagios plugins to:
- report success/failure on the correct tape in the drive (hourly)
This one isn't mine, I found it on some site somewhere:
#!/usr/bin/python
# check_amanda - plugin for nagios to check the status of an amanda
# configuration
import os
import tempfile
import sys
import getopt
version = '0.2'
nagiosStateOk = 0
nagiosStateWarning = 1
nagiosStateCritical = 2
nagiosStateUnknown = 3
verbosity = 0
configuration = "DailySet1"
def printUsage():
print 'Usage: check_amanda [-c <configuration-name>]'
def printHelp():
printUsage()
print ''
print 'Options:'
print '-c, --configuration=configuration-name'
print ' Name of configuration to use (default: DailySet1)'
sys.exit(nagiosStateUnknown)
try:
optlist, args = getopt.getopt(sys.argv[1:], 'Vhc:v?',
['version', 'help', 'configuration='])
except getopt.GetoptError, errorStr:
print errorStr
printUsage()
sys.exit(nagiosStateUnknown)
if len(args) != 0:
printUsage()
sys.exit(nagiosStateUnknown)
for opt, arg in optlist:
if opt in ('-V', '--version'):
print 'check_amanda %s' % (version)
sys.exit(nagiosStateUnknown)
elif opt in ('-c', '--configuration'):
configuration = arg
elif opt in ('-v', '--verbose'):
# Plugin guidelines require this, but we don't have anything
extra to
# report
verbosity = int(arg or 0)
elif opt == '-?':
printUsage()
sys.exit(nagiosStateUnknown)
# Run amcheck
handle, logname = tempfile.mkstemp()
result = os.system("sudo -u amanda /usr/sbin/amcheck %s > %s 2> %s" %
(configuration, logname, logname))
if result:
logfile = file(logname)
data = logfile.readlines()
error = None
warning = None
for line in data:
if line.startswith("ERROR"):
error = line
break
if line.startswith("WARNING"):
warning = line
break
logfile.close()
if error is None:
error = "ERROR: unidentified error in amcheck output, see %s" % \
logname
else:
# Only remove logfile if error is identified.
os.unlink(logname)
print error
sys.exit(nagiosStateCritical)
else:
print 'Amanda backup for "%s" is ok.' % (configuration)
sys.exit(nagiosStateOk)
>
- report on the success/failure of dumps for each item in the disklist.
(daily)
#!/usr/bin/perl
my $dumpsummaryreached = 0;
my $startparsing = 0;
my $NumFilesystemsSuccess = 0;
my $NumFilesystemsFailed = 0;
my $IsBackupReport = 0;
while (<>) {
if($_ =~ /AMANDA MAIL REPORT/)
{
$IsBackupReport = 1;
}
if($IsBackupReport == 1)
{
if($_ =~ /^\(brought to you by Amanda version 2.4.4p3\)/)
{
$startparsing = 0;
$dumpsummaryreached = 0;
break;
}
if($startparsing == 1 && $dumpsummaryreached == 1 &&
not $_ =~ /^\s*$/)
{
if($_ =~ /MISSING/ || $_ =~ /FAILED/)
{
$NumFilesystemsFailed++;
}
else
{
$NumFilesystemsSuccess++;
}
}
if($_ =~ /^DUMP SUMMARY/)
{
$dumpsummaryreached = 1;
}
if($dumpsummaryreached == 1 && $_ =~
/^--------------------------/)
{
$startparsing = 1;
}
}
}
if($IsBackupReport == 1)
{
`echo "$NumFilesystemsFailed filsystems(s) failed,
$NumFilesystemsSuccess filesystem(s) successful" | cat >
/tmp/amandabackupstatus`;
}
I then use the check_file plugin from here:
http://www.openfusion.com.au/labs/nagios/ to check the contents of
/tmp/amandabackupstatus in the nagios check command.
--
Tim Edwards
|