root / tools / perl / lib / FusionInventory / Agent / Task / Inventory / OS / Solaris / Memory.pm @ fa47cac2
History | View | Annotate | Download (17.9 kB)
| 1 |
package FusionInventory::Agent::Task::Inventory::OS::Solaris::Memory; |
|---|---|
| 2 |
use strict; |
| 3 |
|
| 4 |
sub isInventoryEnabled { can_run ("memconf") }
|
| 5 |
|
| 6 |
sub doInventory {
|
| 7 |
|
| 8 |
my $model; |
| 9 |
my $params = shift; |
| 10 |
my $inventory = $params->{inventory};
|
| 11 |
my $logger = $params->{logger};
|
| 12 |
|
| 13 |
my $capacity; |
| 14 |
my $description; |
| 15 |
my $numslots; |
| 16 |
my $speed = undef; |
| 17 |
my $type = undef; |
| 18 |
my $banksize; |
| 19 |
my $module_count=0; |
| 20 |
my $empty_slots; |
| 21 |
my $flag=0; |
| 22 |
my $flag_mt=0; |
| 23 |
my $caption; |
| 24 |
my $sun_class=0; |
| 25 |
my $OSLevel; |
| 26 |
my $zone; |
| 27 |
# for debug only |
| 28 |
my $j=0; |
| 29 |
|
| 30 |
# first, we need determinate on which model of sun server we run, |
| 31 |
# because prtdiags output (and with that memconfs output) is differend |
| 32 |
# from server model to server model |
| 33 |
# we try to classified our box in one of the known classes |
| 34 |
|
| 35 |
$OSLevel=`uname -r`; |
| 36 |
|
| 37 |
if ( $OSLevel =~ /5.8/ ){
|
| 38 |
$zone = "global"; |
| 39 |
}else{
|
| 40 |
foreach (`zoneadm list -p`){
|
| 41 |
$zone=$1 if /^0:([a-z]+):.*$/; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
#print "Nom :".$zone."*************************\n"; |
| 46 |
|
| 47 |
if ($zone) |
| 48 |
{
|
| 49 |
# first, we need determinate on which model of Sun Server we run, |
| 50 |
# because prtdiags output (and with that memconfs output) is differend |
| 51 |
# from server model to server model |
| 52 |
# we try to classified our box in one of the known classes |
| 53 |
$model=`uname -i`; |
| 54 |
# debug print model |
| 55 |
# cut the CR from string model |
| 56 |
$model = substr($model, 0, length($model)-1); |
| 57 |
}else{
|
| 58 |
$model="Solaris Containers"; |
| 59 |
} |
| 60 |
|
| 61 |
#print "Memory Model: $model\n"; |
| 62 |
|
| 63 |
|
| 64 |
#$model=`uname -i`; |
| 65 |
# debug print model |
| 66 |
#print "Model: '$model'"; |
| 67 |
# cut the CR from string model |
| 68 |
#$model = substr($model, 0, length($model)-1); |
| 69 |
# we map (hopfully) our server model to a known class |
| 70 |
#if ($model eq "SUNW,Sun-Fire-280R") { $sun_class = 1; }
|
| 71 |
#if ($model eq "SUNW,Sun-Fire-480R") { $sun_class = 1; }
|
| 72 |
#if ($model eq "SUNW,Sun-Fire-V490") { $sun_class = 1; }
|
| 73 |
#if ($model eq "SUNW,Sun-Fire-880") { $sun_class = 1; }
|
| 74 |
#if ($model eq "SUNW,Sun-Fire-V240") { $sun_class = 2; }
|
| 75 |
#if ($model eq "SUNW,Sun-Fire-V440") { $sun_class = 2; }
|
| 76 |
#if ($model eq "SUNW,Sun-Fire-V250") { $sun_class = 2; }
|
| 77 |
#if ($model eq "SUNW,Sun-Fire-T200") { $sun_class = 3; }
|
| 78 |
#if ($model eq "SUNW,Sun-Fire-T1000") { $sun_class = 3; }
|
| 79 |
#if ($model eq "SUNW,SPARC-Enterprise-T5220") { $sun_class = 4; }
|
| 80 |
#if ($model eq "SUNW,SPARC-Enterprise") { $sun_class = 5; } # for M5000 && M4000
|
| 81 |
|
| 82 |
if ($model =~ /SUNW,SPARC-Enterprise/) { $sun_class = 5; } # for M5000 && M4000
|
| 83 |
if ($model =~ /SUNW,SPARC-Enterprise-T\d/){ $sun_class = 4; }
|
| 84 |
if ($model =~ /SUNW,Netra-T/){ $sun_class = 2; }
|
| 85 |
if ($model =~ /SUNW,Sun-Fire-\d/){ $sun_class = 1; }
|
| 86 |
if ($model =~ /SUNW,Sun-Fire-V/){ $sun_class = 2; }
|
| 87 |
if ($model =~ /SUNW,Sun-Fire-T\d/) { $sun_class = 3; }
|
| 88 |
if ($model =~ /SUNW,T\d/) { $sun_class = 3; }
|
| 89 |
if ($model =~ /Solaris Containers/){ $sun_class = 7; }
|
| 90 |
if ($model =~ /SUNW,Ultra-250/){ $sun_class = 2; }
|
| 91 |
|
| 92 |
|
| 93 |
if ($model eq "i86pc") { $sun_class = 6; }
|
| 94 |
# debug print model |
| 95 |
#print "Sunclass: $sun_class\n"; |
| 96 |
# now we can look at memory information, depending from our class |
| 97 |
|
| 98 |
if($sun_class == 0) |
| 99 |
{
|
| 100 |
$logger->debug("sorry, unknown model, could not detect memory configuration");
|
| 101 |
} |
| 102 |
|
| 103 |
if($sun_class == 1) |
| 104 |
{
|
| 105 |
foreach(`memconf 2>&1`) |
| 106 |
{
|
| 107 |
# debug |
| 108 |
#print "count: " .$j++ . " " . $flag_mt . " : " . "$_"; |
| 109 |
# if we find "empty groups:", we have reached the end and indicate that by setting flag = 0 |
| 110 |
if(/^empty \w+:\s(\S+)/) |
| 111 |
{
|
| 112 |
$flag = 0; |
| 113 |
if($1 eq "None"){$empty_slots = 0;}
|
| 114 |
} |
| 115 |
# grep the type of memory modules from heading |
| 116 |
if($flag_mt && /^\s*\S+\s+\S+\s+\S+\s+\S+\s+(\S+)/) {$flag_mt=0; $description = $1;}
|
| 117 |
|
| 118 |
# only grap for information if flag = 1 |
| 119 |
if ($flag && /^\s*(\S+)\s+(\S+)/) { $caption = "Board " . $1 . " MemCtl " . $2; }
|
| 120 |
if ($flag && /^\s*\S+\s+\S+\s+(\S+)/) { $numslots = $1; }
|
| 121 |
if ($flag && /^\s*\S+\s+\S+\s+\S+\s+(\d+)/) { $banksize = $1; }
|
| 122 |
if ($flag && /^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\d+)/) { $capacity = $1; }
|
| 123 |
if ($flag) |
| 124 |
{
|
| 125 |
for (my $i = 1; $i <= ($banksize / $capacity); $i++) |
| 126 |
{
|
| 127 |
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n"; |
| 128 |
$module_count++; |
| 129 |
$inventory->addMemory({
|
| 130 |
CAPACITY => $capacity, |
| 131 |
DESCRIPTION => $description, |
| 132 |
CAPTION => $caption, |
| 133 |
SPEED => $speed, |
| 134 |
TYPE => $type, |
| 135 |
NUMSLOTS => $numslots |
| 136 |
}) |
| 137 |
} |
| 138 |
} |
| 139 |
# this is the caption line |
| 140 |
if(/^\s+Logical Logical Logical/) { $flag_mt = 1; }
|
| 141 |
# if we find "---", we set flag = 1, and in next line, we start to look for information |
| 142 |
if(/^-+/){ $flag = 1; }
|
| 143 |
} |
| 144 |
#print "# of RAM Modules: " . $module_count . "\n"; |
| 145 |
#print "# of empty slots: " . $empty_slots . "\n"; |
| 146 |
} |
| 147 |
if($sun_class == 2) |
| 148 |
{
|
| 149 |
foreach(`memconf 2>&1`) |
| 150 |
{
|
| 151 |
# debug |
| 152 |
#print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_"; |
| 153 |
# if we find "empty sockets:", we have reached the end and indicate that by resetting flag = 0 |
| 154 |
# emtpy sockets is follow by a list of emtpy slots, where we extract the slot names |
| 155 |
if(/^empty sockets:\s*(\S+)/) |
| 156 |
{
|
| 157 |
$flag = 0; |
| 158 |
# cut of first 15 char containing the string empty sockets: |
| 159 |
substr ($_,0,15) = ""; |
| 160 |
$capacity = "empty"; |
| 161 |
$numslots = 0; |
| 162 |
foreach $caption (split) |
| 163 |
{
|
| 164 |
if ($caption eq "None") |
| 165 |
{
|
| 166 |
$empty_slots = 0; |
| 167 |
# no empty slots -> exit loop |
| 168 |
last; |
| 169 |
} |
| 170 |
# debug |
| 171 |
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n"; |
| 172 |
$empty_slots++; |
| 173 |
$inventory->addMemory({
|
| 174 |
CAPACITY => $capacity, |
| 175 |
# DESCRIPTION => $description, |
| 176 |
CAPTION => $caption, |
| 177 |
SPEED => $speed, |
| 178 |
TYPE => $type, |
| 179 |
NUMSLOTS => $numslots |
| 180 |
}) |
| 181 |
} |
| 182 |
} |
| 183 |
if(/.*Memory Module Groups.*/) |
| 184 |
{
|
| 185 |
$flag = 0; |
| 186 |
$flag_mt = 0; |
| 187 |
} |
| 188 |
# we only grap for information if flag = 1 |
| 189 |
if($flag && /^\s*\S+\s+\S+\s+(\S+)/){ $caption = $1; }
|
| 190 |
if($flag && /^\s*(\S+)/){ $numslots = $1; }
|
| 191 |
if($flag && /^\s*\S+\s+\S+\s+\S+\s+(\d+)/){ $capacity = $1; }
|
| 192 |
if($flag) |
| 193 |
{
|
| 194 |
# debug |
| 195 |
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n"; |
| 196 |
$module_count++; |
| 197 |
$inventory->addMemory({
|
| 198 |
CAPACITY => $capacity, |
| 199 |
# DESCRIPTION => "DIMM", |
| 200 |
CAPTION => "Ram slot ".$numslots, |
| 201 |
SPEED => $speed, |
| 202 |
TYPE => $type, |
| 203 |
NUMSLOTS => $numslots |
| 204 |
}) |
| 205 |
} |
| 206 |
# this is the caption line |
| 207 |
# if(/^ID ControllerID/) { $description = $1;}
|
| 208 |
# if we find "---", we set flag = 1, and in next line, we start to look for information |
| 209 |
if(/^-+/){ $flag = 1;}
|
| 210 |
} |
| 211 |
# debug: show number of modules found and number of empty slots |
| 212 |
} |
| 213 |
|
| 214 |
if($sun_class == 3) |
| 215 |
{
|
| 216 |
foreach(`memconf 2>&1`) |
| 217 |
{
|
| 218 |
# debug |
| 219 |
if(/^empty sockets:\s*(\S+)/) |
| 220 |
{
|
| 221 |
# cut of first 15 char containing the string empty sockets: |
| 222 |
substr ($_,0,15) = ""; |
| 223 |
$capacity = "empty"; |
| 224 |
$numslots = 0; |
| 225 |
foreach $caption (split) |
| 226 |
{
|
| 227 |
if ($caption eq "None") |
| 228 |
{
|
| 229 |
$empty_slots = 0; |
| 230 |
# no empty slots -> exit loop |
| 231 |
last; |
| 232 |
} |
| 233 |
# debug |
| 234 |
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n"; |
| 235 |
$empty_slots++; |
| 236 |
$inventory->addMemory({
|
| 237 |
CAPACITY => $capacity, |
| 238 |
DESCRIPTION => $description, |
| 239 |
CAPTION => $caption, |
| 240 |
SPEED => $speed, |
| 241 |
TYPE => $type, |
| 242 |
NUMSLOTS => $numslots |
| 243 |
}) |
| 244 |
} |
| 245 |
} |
| 246 |
if(/^socket\s+(\S+) has a (\d+)MB\s+\(\S+\)\s+(\S+)/) |
| 247 |
{
|
| 248 |
$caption = $1; |
| 249 |
$description = $3; |
| 250 |
$type = $3; |
| 251 |
$numslots = 0; |
| 252 |
$capacity = $2; |
| 253 |
# debug |
| 254 |
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n"; |
| 255 |
$module_count++; |
| 256 |
$inventory->addMemory({
|
| 257 |
CAPACITY => $capacity, |
| 258 |
DESCRIPTION => $description, |
| 259 |
CAPTION => $caption, |
| 260 |
SPEED => $speed, |
| 261 |
TYPE => $type, |
| 262 |
NUMSLOTS => $numslots |
| 263 |
}) |
| 264 |
} |
| 265 |
} |
| 266 |
# debug: show number of modules found and number of empty slots |
| 267 |
#print "# of RAM Modules: " . $module_count . "\n"; |
| 268 |
#print "# of empty slots: " . $empty_slots . "\n"; |
| 269 |
} |
| 270 |
|
| 271 |
if($sun_class == 4) |
| 272 |
{
|
| 273 |
foreach(`memconf 2>&1`) |
| 274 |
{
|
| 275 |
# debug |
| 276 |
#print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_"; |
| 277 |
# if we find "empty sockets:", we have reached the end and indicate that by resetting flag = 0 |
| 278 |
# emtpy sockets is follow by a list of emtpy slots, where we extract the slot names |
| 279 |
if(/^empty sockets:\s*(\S+)/) |
| 280 |
{
|
| 281 |
$flag = 0; |
| 282 |
# cut of first 15 char containing the string empty sockets: |
| 283 |
substr ($_,0,15) = ""; |
| 284 |
$capacity = "empty"; |
| 285 |
$numslots = 0; |
| 286 |
foreach $caption (split) |
| 287 |
{
|
| 288 |
if ($caption eq "None") |
| 289 |
{
|
| 290 |
$empty_slots = 0; |
| 291 |
# no empty slots -> exit loop |
| 292 |
last; |
| 293 |
} |
| 294 |
# debug |
| 295 |
print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n"; |
| 296 |
$empty_slots++; |
| 297 |
$inventory->addMemory({
|
| 298 |
CAPACITY => $capacity, |
| 299 |
DESCRIPTION => $description, |
| 300 |
CAPTION => $caption, |
| 301 |
SPEED => $speed, |
| 302 |
TYPE => $type, |
| 303 |
NUMSLOTS => $numslots |
| 304 |
}) |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
# we only grap for information if flag = 1 |
| 309 |
# socket MB/CMP0/BR0/CH0/D0 has a Samsung 501-7953-01 Rev 05 2GB FB-DIMM |
| 310 |
if(/^socket\s+(\S+) has a (.+)\s+(\S+)GB\s+(\S+)$/i) |
| 311 |
{
|
| 312 |
$caption = $1; |
| 313 |
$description = $2; |
| 314 |
$type = $4; |
| 315 |
$numslots = 0; |
| 316 |
$capacity = $3 * 1024; |
| 317 |
# debug |
| 318 |
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n"; |
| 319 |
$module_count++; |
| 320 |
$inventory->addMemory({
|
| 321 |
CAPACITY => $capacity, |
| 322 |
DESCRIPTION => $description, |
| 323 |
CAPTION => $caption, |
| 324 |
SPEED => $speed, |
| 325 |
TYPE => $type, |
| 326 |
NUMSLOTS => $numslots |
| 327 |
}) |
| 328 |
} |
| 329 |
} |
| 330 |
# debug: show number of modules found and number of empty slots |
| 331 |
#print "# of RAM Modules: " . $module_count . "\n"; |
| 332 |
#print "# of empty slots: " . $empty_slots . "\n"; |
| 333 |
} |
| 334 |
|
| 335 |
if ($sun_class == 5 ) |
| 336 |
{
|
| 337 |
foreach(`memconf 2>&1`) |
| 338 |
{
|
| 339 |
# debug |
| 340 |
#print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_"; |
| 341 |
# if we find "empty sockets:", we have reached the end and indicate that by resetting flag = 0 |
| 342 |
# emtpy sockets is follow by a list of emtpy slots, where we extract the slot names |
| 343 |
if(/^total memory:\s*(\S+)/) { $flag = 0;}
|
| 344 |
|
| 345 |
#print "flag : $flag\n"; |
| 346 |
if($flag_mt && /^\s+\S+\s+\S+\s+\S+\s+(\S+)/) {$flag_mt=0; $description = $1;}
|
| 347 |
#print "description : $description\n"; |
| 348 |
|
| 349 |
if ($flag && /^\s(\S+)\s+(\S+)/) { $numslots = "LSB " . $1 . " Group " . $2; }
|
| 350 |
if ($flag && /^\s(\S+)\s+(\S+)/) { $caption = "LSB " . $1 . " Group " . $2; }
|
| 351 |
if ($flag && /^\s+\S+\s+\S\s+\S+\s+\S+\s+(\d+)/) { $capacity = $1; }
|
| 352 |
if ($flag && /^\s+\S+\s+\S\s+(\d+)/) { $banksize = $1; }
|
| 353 |
#print "Num slot ". $numslots . " Bank Number: " . $numslots . " Bank size " . $banksize . " DIMM Capacity: " . $capacity . "MB\n"; |
| 354 |
if ($flag && $capacity > 1 ) |
| 355 |
{
|
| 356 |
for (my $i = 1; $i <= ($banksize / $capacity); $i++) |
| 357 |
{
|
| 358 |
#print "caption ". $caption . " Bank Number: " . $numslots . " Bank size " . $banksize . " DIMM Capacity: " . $capacity . "MB\n"; |
| 359 |
$inventory->addMemory({
|
| 360 |
CAPACITY => $capacity, |
| 361 |
DESCRIPTION => $description, |
| 362 |
CAPTION => $caption, |
| 363 |
SPEED => $speed, |
| 364 |
TYPE => $type, |
| 365 |
NUMSLOTS => $module_count |
| 366 |
}) |
| 367 |
} |
| 368 |
$module_count++; |
| 369 |
} |
| 370 |
#Caption Line |
| 371 |
if (/^Sun Microsystems/) { $flag_mt=1; $flag=1; }
|
| 372 |
} |
| 373 |
} |
| 374 |
if($sun_class == 6) |
| 375 |
{
|
| 376 |
foreach(`memconf 2>&1`) |
| 377 |
{
|
| 378 |
# debug |
| 379 |
#print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_"; |
| 380 |
if(/^empty memory sockets:\s*(\S+)/) |
| 381 |
{
|
| 382 |
# cut of first 22 char containing the string empty sockets: |
| 383 |
substr ($_,0,22) = ""; |
| 384 |
$capacity = "0"; |
| 385 |
$numslots = 0; |
| 386 |
foreach $caption (split(/, /,$_)) |
| 387 |
{
|
| 388 |
if ($caption eq "None") |
| 389 |
{
|
| 390 |
$empty_slots = 0; |
| 391 |
# no empty slots -> exit loop |
| 392 |
last; |
| 393 |
} |
| 394 |
# debug |
| 395 |
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n"; |
| 396 |
$empty_slots++; |
| 397 |
$inventory->addMemory({
|
| 398 |
CAPACITY => $capacity, |
| 399 |
DESCRIPTION => "empty", |
| 400 |
CAPTION => $caption, |
| 401 |
SPEED => 'n/a', |
| 402 |
TYPE => 'n/a', |
| 403 |
NUMSLOTS => $numslots |
| 404 |
}) |
| 405 |
} |
| 406 |
} |
| 407 |
if(/^socket DIMM(\d+):\s+(\d+)MB\s(\S+)/) |
| 408 |
{
|
| 409 |
$caption = "DIMM$1"; |
| 410 |
$description = "DIMM$1"; |
| 411 |
$numslots = $1; |
| 412 |
$capacity = $2; |
| 413 |
$type = $3; |
| 414 |
# debug |
| 415 |
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n"; |
| 416 |
$module_count++; |
| 417 |
$inventory->addMemory({
|
| 418 |
CAPACITY => $capacity, |
| 419 |
DESCRIPTION => $description, |
| 420 |
CAPTION => $caption, |
| 421 |
SPEED => $speed, |
| 422 |
TYPE => $type, |
| 423 |
NUMSLOTS => $numslots |
| 424 |
}) |
| 425 |
} |
| 426 |
} |
| 427 |
# debug: show number of modules found and number of empty slots |
| 428 |
#print "# of RAM Modules: " . $module_count . "\n"; |
| 429 |
#print "# of empty slots: " . $empty_slots . "\n"; |
| 430 |
} |
| 431 |
|
| 432 |
if ($sun_class == 7) |
| 433 |
{
|
| 434 |
foreach (`prctl -n project.max-shm-memory $$ 2>&1`) |
| 435 |
{
|
| 436 |
|
| 437 |
$description = $1 if /^project.(\S+)$/; |
| 438 |
$capacity = $1 if /^\s*system+\s*(\d+).*$/; |
| 439 |
if(($description && $capacity)){
|
| 440 |
$capacity = $capacity * 1024; |
| 441 |
$numslots = 1 ; |
| 442 |
$description = "Memory Allocated"; |
| 443 |
$caption = "Memory Share"; |
| 444 |
#print $description."_".$capacity."***\n"; |
| 445 |
$inventory->addMemory({
|
| 446 |
CAPACITY => $capacity, |
| 447 |
DESCRIPTION => $description, |
| 448 |
CAPTION => $caption, |
| 449 |
SPEED => $speed, |
| 450 |
TYPE => $type, |
| 451 |
NUMSLOTS => $numslots |
| 452 |
}) |
| 453 |
} |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
} |
| 458 |
#run(); |
| 459 |
1; |