--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/check_rsnapshot.pl Fri Mar 04 15:07:12 2011 +0100
@@ -0,0 +1,150 @@
+#! /usr/bin/perl -w
+
+# 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 strict;
+use File::Basename;
+use Getopt::Long;
+use Date::Manip;
+use Pod::Usage;
+use if $ENV{DEBUG} => "Smart::Comments";
+
+my %ERRORS = (
+ OK => 0,
+ WARNING => 1,
+ CRITICAL => 2,
+ UNKNOWN => 3,
+ DEPENDENT => 4
+);
+
+sub get_status($);
+sub report($);
+sub version($$);
+
+my $ME = basename $0;
+my $VERSION = "2.0";
+
+my %opt = (
+ binary => "/usr/bin/rsnapshot",
+ logfile => "/var/log/rsnapshot.log"
+);
+
+MAIN: {
+ Getopt::Long::Configure('bundling');
+ GetOptions(
+ "b|binary=s" => \$opt{binary},
+ "l|logfile=s" => \$opt{logfile},
+ "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} ) {
+ print
+ "RSNAPSHOT CRITICAL: $opt{binary} - not found or not executable\n";
+ exit $ERRORS{CRITICAL};
+ }
+
+ my $status = get_status( $opt{logfile} );
+ report($status);
+}
+
+sub get_status($) {
+ my $logfile = shift;
+ my $date = UnixDate( ParseDate("today"), "%d/%b/%Y" );
+ my ( $found, $error ) = undef;
+
+ open( FH, $logfile )
+ or print "RSNAPSHOT CRITICAL: $logfile - $!\n" and exit $ERRORS{CRITICAL};
+ while (<FH>) {
+ unless ($found) {
+ /^\[$date:.*ERROR/ or next;
+ $found = 1;
+ $error = $_;
+ last;
+ }
+ }
+ close(FH);
+
+ if ($found) {
+ print "RSNAPSHOT CRITICAL: $error\n";
+ exit $ERRORS{CRITICAL};
+ }
+ else {
+ print "RSNAPSHOT OK: no errors in $logfile\n";
+ exit $ERRORS{OK};
+ }
+}
+
+=head1 NAME
+
+check_rsnapshot - nagios plugin to check for errors on rsnapshot logfile
+
+=head1 SYNOPSIS
+
+check_release [-b|--binary string]
+ [-l|--logfile string]
+ [-h|--help]
+ [-m|--man]
+ [-V|--version]
+
+=head1 OPTIONS
+
+=over
+
+=item B<-b>|B<--binary> I<string>
+
+rsnapshot binary (default: /usr/bin/rsnapshot)
+
+=item B<-l>|B<--logfile> I<string>
+
+rsnapshot logfile (default: /var/log/rsnapshot.log)
+
+=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 plugin checks rsnapshot logfile for errors.
+
+=head1 VERSION
+
+This man page is current for version 2.0 of check_rsnapshot.
+
+=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