nagios perl module

Bryan Liles lilesb at ijet.com
Mon Feb 10 18:58:57 CET 2003


I have created Nagios-Perl for the Osesm GTK Nagios project.  This perl module 
will load a nagios configuration given the location of a local nagios.cfg 
file.

Currently, Nagios-Perl will load host configuration files given a cfg_file or 
a cfg_dir directive.  Since this is a brand new package, saving the changes 
you might make back to the config file isn't implemented yet.  I plan on 
implementing this, so you can load up a set of configuration files, make 
changes to hosts, hostgroups, services, etc..., and then save them back to 
the same file they were defined in.  I am developing this package with the 
small to medium site in mind.  I have no idea how much memory will be used 
when you load up thousands of objects (yet!!) 

Right now, this module is only packaged for use in the Osesm project.  Could 
anyone else here find use for this?  If so, I will document it, and package 
it as a separate file release at sourceforge.

An example:

#!/usr/bin/perl

# Load nagios module
use nagios;

# Turn on strict
use strict;

# Create Nagios object
my $ncfg = nagios->new();

# Point Nagios object to a nagios config
$ncfg->config("/usr/local/nagios/etc/nagios.cfg");

# Get a list of host files in the config
my @hosts = $ncfg->getHosts();

# List all the hosts in the config
foreach my $h (@hosts) {

	# Get the name of this host.  nagios.pm sets a qName object for each record 
	# as the quick name.  It does this because you can have host objects and 
	# host object templates.  
	my $name = $h->qName;

	# if this is a template, the qName will match name
	if ($name eq $h->name) {
		print "Host Template: $name\n";
	}
	
	# if this is a host, the qName will match host_name
	elsif ($name eq $h->host_name) {
		print "Host: $name\n";
	}
}
-- 
Bryan Liles <bryan at osesm.com>



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com




More information about the Users mailing list