Nagios...Config(3pm)
β¨ Nagios...Config β¨
okay bestie, welcome to the Nagios...Config page β it's a User Contributed Perl Documentation situation and honestly? it's giving useful. pull up a chair π
πΈ NAME πΈ
Nagios::Object::Config β perl objects that represent your Nagios configuration. literally that's the whole thing. iconic.
π¦ DESCRIPTION π¦
so this is a module for parsing and processing Nagios object configuration files and turning them into perl objects. that's it, that's the vibe. π
π METHODS π
new()
creates a shiny new configuration object β¨
okay important stuff, no cap: if you don't specify Version, the validation that's already weak gets weakened even further, which lets you mix Nagios 1.0 and 2.0 configs together. chaotic but fine.
for now, the minor numbers of Version are ignored. and do NOT put any letters in there, like '2.0a1' β just don't. π
to turn on regular expression matching, use either the regexp_matching or true_regexp_matching arguments to new(). go peek at enable_regexp_matching() and enable_true_regexp_matching() below for the tea π
my $objects = Nagios::Object::Config->new();
my $objects = Nagios::Object::Config->new( Version => 1.2 );
my $objects = Nagios::Object::Config->new(
Version => 2.0,
regexp_matching => 1,
true_regexp_matching => 2
);
parse()
parses a nagios object configuration file into memory πΎ
heads up tho: even though Nagios::Objects get created, they are not really usable until you call the register() method. so like, don't skip that step bestie.
$parser->parse( "myfile.cfg" );
find_object()
searches through the list of objects' names and returns the first match. π
the second argument is optional β but always using it can considerably reduce the size of the list it has to search, so it's recommended. efficiency queen behavior π
my $object = $parser->find_object( "localhost" );
my $object = $parser->find_object( "oracle", "Nagios::Service" );
find_objects()
same energy as above but it returns all the matches. the second argument here is required, no skipping it.
my @object_list = $parser->find_objects( "load", "Nagios::Service" );
find_objects_by_regex()
searches through the objects' names and hands you back a list of matches β¨
the first argument gets evaluated as a regular expression. the second argument is required and tells it what kind of object to search for.
the regexes are built by translating "*" into ".*?" and "?" into ".". and for now (v0.9), this code completely ignores Nagios's use_regexp_matching and use_true_regexp_matching and just does full RE matching all the time. it does what it wants π
my @objects = $parser->find_objects_by_regex( "switch_*", "Nagios::Host" );
my @objects = $parser->find_objects_by_regex( "server0?", "Nagios::Host" );
all_objects_for_type()
gets you a reference to all objects of the specified Nagios object type.
Usage: $objects = all_objects_for_type($object_type)
Parameters:
$object_typeβ a specific Nagios object type, i.e."Nagios::Contact".
Returns:
- a reference to an array of references to all objects of the specified type associated with this configuration. objects of this type added to the configuration after the call to this method _will_ be accessible through this reference after the fact. yes queen, live updates π
- note that the array referenced by the return value may be empty.
Example:
my $contacts = $config->all_objects_for_type("Nagios::Contact");
if (scalar(@$contacts) == 0) {
print "No contacts have yet been defined\n";
} else {
foreach $contact (@$contacts) {
...
}
}
all_objects()
returns an arrayref with all objects parsed from the config chilling inside it. everything. the whole squad. π«Ά
my $everything = $config->all_objects;
find_attribute()
searches through the objects parsed so far, looking for a particular textual name. when it finds it, it returns that object.
call it with two arguments and it'll search through all objects currently loaded until it gets a match. a third argument can specify the type of object to search for, which may speed up the search considerably. so like, use it.
my $object = $parser->find_attribute( "command_name", "check_host_alive" );
my $object = $parser->find_attribute( "command_name", "check_host_alive", 'Nagios::Host' );
resolve()
resolves the template for the specified object. templates will not work until this has been done β so do it, bestie. π
$parser->resolve( $object );
register()
examines every attribute of an object and links all of its references to other Nagios objects over to their respective perl objects π
if this isn't called, some methods will return the textual name instead of a perl object. so like, call it. i'm begging.
$parser->register( $host_object );
my $timeperiod_object = $host_object->notification_period;
resolve_objects()
resolves all objects currently loaded into memory. you can call this any number of times without corruption β it's built different, fr fr. πͺ
$parser->resolve_objects();
register_objects()
same deal as resolve_objects(), but as you'd guess, it registers all objects currently loaded into memory instead. π
$parser->register_objects();
enable_regexp_matching() / disable_regexp_matching()
this correlates to the use_regexp_matching option in nagios.cfg π
when this option is enabled, Nagios::Object::Config will translate "*" into ".*?" and "?" into ".", then evaluate the result as a perl RE, anchored at both ends for any value that can point to multiple other objects (^ and $ are added to either end).
$parser->enable_regexp_matching;
$parser->disable_regexp_matching;
enable_true_regexp_matching() / disable_true_regexp_matching()
this one correlates to the use_true_regexp_matching option in nagios.cfg β¨
it's very similar to the enable_regexp_matching() option, but it matches more data and allows more powerful RE syntax. these modules will give you the full power of perl RE's β which is probably more than is available in Nagios, so don't blame me if something works here but not in Nagios (it's usually the other way around anyways, iykyk π).
the generated RE's have the same translation as above, but they do NOT have the anchors to ^ and $.
this option always supersedes enable_regexp_matching. periodt. π
$parser->enable_true_regexp_matching;
$parser->disable_true_regexp_matching;
list_hosts(), list_hostgroups(), etc.
returns an array/arrayref of objects of the given type π¦
$config->list_hosts
$config->list_hostgroups
$config->list_services
$config->list_timeperiods
$config->list_commands
$config->list_contacts
$config->list_contactgroups
$config->list_hostdependencies
$config->list_servicedependencies
$config->list_hostescalations
$config->list_hostgroupescalations
$config->list_serviceescalations
$config->list_servicegroups
$config->list_hostextinfo
$config->list_serviceextinfo
π AUTHOR π
Al Tobey <tobeya@cpan.org>
Contributions From:
- Lynne Lawrence (API & bugs) π«Ά
and that's the whole page bestie!! this doc came to you courtesy of perl v5.34.0, dated 2022-06-16, from Nagios...Config(3pm) β go forth and parse those configs, you absolute main character π β¨π
π¦ where this page comes from
- debian bookworm: libnagios-object-perl 0.21.20-3 Β· GPL-2.0-or-later
- debian trixie: libnagios-object-perl 0.21.20-3 Β· GPL-2.0-or-later
- ubuntu noble: libnagios-object-perl 0.21.20-3 Β· GPL-2.0-or-later
- ubuntu resolute: libnagios-object-perl 0.21.20-3 Β· GPL-2.0-or-later
- ubuntu stonking: libnagios-object-perl 0.21.20-3 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms