diff -r de2bb3e58e60 -r 7cb0168453d4 monitoring/nagios/scripts/process_perfdata.pl --- a/monitoring/nagios/scripts/process_perfdata.pl Wed Nov 26 15:34:28 2008 +0300 +++ b/monitoring/nagios/scripts/process_perfdata.pl Wed Nov 26 15:35:40 2008 +0300 @@ -28,6 +28,7 @@ use warnings; use strict; use Getopt::Long; +use Switch; use Time::HiRes qw(gettimeofday tv_interval); use vars qw ( $PERFDATA $TEMPLATE %NAGIOS $SERVICEDESC $HOSTNAME $CHECK_COMMAND $count $line @lines $t @t $name $xact $warn $crit $min $max $unit $act $ds_create $ds_update @rrd_create $rrd_update $type); @@ -282,6 +283,8 @@ my @ds_create = (); my $ds_update = ''; + my $minval = ''; + my $maxval = ''; for my $i ( 0 .. $#data ) { print_log( " -- Job $i ",3); @@ -294,7 +297,24 @@ print_log( " -- $job -> $data[$i]{$job}",3) ; } } - push(@ds_create, "DS:$DS:$data[$i]{dstype}:8640:U:U"); + + if (defined $data[$i]{min}) { + print_log( " minval defined -> $data[$i]{min}",3) ; + $minval = $data[$i]{min}; + }else{ + print_log( " minval not defined",3) ; + $minval = "U"; + } + + if (defined $data[$i]{max}) { + print_log( " maxval defined -> $data[$i]{max}",3) ; + $maxval = $data[$i]{max}; + }else{ + print_log( " maxval not defined",3) ; + $maxval = "U"; + } + + push(@ds_create, "DS:$DS:$data[$i]{dstype}:8640:$minval:$maxval"); $ds_update="$ds_update:$data[$i]{value}"; write_to_template("TEMPLATE", $data[0]{template}); write_to_template("DS", $DS); @@ -605,8 +625,23 @@ sub find_dstype { my $uom = shift; - my $dstype = "GAUGE"; - $dstype = "COUNTER" if ( $uom eq "c"); + my $template_dstype = shift; + #template_dstype stands for DATATYPE from /etc/nagios-pnp/check_commands/template.cfg + #if we have one defined there we should use it, isn't it? + my $dstype = ""; + + switch ($template_dstype) { + #let's do some sanity check... + case "DERIVE" {print_log("DEBUG: find_dstype found DERIVE ",3);$dstype = $template_dstype} + case "ABSOLUTE" {print_log("DEBUG: find_dstype found ABSOLUTE ",3);$dstype = $template_dstype} + case "GAUGE" {print_log("DEBUG: find_dstype found GAUGE",3);$dstype = $template_dstype} + case "COUNTER" {print_log("DEBUG: find_dstype found COUNTER",3);$dstype = $template_dstype} + else { + print_log("DEBUG: find_dstype in UNKNOWN or EMPTY, falling back to GAUGE",3); + $dstype = "GAUGE"; + $dstype = "COUNTER" if ( $uom eq "c"); + } + } return $dstype } # @@ -647,7 +682,7 @@ } ($p{template}, $p{dstype} ) = adjust_template($multi[1],$p{uom}); $p{multi} = $is_multi; - $p{dstype} = find_dstype($p{uom}); + $p{dstype} = find_dstype($p{uom}, $p{dstype}); $p{label} = cleanup($multi[2]); # store the original label from check_multi header $p{hostname} = cleanup($HOSTNAME); push @perfs, { %p }; @@ -656,7 +691,7 @@ print_log("DEBUG: Next check_multi data for block $count",3); # additional check_multi data $p{multi} = $is_multi; - $p{dstype} = find_dstype($p{uom}); + $p{dstype} = find_dstype($p{uom}, $p{dstype}); $p{hostname} = cleanup($HOSTNAME); $p{servicedesc} = cleanup($multi[0]); # Use the multi servicedesc. $p{label} = cleanup($p{label}) ; @@ -678,12 +713,12 @@ @perfs=() ; last; } - if($count eq 0 ){ + #if($count eq 0 ){ ( $p{template}, $p{dstype} ) = adjust_template($CHECK_COMMAND, $p{uom}); - } + #} $p{multi} = $is_multi; - $p{dstype} = find_dstype($p{uom}); + $p{dstype} = find_dstype($p{uom}, $p{dstype}); $p{hostname} = cleanup($HOSTNAME); $p{servicedesc} = cleanup($SERVICEDESC); $p{label} = cleanup($p{label});