.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Net::Syslogd 3pm" .TH Net::Syslogd 3pm "2022-06-30" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Net::Syslogd \- Perl implementation of Syslog Listener .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Net::Syslogd; \& \& my $syslogd = Net::Syslogd\->new() \& or die "Error creating Syslogd listener: ", Net::Syslogd\->error; \& \& while (1) { \& my $message = $syslogd\->get_message(); \& \& if (!defined($message)) { \& printf "$0: %s\en", Net::Syslogd\->error; \& exit 1 \& } elsif ($message == 0) { \& next \& } \& \& if (!defined($message\->process_message())) { \& printf "$0: %s\en", Net::Syslogd\->error \& } else { \& printf "%s\et%i\et%s\et%s\et%s\et%s\et%s\en", \& $message\->remoteaddr, \& $message\->remoteport, \& $message\->facility, \& $message\->severity, \& $message\->time, \& $message\->hostname, \& $message\->message \& } \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Net::Syslogd is a class implementing a simple Syslog listener in Perl. Net::Syslogd will accept messages on the default Syslog port (\s-1UDP 514\s0) and attempt to decode them according to \s-1RFC 3164.\s0 .SH "METHODS" .IX Header "METHODS" .SS "\fBnew()\fP \- create a new Net::Syslogd object" .IX Subsection "new() - create a new Net::Syslogd object" .Vb 1 \& my $syslogd = Net::Syslogd\->new([OPTIONS]); .Ve .PP Create a new Net::Syslogd object with \s-1OPTIONS\s0 as optional parameters. Valid options are: .PP .Vb 11 \& 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 .Ve .PP \&\fB\s-1NOTE\s0\fR: IPv6 requires IO::Socket::IP. Failback is IO::Socket::INET and only IPv4 support. .PP Allows the following accessors to be called. .PP \fI\f(BIserver()\fI \- return IO::Socket::IP object for server\fR .IX Subsection "server() - return IO::Socket::IP object for server" .PP .Vb 1 \& $syslogd\->server(); .Ve .PP Return \fBIO::Socket::IP\fR object for the created server. All \fBIO::Socket::IP\fR accessors can then be called. .SS "\fBget_message()\fP \- listen for Syslog message" .IX Subsection "get_message() - listen for Syslog message" .Vb 1 \& my $message = $syslogd\->get_message([OPTIONS]); .Ve .PP Listen for Syslog messages. Timeout after default or user specified timeout set in \f(CW\*(C`new\*(C'\fR method and return '0'. If message is received before timeout, return is defined. Return is not defined if error encountered. .PP Valid options are: .PP .Vb 10 \& Option Description Default \& \-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\- \& \-maxsize Max size in bytes of acceptable 65467 \& message. \& Value can be integer 1 <= # <= 65467. \& Keywords: \*(AqRFC\*(Aq = 1024 \& \*(Aqrecommended\*(Aq = 2048 \& \-timeout Timeout in seconds to wait for 10 \& request. Overrides value set with \& new(). .Ve .PP Allows the following accessors to be called. .PP \fI\f(BIremoteaddr()\fI \- return remote address from Syslog message\fR .IX Subsection "remoteaddr() - return remote address from Syslog message" .PP .Vb 1 \& $message\->remoteaddr(); .Ve .PP Return remote address value from a received (\f(CW\*(C`get_message()\*(C'\fR) Syslog message. This is the address from the \s-1IP\s0 header on the \s-1UDP\s0 datagram. .PP \fI\f(BIremoteport()\fI \- return remote port from Syslog message\fR .IX Subsection "remoteport() - return remote port from Syslog message" .PP .Vb 1 \& $message\->remoteport(); .Ve .PP Return remote port value from a received (\f(CW\*(C`get_message()\*(C'\fR) Syslog message. This is the port from the \s-1IP\s0 header on the \s-1UDP\s0 datagram. .PP \fI\f(BIdatagram()\fI \- return datagram from Syslog message\fR .IX Subsection "datagram() - return datagram from Syslog message" .PP .Vb 1 \& $message\->datagram(); .Ve .PP Return the raw datagram from a received (\f(CW\*(C`get_message()\*(C'\fR) Syslog message. .SS "\fBprocess_message()\fP \- process received Syslog message" .IX Subsection "process_message() - process received Syslog message" .Vb 1 \& $message\->process_message([OPTIONS]); .Ve .PP Process a received Syslog message according to \s-1RFC 3164\s0 \- or as close as possible. \s-1RFC 3164\s0 format is as follows: .PP .Vb 5 \& <###>Mmm dd hh:mm:ss hostname tag content \& |_\|_\|_||_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_| |_\|_\|_\|_\|_\|_| |_\|_\|_\|_\|_\|_\|_\|_\|_| \& | Timestamp Hostname Message \& | \& Priority \-> (facility and severity) .Ve .PP \&\fB\s-1NOTE:\s0\fR This module parses the tag and content as a single field. .PP Called with one argument, interpreted as the datagram to process. Valid options are: .PP .Vb 12 \& Option Description Default \& \-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\- \& \-datagram Datagram to process \-Provided by \& get_message()\- \& \-regex Regular expression to parse received \-Provided in \& syslog message. this method\- \& Keywords: \*(AqRFC\*(Aq = Strict RFC 3164 \& Must include ()\-matching: \& $1 = priority \& $2 = time \& $3 = hostname \& $4 = message .Ve .PP \&\fB\s-1NOTE:\s0\fR This uses a regex that parses \s-1RFC 3164\s0 compliant syslog messages. It will also recoginize Cisco syslog messages (not fully \&\s-1RFC 3164\s0 compliant) sent with 'timestamp' rather than 'uptime'. .PP This can also be called as a procedure if one is inclined to write their own \s-1UDP\s0 listener instead of using \f(CW\*(C`get_message()\*(C'\fR. For example: .PP .Vb 4 \& $sock = IO::Socket::IP\->new( blah blah blah ); \& $sock\->recv($datagram, 1500); \& # process datagram in $datagram variable \& $message = Net::Syslogd\->process_message($datagram); .Ve .PP In either instantiation, allows the following accessors to be called. .PP \fI\f(BIpriority()\fI \- return priority from Syslog message\fR .IX Subsection "priority() - return priority from Syslog message" .PP .Vb 1 \& $message\->priority(); .Ve .PP Return priority value from a received and processed (\f(CW\*(C`process_message()\*(C'\fR) Syslog message. This is the raw priority number not decoded into facility and severity. .PP \fI\f(BIfacility()\fI \- return facility from Syslog message\fR .IX Subsection "facility() - return facility from Syslog message" .PP .Vb 1 \& $message\->facility([1]); .Ve .PP Return facility value from a received and processed (\f(CW\*(C`process_message()\*(C'\fR) Syslog message. This is the text representation of the facility. For the raw number, use the optional boolean argument. .PP \fI\f(BIseverity()\fI \- return severity from Syslog message\fR .IX Subsection "severity() - return severity from Syslog message" .PP .Vb 1 \& $message\->severity([1]); .Ve .PP Return severity value from a received and processed (\f(CW\*(C`process_message()\*(C'\fR) Syslog message. This is the text representation of the severity. For the raw number, use the optional boolean argument. .PP \fI\f(BItime()\fI \- return time from Syslog message\fR .IX Subsection "time() - return time from Syslog message" .PP .Vb 1 \& $message\->time(); .Ve .PP Return time value from a received and processed (\f(CW\*(C`process_message()\*(C'\fR) Syslog message. .PP \fI\f(BIhostname()\fI \- return hostname from Syslog message\fR .IX Subsection "hostname() - return hostname from Syslog message" .PP .Vb 1 \& $message\->hostname(); .Ve .PP Return hostname value from a received and processed (\f(CW\*(C`process_message()\*(C'\fR) Syslog message. .PP \fI\f(BImessage()\fI \- return message from Syslog message\fR .IX Subsection "message() - return message from Syslog message" .PP .Vb 1 \& $message\->message(); .Ve .PP Return message value from a received and processed (\f(CW\*(C`process_message()\*(C'\fR) Syslog message. Note this is the tag \fBand\fR msg field from a properly formatted \s-1RFC 3164\s0 Syslog message. .SS "\fBerror()\fP \- return last error" .IX Subsection "error() - return last error" .Vb 1 \& printf "Error: %s\en", Net::Syslogd\->error; .Ve .PP Return last error. .SH "EXPORT" .IX Header "EXPORT" None by default. .SH "EXAMPLES" .IX Header "EXAMPLES" This distribution comes with several scripts (installed to the default \&\*(L"bin\*(R" install directory) that not only demonstrate example uses but also provide functional execution. .SH "LICENSE" .IX Header "LICENSE" This software is released under the same terms as Perl itself. If you don't know what that means visit . .SH "AUTHOR" .IX Header "AUTHOR" Copyright (C) Michael Vincent 2010 .PP .PP All rights reserved