line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::System; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
73291
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
9
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
852
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
75185
|
|
|
1
|
|
|
|
|
440
|
|
12
|
1
|
|
|
1
|
|
633
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
694
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################## |
19
|
|
|
|
|
|
|
# Start Public Module |
20
|
|
|
|
|
|
|
################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _sysOID { |
23
|
0
|
|
|
0
|
|
0
|
return '1.3.6.1.2.1.1' |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub sysOIDs { |
27
|
1
|
|
|
1
|
1
|
5
|
return qw(Descr ObjectID UpTime Contact Name Location Services ORLastChange) |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub system_info { |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $response = Cisco::SNMP::_snmpwalk($session, _sysOID()); |
37
|
0
|
0
|
|
|
|
|
if (defined $response) { |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $sysinfo; |
40
|
0
|
|
|
|
|
|
my @SYSKEYS = sysOIDs(); |
41
|
0
|
|
|
|
|
|
for (0..$#SYSKEYS) { |
42
|
0
|
|
|
|
|
|
$sysinfo->{$SYSKEYS[$_]} = $response->[$_] |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
return bless $sysinfo, $class |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot read system MIB"; |
47
|
|
|
|
|
|
|
return undef |
48
|
0
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub sysDescr { |
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
53
|
|
|
|
|
|
|
return $self->{Descr} |
54
|
0
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub sysObjectID { |
57
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
return $self->{ObjectID} |
59
|
0
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub sysUpTime { |
62
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
63
|
|
|
|
|
|
|
return $self->{UpTime} |
64
|
0
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub sysContact { |
67
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
return $self->{Contact} |
69
|
0
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub sysName { |
72
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
73
|
|
|
|
|
|
|
return $self->{Name} |
74
|
0
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub sysLocation { |
77
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
return $self->{Location} |
79
|
0
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub sysORLastChange { |
82
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
83
|
|
|
|
|
|
|
return $self->{ORLastChange} |
84
|
0
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub sysServices { |
87
|
0
|
|
|
0
|
1
|
|
my ($self, $arg) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
0
|
|
|
|
if (defined($arg) && ($arg >= 1)) { |
90
|
|
|
|
|
|
|
return $self->{Services} |
91
|
0
|
|
|
|
|
|
} else { |
92
|
0
|
|
|
|
|
|
my %Services = ( |
93
|
|
|
|
|
|
|
1 => 'Physical', |
94
|
|
|
|
|
|
|
2 => 'Datalink', |
95
|
|
|
|
|
|
|
4 => 'Network', |
96
|
|
|
|
|
|
|
8 => 'Transport', |
97
|
|
|
|
|
|
|
16 => 'Session', |
98
|
|
|
|
|
|
|
32 => 'Presentation', |
99
|
|
|
|
|
|
|
64 => 'Application' |
100
|
|
|
|
|
|
|
); |
101
|
0
|
|
|
|
|
|
my @Svcs; |
102
|
0
|
|
|
|
|
|
for (sort {$b <=> $a} (keys(%Services))) { |
|
0
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
push @Svcs, $Services{$_} if ($self->{Services} & int($_)) |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
return \@Svcs |
106
|
0
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub sysOSVersion { |
110
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if ($self->{Descr} =~ /Version ([^ ,\n\r]+)/) { |
113
|
0
|
|
|
|
|
|
return $1 |
114
|
|
|
|
|
|
|
} else { |
115
|
0
|
|
|
|
|
|
return "Cannot determine OS Version" |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
1
|
|
13
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
384
|
|
120
|
|
|
|
|
|
|
# get_ direct |
121
|
|
|
|
|
|
|
my @OIDS = sysOIDs(); |
122
|
|
|
|
|
|
|
for my $o (0..$#OIDS) { |
123
|
|
|
|
|
|
|
*{"get_sys" . $OIDS[$o]} = sub { |
124
|
0
|
|
|
0
|
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $s = $self->session; |
127
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
128
|
|
|
|
|
|
|
varbindlist => [_sysOID() . '.' . ($o+1) . '.0'] |
129
|
|
|
|
|
|
|
); |
130
|
0
|
|
|
|
|
|
return $r->{_sysOID() . '.' . ($o+1) . '.0'} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# set_ direct |
135
|
|
|
|
|
|
|
for my $o (3..5) { |
136
|
|
|
|
|
|
|
*{"set_sys" . $OIDS[$o]} = sub { |
137
|
0
|
|
|
0
|
|
|
my $self = shift; |
138
|
0
|
|
|
|
|
|
my ($val) = @_; |
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = '' } |
|
0
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $s = $self->session; |
142
|
0
|
|
|
|
|
|
my $r = $s->set_request( |
143
|
|
|
|
|
|
|
_sysOID() . '.' . ($o+1) . '.0', OCTET_STRING, $val |
144
|
|
|
|
|
|
|
); |
145
|
0
|
0
|
|
|
|
|
if (!defined $r) { |
146
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = $s->error; |
147
|
|
|
|
|
|
|
return |
148
|
0
|
|
|
|
|
|
} else { |
149
|
0
|
|
|
|
|
|
return $r->{_sysOID() . '.' . ($o+1) . '.0'} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
################################################## |
155
|
|
|
|
|
|
|
# End Public Module |
156
|
|
|
|
|
|
|
################################################## |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
__END__ |