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", );
If pw is provided, sets the password. Otherwise, returns the currently set password.
If host is provided, sets the mon host. Otherwise, returns the currently set mon host.
If portnum is provided, sets the mon port number. Otherwise, returns the currently set port number.
If user is provided, sets the user login. Otherwise, returns the currently set user login.
If protocol is provided, sets the protocol, specified by a string which is of the form "1.2.3", where "1" is the major revision, "2" is the minor revision, and "3" is the sub-minor revision. If protocol is not provided, the currently set protocol is returned.
Compares two protocol versions and returns -1, 0, or 1 if prot_a is less than, equal, or greater than prot_b, respectively. The protocols must be specified in the form described by above entry for "prot".
Returns the protocol version of the remote server.
Returns the error string from set by the last method, or undef if there was no error.
Returns 0 (not connected) or 1 (connected).
Connects to the server. If host and port have not been set, uses the defaults. Returns undef on error.
Disconnects from the server. Return undef on error.
%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.
Disables watch.
Disables a service, as specified by watch and service.
Disables host.
Enables watch.
Enables a service as specified by watch and service.
Enables host.
Sets var in group,service to val. Returns undef on error.
Gets variable var in group,service and returns it, or undef on error.
Logs out of the server. This method should be followed by a call to the disconnect method.
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"; } }
Lists members of hostgroup. Returns an array of each member.
Returns a hash of per-service operational statuses, as indexed by watch and service.
%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 in the same manner as list_opstatus, but only the services which are in a failure state.
Returns a hash in the same manner as list_opstatus, but only the services which are in a success state.
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 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.
@s = $mon->list_state; if ($s[0] == 0) { print "scheduler stopped since " . localtime ($s[1]) . "\n"; }
Starts the scheduler.
Stops the scheduler.
Resets the server.
Causes the server to reload its configuration.
Terminates the server.
Sets the maximum number of history entries to store in memory.
Returns the maximum number of history entries to store in memory.
Schedules a service to run immediately.
When group/service is in a failure state, acknowledges this with text, and disables all further alerts during this failure period.
Loads state.
Saves state.
Returns the time on the server using the same output as the time(2) system call.
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.
To install Mon::SNMP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mon::SNMP
CPAN shell
perl -MCPAN -e shell install Mon::SNMP
For more information on module installation, please visit the detailed CPAN module installation guide.