Monit::HTTP - an OOP interface to Monit.
Version 0.01
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 ':constants'; my $hd = new Monit::HTTP( 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 $@; };
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.
$monit = new Monit::HTTP (...)
Constructor. Create a new Monit::HTTP object. This constructor can be called passing a list of various parameters:
Monit::HTTP
my $monit = new Monit::HTTP ( 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->set_hostname($hostname)
Set the hostname of the monit instance
Monit::HTTP->set_port($port)
Set the tcp port of the monit instance
Monit::HTTP->set_username($username)
Set the username to be used in thee basic http authentication
Monit::HTTP->set_password($password)
Set the password to be used in thee basic http authentication
$res = Monit::HTTP->_fetch_info()
Called bye Monit::HTTP-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.
Monit::HTTP-
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->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->_set_xml($xml)
Private method to set raw xml data. Called from Monit::HTTP-_fetch_info()>
$res = Monit::HTTP->_get_xml($xml)
Private method to get raw xml data. Called from Monit::HTTP-_fetch_info()>
$hashref_tree = Monit::HTTP->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. To know the structure of the hash ref use Data::Dumper :D
$hashref_tree = Monit::HTTP->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.
Angelo "pallotron" Failla, <pallotron at freaknet.org>
<pallotron at freaknet.org>
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.
bug-monit-http-api at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Monit::HTTP
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Monit-HTTP-API
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Monit-HTTP-API
CPAN Ratings
http://cpanratings.perl.org/d/Monit-HTTP-API
Search CPAN
http://search.cpan.org/dist/Monit-HTTP-API
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.
To install Monit::HTTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Monit::HTTP
CPAN shell
perl -MCPAN -e shell install Monit::HTTP
For more information on module installation, please visit the detailed CPAN module installation guide.