|
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 5.010; |
|
21 use strict; |
|
22 use File::Basename; |
|
23 use Getopt::Long; |
|
24 use Pod::Usage; |
|
25 use LWP::Simple; |
|
26 |
|
27 delete @ENV{ grep /^LC_/ => keys %ENV }; |
|
28 $ENV{LANG} = "C"; |
|
29 $ENV{LC_ALL} = "C"; |
|
30 |
|
31 sub version($$); |
|
32 sub get_current_version($); |
|
33 sub get_last_version($$); |
|
34 sub report($$); |
|
35 |
|
36 my %ERRORS = ( |
|
37 OK => 0, |
|
38 WARNING => 1, |
|
39 CRITICAL => 2, |
|
40 UNKNOWN => 3, |
|
41 DEPENDENT => 4 |
|
42 ); |
|
43 |
|
44 my $ME = basename $0; |
|
45 my $NAME = "Z-PUSH"; |
|
46 my $VERSION = "0.1"; |
|
47 |
|
48 my %opt = ( |
|
49 url => "http://developer.berlios.de/project/showfiles.php?group_id=8963", |
|
50 file => "/var/www/z-push/version.php" |
|
51 ); |
|
52 |
|
53 MAIN: { |
|
54 Getopt::Long::Configure('bundling'); |
|
55 GetOptions( |
|
56 "u|url=s" => \$opt{url}, |
|
57 "l|file=s" => \$opt{file}, |
|
58 "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) }, |
|
59 "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) }, |
|
60 "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; } |
|
61 ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} ); |
|
62 |
|
63 my $current_version = get_current_version( $opt{file} ); |
|
64 my $last_version = get_last_version( $opt{url}, $opt{search} ); |
|
65 report( $last_version, $current_version ); |
|
66 } |
|
67 |
|
68 sub report($$) { |
|
69 my ( $last_version, $current_version ) = @_; |
|
70 |
|
71 unless ( $last_version eq $current_version ) { |
|
72 say |
|
73 "$NAME WARNING: installed version $current_version available version $last_version"; |
|
74 exit $ERRORS{WARNING}; |
|
75 } |
|
76 |
|
77 say "$NAME OK: installed version $current_version"; |
|
78 exit $ERRORS{OK}; |
|
79 } |
|
80 |
|
81 sub get_current_version($) { |
|
82 my ($file) = @_; |
|
83 |
|
84 unless ( -r $file ) { |
|
85 say "$NAME CRITICAL: $file - $!."; |
|
86 exit $ERRORS{CRITICAL}; |
|
87 } |
|
88 |
|
89 open( FH, $file ) |
|
90 or say "$NAME CRITICAL: $file - $!." and exit $ERRORS{CRITICAL}; |
|
91 |
|
92 while (<FH>) { |
|
93 /^\$zpush_version\s+=\s+"(?<version>[\d.]+)/ and return $+{version}; |
|
94 } |
|
95 |
|
96 close(FH); |
|
97 |
|
98 say "$NAME CRITICAL: Can't find installed version." |
|
99 and exit $ERRORS{CRITICAL}; |
|
100 } |
|
101 |
|
102 sub get_last_version($$) { |
|
103 my ( $url, $search ) = @_; |
|
104 my @webside = (); |
|
105 |
|
106 my $side = get($url); |
|
107 return "can't get $url" if ( !$side ); |
|
108 |
|
109 push @webside, split( "\n", $side ); |
|
110 my $zpb = undef; |
|
111 foreach (@webside) { |
|
112 if ( $zpb || m|<h3>Z-Push Backend</h3>| ) { |
|
113 $zpb = 1; |
|
114 m|<h3>Z-Push Backend/older releases</h3>| and last; |
|
115 m|>Version\s+(?<version>[\d.]+)<| and return $+{version}; |
|
116 } |
|
117 } |
|
118 |
|
119 say "$NAME CRITICAL: Can't find last version." and exit $ERRORS{CRITICAL}; |
|
120 } |
|
121 |
|
122 sub version($$) { |
|
123 my ( $progname, $version ) = @_; |
|
124 |
|
125 say <<_VERSION; |
|
126 $progname version $version |
|
127 Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support. |
|
128 |
|
129 $ME comes with ABSOLUTELY NO WARRANTY. This is free software, |
|
130 and you are welcome to redistribute it under certain conditions. |
|
131 See the GNU General Public Licence for details. |
|
132 _VERSION |
|
133 } |
|
134 |
|
135 __END__ |
|
136 |
|
137 =head1 NAME |
|
138 |
|
139 check_zpush - nagios plugin to check z-push version |
|
140 |
|
141 =head1 SYNOPSIS |
|
142 |
|
143 check_zpush [B<-u>|B<--url>] |
|
144 |
|
145 check_zpush [B<-f>|B<--file>] |
|
146 |
|
147 check_zpush [B<-h>|B<--help>] |
|
148 |
|
149 check_zpush [B<-m>|B<--man>] |
|
150 |
|
151 check_zpush [B<-v>|B<--version>] |
|
152 |
|
153 =head1 OPTIONS |
|
154 |
|
155 =over |
|
156 |
|
157 =item B<-u>|B<--url> |
|
158 |
|
159 Download I<url> with z-push release information. (default: http://developer.berlios.de/project/showfiles.php?group_id=8963) |
|
160 |
|
161 =item B<-f>|B<--file> |
|
162 |
|
163 Local z-push version file. (default: /var/www/z-push/version.php) |
|
164 |
|
165 =item B<-h>|B<--help> |
|
166 |
|
167 Print detailed help screen. |
|
168 |
|
169 =item B<-m>|B<--man> |
|
170 |
|
171 Print manual page. |
|
172 |
|
173 =item B<-V>|B<--version> |
|
174 |
|
175 Print version information. |
|
176 |
|
177 =back |
|
178 |
|
179 =head1 DESCRIPTION |
|
180 |
|
181 This nagios plugin search on a specified I<url> for a new version of z-push and compare the search result with an installed version. |
|
182 |
|
183 =head1 VERSION |
|
184 |
|
185 This man page is current for version 0.1 of B<check_zpush>. |
|
186 |
|
187 =head1 AUTHOR |
|
188 |
|
189 Written by Christian Arnold L<arnold@schlittermann.de> |
|
190 |
|
191 =head1 COPYRIGHT |
|
192 |
|
193 Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support. |
|
194 This is free software, and you are welcome to redistribute it under certain conditions. |
|
195 See the GNU General Public Licence for details. |
|
196 |
|
197 =cut |