Revision: 296
http://pnp4nagios.svn.sourceforge.net/pnp4nagios/?rev=296&view=rev
Author: pitchfork
Date: 2007-08-24 23:05:47 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
process_perfdata rewrite. Please test and report bugs
Modified Paths:
--------------
trunk/ChangeLog
trunk/scripts/process_perfdata.pl.in
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-08-16 08:10:19 UTC (rev 295)
+++ trunk/ChangeLog 2007-08-25 06:05:47 UTC (rev 296)
@@ -1,6 +1,11 @@
Last changed: $Id$
**SVN Current:**
+ * process_perfdata rewrite.
+ * Parser used from Nagios::Plugin::Performance.
+ * Added support for Host Perfdata processing in bulk and default mode.
+ * Code cleanup.
+ * The use of RRDs Perl module is now default.
* Support for check_multi Plugin added.
* New PDF Function for all views.
* Complete internal rewrite.
Modified: trunk/scripts/process_perfdata.pl.in
===================================================================
--- trunk/scripts/process_perfdata.pl.in 2007-08-16 08:10:19 UTC (rev 295)
+++ trunk/scripts/process_perfdata.pl.in 2007-08-25 06:05:47 UTC (rev 296)
@@ -21,7 +21,7 @@
#
if ($< == 0){
- print "don\xB4t try this as root \n";
+ print "dont try this as root \n";
exit 1;
}
@@ -29,13 +29,13 @@
use strict;
use Getopt::Long;
use Time::HiRes qw(gettimeofday tv_interval);
-use vars qw ( $PERFDATA $TEMPLATE %NAGIOS $SERVICEDESC $HOSTNAME $count $line @lines $t @t $name $xact $warn $crit $min $max $unit $act $ds_create $ds_update @rrd_create $rrd_update $type);
+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);
my %conf = (
VERSION => "@PACKAGE_VERSION@",
TIMEOUT => "5",
CFG_DIR => "@CFG_DIR@",
- USE_RRDs => 0,
+ USE_RRDs => 1,
RRDPATH => "@PERFDATA_DIR@",
RRDTOOL => "@RRDTOOL@",
RRA_STEP => 60,
@@ -56,6 +56,8 @@
}
}
+
+
#
# "rrdtool create" Syntax
#
@@ -76,9 +78,8 @@
Getopt::Long::Configure('bundling');
-my ($opt_V, $opt_h, $opt_i, $opt_b);
+my ($opt_d, $opt_V, $opt_h, $opt_i, $opt_b);
my $opt_t=$conf{TIMEOUT}; # Default Timeout
-my $opt_d="SERVICEPERFDATA";
GetOptions(
"V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
@@ -103,7 +104,7 @@
#
# Subs
#
-
+# Main function to switch to the right mode.
sub main {
my $t0 = [gettimeofday];
if($opt_i){
@@ -116,7 +117,7 @@
}else{
print_log("process_perfdata.pl-$conf{VERSION} starting in DEFAULT Mode",1);
%NAGIOS = parse_env();
- check_perfdata();
+ process_perfdata();
}
my $t1 = [gettimeofday];
my $rt = tv_interval $t0, $t1;
@@ -124,20 +125,124 @@
exit 0;
}
-sub process_data2rrd {
- #my @lines = check_perfdata();
- my $type = "GAUGE";
- #
- # Strip Chars.
- #
+#
+# Parse %ENV and return an global hash %NAGIOS
+#
+sub parse_env {
- $SERVICEDESC =~ s/[: \/]/_/g ;
- $HOSTNAME =~ s/[: \/]/_/g ;
+ $NAGIOS{DATATYPE} = "SERVICEPERFDATA";
+ if($opt_i){
+ my @input=<STDIN>;
+ foreach my $key(@input){
+ $key =~ s/([&])/sprintf("%%%02x",ord($1))/eg; # URLencode
+ $key =~ /<(NAGIOS_[A-Z 0-9_]+)>(.*)<\/NAGIOS_.*>/ ;
+ $ENV{$1}=$2 if($2);
+ }
+ }
- #
- # If $conf{RRDPATH} doesn`t exist -> create it.
- #
+ if(!$ENV{NAGIOS_HOSTNAME}){
+ print_log("Cant find Nagios Envirionment. Exiting ....",1);
+ exit 2;
+ }
+ foreach my $key (sort keys %ENV) {
+ if ( $key =~ /^NAGIOS_(.*)/ ) {
+ $NAGIOS{$1} = $ENV{$key};
+ }
+ }
+
+ if($opt_d){
+ $NAGIOS{DATATYPE} = $opt_d;
+ }
+
+ print_log("DEBUG: DATATYPE -> $NAGIOS{DATATYPE} ",3);
+
+ $HOSTNAME = $NAGIOS{HOSTNAME};
+ $SERVICEDESC = $NAGIOS{SERVICEDESC};
+ $PERFDATA = $NAGIOS{SERVICEPERFDATA};
+ $CHECK_COMMAND = $NAGIOS{SERVICECHECKCOMMAND};
+
+ if($NAGIOS{DATATYPE} eq "HOSTPERFDATA"){
+ $SERVICEDESC = "_HOST_";
+ $PERFDATA = $NAGIOS{HOSTPERFDATA};
+ $CHECK_COMMAND = $NAGIOS{HOSTCHECKCOMMAND};
+ print_log("Datatype set to 'HOSTPERFDATA' ",2);
+ }
+
+ print_log("Datatype set to 'SERVICEPERFDATA' ",2);
+
+ return %NAGIOS;
+}
+
+#
+# Perfdata sanity check
+#
+sub process_perfdata {
+ if (!$PERFDATA){
+ print_log ("No Performance Data for $NAGIOS{HOSTNAME} / $NAGIOS{SERVICEDESC} ",1);
+ if(!$opt_b){
+ print_log ("PNP exiting ...",1);
+ exit 1;
+ }
+ }
+ $PERFDATA =~ s/,/./g;
+ $PERFDATA =~ s/\s+=/=/g;
+ $PERFDATA =~ s/=\s+/=/g;
+ $PERFDATA .= " ";
+ parse_perfstring($PERFDATA);
+}
+
+#
+# Process Perfdata in Bulk Mode
+#
+sub process_perfdata_file {
+ print_log("searching for $opt_b",2);
+ if(-e $opt_b){
+ my $pdfile = $opt_b."-PID-".$$;
+ print_log("renaming $opt_b to $pdfile for bulk update",2);
+ unless ( rename $opt_b,$pdfile ){
+ print_log ("ERROR: rename $opt_b to $pdfile failed",1);
+ exit 1;
+ }
+
+ print_log("reading $pdfile for bulk update",2);
+ open(PDFILE, "< $pdfile");
+ my $count=0;
+ while (<PDFILE>) {
+ $count++;
+ print_log("Processing Line $count",2);
+ my @LINE = split(/\t/);
+ %ENV = (); # cleaning ENV
+ foreach my $k(@LINE){
+ $k =~ /([A-Z 0-9_]+)::(.*)$/ ;
+ $ENV{'NAGIOS_'.$1}=$2 if($2);
+ }
+ if($ENV{NAGIOS_SERVICEPERFDATA} || $ENV{NAGIOS_HOSTPERFDATA}){
+ parse_env();
+ process_perfdata();
+ }else{
+ print_log("No Perfdata. Skipping line $count",2);
+ }
+ }
+ print_log("$count Lines processed",1);
+ unlink $pdfile;
+ print_log("$pdfile deleted",1);
+ }else{
+ print_log("ERROR: File $opt_b not found",1);
+ }
+}
+
+#
+# Write Data to RRD Files
+#
+sub data2rrd {
+
+ my @data = @_;
+ print_log ("data2rrd called",2);
+ $HOSTNAME=$data[0]{hostname};
+ $SERVICEDESC=$data[0]{servicedesc};
+ $TEMPLATE=$data[0]{template};
+
unless ( -d "$conf{RRDPATH}" ) {
unless (mkdir "$conf{RRDPATH}"){
print_log ("mkdir $conf{RRDPATH}, permission denied ",1);
@@ -146,9 +251,6 @@
}
}
- #
- # Create Dir for this Host.
- #
unless ( -d "$conf{RRDPATH}/$HOSTNAME" ) {
unless (mkdir "$conf{RRDPATH}/$HOSTNAME"){
print_log ("mkdir $conf{RRDPATH}/$HOSTNAME, permission denied ",1);
@@ -164,74 +266,32 @@
my @ds_create = ();
my $ds_update = '';
- my $count = 0;
- my (@min, @max, @act, @warn, @crit);
- foreach $line (@lines) {
- $count++;
- print_log ("Turn $count \"$line\"",2);
- $_ = $line ;
- ($name, $xact, $warn, $crit, $min, $max) = split (/[=;]/) ;
- if(!defined $warn ){ $warn='';}
- if(!defined $crit ){ $crit='';}
- if(!defined $min ){ $min='';}
- if(!defined $max ){ $max='';}
-
- ($unit = $xact) =~ s/[0-9.,]+(.*)/$1/ ;
+ for my $i ( 0 .. $#data ) {
+ print_log( " -- Job $i ",3);
+ my $DS = $i+1;
#
- # % to %% .
- #
- if ( $unit =~ /%/ ){
- $unit = "%%";
- print_log ("adapting unit to %%",2);
- }
- #
- #
- #
- ($act = $xact) =~ s/([0-9.,]+).*/$1/ ;
- $name =~ s/[':]//g ;
- $act =~ s/,/\./g ;
+ # Pro Datasource
+ #
+ for my $job ( sort keys %{ $data[$i] } ) {
+ if (defined $data[$i]{$job}){
+ print_log( " -- $job -> $data[$i]{$job}",3) ;
+ }
+ }
+ push(@ds_create, "DS:$DS:$data[$i]{dstype}:8640:U:U");
+ $ds_update="$ds_update:$data[$i]{value}";
+ write_to_template("TEMPLATE", $data[0]{template});
+ write_to_template("DS", $DS);
+ write_to_template("NAME", "$data[$i]{label}");
+ write_to_template("UNIT", $data[$i]{uom});
+ write_to_template("ACT", $data[$i]{value});
+ write_to_template("WARN", $data[$i]{warning});
+ write_to_template("CRIT", $data[$i]{critical});
+ write_to_template("MIN", $data[$i]{min});
+ write_to_template("MAX", $data[$i]{max});
+
+ }
- #
- # unit "c" defines Counter
- #
-
- if ( $unit eq "c" ){
- $type = "COUNTER";
- print_log ("Unit c found. Adapting type to $type ",2);
- }else{
- $type = "GAUGE";
- }
-
- #
- # Adjust the Template name and RRD Datatype if needed.
- #
-
- adjust_template();
-
-
- # If Type is COUNTER ,
- # only Integer values are allowed.
- #
- if ( $type eq "COUNTER" ){
- $act = (int $act);
- print_log ("RRDTool needs integer Values if DS type is $type ",2);
- print_log ("adapting value to $act ",2);
- }
-
- push(@ds_create, "DS:$count:$type:8640:U:U");
- $ds_update="$ds_update:$act";
- write_to_template("TEMPLATE", $TEMPLATE);
- write_to_template("DS", $count);
- write_to_template("NAME", $name);
- write_to_template("UNIT", $unit);
- write_to_template("ACT", $act);
- write_to_template("WARN", $warn);
- write_to_template("CRIT", $crit);
- write_to_template("MIN", $min);
- write_to_template("MAX", $max);
- }
-
write_env_to_template();
close_template();
@@ -278,138 +338,6 @@
}
#
-#
-# Write to Logfile
-sub print_log {
- return if($conf{LOG_LEVEL}==0);
- my $out = shift;
- my $severity = shift;
- if($severity <= $conf{LOG_LEVEL}){
- open (LOG,">>".$conf{LOG_FILE}) || die "Can't open logfile ($conf{LOG_FILE}) ",$!;
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
- printf (LOG "%02d-%02d-%02d %02d:%02d:%02d [%d] %s\n",$year+1900,$mon+1,$mday,$hour,$min,$sec,$$,$out);
- close (LOG);
- }
-}
-
-
-sub process_perfdata_file {
- print_log("searching for $opt_b",2);
- if(-e $opt_b){
- my $pdfile = $opt_b."-PID-".$$;
- print_log("renaming $opt_b to $pdfile for bulk update",2);
- unless ( rename $opt_b,$pdfile ){
- print_log ("ERROR: rename $opt_b to $pdfile failed",1);
- exit 1;
- }
-
- print_log("reading $pdfile for bulk update",2);
- open(PDFILE, "< $pdfile");
- my $count=0;
- while (<PDFILE>) {
- $count++;
- print_log("Processing Line $count",2);
- my @LINE = split(/\t/);
- %ENV = (); # cleaning ENV
- foreach my $k(@LINE){
- $k =~ /([A-Z 0-9_]+)::(.*)$/ ;
- $ENV{'NAGIOS_'.$1}=$2 if($2);
- }
- if($ENV{NAGIOS_SERVICEPERFDATA} || $ENV{NAGIOS_HOSTPERFDATA}){
- parse_env();
- check_perfdata();
- }else{
- print_log("No Perfdata. Skipping line $count",2);
- }
- }
- print_log("$count Lines processed",1);
- unlink $pdfile;
- print_log("$pdfile deleted",1);
- }else{
- print_log("ERROR: File $opt_b not found",1);
- }
-}
-
-
-sub process_perfdata {
- if(check_multi() == 1){
- print_log("processing check_multi Perfdata",1);
- print_log("check_multi data is -> @lines",1);
- my $i = 0;
- my @data = @lines;
- @lines = ();
- foreach (@data){
- if( /^(.*):(.*):(.*=.*)$/){
- if($i > 0){
- print_log("check_multi part [$i] -> $SERVICEDESC -> $TEMPLATE -> @lines",1);
- process_data2rrd();
- @lines = ();
- $SERVICEDESC = $1;
- $TEMPLATE = $2;
- }
- push(@lines, $3);
- $i++;
- }else{
- push(@lines, $_);
- }
- }
- }else{
- process_data2rrd();
- }
-}
-
-sub check_multi {
- if($PERFDATA =~ /^.*:check_multi:/){
- return 1;
- }
- return 0
-}
-
-#
-# Parse %ENV
-#
-sub parse_env {
-
- if($opt_i){
- my @input=<STDIN>;
- foreach my $key(@input){
- $key =~ s/([&])/sprintf("%%%02x",ord($1))/eg; # URLencode
- $key =~ /<(NAGIOS_[A-Z 0-9_]+)>(.*)<\/NAGIOS_.*>/ ;
- $ENV{$1}=$2 if($2);
- }
- }
-
- if(!$ENV{NAGIOS_HOSTNAME}){
- print_log("Cant find Nagios Envirionment. Exiting ....",1);
- exit 2;
- }
- foreach my $key (sort keys %ENV) {
- if ( $key =~ /^NAGIOS_(.*)/ ) {
- $NAGIOS{$1} = $ENV{$key};
- }
- }
-
- if($opt_d){
- $NAGIOS{DATATYPE} = $opt_d;
- }else{
- $NAGIOS{DATATYPE} = "SERVICEPERFDATA";
- }
-
- $HOSTNAME = $NAGIOS{HOSTNAME};
- $SERVICEDESC = $NAGIOS{SERVICEDESC};
- $PERFDATA = $NAGIOS{SERVICEPERFDATA};
- $TEMPLATE = $NAGIOS{SERVICECHECKCOMMAND};
-
- if($NAGIOS{DATATYPE} eq "HOSTPERFDATA"){
- $SERVICEDESC = "_HOST_";
- $PERFDATA = $NAGIOS{HOSTPERFDATA};
- $TEMPLATE = $NAGIOS{HOSTCHECKCOMMAND};
- }
-
- return %NAGIOS;
-}
-
-#
# Write Template
#
sub open_template {
@@ -419,6 +347,7 @@
print XML "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
print XML "<NAGIOS>\n";
}
+
#
# Close Template FH
#
@@ -432,14 +361,17 @@
sub write_to_template {
my $tag = shift;
my $data = shift;
+ if(!defined $data){
+ $data = "";
+ }
if($tag =~ /^TEMPLATE$/){
printf( XML " <DATASOURCE>\n");
- printf( XML " <%s>%s</%s>\n",$tag,$data,$tag);
+ printf( XML " <%s>%s</%s>\n",$tag,"$data",$tag);
}elsif($tag =~ /^MAX$/){
- printf( XML " <%s>%s</%s>\n",$tag,$data,$tag);
+ printf( XML " <%s>%s</%s>\n",$tag,"$data",$tag);
printf( XML " </DATASOURCE>\n");
}else{
- printf( XML " <%s>%s</%s>\n",$tag,$data,$tag);
+ printf( XML " <%s>%s</%s>\n",$tag,"$data",$tag);
}
}
#
@@ -452,117 +384,56 @@
}
}
#
-# Perfdata sanity check
-#
-sub check_perfdata {
- if (!$PERFDATA){
- print_log ("No Performance Data for $NAGIOS{HOSTNAME} / $NAGIOS{SERVICEDESC} ",1);
- if(!$opt_b){
- print_log ("PNP exiting ...",1);
- exit 1;
- }
- }
- if( $PERFDATA =~ /^(.*)\s\[(.*)\]$/ ) {
- $PERFDATA = $1;
- $TEMPLATE = $2 ;
- print_log ("Perfdata from Distributed Server found",2);
- }else{
- print_log ("found Performance Data for $NAGIOS{HOSTNAME} / $NAGIOS{SERVICEDESC} ( $PERFDATA ) ",1);
- }
- @lines = ();
- $PERFDATA =~ s/,/./g;
- $PERFDATA =~ s/\s+=/=/g;
- $PERFDATA =~ s/=\s+/=/g;
- $PERFDATA .= " ";
- $_ = $PERFDATA;
-
- if ( /('.*?'=.*?)\s+/g ) {
- @lines = ( $PERFDATA =~ /('.*?'=.*?)\s+/g );
- }elsif( /(.*?=[a-z A-Z 0-9;%-\.]+)\s/gc ) {
- @lines = ( $PERFDATA =~ /(.*?=[a-z A-Z 0-9;%-\.]+)\s/gc );
- }else{
- print_log ("Perfdata is not valid ( $PERFDATA )",1);
- if(!$opt_b){
- print_log ("PNP exiting ...",1);
- exit 1;
- }
- }
- process_perfdata();
-}
-#
# Analyse check_command to find PNP Template .
#
sub adjust_template {
- $type = "GAUGE";
- my @temp_template = split /\!/,$TEMPLATE ;
- $TEMPLATE = $temp_template[0];
- my $template_cfg = "$conf{CFG_DIR}/check_commands/$temp_template[0].cfg";
+ my $dstype = "GAUGE";
+ my @temp_template = split /\!/,$CHECK_COMMAND ;
+ my $template = $temp_template[0];
+ my $template_cfg = "$conf{CFG_DIR}/check_commands/$template.cfg";
if(-e $template_cfg){
- print_log ("adjust_template() => $template_cfg",2);
- open FH, "<" ,$template_cfg;
- while (<FH>) {
- next if /^#/;
- next if /^$/;
- s/#.*//;
- s/ //g;
- if (/^(.*)=(.*)$/) {
- if ($1 eq "DATATYPE") {
- $type = $2;
- print_log ("Adapting RRD Datatype to $type as defined in $template_cfg",2);
- }
- if ($1 eq "CUSTOM_TEMPLATE") {
- print_log ("Adapting Template using ARG $2",2);
- my $i = 1;
- my @keys = split /,/,$2;
- foreach my $keys (@keys){
- if($i == 1){
- $TEMPLATE = $temp_template[$keys];
- print_log ("Adapting Template to $TEMPLATE.php (added ARG$keys)",2);
- }else{
- $TEMPLATE .= "_".$temp_template[$keys];
- print_log ("Adapting Template to $TEMPLATE.php (added ARG$keys)",2);
- }
- $i++;
- }
- print_log ("Adapting Template to $TEMPLATE.php as defined in $template_cfg",2);
- }
- }
- }
- close FH;
+ print_log ("adjust_template() => $template_cfg",2);
+ open FH, "<" ,$template_cfg;
+ while (<FH>) {
+ next if /^#/;
+ next if /^$/;
+ s/#.*//;
+ s/ //g;
+ if (/^(.*)=(.*)$/) {
+ if ($1 eq "DATATYPE") {
+ $dstype = uc($2);
+ print_log ("Adapting RRD Datatype to $dstype as defined in $template_cfg",2);
+ }
+ if ($1 eq "CUSTOM_TEMPLATE") {
+ print_log ("Adapting Template using ARG $2",2);
+ my $i = 1;
+ my @keys = split /,/,$2;
+ foreach my $keys (@keys){
+ if($i == 1){
+ $template = $temp_template[$keys];
+ print_log ("Adapting Template to $template.php (added ARG$keys)",2);
+ }else{
+ $template .= "_".$temp_template[$keys];
+ print_log ("Adapting Template to $template.php (added ARG$keys)",2);
+ }
+ $i++;
+ }
+ print_log ("Adapting Template to $template.php as defined in $template_cfg",2);
+ }
+ }
+ }
+ close FH;
}else{
- print_log ("No Custom Template found for $temp_template[0] ($template_cfg) ",2);
- print_log ("RRD Datatype is $type",2);
+ print_log ("No Custom Template found for $template ($template_cfg) ",2);
+ print_log ("RRD Datatype is $dstype",2);
}
- print_log ("Template is $TEMPLATE.php",2);
+ print_log ("Template is $template.php",2);
+ return $template,$dstype;
}
-
-sub print_help {
- print "Copyright (c) 2005-2005 Joerg Linge <pitchfork\@ederdrom.de>\n";
- print "Use process_perfdata.pl to store Nagios Plugin Performance Data into RRD Databases\n";
- print "\n";
- print "Options:\n";
- print " -h, --help\n";
- print " Print detailed help screen\n";
- print " -V, --version\n";
- print " Print version information\n";
- print " -t, --timeout=INTEGER\n";
- print " Seconds before process_perfdata.pl times out (default: $opt_t)\n";
- print " -i, --inetd\n";
- print " Use this Option if process_perfdata.pl is executed by inetd/xinetd.\n";
- print " -d, --datatype\n";
- print " Defaults to \"SERVICEPERFDATA\". Use \"HOSTPERFDATA\" to process Perfdata from regular Host Checks\n";
- print " Only used in default or inetd Mode\n";
- print " -b, --bulk\n";
- print " Provide a file for bulk update\n";
- exit 0;
-}
-sub print_version {
- print "Version: process_perfdata.pl $conf{VERSION}\n";
- print "Copyright (c) 2005-2007 Joerg Linge <pitchfork\@ederdrom.de>\n";
- exit 0;
-}
-
+#
+# Parse process_perfdata.cfg
+#
sub parse_config {
my $config_file = shift;
my $line = 0;
@@ -587,6 +458,9 @@
}
}
+#
+# Parse rra.cfg
+#
sub parse_rra_config {
@rrd_create = ();
print_log("Reading $conf{RRA_CFG}",2);
@@ -601,4 +475,151 @@
}
close RRA;
return @rrd_create;
+
}
+
+#
+# Function adpated from Nagios::Plugin::Performance
+# Thanks to Gavin Carr and Ton Voon
+#
+sub _parse {
+ # Aus Nagios::Plugin::Performance
+ my $string = shift;
+ $string =~ s/^([^=]+)=([\d\.]+)([\w%]*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?\s*//;
+ return undef unless ((defined $1 && $1 ne "") && (defined $2 && $2 ne ""));
+ # Hash mit allen werten aus den Perfdatan bauen.
+ my %p = (
+ "label" => $1,
+ "value" => $2+0,
+ "uom" => $3,
+ "warning" => $4,
+ "critical" => $5,
+ "min" => $6,
+ "max" => $7
+ );
+ if( $p{uom} eq "%" ){
+ $p{uom} = "%%";
+ print_log("DEBUG: $. UOM adjust = $p{uom}",3);
+ }
+ return ($string,%p);
+}
+
+#
+# Parse the Performance String and call data2rrd()
+#
+sub parse_perfstring {
+ my $perfstring = shift;
+ $perfstring =~ s/\\/\//;
+ my $is_multi = "0";
+ my @perfs;
+ my %p;
+ my $check_multi_group = "0";
+ my $last_check_multi_group = "0";
+ (my $template, my $dstype) = adjust_template();
+ print_log("DEBUG: dstype = $dstype",3);
+ while ($perfstring) {
+ ($perfstring,%p) = _parse($perfstring);
+ if( $p{uom} eq "c" ){
+ $p{dstype} = "COUNTER";
+ print_log("DEBUG: $. DSTYPE adjust = $p{dstype}",3);
+ }else{
+ $p{dstype} = $dstype;
+ }
+ if( $p{label} =~ /^(.*):(.*):(.*)$/ ){
+ # check_multi first datasource
+ $is_multi = 1;
+ $p{multi} = $is_multi;
+ $p{label} = $3; # store the original label fron check_multi header
+ $p{hostname} = $HOSTNAME;
+ $p{hostname} =~ s/[: \/]/_/g ;
+ if($check_multi_group == 0){
+ $p{servicedesc} = $SERVICEDESC;
+ $p{servicedesc} =~ s/[: \/]/_/g ;
+ }else{
+ $p{servicedesc} = $2;
+ $p{servicedesc} =~ s/[: \/]/_/g ;
+ }
+ $p{template} = $2;
+ $check_multi_group++;
+ }else{
+ if($check_multi_group == $last_check_multi_group && $check_multi_group != 0){
+ # additional check_multi data
+ $p{multi} = $is_multi;
+ $p{hostname} = $HOSTNAME;
+ $p{hostname} =~ s/[: \/]/_/g ;
+ $p{servicedesc} = $SERVICEDESC;
+ $p{servicedesc} =~ s/[: \/]/_/g ;
+ }
+
+ if($check_multi_group == 0){
+ # normal plugins
+ $p{multi} = $is_multi;
+ $p{template} = $template;
+ $p{hostname} = $HOSTNAME;
+ $p{hostname} =~ s/[: \/]/_/g ;
+ $p{servicedesc} = $SERVICEDESC;
+ $p{servicedesc} =~ s/[: \/]/_/g ;
+ }
+
+ }
+
+ if($check_multi_group > $last_check_multi_group && $last_check_multi_group != 0){
+ # process a complete check_multi group
+ data2rrd(@perfs);
+ @perfs=() ;
+ }
+ $last_check_multi_group = $check_multi_group;
+ push @perfs, { %p };
+ }
+ data2rrd(@perfs);
+}
+
+
+#
+# Write to Logfile
+#
+sub print_log {
+ return if($conf{LOG_LEVEL}==0);
+ my $out = shift;
+ my $severity = shift;
+ if($severity <= $conf{LOG_LEVEL}){
+ open (LOG,">>".$conf{LOG_FILE}) || die "Can't open logfile ($conf{LOG_FILE}) ",$!;
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
+ printf (LOG "%02d-%02d-%02d %02d:%02d:%02d [%d] %s\n",$year+1900,$mon+1,$mday,$hour,$min,$sec,$$,$out);
+ close (LOG);
+ }
+}
+
+#
+#
+#
+sub print_help {
+ print "Copyright (c) 2005-2005 Joerg Linge <pitchfork\@ederdrom.de>\n";
+ print "Use process_perfdata.pl to store Nagios Plugin Performance Data into RRD Databases\n";
+ print "\n";
+ print "Options:\n";
+ print " -h, --help\n";
+ print " Print detailed help screen\n";
+ print " -V, --version\n";
+ print " Print version information\n";
+ print " -t, --timeout=INTEGER\n";
+ print " Seconds before process_perfdata.pl times out (default: $opt_t)\n";
+ print " -i, --inetd\n";
+ print " Use this Option if process_perfdata.pl is executed by inetd/xinetd.\n";
+ print " -d, --datatype\n";
+ print " Defaults to \"SERVICEPERFDATA\". Use \"HOSTPERFDATA\" to process Perfdata from regular Host Checks\n";
+ print " Only used in default or inetd Mode\n";
+ print " -b, --bulk\n";
+ print " Provide a file for bulk update\n";
+ exit 0;
+}
+
+#
+#
+#
+sub print_version {
+ print "Version: process_perfdata.pl $conf{VERSION}\n";
+ print "Copyright (c) 2005-2007 Joerg Linge <pitchfork\@ederdrom.de>\n";
+ exit 0;
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|