diff options
author | kwadronaut <kwadronaut@leap.se> | 2013-01-31 10:15:44 +0100 |
---|---|---|
committer | kwadronaut <kwadronaut@leap.se> | 2013-01-31 10:15:44 +0100 |
commit | daeb1a1f112a4dbf6b39565f0dea461e46a64681 (patch) | |
tree | c332df612a6f8836b48fa237bd526e37a8108fb2 /files | |
parent | d7345c06a7bb9f1b76ec57496ad99f68c6b0c5f4 (diff) | |
download | puppet-backupninja-daeb1a1f112a4dbf6b39565f0dea461e46a64681.tar.gz puppet-backupninja-daeb1a1f112a4dbf6b39565f0dea461e46a64681.tar.bz2 |
updating nagios scripts
Diffstat (limited to 'files')
-rw-r--r-- | files/nagios_plugins/duplicity/backupninja_duplicity_freshness.sh | 58 | ||||
-rw-r--r-- | files/nagios_plugins/duplicity/check_backupninja_duplicity.py | 47 |
2 files changed, 55 insertions, 50 deletions
diff --git a/files/nagios_plugins/duplicity/backupninja_duplicity_freshness.sh b/files/nagios_plugins/duplicity/backupninja_duplicity_freshness.sh index ea694d0..7af2bf7 100644 --- a/files/nagios_plugins/duplicity/backupninja_duplicity_freshness.sh +++ b/files/nagios_plugins/duplicity/backupninja_duplicity_freshness.sh @@ -1,3 +1,4 @@ +#!/bin/bash # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- # vim: set filetype=sh sw=3 sts=3 expandtab autoindent: @@ -192,34 +193,34 @@ function mangle_cli(){ fi } -function findlastdates(){ - outputfile=$1 - lastfull=0 - lastinc=0 - backuptime=0 - - while read line; do - atime=0 - arr=() - sort='' - test=$(echo $line|awk '{if (NF == 7); if ($1 == "Full" || $1 == "Incremental") {print $4, $3, $6, $5}}' ) - - if [ -n "$test" ]; then - backuptime=$(date -u -d "$test" +%s) - - arr=($(echo $line|awk '{print $1, $2, $3, $4, $5, $6}')) - if [ ${arr[0]} == "Incremental" ] && [ "$lastinc" -lt "$backuptime" ] ; then - lastinc=$backuptime - elif [ ${arr[0]} == "Full" ] && [ "$lastfull" -lt "$backuptime" ] ; then - lastfull=$backuptime - fi - - fi - - done < $outputfile - # a full backup can be seen as incremental too - lastinc=$(echo $lastinc | awk 'max=="" || $1 > max {max=$1} END{ print max}') -} +#function findlastdates(){ +# outputfile=$1 +# lastfull=0 +# lastinc=0 +# backuptime=0 +# +# while read line; do +# atime=0 +# arr=() +# sort='' +# test=$(echo $line|awk '{if (NF == 7); if ($1 == "Full" || $1 == "Incremental") {print $4, $3, $6, $5}}' ) +# +# if [ -n "$test" ]; then +# backuptime=$(date -u -d "$test" +%s) +# +# arr=($(echo $line|awk '{print $1, $2, $3, $4, $5, $6}')) +# if [ ${arr[0]} == "Incremental" ] && [ "$lastinc" -lt "$backuptime" ] ; then +# lastinc=$backuptime +# elif [ ${arr[0]} == "Full" ] && [ "$lastfull" -lt "$backuptime" ] ; then +# lastfull=$backuptime +# fi +# +# fi +# +# done < $outputfile +# # a full backup can be seen as incremental too +# lastinc=$(echo $lastinc | awk 'max=="" || $1 > max {max=$1} END{ print max}') +#} function check_status() { grep -q 'No orphaned or incomplete backup sets found.' $1 @@ -244,7 +245,6 @@ function process_action() { export FTP_PASSWORD=$ftp_password output=` su -c \ "$execstr_precmd duplicity $execstr_options collection-status $execstr_serverpart >$outputfile 2>&1"` - #echo "$execstr_precmd duplicity $execstr_options collection-status $execstr_serverpart" >$outputfile exit_code=$? echo -n $outputfile diff --git a/files/nagios_plugins/duplicity/check_backupninja_duplicity.py b/files/nagios_plugins/duplicity/check_backupninja_duplicity.py index 5deeccb..8ed9ce6 100644 --- a/files/nagios_plugins/duplicity/check_backupninja_duplicity.py +++ b/files/nagios_plugins/duplicity/check_backupninja_duplicity.py @@ -13,27 +13,20 @@ import getopt def main(): # getopt = much more writing - parser = argparse.ArgumentParser(description='Nagios Duplicity status checker') parser.add_argument("-w", dest="warninc", default=28, type=int, - help="Number of hours allowed for incremential backup warning level") - parser.add_argument("-W", dest="warnfull", default=40, type=int, - help="Number of hours allowed for incremential backup critical level") - + help="Number of hours allowed for incremential backup warning level, default 28") + parser.add_argument("-W", dest="warnfull", default=31, type=int, + help="Number of days allowed for full backup warning level, default 31") parser.add_argument("-c", dest="critinc", default=52, type=int, - help="Number of days allowed for full backup warning level") - - parser.add_argument("-C", dest="critfull", default=60, type=int, - help="Number of days allowed for full backup critical level") - + help="Number of hours allowed for incremential backup critical level, default 52") + parser.add_argument("-C", dest="critfull", default=33, type=int, + help="Number of days allowed for full backup critical level, default 33") args = parser.parse_args() okay = 0 - #f = open ('/tmp/tmp.q5Mqui6nVr/backupout.amDtCIcW', 'r') - #output = f.read() - # *sigh* check_output is from python 2.7 and onwards. Debian, upgrade yourself. #output , err = check_output(['/root/freshness.sh']) @@ -45,8 +38,20 @@ def main(): # Don't use exec(), popen(), etc. to execute external commands without explicity using the full path of the external program. Hijacked search path could be problematic. #checkstatus, err = Popen(['/bin/bash', './freshness.sh'], stdout=PIPE, stderr=PIPE, env={'HOME': '/root', 'PATH': os.environ['PATH']}).communicate() - f = open (checkstatus) - output = f.read() + #another sigh: Debian testing, upgrade yourself, this is only needed because Debian testing uses duplicity 0.6.18-3 + # open file read/write + f = open (checkstatus,"r") + checklines = f.readlines() + f.close() + + # remove the line that says Import of duplicity.backends.giobackend Failed: No module named gio + f = open(checkstatus,"w") + for line in checklines: + if not 'Import of duplicity.backends.giobackend Failed: No module named gio' in line: + f.write(line) + f.close() + + output = open(checkstatus).read() lastfull, lastinc = findlastdates(output) @@ -58,26 +63,26 @@ def main(): if sincelastfull > (args.warnfull * 24 * 3600) or sincelastinc > (args.warninc * 3600): okay = 1 msg = "WARNING: " - if sincelastfull > (args.critfull * 24 * 3600) or sincelastinc > (args.critinc * 3600): okay = 2 msg = "CRITICAL: " - if not checkoutput(output): okay = max(okay,1) msg = "WARNING: duplicity output: %s " % repr(output) - if err: okay=2 msg = "Unexpected output: %s, " % repr(err) print msg, "last full %s ago, last incremential %s ago|lastfull=%d, lastinc=%d" % ( formattime(sincelastfull), formattime(sincelastinc), sincelastfull, sincelastinc) + + #clean up cruft + os.remove(checkstatus) sys.exit(okay) def checkoutput(output): - if output.find("No orphaned or incomplete backup sets found.")==-1: + if not 'No orphaned or incomplete backup sets found.' in output: return False - + return True def formattime(seconds): @@ -91,7 +96,7 @@ def formattime(seconds): def findlastdates(output): - lastfull =0 + lastfull = 0 lastinc = 0 for line in output.split("\n"): |