import to mercurial
authorChristian Arnold <arnold@schlittermann.de>
Tue, 17 May 2011 10:12:33 +0200
changeset 0 2098311fb227
child 1 0990f72db33c
import to mercurial
.hgignore
.perltitdy
Makefile
check_amanda.pl
debian/changelog
debian/compat
debian/control
debian/copyright
debian/docs
debian/rules
debian/source/format
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Tue May 17 10:12:33 2011 +0200
@@ -0,0 +1,8 @@
+syntax: glob
+*.swp
+debian/files
+check_amanda
+
+syntax: regexp
+(build|configure)-stamp$
+debian/nagios-plugin-amanda[./]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.perltitdy	Tue May 17 10:12:33 2011 +0200
@@ -0,0 +1,2 @@
+--paren-tightness=2
+--square-bracket-tightness=2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Tue May 17 10:12:33 2011 +0200
@@ -0,0 +1,22 @@
+SCRIPTS = check_amanda
+CLEANFILES = ${SCRIPTS}
+DESTDIR =
+prefix = /usr
+
+plugindir = ${prefix}/lib/nagios/plugins/ius
+
+.PHONY: all clean install
+
+all: ${SCRIPTS}
+
+clean:
+	-rm -f ${CLEANFILES}
+
+install: all
+	install -d -m 0755 ${DESTDIR}/${plugindir}
+	install -m 0755 $(SCRIPTS) ${DESTDIR}/${plugindir}/
+
+%:	%.pl
+	@perl -c $<
+	@cp -f $< $@
+	@chmod +x $@
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/check_amanda.pl	Tue May 17 10:12:33 2011 +0200
@@ -0,0 +1,197 @@
+#! /usr/bin/perl
+
+#   Copyright (C) 2011  Christian Arnold
+#
+#   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 <http://www.gnu.org/licenses/>.
+#
+#   Christian Arnold <arnold@schlittermann.de>
+
+use 5.010;
+use strict;
+use warnings;
+use File::Basename qw(basename);
+use Pod::Usage;
+use Getopt::Long;
+use Date::Manip;
+use Date::Calc qw(Delta_Days);
+
+delete @ENV{ grep /^LC_/ => keys %ENV };
+$ENV{LANG}   = "C";
+$ENV{LC_ALL} = "C";
+
+sub version($$);
+sub check_status($$);
+sub report($$);
+
+my %ERRORS = (
+    OK        => 0,
+    WARNING   => 1,
+    CRITICAL  => 2,
+    UNKNOWN   => 3,
+    DEPENDENT => 4
+);
+
+my $ME      = basename $0;
+my $NAME    = 'AMANDA';
+my $VERSION = '1.2';
+
+my %opt = (
+    configfile => 'DailySet1',
+    time       => '1day',
+    binary     => '/usr/sbin/amstatus'
+);
+
+MAIN: {
+    Getopt::Long::Configure('no_ignore_case_always');
+    GetOptions(
+        "C|configfile=s" => \$opt{configfile},
+        "t|time=s"       => \$opt{time},
+        "b|binary=s"     => \$opt{binary},
+        "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) },
+        "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) },
+        "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; }
+    ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} );
+
+    unless ( -x $opt{binary} ) {
+        say "$NAME CRITICAL: $opt{binary} - not found or not executable";
+        exit $ERRORS{CRITICAL};
+    }
+
+    my ( $rc, $date ) = check_status( $opt{configfile}, $opt{time} );
+    report( $rc, $date );
+
+}
+
+sub check_status($$) {
+    my ( $configfile, $time ) = @_;
+    my $last_backup_date;
+    my $mesg = undef;
+    my $rc   = "CRITICAL";
+
+    foreach (`$opt{binary} --config $configfile --error`) {
+        /^Using.*from\s+(.*)$/ and $last_backup_date = $1 and next;
+        /^\S+/ and $mesg = "some failed backups" and last;
+    }
+
+    # report critical status at any errors
+    if ($mesg) {
+        return ( $rc, $mesg );
+    }
+
+    # check the backup time state
+    if ($last_backup_date) {
+        my $now              = localtime();
+        my @last_backup_date = UnixDate( $last_backup_date, "%Y", "%m", "%d" );
+        my $max_backup_date  = DateCalc( $last_backup_date, "+ $time" );
+        my @max_backup_date  = UnixDate( $max_backup_date, "%Y", "%m", "%d" );
+        my @now              = UnixDate( $now, "%Y", "%m", "%d" );
+        my $allowed_difference_in_days =
+          Delta_Days( @last_backup_date, @max_backup_date );
+        my $difference_in_days = Delta_Days( @last_backup_date, @now );
+        $mesg = $last_backup_date;
+
+        $rc =
+          ( $allowed_difference_in_days > $difference_in_days )
+          ? "OK"
+          : "CRITICAL";
+    }
+    return ( $rc, $mesg );
+}
+
+sub report($$) {
+    my ( $rc, $mesg ) = @_;
+    say "$NAME $rc: Backup ERROR $opt{configfile} - $mesg"
+      and exit $ERRORS{CRITICAL}
+      if ( $rc eq "CRITICAL" );
+    say "$NAME $rc: Backup OK $opt{configfile} - $mesg";
+    exit $ERRORS{OK};
+}
+
+sub version($$) {
+    my ( $progname, $version ) = @_;
+    say <<_VERSION;
+$progname version $version
+Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support.
+
+$ME comes with ABSOLUTELY NO WARRANTY. This is free software,
+and you are welcome to redistribute it under certain conditions.
+See the GNU General Public Licence for details.
+_VERSION
+}
+
+__END__
+
+=head1 NAME
+
+check_amanda - nagios plugin to checks the last amanda backup status
+
+=head1 SYNOPSIS
+
+check_amanda [B<-C>|B<--configfile> string] [B<-t>|B<--time> string] [B<-b>|B<--binary> string]
+
+check_amanda [B<-h>|B<--help>]
+
+check_amanda [B<-m>|B<--man>]
+
+check_amanda [B<-V>|B<--version>]
+
+=head1 OPTIONS
+
+=over
+
+=item B<-C>|B<--configfile> I<string>
+
+The name of your amanda configuration (default: DailySet1)
+
+=item B<-t>|B<--time> I<string>
+
+The maximum time difference from the current time (default: 1day)
+
+=item B<-b>|B<--binary> I<string>
+
+Path to amstatus binary (default: /usr/sbin/amstatus)
+
+=item B<-h>|B<--help>
+
+Print detailed help screen.
+
+=item B<-m>|B<--man>
+
+Print manual page.
+
+=item B<-V>|B<--version>
+
+Print version information.
+
+=back
+
+=head1 DESCRIPTION
+
+This nagios plugin I<search> on a specified I<url> for a version string and compare the I<search> result with an installed I<package> version.
+
+=head1 VERSION
+
+This man page is current for version 1.2 of B<check_amanda>.
+
+=head1 AUTHOR
+
+Written by Christian Arnold L<arnold@schlittermann.de>
+
+=head1 COPYRIGHT
+
+Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support.  This is free software, and you are welcome to
+redistribute it under certain conditions.
+See the GNU General Public Licence for details.
+
+=cut
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debian/changelog	Tue May 17 10:12:33 2011 +0200
@@ -0,0 +1,5 @@
+nagios-plugin-amanda (1.2) lenny squeeze; urgency=low
+
+  * Initial Release.
+
+ -- Christian Arnold <arnold@schlittermann.de>  Tue, 17 May 2011 09:42:50 +0200
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debian/compat	Tue May 17 10:12:33 2011 +0200
@@ -0,0 +1,1 @@
+7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debian/control	Tue May 17 10:12:33 2011 +0200
@@ -0,0 +1,14 @@
+Source: nagios-plugin-amanda
+Section: net
+Priority: extra
+Maintainer: Christian Arnold <arnold@schlittermann.de>
+Build-Depends: debhelper (>= 7.0.50~)
+Standards-Version: 3.8.4
+Homepage: https://keller.schlittermann.de/hg/ius/nagios/nagios-plugin-amanda
+
+Package: nagios-plugin-amanda
+Architecture: all
+Depends: perl-base, perl-doc, libdate-manip-perl, libdate-calc-perl
+Recommends: amanda-server
+Description: nagios plugin to check amanda backup status
+ This plugin checks the last amanda backup status.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debian/copyright	Tue May 17 10:12:33 2011 +0200
@@ -0,0 +1,39 @@
+This work was packaged for Debian by:
+
+    Christian Arnold <arnold@schlittermann.de> on Tue, 17 May 2011 09:42:50 +0200
+
+It was downloaded from:
+
+    https://keller.schlittermann.de/hg/ius/nagios/nagios-plugin-amanda/
+
+Upstream Author(s):
+
+    Christian Arnold <arnold@schlittermann.de>
+
+Copyright:
+
+    Copyright (C) 2011 Schlittermann internet & unix support
+
+License:
+
+    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 package 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 <http://www.gnu.org/licenses/>.
+
+On Debian systems, the complete text of the GNU General
+Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
+
+The Debian packaging is:
+
+    Copyright (C) 2011 Christian Arnold <arnold@schlittermann.de>
+
+and is licensed under the GPL version 3, see above.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debian/rules	Tue May 17 10:12:33 2011 +0200
@@ -0,0 +1,13 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+%:
+	dh $@ 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debian/source/format	Tue May 17 10:12:33 2011 +0200
@@ -0,0 +1,1 @@
+3.0 (native)