Re: [Nagios-devel] Fixes for macros introduced in latest CVS update
Posted: Mon Oct 25, 2004 7:27 pm
I implemented this a bit differently than your original patch. The
affected macros are now run through the process_macro() command to
have any macros they contain expanded. The macros are also URL-
encoded, so the links should be good.
I left the CGIs they way they were, as I think it offers a bit more
flexibility. Even though it does take a few extra CPU cycles, it
makes it easier for people to add more macro processing if they wish
(especially for dynamic variables like HOSTSTATUS, etc.).
Patch should be in CVS shortly.
On 23 Oct 2004 at 12:05, Andreas Ericsson wrote:
> 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)<sizeof
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
affected macros are now run through the process_macro() command to
have any macros they contain expanded. The macros are also URL-
encoded, so the links should be good.
I left the CGIs they way they were, as I think it offers a bit more
flexibility. Even though it does take a few extra CPU cycles, it
makes it easier for people to add more macro processing if they wish
(especially for dynamic variables like HOSTSTATUS, etc.).
Patch should be in CVS shortly.
On 23 Oct 2004 at 12:05, Andreas Ericsson wrote:
> 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)<sizeof
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]