--- /usr/lib/pnp4nagios/process_perfdata.pl.orig 2009-01-08 19:37:56.000000000 +0300 +++ /usr/lib/pnp4nagios/process_perfdata.pl 2009-01-21 03:06:54.000000000 +0300 @@ -29,6 +29,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 $dstype); @@ -313,6 +314,8 @@ my @ds_create = (); my $ds_update = ''; + my $minval = ''; + my $maxval = ''; for my $i ( 0 .. $#data ) { print_log( " -- Job $i ", 3 ); @@ -326,7 +329,23 @@ print_log( " -- $job -> $data[$i]{$job}", 3 ); } } - push( @ds_create, "DS:$DS:$data[$i]{dstype}:$conf{RRD_HEARTBEAT}:U:U" ); + + if (defined $data[$i]{min} && $data[$i]{useminval} == 1) { + print_log( " -- minval defined, useminval enabled; minval -> $data[$i]{min}",3) ; + $minval = $data[$i]{min}; + }else{ + print_log( " -- minval not defined or useminval disabled, using U",3) ; + $minval = "U"; + } + if (defined $data[$i]{max} && $data[$i]{usemaxval} ) { + print_log( " -- maxval defined, usemaxval enabled; maxval -> $data[$i]{max}",3) ; + $maxval = $data[$i]{max}; + }else{ + print_log( " -- maxval not defined or usemaxval disabled, using U",3) ; + $maxval = "U"; + } + + push( @ds_create, "DS:$DS:$data[$i]{dstype}:$conf{RRD_HEARTBEAT}:$minval:$maxval" ); $ds_update = "$ds_update:$data[$i]{value}"; write_to_template( "TEMPLATE", $data[0]{template} ); write_to_template( "IS_MULTI", $data[0]{multi} ); @@ -494,6 +513,7 @@ my $command = shift; my $uom = shift; my $count = shift; + #print_log ("command is $command, uom is $uom, count is $count",3); my @dstype_list = (); if ( $uom eq "c" ) { $dstype = "COUNTER"; @@ -502,6 +522,8 @@ else { $dstype = "GAUGE"; } + my $usemaxval = 0; + my $useminval = 0; my @temp_template = split /\!/, $command; my $template = cleanup( $temp_template[0] ); my $template_cfg = "$conf{CFG_DIR}/check_commands/$template.cfg"; @@ -527,11 +549,57 @@ print_log( "Adapting RRD Datatype to \"$dstype\" as defined in $template_cfg", 2 ); } else { - print_log( "RRD Datatype \"$dstype\” defined in $template_cfg is invalid", 2 ); + print_log( "RRD Datatype \"$dstype\" defined in $template_cfg is invalid", 2 ); $dstype = $initial_dstype; } - } + + #this block checks should we set max limit when creating rrd or not + #record format is: USE_MAX_ON_RRDCREATE = 1,1,0,1... + #where 1 is positinal parameter for corresponding datasource + if ( $1 eq "USE_MAX_ON_RRDCREATE" ) { + #$dstype = uc($2); + #$dstype =~ s/ //g; + my @usemax_list = split /,/, $2; + if ( exists $usemax_list[$count] && $usemax_list[$count] eq "1" ) { + #$dstype = $dstype_list[$count]; + $usemaxval=1; + print_log("Adapting template - usage of MAX value of performance data is enabled in $template_cfg for key $count", 2); + #print_log( "Adapting RRD Datatype to \"$dstype\" as defined in $template_cfg with key $count", 2 ); + } + else { + my $definedkey = ""; + if ( exists $usemax_list[$count] ) { + $definedkey = $usemax_list[$count]; + } + print_log( "Adapting template - MAX value should be ignored as defined in $template_cfg for key $count, value \"$definedkey\"", 2 ); + #$dstype = $initial_dstype; + } + } + + #this block checks should we set min limit when creating rrd or not + #record format is: USE_MIN_ON_RRDCREATE = 1,1,0,1... + #where 1 is positinal parameter for corresponding datasource + if ( $1 eq "USE_MIN_ON_RRDCREATE" ) { + #$dstype = uc($2); + #$dstype =~ s/ //g; + my @usemin_list = split /,/, $2; + if ( exists $usemin_list[$count] && $usemin_list[$count] eq "1" ) { + #$dstype = $dstype_list[$count]; + $useminval=1; + print_log("Adapting template - usage of MIN value of performance data is enabled in $template_cfg for key $count", 2); + #print_log( "Adapting RRD Datatype to \"$dstype\" as defined in $template_cfg with key $count", 2 ); + } + else { + my $definedkey = ""; + if ( exists $usemin_list[$count] ) { + $definedkey = $usemin_list[$count]; + } + print_log( "Adapting template - MIN value should be ignored as defined in $template_cfg for key $count, value \"$definedkey\"", 2 ); + #$dstype = $initial_dstype; + } + } + if ( $1 eq "CUSTOM_TEMPLATE" ) { print_log( "Adapting Template using ARG $2", 2 ); my $i = 1; @@ -558,7 +626,7 @@ print_log( "RRD Datatype is $dstype", 2 ); } print_log( "Template is $template.php", 2 ); - return $template, $dstype; + return $template, $dstype, $usemaxval, $useminval; } # @@ -739,10 +807,14 @@ data2rrd(@perfs) if ( $#perfs >= 0 ); # Process when a new block starts. @perfs = (); # Clear the perfs array. } - ( $p{template}, $dstype ) = adjust_template( $multi[1], $p{uom}, $count ); + my $usemaxval = 0; + my $useminval = 0; + ( $p{template}, $dstype, $usemaxval, $useminval ) = adjust_template( $multi[1], $p{uom}, $count ); $p{dstype} = $dstype; $p{label} = cleanup( $multi[2] ); # store the original label from check_multi header $p{hostname} = cleanup($HOSTNAME); + $p{usemaxval} = $usemaxval; + $p{useminval} = $useminval; push @perfs, {%p}; $count++; } @@ -776,14 +848,17 @@ @perfs = (); last; } - - ( $p{template}, $dstype ) = adjust_template( $CHECK_COMMAND, $p{uom}, $count ); + my $usemaxval = 0; + my $useminval = 0; + ( $p{template}, $dstype, $usemaxval, $useminval ) = adjust_template( $CHECK_COMMAND, $p{uom}, $count ); $p{multi} = $is_multi; $p{dstype} = $dstype; $p{hostname} = cleanup($HOSTNAME); $p{servicedesc} = cleanup($SERVICEDESC); $p{label} = cleanup( $p{label} ); + $p{usemaxval} = $usemaxval; + $p{useminval} = $useminval; push @perfs, {%p}; $count++;