|
1 #! /usr/bin/perl -w |
|
2 # $Id$ |
|
3 # $URL$ |
|
4 |
|
5 use strict; |
|
6 use File::Basename; |
|
7 use Getopt::Long; |
|
8 use LWP::Simple; |
|
9 |
|
10 use lib "/usr/lib/nagios/plugins"; |
|
11 use utils qw (%ERRORS &print_revision &support); |
|
12 |
|
13 sub print_help(); |
|
14 sub print_usage(); |
|
15 |
|
16 my $ME = basename $0; |
|
17 my ( $opt_u, $opt_s, $opt_V, $opt_h, $opt_b ); |
|
18 my ( $result, $found, $message, $version, $current_version ); |
|
19 my ( @webside ); |
|
20 |
|
21 $opt_u = "http://www.avira.com/de/downloads/avira_antivir_unix_webgate.html"; |
|
22 $opt_s = ">Avira AntiVir UNIX WebGate<"; |
|
23 $opt_b = "/usr/lib/AntiVir/avwebgate.bin"; |
|
24 |
|
25 Getopt::Long::Configure('bundling'); |
|
26 GetOptions( |
|
27 "V" => \$opt_V, |
|
28 "version" => \$opt_V, |
|
29 "h" => \$opt_h, |
|
30 "help" => \$opt_h, |
|
31 "b=s" => \$opt_b, |
|
32 "binary" => \$opt_b, |
|
33 "u=s" => \$opt_u, |
|
34 "url=s" => \$opt_u, |
|
35 "s=s" => \$opt_s, |
|
36 "search=s" => \$opt_s |
|
37 ); |
|
38 |
|
39 if ($opt_V) { |
|
40 print_revision( $ME, "0.1" ); |
|
41 exit $ERRORS{"OK"}; |
|
42 } |
|
43 |
|
44 if ($opt_h) { |
|
45 print_help(); |
|
46 exit $ERRORS{"OK"}; |
|
47 } |
|
48 |
|
49 # check avwebgate binary |
|
50 unless ( -x $opt_b ) { |
|
51 print "AVWEBGATE CRITICAL: AntiVir WebGate not found or not executable - $opt_b\n"; |
|
52 exit $ERRORS{"CRITICAL"}; |
|
53 } |
|
54 |
|
55 # download the webside |
|
56 push @webside, split("\n", get($opt_u)); |
|
57 |
|
58 foreach (@webside) { |
|
59 unless ($found) { |
|
60 /$opt_s/ or next; |
|
61 $found = 1; |
|
62 next; |
|
63 } |
|
64 /Version:\s([\d\.-]+).*/ or next; |
|
65 $version = $1 and last; |
|
66 } |
|
67 |
|
68 unless ($version) { |
|
69 print "AVWEBGATE CRITICAL: cannot get version info from avira server\n"; |
|
70 exit $ERRORS{"CRITICAL"}; |
|
71 } |
|
72 |
|
73 $_ = `$opt_b --version`; |
|
74 if ($_ =~ /product version:\s+(\S+)/) { $current_version = $1; } |
|
75 |
|
76 $result = ($current_version eq $version) ? "OK" : "WARNING"; |
|
77 |
|
78 if ($result eq "WARNING") { |
|
79 $message = "new version available: $version"; |
|
80 print "AVWEBGATE $result: $message\n"; |
|
81 exit $ERRORS{$result}; |
|
82 } else { |
|
83 $message = "current version: $current_version"; |
|
84 print "AVWEBGATE $result: $message\n"; |
|
85 exit $ERRORS{$result}; |
|
86 } |
|
87 |
|
88 sub print_usage() { |
|
89 print "Usage:\n"; |
|
90 print " $ME [-b <binary>] [-u <url>] [-s <search>\n"; |
|
91 print " $ME [-h | --help]\n"; |
|
92 print " $ME [-V | --version]\n"; |
|
93 } |
|
94 |
|
95 sub print_help() { |
|
96 print_revision( $ME, "0.1" ); |
|
97 print "Copyright (c) 2008 Christian Arnold\n\n"; |
|
98 print "This plugin checks for new versions of Avira AntiVir WebGate.\n\n"; |
|
99 print_usage(); |
|
100 print "\n"; |
|
101 print " -b, --binary <binary>\n"; |
|
102 print " Path of AntiVir WebGate binary (default: /usr/lib/AntiVir/avwebgate.bin)\n"; |
|
103 print " -u, --url <url>\n"; |
|
104 print " URL where will be look for the search string (default: http://www.avira.com/de/downloads/avira_antivir_unix_webgate.html)\n"; |
|
105 print " -s, --search <search>\n"; |
|
106 print " Search string on the url (default: >Avira AntiVir UNIX WebGate<)\n"; |
|
107 print "\n"; |
|
108 support(); |
|
109 } |