--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Tue Apr 19 14:33:24 2011 +0200
@@ -0,0 +1,8 @@
+syntax: glob
+*.swp
+debian/files
+check_dump
+
+syntax: regexp
+(build|configure)-stamp$
+debian/nagios-plugin-dump[./]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.perltitdy Tue Apr 19 14:33:24 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 Apr 19 14:33:24 2011 +0200
@@ -0,0 +1,22 @@
+SCRIPTS = check_dump
+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_dump.pl Tue Apr 19 14:33:24 2011 +0200
@@ -0,0 +1,242 @@
+#! /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 5.010;
+use Perl6::Slurp;
+use strict;
+use warnings;
+use File::Basename;
+use Pod::Usage;
+use Getopt::Long;
+use Date::Parse qw(str2time);
+use Cwd qw(realpath);
+
+delete @ENV{ grep /^LC_/ => keys %ENV };
+$ENV{LANG} = "C";
+$ENV{LC_ALL} = "C";
+
+sub get_candidates();
+sub get_history(%);
+sub report(%);
+
+sub devno($);
+sub real_device($);
+sub version($$);
+
+my %ERRORS = (
+ OK => 0,
+ WARNING => 1,
+ CRITICAL => 2,
+ UNKNOWN => 3,
+ DEPENDENT => 4
+);
+
+my $ME = basename $0;
+my $VERSION = "0.1";
+my $NAME = "DUMP";
+my $NOW = time();
+
+MAIN: {
+ Getopt::Long::Configure('bundling');
+ GetOptions(
+ "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 %devs = get_candidates();
+ %devs = get_history(%devs);
+
+ report(%devs);
+}
+
+sub report(%) {
+ my %devs = @_;
+ my %rc;
+
+ foreach my $devno ( keys %devs ) {
+ if ( $devs{$devno}{date} ) {
+ if ( ( $NOW - $devs{$devno}{date} ) >
+ ( $devs{$devno}{dump} * 86400 ) )
+ {
+ $rc{ $devs{$devno}{dev} } = { rc => $ERRORS{WARNING} };
+ }
+ }
+ else {
+ $rc{ $devs{$devno}{dev} } = { rc => $ERRORS{CRITICAL} };
+ }
+ }
+
+ my ( @critical, @warning );
+
+ foreach my $dev ( keys %rc ) {
+ if ( $rc{$dev}{rc} eq $ERRORS{CRITICAL} ) {
+ push @critical, $dev;
+ }
+ else {
+ push @warning, $dev;
+ }
+ }
+
+ say "$NAME CRITICAL: @critical check dump backup" and exit $ERRORS{CRITICAL}
+ if (@critical);
+ say "$NAME WARNING: @warning check dump backup" and exit $ERRORS{WARNING}
+ if (@warning);
+ say "$NAME OK: all dump backups in limit" and exit $ERRORS{OK};
+}
+
+sub get_candidates() {
+
+ my %devs;
+
+ foreach ( grep !/^\s*#/, slurp("/etc/fstab") ) {
+ my ( $dev, $mp, $fstype, $options, $dump, $check ) = split;
+ next if not $dump;
+
+ my $rdev = real_device($dev);
+ my ( $major, $minor ) = devno($rdev);
+
+ $devs{"$major:$minor"} = {
+ dev => $dev,
+ rdev => $rdev,
+ dump => $dump
+ };
+ }
+
+ return %devs;
+}
+
+sub get_history(%) {
+
+ my %devs = @_;
+
+ say "$NAME CRITICAL: Command 'dump' not found." and exit $ERRORS{CRITICAL}
+ if system("command -v dump >/dev/null");
+
+ foreach (`dump -W`) {
+ chomp;
+ /^
+ (?:\s+|>\s+)
+ (?<dev>\S+)\s+
+ \(
+ (?:\s+)?
+ (?<mp>\S+)\)\s+
+ Last\s+dump:\s+
+ (?:(Level\s+(?<level>\d+)|(?<level>\S+)))
+ (?:,\s+Date\s+)?
+ (?<date>.*)
+ /x or next;
+ my $rdev = real_device( $+{dev} );
+ my ( $major, $minor ) = devno($rdev);
+
+ if ( exists( $devs{"$major:$minor"} ) ) {
+ $devs{"$major:$minor"} = {
+ dev => $+{dev},
+ rdev => $rdev,
+ mp => $+{mp},
+ level => $+{level},
+ dump => $devs{"$major:$minor"}{dump},
+ date => str2time( $+{date} )
+ };
+ }
+ }
+
+ return %devs;
+}
+
+sub real_device($) {
+ my $dev = shift;
+
+ if ( $dev ~~ /^(LABEL|UUID)=/ ) {
+ chomp( $dev = `blkid -c /dev/null -o device -t '$dev'` );
+ }
+
+ $dev = realpath($dev);
+}
+
+sub devno($) {
+ my @mm = ( ( stat shift )[6] >> 8, ( stat _ )[6] & 0xff );
+ return wantarray ? @mm : "$mm[0]:$mm[1]";
+}
+
+sub version($$) {
+ my $progname = shift;
+ my $version = shift;
+
+ 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_dump - nagios plugin to check backup status from dump
+
+=head1 SYNOPSIS
+
+check_dump [B<-h>|B<--help>]
+
+check_dump [B<-m>|B<--man>]
+
+check_dump [B<-v>|B<--version>]
+
+=head1 OPTIONS
+
+=over
+
+=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 check backup status from dump.
+
+=head1 VERSION
+
+This man page is current for version 0.1 of B<check_dump>.
+
+=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