[Nagios-devel] Patch for portable CGI's

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] Patch for portable CGI's

Post by Guest »

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

In the past I wrote about a way of making the CGI's truly portable
(without needing to rerun ./configure or make). The link to the old
submission is:

http://sourceforge.net/mailarchive/foru ... um_id=1872

I finally created a patch file (a context diff for all the .c files in
the cgi source directory - it is attached to this email). This patch
file was made fron Nagios 1.0b3, but I tested it and it fixes everything
for b5 as well (it's a context diff, so it can see when lines have moved
up or down without a problem).

This patch will make the CGI's look for the cgi.cfg file (and
nagios.cmd) by calling a small function I added, instead of directly
referencing a value in locations.h (where the hardcoded path is after
you run ./configure). The method will first look for the location of
the cgi.cfg file in an Apache environment variable. If there is no env
variable set, it will then use the value in locations.h.

The one small thing I'm running into with this is that I get a bunch of
warning messages when I run make all. They are cast warnings relating
to the changes I made, but the code does work fine. If anyone who is a
better coder wants to look into this and make the patch better, please
feel free.

Now, to use the Apache environment variables, you need to edit your
httpd.conf. Here is a sample of an edited httpd.conf.

# Nagios CGI-Bin Alias
ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/

AllowOverride AuthConfig
Options ExecCGI
Order allow,deny
Allow from all
SetEnv NAGIOS_CGI_CONFIG /usr/local/nagios/etc/cgi.cfg


This requires Apache 1.3.7 or higher. But all you have to do is add the
one extra line per Nagios CGI Alias definition in the httpd.conf. This
patch won't work for Netscape Webserver, but there's probably a similar
way of getting an environment variable if someone wants to look into it.

I don't know if this can be a permanent solution for the Nagios CGI's
that should be added to the code base, but it is working well for us.
If you have any questions/comments, please email me (and the list)
back. Thanks.

-Russell Scibetti


--
Russell Scibetti
Quadrix Solutions, Inc.
http://www.quadrix.com
(732) 235-2335, ext. 7038


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

diff -c oldcgi/auth.c newcgi/auth.c
*** oldcgi/auth.c Tue Aug 13 13:40:28 2002
--- newcgi/auth.c Tue Aug 13 13:40:40 2002
***************
*** 107,113 ****
}

/* read in authorization override vars from config file... */
! fp=fopen(DEFAULT_CGI_CONFIG_FILE,"r");
if(fp!=NULL){

while(read_line(input_buffer,MAX_INPUT_BUFFER,fp)){
--- 107,113 ----
}

/* read in authorization override vars from config file... */
! fp=fopen(get_cgi_config_location(),"r");
if(fp!=NULL){

while(read_line(input_buffer,MAX_INPUT_BUFFER,fp)){
diff -c oldcgi/avail.c newcgi/avail.c
*** oldcgi/avail.c Tue Aug 13 13:40:28 2002
--- newcgi/avail.c Tue Aug 13 13:40:40 2002
***************
*** 256,265 ****
reset_cgi_vars();

/* read the CGI configuration file */
! result=read_cgi_config_file(DEFAULT_CGI_CONFIG_FILE);
if(result==ERROR){
document_header(FALSE);
! cgi_config_file_error(DEFAULT_CGI_CONFIG_FILE);
document_footer();
return ERROR;
}
--- 256,265 ----
reset_cgi_vars();

/* read the CGI configuration file */
! result=read_cgi_config_file(get_cgi_config_location());
if(result==ERROR){
document_header(FALSE);
! cgi_config_file_error(get_cgi_config_location());
document_footer();
return ERROR;
}
***************
*** 283,289 ****
}

/* read all status data */
! result=read_all_status_data(DEFAULT_CGI_CONFIG_FILE,READ_ALL_STATUS_DATA);
if(result==ERROR){
document_header(FALSE);
status_data_error();
--- 283,289 ----
}

/* read all status data */
! result=read_all_status_data(get_cgi_confi

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: russell@quadrix.com
Locked