Subject: | Nagios::Object::Config not handling include_file=, include_dir= directives |
There appears to be a poorly (if at all) documented feature in nagios
object configuration
files for including other files: the
include_file=_path_to_file_
and
include_dir=_path_to_dir_
Seem to operate much like cfg_file, cfg_dir, but also appear to be
allowed in object config
files (not sure if available in main config, but cfg_file/cfg_dir seem
to do same thing.)
Since someone at our site discovered this "feature" way back, we make
heavy use of, and w/out
attached patch most of our config is silently ignored.
Have only tested the include_file portion of patch, and not positive if
include_dir requires
the .cfg suffix or not (am planning to submit documentation bug report
to Nagios re this).
Thanks for the package. Looks like will be quite useful here.
Subject: | patch.diff |
diff -Naur Nagios-Object-0.21.5/lib/Nagios/Object/Config.pm Nagios-Object-0.21.5-patched/lib/Nagios/Object/Config.pm
--- Nagios-Object-0.21.5/lib/Nagios/Object/Config.pm 2009-06-08 11:16:32.000000000 -0400
+++ Nagios-Object-0.21.5-patched/lib/Nagios/Object/Config.pm 2009-07-10 15:11:45.000000000 -0400
@@ -180,6 +180,24 @@
$append = undef;
}
+ if ( $line =~ /include_file\s*=\s*([\w\-\/\\\:\.]+)/ )
+ { my $incfile = $1;
+ $self->parse($incfile);
+ next;
+ }
+ if ( $line =~ /include_dir\s*=\s*([\w\-\/\\\:\.]+)/ )
+ { my $incdir = $1;
+ opendir(INCDIR, $incdir) or next; #Just ignore if can't open directory?
+ my @files = readdir(INCDIR);
+ closedir(INCDIR);
+ @files = grep /\.cfg$/, @files; #Only want *.cfg files
+ @files = grep { -f "$incdir/$_" } @files; #Only want files
+ foreach my $file (@files)
+ { $self->parse($file);
+ }
+ next;
+ }
+
# end of object definition
# Some object attributes are strings, which can contain a right-curly bracket and confuse this parser:
# - The proper fix would be to make the parser sensitive to arbitrary string attributes, but I will just