#!/bin/perl -w # ---------------------------------------------------------------------- # $Id: checkmf.pl,v 1.6 2007/06/20 21:10:38 arons Exp $ # ---------------------------------------------------------------------- use Getopt::Std; $CERT = "/usr/local/nagios/etc/ssl/nagios.crt"; $KEY = "/usr/local/nagios/etc/ssl/nagios.key"; $WGET="/usr/local/bin/wget"; $WARGS=" -q "; $TMPDIR="/usr/local/nagios/var/tmp/"; # defaults: # timestamp older than 20 minutes $timestampc = 50*60;#-t # spam or virus update older than 20 minutes $upc = 20*60;#-s $upv = 1*24*60*60;#-s # loadavg greater than 95 $loadc = 95;#-l # in out unscan greater than 500 $inquec = 500;#-i $outquec = 500;#-o $unsquec = 500;#-u # RAID other than clean #Supply URL and host if( (@ARGV == 0) or ($ARGV[1] eq "-h") ) { print "Usage:\n"; print "Required: \t-a hostname\n"; print "\t\t-g URL to retrieve\n"; print "Optional:\n"; print "\t\t-c Use default cert and key for https urls\n"; print "\t\t-t Max timestamp age in minutes\n"; print "\t\t-s Spam definition age in minutes\n"; print "\t\t-v Virus definition age in minutes\n"; print "\t\t-l Max load average\n"; print "\t\t-i Max incoming queue size\n"; print "\t\t-o Max outgoing queue size\n"; print "\t\t-u Max unscanned queue size\n"; exit(); } getopts("ct:s:l:i:o:u:g:a:v:", \%opt); if( $opt{c} ) { $WARGS = " -q --sslcertfile=$CERT --sslcertkey=$KEY "; } if( $opt{g} ) {$url = $opt{g};} else { print "Need URL (-g)\n"; exit(2); } if( $opt{a} ) {$host = $opt{a};} else { print "Need host (-a)\n"; exit(2); } if( $opt{t} ) { $timestampc = $opt{t}*60*60; } if( $opt{s} ) { $upc = $opt{s}*60*60; } if( $opt{v} ) { $upv = $opt{v}*60*60; } if( $opt{l} ) { $loadc = $opt{l}; } if( $opt{i} ) { $inquec = $opt{i}; } if( $opt{o} ) { $outquec = $opt{o}; } if( $opt{u} ) { $unsquec = $opt{u}; } #Compose wget command $command = $WGET.$WARGS."-O ".$TMPDIR.$host.".outfile ".$url; #Run it system($command); open(FILE, $TMPDIR.$host.".outfile") or die "outfile unavailable: $!"; #Process outfile, storing data in vars when we see it while() { if(/Timestamp.*\[(.*)\]/) { $timestamp = $1; } if(/Last Spam Update.*\[(.*)\]/) { $spamup = $1; } if(/Last Virus Update.*\[(.*)\]/) { $virusup = $1; } if(/System Load Avg \[1 minute\]: ([0-9]*\.[0-9]*) %/) { $sysla = $1; } if(/System Load Avg \[5 minute\]: ([0-9]*\.[0-9]*) %/) { $syslb = $1; } if(/System Load Avg \[15 minute\]: ([0-9]*\.[0-9]*) %/) { $syslc = $1; } if(/Queue Count \[outgoing\]: ([0-9]*)/) { $queout = $1; } if(/Queue Count \[unscanned\]: ([0-9]*)/) { $queun = $1; } if(/Queue Count \[incoming\]: ([0-9]*)/) { $quein = $1; } #Not currently used # if(/Queue Count \[quarantine\]: ([0-9]*)/) # { $quequar = $1; } if(/Raid 1 State:\s*(.*)/) { $raid = $1; } } close(FILE); #Check variables $curtime = time(); $alarmv=0; $alarmc=""; if( ($curtime-$timestamp) > $timestampc ) { $alarmv=1; $alarmc=$alarmc.":timestamp(". int (($curtime - $timestamp) / 60) ."m old)"; } if( ($timestamp-$spamup) > $upc ) { $alarmv=1; $alarmc=$alarmc.":spamupdate(". int (($timestamp - $spamup) / 60) ."m old)"; } if( ($timestamp-$virusup) > $upv ) { $alarmv=1; $alarmc=$alarmc.":virusupdate". int (($timestamp - $virusup) / 60) ."m old)"; } if($sysla > $loadc ) { $alarmv=1; $alarmc=$alarmc.":SysLA1m"; } if($syslb > $loadc ) { $alarmv=1; $alarmc=$alarmc.":SysLA5m"; } if($syslc > $loadc ) { $alarmv=1; $alarmc=$alarmc.":SysLA15m"; } if($queout > $outquec ) { $alarmv=1; $alarmc=$alarmc.":QueueOut#".$queout; } if($quein > $inquec ) { $alarmv=1; $alarmc=$alarmc.":QueueIn#".$quein; } if($queun > $unsquec ) { $alarmv=1; $alarmc=$alarmc.":QueueUns#".$queun; } if(($raid) and ($raid ne "clean" and $raid ne "dirty" and $raid ne "OK") ) { $alarmv=1; $alarmc=$alarmc.":RAID(".$raid.")"; } #Print status if( $alarmv == 0) { print "OK\n"; exit(0); } else { print $alarmc."\n"; exit(2); }