I wanted to add some debug logging to a Perl script I created as a Nagios plugin. It works perfectly when started from the command line, but when it is being called by Nagios, 'localtime' returns the time the nagios3 daemon was last restarted (yesterday afternoon, in this case).
Running Perl v5.14.2 and Nagios 3.2.3 on Ubuntu Server 12.04 LTS.
script (partial):
#!/usr/bin/perl
use POSIX;
my $result = 0;
my $IP=$ARGV[0];
# actual processing here...
open (LOGFILE, ">>/var/log/nagios3/check_pisystem.log");
print LOGFILE strftime "%F %T%z (%Z)", localtime $^T;
print LOGFILE "," . $IP . "," . $result . "\n";
close (LOGFILE);
Logfile contents after running for a while: the lines at 10:xx were added by manually starting the script from the shell prompt. The other lines are the result of it being called by nagios, 4 different IP's at 5 minute intervals (each).
2013-07-29 15:18:24+0200 (CEST),10.3.4.83,0
2013-07-29 15:18:24+0200 (CEST),10.3.3.83,0
2013-07-30 10:24:51+0200 (CEST),10.3.0.83,0
2013-07-29 15:18:24+0200 (CEST),10.3.1.83,1
...
2013-07-29 15:18:24+0200 (CEST),10.3.3.83,1
2013-07-29 15:18:24+0200 (CEST),10.3.1.83,0
2013-07-29 15:18:24+0200 (CEST),10.3.0.83,0
2013-07-29 15:18:24+0200 (CEST),10.3.4.83,0
2013-07-30 10:46:54+0200 (CEST),10.3.0.83,0