File: Slots.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 (116 lines) | stat: -rw-r--r-- 2,775 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
package Ocsinventory::Agent::Backend::OS::Solaris::Slots;

use strict;
sub check { can_run ("prtdiag") }

sub run {
  my $params = shift;
  my $common = $params->{common};

  my $description;
  my $designation;
  my $name;
  my $status;  
  my @pci;
  my $flag;
  my $flag_pci;
  my $model;
  my $sun_class;

  $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,SPARC-Enterprise") { $sun_class = 1; }
  if ($model eq "SUNW,SPARC-Enterprise-T5120") { $sun_class = 2 ; }
  else { $sun_class = 0; }
  #Debug
  #print "sun_class : $sun_class\n";


    foreach (`prtdiag `) {
    #print $_."\n";
 
   if ( $sun_class == 0 )
   {
    last if(/^\=+/ && $flag_pci);
    next if(/^\s+/ && $flag_pci);
    if($flag && $flag_pci && /^(\S+)\s+/){
      $name = $1;
    }
    if($flag && $flag_pci && /(\S+)\s*$/){
      $designation = $1;
    }
    if($flag && $flag_pci && /^\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)/){
      $description = $1;
    }
    if($flag && $flag_pci && /^\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)/){
      $status = $1;
    }
    if($flag && $flag_pci){
      $common->addSlot({
          DESCRIPTION =>  $description,
          DESIGNATION =>  $designation,
          NAME            =>  $name,
          STATUS          =>  $status,
          });
    }
    if(/^=+\s+IO Cards/){$flag_pci = 1;}
    if($flag_pci && /^-+/){$flag = 1;}

   }
   
   if ( $sun_class == 1 )
   {
	last if(/^\=+/ && $flag_pci && $flag);
	
	if($flag && $flag_pci && /^\s+(\d+)/){
           $name = "LSB " . $1;	 
	}
 	if($flag && $flag_pci && /^\s+\S+\s+(\S+)/){
                $description = $1;
        }
        if($flag && $flag_pci && /^\s+\S+\s+\S+\s+(\S+)/){
                $designation = $1;
        }
	$status = " ";
	
	#Debug
	#if ($flag && $flag_pci){print "$name" . "||||" . "$designation" . "||" . "$description\n";}
    	#print $_."\n";

        if($flag && $flag_pci){
        $common->addSlot({
          DESCRIPTION =>  $description,
          DESIGNATION =>  $designation,
          NAME            =>  $name,
          STATUS          =>  $status,
          });
        }
        if(/^=+\S+\s+IO Cards/){$flag_pci = 1;  }
        if($flag_pci && /^-+/){$flag = 1;}
   }
   if ( $sun_class == 2 )
   {
	if (/pci/)
	{
	@pci = split(/ +/);
	$name=$pci[4]." ".$pci[5];
	$description=$pci[0]." (".$pci[1].")";
	$designation=$pci[3];
	$status="";
	$common->addSlot({
          DESCRIPTION =>  $description,
          DESIGNATION =>  $designation,
          NAME            =>  $name,
          STATUS          =>  $status,
          });
	
	}
	
   }
  }
}
1;