Re: [Nagios-devel] Fixes for macros introduced in latest CVS update
Posted: Sat Oct 23, 2004 2:05 am
This is a multi-part message in MIME format.
--------------000007090506020501000303
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
As it turns out there were a couple of errors in the patch. Most notably
in the add_hostextinfo and add_serviceextinfo functions, where notes_url
and action_url weren't beeing assigned by reference instead of getting
strdup()'ed.
I had also left some debugging output and missed to re-insert the
original number of empty lines in the original patch, causing a few
really silly hunks to be included.
Use this new one instead. It's been tested rather thoroughly and works
splendidly.
Andreas Ericsson wrote:
> 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.
>
>
> ------------------------------------------------------------------------
>
> 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) + strncat(output_buffer,temp_buffer,sizeof(output_buffer)-strlen(output_buffer)-1);
> + output_buffer[sizeof(output_buffer)-1]='\x0';
> + }
> + in_macro=TRUE;
> + }
> + else{
> +
> + if(strlen(output_buffer)+strlen(temp_buffer) +
> + if(!strcmp(temp_buffer,"HOSTNAME"))
> + strncat(output_buffer,temp_host->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,si
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
--------------000007090506020501000303
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
As it turns out there were a couple of errors in the patch. Most notably
in the add_hostextinfo and add_serviceextinfo functions, where notes_url
and action_url weren't beeing assigned by reference instead of getting
strdup()'ed.
I had also left some debugging output and missed to re-insert the
original number of empty lines in the original patch, causing a few
really silly hunks to be included.
Use this new one instead. It's been tested rather thoroughly and works
splendidly.
Andreas Ericsson wrote:
> 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.
>
>
> ------------------------------------------------------------------------
>
> 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) + strncat(output_buffer,temp_buffer,sizeof(output_buffer)-strlen(output_buffer)-1);
> + output_buffer[sizeof(output_buffer)-1]='\x0';
> + }
> + in_macro=TRUE;
> + }
> + else{
> +
> + if(strlen(output_buffer)+strlen(temp_buffer) +
> + if(!strcmp(temp_buffer,"HOSTNAME"))
> + strncat(output_buffer,temp_host->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,si
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]