|
1 #! /usr/bin/perl -w |
|
2 |
|
3 # Copyright (C) 2011 Christian Arnold |
|
4 # |
|
5 # This program is free software: you can redistribute it and/or modify |
|
6 # it under the terms of the GNU General Public License as published by |
|
7 # the Free Software Foundation, either version 3 of the License, or |
|
8 # (at your option) any later version. |
|
9 # |
|
10 # This program is distributed in the hope that it will be useful, |
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 # GNU General Public License for more details. |
|
14 # |
|
15 # You should have received a copy of the GNU General Public License |
|
16 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 # |
|
18 # Christian Arnold <arnold@schlittermann.de> |
|
19 |
|
20 use strict; |
|
21 use File::Basename; |
|
22 use Getopt::Long; |
|
23 use Date::Manip; |
|
24 use Pod::Usage; |
|
25 use if $ENV{DEBUG} => "Smart::Comments"; |
|
26 |
|
27 my %ERRORS = ( |
|
28 OK => 0, |
|
29 WARNING => 1, |
|
30 CRITICAL => 2, |
|
31 UNKNOWN => 3, |
|
32 DEPENDENT => 4 |
|
33 ); |
|
34 |
|
35 sub get_status($); |
|
36 sub report($); |
|
37 sub version($$); |
|
38 |
|
39 my $ME = basename $0; |
|
40 my $VERSION = "2.0"; |
|
41 |
|
42 my %opt = ( |
|
43 binary => "/usr/bin/rsnapshot", |
|
44 logfile => "/var/log/rsnapshot.log" |
|
45 ); |
|
46 |
|
47 MAIN: { |
|
48 Getopt::Long::Configure('bundling'); |
|
49 GetOptions( |
|
50 "b|binary=s" => \$opt{binary}, |
|
51 "l|logfile=s" => \$opt{logfile}, |
|
52 "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) }, |
|
53 "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) }, |
|
54 "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; } |
|
55 ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} ); |
|
56 |
|
57 unless ( -x $opt{binary} ) { |
|
58 print |
|
59 "RSNAPSHOT CRITICAL: $opt{binary} - not found or not executable\n"; |
|
60 exit $ERRORS{CRITICAL}; |
|
61 } |
|
62 |
|
63 my $status = get_status( $opt{logfile} ); |
|
64 report($status); |
|
65 } |
|
66 |
|
67 sub get_status($) { |
|
68 my $logfile = shift; |
|
69 my $date = UnixDate( ParseDate("today"), "%d/%b/%Y" ); |
|
70 my ( $found, $error ) = undef; |
|
71 |
|
72 open( FH, $logfile ) |
|
73 or print "RSNAPSHOT CRITICAL: $logfile - $!\n" and exit $ERRORS{CRITICAL}; |
|
74 while (<FH>) { |
|
75 unless ($found) { |
|
76 /^\[$date:.*ERROR/ or next; |
|
77 $found = 1; |
|
78 $error = $_; |
|
79 last; |
|
80 } |
|
81 } |
|
82 close(FH); |
|
83 |
|
84 if ($found) { |
|
85 print "RSNAPSHOT CRITICAL: $error\n"; |
|
86 exit $ERRORS{CRITICAL}; |
|
87 } |
|
88 else { |
|
89 print "RSNAPSHOT OK: no errors in $logfile\n"; |
|
90 exit $ERRORS{OK}; |
|
91 } |
|
92 } |
|
93 |
|
94 =head1 NAME |
|
95 |
|
96 check_rsnapshot - nagios plugin to check for errors on rsnapshot logfile |
|
97 |
|
98 =head1 SYNOPSIS |
|
99 |
|
100 check_release [-b|--binary string] |
|
101 [-l|--logfile string] |
|
102 [-h|--help] |
|
103 [-m|--man] |
|
104 [-V|--version] |
|
105 |
|
106 =head1 OPTIONS |
|
107 |
|
108 =over |
|
109 |
|
110 =item B<-b>|B<--binary> I<string> |
|
111 |
|
112 rsnapshot binary (default: /usr/bin/rsnapshot) |
|
113 |
|
114 =item B<-l>|B<--logfile> I<string> |
|
115 |
|
116 rsnapshot logfile (default: /var/log/rsnapshot.log) |
|
117 |
|
118 =item B<-h>|B<--help> |
|
119 |
|
120 Print detailed help screen. |
|
121 |
|
122 =item B<-m>|B<--man> |
|
123 |
|
124 Print manual page. |
|
125 |
|
126 =item B<-V>|B<--version> |
|
127 |
|
128 Print version information. |
|
129 |
|
130 =back |
|
131 |
|
132 =head1 DESCRIPTION |
|
133 |
|
134 This plugin checks rsnapshot logfile for errors. |
|
135 |
|
136 =head1 VERSION |
|
137 |
|
138 This man page is current for version 2.0 of check_rsnapshot. |
|
139 |
|
140 =head1 AUTHOR |
|
141 |
|
142 Written by Christian Arnold L<arnold@schlittermann.de> |
|
143 |
|
144 =head1 COPYRIGHT |
|
145 |
|
146 Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support. |
|
147 This is free software, and you are welcome to redistribute it under certain conditions. |
|
148 See the GNU General Public Licence for details. |
|
149 |
|
150 =cut |