1SNMP::Simple(3) User Contributed Perl Documentation SNMP::Simple(3)
2
3
4
6 SNMP::Simple - shortcuts for when using SNMP
7
9 use SNMP::Simple;
10
11 $name = $s->get('sysName'); # same as sysName.0
12 $location = $s->get('sysLocation');
13
14 @array = $s->get_list('hrPrinterStatus');
15 $arrayref = $s->get_list('hrPrinterStatus');
16
17 @list_of_lists = $s->get_table(
18 qw(
19 prtConsoleOnTime
20 prtConsoleColor
21 prtConsoleDescription
22 )
23 );
24
25 @list_of_hashes = $s->get_named_table(
26 name => 'prtInputDescription',
27 media => 'prtInputMediaName',
28 status => 'prtInputStatus',
29 level => 'prtInputCurrentLevel',
30 max => 'prtInputMaxCapacity',
31 );
32
34 This module provides shortcuts when performing repetitive information-
35 retrieval tasks with SNMP.
36
37 Instead of this:
38
39 use SNMP;
40 $vars = new SNMP::VarList( ['prtConsoleOnTime'], ['prtConsoleColor'],
41 ['prtConsoleDescription'], );
42 my ( $light_status, $light_color, $light_desc ) = $s->getnext($vars);
43 die $s->{ErrorStr} if $s->{ErrorStr};
44 while ( !$s->{ErrorStr} and $$vars[0]->tag eq "prtConsoleOnTime" ) {
45 push @{ $data{lights} },
46 {
47 status => ( $light_status ? 0 : 1 ),
48 color => SNMP::mapEnum( $$vars[1]->tag, $light_color ),
49 description => $light_desc,
50 };
51 ( $light_status, $light_color, $light_desc ) = $s->getnext($vars);
52 }
53
54 ...you can do this:
55
56 use SNMP::Simple;
57 $data{lights} = $s->get_named_table(
58 status => 'prtConsoleOnTime',
59 color => 'prtConsoleColor',
60 name => 'prtConsoleDescription',
61 );
62
63 SNMP Beginners, read me first!
64 Please, please, please do not use this module as a starting point for
65 working with SNMP and Perl. Look elsewhere for starting resources:
66
67 • The SNMP module
68
69 • The Net-SNMP web site (<http://www.net-snmp.org/>) and tutorial
70 (<http://www.net-snmp.org/tutorial-5/>)
71
72 • Appendix E of Perl for System Administration
73 (<http://www.amazon.com/exec/obidos/tg/detail/-/1565926099>) by
74 David N. Blank-Edelman
75
76 SNMP Advanced and Intermediate users, read me first!
77 I'll admit this is a complete slaughtering of SNMP, but my goals were
78 precise. If you think SNMP::Simple could be refined in any way, feel
79 free to send me suggestions/fixes/patches.
80
82 new( @args )
83 Creates a new SNMP::Simple object. Arguments given are passed directly
84 to "SNMP::Session->new". See "SNMP::Session" in SNMP for details.
85
86 Example:
87
88 use SNMP::Simple
89
90 my $s = SNMP::Simple->new(
91 DestHost => 'host.example.com',
92 Community => 'public',
93 Version => 1,
94 ) or die "couldn't create session";
95
96 ...
97
98 get( $oid )
99 Gets the named variable and returns its value. If no value is returned,
100 get() will try to retrieve a list named $name and return its first
101 vlaue. Thus, for convenience,
102
103 $s->get('sysDescr')
104
105 ..should be the same as:
106
107 $s->get('sysDescr.0')
108
109 Numbered OIDs are fine, too, with or without a leading dot:
110
111 $s->get('1.3.6.1.2.1.1.1.0')
112
113 SNMP::mapEnum() is automatically used on the result.
114
115 get_list( $oid )
116 Returns leaves of the given OID.
117
118 If called in array context, returns an array. If called in scalar
119 context, returns an array reference.
120
121 get_table( @oids )
122 Given a list of OIDs, this will return a list of lists of all of the
123 values of the table.
124
125 For example, to get a list of all known network interfaces on a machine
126 and their status:
127
128 $s->get_table('ifDescr', 'ifOperStatus')
129
130 Would return something like the following:
131
132 [ 'lo', 'up' ],
133 [ 'eth0', 'down' ],
134 [ 'eth1', 'up' ],
135 [ 'sit0', 'down' ]
136
137 If called in array context, returns an array (of arrays). If called in
138 scalar context, returns an array reference.
139
140 get_named_table( %oids_by_alias )
141 Like "get_table", but lets you rename ugly OID names on the fly. To
142 get a list of all known network interfaces on a machine and their
143 status:
144
145 $s->get_table( name => 'ifDescr', status => 'ifOperStatus' )
146
147 Would return something like the following:
148
149 {
150 status => 'up',
151 name => 'lo'
152 },
153 {
154 status => 'down',
155 name => 'eth0'
156 },
157 {
158 status => 'up',
159 name => 'eth1'
160 },
161 {
162 status => 'down',
163 name => 'sit0'
164 }
165
166 If called in array context, returns an array (of hashes). If called in
167 scalar context, returns an array reference.
168
170 A sample script examples/printerstats.pl is included with this
171 distribution.
172
174 SNMP
175
177 Ian Langworth, "<ian@cpan.org>"
178
180 • There are no real tests.
181
182 • I haven't tested this with v3.
183
184 Please report any bugs or feature requests to
185 "bug-snmp-simple@rt.cpan.org", or through the web interface at
186 <http://rt.cpan.org>. I will be notified, and then you'll
187 automatically be notified of progress on your bug as I make changes.
188
190 Copyright 2005 Ian Langworth, All Rights Reserved.
191
192 This program is free software; you can redistribute it and/or modify it
193 under the same terms as Perl itself.
194
195
196
197perl v5.36.0 2023-01-20 SNMP::Simple(3)