1 #! /usr/bin/perl |
|
2 |
|
3 # Copyright (C) 2011 Christian Arnold |
|
4 # Copyright (C) 2014 Matthias Förste |
|
5 # |
|
6 # This program is free software: you can redistribute it and/or modify |
|
7 # it under the terms of the GNU General Public License as published by |
|
8 # the Free Software Foundation, either version 3 of the License, or |
|
9 # (at your option) any later version. |
|
10 # |
|
11 # This program is distributed in the hope that it will be useful, |
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 # GNU General Public License for more details. |
|
15 # |
|
16 # You should have received a copy of the GNU General Public License |
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18 # |
|
19 # Christian Arnold <arnold@schlittermann.de> |
|
20 |
|
21 use 5.010; |
|
22 use strict; |
|
23 use warnings; |
|
24 use File::Basename qw(basename); |
|
25 use Pod::Usage; |
|
26 use Getopt::Long; |
|
27 use Date::Manip; |
|
28 |
|
29 delete @ENV{ grep /^LC_/ => keys %ENV }; |
|
30 $ENV{LANG} = "C"; |
|
31 $ENV{LC_ALL} = "C"; |
|
32 |
|
33 sub version($$); |
|
34 sub check_status($$); |
|
35 sub report($$); |
|
36 |
|
37 my %ERRORS = ( |
|
38 OK => 0, |
|
39 WARNING => 1, |
|
40 CRITICAL => 2, |
|
41 UNKNOWN => 3, |
|
42 DEPENDENT => 4 |
|
43 ); |
|
44 |
|
45 my $ME = basename $0; |
|
46 my $NAME = 'AMANDA'; |
|
47 my $VERSION = '1.3'; |
|
48 |
|
49 my %opt = ( |
|
50 configfile => 'DailySet1', |
|
51 time => '1day', |
|
52 binary => '/usr/sbin/amstatus' |
|
53 ); |
|
54 |
|
55 MAIN: { |
|
56 Getopt::Long::Configure('no_ignore_case_always'); |
|
57 GetOptions( |
|
58 "C|configfile=s" => \$opt{configfile}, |
|
59 "t|time=s" => \$opt{time}, |
|
60 "b|binary=s" => \$opt{binary}, |
|
61 "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) }, |
|
62 "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) }, |
|
63 "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; } |
|
64 ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} ); |
|
65 |
|
66 my $time = Delta_Format($opt{time}, 0, "%sys"); |
|
67 report 'CRITICAL', "Invalid --time" unless (defined $time and $time); |
|
68 |
|
69 unless ( -x $opt{binary} ) { |
|
70 say "$NAME CRITICAL: $opt{binary} - not found or not executable"; |
|
71 exit $ERRORS{CRITICAL}; |
|
72 } |
|
73 |
|
74 my ( $rc, $date ) = check_status( $opt{configfile}, $time ); |
|
75 report( $rc, $date ); |
|
76 |
|
77 } |
|
78 |
|
79 sub check_status($$) { |
|
80 my ( $configfile, $time ) = @_; |
|
81 my $last_backup_time; |
|
82 my $mesg = undef; |
|
83 my $rc = "CRITICAL"; |
|
84 |
|
85 foreach (`$opt{binary} --config $configfile --error`) { |
|
86 /^Using / and next; |
|
87 /^From\s+(.*)$/ and $last_backup_time = $1 and next; |
|
88 /^\S+/ and return ('CRITICAL', 'some failed backups'); |
|
89 } |
|
90 |
|
91 # check the backup time state |
|
92 my $now = time; |
|
93 my $last = Date_SecsSince1970GMT(UnixDate(ParseDate( $last_backup_time ), qw(%m %d %Y %H %M %S))); |
|
94 return 'CRITICAL', "Last Backup too old: $last_backup_time" if $now - $last > $time; |
|
95 return 'OK', $last_backup_time; |
|
96 |
|
97 } |
|
98 |
|
99 sub report($$) { |
|
100 my ( $rc, $mesg ) = @_; |
|
101 say "$NAME $rc: Backup ERROR $opt{configfile} - $mesg" |
|
102 and exit $ERRORS{CRITICAL} |
|
103 if ( $rc eq "CRITICAL" ); |
|
104 say "$NAME $rc: Backup OK $opt{configfile} - $mesg"; |
|
105 exit $ERRORS{OK}; |
|
106 } |
|
107 |
|
108 sub version($$) { |
|
109 my ( $progname, $version ) = @_; |
|
110 say <<_VERSION; |
|
111 $progname version $version |
|
112 Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support. |
|
113 |
|
114 $ME comes with ABSOLUTELY NO WARRANTY. This is free software, |
|
115 and you are welcome to redistribute it under certain conditions. |
|
116 See the GNU General Public Licence for details. |
|
117 _VERSION |
|
118 } |
|
119 |
|
120 __END__ |
|
121 |
|
122 =head1 NAME |
|
123 |
|
124 check_amanda - nagios plugin to checks the last amanda backup status |
|
125 |
|
126 =head1 SYNOPSIS |
|
127 |
|
128 check_amanda [B<-C>|B<--configfile> string] [B<-t>|B<--time> string] [B<-b>|B<--binary> string] |
|
129 |
|
130 check_amanda [B<-h>|B<--help>] |
|
131 |
|
132 check_amanda [B<-m>|B<--man>] |
|
133 |
|
134 check_amanda [B<-V>|B<--version>] |
|
135 |
|
136 =head1 OPTIONS |
|
137 |
|
138 =over |
|
139 |
|
140 =item B<-C>|B<--configfile> I<string> |
|
141 |
|
142 The name of your amanda configuration (default: DailySet1) |
|
143 |
|
144 =item B<-t>|B<--time> I<string> |
|
145 |
|
146 The maximum time difference from the current time (default: 1day) |
|
147 |
|
148 =item B<-b>|B<--binary> I<string> |
|
149 |
|
150 Path to amstatus binary (default: /usr/sbin/amstatus) |
|
151 |
|
152 =item B<-h>|B<--help> |
|
153 |
|
154 Print detailed help screen. |
|
155 |
|
156 =item B<-m>|B<--man> |
|
157 |
|
158 Print manual page. |
|
159 |
|
160 =item B<-V>|B<--version> |
|
161 |
|
162 Print version information. |
|
163 |
|
164 =back |
|
165 |
|
166 =head1 DESCRIPTION |
|
167 |
|
168 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. |
|
169 |
|
170 =head1 VERSION |
|
171 |
|
172 This man page is current for version 1.3 of B<check_amanda>. |
|
173 |
|
174 =head1 AUTHOR |
|
175 |
|
176 Written by Christian Arnold L<arnold@schlittermann.de> and Matthias Förste L<foerste@schlittermann.de> |
|
177 |
|
178 =head1 COPYRIGHT |
|
179 |
|
180 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. |
|
181 |
|
182 =cut |
|