Page 1 of 1

[Nagios-devel] patch for preprocessing macros

Posted: Mon May 07, 2007 11:19 am
by Guest
This is a multi-part message in MIME format.
--------------030601040904030709020608
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Hi list,

we moved check_cluster from contrib to the main distribution of the
nagios plugins a couple of days ago. While writing the test cases, I
remembered that I had had an issue to flexibly configure service
clusters months ago, so i wrote a small patch to meet these needs
(although i developed a workaround at that time).

The problem:
If there are multiple checks for one server process, eg. apache on port
80 and port 443 a corresponding service cluster has to have a command
line similar to this one:

check_cluster -s \
-d $SERVICESTATEID:myhost1:Port 443$,$SERVICESTATEID:myhost1:Port 80$

Templates cannot be used since myhost1 cannot be substituted by the
$HOSTNAME$ macro due to nagios' macro substitution logic resulting in
one service config for each host.

So i wrote a patch that can handle macros in on demand macros.

I originally thought about syntax like $SERVICESTATEID:$HOSTNAME$:Port$
but I couldn't imagine a way to distinguish between opening and closing
$ signs. So my syntax contains braces and looks like this:

$SERVICESTATEID:{$HOSTNAME$}:svc_desc$

The code substitutes macros in curly braces first.

What do you think about it?

Thanks
Matthias




--------------030601040904030709020608
Content-Type: text/plain;
name="macro_preparse.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="macro_preparse.patch"

--- base/utils.c 2007-05-07 20:24:26.000000000 +0200
+++ /usr/local/src/nagios-2.9/base/utils.c 2007-05-07 20:25:07.000000000 +0200
@@ -258,6 +258,32 @@
printf("Buffer length: %d\n",buffer_length);
#endif

+// pre-parse macros in curly braces. Eg for defining an argument of an on demand macro $HOSTSTATEID:{$HOSTNAME$}$
+for(temp_buffer=strstr(input_buffer,":{$"); temp_buffer!=NULL; temp_buffer=strstr(temp_buffer,":{$")) {
+ char * pre,* macro,* rest;
+ char * buf = strdup(temp_buffer);
+ char * subst_macro = strdup("");
+ pre = buf;
+ if (macro = index(buf,'{')) {
+ macro[0] = '\x0';
+ macro++;
+
+ if (rest = strstr(macro,"$}")) {
+ rest[1] = '\x0';
+ rest += 2;
+
+ buf = strcpy(buf,pre);
+ process_macros(macro,subst_macro,strlen(macro)+1,options);
+ buf = strcat(buf,subst_macro);
+ buf = strcat(buf,rest);
+ temp_buffer=strcpy(temp_buffer,buf);
+ }
+ }
+ free(buf);
+ free(subst_macro);
+ }
+
+
for(temp_buffer=my_strtok(input_buffer,"$");temp_buffer!=NULL;temp_buffer=my_strtok(NULL,"$")){

#ifdef TEST_MACROS

--------------030601040904030709020608--





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]