Hardware::UPS::Perl::Connection::Net - package of methods to connect to a remote UPS agent.
use Hardware::UPS::Perl::Connection::Net; $net = Hardware::UPS::Perl::Connection::Net->new(); $net = Hardware::UPS::Perl::Connection::Net->new({ Host => 192.168.41.2, TCPPort => 9050, }); undef $net; # disconnects
Hardware::UPS::Perl::Connection::Net provides methods to connect to a remote UPS agent running on host Host at TCP port TCPPort.
new - creates a new UPS connection object using TCP/IP
$net = Hardware::UPS::Perl::Connection::Net->new(); $net = Hardware::UPS::Perl::Connection::Net->new({ Host => $host , TCPPort => $port , Logger => $Logger, });
new initializes a connection object $net and opens the connection to a remotely running UPS agent via TCP, if the host $host and the TCP port $port are specified. If the initialization fails, new returns undef.
new expects either a single argument, the host and, optionally, the TCP port both separated by ":", or an anonymous hash as options consisting of key-value pairs.
$host[:$port]
optional; the host and, optionally, the TCP port; defines the host (and port), where the UPS agent is running.
Host => $host[:$port]
optional; the host; defines the host (and port), where the UPS agent is running.
TCPPort => $port
optional; the TCP port; defines the port at the host, where the UPS agent is running.
Logger => $logger
optional; a Hardware::UPS::Perl::Logging object; defines a logger; if not specified, a logger sending its output to STDERR is created.
"connect", "connected", "disconnect", "getHost", "getLogger", "getTCPPort", "setHost", "setLogger", "setTCPPort"
setHost - sets the host to connect to
$net = Hardware::UPS::Perl::Connection::Net->new(); $net->setHost($host);
setHost sets the host to connect to and returns the previous host if available, undef otherwise.
$host
host; defines a resolvable host.
"new", "connect", "connected", "disconnect", "getHost", "setTCPPort", "getTCPPort"
getHost - gets the host to connect or connected to
$net = Hardware::UPS::Perl::Connection::Net->new({ Host => 192.168.1.2 TCPPort => 9050, }); $host = $net->getHost();
getHost returns the host to connect or already connected to.
"new", "connect", "connected", "disconnect", "getTCPPort", "setHost", "setTCPPort"
setTCPPort - sets the TCP port to connect to
$net = Hardware::UPS::Perl::Connection::Net->new(); $net->setTCPPort($port);
setTCPPort sets the TCP port to connect to and returns the previous TCP port if available, undef otherwise.
$port
natural number; TCP port.
"new", "connect", "connected", "disconnect", "getHost", "getTCPPort", "setTCPPort"
getTCPPort - gets the TCP port to connect or connected to
$net = Hardware::UPS::Perl::Connection::Net->new({ Host => 192.168.1.2 TCPPort => 9050, }); $host = $net->getTCPPort();
getTCPPort returns the TCP port to connect or already connected to.
"new", "connect", "connected", "disconnect", "getHost", "getLogger", "setHost", "setLogger", "setTCPPort"
setDebugLevel - sets the debug level
$net = Hardware::UPS::Perl::Connection::Net->new(); $net->setDebugLevel(1);
setDebugLevel sets the debug level, the higher, the better. It returns the previous one if available, 0 otherwise.
$debugLevel
natural number; defines the debug level.
"getDebugLevel"
getDebugLevel - gets the current debug level
$net = Hardware::UPS::Perl::Connection::Net->new(); $debugLevel = $net->getDebugLevel();
getDebugLevel returns the current debug level.
"setDebugLevel"
setLogger - sets the logger to use
$net = Hardware::UPS::Perl::Connection::Net->new(); $logger = Hardware::UPS::Perl::Logging->new(); $net->setLogger($logger);
setLogger sets the logger object used for logging. setLogger returns the previous logger used.
$logger
required; a Hardware::UPS::Perl:Logging object; defines the logger for logging.
"new", "getLogger"
getLogger - gets the current logger for logging
$net = Hardware::UPS::Perl::Connection::Net->new(); $logger = $net->getLogger();
getLogger returns the current logger, i.e. a Hardware::UPS::Perl::Logging object used for logging, if defined, undef otherwise.
"new", "setLogger"
getErrorMessage - gets the internal error message
$net = Hardware::UPS::Perl::Connection::Net->new(); if (!$net->connected()) { print STDERR $net->getErrorMessage(), "\n"; exit 0; }
getErrorMessage returns the internal error message, if something went wrong.
connect - connects to a romotely running UPS agent
$net = Hardware::UPS::Perl::Connection::Net->new(); $net->connect(); $net->connect({ Host => $host, TCPPort => $port, });
connect connects to an UPS agent running at TCP port $port on host $host using package IO::Socket::INET. If there is already a connection and the host and/or TCP port have changed, the old connection is dropped, otherwise nothing will be done. If no host and/or TCP port are specified, it will be checked whether the host and/or TCP port has been previously set by methods setHost and setTCPPort, respectively, and used for the connection, consequently. If no host and/or no port is available at all. the default host and default TCP port provided by package Hardware::UPS::Perl::Constants will be used, usually being the FQDN of the local host and port 9050.
optional; host; defines a resolvable host (IP address, FQDN, hostname). The TCP port to be used can be appended with a ":".
optional; TCP port; defines a valid TCP port.
"new", "connected", "disconnect", "setHost", "getHost", "setTCPPort", "getTCPPort"
connected - tests the connection status
$net = Hardware::UPS::Perl::Connection::Net->new(); $net->connect(); if ($net->connected()) { ... }
connected tests the connection status, returning 0, when not connected, and 1 when connected.
"new", "connect", "disconnect"
disconnect - disconnects from an UPS agent
$net = Hardware::UPS::Perl::Connection::Net->new(); $net->connect(); $net->disconnect(); $net = Hardware::UPS::Perl::Connection::Net->new(); $net->connect(); undef $net;
disconnect disconnects from an UPS agent.
undef $net has the same effect as $net->disconnect().
undef $net
$net->disconnect()
"new", "connect", "connected", "setHost", "getHost", "setTCPPort", "getTCPPort"
sendCommand - sending a command to the UPS agent
$net = Hardware::UPS::Perl::Connection::Net->new(); $net->connect(); $net->sendCommand($command, \$response, $responseSize);
sendCommand sends a command $command to an UPS agent connected appending the response size expected using <C-A> and "\n" and reads the response $response from the UPS agent using the package IO::Select.
$command
string; defines a command.
$response
string; the response from the UPS.
$responseSize
integer; the buffer size of the response from the UPS.
"new", "connect", "connected", "disconnect"
Errno(3pm), IO::Select(3pm), IO::Socket::INET(3pm), Hardware::UPS::Perl::Connection(3pm), Hardware::UPS::Perl::Connection::Serial(3pm), Hardware::UPS::Perl::Constants(3pm), Hardware::UPS::Perl::Driver(3pm), Hardware::UPS::Perl::Driver::Megatec(3pm), Hardware::UPS::Perl::General(3pm), Hardware::UPS::Perl::Logging(3pm), Hardware::UPS::Perl::PID(3pm), Hardware::UPS::Perl::Utils(3pm)
Hardware::UPS::Perl::Connection::Net was inspired by the usv.pl program by Bernd Holzhauer, <www.cc-c.de>. The latest version of this program can be obtained from
http://www.cc-c.de/german/linux/linux_usv.php
Another great resource was the Network UPS Tools site, which can be found at
http://www.networkupstools.org
Hardware::UPS::Perl::Connection::Net was developed using perl 5.8.8 on a SuSE 10.1 Linux distribution.
There are plenty of them for sure. Maybe the embedded pod documentation has to be revised a little bit.
Suggestions to improve Hardware::UPS::Perl::Connection::Net are welcome, though due to the lack of time it might take a while to incorporate them.
Copyright (c) 2007 by Christian Reile, <Christian.Reile@t-online.de>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. For further licensing details, please see the file COPYING in the distribution.
cut
To install Hardware::UPS::Perl::PID, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hardware::UPS::Perl::PID
CPAN shell
perl -MCPAN -e shell install Hardware::UPS::Perl::PID
For more information on module installation, please visit the detailed CPAN module installation guide.