[Nagios-devel] Making the CGI's portable

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] Making the CGI's portable

Post by Guest »

I have written to the users list once or twice about an apparent issue
in the CGI's. You can't move around the compiled CGI's without
recompiling and making because they use a hardcoded path from
common/locations.h. Almost all the CGI's use the variable
DEFAULT_CGI_CONFIG_FILE which contains a hardcoded path generated by
./configure. One of the cgi related files (cgiutils.c) also has another
hardcoded reference, this one for DEFAULT_COMMAND_FILE.

We have figured out a pretty simple way of making the CGI's portable
without needing to recompile through using Apache environment variable.
**NOTE:** Our solution only works with Apache version 1.3.7 and
higher! We've added two method to cgiutils.c as follows:

/* read the CGI config file location from an environment variable */
char * get_cgi_config_location() {
static char *cgiloc = NULL;
if (!cgiloc) {
cgiloc = getenv("NAGIOS_CGI_CONFIG");
if (!cgiloc) {
cgiloc = DEFAULT_CGI_CONFIG_FILE;
}
}
return cgiloc;
}

/* read the command file location from an environment variable */
char * get_cmd_file_location() {
static char *cmdloc = NULL;
if (!cmdloc) {
cmdloc = getenv("NAGIOS_COMMAND_FILE");
if (!cmdloc) {
cmdloc = DEFAULT_COMMAND_FILE;
}
}
return cmdloc;
}

Then we edited cgiutils.h.in by adding the following 2 lines under the
functions section:

char * get_cgi_config_location();
char * get_cmd_file_location();

Then, in all the CGI source code (the .c files in the cgi directory), we
replaced references to DEFAULT_CGI_CONFIG_FILE with
get_cgi_config_location() and the one DEFAULT_COMMAND_FILE reference in
cgiutils.c with get_cmd_file_location(). Now, nagios will first try to
get the location of the cgi.cfg and nagios.cmd files from the apache
environment. If they don't exist there, then nagios uses the defaults.

Now, you need to add the environment variables to apache's httpd.conf in
the Nagios directory entry as such:

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

AllowOverride AuthConfig
Options ExecCGI
Order allow,deny
Allow from all
SetEnv NAGIOS_CGI_CONFIG /usr/local/nagios-client2/etc/cgi.cfg
SetEnv NAGIOS_COMMAND_FILE
/usr/local/nagios-client2/var/rw/nagios.cmd


For every Nagios install that uses CGI's, just add these two lines to
that nagios instances's directory entry in httpd.conf. Now, when you
run ./configure and make all to create the nagios daemon and cgi's, the
cgi's will be set to look for these apache environment variables before
using the defaults. You can now copy this instance of Nagios and CGI's
anywhere you want, and as long as you edit the .cfg files properly (lots
of paths to edit), you do not need to recompile and remake every time.

Remember this will only work with Apache 1.3.7 and up (the environment
variables cannot be set for different Directories in apache versions
older than that).

If there is anything that's unclear, feel free to email me back and I'll
try to explain more.

-Russell Scibetti

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







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