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