Skip to content
This repository
Browse code

XML_WRITE_DELAY option added to process_perfdata.cfg as suggested by …

…Mathias Kettner
  • Loading branch information...
commit 65faff02fd46a846a4fd937b81ac00046ac8dac8 1 parent 97601be
Joerg Linge authored
1  ChangeLog
... ... @@ -1,5 +1,6 @@
1 1 **pnp-0.6.2 ??/??/2009**
2 2
  3 + * Feature: XML_WRITE_DELAY option added to process_perfdata.cfg as suggested by Mathias Kettner
3 4 * Feature: New template integer.php
4 5 * Update: FPDI update to 1.3.1
5 6 * Feature: PNP will now work with [[http://http://www.lighttpd.net|lighttpd]] and php-cgi
1  THANKS
@@ -45,6 +45,7 @@ Trond Hasle Amundsen - Template check_openmanage
45 45 Silvan Hunkirchen - Bugreport
46 46 Petr Maizner - Bugreport
47 47 Steve Finkelstein - Bugreport
  48 +Mathias Kettner - xml write delay
48 49
49 50 ###########################################
50 51 # NPCD Thanks #
8 sample-config/pnp/process_perfdata.cfg-sample.in
@@ -72,6 +72,14 @@ LOG_LEVEL = @DEBUG@
72 72 XML_ENC = UTF-8
73 73
74 74 #
  75 +# XML update delay in seconds
  76 +# 0 = Update XML Files everytime new data arrives
  77 +#
  78 +# Use this option to reduce disk I/O
  79 +#
  80 +XML_UPDATE_DELAY = 0
  81 +
  82 +#
75 83 # EXPERIMENTAL rrdcached Support
76 84 # Use only with rrdtool svn revision 1511+
77 85 #
21 scripts/process_perfdata.pl.in
@@ -28,7 +28,7 @@ use warnings;
28 28 use strict;
29 29 use Getopt::Long;
30 30 use Time::HiRes qw(gettimeofday tv_interval);
31   -use vars qw ( $TEMPLATE %NAGIOS $rrdfile @ds_create $count $line @lines $t @t $name $xact $warn $crit $min $max $unit $act $ds_create $ds_update @rrd_create $rrd_update $dstype);
  31 +use vars qw ( $TEMPLATE %NAGIOS $delayed_write $rrdfile @ds_create $count $line @lines $t @t $name $xact $warn $crit $min $max $unit $act $ds_create $ds_update @rrd_create $rrd_update $dstype);
32 32
33 33 my %conf = (
34 34 TIMEOUT => "5",
@@ -45,7 +45,8 @@ my %conf = (
45 45 LOG_FILE_MAX_SIZE => "10485760", #Truncate after 10MB
46 46 LOG_LEVEL => @DEBUG@,
47 47 XML_ENC => "UTF-8",
48   - RRD_DAEMON_OPTS => ""
  48 + XML_UPDATE_DELAY => 0, # Write XML only if file is older then XML_UPDATE_DELAY seconds
  49 + RRD_DAEMON_OPTS => ""
49 50 );
50 51
51 52 my %const = (
@@ -486,8 +487,18 @@ sub write_rrd {
486 487 #
487 488 sub open_template {
488 489 my $xmlfile = shift;
  490 + $delayed_write = 0;
  491 + my $mtime = (stat($xmlfile))[9];
  492 + my $t = time();
  493 + my $age = ($t - $mtime);
  494 + if ( $age < $conf{'XML_UPDATE_DELAY'} ){
  495 + print_log( "DEBUG: XML File is $age seconds old. No update needed", 3 );
  496 + $delayed_write = 1;
  497 + return;
  498 + }
  499 + print_log( "DEBUG: XML File is $age Seconds old. UPDATE!", 3 );
489 500 open( XML, "> $xmlfile.$$" ) or die "Cant create temporary XML file ", $!;
490   - print XML "<?xml version=\"1.0\" encoding=\"" . $conf{XML_ENC} . "\" standalone=\"yes\"?>\n";
  501 + print XML "<?xml version=\"1.0\" encoding=\"" . $conf{XML_ENC} . "\" standalone=\"yes\"?>\n";
491 502 print XML "<NAGIOS>\n";
492 503 }
493 504
@@ -495,6 +506,7 @@ sub open_template {
495 506 # Close Template FH
496 507 #
497 508 sub close_template {
  509 + return if $delayed_write == 1;
498 510 my $xmlfile = shift;
499 511 printf( XML " <XML>\n" );
500 512 printf( XML " <VERSION>%d</VERSION>\n", $const{'XML_STRUCTURE_VERSION'} );
@@ -509,6 +521,7 @@ sub close_template {
509 521 # Add Lines
510 522 #
511 523 sub write_to_template {
  524 + return if $delayed_write == 1;
512 525 my $tag = shift;
513 526 my $data = shift;
514 527 if ( !defined $data ) {
@@ -528,6 +541,7 @@ sub write_to_template {
528 541 }
529 542
530 543 sub write_state_to_template {
  544 + return if $delayed_write == 1;
531 545 my @rrd_state = @_;
532 546 printf( XML " <RRD>\n" );
533 547 printf( XML " <RC>%s</RC>\n", $rrd_state[0] );
@@ -539,6 +553,7 @@ sub write_state_to_template {
539 553 # Store the complete Nagios ENV
540 554 #
541 555 sub write_env_to_template {
  556 + return if $delayed_write == 1;
542 557 foreach my $key ( sort keys %NAGIOS ) {
543 558 $NAGIOS{$key} = urlencode($NAGIOS{$key});
544 559 printf( XML " <NAGIOS_%s>%s</NAGIOS_%s>\n", $key, $NAGIOS{$key}, $key );

0 comments on commit 65faff0

Please sign in to comment.
Something went wrong with that request. Please try again.