check_amanda.pl
changeset 11 1f85ad1a7758
parent 10 470e82d70ee0
--- a/check_amanda.pl	Fri Oct 10 16:45:44 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,182 +0,0 @@
-#! /usr/bin/perl
-
-#   Copyright (C) 2011  Christian Arnold
-#   Copyright (C) 2014  Matthias Förste
-#
-#   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;
-
-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.3';
-
-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} );
-
-    my $time = Delta_Format($opt{time}, 0, "%sys");
-    report 'CRITICAL', "Invalid --time" unless (defined $time and $time);
-
-    unless ( -x $opt{binary} ) {
-        say "$NAME CRITICAL: $opt{binary} - not found or not executable";
-        exit $ERRORS{CRITICAL};
-    }
-
-    my ( $rc, $date ) = check_status( $opt{configfile}, $time );
-    report( $rc, $date );
-
-}
-
-sub check_status($$) {
-    my ( $configfile, $time ) = @_;
-    my $last_backup_time;
-    my $mesg = undef;
-    my $rc   = "CRITICAL";
-
-    foreach (`$opt{binary} --config $configfile --error`) {
-	/^Using / and next;
-        /^From\s+(.*)$/ and $last_backup_time = $1 and next;
-        /^\S+/ and return ('CRITICAL', 'some failed backups');
-    }
-
-    # check the backup time state
-    my $now              = time;
-    my $last             = Date_SecsSince1970GMT(UnixDate(ParseDate( $last_backup_time ), qw(%m %d %Y %H %M %S)));
-    return 'CRITICAL', "Last Backup too old: $last_backup_time" if $now - $last > $time;
-    return 'OK', $last_backup_time;
-
-}
-
-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.3 of B<check_amanda>.
-
-=head1 AUTHOR
-
-Written by Christian Arnold L<arnold@schlittermann.de> and Matthias Förste L<foerste@schlittermann.de>
-
-=head1 COPYRIGHT
-
-Copyright (C) 2011 by Christian Arnold, 2014 by Matthias Förste 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