SNMP::Simple(3)
π SNMP::Simple π
okay so welcome to the SNMP::Simple(3) page, straight outta the User Contributed Perl Documentation set β¨ this is the section-3 manual page for it and yes bestie it's giving "tiny module, huge time-saver" energy π
πΈ NAME πΈ
SNMP::Simple β shortcuts for when using SNMP π
β¨ SYNOPSIS β¨
use SNMP::Simple;
$name = $s->get('sysName'); # same as sysName.0
$location = $s->get('sysLocation');
@array = $s->get_list('hrPrinterStatus');
$arrayref = $s->get_list('hrPrinterStatus');
@list_of_lists = $s->get_table(
qw(
prtConsoleOnTime
prtConsoleColor
prtConsoleDescription
)
);
@list_of_hashes = $s->get_named_table(
name => 'prtInputDescription',
media => 'prtInputMediaName',
status => 'prtInputStatus',
level => 'prtInputCurrentLevel',
max => 'prtInputMaxCapacity',
);
π¦ DESCRIPTION π¦
This module hands you shortcuts for those repetitive little information-retrieval tasks you keep doing with SNMP. No cap. π
So instead of writing this whole saga:
use SNMP;
$vars = new SNMP::VarList( ['prtConsoleOnTime'], ['prtConsoleColor'],
['prtConsoleDescription'], );
my ( $light_status, $light_color, $light_desc ) = $s->getnext($vars);
die $s->{ErrorStr} if $s->{ErrorStr};
while ( !$s->{ErrorStr} and $$vars[0]->tag eq "prtConsoleOnTime" ) {
push @{ $data{lights} },
{
status => ( $light_status ? 0 : 1 ),
color => SNMP::mapEnum( $$vars[1]->tag, $light_color ),
description => $light_desc,
};
( $light_status, $light_color, $light_desc ) = $s->getnext($vars);
}
β¦you can just do this instead:
use SNMP::Simple;
$data{lights} = $s->get_named_table(
status => 'prtConsoleOnTime',
color => 'prtConsoleColor',
name => 'prtConsoleDescription',
);
like. the glow up. πβ¨
πΌ SNMP Beginners, read me first! πΌ
Bestie. Please, please, please do not use this module as your starting point for learning SNMP and Perl together. This is not the tutorial you're looking for π go get your foundations somewhere else:
- The SNMP module
- The Net-SNMP web site (
http://www.net-snmp.org/) and its tutorial (http://www.net-snmp.org/tutorial-5/) - Appendix E of Perl for System Administration (
http://www.amazon.com/exec/obidos/tg/detail/-/1565926099) by David N. Blank-Edelman
fr fr, start with those. this module is a shortcut, not a class. π
π SNMP Advanced and Intermediate users, read me first! π
ngl I will fully admit this is a complete slaughtering of SNMP π but my goals were precise, okay?? If you think SNMP::Simple could be refined in any way, feel free to send me suggestions / fixes / patches. I'm listening π«Ά
π METHODS π
π new( @args )
Makes you a brand new SNMP::Simple object. Whatever arguments you hand it get passed directly to SNMP::Session->new. Go see "SNMP::Session" in SNMP for the details.
Example:
use SNMP::Simple
my $s = SNMP::Simple->new(
DestHost => 'host.example.com',
Community => 'public',
Version => 1,
) or die "couldn't create session";
...
π get( $oid )
Grabs the named variable and returns its value. If nothing comes back for it, get() will try to retrieve a list named $name and return its first value. So, for convenience's sake:
$s->get('sysDescr')
β¦should be the exact same thing as:
$s->get('sysDescr.0')
Numbered OIDs are totally fine too, with or without a leading dot:
$s->get('1.3.6.1.2.1.1.1.0')
SNMP::mapEnum() gets automatically used on the result. β¨
π§ get_list( $oid )
Returns the leaves of the OID you gave it.
Called in array context? You get an array. Called in scalar context? You get an array reference. iykyk π
π get_table( @oids )
Hand it a list of OIDs and it returns a list of lists holding every value in that table.
For example, to get a list of all known network interfaces on a machine plus their status:
$s->get_table('ifDescr', 'ifOperStatus')
Would return something like the following:
[ 'lo', 'up' ],
[ 'eth0', 'down' ],
[ 'eth1', 'up' ],
[ 'sit0', 'down' ]
Called in array context, you get an array (of arrays). Called in scalar context, you get an array reference.
π get_named_table( %oids_by_alias )
Just like "get_table", except it lets you rename ugly OID names on the fly πͺ To get a list of all known network interfaces on a machine and their status:
$s->get_table( name => 'ifDescr', status => 'ifOperStatus' )
Would return something like the following:
{
status => 'up',
name => 'lo'
},
{
status => 'down',
name => 'eth0'
},
{
status => 'up',
name => 'eth1'
},
{
status => 'down',
name => 'sit0'
}
Called in array context, you get an array (of hashes). Called in scalar context, you get an array reference. iconic, honestly π
π₯ EXAMPLES π₯
A sample script examples/printerstats.pl is included with this distribution. go look at it, it's right there π
π SEE ALSO π
SNMP
π«Ά AUTHOR π«Ά
Ian Langworth, "<ian@cpan.org>"
π BUGS π
- There are no real tests. (not me saying this out loud π)
- I haven't tested this with v3.
Please report any bugs or feature requests to "bug-snmp-simple@rt.cpan.org", or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. that's the deal π€
β COPYRIGHT & LICENSE β
Copyright 2005 Ian Langworth, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie π this one wasSNMP::Simple(3), it came to you as part of the User Contributed Perl Documentation set, and the footer saidperl v5.42.0dated2025-07-25β so yeah, that's the version and the date, mwah π periodt.
π¦ where this page comes from
- fedora 43: perl-SNMP-Simple 0.02-38.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms