Net::Syslogd(3pm)

πŸ“¦
version 0.16 Β· 2 versions
  • 0.16 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.16 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Net::Syslogd β€” the Perl syslog listener era πŸ’–

ok so bestie, this is a page from the User Contributed Perl Documentation and it's about Net::Syslogd, which is a Perl implementation of a Syslog Listener. yes, the thing that catches all the log messages. it's giving network girlie. πŸŽ€


✨ NAME ✨

Net::Syslogd β€” Perl implementation of Syslog Listener πŸ¦‹


🌸 SYNOPSIS 🌸

ok here's the whole vibe, copy it exactly bestie:

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\n", Net::Syslogd->error;
        exit 1
    } elsif ($message == 0) {
        next
    }

    if (!defined($message->process_message())) {
        printf "$0: %s\n", Net::Syslogd->error
    } else {
        printf "%s\t%i\t%s\t%s\t%s\t%s\t%s\n",
               $message->remoteaddr,
               $message->remoteport,
               $message->facility,
               $message->severity,
               $message->time,
               $message->hostname,
               $message->message
    }
}

like, an infinite loop that just listens. main character energy honestly. πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

Net::Syslogd is a class implementing a simple Syslog listener in Perl. no cap.

Net::Syslogd will accept messages on the default Syslog port (UDP 514) and attempt to decode them according to RFC 3164. periodt. πŸ’–


🧚 METHODS 🧚

new() - create a new Net::Syslogd object ✨

my $syslogd = Net::Syslogd->new([OPTIONS]);

Create a new Net::Syslogd object with OPTIONS as optional parameters. the valid options are:

  • -Family β€” Address family IPv4/IPv6. Default: 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. Default: any
  • -LocalPort β€” Port to bind server to. Default: 514
  • -timeout β€” Timeout in seconds for socket operations and to wait for request. Default: 10
NOTE: IPv6 requires IO::Socket::IP. Failback is IO::Socket::INET and only IPv4 support. 😭

Allows the following accessors to be called. 🫢

server() - return IO::Socket::IP object for server πŸ¦‹

$syslogd->server();

Return IO::Socket::IP object for the created server. All IO::Socket::IP accessors can then be called. iconic.


get_message() - listen for Syslog message 🌸

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.

the valid options are:

  • -maxsize β€” Max size in bytes of acceptable message. Default: 65467
    • Value can be integer 1 <= # <= 65467.
    • Keywords: 'RFC' = 1024, 'recommended' = 2048
  • -timeout β€” Timeout in seconds to wait for request. Overrides value set with new(). Default: 10

Allows the following accessors to be called. πŸ’œ

remoteaddr() - return remote address from Syslog message πŸ“

$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. fr fr.

remoteport() - return remote port from Syslog message πŸ”Œ

$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() - return datagram from Syslog message πŸ“¦

$message->datagram();

Return the raw datagram from a received ("get_message()") Syslog message.


process_message() - process received Syslog message πŸŽ€

$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. the valid options are:

  • -datagram β€” Datagram to process. Default: -Provided by get_message()-
  • -regex β€” Regular expression to parse received syslog message. Default: -Provided in 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() - return priority from Syslog message ⭐

$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() - return facility from Syslog message 🏒

$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() - return severity from Syslog message 🚨

$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() - return time from Syslog message ⏰

$message->time();

Return time value from a received and processed ("process_message()") Syslog message.

hostname() - return hostname from Syslog message πŸ’»

$message->hostname();

Return hostname value from a received and processed ("process_message()") Syslog message.

message() - return message from Syslog message πŸ’¬

$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() - return last error πŸ’€

printf "Error: %s\n", Net::Syslogd->error;

Return last error. bestie when this fires it's giving character development 😭


🌈 EXPORT 🌈

None by default. literally nothing. zero. nada. πŸ™ˆ


πŸ“ EXAMPLES πŸ“

This distribution comes with several scripts (installed to the default "bin" install directory) that not only demonstrate example uses but also provide functional execution. runnable AND educational, we love a multitasker πŸ’…


πŸ‘‘ LICENSE πŸ‘‘

This software is released under the same terms as Perl itself. If you don't know what that means visit <http://perl.com/>.


πŸ’– AUTHOR πŸ’–

Copyright (C) Michael Vincent 2010

<http://www.VinsWorld.com>

All rights reserved


and that's the whole page bestie, no notes, ate and left no crumbs 🫢✨ perl v5.34.0, dated 2022-06-30 β€” mwah, go log something πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from