check_avwebgate.pl
changeset 5 e061bc121954
parent 4 1e812db5da23
child 12 99ed3413c15a
equal deleted inserted replaced
4:1e812db5da23 5:e061bc121954
     6 use File::Basename;
     6 use File::Basename;
     7 use Getopt::Long;
     7 use Getopt::Long;
     8 use LWP::Simple;
     8 use LWP::Simple;
     9 
     9 
    10 use lib "/usr/lib/nagios/plugins";
    10 use lib "/usr/lib/nagios/plugins";
    11 use utils qw (%ERRORS &print_revision &support);
    11 use utils qw (%ERRORS &print_revision);
    12 
    12 
    13 sub print_help();
    13 sub print_help();
    14 sub print_usage();
    14 sub print_usage();
    15 
    15 
    16 my $ME = basename $0;
    16 my $ME = basename $0;
    17 my ( $opt_u, $opt_s, $opt_V, $opt_h, $opt_b );
    17 my ( $opt_u, $opt_s, $opt_V, $opt_h, $opt_b );
    18 my ( $result, $found, $message, $version, $current_version );
    18 my ( $result, $found, $message, $version, $current_version );
    19 my ( @webside );
       
    20 
    19 
    21 $opt_u = "http://www.avira.de/de/downloads/avira_antivir_webgate.html";
    20 $opt_u = 'http://www.avira.com/de/support-download-avira-antivir-webgate';
    22 $opt_s = ">Avira AntiVir WebGate / Avira WebGate Suite<";
    21 $opt_s = '<a.*>Avira AntiVir WebGate / Avira WebGate Suite</a>.*(?:\n.*){4}<td>(\d+\.\d+\.\d+\.[\d-]+)</td>';
    23 $opt_b = "/usr/lib/AntiVir/avwebgate.bin";
    22 $opt_b = "/usr/lib/AntiVir/avwebgate.bin";
    24 
    23 
    25 Getopt::Long::Configure('bundling');
    24 Getopt::Long::Configure('bundling');
    26 GetOptions(
    25 GetOptions(
    27     "V"              => \$opt_V,
    26     "V"              => \$opt_V,
    50 unless ( -x $opt_b ) {
    49 unless ( -x $opt_b ) {
    51     print "AVWEBGATE CRITICAL: AntiVir WebGate not found or not executable - $opt_b\n";
    50     print "AVWEBGATE CRITICAL: AntiVir WebGate not found or not executable - $opt_b\n";
    52     exit $ERRORS{"CRITICAL"};
    51     exit $ERRORS{"CRITICAL"};
    53 }
    52 }
    54 
    53 
    55 # download the webside
    54 { 
    56 push @webside, split("\n", get($opt_u));
    55 	get($opt_u) =~ /$opt_s/;
    57 
    56 	unless ($version = $1) {
    58 foreach (@webside) {
    57 		print "AVWEBGATE CRITICAL: cannot get version info from avira server\n";
    59 	unless ($found) {
    58 		exit $ERRORS{"CRITICAL"};
    60 		/$opt_s/ or next;
       
    61 		$found = 1;
       
    62 		next;
       
    63 	}
    59 	}
    64 	/Version:\s([\d\.-]+).*/ or next;
       
    65 	$version = $1 and last;
       
    66 }
    60 }
    67 
    61 
    68 unless ($version) {
    62 {
    69 	print "AVWEBGATE CRITICAL: cannot get version info from avira server\n";
    63 	qx(LANG= $opt_b --version) =~ /product version:\s*(\S+)/;
    70 	exit $ERRORS{"CRITICAL"};
    64 	unless ($current_version = $1) {
       
    65 		print "AVWEBGATE CRITICAL: cannot get local version info\n";
       
    66 		exit $ERRORS{"CRITICAL"};
       
    67 	}
    71 }
    68 }
    72 
       
    73 $_ = `$opt_b --version`;
       
    74 if ($_ =~ /product version:\s+(\S+)/) { $current_version = $1; }
       
    75 
    69 
    76 $result = ($current_version eq $version) ? "OK" : "WARNING";
    70 $result = ($current_version eq $version) ? "OK" : "WARNING";
    77 
    71 
    78 if ($result eq "WARNING") {
    72 if ($result eq "WARNING") {
    79 	$message = "new version available: $version";
    73 	$message = "new version available: $version";
    97     print "Copyright (c) 2008 Christian Arnold\n\n";
    91     print "Copyright (c) 2008 Christian Arnold\n\n";
    98     print "This plugin checks for new versions of Avira AntiVir WebGate.\n\n";
    92     print "This plugin checks for new versions of Avira AntiVir WebGate.\n\n";
    99     print_usage();
    93     print_usage();
   100     print "\n";
    94     print "\n";
   101     print "  -b, --binary <binary>\n";
    95     print "  -b, --binary <binary>\n";
   102     print "     Path of AntiVir WebGate binary (default: /usr/lib/AntiVir/avwebgate.bin)\n";
    96     print "     Path of AntiVir WebGate binary (default: $opt_b)\n";
   103     print "  -u, --url <url>\n";
    97     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";
    98     print "     URL where will be look for the search string (default: $opt_u)\n";
   105     print "  -s, --search <search>\n";
    99     print "  -s, --search <search>\n";
   106     print "     Search string on the url (default: >Avira AntiVir UNIX WebGate<)\n";
   100     print "     Search string on the url - put the pattern matching the version in parenthesis like 'optionalprefix(theversion)optionalpostfix' (default: $opt_s)\n";
   107     print "\n";
   101     print "\n";
   108     support();
       
   109 }
   102 }