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
|
|
53264
|
use strict; |
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
38
|
|
9
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
616
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
72973
|
|
|
1
|
|
|
|
|
393
|
|
12
|
1
|
|
|
1
|
|
575
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
509
|
|
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
|
3
|
return qw(Descr ObjectID UpTime Contact Name Location Services |
28
|
|
|
|
|
|
|
ORLastChange); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub system_info { |
32
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
33
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $response = Cisco::SNMP::_snmpwalk( $session, _sysOID() ); |
38
|
0
|
0
|
|
|
|
|
if ( defined $response ) { |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $sysinfo; |
41
|
0
|
|
|
|
|
|
my @SYSKEYS = sysOIDs(); |
42
|
0
|
|
|
|
|
|
for ( 0 .. $#SYSKEYS ) { |
43
|
0
|
|
|
|
|
|
$sysinfo->{$SYSKEYS[$_]} = $response->[$_]; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
return bless $sysinfo, $class; |
46
|
|
|
|
|
|
|
} else { |
47
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot read system MIB"; |
48
|
0
|
|
|
|
|
|
return undef; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub sysDescr { |
53
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
54
|
0
|
|
|
|
|
|
return $self->{Descr}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub sysObjectID { |
58
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
return $self->{ObjectID}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub sysUpTime { |
63
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
return $self->{UpTime}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub sysContact { |
68
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
69
|
0
|
|
|
|
|
|
return $self->{Contact}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub sysName { |
73
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
74
|
0
|
|
|
|
|
|
return $self->{Name}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub sysLocation { |
78
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
79
|
0
|
|
|
|
|
|
return $self->{Location}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub sysORLastChange { |
83
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
return $self->{ORLastChange}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub sysServices { |
88
|
0
|
|
|
0
|
1
|
|
my ( $self, $arg ) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
0
|
|
|
|
if ( defined($arg) && ( $arg >= 1 ) ) { |
91
|
0
|
|
|
|
|
|
return $self->{Services}; |
92
|
|
|
|
|
|
|
} else { |
93
|
0
|
|
|
|
|
|
my %Services = ( |
94
|
|
|
|
|
|
|
1 => 'Physical', |
95
|
|
|
|
|
|
|
2 => 'Datalink', |
96
|
|
|
|
|
|
|
4 => 'Network', |
97
|
|
|
|
|
|
|
8 => 'Transport', |
98
|
|
|
|
|
|
|
16 => 'Session', |
99
|
|
|
|
|
|
|
32 => 'Presentation', |
100
|
|
|
|
|
|
|
64 => 'Application' |
101
|
|
|
|
|
|
|
); |
102
|
0
|
|
|
|
|
|
my @Svcs; |
103
|
0
|
|
|
|
|
|
for ( sort { $b <=> $a } ( keys(%Services) ) ) { |
|
0
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
push @Svcs, $Services{$_} if ( $self->{Services} & int($_) ); |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
|
return \@Svcs; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub sysOSVersion { |
111
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
if ( $self->{Descr} =~ /Version ([^ ,\n\r]+)/ ) { |
114
|
0
|
|
|
|
|
|
return $1; |
115
|
|
|
|
|
|
|
} else { |
116
|
0
|
|
|
|
|
|
return "Cannot determine OS Version"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
250
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# get_ direct |
123
|
|
|
|
|
|
|
my @OIDS = sysOIDs(); |
124
|
|
|
|
|
|
|
for my $o ( 0 .. $#OIDS ) { |
125
|
|
|
|
|
|
|
*{"get_sys" . $OIDS[$o]} = sub { |
126
|
0
|
|
|
0
|
|
|
my $self = shift; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $s = $self->session; |
129
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
130
|
|
|
|
|
|
|
varbindlist => [_sysOID() . '.' . ( $o + 1 ) . '.0'] ); |
131
|
0
|
|
|
|
|
|
return $r->{_sysOID() . '.' . ( $o + 1 ) . '.0'}; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# set_ direct |
136
|
|
|
|
|
|
|
for my $o ( 3 .. 5 ) { |
137
|
|
|
|
|
|
|
*{"set_sys" . $OIDS[$o]} = sub { |
138
|
0
|
|
|
0
|
|
|
my $self = shift; |
139
|
0
|
|
|
|
|
|
my ($val) = @_; |
140
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
if ( not defined $val ) { $val = '' } |
|
0
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $s = $self->session; |
143
|
0
|
|
|
|
|
|
my $r = $s->set_request( _sysOID() . '.' . ( $o + 1 ) . '.0', |
144
|
|
|
|
|
|
|
OCTET_STRING, $val ); |
145
|
0
|
0
|
|
|
|
|
if ( not defined $r ) { |
146
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = $s->error; |
147
|
0
|
|
|
|
|
|
return; |
148
|
|
|
|
|
|
|
} 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__ |