MAX_PLUGINOUTPUT_LENGTH limits for Nagios 2.x

Daniel Reynolds danny at deakin.edu.au
Thu Jan 18 00:03:11 CET 2007


Hello all,

I have noticed that a number of fellow Nagios users have requested
larger service check output.  I also have this requirement.

While Nagios 3.x will remove the service check output limit we could
have a reasonable solution now.  Below is a patch I hope will be considered
for the 2.x branch.

I believe that the patch has the following benefits.

1)    MAX_PLUGINOUTPUT_LENGTH is calculated to use the largest value
reasonable for the computer it is compiled on.  This increases service check
output limit to just under 4k on Linux, more for Solaris.
2)    Some compilers use struct padding to speed up access to variables 
in structures
(gcc for one).  struct service_message_struct has been reordered to 
avoid this.


Ethan is it possible to get this patch in?  If you have any issues with the
coding of it I would be happy to redo the patch as required.

Regards,
Danny Reynolds


p.s.  The patch below is for Nagios 2.6.1 from the RPM repository DAG.



Index: nagios/include/common.h
===================================================================
RCS file: /local/noc/cvs/nagios/nagios/include/common.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 common.h
--- nagios/include/common.h    21 Dec 2006 02:53:21 -0000    1.1.1.1
+++ nagios/include/common.h    10 Jan 2007 21:55:04 -0000
@@ -378,8 +378,33 @@
 
 /************************** MISC DEFINITIONS ****************************/
 
-#define MAX_FILENAME_LENGTH            256    /* max length of 
path/filename that Nagios will process */
+
+/*
+Work out the best size for MAX_PLUGINOUTPUT_LENGTH.  
MAX_PLUGINOUTPUT_LENGTH
+is calculated below to make sure that struct service_message_struct
+is smaller than PIPE_BUF for your system.  This stops service check 
results from
+being mangled when going through internal pipes, yet still allowing
+modern POSIX systems to have a decently large MAX_PLUGINOUTPUT_LENGTH.
+
+MAX_INPUT_BUFFER is used for writing out perfdata (amoungst other things).
+it must be the same size or larger than MAX_PLUGINOUTPUT_LENGTH.
+
+NOTE:  The '+ 20' at the end is a kludge to avoid problems due to
+struct padding under some compilers (GCC for one).  See
+http://www.delorie.com/djgpp/v2faq/faq22_11.html for the gruesome details.
+*/
+#include <limits.h>
+#include <sys/time.h>
+
+#ifdef PIPE_BUF
+#define MAX_PLUGINOUTPUT_LENGTH            (PIPE_BUF - 
(MAX_HOSTNAME_LENGTH + MAX_SERVICEDESC_LENGTH + sizeof(int) * 5 + 
sizeof(struct timeval) * 2 + 20))    /* max. length of plugin output */
+#define MAX_INPUT_BUFFER            (1024 + MAX_PLUGINOUTPUT_LENGTH)   
 /* size in bytes of max. input buffer (for reading files) */
+#else
+#define MAX_PLUGINOUTPUT_LENGTH            332    /* max. length of 
plugin output */
 #define MAX_INPUT_BUFFER            1024    /* size in bytes of max. 
input buffer (for reading files) */
+#endif
+
+#define MAX_FILENAME_LENGTH            256    /* max length of 
path/filename that Nagios will process */
 #define MAX_COMMAND_BUFFER                      8192    /* max length 
of raw or processed command line */
 
 #define MAX_DATETIME_LENGTH            48
Index: nagios/include/nagios.h.in
===================================================================
RCS file: /local/noc/cvs/nagios/nagios/include/nagios.h.in,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 nagios.h.in
--- nagios/include/nagios.h.in    21 Dec 2006 02:53:21 -0000    1.1.1.1
+++ nagios/include/nagios.h.in    10 Jan 2007 21:28:08 -0000
@@ -391,8 +391,6 @@
 
 /* SERVICE_MESSAGE structure */
 typedef struct service_message_struct{
-    char host_name[MAX_HOSTNAME_LENGTH];        /* host name */
-    char description[MAX_SERVICEDESC_LENGTH];    /* service description */
     int return_code;                /* plugin return code */
     int exited_ok;                    /* did the plugin check return 
okay? */
     int check_type;                    /* was this an active or passive 
service check? */
@@ -401,6 +399,8 @@
     struct timeval finish_time;            /* time the service check 
was completed */
     int early_timeout;                              /* did the service 
check timeout? */
     char output[MAX_PLUGINOUTPUT_LENGTH];        /* plugin output */
+    char host_name[MAX_HOSTNAME_LENGTH];        /* host name */
+    char description[MAX_SERVICEDESC_LENGTH];    /* service description */
     }service_message;
 
 
Index: nagios/include/objects.h
===================================================================
RCS file: /local/noc/cvs/nagios/nagios/include/objects.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 objects.h
--- nagios/include/objects.h    21 Dec 2006 02:53:21 -0000    1.1.1.1
+++ nagios/include/objects.h    10 Jan 2007 21:53:28 -0000
@@ -45,10 +45,9 @@
 
 #define MAX_HOSTNAME_LENGTH                    64    /* max. host name 
length */
 #define MAX_SERVICEDESC_LENGTH            64    /* max. service 
description length */
-#define MAX_PLUGINOUTPUT_LENGTH            332    /* max. length of 
plugin output */
 
-#define MAX_STATE_HISTORY_ENTRIES        21    /* max number of old 
states to keep track of for flap detection */
 
+#define MAX_STATE_HISTORY_ENTRIES        21    /* max number of old 
states to keep track of for flap detection */
 #define MAX_CONTACT_ADDRESSES                   6       /* max number 
of custom addresses a contact can have */
 
 

-------------------------------------------------------------------------
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