[Nagiosplug-devel] Patch for leading whitespace on comments

Tobias Klausmann klausman at schwarzvogel.de
Fri Jan 19 14:37:33 CET 2007


Hi! 

(Sent this to the wrong list initially. Sorry 'bout that)

As of 2.6, Nagios recognizes leading whitespace only in the main
config file. The attached patch fixes this.

To illustrate, this piece of config does not work currently:

define host {
    host_name                 eric.schwarzvogel.de
    alias                     eric.schwarzvogel.de
    address                   194.97.4.250
    #check_command             check_host_alive
    check_command             check_host_new
    max_check_attempts        3
    retain_status_information 1
    contact_groups            Privat Klausmann
    notification_interval     30
    notification_period       24x7
    notification_options      d,u,r
    passive_checks_enabled    1
}

The reason is the commented-out check_command line. It would work
like this:

define host {
...
#   check_command             check_host_alive
    check_command             check_host_new
...
}

This is because (for non-main config files), Nagios first checks
if the first char is "#" and *then* strips the line. For the main
config file, this happens the other way around.

I've attached a patch that makes this behaviour more consistent.
I believe the check for '\0', '\n' etc. could be simplified to,
*if* strip() removes some of the chars. I tried to be
non-invasive as possible, so I didn't do that.

I'd like it if this patch makes it into the 2.x series. 

Regards,
Tobias

-------------- next part --------------
--- base/config.c.orig	2007-01-19 13:15:52.000000000 +0100
+++ base/config.c	2007-01-19 13:17:00.000000000 +0100
@@ -1518,12 +1518,15 @@
 
 		current_line=thefile->current_line;
 
+		/* Strip line first so that a hash preceded by
+		 * only whitespace is treated correctly 
+		 */
+		strip(input);
+
 		/* skip blank lines and comments */
 		if(input[0]=='#' || input[0]=='\x0' || input[0]=='\n' || input[0]=='\r')
 			continue;
 
-		strip(input);
-
 		/* get the variable name */
 		temp_ptr=my_strtok(input,"=");
 
-------------- next part --------------
-------------------------------------------------------------------------
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
-------------- next part --------------
_______________________________________________________
Nagios Plugin Development Mailing List Nagiosplug-devel at lists.sourceforge.net
Unsubscribe at https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
::: Please include plugins version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null
-------------- next part --------------
-------------------------------------------------------------------------
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
-------------- next part --------------
_______________________________________________
Nagios-devel mailing list
Nagios-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-devel


More information about the Developers mailing list