File: Memory.pm

package info (click to toggle)
ocsinventory-agent 2%3A2.0.5-1.2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 4,120 kB
  • ctags: 899
  • sloc: perl: 20,687; sh: 576; objc: 468; ansic: 333; makefile: 55
file content (526 lines) | stat: -rw-r--r-- 17,437 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
package Ocsinventory::Agent::Backend::OS::Solaris::Memory;
use strict;

sub check { can_run ("memconf") }

sub run {

  my $model;
  my $params = shift;
  my $common = $params->{common};
  my $logger = $params->{logger};

  my $capacity;
  my $description;
  my $numslots;
  my $speed = undef;
  my $type = undef;
  my $banksize;
  my $module_count=0;
  my $empty_slots;
  my $flag=0;
  my $flag_mt=0;
  my $caption;
  my $sun_class=0;
  my $OSLevel;
  my $zone;
  # for debug only
  my $j=0;

  # first, we need determinate on which model of sun server we run,
  # because prtdiags output (and with that memconfs output) is differend
  # from server model to server model
  # we try to classified our box in one of the known classes

   $OSLevel=`uname -r`;	  
  
  if ( $OSLevel =~ /5.8/ || !can_run("zoneadm") ){
	$zone = "global";
  }else{
	  foreach (`zoneadm list -p`){
		$zone=$1 if /^0:([a-z]+):.*$/;
	  } 
  }
    
  #print "Nom :".$zone."*************************\n";
  
  if ($zone)
  {  
  # first, we need determinate on which model of Sun Server we run,
  # because prtdiags output (and with that memconfs output) is differend
  # from server model to server model
  # we try to classified our box in one of the known classes
	$model=`uname -i`;
  # debug print model  
  # cut the CR from string model
	$model = substr($model, 0, length($model)-1);
  }else{
	$model="Solaris Containers";
  }
  
  #print "Memory Model: $model\n";
  
  
  #$model=`uname -i`;
  # debug print model
  #print "Model: '$model'";
  # cut the CR from string model
  #$model = substr($model, 0, length($model)-1);
  # we map (hopfully) our server model to a known class 
  #if ($model eq "SUNW,Sun-Fire-280R") { $sun_class = 1; }
  #if ($model eq "SUNW,Sun-Fire-480R") { $sun_class = 1; }
  #if ($model eq "SUNW,Sun-Fire-V490") { $sun_class = 1; }
  #if ($model eq "SUNW,Sun-Fire-880")  { $sun_class = 1; }
  #if ($model eq "SUNW,Sun-Fire-V240") { $sun_class = 2; }
  #if ($model eq "SUNW,Sun-Fire-V440") { $sun_class = 2; }
  #if ($model eq "SUNW,Sun-Fire-V250") { $sun_class = 2; }
  #if ($model eq "SUNW,Sun-Fire-T200") { $sun_class = 3; }
  #if ($model eq "SUNW,Sun-Fire-T1000") { $sun_class = 3; }
  #if ($model eq "SUNW,SPARC-Enterprise-T5220") { $sun_class = 4; }
  #if ($model eq "SUNW,SPARC-Enterprise") { $sun_class = 5; } # for M5000 && M4000
  
  if ($model  =~ /SUNW,SPARC-Enterprise/) { $sun_class = 5; } # for M5000 && M4000
  if ($model  =~ /SUNW,SPARC-Enterprise-T\d/){ $sun_class = 4; }
  if ($model  =~ /SUNW,Netra-T/){ $sun_class = 2; }
  if ($model  =~ /SUNW,Sun-Fire-\d/){ $sun_class = 1; }
  if ($model  =~ /SUNW,Sun-Fire-V/){ $sun_class = 2; }  
  if ($model  =~ /SUNW,Sun-Fire-V490/) { $sun_class = 1; }
  if ($model  =~ /SUNW,Sun-Fire-T\d/) { $sun_class = 3; }
  if ($model  =~ /SUNW,SPARCstation/) { $sun_class = 3; }
  if ($model  =~ /SUNW,Ultra-/) { $sun_class = 3; }
  if ($model  =~ /SUNW,Sun-Blade-100/) { $sun_class = 8; }
  if ($model  =~ /SUNW,T\d/) { $sun_class = 3; }
  if ($model  =~ /Solaris Containers/){ $sun_class = 7; } 
 
  
  if ($model eq "i86pc") { $sun_class = 6; }
  # debug print model
  #print "Sunclass: $sun_class\n";
  # now we can look at memory information, depending from our class

  if($sun_class == 0) 
  {
    $logger->debug("sorry, unknown model, could not detect memory configuration");
  }

  if($sun_class == 1)
  {
    foreach(`memconf 2>&1`) 
    {
      # debug
      #print "count: " .$j++ . " " . $flag_mt . " : " . "$_";
      # if we find "empty groups:", we have reached the end and indicate that by setting flag = 0
      if(/^empty \w+:\s(\S+)/)
      {
        $flag = 0;
        if($1 eq "None"){$empty_slots = 0;}
      }
      # grep the type of memory modules from heading
      if($flag_mt && /^\s*\S+\s+\S+\s+\S+\s+\S+\s+(\S+)/) {$flag_mt=0; $description = $1;}

      # only grap for information if flag = 1
      if ($flag && /^\s*(\S+)\s+(\S+)/) { $caption = "Board " . $1 . " MemCtl " . $2; }
      if ($flag && /^\s*\S+\s+\S+\s+(\S+)/) { $numslots = $1; }
      if ($flag && /^\s*\S+\s+\S+\s+\S+\s+(\d+)/) { $banksize = $1; }
      if ($flag && /^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\d+)/) { $capacity = $1; }
      if ($flag) 
      {
        for (my $i = 1; $i <= ($banksize / $capacity); $i++)
        {
          #print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " .  $capacity . "MB\n";
          $module_count++;
          $common->addMemory({
            CAPACITY => $capacity,
            DESCRIPTION => $description,
            CAPTION => $caption,
            SPEED => $speed,
            TYPE => $type,
            NUMSLOTS => $numslots
          })
        }
      }
      # this is the caption line 
      if(/^\s+Logical  Logical  Logical/) { $flag_mt = 1; }
      # if we find "---", we set flag = 1, and in next line, we start to look for information
      if(/^-+/){ $flag = 1; }
    }
  #print "# of RAM Modules: " . $module_count . "\n";
  #print "# of empty slots: " . $empty_slots . "\n";
  }
  if($sun_class == 2)
  {
    foreach(`memconf 2>&1`) 
    {
      # debug
      #print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_";
      # if we find "empty sockets:", we have reached the end and indicate that by resetting flag = 0
      # emtpy sockets is follow by a list of emtpy slots, where we extract the slot names
      if(/^empty sockets:\s*(\S+)/)
      {
        $flag = 0;
        # cut of first 15 char containing the string empty sockets:
        substr ($_,0,15) = "";
        $capacity = "empty";
        $numslots = 0;
        foreach $caption (split)
        {
          if ($caption eq "None") 
          {
            $empty_slots = 0;
            # no empty slots -> exit loop
            last;
          }
          # debug
          #print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " .  $capacity . "MB\n";
          $empty_slots++;
          $common->addMemory({
            CAPACITY => $capacity,
            DESCRIPTION => $description,
            CAPTION => $caption,
            SPEED => $speed,
            TYPE => $type,
            NUMSLOTS => $numslots
          })
        }
      }
	if(/.*Memory Module Groups.*/)
	{
		$flag = 0;
		$flag_mt = 0;
	}	
      # we only grap for information if flag = 1
      if($flag && /^\s*\S+\s+\S+\s+(\S+)/){ $caption = $1; }
      if($flag && /^\s*(\S+)/){ $numslots = $1; }
      if($flag && /^\s*\S+\s+\S+\s+\S+\s+(\d+)/){ $capacity = $1; }
      if($flag)
      {
        # debug
        #print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " .  $capacity . "MB\n";
        $module_count++;
        $common->addMemory({
          CAPACITY => $capacity,
          DESCRIPTION => "DIMM",
          CAPTION => "Ram slot ".$numslots,
          SPEED => $speed,
          TYPE => $type,
          NUMSLOTS => $numslots
        })
      }
        # this is the caption line 
      if(/^ID       ControllerID/) { $flag_mt = 1; $description = $1;}
      # if we find "---", we set flag = 1, and in next line, we start to look for information
  		if($flag_mt && /^-+/){ $flag = 1;}
    }
    # debug: show number of modules found and number of empty slots
  }
 
  if($sun_class == 3)
  {
    foreach(`memconf 2>&1`) 
    {
      # debug
      if(/^empty sockets:\s*(\S+)/)
      {
        # cut of first 15 char containing the string empty sockets:
        substr ($_,0,15) = "";
        $capacity = "empty";
        $numslots = 0;
        foreach $caption (split)
        {
          if ($caption eq "None") 
          {
            $empty_slots = 0;
            # no empty slots -> exit loop
            last;
          }
          # debug
          #print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " .  $capacity . "MB\n";
          $empty_slots++;
          $common->addMemory({
            CAPACITY => $capacity,
            DESCRIPTION => $description,
            CAPTION => $caption,
            SPEED => $speed,
            TYPE => $type,
            NUMSLOTS => $numslots
          })
        }
      }
      if(/^socket\s+(\S+) has a (\d+)MB\s+(\(\S+\)\s+)?(\S+)/)
      {
	$caption = $1;
        $description = $4;
        $type = $4;
        $numslots = 0;
        $capacity = $2;
        # debug
        #print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " .  $capacity . "MB\n";
        $module_count++;
        $common->addMemory({
          CAPACITY => $capacity,
          DESCRIPTION => $description,
          CAPTION => $caption,
          SPEED => $speed,
          TYPE => $type,
          NUMSLOTS => $numslots
        })
      }
    }
    # debug: show number of modules found and number of empty slots
    #print "# of RAM Modules: " . $module_count . "\n";
    #print "# of empty slots: " . $empty_slots . "\n";
  }

  if($sun_class == 4)
  {
    foreach(`memconf 2>&1`) 
    {
      # debug
      #print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_";
      # if we find "empty sockets:", we have reached the end and indicate that by resetting flag = 0
      # emtpy sockets is follow by a list of emtpy slots, where we extract the slot names
      if(/^empty sockets:\s*(\S+)/)
      {
        $flag = 0;
        # cut of first 15 char containing the string empty sockets:
        substr ($_,0,15) = "";
        $capacity = "empty";
        $numslots = 0;
        foreach $caption (split)
        {
          if ($caption eq "None") 
          {
            $empty_slots = 0;
            # no empty slots -> exit loop
            last;
          }
          # debug
          print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " .  $capacity . "MB\n";
          $empty_slots++;
          $common->addMemory({
            CAPACITY => $capacity,
            DESCRIPTION => $description,
            CAPTION => $caption,
            SPEED => $speed,
            TYPE => $type,
            NUMSLOTS => $numslots
          })
        }
      }
  
      # we only grap for information if flag = 1
      # socket MB/CMP0/BR0/CH0/D0 has a Samsung 501-7953-01 Rev 05 2GB FB-DIMM
      if(/^socket\s+(\S+) has a (.+)\s+(\S+)GB\s+(\S+)$/i)
      {
	$caption = $1;
        $description = $2;
        $type = $4;
        $numslots = 0;
        $capacity = $3 * 1024;
        # debug
        #print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " .  $capacity . "MB\n";
        $module_count++;
        $common->addMemory({
          CAPACITY => $capacity,
          DESCRIPTION => $description,
          CAPTION => $caption,
          SPEED => $speed,
          TYPE => $type,
          NUMSLOTS => $numslots
        })
      }
    }
    # debug: show number of modules found and number of empty slots
    #print "# of RAM Modules: " . $module_count . "\n";
    #print "# of empty slots: " . $empty_slots . "\n";
  }

  if ($sun_class ==  5 )
  {
    foreach(`memconf 2>&1`)
    {
        # debug
        #print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_";
        # if we find "empty sockets:", we have reached the end and indicate that by resetting flag = 0
        # emtpy sockets is follow by a list of emtpy slots, where we extract the slot names
        if(/^total memory:\s*(\S+)/) { $flag = 0;}

        #print "flag : $flag\n";
        if($flag_mt && /^\s+\S+\s+\S+\s+\S+\s+(\S+)/) {$flag_mt=0;  $description = $1;}
        #print "description : $description\n";

        if ($flag && /^\s(\S+)\s+(\S+)/) { $numslots = "LSB " . $1 . " Group " . $2; }
        if ($flag && /^\s(\S+)\s+(\S+)/) { $caption = "LSB " . $1 . " Group " . $2; }
        if ($flag && /^\s+\S+\s+\S\s+\S+\s+\S+\s+(\d+)/) { $capacity = $1; }
        if ($flag && /^\s+\S+\s+\S\s+(\d+)/) { $banksize = $1; }
        #print "Num slot ". $numslots  . " Bank Number: " . $numslots . " Bank size " .  $banksize . " DIMM Capacity: " .  $capacity . "MB\n";
        if ($flag && $capacity > 1 )
        {
                for (my $i = 1; $i <= ($banksize / $capacity); $i++)
                {
                #print "caption ". $caption  . " Bank Number: " . $numslots . " Bank size " .  $banksize . " DIMM Capacity: " .  $capacity . "MB\n";
                $common->addMemory({
                CAPACITY => $capacity,
                DESCRIPTION => $description,
                CAPTION => $caption,
                SPEED => $speed,
                TYPE => $type,
                NUMSLOTS => $module_count
                })
                }
                $module_count++;
        }
        #Caption Line
        if (/^Sun Microsystems/) { $flag_mt=1; $flag=1; }
    }
  }
  if($sun_class == 6)
  {
    foreach(`memconf 2>&1`)
    {
      # debug
      #print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_";
      if(/^empty memory sockets:\s*(\S+)/)
      {
        # cut of first 22 char containing the string empty sockets:
        substr ($_,0,22) = "";
        $capacity = "0";
        $numslots = 0;
        foreach $caption (split(/, /,$_))
        {
          if ($caption eq "None")
          {
            $empty_slots = 0;
            # no empty slots -> exit loop
            last;
          }
          # debug
          #print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " .  $capacity . "MB\n";
          $empty_slots++;
          $common->addMemory({
            CAPACITY => $capacity,
            DESCRIPTION => "empty",
            CAPTION => $caption,
            SPEED => 'n/a',
            TYPE => 'n/a',
            NUMSLOTS => $numslots
          })
        }
      }
      if(/^socket DIMM(\d+):\s+(\d+)MB\s(\S+)/)
      {
        $caption = "DIMM$1";
        $description = "DIMM$1";
        $numslots = $1;
        $capacity = $2;
	$type = $3;
        # debug
        #print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " .  $capacity . "MB\n";
        $module_count++;
        $common->addMemory({
          CAPACITY => $capacity,
          DESCRIPTION => $description,
          CAPTION => $caption,
          SPEED => $speed,
          TYPE => $type,
          NUMSLOTS => $numslots
        })
      }
    }
    # debug: show number of modules found and number of empty slots
    #print "# of RAM Modules: " . $module_count . "\n";
    #print "# of empty slots: " . $empty_slots . "\n";
  }

  if ($sun_class == 7)
  {
  foreach (`prctl -n project.max-shm-memory $$ 2>&1`)
	{
		
		$description = $1 if /^project.(\S+)$/;		
		$capacity = $1 if /^\s*system+\s*(\d+).*$/;		
		if(($description && $capacity)){
			$capacity = $capacity * 1024;
			$numslots = 1 ;
			$description = "Memory Allocated";
			$caption = "Memory Share";
			#print $description."_".$capacity."***\n";
			$common->addMemory({
			  CAPACITY => $capacity,
			  DESCRIPTION => $description,
			  CAPTION => $caption,
			  SPEED => $speed,
			  TYPE => $type,
			  NUMSLOTS => $numslots
			})
		}
	}
  }	
  

  if($sun_class == 8) {
    # example output of a Sun Blade 100 Workstation

    #Sun Microsystems, Inc. Sun Blade 100 (UltraSPARC-IIe 502MHz)
    #Memory Segment Table:
    #-----------------------------------------------------------------------
    #Base Address       Size       Interleave Factor  Contains
    #-----------------------------------------------------------------------
    #0x0                256MB             1           chassis/system-board/DIMM0
    #empty sockets: DIMM1 DIMM2 DIMM3
    #total memory = 256MB

    #Sun Microsystems, Inc. Sun Blade 100 (UltraSPARC-IIe 502MHz)
    #Memory Segment Table:
    #-----------------------------------------------------------------------
    #Base Address       Size       Interleave Factor  Contains
    #-----------------------------------------------------------------------
    #0x0                256MB             1           Label DIMM0
    #0x20000000         256MB             1           Label DIMM1
    #empty sockets: DIMM2 DIMM3
    #total memory = 512MB

    foreach(`memconf 2>&1`) {
      if (/^empty sockets:\s*(.+)/) {
        foreach $caption (split(/ /, $1)) {
          if ($caption eq "None") {
            $empty_slots = 0;
            last;
          }
          $empty_slots++;
 #         print "empty slot\n";
          $common->addMemory({
            CAPACITY => "empty",
            DESCRIPTION => '',
            CAPTION => $caption,
            SPEED => '',
            TYPE => '',
            NUMSLOTS => $numslots
          })
        }
       }
      if (/^0x(\d+)\s+(\d+)MB\s+(\S+)\s+(.+)/) {
        $caption = "$4";
        $description = "";
        $numslots = 0;
        $capacity = $2;
        $type = "";
        # debug
#        print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " .  $capacity . "MB\n";
        $module_count++;
        $common->addMemory({
          CAPACITY => $capacity,
          DESCRIPTION => $description,
          CAPTION => $caption,
          SPEED => $speed,
          TYPE => $type,
          NUMSLOTS => $numslots
        })
      }
    }
  }


}
#run();
1;