#!/usr/bin/perl # # check_apache_watch - Apache mod_watch monitoring Nagios plugin # version 1.0 13.11.2012 # by Mikanoshi - iam@mikanoshi.name, http://en.mikanoshi.name # # Plugin arguments: # 1: watch-list URL, e.g. http://login:pass@example.org:8080/watch-list?auto # 2: Comma-separated list of hosts to monitor # # This Nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. # It may be used, redistributed and/or modified under the terms of the # GNU General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt). my $ret = undef; if (!eval "require LWP::UserAgent;") { $ret = "LWP::UserAgent not found"; } my $URL = exists $ARGV[0] ? $ARGV[0] : "http://127.0.0.1:80/watch-list?auto"; my @domains = split(',', $ARGV[1]); my @servers = (); my @data; my $ua = LWP::UserAgent->new (timeout => 10); my $response = $ua->request (HTTP::Request->new ('GET', $URL)); if ($response->is_success) { if ($response->code == 200) { print "OK - data received"; } else { print "CRITICAL - Response code: ", $response->code; } } else { print "CRITICAL - Cannot open watch-list url"; } foreach my $string (split (/\n/, $response->content)) { my ($server, undef, $ifInOctets, $ifOutOctets, $ifRequests, $ifDocuments) = split (/\s/, $string, 6); push @servers, $server unless $server eq "SERVER"; push @data, "$server $ifRequests $ifDocuments" unless $server eq "SERVER"; } print " |"; foreach my $string (sort (@data)) { my ($server, $ifRequests, $ifDocuments) = split (/\s/, $string); if (grep $_ eq $server, @domains) { (my $txtserver = $server) =~ s/(-|\.)/\_/g; print " '${txtserver}::docs'=", $ifDocuments, "c;;; ${txtserver}::reqs'=", $ifRequests, "c;;;"; } } print "\n";