line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::CPU; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
69570
|
use strict; |
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
34
|
|
9
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
664
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
69154
|
|
|
1
|
|
|
|
|
236
|
|
12
|
1
|
|
|
1
|
|
379
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
469
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################## |
19
|
|
|
|
|
|
|
# Start Public Module |
20
|
|
|
|
|
|
|
################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub cpuOIDs { |
23
|
1
|
|
|
1
|
1
|
4
|
return qw(Name 5sec 1min 5min Type); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub cpu_info { |
27
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
28
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my ( $type, $cpu5min ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# IOS releases > 12.2(3.5) |
35
|
0
|
0
|
0
|
|
|
|
if (( $cpu5min = Cisco::SNMP::_snmpwalk( |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
36
|
|
|
|
|
|
|
$session, "1.3.6.1.4.1.9.9.109.1.1.1.1.8" |
37
|
|
|
|
|
|
|
) |
38
|
|
|
|
|
|
|
) |
39
|
|
|
|
|
|
|
and defined $cpu5min->[0] |
40
|
|
|
|
|
|
|
) { |
41
|
0
|
|
|
|
|
|
$type = 3 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# 12.0(3)T < IOS releases < 12.2(3.5) |
44
|
|
|
|
|
|
|
} elsif ( |
45
|
|
|
|
|
|
|
( $cpu5min = Cisco::SNMP::_snmpwalk( |
46
|
|
|
|
|
|
|
$session, "1.3.6.1.4.1.9.9.109.1.1.1.1.5" |
47
|
|
|
|
|
|
|
) |
48
|
|
|
|
|
|
|
) |
49
|
|
|
|
|
|
|
and defined $cpu5min->[0] |
50
|
|
|
|
|
|
|
) { |
51
|
0
|
|
|
|
|
|
$type = 2 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# IOS releases < 12.0(3)T |
54
|
|
|
|
|
|
|
} elsif ( |
55
|
|
|
|
|
|
|
( $cpu5min |
56
|
|
|
|
|
|
|
= Cisco::SNMP::_snmpwalk( $session, "1.3.6.1.4.1.9.2.1.58" ) |
57
|
|
|
|
|
|
|
) |
58
|
|
|
|
|
|
|
and defined $cpu5min->[0] |
59
|
|
|
|
|
|
|
) { |
60
|
0
|
|
|
|
|
|
$type = 1; |
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot determine CPU type"; |
63
|
0
|
|
|
|
|
|
return undef; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my %cpuType = ( |
67
|
|
|
|
|
|
|
1 => 'IOS releases < 12.0(3)T', |
68
|
|
|
|
|
|
|
2 => '12.0(3)T < IOS releases < 12.2(3.5)', |
69
|
|
|
|
|
|
|
3 => 'IOS releases > 12.2(3.5)' |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my @cpuName; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Get multiple CPU names |
75
|
0
|
0
|
|
|
|
|
if ( $type > 1 ) { |
76
|
0
|
|
|
|
|
|
my $temp = Cisco::SNMP::_snmpwalk( $session, |
77
|
|
|
|
|
|
|
"1.3.6.1.4.1.9.9.109.1.1.1.1.2" ); |
78
|
0
|
|
|
|
|
|
for ( 0 .. $#{$temp} ) { |
|
0
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if ( $temp->[$_] == 0 ) { |
80
|
0
|
|
|
|
|
|
$cpuName[$_] = ''; |
81
|
0
|
|
|
|
|
|
next; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
0
|
|
|
|
|
if (defined( |
84
|
|
|
|
|
|
|
my $result = $session->get_request( |
85
|
|
|
|
|
|
|
-varbindlist => |
86
|
|
|
|
|
|
|
['1.3.6.1.2.1.47.1.1.1.1.7.' . $temp->[$_]] |
87
|
|
|
|
|
|
|
) |
88
|
|
|
|
|
|
|
) |
89
|
|
|
|
|
|
|
) { |
90
|
|
|
|
|
|
|
$cpuName[$_] |
91
|
0
|
|
|
|
|
|
= $result->{'1.3.6.1.2.1.47.1.1.1.1.7.' . $temp->[$_]}; |
92
|
|
|
|
|
|
|
} else { |
93
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR |
94
|
|
|
|
|
|
|
= "Cannot get CPU name for type `$cpuType{$type}'"; |
95
|
0
|
|
|
|
|
|
return undef; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my ( $cpu5sec, $cpu1min ); |
101
|
0
|
0
|
|
|
|
|
if ( $type == 1 ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$cpu5sec = Cisco::SNMP::_snmpwalk( $session, "1.3.6.1.4.1.9.2.1.56" ); |
103
|
0
|
|
|
|
|
|
$cpu1min = Cisco::SNMP::_snmpwalk( $session, "1.3.6.1.4.1.9.2.1.57" ); |
104
|
0
|
|
|
|
|
|
$cpu5min = Cisco::SNMP::_snmpwalk( $session, "1.3.6.1.4.1.9.2.1.58" ); |
105
|
|
|
|
|
|
|
} elsif ( $type == 2 ) { |
106
|
0
|
|
|
|
|
|
$cpu5sec = Cisco::SNMP::_snmpwalk( $session, |
107
|
|
|
|
|
|
|
"1.3.6.1.4.1.9.9.109.1.1.1.1.3" ); |
108
|
0
|
|
|
|
|
|
$cpu1min = Cisco::SNMP::_snmpwalk( $session, |
109
|
|
|
|
|
|
|
"1.3.6.1.4.1.9.9.109.1.1.1.1.4" ); |
110
|
0
|
|
|
|
|
|
$cpu5min = Cisco::SNMP::_snmpwalk( $session, |
111
|
|
|
|
|
|
|
"1.3.6.1.4.1.9.9.109.1.1.1.1.5" ); |
112
|
|
|
|
|
|
|
} elsif ( $type == 3 ) { |
113
|
0
|
|
|
|
|
|
$cpu5sec = Cisco::SNMP::_snmpwalk( $session, |
114
|
|
|
|
|
|
|
"1.3.6.1.4.1.9.9.109.1.1.1.1.6" ); |
115
|
0
|
|
|
|
|
|
$cpu1min = Cisco::SNMP::_snmpwalk( $session, |
116
|
|
|
|
|
|
|
"1.3.6.1.4.1.9.9.109.1.1.1.1.7" ); |
117
|
0
|
|
|
|
|
|
$cpu5min = Cisco::SNMP::_snmpwalk( $session, |
118
|
|
|
|
|
|
|
"1.3.6.1.4.1.9.9.109.1.1.1.1.8" ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my @CPUInfo; |
122
|
0
|
|
|
|
|
|
for my $cpu ( 0 .. $#{$cpu5min} ) { |
|
0
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my %CPUInfoHash; |
124
|
0
|
|
|
|
|
|
$CPUInfoHash{Name} = $cpuName[$cpu]; |
125
|
0
|
|
|
|
|
|
$CPUInfoHash{'5sec'} = $cpu5sec->[$cpu]; |
126
|
0
|
|
|
|
|
|
$CPUInfoHash{'1min'} = $cpu1min->[$cpu]; |
127
|
0
|
|
|
|
|
|
$CPUInfoHash{'5min'} = $cpu5min->[$cpu]; |
128
|
0
|
|
|
|
|
|
$CPUInfoHash{Type} = $cpuType{$type}; |
129
|
0
|
|
|
|
|
|
push @CPUInfo, \%CPUInfoHash; |
130
|
|
|
|
|
|
|
} |
131
|
0
|
|
|
|
|
|
return bless \@CPUInfo, $class; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
for ( cpuOIDs() ) { |
135
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_array_1( 'cpu', $_ ); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
################################################## |
139
|
|
|
|
|
|
|
# End Public Module |
140
|
|
|
|
|
|
|
################################################## |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |