--- process_perfdata.pl.orig 2006-11-01 07:10:44.000000000 +0100 +++ process_perfdata.pl 2006-11-01 19:12:59.000000000 +0100 @@ -26,6 +26,7 @@ use warnings; use strict; +use Sys::Syslog; use vars qw ($count $line @lines $t @t $name $xact $warn $crit $min $max $unit $act $ds_create $ds_update $rrd_create $rrd_update $type); my $version = '$Id: process_perfdata.pl 82 2006-09-24 11:51:53Z linge $'; @@ -72,6 +73,8 @@ my $type = ""; +openlog("process_perfdata.pl", "pid", "user"); + # # If $NAGIOS_SERVICEPERFDATA is not set # @@ -79,6 +82,7 @@ if (!$NAGIOS_SERVICEPERFDATA){ print_log ("No Performance Data for $NAGIOS_HOSTNAME / $NAGIOS_SERVICEDESC ") if($log_level == 1); print_log ("PNP exiting ...") if($log_level == 1); + closelog(); exit 1; }else{ print_log ("found Performance Data for $NAGIOS_HOSTNAME / $NAGIOS_SERVICEDESC ( $NAGIOS_SERVICEPERFDATA ) ") if($log_level == 1); @@ -141,25 +145,38 @@ unless (mkdir "$rrdpath"){ print_log ("mkdir $rrdpath, permission denied ") if($log_level == 1); print_log ("PNP exiting ...") if($log_level == 1); + syslog("err", "mkdir $rrdpath, permission denied - exiting"); + closelog(); exit 1; } } +# strip leading blanks, because of performance data of check_snmp_storage +$NAGIOS_SERVICEPERFDATA=~s/^ *//; -my @t = split /=/,$NAGIOS_SERVICEPERFDATA; # Perfdata beim = splitten -my $t = shift @t; # Alles bis zum 1. = als $t -if ( $t =~ /^('.*)/ ) { - print_log ("Perfdata contains spaces ($NAGIOS_SERVICEPERFDATA) processing ...") if($log_level == 1); - @lines = split(/ '/, $NAGIOS_SERVICEPERFDATA); +my $search_pattern; +$search_pattern="(PREFIX=[0-9\.]+(B|kB|MB|GB|TB|PB|s|ms|us|ns|%|c|)"; +$search_pattern.="(;([0-9\.]+:?|~:[0-9\.]+|@?[0-9\.]+:[0-9\.]+)*){0,2}"; +$search_pattern.="(;([0-9\.]+)*){0,2};?) ?"; -}elsif ( $t =~ /(.*\s+.*)/ ) { - print_log ("Perfdata contains spaces ($NAGIOS_SERVICEPERFDATA) check illegal_macro_otput_chars in nagios.cfg") if($log_level == 1); - print_log ("PNP exiting ...") if($log_level == 1); - exit 1; -}else{ - print_log ("Perfdata is valid ($NAGIOS_SERVICEPERFDATA) ") if($log_level == 1); - @lines = split(/ /, $NAGIOS_SERVICEPERFDATA); +if ($NAGIOS_SERVICEPERFDATA=~/^'/) { + $search_pattern=~s/PREFIX/'[^']+'/; +} else { + $search_pattern=~s/PREFIX/[^= ]+/; +} + +while ($NAGIOS_SERVICEPERFDATA=~/$search_pattern/g) { + push (@lines, $1); +} + +if ($#lines==-1) { + print_log ("Perfdata not valid ($NAGIOS_SERVICEPERFDATA)") if ($log_level == 1); + syslog("err", "Perfdata not valid ($NAGIOS_SERVICEPERFDATA) - exiting"); + closelog(); + exit 1; +} else { + print_log ("Perfdata is valid ($NAGIOS_SERVICEPERFDATA)") if ($log_level == 1); } @@ -170,6 +187,8 @@ unless (mkdir "$rrdpath/$HOSTNAME"){ print_log ("mkdir $rrdpath/$HOSTNAME, permission denied ") if($log_level == 1); print_log ("PNP exiting ...") if($log_level == 1); + syslog("err", "mkdir $rrdpath/$HOSTNAME, permission denied - exiting"); + closelog(); exit 1; } } @@ -229,6 +248,37 @@ $max =~ s/,/\./g ; $warn =~ s/,/\./g ; $crit =~ s/,/\./g ; + my $factor=1; + if ($unit eq 'KB') { + $factor=1024; + $unit='B'; + } elsif ($unit eq 'MB') { + $factor=1024*1024; + $unit='B'; + } elsif ($unit eq 'GB') { + $factor=1024*1024*1024; + $unit='B'; + } elsif ($unit eq 'TB') { + $factor=1024*1024*1024*1024; + $unit='B'; + } elsif ($unit eq 'PB') { + $factor=1024*1024*1024*1024*1024; + $unit='B'; + } elsif ($unit eq 'ms') { + $factor=1.0/1000.0; + $unit="s"; + } elsif ($unit eq 'us') { + $factor=1.0/1000000.0; + $unit="s"; + } elsif ($unit eq 'ns') { + $factor=1.0/1000000000.0; + $unit="s"; + } + $act=$act*$factor; + $min=$min*$factor; + $max=$max*$factor; + $warn=$warn*$factor; + $crit=$crit*$factor; $ds_create = "$ds_create DS:$count:$type:8640:U:U "; $ds_update = "$ds_update:$act"; @@ -276,6 +326,7 @@ # if(!-e "$rrdpath/$HOSTNAME/$SERVICEDESC.rrd"){ print_log ("$rrdtool create $rrdpath/$HOSTNAME/$SERVICEDESC.rrd --step 60 $ds_create ...") if($log_level == 1); + my $ret; system("$rrd_create"); print_log ("rrdtool create returns $?") if($log_level == 1); # Und gleich ein update hinterher .. @@ -284,7 +335,7 @@ print_log ("rrdtool update returns $?") if($log_level == 1); }else{ print_log ("$rrdtool update $rrdpath/$HOSTNAME/$SERVICEDESC.rrd $NAGIOS_TIMET$ds_update") if($log_level == 1); - system("$rrd_update"); + system("$rrd_update >> /tmp/test.test 2>&1"); print_log ("rrdtool update returns $?") if($log_level == 1); } # Write to Logfile @@ -297,4 +348,5 @@ close (LOG); } print_log ("PNP exiting ...") if($log_level == 1); +closelog(); exit 0;