line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::HPUX::Memory; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
73115074
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
87
|
|
4
|
1
|
|
|
1
|
|
11
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
76
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
465
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
159
|
|
7
|
1
|
|
|
1
|
|
397
|
use FusionInventory::Agent::Tools::HPUX; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
8
|
1
|
|
|
1
|
|
6
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub isEnabled { |
11
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
12
|
0
|
0
|
|
|
|
|
return 0 if $params{no_category}->{memory}; |
13
|
0
|
|
|
|
|
|
return 1; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub doInventory { |
17
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
20
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my @memories; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# http://forge.fusioninventory.org/issues/754 |
25
|
0
|
0
|
0
|
|
|
|
if (canRun('/opt/propplus/bin/cprop') && !isHPVMGuest()) { |
26
|
0
|
|
|
|
|
|
@memories = _parseCprop( |
27
|
|
|
|
|
|
|
command => '/opt/propplus/bin/cprop -summary -c Memory', |
28
|
|
|
|
|
|
|
logger => $logger |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} else { |
31
|
0
|
|
|
|
|
|
my $arch = getFirstLine(command => 'uname -m'); |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
if ($arch =~ /ia64/ ) { |
34
|
|
|
|
|
|
|
# enable infolog |
35
|
0
|
|
|
|
|
|
system("echo 'sc product IPF_MEMORY;info' | /usr/sbin/cstm"); |
36
|
0
|
|
|
|
|
|
@memories = _parseCstm64( |
37
|
|
|
|
|
|
|
command => "echo 'sc product IPF_MEMORY;il' | /usr/sbin/cstm", |
38
|
|
|
|
|
|
|
logger => $logger |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} else { |
41
|
0
|
|
|
|
|
|
@memories = _parseCstm( |
42
|
|
|
|
|
|
|
command => "echo 'sc product mem;il'| /usr/sbin/cstm", |
43
|
|
|
|
|
|
|
logger => $logger |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $memorySize; |
49
|
0
|
|
|
|
|
|
my $swapSize = getFirstMatch( |
50
|
|
|
|
|
|
|
command => 'swapinfo -dt', |
51
|
|
|
|
|
|
|
logger => $logger, |
52
|
|
|
|
|
|
|
pattern => qr/^total\s+(\d+)/ |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
foreach my $memory (@memories) { |
56
|
0
|
|
|
|
|
|
$inventory->addEntry( |
57
|
|
|
|
|
|
|
section => 'MEMORIES', |
58
|
|
|
|
|
|
|
entry => $memory |
59
|
|
|
|
|
|
|
); |
60
|
0
|
|
|
|
|
|
$memorySize += $memory->{CAPACITY}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$inventory->setHardware({ |
64
|
0
|
|
|
|
|
|
SWAP => int($swapSize / 1024), |
65
|
|
|
|
|
|
|
MEMORY => $memorySize |
66
|
|
|
|
|
|
|
}); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _parseCprop { |
70
|
0
|
|
|
0
|
|
|
my $handle = getFileHandle(@_); |
71
|
0
|
0
|
|
|
|
|
return unless $handle; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my @memories; |
74
|
|
|
|
|
|
|
my $instance; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
77
|
0
|
0
|
|
|
|
|
if ($line =~ /\[Instance\]: \d+/) { |
78
|
|
|
|
|
|
|
# new block |
79
|
0
|
|
|
|
|
|
$instance = {}; |
80
|
0
|
|
|
|
|
|
next; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if ($line =~ /^ \s+ \[ ([^\]]+) \]: \s (\S+.*)/x) { |
84
|
0
|
|
|
|
|
|
$instance->{$1} = $2; |
85
|
0
|
|
|
|
|
|
next; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if ($line =~ /^\*+/) { |
89
|
0
|
0
|
|
|
|
|
next unless keys %$instance; |
90
|
0
|
0
|
|
|
|
|
next unless $instance->{Size}; |
91
|
0
|
|
|
|
|
|
push @memories, { |
92
|
|
|
|
|
|
|
CAPACITY => getCanonicalSize($instance->{Size}), |
93
|
|
|
|
|
|
|
DESCRIPTION => $instance->{'Part Number'}, |
94
|
|
|
|
|
|
|
SERIALNUMBER => $instance->{'Serial Number'}, |
95
|
|
|
|
|
|
|
TYPE => $instance->{'Module Type'}, |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
|
close $handle; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return @memories; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _parseCstm { |
105
|
0
|
|
|
0
|
|
|
my $handle = getFileHandle(@_); |
106
|
0
|
0
|
|
|
|
|
return unless $handle; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my @memories; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my %capacities; |
111
|
0
|
|
|
|
|
|
my $capacity = 0; |
112
|
0
|
|
|
|
|
|
my $description; |
113
|
0
|
|
|
|
|
|
my $numslot = 1; |
114
|
0
|
|
|
|
|
|
my $subnumslot; |
115
|
0
|
|
|
|
|
|
my $serialnumber = 'No Serial Number available!'; |
116
|
0
|
|
|
|
|
|
my $type; |
117
|
0
|
|
|
|
|
|
my $ok = 0; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
if ($line =~ /FRU\sSource\s+=\s+\S+\s+\(memory/ ) { |
122
|
0
|
|
|
|
|
|
$ok = 0; |
123
|
|
|
|
|
|
|
} |
124
|
0
|
0
|
|
|
|
|
if ($line =~ /Source\s+Detail\s+=\s4/ ) { |
125
|
0
|
|
|
|
|
|
$ok = 1; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
0
|
|
|
|
|
if ($line =~ /\s+(\d+)\s+(\d+)/ ) { |
128
|
0
|
|
|
|
|
|
$capacities{$1} = $2; |
129
|
|
|
|
|
|
|
} |
130
|
0
|
0
|
|
|
|
|
if ($line =~ /Extender\s+Location\s+=\s+(\S+)/ ) { |
131
|
0
|
|
|
|
|
|
$subnumslot = $1; |
132
|
|
|
|
|
|
|
}; |
133
|
0
|
0
|
|
|
|
|
if ($line =~ /DIMMS\s+Rank\s+=\s+(\S+)/ ) { |
134
|
0
|
|
|
|
|
|
$numslot = sprintf("%02x",$1); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
if ($line =~ /FRU\s+Name\.*:\s+(\S+)/ ) { |
138
|
0
|
0
|
|
|
|
|
if ($line =~ /(\S+)_(\S+)/ ) { |
|
|
0
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$type = $1; |
140
|
0
|
|
|
|
|
|
$capacity = $2; |
141
|
|
|
|
|
|
|
} elsif ($line =~ /(\wIMM)(\S+)/ ) { |
142
|
0
|
|
|
|
|
|
$ok = 1; |
143
|
0
|
|
|
|
|
|
$type = $1; |
144
|
0
|
|
|
|
|
|
$numslot = $2; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
0
|
0
|
|
|
|
|
if ($line =~ /Part\s+Number\.*:\s*(\S+)\s+/ ) { |
148
|
0
|
|
|
|
|
|
$description = $1; |
149
|
|
|
|
|
|
|
} |
150
|
0
|
0
|
|
|
|
|
if ($line =~ /Serial\s+Number\.*:\s*(\S+)\s+/ ) { |
151
|
0
|
|
|
|
|
|
$serialnumber = $1; |
152
|
0
|
0
|
|
|
|
|
if ( $ok eq 1 ) { |
153
|
0
|
0
|
|
|
|
|
if ( $capacity eq 0 ) { |
154
|
0
|
|
|
|
|
|
$capacity = $capacities{$numslot}; |
155
|
|
|
|
|
|
|
} |
156
|
0
|
|
|
|
|
|
push @memories, { |
157
|
|
|
|
|
|
|
CAPACITY => $capacity, |
158
|
|
|
|
|
|
|
DESCRIPTION => "Part Number $description", |
159
|
|
|
|
|
|
|
CAPTION => "Ext $subnumslot Slot $numslot", |
160
|
|
|
|
|
|
|
TYPE => $type, |
161
|
|
|
|
|
|
|
NUMSLOTS => '1', |
162
|
|
|
|
|
|
|
SERIALNUMBER => $serialnumber, |
163
|
|
|
|
|
|
|
}; |
164
|
0
|
|
|
|
|
|
$ok = 0; |
165
|
0
|
|
|
|
|
|
$capacity = 0; |
166
|
|
|
|
|
|
|
} # $ok eq 1 |
167
|
|
|
|
|
|
|
} # /Serial\s+Number\.*:\s*(\S+)\s+/ |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
} |
170
|
0
|
|
|
|
|
|
close $handle; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
return @memories; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _parseCstm64 { |
176
|
0
|
|
|
0
|
|
|
my $handle = getFileHandle(@_); |
177
|
0
|
0
|
|
|
|
|
return unless $handle; |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
my @memories; |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# this pattern assumes memory slots are correctly |
184
|
|
|
|
|
|
|
# balanced (slot A and slot B are occuped) |
185
|
0
|
0
|
|
|
|
|
next unless $line =~ / |
186
|
|
|
|
|
|
|
(\w+IMM)\s+(\w+)\s+(\d+) # first column |
187
|
|
|
|
|
|
|
\s+ |
188
|
|
|
|
|
|
|
(\w+IMM)\s+(\w+)\s+(\d+) # second column |
189
|
|
|
|
|
|
|
/x; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
push @memories, { |
192
|
|
|
|
|
|
|
CAPACITY => $3, |
193
|
|
|
|
|
|
|
DESCRIPTION => $1, |
194
|
|
|
|
|
|
|
CAPTION => $1 . ' ' . $2, |
195
|
|
|
|
|
|
|
TYPE => $1, |
196
|
|
|
|
|
|
|
NUMSLOTS => $2, |
197
|
|
|
|
|
|
|
}, { |
198
|
|
|
|
|
|
|
CAPACITY => $6, |
199
|
|
|
|
|
|
|
DESCRIPTION => $4, |
200
|
|
|
|
|
|
|
CAPTION => $4 . ' ' . $5, |
201
|
|
|
|
|
|
|
TYPE => $4, |
202
|
|
|
|
|
|
|
NUMSLOTS => $5, |
203
|
|
|
|
|
|
|
}; |
204
|
|
|
|
|
|
|
} |
205
|
0
|
|
|
|
|
|
close $handle; |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
return @memories; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
1; |