| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package SNMP::Insight::Session::NetSNMP; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#ABSTRACT: Net::SNMP based implementation for SNMP::Insight::Session |
|
4
|
1
|
|
|
1
|
|
14932
|
use Moose; |
|
|
1
|
|
|
|
|
337594
|
|
|
|
1
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; #TRIAL VERSION: |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'SNMP::Insight::Session'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6225
|
use Net::SNMP 6.0 qw( :snmp DEBUG_ALL ENDOFMIBVIEW ); |
|
|
1
|
|
|
|
|
52507
|
|
|
|
1
|
|
|
|
|
206
|
|
|
11
|
1
|
|
|
1
|
|
375
|
use SNMP::Insight::Utils qw( _debug_level _debug ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
513
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has '_driver' => ( |
|
14
|
|
|
|
|
|
|
is => 'ro', |
|
15
|
|
|
|
|
|
|
isa => 'Object', |
|
16
|
|
|
|
|
|
|
lazy => 1, |
|
17
|
|
|
|
|
|
|
builder => '_build_driver', |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _build_driver { |
|
21
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my %options; |
|
24
|
0
|
|
|
|
|
|
$options{-hostname} = $self->hostname; |
|
25
|
0
|
|
|
|
|
|
$options{-port} = $self->port; |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my %version_map = ( 1 => 'snmpv1', '2c' => 'snmpv2c', 3 => 'snmpv3' ); |
|
28
|
0
|
|
|
|
|
|
$options{-version} = $version_map{ $self->version }; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# $options{-domain} = $self->domain; |
|
31
|
0
|
|
|
|
|
|
$options{-timeout} = $self->timeout; |
|
32
|
0
|
|
|
|
|
|
$options{-retries} = $self->retries; |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
$options{-debug} = DEBUG_ALL if _debug_level() > 1; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
$options{-localaddr} = $self->localaddr if $self->localaddr; |
|
37
|
0
|
0
|
|
|
|
|
$options{-localport} = $self->localport if $self->localport; |
|
38
|
0
|
0
|
|
|
|
|
$options{-community} = $self->community if $self->community; |
|
39
|
0
|
0
|
|
|
|
|
$options{-username} = $self->username if $self->username; |
|
40
|
0
|
0
|
|
|
|
|
$options{-authkey} = $self->authkey if $self->authkey; |
|
41
|
0
|
0
|
|
|
|
|
$options{-authpassword} = $self->authpassword if $self->authpassword; |
|
42
|
0
|
0
|
|
|
|
|
$options{-authprotocol} = $self->authprotocol if $self->authprotocol; |
|
43
|
0
|
0
|
|
|
|
|
$options{-privkey} = $self->privkey if $self->privkey; |
|
44
|
0
|
0
|
|
|
|
|
$options{-privpassword} = $self->privpassword if $self->privpassword; |
|
45
|
0
|
0
|
|
|
|
|
$options{-privprotocol} = $self->privprotocol if $self->privprotocol; |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$options{-translate} = [ |
|
48
|
|
|
|
|
|
|
'-all' => 1, |
|
49
|
|
|
|
|
|
|
'-octetstring' => 0, |
|
50
|
|
|
|
|
|
|
'-null' => 1, |
|
51
|
|
|
|
|
|
|
'-timeticks' => 0, |
|
52
|
|
|
|
|
|
|
'-opaque' => 1, |
|
53
|
|
|
|
|
|
|
'-nosuchobject' => 1, |
|
54
|
|
|
|
|
|
|
'-nosuchinstance' => 1, |
|
55
|
|
|
|
|
|
|
'-endofmibview' => 1, |
|
56
|
|
|
|
|
|
|
'-unsigned' => 1, |
|
57
|
|
|
|
|
|
|
]; |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return Net::SNMP->session(%options); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub get_scalar { |
|
64
|
0
|
|
|
0
|
1
|
|
my ( $self, $oid ) = @_; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $session = $self->_driver; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#add istance number to the oid |
|
69
|
0
|
|
|
|
|
|
$oid .= '.0'; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
_debug("SNMP::Insight fetching scalar $oid\n"); |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $result = $session->get_request( '-varbindlist' => [$oid] ); |
|
74
|
0
|
0
|
|
|
|
|
$result or die "SNMP error " . $session->error(); |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $result->{$oid}; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub get_subtree { |
|
80
|
0
|
|
|
0
|
1
|
|
my ( $self, $oid ) = @_; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my @result; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $s = $self->_driver; |
|
85
|
0
|
0
|
|
|
|
|
$oid eq '.' and $oid = '0'; |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
_debug("SNMP::Insight fetching subtree $oid\n"); |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $last_oid = $oid; |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
if ( $s->version() == SNMP_VERSION_1 ) { |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
while ( defined $s->get_next_request( -varbindlist => [$last_oid] ) ) { |
|
94
|
0
|
|
|
|
|
|
my $returned_oid = ( $s->var_bind_names() )[0]; |
|
95
|
0
|
0
|
|
|
|
|
if ( !oid_base_match( $last_oid, $returned_oid ) ) { |
|
96
|
0
|
|
|
|
|
|
last; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# store into result |
|
100
|
0
|
|
|
|
|
|
push @result, |
|
101
|
|
|
|
|
|
|
[ $returned_oid, $s->var_bind_list()->{$returned_oid} ]; |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$last_oid = $returned_oid; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
else { |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
GET_BULK: |
|
110
|
0
|
|
|
|
|
|
while ( |
|
111
|
|
|
|
|
|
|
defined $s->get_bulk_request( |
|
112
|
|
|
|
|
|
|
-maxrepetitions => 25, |
|
113
|
|
|
|
|
|
|
-varbindlist => [$last_oid] |
|
114
|
|
|
|
|
|
|
) |
|
115
|
|
|
|
|
|
|
) |
|
116
|
|
|
|
|
|
|
{ |
|
117
|
0
|
|
|
|
|
|
my @oids = $s->var_bind_names(); |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
if ( !scalar @oids ) { |
|
120
|
0
|
|
|
|
|
|
die('Received an empty varBindList'); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
foreach my $returned_oid (@oids) { |
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
if ( !oid_base_match( $oid, $returned_oid ) ) { |
|
126
|
0
|
|
|
|
|
|
last GET_BULK; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Make sure we have not hit the end of the MIB. |
|
130
|
0
|
0
|
|
|
|
|
if ( $s->var_bind_types()->{$returned_oid} == ENDOFMIBVIEW ) { |
|
131
|
0
|
|
|
|
|
|
last GET_BULK; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
push @result, |
|
135
|
|
|
|
|
|
|
[ $returned_oid, $s->var_bind_list()->{$returned_oid} ]; |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
$last_oid = $returned_oid; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
return \@result; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Local Variables: |
|
149
|
|
|
|
|
|
|
# mode: cperl |
|
150
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
|
151
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
|
152
|
|
|
|
|
|
|
# cperl-indent-parens-as-block: t |
|
153
|
|
|
|
|
|
|
# End: |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__ |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=pod |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 NAME |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
SNMP::Insight::Session::NetSNMP - Net::SNMP based implementation for SNMP::Insight::Session |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 VERSION |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
version 0.002 |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 METHODS |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 get_scalar($oid) |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Implements get_scalar using Net::SNMP session |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 get_subtree($oid) |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Implements get_subtree using Net::SNMP session |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Session interface L<SNMP::Insight::Session> |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 AUTHOR |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Gabriele Mambrini <g.mambrini@gmail.com> |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Gabriele Mambrini. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
190
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |