line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::Interface; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
55876
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
831
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
72124
|
|
|
1
|
|
|
|
|
403
|
|
12
|
1
|
|
|
1
|
|
648
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
5150
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################## |
19
|
|
|
|
|
|
|
# Start Public Module |
20
|
|
|
|
|
|
|
################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _ifOID { |
23
|
0
|
|
|
0
|
|
0
|
return '1.3.6.1.2.1.2.2.1' |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub ifOIDs { |
27
|
2
|
|
|
2
|
1
|
14
|
return qw(Index Description Type MTU Speed PhysAddress AdminStatus OperStatus LastChange Duplex Name Alias) |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub ipOIDs { |
31
|
0
|
|
|
0
|
1
|
0
|
return qw(Addr NetMask) |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub ifMetricUserOIDs { |
35
|
0
|
|
|
0
|
1
|
0
|
return qw(Multicasts Broadcasts Octets Unicasts Discards Errors Unknowns) |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub ifMetricOIDs { |
39
|
1
|
|
|
1
|
1
|
8
|
return qw(InMulticasts OutMulticasts InBroadcasts OutBroadcasts InOctets OutOctets InUnicasts OutUnicasts InDiscards OutDiscards InErrors OutErrors InUnknowns) |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _ifMetricOIDVals { |
43
|
1
|
|
|
1
|
|
24
|
return qw(InOctets 10 OutOctets 16 InUnicasts 11 OutUnicasts 17 InDiscards 13 OutDiscards 19 InErrors 14 OutErrors 20 InUnknowns 15) |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub interface_getbyindex { |
47
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $uIfx; |
52
|
|
|
|
|
|
|
my %args; |
53
|
0
|
0
|
|
|
|
|
if (@_ == 1) { |
54
|
0
|
|
|
|
|
|
($uIfx) = @_; |
55
|
0
|
0
|
|
|
|
|
if ($uIfx !~ /^\d+$/) { |
56
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Invalid ifIndex `$uIfx'"; |
57
|
|
|
|
|
|
|
return undef |
58
|
0
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} else { |
60
|
0
|
|
|
|
|
|
%args = @_; |
61
|
0
|
|
|
|
|
|
for (keys(%args)) { |
62
|
0
|
0
|
0
|
|
|
|
if ((/^-?interface$/i) || (/^-?index$/i)) { |
63
|
0
|
0
|
|
|
|
|
if ($args{$_} =~ /^\d+$/) { |
64
|
0
|
|
|
|
|
|
$uIfx = $args{$_} |
65
|
|
|
|
|
|
|
} else { |
66
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Invalid ifIndex `$args{$_}'"; |
67
|
|
|
|
|
|
|
return undef |
68
|
0
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
0
|
0
|
|
|
|
|
if (!defined $uIfx) { |
73
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "No ifIndex provided"; |
74
|
|
|
|
|
|
|
return undef |
75
|
0
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
my $rIf = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.2'); |
77
|
0
|
0
|
|
|
|
|
if (!defined $rIf) { |
78
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface names from device"; |
79
|
|
|
|
|
|
|
return undef |
80
|
0
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
my $rIfx = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.1'); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
for (0..$#{$rIfx}) { |
|
0
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if ($rIfx->[$_] == $uIfx) { |
85
|
0
|
|
|
|
|
|
return $rIf->[$_] |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface for ifIndex `$uIfx'"; |
89
|
|
|
|
|
|
|
return undef |
90
|
0
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub interface_getbyname { |
93
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my %params = ( |
98
|
|
|
|
|
|
|
'index' => 0 |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my %args; |
102
|
0
|
0
|
|
|
|
|
if (@_ == 1) { |
103
|
0
|
|
|
|
|
|
($params{uIf}) = @_ |
104
|
|
|
|
|
|
|
} else { |
105
|
0
|
|
|
|
|
|
%args = @_; |
106
|
0
|
|
|
|
|
|
for (keys(%args)) { |
107
|
0
|
0
|
|
|
|
|
if (/^-?interface$/i) { |
|
|
0
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$params{uIf} = $args{$_} |
109
|
|
|
|
|
|
|
} elsif (/^-?index$/i) { |
110
|
0
|
0
|
|
|
|
|
if ($args{$_} == 1) { |
111
|
0
|
|
|
|
|
|
$params{index} = 1 |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
0
|
0
|
|
|
|
|
if (!exists($params{uIf})) { |
117
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "No interface provided"; |
118
|
|
|
|
|
|
|
return undef |
119
|
0
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $rIf = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.2'); |
122
|
0
|
0
|
|
|
|
|
if (!defined $rIf) { |
123
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface names from device"; |
124
|
|
|
|
|
|
|
return undef |
125
|
0
|
|
|
|
|
|
} |
126
|
0
|
|
|
|
|
|
my $rIfx = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.1'); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# user Provided |
129
|
|
|
|
|
|
|
# split Gig0/1 into 'Gig' '0/1' |
130
|
0
|
|
|
|
|
|
my @parts = split /([0-9])/, $params{uIf}, 2; |
131
|
0
|
|
|
|
|
|
my $uIfNamePart = shift @parts; |
132
|
0
|
|
|
|
|
|
my $uIfNumPart = "@parts"; |
133
|
0
|
|
|
|
|
|
$uIfNumPart =~ s/\s+//; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my @matches; |
136
|
|
|
|
|
|
|
my $idx; |
137
|
0
|
|
|
|
|
|
for (0..$#{$rIf}) { |
|
0
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# Real Names |
139
|
0
|
|
|
|
|
|
@parts = split /([0-9])/, $rIf->[$_], 2; |
140
|
0
|
|
|
|
|
|
my $rIfNamePart = shift @parts; |
141
|
0
|
|
|
|
|
|
my $rIfNumPart = "@parts"; |
142
|
0
|
|
|
|
|
|
$rIfNumPart =~ s/\s+//; |
143
|
0
|
0
|
0
|
|
|
|
if (($rIfNamePart =~ /^$uIfNamePart/i) && ($rIfNumPart eq $uIfNumPart)) { |
144
|
0
|
|
|
|
|
|
push @matches, $rIf->[$_]; |
145
|
0
|
|
|
|
|
|
$idx = $rIfx->[$_] |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
0
|
0
|
|
|
|
|
if (@matches == 1) { |
|
|
0
|
|
|
|
|
|
149
|
0
|
0
|
|
|
|
|
if ($params{index} == 0) { |
150
|
0
|
|
|
|
|
|
return "@matches" |
151
|
|
|
|
|
|
|
} else { |
152
|
0
|
|
|
|
|
|
return $idx |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} elsif (@matches == 0) { |
155
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot find interface `$params{uIf}'"; |
156
|
|
|
|
|
|
|
return undef |
157
|
0
|
|
|
|
|
|
} else { |
158
|
0
|
|
|
|
|
|
print "Interface `$params{uIf}' not specific enough - [@matches]"; |
159
|
|
|
|
|
|
|
return undef |
160
|
0
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub interface_info { |
164
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
165
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
my %params = ( |
170
|
|
|
|
|
|
|
'ifs' => [-1] |
171
|
|
|
|
|
|
|
); |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
my %args; |
174
|
0
|
0
|
|
|
|
|
if (@_ == 1) { |
175
|
0
|
|
|
|
|
|
($params{ifs}) = @_; |
176
|
0
|
0
|
|
|
|
|
if (!defined($params{ifs} = Cisco::SNMP::_get_range($params{ifs}))) { |
177
|
|
|
|
|
|
|
return undef |
178
|
0
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
} else { |
180
|
0
|
|
|
|
|
|
%args = @_; |
181
|
0
|
|
|
|
|
|
for (keys(%args)) { |
182
|
0
|
0
|
|
|
|
|
if (/^-?interface(?:s)?$/i) { |
183
|
0
|
0
|
|
|
|
|
if (!defined($params{ifs} = Cisco::SNMP::_get_range($args{$_}))) { |
184
|
|
|
|
|
|
|
return undef |
185
|
0
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
my %IfInfo; |
191
|
0
|
|
|
|
|
|
for my $ifs (@{$params{ifs}}) { |
|
0
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
my $interface; |
194
|
0
|
0
|
|
|
|
|
if ($ifs == -1) { |
195
|
0
|
|
|
|
|
|
$interface = '' |
196
|
|
|
|
|
|
|
} else { |
197
|
0
|
|
|
|
|
|
$interface = '.' . $ifs |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my %ret; |
201
|
0
|
|
|
|
|
|
my @IFKEYS = ifOIDs(); |
202
|
|
|
|
|
|
|
# -3 because last key (Duplex Name Alias) are different OID |
203
|
0
|
|
|
|
|
|
for my $oid (0..$#IFKEYS-3) { |
204
|
0
|
|
|
|
|
|
$ret{$IFKEYS[$oid]} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.' . ($oid+1) . $interface); |
205
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFKEYS[$oid]}) { |
206
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFKEYS[$oid]'"; |
207
|
|
|
|
|
|
|
return undef |
208
|
0
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
# Name Alias are different OID |
211
|
0
|
|
|
|
|
|
$ret{Name} = Cisco::SNMP::_snmpwalk($session, '.1.3.6.1.2.1.31.1.1.1.1' . $interface); |
212
|
0
|
|
|
|
|
|
$ret{Alias} = Cisco::SNMP::_snmpwalk($session, '.1.3.6.1.2.1.31.1.1.1.18' . $interface); |
213
|
|
|
|
|
|
|
# Duplex is different OID |
214
|
0
|
|
|
|
|
|
my $OIDS; |
215
|
0
|
|
|
|
|
|
($OIDS, $ret{$IFKEYS[9]}) = Cisco::SNMP::_snmpwalk($session, '1.3.6.1.2.1.10.7.2.1.19' . $interface); |
216
|
0
|
|
|
|
|
|
my %duplexIfs; |
217
|
0
|
|
|
|
|
|
for (0..$#{$OIDS}) { |
|
0
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# split the OID at dots |
219
|
0
|
|
|
|
|
|
my @if = split /\./, $OIDS->[$_]; |
220
|
|
|
|
|
|
|
# take the last value, which is the ifIndex equal to value returned |
221
|
0
|
|
|
|
|
|
$duplexIfs{$if[$#if]} = $ret{$IFKEYS[9]}->[$_] |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
my %UpDownStatus = ( |
225
|
|
|
|
|
|
|
1 => 'UP', |
226
|
|
|
|
|
|
|
2 => 'DOWN', |
227
|
|
|
|
|
|
|
3 => 'TEST', |
228
|
|
|
|
|
|
|
4 => 'UNKNOWN', |
229
|
|
|
|
|
|
|
5 => 'DORMANT', |
230
|
|
|
|
|
|
|
6 => 'NOTPRESENT', |
231
|
|
|
|
|
|
|
7 => 'LOWLAYERDOWN' |
232
|
|
|
|
|
|
|
); |
233
|
0
|
|
|
|
|
|
my %DuplexType = ( |
234
|
|
|
|
|
|
|
1 => 'UNKNOWN', |
235
|
|
|
|
|
|
|
2 => 'HALF', |
236
|
|
|
|
|
|
|
3 => 'FULL' |
237
|
|
|
|
|
|
|
); |
238
|
0
|
|
|
|
|
|
for my $idx (0..$#{$ret{$IFKEYS[0]}}) { |
|
0
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
my %IfInfoHash; |
240
|
0
|
|
|
|
|
|
for (0..$#IFKEYS) { |
241
|
0
|
0
|
0
|
|
|
|
if ($_ == 5) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
242
|
0
|
0
|
|
|
|
|
$IfInfoHash{$IFKEYS[$_]} = ($ret{$IFKEYS[$_]}->[$idx] =~ /^\0/) ? unpack('H12', $ret{$IFKEYS[$_]}->[$idx]) : (($ret{$IFKEYS[$_]}->[$idx] =~ /^0x/) ? substr($ret{$IFKEYS[$_]}->[$idx],2) : $ret{$IFKEYS[$_]}->[$idx]) |
|
|
0
|
|
|
|
|
|
243
|
|
|
|
|
|
|
} elsif (($_ == 6) || ($_ == 7)) { |
244
|
0
|
0
|
|
|
|
|
$IfInfoHash{$IFKEYS[$_]} = exists($UpDownStatus{$ret{$IFKEYS[$_]}->[$idx]}) ? $UpDownStatus{$ret{$IFKEYS[$_]}->[$idx]} : $ret{$IFKEYS[$_]}->[$idx] |
245
|
|
|
|
|
|
|
} elsif ($_ == 9) { |
246
|
|
|
|
|
|
|
# if $duplexIfs{ifIndex}, not necessarily the current array index |
247
|
0
|
0
|
|
|
|
|
if (exists $duplexIfs{$ret{$IFKEYS[0]}->[$idx]}) { |
248
|
0
|
0
|
|
|
|
|
$IfInfoHash{$IFKEYS[$_]} = exists($DuplexType{$duplexIfs{$ret{$IFKEYS[0]}->[$idx]}}) ? $DuplexType{$duplexIfs{$ret{$IFKEYS[0]}->[$idx]}} : $duplexIfs{$ret{$IFKEYS[0]}->[$idx]} |
249
|
|
|
|
|
|
|
} else { |
250
|
0
|
|
|
|
|
|
$IfInfoHash{$IFKEYS[$_]} = '' |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
} else { |
253
|
0
|
|
|
|
|
|
$IfInfoHash{$IFKEYS[$_]} = $ret{$IFKEYS[$_]}->[$idx] |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
} |
256
|
0
|
|
|
|
|
|
$IfInfo{$ret{$IFKEYS[0]}->[$idx]} = \%IfInfoHash |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
} |
259
|
0
|
|
|
|
|
|
return bless \%IfInfo, $class |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
for (ifOIDs()) { |
263
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_hash_1('if', $_) |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub interface_metrics { |
267
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
268
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
269
|
|
|
|
|
|
|
|
270
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
271
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
my %params = ( |
273
|
|
|
|
|
|
|
'ifs' => [-1], |
274
|
|
|
|
|
|
|
); |
275
|
|
|
|
|
|
|
# assume all metrics |
276
|
0
|
|
|
|
|
|
my @IFMETRICUSERKEYS = ifMetricUserOIDs(); |
277
|
0
|
|
|
|
|
|
for (@IFMETRICUSERKEYS) { |
278
|
0
|
|
|
|
|
|
$params{$_} = 1 |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
0
|
|
|
|
|
|
my %args; |
282
|
0
|
0
|
|
|
|
|
if (@_ == 1) { |
283
|
0
|
|
|
|
|
|
($params{ifs}) = @_; |
284
|
0
|
0
|
|
|
|
|
if (!defined($params{ifs} = Cisco::SNMP::_get_range($params{ifs}))) { |
285
|
|
|
|
|
|
|
return undef |
286
|
0
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
} else { |
288
|
0
|
|
|
|
|
|
%args = @_; |
289
|
0
|
|
|
|
|
|
for (keys(%args)) { |
290
|
0
|
0
|
|
|
|
|
if (/^-?interface(?:s)?$/i) { |
|
|
0
|
|
|
|
|
|
291
|
0
|
0
|
|
|
|
|
if (!defined($params{ifs} = Cisco::SNMP::_get_range($args{$_}))) { |
292
|
|
|
|
|
|
|
return undef |
293
|
0
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
} elsif (/^-?metric(?:s)?$/i) { |
295
|
|
|
|
|
|
|
# metrics provided - only use provided |
296
|
0
|
|
|
|
|
|
for (@IFMETRICUSERKEYS) { |
297
|
0
|
|
|
|
|
|
$params{$_} = 0 |
298
|
|
|
|
|
|
|
} |
299
|
0
|
0
|
|
|
|
|
if (ref($args{$_}) eq 'ARRAY') { |
300
|
0
|
|
|
|
|
|
$params{oids} = ''; |
301
|
0
|
|
|
|
|
|
for my $mets (@{$args{$_}}) { |
|
0
|
|
|
|
|
|
|
302
|
0
|
0
|
|
|
|
|
if (exists($params{ucfirst(lc($mets))})) { |
303
|
0
|
|
|
|
|
|
$params{ucfirst(lc($mets))} = 1 |
304
|
|
|
|
|
|
|
} else { |
305
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Invalid metric `$mets'"; |
306
|
|
|
|
|
|
|
return undef |
307
|
0
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
} else { |
310
|
0
|
|
|
|
|
|
$params{oids} = ''; |
311
|
0
|
0
|
|
|
|
|
if (exists($params{ucfirst(lc($args{$_}))})) { |
312
|
0
|
|
|
|
|
|
$params{ucfirst(lc($args{$_}))} = 1 |
313
|
|
|
|
|
|
|
} else { |
314
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Invalid metric `$args{$_}'"; |
315
|
|
|
|
|
|
|
return undef |
316
|
0
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
0
|
|
|
|
|
|
my %IfMetric; |
323
|
0
|
|
|
|
|
|
my @IFMETRICKEYS = ifMetricOIDs(); |
324
|
0
|
|
|
|
|
|
for my $ifs (@{$params{ifs}}) { |
|
0
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
|
326
|
0
|
|
|
|
|
|
my $interface; |
327
|
0
|
0
|
|
|
|
|
if ($ifs == -1) { |
328
|
0
|
|
|
|
|
|
$interface = '' |
329
|
|
|
|
|
|
|
} else { |
330
|
0
|
|
|
|
|
|
$interface = '.' . $ifs |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
|
333
|
0
|
|
|
|
|
|
my %ret; |
334
|
0
|
|
|
|
|
|
$ret{Index} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.1' . $interface); |
335
|
0
|
0
|
|
|
|
|
if (!defined $ret{Index}) { |
336
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get ifIndex `$interface'"; |
337
|
|
|
|
|
|
|
return undef |
338
|
0
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
# multicasts |
340
|
0
|
0
|
|
|
|
|
if ($params{$IFMETRICUSERKEYS[0]}) { |
341
|
|
|
|
|
|
|
# In |
342
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[0]} = Cisco::SNMP::_snmpwalk($session, '1.3.6.1.2.1.31.1.1.1.2' . $interface); |
343
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[0]}) { |
344
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[0]'"; |
345
|
|
|
|
|
|
|
return undef |
346
|
0
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
# Out |
348
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[1]} = Cisco::SNMP::_snmpwalk($session, '1.3.6.1.2.1.31.1.1.1.4' . $interface); |
349
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[1]}) { |
350
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[1]'"; |
351
|
|
|
|
|
|
|
return undef |
352
|
0
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
# broadcasts |
355
|
0
|
0
|
|
|
|
|
if ($params{$IFMETRICUSERKEYS[1]}) { |
356
|
|
|
|
|
|
|
# In |
357
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[2]} = Cisco::SNMP::_snmpwalk($session, '1.3.6.1.2.1.31.1.1.1.3' . $interface); |
358
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[2]}) { |
359
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[2]'"; |
360
|
|
|
|
|
|
|
return undef |
361
|
0
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
# Out |
363
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[3]} = Cisco::SNMP::_snmpwalk($session, '1.3.6.1.2.1.31.1.1.1.5' . $interface); |
364
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[3]}) { |
365
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[3]'"; |
366
|
|
|
|
|
|
|
return undef |
367
|
0
|
|
|
|
|
|
} |
368
|
|
|
|
|
|
|
} |
369
|
|
|
|
|
|
|
# octets |
370
|
0
|
0
|
|
|
|
|
if ($params{$IFMETRICUSERKEYS[2]}) { |
371
|
|
|
|
|
|
|
# In |
372
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[4]} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.10' . $interface); |
373
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[4]}) { |
374
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[4]'"; |
375
|
|
|
|
|
|
|
return undef |
376
|
0
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
# Out |
378
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[5]} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.16' . $interface); |
379
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[5]}) { |
380
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[5]'"; |
381
|
|
|
|
|
|
|
return undef |
382
|
0
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
# unicasts |
385
|
0
|
0
|
|
|
|
|
if ($params{$IFMETRICUSERKEYS[3]}) { |
386
|
|
|
|
|
|
|
# In |
387
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[6]} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.11' . $interface); |
388
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[6]}) { |
389
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[6]'"; |
390
|
|
|
|
|
|
|
return undef |
391
|
0
|
|
|
|
|
|
} |
392
|
|
|
|
|
|
|
# Out |
393
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[7]} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.17' . $interface); |
394
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[7]}) { |
395
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[7]'"; |
396
|
|
|
|
|
|
|
return undef |
397
|
0
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
# discards |
400
|
0
|
0
|
|
|
|
|
if ($params{$IFMETRICUSERKEYS[4]}) { |
401
|
|
|
|
|
|
|
# In |
402
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[8]} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.13' . $interface); |
403
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[8]}) { |
404
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[8]'"; |
405
|
|
|
|
|
|
|
return undef |
406
|
0
|
|
|
|
|
|
} |
407
|
|
|
|
|
|
|
# Out |
408
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[9]} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.19' . $interface); |
409
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[9]}) { |
410
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[9]'"; |
411
|
|
|
|
|
|
|
return undef |
412
|
0
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
# errors |
415
|
0
|
0
|
|
|
|
|
if ($params{$IFMETRICUSERKEYS[5]}) { |
416
|
|
|
|
|
|
|
# In |
417
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[10]} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.14' . $interface); |
418
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[10]}) { |
419
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[10]'"; |
420
|
|
|
|
|
|
|
return undef |
421
|
0
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
# Out |
423
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[11]} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.20' . $interface); |
424
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[11]}) { |
425
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[11]'"; |
426
|
|
|
|
|
|
|
return undef |
427
|
0
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
# unknowns |
430
|
0
|
0
|
|
|
|
|
if ($params{$IFMETRICUSERKEYS[6]}) { |
431
|
|
|
|
|
|
|
# In |
432
|
0
|
|
|
|
|
|
$ret{$IFMETRICKEYS[12]} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.15' . $interface); |
433
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IFMETRICKEYS[12]}) { |
434
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interface `$interface' `$IFMETRICKEYS[12]'"; |
435
|
|
|
|
|
|
|
return undef |
436
|
0
|
|
|
|
|
|
} |
437
|
|
|
|
|
|
|
} |
438
|
|
|
|
|
|
|
|
439
|
0
|
|
|
|
|
|
for my $idx (0..$#{$ret{Index}}) { |
|
0
|
|
|
|
|
|
|
440
|
0
|
|
|
|
|
|
my %IfMetricHash; |
441
|
0
|
|
|
|
|
|
for (0..$#IFMETRICKEYS) { |
442
|
0
|
|
|
|
|
|
$IfMetricHash{$IFMETRICKEYS[$_]} = $ret{$IFMETRICKEYS[$_]}->[$idx] |
443
|
|
|
|
|
|
|
} |
444
|
0
|
|
|
|
|
|
$IfMetric{$ret{Index}->[$idx]} = \%IfMetricHash |
445
|
|
|
|
|
|
|
} |
446
|
|
|
|
|
|
|
} |
447
|
0
|
|
|
|
|
|
return bless \%IfMetric, $class |
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
for (ifMetricOIDs()) { |
451
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_hash_1('if', $_) |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
sub interface_utilization { |
455
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
456
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
457
|
|
|
|
|
|
|
|
458
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
459
|
|
|
|
|
|
|
|
460
|
0
|
|
|
|
|
|
my %params = ( |
461
|
|
|
|
|
|
|
'polling' => 10 |
462
|
|
|
|
|
|
|
); |
463
|
|
|
|
|
|
|
|
464
|
0
|
|
|
|
|
|
my %args; |
465
|
0
|
0
|
|
|
|
|
if (@_ != 1) { |
466
|
0
|
|
|
|
|
|
%args = @_; |
467
|
0
|
|
|
|
|
|
for (keys(%args)) { |
468
|
0
|
0
|
0
|
|
|
|
if ((/^-?polling$/i) || (/^-?interval$/i)) { |
|
|
0
|
|
|
|
|
|
469
|
0
|
0
|
0
|
|
|
|
if (($args{$_} =~ /^\d+$/) && ($args{$_} > 0)) { |
470
|
0
|
|
|
|
|
|
$params{polling} = $args{$_} |
471
|
|
|
|
|
|
|
} else { |
472
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Invalid polling interval `$args{$_}'"; |
473
|
|
|
|
|
|
|
return undef |
474
|
0
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
} elsif (/^-?recursive$/i) { |
476
|
0
|
|
|
|
|
|
$params{recur} = $args{$_} |
477
|
|
|
|
|
|
|
} |
478
|
|
|
|
|
|
|
} |
479
|
|
|
|
|
|
|
} |
480
|
|
|
|
|
|
|
|
481
|
0
|
|
|
|
|
|
my $prev; |
482
|
0
|
0
|
0
|
|
|
|
if (exists($params{recur}) && (ref($params{recur}) eq __PACKAGE__)) { |
483
|
|
|
|
|
|
|
$prev = $params{recur} |
484
|
0
|
|
|
|
|
|
} else { |
485
|
0
|
0
|
|
|
|
|
if (!defined($prev = $self->interface_metrics(@_))) { |
486
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get initial utilization: " . $Cisco::SNMP::LASTERROR; |
487
|
|
|
|
|
|
|
return undef |
488
|
0
|
|
|
|
|
|
} |
489
|
|
|
|
|
|
|
} |
490
|
0
|
|
|
|
|
|
sleep $params{polling}; |
491
|
0
|
|
|
|
|
|
my $curr; |
492
|
0
|
0
|
|
|
|
|
if (!defined($curr = $self->interface_metrics(@_))) { |
493
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get current utilization: " . $Cisco::SNMP::LASTERROR; |
494
|
|
|
|
|
|
|
return undef |
495
|
0
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
|
|
497
|
0
|
|
|
|
|
|
my %IfUtil; |
498
|
0
|
|
|
|
|
|
my @IFMETRICKEYS = ifMetricOIDs(); |
499
|
0
|
|
|
|
|
|
for my $ifs (sort {$a <=> $b} (keys(%{$prev}))) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
500
|
0
|
|
|
|
|
|
my %IfUtilHash; |
501
|
0
|
|
|
|
|
|
for (0..$#IFMETRICKEYS) { |
502
|
0
|
0
|
0
|
|
|
|
if (($_ == 4) || ($_ == 5)) { |
503
|
0
|
0
|
|
|
|
|
$IfUtilHash{$IFMETRICKEYS[$_]} = defined($curr->{$ifs}->{$IFMETRICKEYS[$_]}) ? (($curr->{$ifs}->{$IFMETRICKEYS[$_]} - $prev->{$ifs}->{$IFMETRICKEYS[$_]}) * 8) / $params{polling} : undef; |
504
|
|
|
|
|
|
|
} else { |
505
|
0
|
0
|
|
|
|
|
$IfUtilHash{$IFMETRICKEYS[$_]} = defined($curr->{$ifs}->{$IFMETRICKEYS[$_]}) ? ($curr->{$ifs}->{$IFMETRICKEYS[$_]} - $prev->{$ifs}->{$IFMETRICKEYS[$_]}) / $params{polling} : undef; |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
} |
508
|
0
|
|
|
|
|
|
$IfUtil{$ifs} = \%IfUtilHash |
509
|
|
|
|
|
|
|
} |
510
|
0
|
|
|
|
|
|
$prev = bless \%IfUtil, $class; |
511
|
0
|
0
|
|
|
|
|
return wantarray ? ($prev, $curr) : $prev |
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
sub interface_updown { |
515
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
516
|
|
|
|
|
|
|
|
517
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
518
|
|
|
|
|
|
|
|
519
|
0
|
|
|
|
|
|
my %op = ( |
520
|
|
|
|
|
|
|
'UP' => 1, |
521
|
|
|
|
|
|
|
'DOWN' => 2 |
522
|
|
|
|
|
|
|
); |
523
|
|
|
|
|
|
|
my %params = ( |
524
|
|
|
|
|
|
|
'oper' => $op{UP} |
525
|
0
|
|
|
|
|
|
); |
526
|
|
|
|
|
|
|
|
527
|
0
|
|
|
|
|
|
my %args; |
528
|
0
|
|
|
|
|
|
my $oper = 'UP'; |
529
|
0
|
0
|
|
|
|
|
if (@_ == 1) { |
530
|
0
|
|
|
|
|
|
($params{ifs}) = @_; |
531
|
0
|
0
|
|
|
|
|
if (!defined($params{ifs} = Cisco::SNMP::_get_range($params{ifs}))) { |
532
|
|
|
|
|
|
|
return undef |
533
|
0
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
} else { |
535
|
0
|
|
|
|
|
|
%args = @_; |
536
|
0
|
|
|
|
|
|
for (keys(%args)) { |
537
|
0
|
0
|
0
|
|
|
|
if (/^-?interface(?:s)?$/i) { |
|
|
0
|
|
|
|
|
|
538
|
0
|
0
|
|
|
|
|
if (!defined($params{ifs} = Cisco::SNMP::_get_range($args{$_}))) { |
539
|
|
|
|
|
|
|
return undef |
540
|
0
|
|
|
|
|
|
} |
541
|
|
|
|
|
|
|
} elsif ((/^-?operation$/i) || (/^-?command$/i)) { |
542
|
0
|
0
|
|
|
|
|
if (exists($op{uc($args{$_})})) { |
543
|
0
|
|
|
|
|
|
$params{oper} = $op{uc($args{$_})}; |
544
|
0
|
|
|
|
|
|
$oper = uc($args{$_}) |
545
|
|
|
|
|
|
|
} else { |
546
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Invalid operation `$args{$_}'"; |
547
|
|
|
|
|
|
|
return undef |
548
|
0
|
|
|
|
|
|
} |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
} |
551
|
|
|
|
|
|
|
} |
552
|
|
|
|
|
|
|
|
553
|
0
|
0
|
|
|
|
|
if (!defined $params{ifs}) { |
554
|
0
|
|
|
|
|
|
$params{ifs} = Cisco::SNMP::_snmpwalk($session, _ifOID() . '.1'); |
555
|
0
|
0
|
|
|
|
|
if (!defined $params{ifs}) { |
556
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get interfaces to $oper"; |
557
|
|
|
|
|
|
|
return undef |
558
|
0
|
|
|
|
|
|
} |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
|
561
|
0
|
|
|
|
|
|
my @intf; |
562
|
0
|
|
|
|
|
|
for (@{$params{ifs}}) { |
|
0
|
|
|
|
|
|
|
563
|
0
|
0
|
|
|
|
|
if (defined $session->set_request(_ifOID() . '.7.' . $_, INTEGER, $params{oper})) { |
564
|
0
|
|
|
|
|
|
push @intf, $_ |
565
|
|
|
|
|
|
|
} else { |
566
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Failed to $oper interface $_"; |
567
|
|
|
|
|
|
|
return undef |
568
|
0
|
|
|
|
|
|
} |
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
return \@intf |
571
|
0
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
|
573
|
1
|
|
|
1
|
|
20
|
no strict 'refs'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
833
|
|
574
|
|
|
|
|
|
|
# get_ direct |
575
|
|
|
|
|
|
|
my @OIDS = ifOIDs(); |
576
|
|
|
|
|
|
|
# -3 because last keys (Duplex Name Alias) are different OID |
577
|
|
|
|
|
|
|
for my $o (0..$#OIDS-3) { |
578
|
|
|
|
|
|
|
*{"get_if" . $OIDS[$o]} = sub { |
579
|
0
|
|
|
0
|
|
|
my $self = shift; |
580
|
0
|
|
|
|
|
|
my ($val) = @_; |
581
|
|
|
|
|
|
|
|
582
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = 0 } |
|
0
|
|
|
|
|
|
|
583
|
0
|
|
|
|
|
|
my $s = $self->session; |
584
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
585
|
|
|
|
|
|
|
varbindlist => [_ifOID() . '.' . ($o+1) . '.' . $val] |
586
|
|
|
|
|
|
|
); |
587
|
0
|
|
|
|
|
|
return $r->{_ifOID() . '.' . ($o+1) . '.' . $val} |
588
|
|
|
|
|
|
|
} |
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
sub get_ifDuplex { |
592
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
593
|
0
|
|
|
|
|
|
my ($val) = @_; |
594
|
|
|
|
|
|
|
|
595
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = 0 } |
|
0
|
|
|
|
|
|
|
596
|
0
|
|
|
|
|
|
my $s = $self->session; |
597
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
598
|
|
|
|
|
|
|
varbindlist => ['1.3.6.1.2.1.10.7.2.1.19.' . $val] |
599
|
|
|
|
|
|
|
); |
600
|
0
|
|
|
|
|
|
return $r->{'1.3.6.1.2.1.10.7.2.1.19.' . $val} |
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
sub get_ifName { |
604
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
605
|
0
|
|
|
|
|
|
my ($val) = @_; |
606
|
|
|
|
|
|
|
|
607
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = 0 } |
|
0
|
|
|
|
|
|
|
608
|
0
|
|
|
|
|
|
my $s = $self->session; |
609
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
610
|
|
|
|
|
|
|
varbindlist => ['1.3.6.1.2.1.31.1.1.1.1.' . $val] |
611
|
|
|
|
|
|
|
); |
612
|
0
|
|
|
|
|
|
return $r->{'1.3.6.1.2.1.31.1.1.1.1.' . $val} |
613
|
|
|
|
|
|
|
} |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
sub get_ifAlias { |
616
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
617
|
0
|
|
|
|
|
|
my ($val) = @_; |
618
|
|
|
|
|
|
|
|
619
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = 0 } |
|
0
|
|
|
|
|
|
|
620
|
0
|
|
|
|
|
|
my $s = $self->session; |
621
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
622
|
|
|
|
|
|
|
varbindlist => ['1.3.6.1.2.1.31.1.1.1.18.' . $val] |
623
|
|
|
|
|
|
|
); |
624
|
0
|
|
|
|
|
|
return $r->{'1.3.6.1.2.1.31.1.1.1.18.' . $val} |
625
|
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
my %OIDS = _ifMetricOIDVals(); |
628
|
|
|
|
|
|
|
for my $o (keys(%OIDS)) { |
629
|
|
|
|
|
|
|
*{"get_if" . $o} = sub { |
630
|
0
|
|
|
0
|
|
|
my $self = shift; |
631
|
0
|
|
|
|
|
|
my ($val) = @_; |
632
|
|
|
|
|
|
|
|
633
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = 0 } |
|
0
|
|
|
|
|
|
|
634
|
0
|
|
|
|
|
|
my $s = $self->session; |
635
|
|
|
|
|
|
|
my $r = $s->get_request( |
636
|
0
|
|
|
|
|
|
varbindlist => [_ifOID() . '.' . $OIDS{$o} . '.' . $val] |
637
|
|
|
|
|
|
|
); |
638
|
0
|
|
|
|
|
|
return $r->{_ifOID() . '.' . $OIDS{$o} . '.' . $val} |
639
|
|
|
|
|
|
|
} |
640
|
|
|
|
|
|
|
} |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
@OIDS = qw(InMulticasts InBroadcasts OutMulticasts OutBroadcasts); |
643
|
|
|
|
|
|
|
for my $o (0..3) { |
644
|
|
|
|
|
|
|
*{"get_if" . $OIDS[$o]} = sub { |
645
|
0
|
|
|
0
|
|
|
my $self = shift; |
646
|
0
|
|
|
|
|
|
my ($val) = @_; |
647
|
|
|
|
|
|
|
|
648
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = 0 } |
|
0
|
|
|
|
|
|
|
649
|
0
|
|
|
|
|
|
my $s = $self->session; |
650
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
651
|
|
|
|
|
|
|
varbindlist => ['1.3.6.1.2.1.31.1.1.1.' . ($o+2) . '.' . $val] |
652
|
|
|
|
|
|
|
); |
653
|
0
|
|
|
|
|
|
return $r->{'1.3.6.1.2.1.31.1.1.1.' . ($o+2) . '.' . $val} |
654
|
|
|
|
|
|
|
} |
655
|
|
|
|
|
|
|
} |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
################################################## |
658
|
|
|
|
|
|
|
# End Public Module |
659
|
|
|
|
|
|
|
################################################## |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
1; |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
__END__ |