File: Ports.pm

package info (click to toggle)
ocsinventory-agent 2%3A2.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,424 kB
  • sloc: perl: 26,492; xml: 773; objc: 528; sh: 386; ansic: 333; makefile: 12
file content (47 lines) | stat: -rw-r--r-- 1,315 bytes parent folder | download | duplicates (4)
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
package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::Ports;

use strict;

sub run {
    my $params = shift;
    my $common = $params->{common};
  
    my $dmidecode = `dmidecode`; # TODO retrieve error
    # some versions of dmidecode do not separate items with new lines
    # so add a new line before each handle
    $dmidecode =~ s/\nHandle/\n\nHandle/g;
    my @dmidecode = split (/\n/, $dmidecode);
    # add a new line at the end
    push @dmidecode, "\n";
  
    s/^\s+// for (@dmidecode);
  
    my $flag;
  
    my $caption;
    my $description;
    my $name;
    my $type;
  
    foreach (@dmidecode) {
        if (/dmi type 8,/i) {
            $flag = 1;
        } elsif ($flag && /^$/){ # end of section
            $flag = 0;
            $common->addPorts({
                CAPTION => $caption,
                DESCRIPTION => $description,
                NAME => $name,
                TYPE => $type,
            });
            $caption = $description = $name = $type = undef;
        } elsif ($flag) {
            $caption = $1 if /^external connector type\s*:\s*(.+)/i;
            $description = $1 if /^internal connector type\s*:\s*(.+)/i;
            $name = $1 if /^internal reference designator\s*:\s*(.+)/i;
            $type = $1 if /^port type\s*:\s*(.+)/i;
        }
    }
}

1;