[Nagiosplug-devel] [ nagiosplug-Bugs-1296242 ] check_nagios 1.26 (plugins 1.4.2) not working with Nagios 2

SourceForge.net noreply at sourceforge.net
Fri Dec 2 06:03:02 CET 2005


Bugs item #1296242, was opened at 2005-09-20 12:20
Message generated for change (Comment added) made by lausser
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=397597&aid=1296242&group_id=29880

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Parsing problem
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Daniel Bimschas (bimschas)
Assigned to: Ton Voon (tonvoon)
Summary: check_nagios 1.26 (plugins 1.4.2) not working with Nagios 2

Initial Comment:
Hi,

the check_nagios plugin always gets the last_entry_time
wrong when doing checks on NAGIOSHOME/var/status.dat.

I made a little fix, my diff:

65,67c65
<       char tag[] = "created=";
<       char *dummy = NULL;
<
---
>
92,97c90,94
<               temp_ptr = strtok (input_buffer, tag);
<               temp_ptr = strtok (NULL,tag);
<               if (temp_ptr != NULL) {
<                       latest_entry_time = strtoul
(temp_ptr,NULL,10);
<                       break;
<               }
---
>               temp_ptr = strtok (input_buffer, "]");
>               temp_entry_time =
>                       (temp_ptr == NULL) ? 0L :
strtoul (temp_ptr + 1, NULL, 10);
>               if (temp_entry_time > latest_entry_time)
>                       latest_entry_time =
temp_entry_time;

----------------------------------------------------------------------

Comment By: gerhard lausser (lausser)
Date: 2005-12-02 15:02

Message:
Logged In: YES 
user_id=613416

Hi,
i stumbled into the same problem and modified the fgets 
loop so that both nagios versions can be handled.
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
  if (temp_ptr = strstr (input_buffer, "created=")) {
    temp_entry_time = strtoul (temp_ptr + 8, NULL, 10);
    latest_entry_time = temp_entry_time;
    break;
  } else if (temp_ptr = strtok (input_buffer, "]")) {
    temp_entry_time = strtoul (temp_ptr + 1, NULL, 10);
    if (temp_entry_time > latest_entry_time)
      latest_entry_time = temp_entry_time;
  }
}
fclose (fp);

The first branch recognizes a version2 status.log which 
stores it's modification date in a structure like this:
info {
  created=1133528543
  version=2.0b4
}
If the created= is found, no more parsing is necessary and 
the loop will be left with break.
The second branch does principally the same as the current 
code, but calculates temp_entry_time only if actually 
a ']' was found.

Here is a patch, which can be applied like this.
# cd nagios-plugins-1.4.2
# patch -Np0 < check_nagios.patch.v2


diff -Naur plugins/check_nagios.c plugins.v2/check_nagios.c
--- plugins/check_nagios.c      2005-12-02 
14:49:11.143735914 +0100
+++ plugins.v2/check_nagios.c   2005-12-02 
14:49:57.157079844 +0100
@@ -87,11 +87,15 @@
 
        /* get the date/time of the last item updated in 
the log */
        while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, 
fp)) {
-               temp_ptr = strtok (input_buffer, "]");
-               temp_entry_time =
-                       (temp_ptr == NULL) ? 0L : strtoul 
(temp_ptr + 1, NULL, 10);
-               if (temp_entry_time > latest_entry_time)
-                       latest_entry_time = 
temp_entry_time;
+               if (temp_ptr = strstr 
(input_buffer, "created=")) {
+                       temp_entry_time = strtoul 
(temp_ptr + 8, NULL, 10);
+                       latest_entry_time = 
temp_entry_time;
+                       break;
+                } else if (temp_ptr = strtok 
(input_buffer, "]")) {
+                       temp_entry_time = strtoul 
(temp_ptr + 1, NULL, 10);
+                       if (temp_entry_time > 
latest_entry_time)
+                               latest_entry_time = 
temp_entry_time;
+               }
        }
        fclose (fp);

If the formatting is messed up, you can find it also here: 
http://people.consol.de/~lausser/nagios/check_nagios.patch.
v2

Greetings from Munich,
Gerhard

----------------------------------------------------------------------

Comment By: Ton Voon (tonvoon)
Date: 2005-09-20 12:36

Message:
Logged In: YES 
user_id=664364

Daniel,

Thanks for the patch. Can you attach a diff -u output please as these 
are easier to parse. Also, could you attach an extract of status.dat 
please (I don't have access to a Nagios 2 version).

Ideally, we want a check_nagios which can read either nagios1 or 
nagios2 format, so if you can provide a patch that can handle both, it 
will definitely go in.

Ton

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=397597&aid=1296242&group_id=29880




More information about the Devel mailing list