AnyEvent-Porttracker
view release on metacpan or search on metacpan
DESCRIPTION
Porttracker (<http://www.porttracker.com/>) is a product that (among
other things) scans switches and routers in a network and gives a
coherent view of which end devices are connected to which switch ports
on which switches and routers. It also offers a JSON-based client API,
for which this module is an implementation.
In addition to Porttracker, the PortIQ product is also supported, as it
uses the same protocol.
If you do not have access to either a Porttracker or PortIQ box then
this module will be of little value to you.
This module is an AnyEvent user, you need to make sure that you use and
run a supported event loop.
To quickly understand how this module works you should read how to
construct a new connection object and then read about the event/callback
system.
The actual low-level protocol and, more importantly, the existing
requests and responses, are documented in the official Porttracker API
documentation (a copy of which is included in this module as
AnyEvent::Porttracker::protocol.
THE AnyEvent::Porttracker CLASS
The AnyEvent::Porttracker class represents a single connection.
$api = new AnyEvent::Porttracker [key => value...]
Creates a new porttracker API connection object and tries to connect
to the specified host (see below). After the connection has been
established, the TLS handshake (if requested) will take place,
followed by a login attempt using either the "none",
"login_cram_md6" or "login" methods, in this order of preference
(typically, "login_cram_md6" is used, which shields against some
man-in-the-middle attacks and avoids transferring the password).
It is permissible to send requests immediately after creating the
object - they will be queued until after successful login.
Possible key-value pairs are:
host => $hostname [MANDATORY]
The hostname or IP address of the Porttracker box.
port => $service
The service (port) to use (default: "porttracker=55").
user => $string, pass => $string
These are the username and password to use when authentication
is required (which it is in almost all cases, so these keys are
normally mandatory).
tls => $bool
Enables or disables TLS (default: disables). When enabled, then
the connection will try to handshake a TLS connection before
logging in. If unsuccessful a fatal error will be raised.
Since most Porttracker/PortIQ boxes will not have a
sensible/verifiable certificate, no attempt at verifying it will
be done (which means man-in-the-middle-attacks will be trivial).
If you want some form of verification you need to provide your
own "tls_ctx" object with "verify => 1, verify_peername => [1,
1, 1]" or whatever verification mode you wish to use.
tls_ctx => $tls_ctx
The AnyEvent::TLS object to use. See "tls", above.
on_XYZ => $coderef
You can specify event callbacks either by sub-classing and
overriding the respective methods or by specifying code-refs as
key-value pairs when constructing the object. You add or remove
event handlers at any time with the "event" method.
$api->req ($type => @args, $callback->($api, @reply))
Sends a generic request of type $type to the server. When the server
responds, the API object and the response arguments (without the
success status) are passed to the callback, which is the last
argument to this method.
If the request fails, then a fatal error will be raised. If you want
to handle failures gracefully, you need to use "->req_failok"
instead.
The available requests are documented in the Porttracker API
documentation (a copy of which is included in this module as
AnyEvent::Porttracker::protocol.
It is permissible to call this (or any other request function) at
any time, even before the connection has been established - the API
object always waits until after login before it actually sends the
requests, and queues them until then.
Example: ping the porttracker server.
$api->req ("ping", sub {
my ($api, $ok, $timestamp, $pid) = @_;
...
});
Example: determine the product ID.
$api->req (product_id => sub {
my ($api, $ok, $branding, $product_id) = @_;
...
});
Example: set a new license.
$api->req (set_license => $LICENSE_STRING, sub {
my ($api, $ok) = @_;
$ok or die "failed to set license";
});
@res = $api->req_sync ($type => @args)
Similar to "->req", but waits for the results of the request and on
success, returns the values instead (without the success flag, and
only the first value in scalar context). On failure, the method will
"croak" with the error message.
$api->req_failok ($type => @args, $callback->($api, $success, @reply))
Just like "->req", with two differences: first, a failure will not
( run in 0.626 second using v1.01-cache-2.11-cpan-39bf76dae61 )