WebService::LogicMonitor - Interact with LogicMonitor's API
version 0.153170
use v5.16;
use warnings;
use Try::Tiny;
use WebService::LogicMonitor;
# find a hostgroup by name, iterate through its child groups
# and check the status of a datasource instance
my $lm = WebService::LogicMonitor->new(
username => $ENV{LOGICMONITOR_USER},
password => $ENV{LOGICMONITOR_PASS},
company => $ENV{LOGICMONITOR_COMPANY},
);
my $top_group_name = shift || die "What group?\n";
my $datasource = shift || 'Ping';
sub recurse_group {
my $group = shift;
foreach my $entity (@{$group->children}) {
if ($entity->is_group) {
say 'GROUP: ' . $entity->name;
recurse_group($entity);
} elsif ($entity->is_host) {
say ' HOST: ' . $entity->host_name;
my $instances = try {
$entity->get_datasource_instances($datasource);
} catch {
say "Failed to retrieve data source instances: " . $_;
next;
};
next unless $instances;
# assume only one instance
my $instance = shift @$instances;
say ' datasource status: '
. ($instance->enabled ? 'enabled' : 'disabled');
say ' alert status: '
. ($instance->alert_enable ? 'enabled' : 'disabled');
}
}
}
my $groups = $lm->get_groups(name => $top_group_name);
recurse_group(shift @$groups);
LogicMonitor is a SaaS infrastructure monitoring provider. They provide an RPC API which provides most of functionality of their web GUI (with the unfortunate omission of managing DataSources).
They have recently started a REST API which covers a different set of functionality.
This module puts an OO wrapper around the RPC API in what is a hopefully a much more convenient and user-friendly manner.
HOWEVER the API provided by this module is not considered stable and will almost certainly have some changes before version 1.0.
The CUP authentication details for your LogicMonitor account. See http://help.logicmonitor.com/developers-guide/authenticating-requests/
Returns an arrayref of all available escalation chains.
http://help.logicmonitor.com/developers-guide/manage-escalation-chains/#get1
Convenience wrapper aroung "get_escalation_chains" which only returns chains
where a name eq $name
.
Retrieves a complete list of accounts as an arrayref.
http://help.logicmonitor.com/developers-guide/manage-user-accounts/#getAccounts
Convenience wrapper aroung "get_accounts" which only returns accounts matching $email.
Convenience wrapper aroung "get_accounts" which only returns accounts
matching $username
.
Returns an arrayref of alerts or undef if none found.
See http://help.logicmonitor.com/developers-guide/manage-alerts/ for what parameters are available to filter the alerts.
Creates and returns a new host. Shortcut for WebService::LogicMonitor::Host
new
and create
Deletes a host identified by its displayname. Convenience wrapper around "get_host" in WebService::LogicMonitor and "delete" in WebService::LogicMonitor::Host.
Return a host.
http://help.logicmonitor.com/developers-guide/manage-hosts/#get1
Return an array of hosts in the group specified by group_id
http://help.logicmonitor.com/developers-guide/manage-hosts/#get1
In scalar context, will return an arrayref of hosts in the group.
In array context, will return the same arrayref plus a hashref of the group.
Convenience wrapper around "get_hosts" which returns all hosts. BEWARE This will probably take a while.
Returns an arrayref of all host groups.
http://help.logicmonitor.com/developers-guide/manage-host-group/#list
Optionally takes a string or regexp as an argument. Only those hostgroups with names
matching the argument will be returned, or undef if there are none. If the arg is a string,
it must be an exact match with eq
.
Returns an array of SDT hashes. With no args, it will return all SDTs in the account. See the LoMo docs for details on what keys are supported.
http://help.logicmonitor.com/developers-guide/schedule-down-time/get-sdt-data/
Sets SDT for an entity. Entity can be
Host
HostGroup
HostDataSource
DataSourceInstance
HostDataSourceInstanceGroup
Agent
The id for Host can be either an id number or hostname string.
To simplify calling this we take two keys, start
and end
which must
be either DateTime objects or ISO8601 strings parseable by
DateTime::Format::ISO8601.
http://help.logicmonitor.com/developers-guide/schedule-down-time/set-sdt-data/
$lomo->set_sdt(
Host => 'somehost',
start => '20151101T1000',
end => '20151101T1350',
comment => 'Important maintenance',
);
Wrapper around "set_sdt" to quickly set SDT starting immediately. The lenght of the SDT can be specfied as hours, minutes or any other unit supported by https://metacpan.org/pod/DateTime#Adding-a-Duration-to-a-Datetime, but only one unit can be specified.
$lomo->set_quick_sdt(Host => 'somehost', minutes => 30, comment => 'Reboot to annoy support');
$lomo->set_quick_sdt(HostGroup => 456, hours => 6);
Ioan Rogers <ioan.rogers@sophos.com>
This software is copyright (c) 2015 by Sophos Ltd.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
This repository has been formally archived, the project supporting it has been closed and no future updates will be made. The code will remain available for a period of time until and unless the owner decides to withdraw it.