line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::Line; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
24963
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
60
|
|
9
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
53
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1574
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
119826
|
|
|
1
|
|
|
|
|
461
|
|
12
|
1
|
|
|
1
|
|
898
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
3085
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################## |
19
|
|
|
|
|
|
|
# Start Public Module |
20
|
|
|
|
|
|
|
################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _trmsrvOID { |
23
|
0
|
|
|
0
|
|
0
|
return '1.3.6.1.4.1.9.2.9' |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _lineOID { |
27
|
0
|
|
|
0
|
|
0
|
return _trmsrvOID . '.2.1' |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub lineOIDs { |
31
|
2
|
|
|
2
|
1
|
22
|
return qw(Active Type Autobaud SpeedIn SpeedOut Flow Modem Location Term ScrLen ScrWid Esc Tmo Sestmo Rotary Uses Nses User Noise Number TimeActive) |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _sessOID { |
35
|
0
|
|
|
0
|
|
0
|
return _trmsrvOID . '.3.1' |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub sessOIDs { |
39
|
2
|
|
|
2
|
1
|
17
|
return qw(Type Direction Address Name Current Idle Line) |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub line_clear { |
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my %params; |
48
|
|
|
|
|
|
|
my %args; |
49
|
0
|
0
|
|
|
|
|
if (@_ == 1) { |
50
|
0
|
|
|
|
|
|
($params{lines}) = @_; |
51
|
0
|
0
|
|
|
|
|
if (!defined($params{lines} = Cisco::SNMP::_get_range($params{lines}))) { |
52
|
|
|
|
|
|
|
return undef |
53
|
0
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} else { |
55
|
0
|
|
|
|
|
|
%args = @_; |
56
|
0
|
|
|
|
|
|
for (keys(%args)) { |
57
|
0
|
0
|
0
|
|
|
|
if ((/^-?range$/i) || (/^-?line(?:s)?$/i)) { |
58
|
0
|
0
|
|
|
|
|
if (!defined($params{lines} = Cisco::SNMP::_get_range($args{$_}))) { |
59
|
|
|
|
|
|
|
return undef |
60
|
0
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if (!defined $params{lines}) { |
66
|
0
|
|
|
|
|
|
$params{lines} = Cisco::SNMP::_snmpwalk($session, _lineOID() . '.20'); |
67
|
0
|
0
|
|
|
|
|
if (!defined $params{lines}) { |
68
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get lines to clear"; |
69
|
|
|
|
|
|
|
return undef |
70
|
0
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my @lines; |
74
|
0
|
|
|
|
|
|
for (@{$params{lines}}) { |
|
0
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if (defined $session->set_request(_trmsrvOID . '.10.0', INTEGER, $_)) { |
76
|
0
|
|
|
|
|
|
push @lines, $_ |
77
|
|
|
|
|
|
|
} else { |
78
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Failed to clear line $_"; |
79
|
|
|
|
|
|
|
return undef |
80
|
0
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
return \@lines |
83
|
0
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub line_info { |
86
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
87
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my %ret; |
92
|
0
|
|
|
|
|
|
my @LINEKEYS = lineOIDs(); |
93
|
0
|
|
|
|
|
|
for my $oid (0..$#LINEKEYS) { |
94
|
0
|
|
|
|
|
|
$ret{$LINEKEYS[$oid]} = Cisco::SNMP::_snmpwalk($session, _lineOID() . '.' . ($oid+1)); |
95
|
0
|
0
|
|
|
|
|
if (!defined $ret{$LINEKEYS[$oid]}) { |
96
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get line `$LINEKEYS[$oid]' info"; |
97
|
|
|
|
|
|
|
return undef |
98
|
0
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my %LineTypes = ( |
102
|
|
|
|
|
|
|
2 => 'CON', |
103
|
|
|
|
|
|
|
3 => 'TRM', |
104
|
|
|
|
|
|
|
4 => 'LNP', |
105
|
|
|
|
|
|
|
5 => 'VTY', |
106
|
|
|
|
|
|
|
6 => 'AUX' |
107
|
|
|
|
|
|
|
); |
108
|
0
|
|
|
|
|
|
my %LineModem = ( |
109
|
|
|
|
|
|
|
2 => 'none', |
110
|
|
|
|
|
|
|
3 => 'callin', |
111
|
|
|
|
|
|
|
4 => 'callout', |
112
|
|
|
|
|
|
|
5 => 'cts-reqd', |
113
|
|
|
|
|
|
|
6 => 'ri-is-cd', |
114
|
|
|
|
|
|
|
7 => 'inout' |
115
|
|
|
|
|
|
|
); |
116
|
0
|
|
|
|
|
|
my %LineFlow = ( |
117
|
|
|
|
|
|
|
2 => 'none', |
118
|
|
|
|
|
|
|
3 => 'sw-in', |
119
|
|
|
|
|
|
|
4 => 'sw-out', |
120
|
|
|
|
|
|
|
5 => 'sw-both', |
121
|
|
|
|
|
|
|
6 => 'hw-in', |
122
|
|
|
|
|
|
|
7 => 'hw-out', |
123
|
|
|
|
|
|
|
8 => 'hw-both' |
124
|
|
|
|
|
|
|
); |
125
|
0
|
|
|
|
|
|
my %LineInfo; |
126
|
0
|
|
|
|
|
|
for my $lines (0..$#{$ret{$LINEKEYS[19]}}) { |
|
0
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my %LineInfoHash; |
128
|
0
|
|
|
|
|
|
for (0..$#LINEKEYS) { |
129
|
0
|
0
|
|
|
|
|
if ($_ == 1) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
$LineInfoHash{$LINEKEYS[$_]} = exists $LineTypes{$ret{$LINEKEYS[$_]}->[$lines]} ? $LineTypes{$ret{$LINEKEYS[$_]}->[$lines]} : $ret{$LINEKEYS[$_]}->[$lines] |
131
|
|
|
|
|
|
|
} elsif ($_ == 5) { |
132
|
0
|
0
|
|
|
|
|
$LineInfoHash{$LINEKEYS[$_]} = exists $LineFlow{$ret{$LINEKEYS[$_]}->[$lines]} ? $LineFlow{$ret{$LINEKEYS[$_]}->[$lines]} : $ret{$LINEKEYS[$_]}->[$lines] |
133
|
|
|
|
|
|
|
} elsif ($_ == 6) { |
134
|
0
|
0
|
|
|
|
|
$LineInfoHash{$LINEKEYS[$_]} = exists $LineModem{$ret{$LINEKEYS[$_]}->[$lines]} ? $LineModem{$ret{$LINEKEYS[$_]}->[$lines]} : $ret{$LINEKEYS[$_]}->[$lines] |
135
|
|
|
|
|
|
|
} else { |
136
|
0
|
|
|
|
|
|
$LineInfoHash{$LINEKEYS[$_]} = $ret{$LINEKEYS[$_]}->[$lines] |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
0
|
|
|
|
|
|
$LineInfo{$ret{$LINEKEYS[19]}->[$lines]} = \%LineInfoHash |
140
|
|
|
|
|
|
|
} |
141
|
0
|
|
|
|
|
|
return bless \%LineInfo, $class |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
for (lineOIDs()) { |
145
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_hash_1('line', $_) |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub line_sessions { |
149
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
150
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my %ret; |
155
|
0
|
|
|
|
|
|
my @SESSIONKEYS = sessOIDs(); |
156
|
0
|
|
|
|
|
|
for my $oid (0..$#SESSIONKEYS) { |
157
|
0
|
|
|
|
|
|
$ret{$SESSIONKEYS[$oid]} = Cisco::SNMP::_snmpwalk($session, _sessOID() . '.' . ($oid+1)); |
158
|
0
|
0
|
|
|
|
|
if (!defined $ret{$SESSIONKEYS[$oid]}) { |
159
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get session `$SESSIONKEYS[$oid]' info"; |
160
|
|
|
|
|
|
|
return undef |
161
|
0
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my %SessionTypes = ( |
165
|
|
|
|
|
|
|
1 => 'unknown', |
166
|
|
|
|
|
|
|
2 => 'PAD', |
167
|
|
|
|
|
|
|
3 => 'stream', |
168
|
|
|
|
|
|
|
4 => 'rlogin', |
169
|
|
|
|
|
|
|
5 => 'telnet', |
170
|
|
|
|
|
|
|
6 => 'TCP', |
171
|
|
|
|
|
|
|
7 => 'LAT', |
172
|
|
|
|
|
|
|
8 => 'MOP', |
173
|
|
|
|
|
|
|
9 => 'SLIP', |
174
|
|
|
|
|
|
|
10 => 'XRemote', |
175
|
|
|
|
|
|
|
11 => 'rshell' |
176
|
|
|
|
|
|
|
); |
177
|
0
|
|
|
|
|
|
my %SessionDir = ( |
178
|
|
|
|
|
|
|
1 => 'unknown', |
179
|
|
|
|
|
|
|
2 => 'IN', |
180
|
|
|
|
|
|
|
3 => 'OUT' |
181
|
|
|
|
|
|
|
); |
182
|
0
|
|
|
|
|
|
my %SessionInfo; |
183
|
0
|
|
|
|
|
|
for my $sess (0..$#{$ret{$SESSIONKEYS[6]}}) { |
|
0
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
my %SessionInfoHash; |
185
|
0
|
|
|
|
|
|
for (0..$#SESSIONKEYS) { |
186
|
0
|
0
|
|
|
|
|
if ($_ == 0) { |
|
|
0
|
|
|
|
|
|
187
|
0
|
0
|
|
|
|
|
$SessionInfoHash{$SESSIONKEYS[$_]} = exists($SessionTypes{$ret{$SESSIONKEYS[$_]}->[$sess]}) ? $SessionTypes{$ret{$SESSIONKEYS[$_]}->[$sess]} : $ret{$SESSIONKEYS[$_]}->[$sess] |
188
|
|
|
|
|
|
|
} elsif ($_ == 1) { |
189
|
0
|
0
|
|
|
|
|
$SessionInfoHash{$SESSIONKEYS[$_]} = exists($SessionDir{$ret{$SESSIONKEYS[$_]}->[$sess]}) ? $SessionDir{$ret{$SESSIONKEYS[$_]}->[$sess]} : $ret{$SESSIONKEYS[$_]}->[$sess] |
190
|
|
|
|
|
|
|
} else { |
191
|
0
|
|
|
|
|
|
$SessionInfoHash{$SESSIONKEYS[$_]} = $ret{$SESSIONKEYS[$_]}->[$sess] |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
0
|
|
|
|
|
|
push @{$SessionInfo{$ret{$SESSIONKEYS[6]}->[$sess]}}, \%SessionInfoHash |
|
0
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
} |
196
|
0
|
|
|
|
|
|
return bless \%SessionInfo, $class |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
for (sessOIDs()) { |
200
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_hash_2('line', 'sess', $_) |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub line_message { |
204
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
207
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
my %params = ( |
209
|
|
|
|
|
|
|
message => 'Test Message.', |
210
|
|
|
|
|
|
|
lines => [-1] |
211
|
|
|
|
|
|
|
); |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
my %args; |
214
|
0
|
0
|
|
|
|
|
if (@_ == 1) { |
215
|
0
|
|
|
|
|
|
($params{message}) = @_ |
216
|
|
|
|
|
|
|
} else { |
217
|
0
|
|
|
|
|
|
%args = @_; |
218
|
0
|
|
|
|
|
|
for (keys(%args)) { |
219
|
0
|
0
|
|
|
|
|
if (/^-?message$/i) { |
|
|
0
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
$params{message} = $args{$_} |
221
|
|
|
|
|
|
|
} elsif (/^-?line(?:s)?$/i) { |
222
|
0
|
0
|
|
|
|
|
if (!defined($params{lines} = Cisco::SNMP::_get_range($args{$_}))) { |
223
|
|
|
|
|
|
|
return undef |
224
|
0
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
my $response; |
230
|
|
|
|
|
|
|
my @lines; |
231
|
0
|
|
|
|
|
|
for (@{$params{lines}}) { |
|
0
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# Lines |
233
|
0
|
|
|
|
|
|
my $response = $session->set_request(_trmsrvOID() . '.4.0', INTEGER, $_); |
234
|
|
|
|
|
|
|
# Interval (reissue) |
235
|
0
|
|
|
|
|
|
$response = $session->set_request(_trmsrvOID() . '.5.0', INTEGER, 0); |
236
|
|
|
|
|
|
|
# Duration |
237
|
0
|
|
|
|
|
|
$response = $session->set_request(_trmsrvOID() . '.6.0', INTEGER, 0); |
238
|
|
|
|
|
|
|
# Text (256 chars) |
239
|
0
|
|
|
|
|
|
$response = $session->set_request(_trmsrvOID() . '.7.0', OCTET_STRING, $params{message}); |
240
|
|
|
|
|
|
|
# Temp Banner (1=no 2=append) |
241
|
0
|
|
|
|
|
|
$response = $session->set_request(_trmsrvOID() . '.8.0', INTEGER, 1); |
242
|
|
|
|
|
|
|
# Send |
243
|
0
|
|
|
|
|
|
$response = $session->set_request(_trmsrvOID() . '.9.0', INTEGER, 1); |
244
|
0
|
0
|
|
|
|
|
if (defined $response) { |
245
|
0
|
|
|
|
|
|
push @lines, $_ |
246
|
|
|
|
|
|
|
} else { |
247
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Failed to send message to line $_"; |
248
|
|
|
|
|
|
|
return undef |
249
|
0
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
# clear message |
252
|
0
|
|
|
|
|
|
$session->set_request(_trmsrvOID() . '.7.0', OCTET_STRING, ""); |
253
|
0
|
0
|
|
|
|
|
if ($lines[0] == -1) { $lines[0] = "ALL" } |
|
0
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
return \@lines |
255
|
0
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub line_numberof { |
258
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
259
|
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
261
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
|
my $response; |
263
|
0
|
0
|
|
|
|
|
if (!defined($response = $session->get_request( -varbindlist => [_trmsrvOID . '.1.0'] ))) { |
264
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get number of lines"; |
265
|
|
|
|
|
|
|
return undef |
266
|
0
|
|
|
|
|
|
} else { |
267
|
0
|
|
|
|
|
|
return $response->{_trmsrvOID() . '.1.0'} |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
1
|
|
|
1
|
|
13
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
609
|
|
272
|
|
|
|
|
|
|
# get_ direct |
273
|
|
|
|
|
|
|
my @OIDS = lineOIDs(); |
274
|
|
|
|
|
|
|
for my $o (0..$#OIDS) { |
275
|
|
|
|
|
|
|
*{"get_line" . $OIDS[$o]} = sub { |
276
|
0
|
|
|
0
|
|
|
my $self = shift; |
277
|
0
|
|
|
|
|
|
my ($val) = @_; |
278
|
|
|
|
|
|
|
|
279
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = 0 } |
|
0
|
|
|
|
|
|
|
280
|
0
|
|
|
|
|
|
my $s = $self->session; |
281
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
282
|
|
|
|
|
|
|
varbindlist => [_lineOID() . '.' . ($o+1) . '.' . $val] |
283
|
|
|
|
|
|
|
); |
284
|
0
|
|
|
|
|
|
return $r->{_lineOID() . '.' . ($o+1) . '.' . $val} |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
@OIDS = sessOIDs(); |
289
|
|
|
|
|
|
|
for my $o (0..$#OIDS) { |
290
|
|
|
|
|
|
|
*{"get_sess" . $OIDS[$o]} = sub { |
291
|
0
|
|
|
0
|
|
|
my $self = shift; |
292
|
0
|
|
|
|
|
|
my ($val1, $val2) = @_; |
293
|
|
|
|
|
|
|
|
294
|
0
|
0
|
|
|
|
|
if (!defined $val1) { $val1 = 0 } |
|
0
|
|
|
|
|
|
|
295
|
0
|
0
|
|
|
|
|
if (!defined $val2) { $val2 = 0 } |
|
0
|
|
|
|
|
|
|
296
|
0
|
|
|
|
|
|
my $s = $self->session; |
297
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
298
|
|
|
|
|
|
|
varbindlist => [_sessOID() . '.' . ($o+1) . '.' . "$val1.$val2"] |
299
|
|
|
|
|
|
|
); |
300
|
0
|
|
|
|
|
|
return $r->{_sessOID() . '.' . ($o+1) . '.' . "$val1.$val2"} |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
################################################## |
305
|
|
|
|
|
|
|
# End Public Module |
306
|
|
|
|
|
|
|
################################################## |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
1; |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
__END__ |