NAME
Monit::HTTP::API - an OOP interface to Monit.
VERSION
Version 0.01
SYNOPSIS
This module exposes an interface to talk with Monit via its HTTP interface. You can use it to get the status of all the monitored services on that particular host such as CPU and Memory usage, current PID, parent PID, current running status, current monitoring status and so on. The module can be used also for performing actions like:
Start/Stop/Restart services
Monitor/Unmonitor services
use Monit::HTTP::API ':constants'; my $hd = new Monit::HTTP::API( hostname => '127.0.0.1', port => '2812', use_auth => 1, username => 'admin', password => 'monit', ); eval { my @processes = $hd->get_services(TYPE_PROCESS); $hd->command_run($processes[0], ACTION_STOP); my $service_status_href = $hd->service_status($processes[0]); } or do { print $@; };
EXPORTED CONSTANTS
This module exports a set of constants:
TYPE_FILESYSTEM
TYPE_DIRECTORY
TYPE_FILE
TYPE_PROCESS
TYPE_HOST
TYPE_SYSTEM
TYPE_FIFO
ACTION_STOP
ACTION_START
ACTION_RESTART
ACTION_MONITOR
ACTION_UNMONITOR
They are meant to be used as arguments of the methods.
METHODS
$monit = new Monit::HTTP::API (...)
Constructor. Create a new Monit::HTTP::API
object. This constructor can be called passing a list of various parameters:
my $monit = new Monit::HTTP::API (
hostname => localhost,
port => 2812,
use_auth => 1,
username => admin,
password => monit );
The values showed above are the default values in case no argument is passed to the constructor. If use_auth is equal to 1 (true) and username and password are not null the http request will be peformed using those usernames and password (basic http auth). Be aware that if you provide username and password and you don't set use_auth to be 1 authentication won't work.
Monit::HTTP::API-
set_hostname($hostname)>
Set the hostname of the monit instance
Monit::HTTP::API-
set_port($port)>
Set the tcp port of the monit instance
Monit::HTTP::API-
set_username($username)>
Set the username to be used in thee basic http authentication
Monit::HTTP::API-
set_password($password)>
Set the password to be used in thee basic http authentication
$res = Monit::HTTP::API-
_fetch_info()>
Called bye Monit::HTTP::API-
get_services()>. Does not need to be called by user. This is a private (internal) method This private function connects via http (GET) to the monit server.
URL requested is http://<hostname>:<port>/_status?format=xml
An XML file is returned and parsed using XML::Bare.
The raw XML data is stored in the object using the _set_xml() method. The raw XML data can be retrieved using _get_xml.
An hash reference of the XML data (as the one returned by the parse_xml function of XML::Bare) is stored in the object.
$res = Monit::HTTP::API-
get_services()>
Return an array of services configured on the remote monit daemon.
In case of any exepction an error is thrown and undef is returned.
$res = Monit::HTTP::API-
_set_xml($xml)
Private method to set raw xml data. Called from Monit::HTTP::API-
_fetch_info()>
$res = Monit::HTTP::API-
_get_xml($xml)
Private method to get raw xml data. Called from Monit::HTTP::API-
_fetch_info()>
$hashref_tree = Monit::HTTP::API-
service_status($servicename)
Returns the status for a particular service in form of hash with all the info for that service. Return undef is the service does not exists.
$hashref_tree = Monit::HTTP::API-
command_run($servicename, $command)
Perform an action against a service. $command can be a constant (ACTION_STOP, ACTION_START, ACTION_RESTART, ACTION_MONITOR, ACTION_UNMONITOR)
This method throws errors in case something goes wrong. Use eval { } statement to catch the error.
AUTHOR
Angelo "pallotron" Failla, <pallotron at freaknet.org>
BUGS
Please report any bugs or feature requests to bug-monit-http-api at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Monit-HTTP-API. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Monit::HTTP::API
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2009 Angelo "pallotron" Failla, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.