Problem with perfdata file in Nagios 2.9?

Thomas Guyot-Sionnest dermoth at aei.ca
Fri Apr 13 05:11:02 CEST 2007


On 12/04/07 11:58 AM, Frost, Mark {PBG} wrote:
> Hello.  I recently posted to the Nagios-users list about an issue that
> seems to have cropped up since I moved to 2.9.
> 
> I use Nagiosgraph 0.8.2.  My nagios.cfg file has the following
> configuration options:
> 
> 	process_performance_data=1
> 	service_perfdata_file_mode=a
> 	service_perfdata_file_processing_interval=30

There was a bug in 2.8 and earlier were perfdata_file_mode=a were
writing and perfdata_file_mode=w were appending. change it to "w" and
you'll get the old behavior.

My understanding is that you never remove the file in your perfdata
processing script so that in 2.8, when told to write, the file was
truncated when Nagios was reopening it. The correct fix is to remove the
file before returning back to nagios.

For better performance I'd suggest something like this:

open(PERFDATA, "<$perfdata_file") or die;
if ((my $test=fork) == 0) {
  # Do something useful here
  close (PERFDATA);
  exit (0);
} elsif ($test > 0) {
  # Fork forked, remove file and return
  unlink ($perfdata_file);
  close (PERFDATA);
  exit (0);
} else {
  # Something went wrong! Don't remove the file, Nagios
  # will keep appending to it.
  close (PERFDATA);
  exit (1);
}

This will open the file, remove it and return immediately to nagios
while the forked process will continue processing the file. Since the
file is already opened when it is unlinked the new file won't interfere
with the one opened by the forked process.

Thomas

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV




More information about the Developers mailing list