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

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

Copyt trusty code

File size: 1.1 KB
Line 
1package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::Slots;
2
3use strict;
4
5sub run {
6  my $params = shift;
7  my $common = $params->{common};
8
9  my $dmidecode = `dmidecode`;
10  # some versions of dmidecode do not separate items with new lines
11  # so add a new line before each handle
12  $dmidecode =~ s/\nHandle/\n\nHandle/g;
13  my @dmidecode = split (/\n/, $dmidecode);
14  # add a new line at the end
15  push @dmidecode, "\n";
16
17  s/^\s+// for (@dmidecode);
18
19  my $flag;
20
21  my $description;
22  my $designation;
23  my $name;
24  my $status;
25
26
27  foreach (@dmidecode) {
28
29    if(/dmi type 9,/i) {
30      $flag=1;
31    } elsif ($flag && /^$/) {
32      $flag=0;
33
34      $common->addSlot({
35          DESCRIPTION =>  $description,
36          DESIGNATION =>  $designation,
37          NAME =>  $name,
38          STATUS =>  $status,
39
40          });
41
42      $description = $designation = $name = $status = undef;
43
44    } elsif ($flag) {
45
46      $description = $1 if /^type\s*:\s*(.+)/i;
47      $designation = $1 if /^id\s*:\s*(.+)/i;
48      $name = $1 if /^designation\s*:\s*(.+)/i;
49      $status = $1 if /^current usage\s*:\s*(.+)/i;
50
51    };
52  }
53
54}
55
561;
Note: See TracBrowser for help on using the repository browser.