[Nagios-devel] Fixes for macros introduced in latest CVS update

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] Fixes for macros introduced in latest CVS update

Post by Guest »

This is a multi-part message in MIME format.
--------------090303090501040609050903
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Ahoy.

I've been playing around with the nagios code a bit and found a two bugs
inserted while making the latest additions to the macro family;
HOSTACTIONURL, HOSTNOTESURL, SERVICEACTIONURL and SERVICENOTESURL.

1. Originally, Nagios would free and NULL the extended data after
parsing it and dumping it to the objects.cache file. As such, the
extended info macros couldn't be expanded at notification time and thus
failed. This has been fixed in the attached patch.

2. It is allowed to use a limited subset of macros in these variables,
namely HOSTADDRESS, HOSTNAME and (for services only) SERVICEDESC.
Previously, these macros were expanded at run-time by the CGI programs
which turned out to be troublesome come notification time. I relocated
the code so that URL macro expansion takes place at loading time and
made the necessary changes to the CGI's.
As a bonus, a few of the cgi's will run a little faster as well.


I have done a few test so far and everything appears to be in order. Let
me know if you find any bugs.

--
Andreas Ericsson [email protected]
OP5 AB www.op5.se
Lead Developer

--------------090303090501040609050903
Content-Type: text/plain;
name="nagios-extinfo_url-processing.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="nagios-extinfo_url-processing.diff"

diff -urN ../Nagios/base/nagios.c ./base/nagios.c
--- ../Nagios/base/nagios.c Fri Oct 22 18:51:27 2004
+++ ./base/nagios.c Sat Oct 23 02:49:51 2004
@@ -556,9 +556,6 @@
exit(ERROR);
}

- /* free extended info data - we don't need this for monitoring */
- free_extended_data();
-
/* initialize embedded Perl interpreter */
init_embedded_perl();

diff -urN ../Nagios/base/utils.c ./base/utils.c
--- ../Nagios/base/utils.c Fri Oct 22 18:51:29 2004
+++ ./base/utils.c Sat Oct 23 04:20:13 2004
@@ -303,9 +303,74 @@
/************************ MACRO FUNCTIONS *************************/
/******************************************************************/

+/* substitute macros in url type vars for hostextinfo and serviceextinfo */
+char *process_extinfo_url(char *host_name, char *svc_description, char *url){
+ char input_buffer[MAX_INPUT_BUFFER]="";
+ char output_buffer[MAX_INPUT_BUFFER]="";
+ char *temp_buffer;
+ char *processed_url;
+ int in_macro=FALSE;
+ service *temp_service;
+ host *temp_host;
+
+ if(host_name==NULL || url==NULL)
+ return;
+
+ if(svc_description!=NULL) {
+ temp_service=find_service(host_name,svc_description);
+ if(temp_service==NULL)
+ return(url);
+ }
+
+ temp_host=find_host(host_name);
+ if(temp_host==NULL)
+ return(url);
+
+ strncpy(input_buffer,url,sizeof(input_buffer)-1);
+ input_buffer[sizeof(input_buffer)-1]='\x0';
+
+ for(temp_buffer=my_strtok(input_buffer,"$");temp_buffer!=NULL;temp_buffer=my_strtok(NULL,"$")){
+
+ if(in_macro==FALSE){
+ if(strlen(output_buffer)+strlen(temp_buffer)name,sizeof(output_buffer)-strlen(output_buffer)-1);
+
+ else if(!strcmp(temp_buffer,"HOSTADDRESS") && temp_host!=NULL)
+ strncat(output_buffer,(temp_host->address==NULL)?"":temp_host->address,sizeof(output_buffer)-strlen(output_buffer)-1);
+
+ else if(temp_service!=NULL && !strcmp(temp_buffer,"SERVICEDESC"))
+ strncat(output_buffer,temp_service->description,sizeof(output_buffer)-strlen(output_buffer)-1);
+ }
+
+ in_macro=FALSE;
+ }
+ }
+
+
+ temp_buffer=strdup(output_buffer);
+ if(temp_buffer==NULL)
+ return(url);
+
+ return(temp_buffer);
+ }
+
+
+
/* replace macros in notification co

...[email truncated]...


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