Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 rodolico 1
#! /usr/bin/perl -w
2
 
3
# gets information on pci information assuming lspci is installed
4
# I really don't remember how I wrote this originally, so I just put everything
5
# into the has (as done in v2), then print the hash. Unneccessarily wasteful of memory
6
 
7
BEGIN {
8
   push @INC, shift;
9
}
10
 
11
use library;
12
 
13
my $command = &validCommandOnSystem('lspci');
14
exit 1 unless $command;
15
 
16
 
17
my $CATEGORY = 'pci';
18
 
19
my $pciInfo =  qx(lspci -Dvmm);
20
 
21
# this is a regular expression to "find" the slot number, if one exists
22
# Different versions of lspci use different keys for the name and the slot
23
# in some cases, the key Device: is used for both the device name and the slot (Debian Etch lspci version 2.2.4-pre4)
24
# so I have to use this kludge. I may rewrite it to just search the sys directory tree later.
25
my $SLOT_REGEX = '^[0-9a-z]+[:.][0-9a-z]+';
26
my @pciInfo = split ("\n\n", $pciInfo);
27
my $i = 0;
28
while (my $test = shift (@pciInfo)) {
29
   foreach my $thisLine (sort split("\n", $test)) {
30
      if ($thisLine =~ m/([a-z]+):\s*(\S.*)/i) {
31
         my ($key, $value) = (lc $1,$2);
32
         # remove any leading whitespace
33
         $key =~ s/^\s*//g;
34
         $value =~ s/^\s*//g;
35
         while (defined($returnValue{$i}{$key})) { # dup key, so give it a unique value
36
            $key .= '0'; # just add some 0's at the end
37
         }
38
         $returnValue{$i}{$key} = $value;
39
      }
40
   }
41
   unless (defined $returnValue{$i}{'slot'}) { # no slot number, so see if we have one
42
      $returnValue{$i}{'slot'} = 'Unknown';
43
      for my $thisKey ( keys %{$returnValue{$i}} ) {
44
            if ($returnValue{$i}{$thisKey} =~ m/$SLOT_REGEX/i) {
45
            $returnValue{$i}{'slot'} = $returnValue{$i}{$thisKey}; # this puts it in two places, so remove the original
46
            delete $returnValue{$i}{$thisKey};
47
            last;
48
            }
49
         }
50
   }
51
 
52
   if (defined ($returnValue{$i}{'name'})) { # we need to not have this; it messes up the xml package
53
      $returnValue{$i}{'device name'} = $returnValue{$i}{'name'};
54
      delete $returnValue{$i}{'name'}
55
   }
56
   unless (defined ($returnValue{$i}{'name'})) { # no name, so see if we have one
57
      $returnValue{$i}{'name'} = 'Unknown';
58
      foreach my $thisKey ( 'slot', 'device', 'device0', 'sdevice', 'class', 'vendor', 'svendor' ) {
59
         if (defined($returnValue{$i}{$thisKey}) && ($returnValue{$i} ne 'Unknown') ) {
60
            $returnValue{$i}{'name'} = $returnValue{$i}{$thisKey};
61
            last;
62
         }
63
      }
64
   }
65
   $i++;
66
}
67
 
68
foreach my $key ( keys %returnValue ) {
69
   my $name = $returnValue{$key}{'name'};
70
   my $temp = $returnValue{$key};
71
   foreach my $info ( keys %$temp ) {
72
      print "$CATEGORY\t$name\t$info\t" . $$temp{$info} . "\n" unless $info eq 'name';
73
   }
74
}