From 017d558d0b7479f4514ec5225058a29c4abc460e Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sat, 23 Mar 2013 17:37:03 +0100 Subject: [PATCH] remove old bacula checks --- dsa-nagios-checks/checks/dsa-check-bacula | 93 ---------- .../checks/dsa-check-bacula-lastbackup | 165 ------------------ .../checks/dsa-check-bacula-lastbackup-wrap | 29 --- 3 files changed, 287 deletions(-) delete mode 100755 dsa-nagios-checks/checks/dsa-check-bacula delete mode 100755 dsa-nagios-checks/checks/dsa-check-bacula-lastbackup delete mode 100755 dsa-nagios-checks/checks/dsa-check-bacula-lastbackup-wrap diff --git a/dsa-nagios-checks/checks/dsa-check-bacula b/dsa-nagios-checks/checks/dsa-check-bacula deleted file mode 100755 index 69988fe..0000000 --- a/dsa-nagios-checks/checks/dsa-check-bacula +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python -# -# check_bacula_client Nagios plugin to check Bacula client backups -# Copyright (C) 2010 Tom Payne -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -from datetime import datetime, timedelta -from optparse import OptionParser, OptionValueError -import re -import sys -import time - -import pexpect - - -OK, WARNING, CRITICAL, UNKNOWN = xrange(0, 4) -status_message = 'OK WARNING CRITICAL UNKNOWN'.split() - -MULTIPLIERS = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400, 'w': 604800} -DIVISORS = ((60, 'minutes'), (60, 'hours'), (24, 'days'), (7, 'weeks')) - - -def parse_period(option, opt_str, value, parser): - m = re.match(r'(\d+(?:\.\d+)?)(%s)\Z' % '|'.join(MULTIPLIERS.keys()), value) - if not m: - raise OptionValueError('invalid period - %s' % value) - setattr(parser.values, option.dest, timedelta(seconds=float(m.group(1)) * MULTIPLIERS[m.group(2)])) - - -def main(argv): - parser = OptionParser() - parser.add_option('-H', metavar='ADDRESS', dest='host', help='client name') - parser.add_option('-w', metavar='PERIOD', type=str, dest='warning', action='callback', callback=parse_period, help='generate warning if last successful backup older than PERIOD') - parser.add_option('-c', metavar='PERIOD', type=str, dest='critical', action='callback', callback=parse_period, help='generate critical if last successful backup older than PERIOD') - parser.add_option('-b', metavar='PATH', dest='bconsole', help='path to bconsole') - parser.set_defaults(bconsole='/usr/bin/bconsole') - options, args = parser.parse_args(argv[1:]) - exit_status, message = OK, None - child = pexpect.spawn(options.bconsole, ['-n']) - try: - child.expect(r'\n\*') - child.sendline('status client=%s.debian.org-fd' % options.host) - if child.expect_list([re.compile(r'Terminated Jobs:'), re.compile(r'Error: Client resource .* does not exist.')]): - raise RuntimeError('unknown client %s' % options.host) - child.expect(r'\n\*') - r = re.compile(r'\s*(\d+)\s+(\S+)\s+(\S+)\s+(\d+\.\d+\s+[KMGTP]|0)\s+OK\s+(\S+\s+\S+)') - job_id = level = files = bytes = finished = None - for line in child.before.splitlines(): - m = r.match(line) - if m: - job_id = int(m.group(1)) - level = m.group(2) - files = int(re.sub(r',', '', m.group(3))) - bytes = re.sub(r'\s+', '', m.group(4)) - finished = datetime(*(time.strptime(m.group(5), '%d-%b-%y %H:%M')[0:6])) - if job_id is None: - raise RuntimeError('no terminated jobs') - age = datetime.now() - finished - if options.warning and age > options.warning: - exit_status = WARNING - if options.critical and age > options.critical: - exit_status = CRITICAL - age, units = 24.0 * 60 * 60 * age.days + age.seconds, 'seconds' - for d, u in DIVISORS: - if age < d: - break - else: - age /= d - units = u - message = '%s, %d files, %sB, %s (%.1f %s ago)' % (level, files, bytes, finished, age, units) - except RuntimeError: - exit_status, message = (CRITICAL, str(sys.exc_info()[1])) - child.sendeof() - child.expect(pexpect.EOF) - print '%s: %s' % (status_message[exit_status], message) - sys.exit(exit_status) - - -if __name__ == '__main__': - main(sys.argv) diff --git a/dsa-nagios-checks/checks/dsa-check-bacula-lastbackup b/dsa-nagios-checks/checks/dsa-check-bacula-lastbackup deleted file mode 100755 index 0c0fce7..0000000 --- a/dsa-nagios-checks/checks/dsa-check-bacula-lastbackup +++ /dev/null @@ -1,165 +0,0 @@ -#!/usr/bin/perl - -# downloaded from http://exchange.nagios.org/directory/Plugins/Backup-and-Recovery/Bacula/check_bacula_lastbackup-2Epl/details -# by weasel, 2013-03-19 - -# modified to use Open2, weasel. - -# Author: Michael Wyraz -# Much code copied from check_mail_loop.pl which is GPL licensed. So this code has the same license. -# -# Checks the age of the last successfull backup of a given client and (optional) of a given level. -# - -use strict; -use Getopt::Long; -use Time::Local; -use IPC::Open2; - -&Getopt::Long::config('auto_abbrev'); - -my $bconsoleCommand="/usr/sbin/bconsole"; -my $level="*"; -my $levelName; -my $client; -my $warningAge=24; -my $criticalAge=48; - -my %ERRORS = ('OK' , '0', - 'WARNING', '1', - 'CRITICAL', '2', - 'UNKNOWN' , '3'); - -# Subs declaration -sub usage; -sub nsexit; - -# Evaluate Command Line Parameters -my $status = GetOptions( - "bconsole-command=s",\$bconsoleCommand, - "level=s",\$level, - "client=s",\$client, - "warningAge=i",\$warningAge, - "criticalAge=i",\$criticalAge, - ); - -if ($status == 0 || !($client && $bconsoleCommand) ) { - usage(); -} - -if ($level eq "*") { - $levelName="backup"; -} -elsif ($level eq "F" || $level eq "f") { - $level="F"; - $levelName="FULL backup"; -} -elsif ($level eq "I" || $level eq "i") { - $level="I"; - $levelName="INCREMENTAL backup"; -} -elsif ($level eq "D" || $level eq "d") { - $level="D"; - $levelName="DIFFERENTIAL backup"; -} -else { - usage(); -} - - - -# restrict client names to a-z,A-Z,0-9,".","_","-" to avoid execution of shell commands -if (!($client=~m/^[a-zA-Z0-9\.\-_]+$/i)) { - nsexit ("INVALID CLIENT NAME","ERROR"); -} - -#open (JOBLIST,"echo 'list jobname=$client' | $bconsoleCommand |"); -my $pid = open2(\*JOBLIST, \*CHLD_IN, $bconsoleCommand, '-n' ); -print CHLD_IN "list jobname=$client\n"; -close(CHLD_IN); - -my $latestBackupAge=-1; - -while() { - my($line) = $_; - # split into columns (and remove whitespaces) - my ($_dummy,$_jobId,$_client,$_startTime,$_type,$_level,$_jobFiles,$_jobBytes,$_jobStatus)=split(/\s*\|\s*/,$line); - - if ( $_jobStatus ne "T" ) { - next; # only jobs which terminated correctly - } - if ( $_client ne $client ) { - next; # only jobs for this client - } - if (!( $level eq "*" || $_level eq $level )) { - next; # only jobs for the reqired level (or any if $level="*") - } - - my ($_y,$_m,$_d,$_H,$_M,$_S); - - ($_y,$_m,$_d,$_H,$_M,$_S) = ( $_startTime=~/^(\d{4})\-(\d{2})\-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})$/ ); - - if (! $_y ) { - next; # require valid startTime - } - - my $_startTimeAsUnixtime=timelocal($_S, $_M, $_H, $_d, $_m-1, $_y); - my $backupAgeInSeconds=time()-$_startTimeAsUnixtime; - - if ($backupAgeInSeconds>0) { - if ($latestBackupAge < 0 || $latestBackupAge > $backupAgeInSeconds) { - $latestBackupAge=$backupAgeInSeconds; - } - } -} - -my $result; -my $status; - -if ($latestBackupAge<0) { - $result="Unable to find a valid $levelName for $client"; - $status="CRITICAL"; -} else { - $result="Last $levelName for $client was "; - $result.=sprintf ("%02D:%02D hours", $latestBackupAge/3600,($latestBackupAge/60) %60); - $result.=" ago."; - if ($latestBackupAge/3600 > $criticalAge ) { - $status="CRITICAL"; - } elsif ($latestBackupAge/3600 > $warningAge) { - $status="WARNING"; - } else { - $status="OK"; - } -} - -nsexit($result,$status); - - -sub usage { - print "check_bacula_lastbackup.pl 1.0 Nagios Plugin\n"; - print "\n"; - print "=" x 75,"\nERROR: Missing or wrong arguments!\n","=" x 75,"\n"; - print "\n"; - print "This script checks before how many hours the last successfull\n"; - print "backup of a certain client was done.\n"; - print "\n"; - print "\nThe following options are available:\n"; - print " -bconsole-command=path path to the bconsole command ($bconsoleCommand)\n"; - print " -client=text bacula client to check\n"; - print " -level=[*|F|D|I] level of backup to check (*=any, F=full, D=differential, I=incremental - default: any)\n"; - print " -warningAge=hours if the last backup is older than $warningAge hours, status is warning\n"; - print " -criticalAge=hours if the last backup is older than $criticalAge hours, status is critical\n"; - print "\n"; - print " Options may abbreviated!\n"; - print "This script comes with ABSOLUTELY NO WARRANTY\n"; - print "This programm is licensed under the terms of the "; - print "GNU General Public License\n\n"; - exit $ERRORS{"UNKNOWN"}; -} - - -sub nsexit { - my ($msg,$code) = @_; - print "$code: $msg\n" if (defined $msg); - exit $ERRORS{$code}; -} diff --git a/dsa-nagios-checks/checks/dsa-check-bacula-lastbackup-wrap b/dsa-nagios-checks/checks/dsa-check-bacula-lastbackup-wrap deleted file mode 100755 index 106f56e..0000000 --- a/dsa-nagios-checks/checks/dsa-check-bacula-lastbackup-wrap +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -check=/usr/lib/nagios/plugins/dsa-check-bacula-lastbackup -usage() { - echo >&2 "Usage: $0 [warn age [critical age (hours)]]" - exit 1 -} - -if [ "$#" -lt 2 ] || [ "$#" -gt 4 ]; then - usage -fi - -if [ "$1" = "full" ]; then - level="F" - crit=1560 - warn=840 -elif [ "$1" = "any" ]; then - level="*" - crit=60 - warn=36 -else - usage -fi - -if [ "$#" -ge 3 ]; then warn="$3"; fi -if [ "$#" -ge 4 ]; then crit="$4"; fi - - -exec "$check" -level="$level" -warningAge="$warn" -criticalAge="$crit" -client="$2.debian.org" -- 2.20.1