The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SNMP::Server::Logtail - Tails logfiles and presents counters via SNMP

SYNOPSIS

 #!/usr/bin/perl
 use SNMP::Server::Logtail;

 sub exim_mainlog {
   my($hash, $line)=@_;
   $hash->{MSG_IN}++ if /^<= /;
   $hash->{MSG_OUT}++ if /^=> /;
   # etc
 }

 snmpd_init( -logfile => '/tmp/testlog',
             -prefix => '.1.3.6.1.4.1.2021.255' );
 add_oidmap( MSG_IN => 1,
             MSG_OUT => 2 );
 add_logfile('/var/log/exim/mainlog' => \&exim_mainlog);
 snmpd_run();

DESCRIPTION

This module implements the core functionality that combines with the Net-SNMP SNMP daemon (not to be confused with the Net::SNMP Perl module) which allows you to monitor updates to a logfile. Typically, it's used to present a MIB of counters that increment whenever certain events are logged. It also detects when the logfile has been rotated and will start monitoring the new logfile when this occurs.

The example in SYNOPSIS above is a complete program that Net-SNMP can use. Note that this module imports functions into your namespace, has global variables, and is generally hostile to your script doing anything other than purely being a client to it. This is intentional.

To tell Net-SNMP about your new MIB and script, insert the following line into snmpd.conf:

 pass_persist .1.3.6.1.4.1.2021.255 /path/to/script.pl

and then reload Net-SNMP. You can then perform a SNMP query:

 snmpget -v 1 -c public localhost .1.3.6.1.4.1.2021.255.1

You can obviously also read this by using Net::SNMP, MRTG, or similar.

The function set with add_logfile() is called back whenever a new entry appears in the logfile. It is passed a hash reference and single lines from the logfile. The function may use the hash as it sees fit, although normally it would just increment/set values in the hash as new log data becomes available to it.

The arguments given to add_oidmap() define which entries in the hash are read whenever a SNMP query is made. It contains key/value pairs. The key corresponds to keys in the hash which are read - the value is the suffix of the OID that causes this read. (The OID's prefix is given in snmpd_init.)

FUNCTIONS

snmpd_init
 snmpd_init( -logfile => '/tmp/testlog',
             -prefix => '.1.3.6.1.4.1.2021.255' );

Initialises the global state for the log tailer. This script's own diagnostics goes to the logfile given with -logfile and the base OID for the MIB you're creating is given with -prefix.

add_oidmap
 add_oidmap( ACCEPT => 1,
             REJECT => 2 );

This adds a mapping of keywords to OIDs.

add_logfile
 add_logfile('/var/log/exim/mainlog' => \&exim_mainlog);

This adds another logfile to be monitored, and registers a callback function which will be called for each new line that appears in the logfile.

snmpd_run
 snmpd_run();

This starts the main loop. Control will return when Net-SNMP is shut down, so you should only clean up and exit after this occurs.

BUGS

This documentation is terrible. Reading the example client may be more helpful.

SEE ALSO

Net::SNMP

AUTHOR

All code and documentation by Peter Corlett <abuse@cabal.org.uk>.

COPYRIGHT

Copyright (C) 2004 Peter Corlett <abuse@cabal.org.uk>. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SUPPORT / WARRANTY

This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.