Service Checks Logged with Wrong Times

Florian.Kirchmeir at infineon.com Florian.Kirchmeir at infineon.com
Wed Jun 9 00:35:20 CEST 2004


Hi Chris!

I can confirm this problem; thanks for documenting it!
I'll try your patch as soon as possible, and let you know in case I find
any problems.

Can anybody confirm this is fixed/still present in 2.0?

Regards,
Florian Kirchmeir



To: nagios-devel at lists.sourceforge.net
From: Chris Jepeway <jepeway-nag at blasted-heath.com>
Date: Wed, 26 May 2004 10:38:11 -0400
Subject: [Nagios-devel] Service Checks Logged with Wrong Times

[Sorry, this might be a re-send]

Is the problem with timestamps on service checks well known?
The times are ignored by Nagios-1.2, and the service result is processed
as though it took place at the time the result was submitted.

If, eg, I submit a passive check result with a timestamp from 3 days  
ago,
Nagios will act as though the result applies to the current time.
This can be seen quite easily in the "View Trends for This Service"
graph for a passively checked service where results are submitted
some appreciable time after they are collected.

Here's a patch that illustrates the problem by providing a possible fix.
It changes log_service_event() to create a log entry with the timestamp
of the event instead of time(0), and then changes write_to_log() so that
it doesn't prepend timestamps for log entries whose data_type's indicate
a service event.

Of course, this fix results in a log file that's out of order
wrt to timestamps.  Turns out that the graphing routines in Nagios
can handle that, though.

Is there a better way to handle this problem?  Is it fixed in 2.0?


Chris <jepeway at blasted-heath.com>.

The following patch is against Nagios-1.2...

--- logging.c   2004/04/14 17:56:43     1.2
+++ logging.c   2004/04/14 23:13:11
@@ -109,14 +109,22 @@
                 return ERROR;
                 }

-       /* get the current time */
-       time(&t);
-
         /* strip any newlines from the end of the buffer */
         strip(buffer);

-       /* write the buffer to the log file */
-       fprintf(fp,"[%lu] %s\n",t,buffer);
+       if ((data_type & (NSLOG_SERVICE_OK
+                         | NSLOG_SERVICE_UNKNOWN
+                         | NSLOG_SERVICE_WARNING
+                         | NSLOG_SERVICE_CRITICAL)) != 0)
+               /* this is a service alert, which already contains a  
timestamp */
+               fprintf(fp,"%s\n",buffer);
+       else {
+               /* get the current time */
+               time(&t);
+
+               /* write the buffer to the log file */
+               fprintf(fp,"[%lu] %s\n",t,buffer);
+       }

         fclose(fp);

@@ -186,7 +194,7 @@
         grab_host_macros(temp_host);
         grab_service_macros(svc);

-       snprintf(temp_buffer,sizeof(temp_buffer),"SERVICE ALERT:  
%s;%s;%s;%s;%s;%s\n",svc->host_name,svc- 
 
>description,macro_service_state,(state_type==SOFT_STATE)?"SOFT":"HARD",

macro_current_service_attempt,svc->plugin_output);
+       snprintf(temp_buffer,sizeof(temp_buffer),"[%lu] SERVICE ALERT:  
%s;%s;%s;%s;%s;%s\n",svc->last_check?svc->last_check:time(NULL),svc- 
 >host_name,svc- 
 
>description,macro_service_state,(state_type==SOFT_STATE)?"SOFT":"HARD",

macro_current_service_attempt,svc->plugin_output);
         temp_buffer[sizeof(temp_buffer)-1]='\x0';
         write_to_logs_and_console(temp_buffer,log_options,FALSE);







-------------------------------------------------------
This SF.Net email is sponsored by: GNOME Foundation
Hackers Unite!  GUADEC: The world's #1 Open Source Desktop Event.
GNOME Users and Developers European Conference, 28-30th June in Norway
http://2004/guadec.org




More information about the Developers mailing list