.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
.\"
.\" 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 turned on, 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
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "SNMP::Extension::PassPersist 3pm"
.TH SNMP::Extension::PassPersist 3pm "2015-05-29" "perl v5.20.2" "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"
SNMP::Extension::PassPersist \- Generic pass/pass_persist extension framework
for Net\-SNMP
.SH "VERSION"
.IX Header "VERSION"
This is the documentation of \f(CW\*(C`SNMP::Extension::PassPersist\*(C'\fR version 0.07
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
Typical setup for a \f(CW\*(C`pass\*(C'\fR program:
.PP
.Vb 2
\& use strict;
\& use SNMP::Extension::PassPersist;
\&
\& # create the object
\& my $extsnmp = SNMP::Extension::PassPersist\->new;
\&
\& # add a few OID entries
\& $extsnmp\->add_oid_entry($oid, $type, $value);
\& $extsnmp\->add_oid_entry($oid, $type, $value);
\&
\& # run the program
\& $extsnmp\->run;
.Ve
.PP
Typical setup for a \f(CW\*(C`pass_persist\*(C'\fR program:
.PP
.Vb 2
\& use strict;
\& use SNMP::Extension::PassPersist;
\&
\& my $extsnmp = SNMP::Extension::PassPersist\->new(
\& backend_collect => \e&update_tree
\& );
\& $extsnmp\->run;
\&
\&
\& sub update_tree {
\& my ($self) = @_;
\&
\& # add a serie of OID entries
\& $self\->add_oid_entry($oid, $type, $value);
\& ...
\&
\& # or directly add a whole OID tree
\& $self\->add_oid_tree(\e%oid_tree);
\& }
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This module is a framework for writing Net-SNMP extensions using the
\&\f(CW\*(C`pass\*(C'\fR or \f(CW\*(C`pass_persist\*(C'\fR mechanisms.
.PP
When in \f(CW\*(C`pass_persist\*(C'\fR mode, it provides a mechanism to spare
resources by quitting from the main loop after a given number of
idle cycles.
.PP
This module can use \f(CW\*(C`Sort::Key::OID\*(C'\fR when it is available, for sorting
OIDs faster than with the internal pure Perl function.
.SH "METHODS"
.IX Header "METHODS"
.SS "\fInew()\fP"
.IX Subsection "new()"
Creates a new object. Can be given any attributes as a hash or hashref.
See \*(L"\s-1ATTRIBUTES\*(R"\s0 for the list of available attributes.
.PP
\&\fBExamples:\fR
.PP
For a \f(CW\*(C`pass\*(C'\fR command, most attributes are useless:
.PP
.Vb 1
\& my $extsnmp = SNMP::Extension::PassPersist\->new;
.Ve
.PP
For a \f(CW\*(C`pass_persist\*(C'\fR command, you'll usually want to at least set the
\&\f(CW\*(C`backend_collect\*(C'\fR callback:
.PP
.Vb 5
\& my $extsnmp = SNMP::Extension::PassPersist\->new(
\& backend_collect => \e&update_tree,
\& idle_count => 10, # no more than 10 idle cycles
\& refresh => 10, # refresh every 10 sec
\& );
.Ve
.SS "\fIrun()\fP"
.IX Subsection "run()"
This method does the following things:
.IP "\(bu" 4
process the command line arguments in order to decide in which mode
the program has to be executed
.IP "\(bu" 4
call the backend init callback
.IP "\(bu" 4
call the backend collect callback a first time
.PP
Then, when in \f(CW\*(C`pass\*(C'\fR mode, the corresponding \s-1SNMP\s0 command is executed,
its result is printed on the output filehandle, and \f(CW\*(C`run()\*(C'\fR returns.
.PP
When in \f(CW\*(C`pass_persist\*(C'\fR mode, \f(CW\*(C`run()\*(C'\fR enters a loop, reading Net-SNMP
queries on its input filehandle, processing them, and printing result
on its output filehandle. The backend collect callback is called every
\&\f(CW\*(C`refresh\*(C'\fR seconds. If no query is read from the input after \f(CW\*(C`idle_count\*(C'\fR
cycles, \f(CW\*(C`run()\*(C'\fR returns.
.SS "add_oid_entry(\s-1FUNC_OID, FUNC_TYPE, FUNC_VALUE\s0)"
.IX Subsection "add_oid_entry(FUNC_OID, FUNC_TYPE, FUNC_VALUE)"
Add an entry to the \s-1OID\s0 tree.
.SS "add_oid_tree(\s-1HASH\s0)"
.IX Subsection "add_oid_tree(HASH)"
Merge an \s-1OID\s0 tree to the main \s-1OID\s0 tree, using the same structure as
the one of the \s-1OID\s0 tree itself.
.SS "\fIdump_oid_tree()\fP"
.IX Subsection "dump_oid_tree()"
Print a complete listing of the \s-1OID\s0 tree on the output file handle.
.SH "ATTRIBUTES"
.IX Header "ATTRIBUTES"
This module's attributes are generated by \f(CW\*(C`Class::Accessor\*(C'\fR, and can
therefore be passed as arguments to \f(CW\*(C`new()\*(C'\fR or called as object methods.
.SS "backend_collect"
.IX Subsection "backend_collect"
Set the code reference for the \fIcollect\fR callback. See also \*(L"\s-1CALLBACKS\*(R"\s0.
.SS "backend_fork"
.IX Subsection "backend_fork"
When set to true, the backend callbacks will be executed in a separate
process. Default value is false.
.SS "backend_init"
.IX Subsection "backend_init"
Set the code reference for the \fIinit\fR callback. See also \*(L"\s-1CALLBACKS\*(R"\s0.
.SS "backend_pipe"
.IX Subsection "backend_pipe"
Contains the pipe used to communicate with the backend child, when executed
in a separate process.
.SS "dispatch"
.IX Subsection "dispatch"
Gives access to the internal dispatch table, stored as a hash with the
following structure:
.PP
.Vb 4
\& dispatch => {
\& SNMP_CMD => { nargs => NUMBER_ARGS, code => CODEREF },
\& ...
\& }
.Ve
.PP
where the \s-1SNMP\s0 command is always in lowercase, \f(CW\*(C`nargs\*(C'\fR gives the number
of arguments expected by the command and \f(CW\*(C`code\*(C'\fR the callback reference.
.PP
You should not modify this table unless you really know what you're doing.
.SS "heap"
.IX Subsection "heap"
Give access to the heap.
.SS "idle_count"
.IX Subsection "idle_count"
Get/set the number of idle cycles before ending the run loop.
.SS "input"
.IX Subsection "input"
Get/set the input filehandle.
.SS "oid_tree"
.IX Subsection "oid_tree"
Gives access to the internal \s-1OID\s0 tree, stored as a hash with the
following structure:
.PP
.Vb 4
\& oid_tree => {
\& FUNC_OID => [ FUNC_TYPE, FUNC_VALUE ],
\& ...
\& }
.Ve
.PP
where \f(CW\*(C`FUNC_OID\*(C'\fR is the absolute \s-1OID\s0 of the \s-1SNMP\s0 function, \f(CW\*(C`FUNC_TYPE\*(C'\fR
the function type (\f(CW"integer"\fR, \f(CW"counter"\fR, \f(CW"gauge"\fR, etc), and
\&\f(CW\*(C`FUNC_VALUE\*(C'\fR the function value.
.PP
You should not directly modify this hash but instead use the appropriate
methods for adding \s-1OID\s0 entries.
.SS "output"
.IX Subsection "output"
Get/set the output filehandle.
.SS "refresh"
.IX Subsection "refresh"
Get/set the refresh delay before calling the backend collect callback
to update the \s-1OID\s0 tree.
.SH "CALLBACKS"
.IX Header "CALLBACKS"
The callbacks are invoked with the corresponding object as first argument,
as for a normal method. A heap is available for storing user-defined data.
.PP
In the specific case of a program running in \f(CW\*(C`pass_persist\*(C'\fR mode with
a forked backend, the callbacks are only executed in the child process
(the forked backend).
.PP
The currently implemented callbacks are:
.IP "\(bu" 4
init
.Sp
This callback is called once, before the first \fIcollect\fR invocation
and before the main loop. It can be accessed and modified through the
\&\f(CW\*(C`backend_init\*(C'\fR attribute.
.IP "\(bu" 4
collect
.Sp
This callback is called every \f(CW\*(C`refresh\*(C'\fR seconds so the user can update
the \s-1OID\s0 tree using the \f(CW\*(C`add_oid_entry()\*(C'\fR and \f(CW\*(C`add_oid_tree()\*(C'\fR methods.
.SS "Examples"
.IX Subsection "Examples"
For simple needs, only the \fIcollect\fR callback needs to be defined:
.PP
.Vb 3
\& my $extsnmp = SNMP::Extension::PassPersist\->new(
\& backend_collect => \e&update_tree,
\& );
\&
\& sub update_tree {
\& my ($self) = @_;
\&
\& # fetch the number of running processes
\& my $nb_proc = @{ Proc::ProcessTable\->new\->table };
\&
\& $self\->add_oid_entry(".1.3.6.1.4.1.32272.10", gauge", $nb_proc);
\& }
.Ve
.PP
A more advanced example is when there is a need to connect to a database,
in which case both the \fIinit\fR and \fIcollect\fR callback need to be defined:
.PP
.Vb 4
\& my $extsnmp = SNMP::Extension::PassPersist\->new(
\& backend_init => \e&connect_db,
\& backend_collect => \e&update_tree,
\& );
\&
\& sub connect_db {
\& my ($self) = @_;
\& my $heap = $self\->heap;
\&
\& # connect to a database
\& my $dbh = DBI\->connect($dsn, $user, $password);
\& $heap\->{dbh} = $dbh;
\& }
\&
\& sub update_tree {
\& my ($self) = @_;
\& my $heap = $self\->heap;
\&
\& # fetch the number of records from a given table
\& my $dbh = $heap\->{dbh};
\& my $sth = $dbh\->prepare_cached("SELECT count(*) FROM whatever");
\& $sth\->execute;
\& my ($count) = $sth\->fetchrow_array;
\&
\& $self\->add_oid_entry(".1.3.6.1.4.1.32272.20", "gauge", $count);
\& }
.Ve
.SH "SEE ALSO"
.IX Header "SEE ALSO"
SNMP::Persist is another pass_persist backend for writing Net-SNMP
extensions, but relies on threads.
.PP
The documentation of Net-SNMP, especially the part on how to configure
a \f(CW\*(C`pass\*(C'\fR or \f(CW\*(C`pass_persist\*(C'\fR extension:
.IP "\(bu" 4
main site:
.IP "\(bu" 4
configuring a pass or pass_persist extension:
.SH "BUGS"
.IX Header "BUGS"
Please report any bugs or feature requests to
\&\f(CW\*(C`bug\-snmp\-extension\-passpersist at rt.cpan.org\*(C'\fR,
or through the web interface at
.
I will be notified, and then you'll automatically be notified of
progress on your bug as I make changes.
.SH "SUPPORT"
.IX Header "SUPPORT"
You can find documentation for this module with the perldoc command.
.PP
.Vb 1
\& perldoc SNMP::Extension::PassPersist
.Ve
.PP
You can also look for information at:
.IP "\(bu" 4
Search \s-1CPAN\s0
.Sp
.IP "\(bu" 4
Meta \s-1CPAN\s0
.Sp
.IP "\(bu" 4
\&\s-1RT: CPAN\s0's request tracker
.Sp
.IP "\(bu" 4
AnnoCPAN: Annotated \s-1CPAN\s0 documentation
.Sp
.IP "\(bu" 4
\&\s-1CPAN\s0 Ratings
.Sp
.SH "AUTHOR"
.IX Header "AUTHOR"
Se\*'bastien Aperghis-Tramoni, \f(CW\*(C`\*(C'\fR
.SH "COPYRIGHT & LICENSE"
.IX Header "COPYRIGHT & LICENSE"
Copyright 2008\-2011 Se\*'bastien Aperghis-Tramoni, all rights reserved.
.PP
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.