source: ocsinventory-agent/trunk/fuentes/lib/Ocsinventory/Agent/Backend/OS/Generic/Dmidecode/Memory.pm @ 468

Last change on this file since 468 was 468, checked in by mabarracus, 4 years ago

Copyt trusty code

File size: 1.4 KB
Line 
1package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::Memory;
2use strict;
3
4sub run {
5  my $params = shift;
6  my $common = $params->{common};
7
8  my $dmidecode = `dmidecode`; # TODO retrieve error
9  # some versions of dmidecode do not separate items with new lines
10  # so add a new line before each handle
11  $dmidecode =~ s/\nHandle/\n\nHandle/g;
12  my @dmidecode = split (/\n/, $dmidecode);
13  # add a new line at the end
14  push @dmidecode, "\n";
15
16  s/^\s+// for (@dmidecode);
17
18  my $flag;
19
20  my $capacity;
21  my $speed;
22  my $type;
23  my $description;
24  my $numslot;
25  my $caption;
26  my $serialnumber;
27
28  foreach (@dmidecode) {
29
30    if (/dmi type 17,/i) { # begining of Memory Device section
31      $flag = 1;
32      $numslot++;
33    } elsif ($flag && /^$/) { # end of section
34      $flag = 0;
35
36      $common->addMemory({
37
38          CAPACITY => $capacity,
39          DESCRIPTION => $description,
40          CAPTION => $caption,
41          SPEED => $speed,
42          TYPE => $type,
43          NUMSLOTS => $numslot,
44          SERIALNUMBER => $serialnumber,
45        });
46
47      $capacity = $description = $caption = $type = $type = $serialnumber = undef;
48    } elsif ($flag) { # in the section
49
50      $capacity = $1 if /^size\s*:\s*(\S+)/i;
51      $description = $1 if /^Form Factor\s*:\s*(.+)/i;
52      $caption = $1 if /^Locator\s*:\s*(.+)/i;
53      $speed = $1 if /^speed\s*:\s*(.+)/i;
54      $type = $1 if /^type\s*:\s*(.+)/i;
55      $serialnumber = $1 if /^Serial Number\s*:\s*(.+)/i;
56
57
58    }
59  }
60}
61
621;
Note: See TracBrowser for help on using the repository browser.