NAME
Nagios::Config - Parse Nagios configuration files
SYNOPSIS
use Nagios::Config ;
my $nc = new Nagios::Config("/usr/local/nagios/etc/nagios.cfg") ;
foreach my $object ($nc->get_objects('host')){
print $object->get('host_name') . "\n" ;
}
DESCRIPTION
Nagios::Config
parses the Nagios configuration files in order to extract all information about nagios.cfg, resource.cfg and template-based objects. All template values are merged recursively, meaning that each object has all its attributes present, even those that were defined in templates.
Note: Nagios::Config
assumes that your Nagios configuration is valid and may react unexpectedly if it is not. Please check your configuration using the "nagios -v" command prior to using Nagios::Config
on it.
CONSTRUCTOR
- new ([FILE])
-
Creates a
Nagios::Config
, which will parse the contents ofFILE
assuming it is a Nagios Main Configuration File.FILE
can be a file name or a reference to an already opened filehandle. IfFILE
is false, it will default to "/usr/local/nagios/etc/nagios.cfg"
METHODS
- get_object_types ()
-
Returns a list of all the object types that where encountered during the parse.
Ex: my @types = $nc->get_object_types() ;
- get_object_files ()
-
Returns a list of all the template object files (as
Nagios::Config::ObjectFile
objects) that where parsed.Ex: my @files = $nc->get_object_files() ;
- get_objects ([TYPE])
-
Returns a list of all the objects of type
TYPE
that where found during the parse. Each of these objects will be blessed in the Nagios::Config::Object::TYPE
package, which inherits from Nagios::Config::Object.Ex: my @hosts = $nc->get_objects('host') ;
- get_object_hash ([TYPE], [KEY])
-
Returns a hash of all the objects of type
TYPE
that where found during the parse, using attributeKEY
as the hash key. Make sure that the value ofKEY
is unique for each object, or else you will not get all the objects in the hash. Each of these objects will be blessed in the Nagios::Config::Object::TYPE
package, which inherits from Nagios::Config::Object.Ex: my %hosts = $nc->get_object_hash('host', 'host_name') ;
- find_objects ([TYPE], [ATTR], [QUERY], [SPLIT])
-
Returns a list of all the objects of type
TYPE
that where found during the parse, whereATTR
"matches"QUERY
.QUERY
can be a regular expression (i.e. qr/.../) or a scalar. IfSPLIT
is true, the values will be split on /\s*,\s*/ and each of the resulting values will be compared separately. Also, if the value of theATTR
is '*', the object is returned regardless of the value ofQUERY
. Each of these objects will be blessed in the Nagios::Config::Object::TYPE
package, which inherits from Nagios::Config::Object.Ex: my %my_host_services = $nc->get_object_hash('service', 'host_name', 'my_host', 1) ;
- get_nagios_cfg ()
-
Returns the
Nagios::Config::File
object corresponding to nagios.cfg. - get_resource_cfg ()
-
Returns the
Nagios::Config::File
object corresponding to resource.cfg.
AUTHOR
Patrick LeBoutillier, patl@cpan.org
SEE ALSO
Nagios::Config::File, Nagios::Config::ObjectFile, Nagios::Config::Object