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
|
|
90646
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
700
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
69440
|
|
|
1
|
|
|
|
|
318
|
|
12
|
1
|
|
|
1
|
|
480
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
755
|
|
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
|
11
|
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
|
|
|
|
|
|
|
# IOS releases > 12.2(3.5) |
34
|
0
|
0
|
0
|
|
|
|
if (($cpu5min = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.9.109.1.1.1.1.8")) && (defined $cpu5min->[0])) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$type = 3 |
36
|
|
|
|
|
|
|
# 12.0(3)T < IOS releases < 12.2(3.5) |
37
|
|
|
|
|
|
|
} elsif (($cpu5min = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.9.109.1.1.1.1.5")) && (defined $cpu5min->[0])) { |
38
|
0
|
|
|
|
|
|
$type = 2 |
39
|
|
|
|
|
|
|
# IOS releases < 12.0(3)T |
40
|
|
|
|
|
|
|
} elsif (($cpu5min = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.2.1.58")) && (defined $cpu5min->[0])) { |
41
|
0
|
|
|
|
|
|
$type = 1 |
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot determine CPU type"; |
44
|
|
|
|
|
|
|
return undef |
45
|
0
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my %cpuType = ( |
48
|
|
|
|
|
|
|
1 => 'IOS releases < 12.0(3)T', |
49
|
|
|
|
|
|
|
2 => '12.0(3)T < IOS releases < 12.2(3.5)', |
50
|
|
|
|
|
|
|
3 => 'IOS releases > 12.2(3.5)' |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my @cpuName; |
54
|
|
|
|
|
|
|
# Get multiple CPU names |
55
|
0
|
0
|
|
|
|
|
if ($type > 1) { |
56
|
0
|
|
|
|
|
|
my $temp = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.9.109.1.1.1.1.2"); |
57
|
0
|
|
|
|
|
|
for (0..$#{$temp}) { |
|
0
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ($temp->[$_] == 0) { |
59
|
0
|
|
|
|
|
|
$cpuName[$_] = ''; |
60
|
|
|
|
|
|
|
next |
61
|
0
|
|
|
|
|
|
} |
62
|
0
|
0
|
|
|
|
|
if (defined(my $result = $session->get_request( -varbindlist => ['1.3.6.1.2.1.47.1.1.1.1.7.' . $temp->[$_]] ))) { |
63
|
0
|
|
|
|
|
|
$cpuName[$_] = $result->{'1.3.6.1.2.1.47.1.1.1.1.7.' . $temp->[$_]} |
64
|
|
|
|
|
|
|
} else { |
65
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get CPU name for type `$cpuType{$type}'"; |
66
|
|
|
|
|
|
|
return undef |
67
|
0
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my ($cpu5sec, $cpu1min); |
72
|
0
|
0
|
|
|
|
|
if ($type == 1) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$cpu5sec = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.2.1.56"); |
74
|
0
|
|
|
|
|
|
$cpu1min = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.2.1.57"); |
75
|
0
|
|
|
|
|
|
$cpu5min = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.2.1.58") |
76
|
|
|
|
|
|
|
} elsif ($type == 2) { |
77
|
0
|
|
|
|
|
|
$cpu5sec = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.9.109.1.1.1.1.3"); |
78
|
0
|
|
|
|
|
|
$cpu1min = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.9.109.1.1.1.1.4"); |
79
|
0
|
|
|
|
|
|
$cpu5min = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.9.109.1.1.1.1.5") |
80
|
|
|
|
|
|
|
} elsif ($type == 3) { |
81
|
0
|
|
|
|
|
|
$cpu5sec = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.9.109.1.1.1.1.6"); |
82
|
0
|
|
|
|
|
|
$cpu1min = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.9.109.1.1.1.1.7"); |
83
|
0
|
|
|
|
|
|
$cpu5min = Cisco::SNMP::_snmpwalk($session,"1.3.6.1.4.1.9.9.109.1.1.1.1.8") |
84
|
|
|
|
|
|
|
} else { } |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my @CPUInfo; |
87
|
0
|
|
|
|
|
|
for my $cpu (0..$#{$cpu5min}) { |
|
0
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my %CPUInfoHash; |
89
|
0
|
|
|
|
|
|
$CPUInfoHash{Name} = $cpuName[$cpu]; |
90
|
0
|
|
|
|
|
|
$CPUInfoHash{'5sec'} = $cpu5sec->[$cpu]; |
91
|
0
|
|
|
|
|
|
$CPUInfoHash{'1min'} = $cpu1min->[$cpu]; |
92
|
0
|
|
|
|
|
|
$CPUInfoHash{'5min'} = $cpu5min->[$cpu]; |
93
|
0
|
|
|
|
|
|
$CPUInfoHash{Type} = $cpuType{$type}; |
94
|
0
|
|
|
|
|
|
push @CPUInfo, \%CPUInfoHash |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
|
return bless \@CPUInfo, $class |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
for (cpuOIDs()) { |
100
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_array_1('cpu', $_) |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
################################################## |
104
|
|
|
|
|
|
|
# End Public Module |
105
|
|
|
|
|
|
|
################################################## |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |