new()-createanewNet::Syslogdobject
my $syslogd = Net::Syslogd->new([OPTIONS]);
Create a new Net::Syslogd object with OPTIONS as optional parameters. Valid options are:
Option Description Default
------ ----------- -------
-Family Address family IPv4/IPv6 IPv4
Valid values for IPv4:
4, v4, ip4, ipv4, AF_INET (constant)
Valid values for IPv6:
6, v6, ip6, ipv6, AF_INET6 (constant)
-LocalAddr Interface to bind to any
-LocalPort Port to bind server to 514
-timeout Timeout in seconds for socket 10
operations and to wait for request
NOTE: IPv6 requires IO::Socket::IP. Failback is IO::Socket::INET and only IPv4 support.
Allows the following accessors to be called.
server()-returnIO::Socket::IPobjectforserver
$syslogd->server();
Return IO::Socket::IP object for the created server. All IO::Socket::IP accessors can then be called.
get_message()-listenforSyslogmessage
my $message = $syslogd->get_message([OPTIONS]);
Listen for Syslog messages. Timeout after default or user specified timeout set in "new" method and
return '0'. If message is received before timeout, return is defined. Return is not defined if error
encountered.
Valid options are:
Option Description Default
------ ----------- -------
-maxsize Max size in bytes of acceptable 65467
message.
Value can be integer 1 <= # <= 65467.
Keywords: 'RFC' = 1024
'recommended' = 2048
-timeout Timeout in seconds to wait for 10
request. Overrides value set with
new().
Allows the following accessors to be called.
remoteaddr()-returnremoteaddressfromSyslogmessage
$message->remoteaddr();
Return remote address value from a received ("get_message()") Syslog message. This is the address from
the IP header on the UDP datagram.
remoteport()-returnremoteportfromSyslogmessage
$message->remoteport();
Return remote port value from a received ("get_message()") Syslog message. This is the port from the IP
header on the UDP datagram.
datagram()-returndatagramfromSyslogmessage
$message->datagram();
Return the raw datagram from a received ("get_message()") Syslog message.
process_message()-processreceivedSyslogmessage
$message->process_message([OPTIONS]);
Process a received Syslog message according to RFC 3164 - or as close as possible. RFC 3164 format is as
follows:
<###>Mmm dd hh:mm:ss hostname tag content
|___||_____________| |______| |_________|
| Timestamp Hostname Message
|
Priority -> (facility and severity)
NOTE: This module parses the tag and content as a single field.
Called with one argument, interpreted as the datagram to process. Valid options are:
Option Description Default
------ ----------- -------
-datagram Datagram to process -Provided by
get_message()-
-regex Regular expression to parse received -Provided in
syslog message. this method-
Keywords: 'RFC' = Strict RFC 3164
Must include ()-matching:
$1 = priority
$2 = time
$3 = hostname
$4 = message
NOTE: This uses a regex that parses RFC 3164 compliant syslog messages. It will also recoginize Cisco
syslog messages (not fully RFC 3164 compliant) sent with 'timestamp' rather than 'uptime'.
This can also be called as a procedure if one is inclined to write their own UDP listener instead of
using "get_message()". For example:
$sock = IO::Socket::IP->new( blah blah blah );
$sock->recv($datagram, 1500);
# process datagram in $datagram variable
$message = Net::Syslogd->process_message($datagram);
In either instantiation, allows the following accessors to be called.
priority()-returnpriorityfromSyslogmessage
$message->priority();
Return priority value from a received and processed ("process_message()") Syslog message. This is the
raw priority number not decoded into facility and severity.
facility()-returnfacilityfromSyslogmessage
$message->facility([1]);
Return facility value from a received and processed ("process_message()") Syslog message. This is the
text representation of the facility. For the raw number, use the optional boolean argument.
severity()-returnseverityfromSyslogmessage
$message->severity([1]);
Return severity value from a received and processed ("process_message()") Syslog message. This is the
text representation of the severity. For the raw number, use the optional boolean argument.
time()-returntimefromSyslogmessage
$message->time();
Return time value from a received and processed ("process_message()") Syslog message.
hostname()-returnhostnamefromSyslogmessage
$message->hostname();
Return hostname value from a received and processed ("process_message()") Syslog message.
message()-returnmessagefromSyslogmessage
$message->message();
Return message value from a received and processed ("process_message()") Syslog message. Note this is
the tag and msg field from a properly formatted RFC 3164 Syslog message.
error()-returnlasterror
printf "Error: %s\n", Net::Syslogd->error;
Return last error.