line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mock::Net::SNMP; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
514771
|
use 5.008008; |
|
15
|
|
|
|
|
58
|
|
|
15
|
|
|
|
|
594
|
|
4
|
15
|
|
|
15
|
|
96
|
use strict; |
|
15
|
|
|
|
|
60
|
|
|
15
|
|
|
|
|
469
|
|
5
|
15
|
|
|
15
|
|
75
|
use warnings; |
|
15
|
|
|
|
|
44
|
|
|
15
|
|
|
|
|
392
|
|
6
|
15
|
|
|
15
|
|
79
|
use Carp; |
|
15
|
|
|
|
|
24
|
|
|
15
|
|
|
|
|
1289
|
|
7
|
15
|
|
|
15
|
|
13438
|
use Readonly; |
|
15
|
|
|
|
|
49223
|
|
|
15
|
|
|
|
|
912
|
|
8
|
15
|
|
|
15
|
|
14922
|
use Test::MockObject::Extends; |
|
15
|
|
|
|
|
126952
|
|
|
15
|
|
|
|
|
130
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Readonly::Scalar my $VARBINDLIST_MULTIPLE => 3; |
11
|
|
|
|
|
|
|
Readonly::Scalar my $MAX_RETRIES => 20; |
12
|
|
|
|
|
|
|
Readonly::Scalar my $MIN_MSG_OCTETS => 484; |
13
|
|
|
|
|
|
|
Readonly::Scalar my $MAX_MSG_OCTETS => 65_535; |
14
|
|
|
|
|
|
|
Readonly::Scalar my $DEFAULT_MSG_SIZE => 1_472; |
15
|
|
|
|
|
|
|
Readonly::Scalar my $DEFAULT_TIMEOUT => 5.0; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $NEGATIVE_ONE => -1; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '1.02'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=pod |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=for stopwords Halliday oid oids SNMP varbindlist varbindnames varbindtypes Varbindlist hostname -varbindlist undef |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Test::Mock::Net::SNMP - Perl extension for mocking Net::SNMP in your unit tests. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Test::Mock::Net::SNMP; |
31
|
|
|
|
|
|
|
my $mock_snmp = Test::Mock::Net::SNMP->new(); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Test::Mock::Net::SNMP is a simple way to mock a Net::SNMP object and allows you |
36
|
|
|
|
|
|
|
to test your modules behaviour when retrieving SNMP data or sending SNMP traps. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 new |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $mock_net_snmp = Test::Mock::Net::SNMP->new(); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Generates the mock object required to mock Net::SNMP |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
15
|
|
|
15
|
1
|
882
|
my ($class, %args) = @_; |
52
|
|
|
|
|
|
|
|
53
|
15
|
|
|
|
|
41
|
my $self = {}; |
54
|
15
|
|
|
|
|
50
|
bless $self, $class; |
55
|
|
|
|
|
|
|
|
56
|
15
|
|
|
|
|
81
|
$self->_initialise(); |
57
|
|
|
|
|
|
|
|
58
|
15
|
|
|
|
|
51
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 set_varbindlist |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$mock_net_snmp->set_varbindlist( |
64
|
|
|
|
|
|
|
[ |
65
|
|
|
|
|
|
|
{'1.3.6.1.2.1.2.2.1' => 1, '1.3.6.1.2.1.2.2.2' => 2, '1.3.6.1.2.1.2.2.3' => 3, '1.3.6.1.2.1.2.2.4' => 4}, |
66
|
|
|
|
|
|
|
{'1.3.6.1.2.1.2.2.5' => 5, '1.3.6.1.2.1.2.3.1' => 1, '1.3.6.1.2.1.2.3.2' => 2, '1.3.6.1.2.1.2.3.3' => 5} |
67
|
|
|
|
|
|
|
] |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
set_varbindlist is the main way of returning values in Net::SNMP |
71
|
|
|
|
|
|
|
the most important part of setting up the mock is setting this correctly |
72
|
|
|
|
|
|
|
takes an array reference of varbindlist hashes and returns true |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This will also set up varbindnames, but you can overwrite this by |
75
|
|
|
|
|
|
|
calling set_varbindnames (see below). set_varbindlist will overwrite |
76
|
|
|
|
|
|
|
varbindnames so it's best to call this first. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
To force a failed return for a request method or a call to var_bind_list |
79
|
|
|
|
|
|
|
assign a value of undef to the array element that represents that call. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
i.e. if we have a blocking get_request that is performed after two set |
82
|
|
|
|
|
|
|
request, and we want that request to fail to make sure that our code is |
83
|
|
|
|
|
|
|
handling a the failure correctly, we could set it up like this: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$mock_net_snmp->set_varbindlist( |
86
|
|
|
|
|
|
|
[ |
87
|
|
|
|
|
|
|
{ '1.3.6.1.2.1.1.4.0' => 'Help Desk x911', '1.3.6.1.2.1.1.6.0' => 'Building 1, First Floor' }, |
88
|
|
|
|
|
|
|
{ '1.3.6.1.2.1.1.4.0' => 'Help Desk x911', '1.3.6.1.2.1.1.6.0' => 'Building 1, Second Floor' }, |
89
|
|
|
|
|
|
|
undef, |
90
|
|
|
|
|
|
|
{ '1.3.6.1.2.1.1.3.0' => 600 } |
91
|
|
|
|
|
|
|
] |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub set_varbindlist { |
97
|
14
|
|
|
14
|
1
|
3773
|
my ($self, $vbl) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# varbindnames is just a list of the oids in vabindlist so we can build this automatically |
100
|
|
|
|
|
|
|
# start by clearing it out |
101
|
14
|
|
|
|
|
55
|
$self->{varbindnames} = []; |
102
|
14
|
|
|
|
|
39
|
for my $lst (@{$vbl}) { |
|
14
|
|
|
|
|
42
|
|
103
|
33
|
100
|
|
|
|
106
|
next unless defined $lst; |
104
|
32
|
|
|
|
|
53
|
my $names = []; |
105
|
32
|
|
|
|
|
44
|
@{$names} = sort { $a cmp $b } keys %{$lst}; |
|
32
|
|
|
|
|
83
|
|
|
63
|
|
|
|
|
143
|
|
|
32
|
|
|
|
|
206
|
|
106
|
32
|
|
|
|
|
51
|
push @{ $self->{varbindnames} }, $names; |
|
32
|
|
|
|
|
92
|
|
107
|
|
|
|
|
|
|
} |
108
|
14
|
|
|
|
|
86
|
$self->{varbindlist} = $vbl; |
109
|
14
|
|
|
|
|
44
|
return 1; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 set_varbindnames |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$mock_net_snmp->set_varbindnames([[qw( 2.2.1 2.2.3 2.2.4 )]]); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
varbindnames is a list of names for each oid, it should match the |
117
|
|
|
|
|
|
|
keys of the hash that the call to var_bind_list returns. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
set_varbindnames takes an array reference of arrays of oids. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub set_varbindnames { |
124
|
1
|
|
|
1
|
1
|
671
|
my ($self, $vbn) = @_; |
125
|
1
|
|
|
|
|
3
|
$self->{varbindnames} = $vbn; |
126
|
1
|
|
|
|
|
4
|
return 1; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 set_varbindtypes |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$mock_net_snmp->set_varbindtypes( |
132
|
|
|
|
|
|
|
[ |
133
|
|
|
|
|
|
|
{ '1.2.1.1' => OCTET_STRING, '1.2.1.2' => OCTET_STRING, '1.2.1.3' => OCTET_STRING }, |
134
|
|
|
|
|
|
|
{ '1.2.2.1' => OCTET_STRING, '1.2.2.2' => OCTET_STRING, '1.2.2.3' => OCTET_STRING } |
135
|
|
|
|
|
|
|
] |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
varbindtypes is a hash of types for each oid |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
set_varbindtypes takes an array reference of varbindtypes |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub set_varbindtypes { |
145
|
2
|
|
|
2
|
1
|
26
|
my ($self, $vbt) = @_; |
146
|
2
|
|
|
|
|
5
|
$self->{varbindtypes} = $vbt; |
147
|
2
|
|
|
|
|
6
|
return 1; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 set_session_failure |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
$mock_net_snmp->set_session_failure() |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
calling this method will mean that all calls to Net::SNMP->session |
155
|
|
|
|
|
|
|
will fail. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
To revert this you need to call reset_values (see below) |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub set_session_failure { |
162
|
3
|
|
|
3
|
1
|
4986
|
my ($self) = @_; |
163
|
3
|
|
|
|
|
14
|
return $self->{session_failure} = 1; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 set_error |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
$mock_net_snmp->set_error('Error message'); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This method allows you to override the error message that |
171
|
|
|
|
|
|
|
will be returned if an error occurs. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub set_error { |
176
|
4
|
|
|
4
|
1
|
13
|
my ($self, $message) = @_; |
177
|
4
|
|
|
|
|
18
|
return $self->{error} = $message; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 set_error_status |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
$mock_net_snmp->set_error_status($status); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This lets you set the return value of an $snmp->error_status() call. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub set_error_status { |
189
|
1
|
|
|
1
|
1
|
2
|
my ($self, $status) = @_; |
190
|
1
|
|
|
|
|
5
|
return $self->{error_status} = $status; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 set_error_index |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
$mock_net_snmp->set_error_index($index); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This lets you set the return value of an $snmp->error_index() call. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub set_error_index { |
202
|
1
|
|
|
1
|
1
|
2
|
my ($self, $index) = @_; |
203
|
1
|
|
|
|
|
5
|
return $self->{error_index} = $index; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 get_option_val |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
is($mock_net_snmp->get_option_val('session','-hostname'),q{myhost.myserver.com},q{correct hostname passed to session}); |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
is_deeply($mock_net_snmp->get_option_val('get_request','-varbindlist',0),['1.2.2.1'],q{first call to get_request is for 1.2.2.1}); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
is($mock_net_snmp->get_option_val($method,$option,$position), $expected, qq{$option passed to $method in call $postition is $expected}); |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
where: |
215
|
|
|
|
|
|
|
$method is the mocked method, |
216
|
|
|
|
|
|
|
$option is the option passed into the method, |
217
|
|
|
|
|
|
|
$position is the position in the call stack (the last call is returned if no position is given) |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
it returns the value for that option. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Net::SNMP lets you specify options in a style such as -varbindlist or Varbindlist. Test::Mock::Net::SNMP expects you to retrieve the option values using the same style as the option passed in. So if your method call uses Varbindlist then $option should equal Varbindlist. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub get_option_val { |
226
|
57
|
|
|
57
|
1
|
4617
|
my ($self, $method, $option, $position) = @_; |
227
|
57
|
100
|
|
|
|
236
|
croak "Unknown mocked method: $method" unless exists $self->{$method}; |
228
|
56
|
100
|
|
|
|
186
|
if ($method eq 'session') { |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
#session values are not stored in a call stack |
231
|
16
|
100
|
|
|
|
58
|
croak "Option: <$option> was not passed in to $method" unless exists $self->{$method}{$option}; |
232
|
15
|
|
|
|
|
80
|
return $self->{$method}{$option}; |
233
|
|
|
|
|
|
|
} else { |
234
|
40
|
100
|
|
|
|
154
|
$position = $NEGATIVE_ONE unless defined $position; |
235
|
40
|
50
|
|
|
|
129
|
croak "Option: <$option> was not passed in to $method at position $position" |
236
|
|
|
|
|
|
|
unless exists $self->{$method}[$position]{$option}; |
237
|
40
|
|
|
|
|
362
|
return $self->{$method}[$position]{$option}; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 get_num_method_calls |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
$mock_net_snmp->get_num_method_calls('get_request'); |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
returns the number of times that the requested method was called. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub get_num_method_calls { |
250
|
4
|
|
|
4
|
1
|
1292
|
my ($self, $method) = @_; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
# if the method is not in $self then either it doesn't exist or it wasn't called |
253
|
4
|
50
|
|
|
|
20
|
return 0 unless exists $self->{$method}; |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
# session calls should only register once |
256
|
4
|
50
|
|
|
|
15
|
return 1 if $method eq 'session'; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
# return the number of option values in the methods array |
259
|
4
|
|
|
|
|
9
|
return scalar @{ $self->{$method} }; |
|
4
|
|
|
|
|
36
|
|
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head2 reset_values |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
$mock_net_snmp->reset_values(); |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Sets all the values to their original state. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=cut |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub reset_values { |
271
|
20
|
|
|
20
|
1
|
2130
|
my ($self) = @_; |
272
|
20
|
|
|
|
|
35
|
for my $setting (keys %{$self}) { |
|
20
|
|
|
|
|
100
|
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# we want to keep the mocked object |
275
|
123
|
100
|
|
|
|
345
|
next if $setting eq 'net_snmp'; |
276
|
103
|
|
|
|
|
295
|
delete $self->{$setting}; |
277
|
|
|
|
|
|
|
} |
278
|
20
|
|
|
|
|
158
|
return 1; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head2 clear_error |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
$mock_net_snmp->clear_error(); |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
Test::Mock::Net::SNMP will only update the error string if it hasn't already been set. This means that sometimes it is useful to clear the error string |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=cut |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
sub clear_error { |
290
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
291
|
0
|
|
|
|
|
0
|
return $self->{error} = q{}; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=head2 set_trap_failure |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
$mock_net_snmp->set_trap_failure(); |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
force a trap method to fail. |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=cut |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
sub set_trap_failure { |
303
|
1
|
|
|
1
|
1
|
2
|
my ($self) = @_; |
304
|
1
|
|
|
|
|
3
|
return $self->{trap_error} = 1; |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
# private methods go here. |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
# set up all the mocked methods |
310
|
|
|
|
|
|
|
sub _initialise { |
311
|
15
|
|
|
15
|
|
35
|
my ($self) = @_; |
312
|
15
|
|
|
|
|
176
|
$self->{net_snmp} = Test::MockObject::Extends->new('Net::SNMP'); |
313
|
15
|
|
|
|
|
2354
|
$self->_mock_session(); # this needs calling before any of the others |
314
|
15
|
|
|
|
|
106
|
$self->_mock_close(); |
315
|
15
|
|
|
|
|
93
|
$self->_mock_snmp_dispatcher(); |
316
|
15
|
|
|
|
|
72
|
$self->_mock_get_request(); |
317
|
15
|
|
|
|
|
65
|
$self->_mock_get_next_request(); |
318
|
15
|
|
|
|
|
71
|
$self->_mock_set_request(); |
319
|
15
|
|
|
|
|
57
|
$self->_mock_trap(); |
320
|
15
|
|
|
|
|
60
|
$self->_mock_get_bulk_request(); |
321
|
15
|
|
|
|
|
84
|
$self->_mock_inform_request(); |
322
|
15
|
|
|
|
|
56
|
$self->_mock_snmpv2_trap(); |
323
|
15
|
|
|
|
|
58
|
$self->_mock_get_table(); |
324
|
15
|
|
|
|
|
63
|
$self->_mock_get_entries(); |
325
|
15
|
|
|
|
|
59
|
$self->_mock_version(); |
326
|
15
|
|
|
|
|
59
|
$self->_mock_error(); |
327
|
15
|
|
|
|
|
57
|
$self->_mock_hostname(); |
328
|
15
|
|
|
|
|
62
|
$self->_mock_error_status(); |
329
|
15
|
|
|
|
|
60
|
$self->_mock_error_index(); |
330
|
15
|
|
|
|
|
61
|
$self->_mock_var_bind_list(); |
331
|
15
|
|
|
|
|
134
|
$self->_mock_var_bind_names(); |
332
|
15
|
|
|
|
|
61
|
$self->_mock_var_bind_types(); |
333
|
15
|
|
|
|
|
58
|
$self->_mock_timeout(); |
334
|
15
|
|
|
|
|
56
|
$self->_mock_retries(); |
335
|
15
|
|
|
|
|
84
|
$self->_mock_max_msg_size(); |
336
|
15
|
|
|
|
|
54
|
$self->_mock_translate(); |
337
|
15
|
|
|
|
|
55
|
$self->_mock_debug(); |
338
|
15
|
|
|
|
|
23
|
return 1; # return true if we got here |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
sub _mock_session { |
342
|
15
|
|
|
15
|
|
35
|
my ($self) = @_; |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
#session() - create a new Net::SNMP object |
345
|
|
|
|
|
|
|
$self->{net_snmp}->fake_module( |
346
|
|
|
|
|
|
|
'Net::SNMP', |
347
|
|
|
|
|
|
|
session => sub { |
348
|
32
|
|
|
32
|
|
4832
|
my ($return_val); |
349
|
32
|
|
|
|
|
158
|
my ($ns_class, %session_options) = @_; |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
# tell all the other methods that we are open |
352
|
32
|
|
|
|
|
82
|
$self->{closed} = 0; |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
# store the session options |
355
|
32
|
|
|
|
|
77
|
$self->{session} = \%session_options; |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
# allow for failing a call to session |
358
|
32
|
100
|
|
|
|
110
|
if ($self->{session_failure}) { |
359
|
6
|
|
|
|
|
9
|
$return_val = undef; |
360
|
6
|
100
|
66
|
|
|
52
|
$self->{error} = 'session failure' unless defined $self->{error} && $self->{error}; |
361
|
|
|
|
|
|
|
} else { |
362
|
26
|
|
|
|
|
54
|
$return_val = $self->{net_snmp}; |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
# Net::SNMP returns the object and an error string if you want it |
366
|
32
|
100
|
|
|
|
95
|
if (wantarray) { |
367
|
19
|
|
|
|
|
71
|
return $return_val, $self->{error}; |
368
|
|
|
|
|
|
|
} else { |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
# it returns the object if you call it in scalar |
371
|
13
|
|
|
|
|
89
|
return $return_val; |
372
|
|
|
|
|
|
|
} |
373
|
|
|
|
|
|
|
} |
374
|
15
|
|
|
|
|
246
|
); |
375
|
15
|
|
|
|
|
2499
|
return 1; |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
sub _mock_close { |
379
|
15
|
|
|
15
|
|
40
|
my ($self) = @_; |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
#close() - clear the Transport Domain associated with the object |
382
|
15
|
|
|
6
|
|
120
|
$self->{net_snmp}->mock(close => sub { return $self->{closed} = 1; }); |
|
6
|
|
|
|
|
428
|
|
383
|
15
|
|
|
|
|
512
|
return 1; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
sub _mock_snmp_dispatcher { |
387
|
15
|
|
|
15
|
|
40
|
my ($self) = @_; |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
#snmp_dispatcher() - enter the non-blocking object event loop |
390
|
|
|
|
|
|
|
# all of the mocked methods are going to block so this only needs to return true |
391
|
15
|
|
|
|
|
164
|
$self->{net_snmp}->set_true('snmp_dispatcher'); |
392
|
15
|
|
|
|
|
938
|
return 1; |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
sub _process_varbindlist { |
396
|
47
|
|
|
47
|
|
122
|
my ($self, $caller, %args) = @_; |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
# if we don't have varbindlist then that will be an error |
399
|
47
|
100
|
66
|
|
|
317
|
unless (exists $args{Varbindlist} || exists $args{-varbindlist}) { |
400
|
6
|
50
|
|
|
|
52
|
$self->{error} = '-varbindlist option not passed in to ' . $caller unless $self->{error}; |
401
|
6
|
|
|
|
|
55
|
return 0; |
402
|
|
|
|
|
|
|
} |
403
|
|
|
|
|
|
|
|
404
|
41
|
|
|
|
|
129
|
return 1; |
405
|
|
|
|
|
|
|
} |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
sub _process_trap_varbindlist { |
408
|
11
|
|
|
11
|
|
25
|
my ($self, $caller, %args) = @_; |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
# check the first 2 sets of values are as expected |
411
|
11
|
|
50
|
|
|
78
|
my $vbl = $args{Varbindlist} || $args{-varbindlist} || []; |
412
|
11
|
|
|
|
|
17
|
my $sets = $VARBINDLIST_MULTIPLE + $VARBINDLIST_MULTIPLE; |
413
|
11
|
100
|
|
|
|
19
|
if (scalar @{$vbl} < ($sets)) { |
|
11
|
|
|
|
|
35
|
|
414
|
2
|
50
|
|
|
|
14
|
$self->{error} = "$caller requires sysUpTime and snmpTrapOID as the first 2 sets of varbindlist." |
415
|
|
|
|
|
|
|
unless $self->{error}; |
416
|
2
|
|
|
|
|
21
|
return 0; |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
|
419
|
9
|
|
33
|
|
|
40
|
my $list = $args{-varbindlist} || $args{Varbindlist}; |
420
|
9
|
100
|
|
|
|
11
|
if (scalar @{$list} % $VARBINDLIST_MULTIPLE > 0) { |
|
9
|
|
|
|
|
32
|
|
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
# we have an incorrect number of variables |
423
|
2
|
50
|
|
|
|
17
|
$self->{error} = "-varbindlist expects multiples of $VARBINDLIST_MULTIPLE in call to $caller" |
424
|
|
|
|
|
|
|
unless $self->{error}; |
425
|
2
|
|
|
|
|
21
|
return 0; |
426
|
|
|
|
|
|
|
} |
427
|
|
|
|
|
|
|
|
428
|
7
|
100
|
66
|
|
|
42
|
unless ($vbl->[0] eq '1.3.6.1.2.1.1.3.0' && $vbl->[$VARBINDLIST_MULTIPLE] eq '1.3.6.1.6.3.1.1.4.1.0') { |
429
|
2
|
50
|
|
|
|
13
|
$self->{error} = "$caller: Wrong oids found in sysUpTime and snmpTrapOID spaces" unless $self->{error}; |
430
|
2
|
|
|
|
|
18
|
return 0; |
431
|
|
|
|
|
|
|
} |
432
|
|
|
|
|
|
|
|
433
|
5
|
|
|
|
|
25
|
return 1; |
434
|
|
|
|
|
|
|
} |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
sub _get_varbindlist { |
437
|
39
|
|
|
39
|
|
65
|
my ($self) = @_; |
438
|
|
|
|
|
|
|
|
439
|
39
|
100
|
66
|
|
|
142
|
if (defined $self->{varbindlist} && @{ $self->{varbindlist} }) { |
|
30
|
|
|
|
|
159
|
|
440
|
30
|
|
|
|
|
45
|
my $value = shift @{ $self->{varbindlist} }; |
|
30
|
|
|
|
|
59
|
|
441
|
30
|
100
|
|
|
|
197
|
return $value if defined $value; |
442
|
|
|
|
|
|
|
} |
443
|
|
|
|
|
|
|
|
444
|
10
|
100
|
|
|
|
51
|
$self->{error} = 'No more elements in varbindlist!' unless $self->{error}; |
445
|
10
|
|
|
|
|
64
|
return; |
446
|
|
|
|
|
|
|
} |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
sub _process_callback { |
449
|
38
|
|
|
38
|
|
93
|
my ($self, %args) = @_; |
450
|
|
|
|
|
|
|
|
451
|
38
|
|
100
|
|
|
319
|
my $cb = $args{-callback} || $args{Callback} || $self->{cb} || q{}; |
452
|
38
|
100
|
|
|
|
106
|
if ($cb) { |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
# calls from within the callback don't set the call back so we need to track it |
455
|
20
|
|
|
|
|
111
|
$self->{cb} = $cb; |
456
|
|
|
|
|
|
|
|
457
|
20
|
100
|
|
|
|
76
|
if (ref($cb) eq 'ARRAY') { |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
# best not mess with our reference |
460
|
15
|
|
|
|
|
24
|
my @cbs = @{$cb}; |
|
15
|
|
|
|
|
58
|
|
461
|
15
|
|
|
|
|
31
|
my $sub = shift @cbs; |
462
|
15
|
|
|
|
|
252
|
$sub->($self->{net_snmp}, @cbs); |
463
|
|
|
|
|
|
|
} else { |
464
|
5
|
|
|
|
|
16
|
$cb->($self->{net_snmp}); |
465
|
|
|
|
|
|
|
} |
466
|
20
|
|
|
|
|
241
|
return 1; |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
} else { |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
# we are blocking so return the first element of varbindlist |
471
|
18
|
|
|
|
|
62
|
return $self->_get_varbindlist(); |
472
|
|
|
|
|
|
|
} |
473
|
0
|
|
|
|
|
0
|
return 1; |
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
# sets the error message appropriately and returns the value of closed |
477
|
|
|
|
|
|
|
sub _closed { |
478
|
67
|
|
|
67
|
|
1386
|
my ($self) = @_; |
479
|
67
|
100
|
|
|
|
211
|
$self->{error} = q{Can't call method on closed object} if $self->{closed}; |
480
|
67
|
|
|
|
|
288
|
return $self->{closed}; |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
sub _mock_get_request { |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
#get_request() - send a SNMP get-request to the remote agent |
486
|
|
|
|
|
|
|
# this just sets up the object with passed in variables so that we can |
487
|
|
|
|
|
|
|
# call them later if we need to and calls the callback if one was provided |
488
|
15
|
|
|
15
|
|
35
|
my ($self) = @_; |
489
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
490
|
|
|
|
|
|
|
get_request => sub { |
491
|
13
|
|
|
13
|
|
1158
|
my ($class, %args) = @_; |
492
|
13
|
|
|
|
|
22
|
push @{ $self->{get_request} }, \%args; |
|
13
|
|
|
|
|
38
|
|
493
|
|
|
|
|
|
|
|
494
|
13
|
100
|
|
|
|
47
|
return if $self->_closed(); |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
# check varbindlist vals |
497
|
12
|
100
|
|
|
|
64
|
return unless $self->_process_varbindlist('get_request', %args); |
498
|
11
|
|
|
|
|
54
|
return $self->_process_callback(%args); |
499
|
|
|
|
|
|
|
} |
500
|
15
|
|
|
|
|
118
|
); |
501
|
15
|
|
|
|
|
347
|
return 1; |
502
|
|
|
|
|
|
|
} |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
sub _mock_get_next_request { |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
#get_next_request() - send a SNMP get-next-request to the remote agent |
507
|
15
|
|
|
15
|
|
31
|
my ($self) = @_; |
508
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
509
|
|
|
|
|
|
|
get_next_request => sub { |
510
|
5
|
|
|
5
|
|
792
|
my ($class, %args) = @_; |
511
|
5
|
|
|
|
|
9
|
push @{ $self->{get_next_request} }, \%args; |
|
5
|
|
|
|
|
16
|
|
512
|
|
|
|
|
|
|
|
513
|
5
|
100
|
|
|
|
19
|
return if $self->_closed(); |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
# check varbindlist vals |
516
|
4
|
100
|
|
|
|
24
|
return unless $self->_process_varbindlist('get_next_request', %args); |
517
|
3
|
|
|
|
|
14
|
return $self->_process_callback(%args); |
518
|
|
|
|
|
|
|
} |
519
|
15
|
|
|
|
|
120
|
); |
520
|
15
|
|
|
|
|
367
|
return 1; |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
sub _mock_set_request { |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
#set_request() - send a SNMP set-request to the remote agent |
526
|
15
|
|
|
15
|
|
41
|
my ($self) = @_; |
527
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
528
|
|
|
|
|
|
|
set_request => sub { |
529
|
13
|
|
|
13
|
|
1038
|
my ($class, %args) = @_; |
530
|
13
|
|
|
|
|
16
|
push @{ $self->{set_request} }, \%args; |
|
13
|
|
|
|
|
46
|
|
531
|
|
|
|
|
|
|
|
532
|
13
|
100
|
|
|
|
36
|
return if $self->_closed(); |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
# check varbindlist vals |
535
|
12
|
100
|
|
|
|
44
|
return unless $self->_process_varbindlist('set_request', %args); |
536
|
11
|
|
33
|
|
|
37
|
my $list = $args{-varbindlist} || $args{Varbindlist}; |
537
|
11
|
100
|
|
|
|
16
|
if (scalar @{$list} % $VARBINDLIST_MULTIPLE > 0) { |
|
11
|
|
|
|
|
40
|
|
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
# we have an incorrect number of variables |
540
|
1
|
50
|
|
|
|
6
|
$self->{error} = "-varbindlist expects multiples of $VARBINDLIST_MULTIPLE in call to set_request" |
541
|
|
|
|
|
|
|
unless $self->{error}; |
542
|
1
|
|
|
|
|
5
|
return; |
543
|
|
|
|
|
|
|
} |
544
|
|
|
|
|
|
|
|
545
|
10
|
|
|
|
|
34
|
return $self->_process_callback(%args); |
546
|
|
|
|
|
|
|
} |
547
|
15
|
|
|
|
|
270
|
); |
548
|
15
|
|
|
|
|
353
|
return 1; |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
sub _mock_trap { |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
#trap() - send a SNMP trap to the remote manager |
554
|
15
|
|
|
15
|
|
322
|
my ($self) = @_; |
555
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
556
|
|
|
|
|
|
|
trap => sub { |
557
|
4
|
|
|
4
|
|
258
|
my ($class, %args) = @_; |
558
|
4
|
|
|
|
|
6
|
push @{ $self->{trap} }, \%args; |
|
4
|
|
|
|
|
10
|
|
559
|
4
|
100
|
|
|
|
11
|
return if $self->_closed(); |
560
|
|
|
|
|
|
|
|
561
|
3
|
100
|
66
|
|
|
19
|
if (defined $self->{trap_error} && $self->{trap_error}) { |
562
|
1
|
|
|
|
|
6
|
return; |
563
|
|
|
|
|
|
|
} else { |
564
|
2
|
|
|
|
|
15
|
return 1; |
565
|
|
|
|
|
|
|
} |
566
|
|
|
|
|
|
|
} |
567
|
15
|
|
|
|
|
130
|
); |
568
|
15
|
|
|
|
|
401
|
return 1; |
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
sub _mock_get_bulk_request { |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
#get_bulk_request() - send a SNMP get-bulk-request to the remote agent |
574
|
15
|
|
|
15
|
|
32
|
my ($self) = @_; |
575
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
576
|
|
|
|
|
|
|
get_bulk_request => sub { |
577
|
7
|
|
|
7
|
|
647
|
my ($class, %args) = @_; |
578
|
7
|
|
|
|
|
10
|
push @{ $self->{get_bulk_request} }, \%args; |
|
7
|
|
|
|
|
19
|
|
579
|
|
|
|
|
|
|
|
580
|
7
|
100
|
|
|
|
56
|
return if $self->_closed(); |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
# check varbindlist vals |
583
|
6
|
100
|
|
|
|
27
|
return unless $self->_process_varbindlist('get_bulk_request', %args); |
584
|
5
|
|
|
|
|
25
|
return $self->_process_callback(%args); |
585
|
|
|
|
|
|
|
} |
586
|
15
|
|
|
|
|
113
|
); |
587
|
15
|
|
|
|
|
383
|
return 1; |
588
|
|
|
|
|
|
|
} |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
sub _mock_inform_request { |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
#inform_request() - send a SNMP inform-request to the remote manager |
593
|
15
|
|
|
15
|
|
50
|
my ($self) = @_; |
594
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
595
|
|
|
|
|
|
|
inform_request => sub { |
596
|
8
|
|
|
8
|
|
607
|
my ($class, %args) = @_; |
597
|
8
|
|
|
|
|
13
|
push @{ $self->{inform_request} }, \%args; |
|
8
|
|
|
|
|
25
|
|
598
|
|
|
|
|
|
|
|
599
|
8
|
100
|
|
|
|
22
|
return if $self->_closed(); |
600
|
|
|
|
|
|
|
|
601
|
7
|
100
|
|
|
|
30
|
return unless $self->_process_varbindlist('inform_request', %args); |
602
|
6
|
100
|
|
|
|
21
|
return unless $self->_process_trap_varbindlist('inform_request', %args); |
603
|
3
|
|
|
|
|
11
|
return $self->_process_callback(%args); |
604
|
|
|
|
|
|
|
} |
605
|
15
|
|
|
|
|
145
|
); |
606
|
15
|
|
|
|
|
339
|
return 1; |
607
|
|
|
|
|
|
|
} |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
sub _mock_snmpv2_trap { |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
#snmpv2_trap() - send a SNMP snmpV2-trap to the remote manager |
612
|
15
|
|
|
15
|
|
53
|
my ($self) = @_; |
613
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
614
|
|
|
|
|
|
|
snmpv2_trap => sub { |
615
|
7
|
|
|
7
|
|
591
|
my ($class, %args) = @_; |
616
|
7
|
|
|
|
|
12
|
push @{ $self->{snmpv2_trap} }, \%args; |
|
7
|
|
|
|
|
20
|
|
617
|
|
|
|
|
|
|
|
618
|
7
|
100
|
|
|
|
26
|
return if $self->_closed(); |
619
|
|
|
|
|
|
|
|
620
|
6
|
100
|
|
|
|
23
|
return unless $self->_process_varbindlist('snmpv2_trap', %args); |
621
|
5
|
100
|
|
|
|
18
|
return unless $self->_process_trap_varbindlist('snmpv2_trap', %args); |
622
|
|
|
|
|
|
|
|
623
|
2
|
50
|
33
|
|
|
10
|
if (defined $self->{trap_error} && $self->{trap_error}) { |
624
|
0
|
|
|
|
|
0
|
return; |
625
|
|
|
|
|
|
|
} else { |
626
|
2
|
|
|
|
|
12
|
return 1; |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
} |
629
|
15
|
|
|
|
|
122
|
); |
630
|
15
|
|
|
|
|
382
|
return 1; |
631
|
|
|
|
|
|
|
} |
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
sub _mock_get_table { |
634
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
#get_table() - retrieve a table from the remote agent |
636
|
15
|
|
|
15
|
|
34
|
my ($self) = @_; |
637
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
638
|
|
|
|
|
|
|
get_table => sub { |
639
|
5
|
|
|
5
|
|
322
|
my ($class, %args) = @_; |
640
|
5
|
|
|
|
|
7
|
push @{ $self->{get_table} }, \%args; |
|
5
|
|
|
|
|
13
|
|
641
|
|
|
|
|
|
|
|
642
|
5
|
100
|
|
|
|
13
|
return if $self->_closed(); |
643
|
|
|
|
|
|
|
|
644
|
4
|
100
|
66
|
|
|
18
|
unless (exists $args{-baseoid} || exists $args{Baseoid}) { |
645
|
1
|
50
|
|
|
|
6
|
$self->{error} = '-baseoid not passed in to get_table' unless $self->{error}; |
646
|
1
|
|
|
|
|
5
|
return; |
647
|
|
|
|
|
|
|
} |
648
|
|
|
|
|
|
|
|
649
|
3
|
|
|
|
|
11
|
return $self->_process_callback(%args); |
650
|
|
|
|
|
|
|
} |
651
|
15
|
|
|
|
|
185
|
); |
652
|
15
|
|
|
|
|
386
|
return 1; |
653
|
|
|
|
|
|
|
} |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
sub _mock_get_entries { |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
#get_entries() - retrieve table entries from the remote agent |
658
|
15
|
|
|
15
|
|
32
|
my ($self) = @_; |
659
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
660
|
|
|
|
|
|
|
get_entries => sub { |
661
|
5
|
|
|
5
|
|
414
|
my ($class, %args) = @_; |
662
|
5
|
|
|
|
|
8
|
push @{ $self->{get_entries} }, \%args; |
|
5
|
|
|
|
|
13
|
|
663
|
|
|
|
|
|
|
|
664
|
5
|
100
|
|
|
|
18
|
return if $self->_closed(); |
665
|
|
|
|
|
|
|
|
666
|
4
|
100
|
66
|
|
|
21
|
unless (exists $args{-columns} || exists $args{Columns}) { |
667
|
1
|
50
|
|
|
|
6
|
$self->{error} = '-columns not passed in to get_entries' unless $self->{error}; |
668
|
1
|
|
|
|
|
5
|
return; |
669
|
|
|
|
|
|
|
} |
670
|
|
|
|
|
|
|
|
671
|
3
|
|
|
|
|
27
|
return $self->_process_callback(%args); |
672
|
|
|
|
|
|
|
} |
673
|
15
|
|
|
|
|
123
|
); |
674
|
15
|
|
|
|
|
340
|
return 1; |
675
|
|
|
|
|
|
|
} |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
sub _mock_version { |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
#version() - get the SNMP version from the object |
680
|
15
|
|
|
15
|
|
34
|
my ($self) = @_; |
681
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
682
|
|
|
|
|
|
|
version => sub { |
683
|
2
|
|
|
2
|
|
116
|
my ($class) = @_; |
684
|
2
|
|
100
|
|
|
21
|
my $version = $self->{session}{-version} || $self->{session}{Version} || 1; |
685
|
2
|
|
|
|
|
8
|
my ($return) = $version =~ /(\d)/; |
686
|
2
|
|
|
|
|
11
|
return $return; |
687
|
|
|
|
|
|
|
} |
688
|
15
|
|
|
|
|
118
|
); |
689
|
15
|
|
|
|
|
327
|
return 1; |
690
|
|
|
|
|
|
|
} |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
sub _mock_error { |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
#error() - get the current error message from the object |
695
|
15
|
|
|
15
|
|
39
|
my ($self) = @_; |
696
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
697
|
|
|
|
|
|
|
error => sub { |
698
|
31
|
|
|
31
|
|
2201
|
return $self->{error}; |
699
|
|
|
|
|
|
|
} |
700
|
15
|
|
|
|
|
130
|
); |
701
|
15
|
|
|
|
|
340
|
return 1; |
702
|
|
|
|
|
|
|
} |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
sub _mock_hostname { |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
#hostname() - get the hostname associated with the object |
707
|
15
|
|
|
15
|
|
45
|
my ($self) = @_; |
708
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
709
|
|
|
|
|
|
|
hostname => sub { |
710
|
20
|
|
100
|
20
|
|
3383
|
return $self->{session}{-hostname} || $self->{session}{Hostname} || 'localhost'; |
711
|
|
|
|
|
|
|
} |
712
|
15
|
|
|
|
|
100
|
); |
713
|
15
|
|
|
|
|
379
|
return 1; |
714
|
|
|
|
|
|
|
} |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
sub _mock_error_status { |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
#error_status() - get the current SNMP error-status from the object |
719
|
15
|
|
|
15
|
|
34
|
my ($self) = @_; |
720
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
721
|
|
|
|
|
|
|
error_status => sub { |
722
|
2
|
100
|
|
2
|
|
113
|
$self->{error_status} = 0 unless defined $self->{error_status}; |
723
|
2
|
|
|
|
|
10
|
return $self->{error_status}; |
724
|
|
|
|
|
|
|
} |
725
|
15
|
|
|
|
|
89
|
); |
726
|
15
|
|
|
|
|
329
|
return 1; |
727
|
|
|
|
|
|
|
} |
728
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
sub _mock_error_index { |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
#error_index() - get the current SNMP error-index from the object |
732
|
15
|
|
|
15
|
|
27
|
my ($self) = @_; |
733
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
734
|
|
|
|
|
|
|
error_index => sub { |
735
|
2
|
100
|
|
2
|
|
123
|
$self->{error_index} = 0 unless defined $self->{error_index}; |
736
|
2
|
|
|
|
|
9
|
return $self->{error_index}; |
737
|
|
|
|
|
|
|
} |
738
|
15
|
|
|
|
|
96
|
); |
739
|
15
|
|
|
|
|
363
|
return 1; |
740
|
|
|
|
|
|
|
} |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
sub _mock_var_bind_list { |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
#var_bind_list() - get the hash reference for the VarBindList values |
745
|
15
|
|
|
15
|
|
26
|
my ($self) = @_; |
746
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
747
|
|
|
|
|
|
|
var_bind_list => sub { |
748
|
21
|
|
|
21
|
|
1333
|
return $self->_get_varbindlist(); |
749
|
|
|
|
|
|
|
} |
750
|
15
|
|
|
|
|
88
|
); |
751
|
15
|
|
|
|
|
314
|
return 1; |
752
|
|
|
|
|
|
|
} |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
sub _mock_var_bind_names { |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
#var_bind_names() - get the array of the ObjectNames in the VarBindList |
757
|
15
|
|
|
15
|
|
37
|
my ($self) = @_; |
758
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
759
|
|
|
|
|
|
|
var_bind_names => sub { |
760
|
4
|
50
|
|
4
|
|
231
|
if (@{ $self->{varbindnames} }) { |
|
4
|
|
|
|
|
26
|
|
761
|
4
|
|
|
|
|
10
|
my $names = shift @{ $self->{varbindnames} }; |
|
4
|
|
|
|
|
8
|
|
762
|
4
|
|
|
|
|
16
|
return @{$names}; |
|
4
|
|
|
|
|
19
|
|
763
|
|
|
|
|
|
|
} else { |
764
|
0
|
0
|
|
|
|
0
|
$self->{error} = 'No more elements in varbindnames!' unless $self->{error}; |
765
|
0
|
|
|
|
|
0
|
return; |
766
|
|
|
|
|
|
|
} |
767
|
|
|
|
|
|
|
} |
768
|
15
|
|
|
|
|
118
|
); |
769
|
15
|
|
|
|
|
345
|
return 1; |
770
|
|
|
|
|
|
|
} |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
sub _mock_var_bind_types { |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
#var_bind_types() - get the hash reference for the VarBindList ASN.1 types |
775
|
15
|
|
|
15
|
|
29
|
my ($self) = @_; |
776
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
777
|
|
|
|
|
|
|
var_bind_types => sub { |
778
|
1
|
50
|
|
1
|
|
683
|
if (@{ $self->{varbindtypes} }) { |
|
1
|
|
|
|
|
7
|
|
779
|
1
|
|
|
|
|
2
|
return shift @{ $self->{varbindtypes} }; |
|
1
|
|
|
|
|
7
|
|
780
|
|
|
|
|
|
|
} else { |
781
|
0
|
0
|
|
|
|
0
|
$self->{error} = 'No more elements in varbindtypes!' unless $self->{error}; |
782
|
0
|
|
|
|
|
0
|
return; |
783
|
|
|
|
|
|
|
} |
784
|
|
|
|
|
|
|
} |
785
|
15
|
|
|
|
|
102
|
); |
786
|
15
|
|
|
|
|
333
|
return 1; |
787
|
|
|
|
|
|
|
} |
788
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
sub _mock_timeout { |
790
|
|
|
|
|
|
|
|
791
|
|
|
|
|
|
|
#timeout() - set or get the current timeout period for the object |
792
|
15
|
|
|
15
|
|
36
|
my ($self) = @_; |
793
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
794
|
|
|
|
|
|
|
timeout => sub { |
795
|
3
|
|
|
3
|
|
176
|
my ($class, $option) = @_; |
796
|
3
|
100
|
|
|
|
8
|
if ($option) { |
797
|
1
|
|
|
|
|
3
|
$self->{timeout} = $option; |
798
|
1
|
|
|
|
|
5
|
return $option; |
799
|
|
|
|
|
|
|
} else { |
800
|
2
|
|
66
|
|
|
16
|
return $self->{timeout} || $DEFAULT_TIMEOUT; |
801
|
|
|
|
|
|
|
} |
802
|
|
|
|
|
|
|
} |
803
|
15
|
|
|
|
|
172
|
); |
804
|
15
|
|
|
|
|
371
|
return 1; |
805
|
|
|
|
|
|
|
} |
806
|
|
|
|
|
|
|
|
807
|
|
|
|
|
|
|
sub _mock_retries { |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
#retries() - set or get the current retry count for the object |
810
|
15
|
|
|
15
|
|
31
|
my ($self) = @_; |
811
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
812
|
|
|
|
|
|
|
retries => sub { |
813
|
5
|
|
|
5
|
|
300
|
my ($class, $option) = @_; |
814
|
5
|
100
|
|
|
|
12
|
if ($option) { |
815
|
3
|
100
|
100
|
|
|
18
|
if ($option >= 0 && $option <= $MAX_RETRIES) { |
816
|
1
|
|
|
|
|
3
|
$self->{retries} = $option; |
817
|
1
|
|
|
|
|
5
|
return $option; |
818
|
|
|
|
|
|
|
} else { |
819
|
2
|
|
|
|
|
5
|
$self->{error} = 'retries out of range'; |
820
|
2
|
|
|
|
|
9
|
return; |
821
|
|
|
|
|
|
|
} |
822
|
|
|
|
|
|
|
} else { |
823
|
2
|
|
100
|
|
|
16
|
return $self->{retries} || 1; |
824
|
|
|
|
|
|
|
} |
825
|
|
|
|
|
|
|
} |
826
|
15
|
|
|
|
|
103
|
); |
827
|
15
|
|
|
|
|
364
|
return 1; |
828
|
|
|
|
|
|
|
} |
829
|
|
|
|
|
|
|
|
830
|
|
|
|
|
|
|
sub _mock_max_msg_size { |
831
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
#max_msg_size() - set or get the current maxMsgSize for the object |
833
|
15
|
|
|
15
|
|
40
|
my ($self) = @_; |
834
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
835
|
|
|
|
|
|
|
max_msg_size => sub { |
836
|
5
|
|
|
5
|
|
261
|
my ($class, $option) = @_; |
837
|
5
|
100
|
|
|
|
11
|
if ($option) { |
838
|
3
|
100
|
100
|
|
|
16
|
if ($option >= $MIN_MSG_OCTETS && $option <= $MAX_MSG_OCTETS) { |
839
|
1
|
|
|
|
|
2
|
$self->{max_msg_size} = $option; |
840
|
1
|
|
|
|
|
39
|
return $option; |
841
|
|
|
|
|
|
|
} else { |
842
|
2
|
|
|
|
|
4
|
$self->{error} = 'max msg size out of range'; |
843
|
2
|
|
|
|
|
10
|
return; |
844
|
|
|
|
|
|
|
} |
845
|
|
|
|
|
|
|
} else { |
846
|
2
|
|
66
|
|
|
14
|
return $self->{max_msg_size} || $DEFAULT_MSG_SIZE; |
847
|
|
|
|
|
|
|
} |
848
|
|
|
|
|
|
|
} |
849
|
15
|
|
|
|
|
169
|
); |
850
|
15
|
|
|
|
|
390
|
return 1; |
851
|
|
|
|
|
|
|
} |
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
sub _mock_translate { |
854
|
|
|
|
|
|
|
|
855
|
|
|
|
|
|
|
#translate() - enable or disable the translation mode for the object |
856
|
15
|
|
|
15
|
|
31
|
my ($self) = @_; |
857
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
858
|
|
|
|
|
|
|
translate => sub { |
859
|
3
|
|
|
3
|
|
157
|
my ($class, $option) = @_; |
860
|
3
|
100
|
|
|
|
89
|
if ($option) { |
861
|
1
|
|
|
|
|
3
|
$self->{translate} = $option; |
862
|
|
|
|
|
|
|
} |
863
|
3
|
|
100
|
|
|
20
|
return $self->{translate} || 1; |
864
|
|
|
|
|
|
|
} |
865
|
15
|
|
|
|
|
115
|
); |
866
|
15
|
|
|
|
|
336
|
return 1; |
867
|
|
|
|
|
|
|
} |
868
|
|
|
|
|
|
|
|
869
|
|
|
|
|
|
|
sub _mock_debug { |
870
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
#debug() - set or get the debug mode for the module |
872
|
15
|
|
|
15
|
|
30
|
my ($self) = @_; |
873
|
|
|
|
|
|
|
$self->{net_snmp}->mock( |
874
|
|
|
|
|
|
|
debug => sub { |
875
|
3
|
|
|
3
|
|
153
|
my ($class, $option) = @_; |
876
|
3
|
100
|
|
|
|
6
|
if ($option) { |
877
|
1
|
|
|
|
|
3
|
$self->{debug} = $option; |
878
|
1
|
|
|
|
|
11
|
return $option; |
879
|
|
|
|
|
|
|
} else { |
880
|
2
|
100
|
|
|
|
8
|
$self->{debug} = 0 unless defined $self->{debug}; |
881
|
2
|
|
|
|
|
11
|
return $self->{debug}; |
882
|
|
|
|
|
|
|
} |
883
|
|
|
|
|
|
|
} |
884
|
15
|
|
|
|
|
146
|
); |
885
|
15
|
|
|
|
|
444
|
return 1; |
886
|
|
|
|
|
|
|
} |
887
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
1; |
889
|
|
|
|
|
|
|
__END__ |