Patch for 'cfg_dir' to follow symlinks in 2.0

Mueller, Karl KMueller at netsuite.com
Tue Apr 13 02:20:38 CEST 2004


I sent an email earlier about whether symlink following would be a good
idea or not.  Since then, I thought about it and couldn't find a reason
it would be bad in most cases.  The only problem that I could come up
with is if somebody had a "cfg_dir" entry pointing to a directory with
non-Nagios symlinks.  This seems counter to the point of cfg_dir, which
implies everything in it are nagios configs objects, so I was not really
worried about that too much.

In looking at a new template architecture here at my company, sharing
configuration directories via symlinks seemed to make a lot of sense.
You could probably produce something similar in effect with a lot of
cfg_file/cfg_dir entries, but it seems simpler  to be able to link them
in at the configuration tree level as opposed to creating entries for
disparate trees to be loaded.  It also allows for a lot more granularity
as symlinks are simpler than main config line entries.  (At least, this
has been my experience)  

For my planned setup, it was looking like I might need 20-30 or more
cfg_dir/cfg_file lines, whereas I can do the same thing with 5 cfg_dir
lines and a handful of symlinked directories & files.  If you have a
shared configuration tree for all Nagios servers like I do, then you
realize the value of editing the config in the tree and not in the
nagios.cfg file.

At the least, this would give me an option for which is better for my
local environment.


I just sat down and wrote the patch to make this work.  The patch does
the following:

1) When recursing through cfg_dir directories (in
xodtemplate_process_config_dir() ), it will also look at symlinks, both
for directories and files.  (readdir() entries for d_type DT_LNK are now
not always ignored)

2) In the case of a '.cfg' file that is a symlink (d_type = DT_LNK),
Nagios will just try to read it outright.  An error (such as a symlink
pointing to an invalid location) will produce a standard "cannot read
file" error.  Otherwise, it is invisible.

3) In the case of a directory, things are a bit more complicated.  If a
symlink exists, since we're not longer limited to '.cfg' files, it could
be a directory or anything else.  We only want to recurse into
directories that are symlinked.  I added checking to make sure the
target of the symlink is a directory.

4) When trying to open a file, it will print the error string now if it
fails.  (Often it's just that it can't read it, but it's more clear)


The patch is located at 

http://www.xney.com/nagios/nagios-2.0-symlink.patch

It's a diff against the xodtemplate.c file in xdata/

If others are interested in the functionality, I'd appreciate some
testing feedback.  I ran a bunch of test cases (positive and negative)
and it seemed to work well, but I haven't run it through a huge number
of them.

I thought about making it a configure option in the 'configure' script,
but it didn't seem obvious as to how to make all that work.  

I'd appreciate any feedback, including the "you're a total moron" type
(if it's true)

-Karl




-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click




More information about the Developers mailing list