* removed usage of 'support()' because it recommends asking on the nagios
authorMatthias Förste <foerste@schlittermann.de>
Fri, 01 Jul 2011 12:29:56 +0200
changeset 5 e061bc121954
parent 4 1e812db5da23
child 6 81d0c7d2823d
* removed usage of 'support()' because it recommends asking on the nagios list in case of problems with this plugin * changed url and search pattern and version detection mechanism * display actual defaults with -h unless they have been overridden on the commandline ;)
check_avwebgate.pl
--- a/check_avwebgate.pl	Thu Oct 30 08:18:50 2008 +0000
+++ b/check_avwebgate.pl	Fri Jul 01 12:29:56 2011 +0200
@@ -8,7 +8,7 @@
 use LWP::Simple;
 
 use lib "/usr/lib/nagios/plugins";
-use utils qw (%ERRORS &print_revision &support);
+use utils qw (%ERRORS &print_revision);
 
 sub print_help();
 sub print_usage();
@@ -16,10 +16,9 @@
 my $ME = basename $0;
 my ( $opt_u, $opt_s, $opt_V, $opt_h, $opt_b );
 my ( $result, $found, $message, $version, $current_version );
-my ( @webside );
 
-$opt_u = "http://www.avira.de/de/downloads/avira_antivir_webgate.html";
-$opt_s = ">Avira AntiVir WebGate / Avira WebGate Suite<";
+$opt_u = 'http://www.avira.com/de/support-download-avira-antivir-webgate';
+$opt_s = '<a.*>Avira AntiVir WebGate / Avira WebGate Suite</a>.*(?:\n.*){4}<td>(\d+\.\d+\.\d+\.[\d-]+)</td>';
 $opt_b = "/usr/lib/AntiVir/avwebgate.bin";
 
 Getopt::Long::Configure('bundling');
@@ -52,27 +51,22 @@
     exit $ERRORS{"CRITICAL"};
 }
 
-# download the webside
-push @webside, split("\n", get($opt_u));
-
-foreach (@webside) {
-	unless ($found) {
-		/$opt_s/ or next;
-		$found = 1;
-		next;
+{ 
+	get($opt_u) =~ /$opt_s/;
+	unless ($version = $1) {
+		print "AVWEBGATE CRITICAL: cannot get version info from avira server\n";
+		exit $ERRORS{"CRITICAL"};
 	}
-	/Version:\s([\d\.-]+).*/ or next;
-	$version = $1 and last;
 }
 
-unless ($version) {
-	print "AVWEBGATE CRITICAL: cannot get version info from avira server\n";
-	exit $ERRORS{"CRITICAL"};
+{
+	qx(LANG= $opt_b --version) =~ /product version:\s*(\S+)/;
+	unless ($current_version = $1) {
+		print "AVWEBGATE CRITICAL: cannot get local version info\n";
+		exit $ERRORS{"CRITICAL"};
+	}
 }
 
-$_ = `$opt_b --version`;
-if ($_ =~ /product version:\s+(\S+)/) { $current_version = $1; }
-
 $result = ($current_version eq $version) ? "OK" : "WARNING";
 
 if ($result eq "WARNING") {
@@ -99,11 +93,10 @@
     print_usage();
     print "\n";
     print "  -b, --binary <binary>\n";
-    print "     Path of AntiVir WebGate binary (default: /usr/lib/AntiVir/avwebgate.bin)\n";
+    print "     Path of AntiVir WebGate binary (default: $opt_b)\n";
     print "  -u, --url <url>\n";
-    print "     URL where will be look for the search string (default: http://www.avira.com/de/downloads/avira_antivir_unix_webgate.html)\n";
+    print "     URL where will be look for the search string (default: $opt_u)\n";
     print "  -s, --search <search>\n";
-    print "     Search string on the url (default: >Avira AntiVir UNIX WebGate<)\n";
+    print "     Search string on the url - put the pattern matching the version in parenthesis like 'optionalprefix(theversion)optionalpostfix' (default: $opt_s)\n";
     print "\n";
-    support();
 }