Mon::Client - Methods for interaction with Mon client
use Mon::Client;
Mon::Client is used to interact with "mon" clients. It supports a protocol-independent API for retrieving the status of the mon server, and performing certain operations, such as disableing hosts and service checks.
Creates a new object. A hash can be supplied which sets the default values. An example which contains all of the variables that you can initialize:
$c = new Mon::Client ( host => "monhost", port => 2583, username => "foo", password => "bar", );
%hash is optional, but if specified, should contain two keys, username and password.
Performs the "login" command to authenticate the user to the server. Uses username and password if specified, otherwise uses the username and password previously set by those methods, respectively.
Returns a hash of service descriptions, indexed by watch and service. For example:
%desc = $mon->list_descriptions; print "$desc{'watchname'}->{'servicename'}\n";
Lists dependency expressions and their components for all services. If there is no dependency for a particular service, then the value will be "NONE".
%deps = $mon->list_deps; foreach $watch (keys %deps) { foreach $service (keys %{$deps{$watch}}) { my $sref = \%{$deps{$watch}->{$service}}; print "expr ($watch,$service) = $sref->{expression}\n"; print "components ($watch,$service) = @{$sref->{components}}\n"; } }
Returns an array of all the defined watch groups and services.
foreach $w ($mon->list_watch) { print "group=$w->[0] service=$w->[1]\n"; }
Returns a hash of per-service operational statuses, as indexed by watch and service. The list of anonymous arrays is optional, and if is not provided then the status of all groups and services will be queried.
%s = $mon->list_opstatus; foreach $watch (keys %s) { foreach $service (keys %{$s{$watch}}) { foreach $var (keys %{$s{$watch}{$service}}) { print "$watch $service $var=$s{$watch}{$service}{$var}\n"; } } }
Returns a hash of disabled watches, services, and hosts.
%d = $mon->list_disabled;
foreach $group (keys %{$d{"hosts"}}) { foreach $host (keys %{$d{"hosts"}{$group}}) { print "host $group/$host disabled\n"; } }
foreach $watch (keys %{$d{"services"}}) { foreach $service (keys %{$d{"services"}{$watch}}) { print "service $watch/$service disabled\n"; } }
for (keys %{$d{"watches"}}) { print "watch $_ disabled\n"; }
Returns an array of hash references containing the alert history.
@a = $mon->list_alerthist;
for (@a) { print join (" ", $_->{"type"}, $_->{"watch"}, $_->{"service"}, $_->{"time"}, $_->{"alert"}, $_->{"args"}, $_->{"summary"}, "\n", ); }
Returns an array of hash references containing the downtime log.
@a = $mon->list_dtlog
for (@a) { print join (" ", $_->{"timeup"}, $_->{"group"}, $_->{"service"}, $_->{"failtime"}, $_->{"downtime"}, $_->{"interval"}, $_->{"summary"}, "\n", ); }
Returns an array of hash references containing the failure history.
@f = $mon->list_failurehist;
for (@f) { print join (" ", $_->{"watch"}, $_->{"service"}, $_->{"time"}, $_->{"summary"}, "\n", ); }
Returns an array of hash references containing the list of process IDs of currently active monitors run by the server.
@p = $mon->list_pids;
$server = shift @p;
for (@p) { print join (" ", $_->{"watch"}, $_->{"service"}, $_->{"pid"}, "\n", ); }
Lists the state of the scheduler. Returns a two-element array. The first element of the array is 0 if the scheduler is stopped, and 1 if the scheduler is currently running. The second element of the array returned is the string "scheduler running" if the scheduler is currently running, and if the scheduler is stopped, the second element is the time(2) that the scheduler was stopped.
@s = $mon->list_state;
if ($s[0] == 0) { print "scheduler stopped since " . localtime ($s[1]) . "\n"; }
Tests the syntax of the configuration file. Returns a two-element array. The first element of the array is 0 if the syntax of the config file is invalid, and 1 if the syntax of the config file is OK. The second element of the array returned is the failure message, if the config file has invalid syntax, and the result code if the config file syntax is OK. This function returns undef if it cannot get a connection or a response from the mon server.
Config file checking stops as soon as an error is found, so you will need to run this command more than once if you have multiple errors in your config file in order to find them all.
@s = $mon->test_config;
if ($s[0] == 0) { print "error in config file:\n" . $s[1] . "\n"; }
Sends a trap to a remote mon server. Here is an example:
$mon->send_trap ( group => "remote-group", service => "remote-service", retval => 1, opstatus => "operational status", summary => "summary line", detail => "multi-line detailed information", );
retval must be a nonnegative integer.
opstatus must be one of fail, ok, coldstart, warmstart, linkdown, unknown, timeout, untested.
Returns undef on error.