Subversion Repositories camp_sysinfo_client_3

Rev

Rev 169 | Rev 198 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 169 Rev 170
Line 33... Line 33...
33
my %ignoreDriveTypes = ( # a list of drive "types" used by virtuals that we just ignore.
33
my %ignoreDriveTypes = ( # a list of drive "types" used by virtuals that we just ignore.
34
         'VBOX HARDDISK' => 1,
34
         'VBOX HARDDISK' => 1,
35
         );
35
         );
36
 
36
 
37
 
37
 
-
 
38
# routine used by geom to process one block at a time.
-
 
39
# first parameter is a pointer to a hash to populate, the rest are
-
 
40
# considered to be a splice of an array that contains only one
-
 
41
# block. Returns the name of the device
-
 
42
sub doGeomBlock {
-
 
43
   my $hashPointer = shift;
-
 
44
#   die join( "\n", @_ ) . "\n";
-
 
45
   while ( my $line = shift ) {
-
 
46
      if ( $line ) {
-
 
47
         my ($key, $value) = split( ':', $line );
-
 
48
         if ( $key =~ m/^\d+\.\s+(.*)$/ ) {
-
 
49
            $key = $1;
-
 
50
         }
-
 
51
         $key = &trim( $key );
-
 
52
         $value = &trim( $value );
-
 
53
         $hashPointer->{$key} = $value;
-
 
54
      }
-
 
55
   }
-
 
56
#   die Dumper( $hashPointer );
-
 
57
   return $hashPointer->{'Name'} ? $hashPointer->{'Name'} : 'Unknown';
-
 
58
}
-
 
59
 
-
 
60
# grab data from geom command (BSD) and import parts of it into driveDefinitions
-
 
61
sub geom {
-
 
62
   my $line = 0;
-
 
63
   my $startBlock = 0;
-
 
64
   my $endBlock = 0;
-
 
65
   my @report = `geom disk list`;
-
 
66
   chomp @report;
-
 
67
 
-
 
68
   while ( $line < scalar( @report ) ) {
-
 
69
      #print "Working on $line\n";
-
 
70
      while ( $line < scalar( @report ) && $report[$line] !~ m/^Geom name:\s+(.*)$/ ) {
-
 
71
         $line++;
-
 
72
      }
-
 
73
      $endBlock = $line - 1;
-
 
74
      if ( $endBlock > $startBlock ) {
-
 
75
         my $thisDrive = {};
-
 
76
         my $key = &doGeomBlock( $thisDrive, @report[$startBlock..$endBlock] );
-
 
77
         # die "$key\n" . Dumper( $thisDrive );
-
 
78
         $key = '/dev/' . $key;
-
 
79
         $driveDefinitions{$key}{'Capacity'} = $thisDrive->{'Mediasize'} if defined $thisDrive->{'Mediasize'};
-
 
80
         if ( defined( $driveDefinitions{$key}{'Capacity'} ) && $driveDefinitions{$key}{'Capacity'} =~ m/^(\d+)/ ) {
-
 
81
            $driveDefinitions{$key}{'Capacity'} = $1;
-
 
82
         }
-
 
83
         $driveDefinitions{$key}{'Model'} = $thisDrive->{'descr'} if defined $thisDrive->{'descr'};
-
 
84
         $driveDefinitions{$key}{'Serial'} = $thisDrive->{'ident'} if defined $thisDrive->{'ident'};
-
 
85
         $driveDefinitions{$key}{'Sector Size'} = $thisDrive->{'Sectorsize'} if defined $thisDrive->{'Sectorsize'};
-
 
86
         $driveDefinitions{$key}{'Rotation'} = $thisDrive->{'rotationrate'} if defined $thisDrive->{'rotationrate'};
-
 
87
 
-
 
88
         $startBlock = $line;
-
 
89
#         die Dumper( $thisDrive );
-
 
90
      }
-
 
91
      $line++;
-
 
92
   }
-
 
93
 
-
 
94
}
-
 
95
 
-
 
96
 
-
 
97
 
38
# acquires information using lsblk, if it is available
98
# acquires information using lsblk, if it is available
39
# uses global %driveDefinitions to store the results
99
# uses global %driveDefinitions to store the results
40
 
100
 
41
sub lsblk {
101
sub lsblk {
42
   eval ( 'use JSON qw( decode_json );' );
102
   eval ( 'use JSON qw( decode_json );' );
Line 227... Line 287...
227
exit 1 unless $commands{'smartctl'} || $commands{'lsblk'} || $commands{'geom'};
287
exit 1 unless $commands{'smartctl'} || $commands{'lsblk'} || $commands{'geom'};
228
 
288
 
229
# first, get basic information using lsblk for linux systems
289
# first, get basic information using lsblk for linux systems
230
&lsblk() if $commands{'lsblk'};
290
&lsblk() if $commands{'lsblk'};
231
# now, try geom for bsd systems
291
# now, try geom for bsd systems
232
#&geom() if $commands{'geom'};
292
&geom() if $commands{'geom'};
-
 
293
 
-
 
294
#die Dumper( \%driveDefinitions );
233
# finally, populate whatever using smartctl if it is on system.
295
# finally, populate whatever using smartctl if it is on system.
234
&smartctl() if $commands{'smartctl'};
296
&smartctl() if $commands{'smartctl'};
235
 
297
 
236
for my $drive ( sort keys %driveDefinitions ) {
298
for my $drive ( sort keys %driveDefinitions ) {
237
   # don't print iSCSI definitions
299
   # don't print iSCSI definitions