Subversion Repositories camp_sysinfo_client_3

Rev

Rev 198 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 198 Rev 203
Line 135... Line 135...
135
   return \%reportHash;
135
   return \%reportHash;
136
} # getSmartInformationReport
136
} # getSmartInformationReport
137
 
137
 
138
sub getSmartAttributeReport {
138
sub getSmartAttributeReport {
139
   my ($drive, $type) = @_;
139
   my ($drive, $type) = @_;
140
   $type = '' if ( $type =~ m/scsi/ );
140
   $type = '' if ( ! defined( $type ) || $type =~ m/scsi/ );
141
   my @report = `smartctl -A $drive $type`;
141
   my @report = `smartctl -A $drive $type`;
142
   chomp @report;
142
   chomp @report;
143
   my %reportHash;
143
   my %reportHash;
144
   my %headers;
144
   my %headers;
145
   # bypass all the header information
145
   # bypass all the header information
Line 176... Line 176...
176
   my ($drive,$type,$sectorSize) = @_;
176
   my ($drive,$type,$sectorSize) = @_;
177
 
177
 
178
   my $report = &getSmartAttributeReport( $drive, $type );
178
   my $report = &getSmartAttributeReport( $drive, $type );
179
 
179
 
180
   # first let's get total disk writes
180
   # first let's get total disk writes
181
   if ( defined( $report->{'241'} ) ) {
181
   if ( defined( $report->{'241'} ) && defined( $sectorSize ) ) {
182
      $sectorSize =~ m/^(\d+)/;
182
      $sectorSize =~ m/^(\d+)/;
183
      $driveDefinitions{$drive}{'writes'} = $report->{'241'} * $sectorSize;
183
      $driveDefinitions{$drive}{'writes'} = $report->{'241'} * $sectorSize;
184
   }
184
   }
185
   # find total uptime
185
   # find total uptime
186
   if ( defined( $report->{'9'} ) ) {
186
   if ( defined( $report->{'9'} ) ) {
Line 236... Line 236...
236
   }
236
   }
237
}
237
}
238
 
238
 
239
sub smartctl {
239
sub smartctl {
240
   # Get all the drives on the system
240
   # Get all the drives on the system
-
 
241
   my %allDrives;
-
 
242
   eval{ 
241
   my %allDrives = map { $_ =~ '(^[a-z0-9/]+)\s+(.*)\#'; ($1,$2) } `smartctl --scan`;
243
      %allDrives = map { $_ =~ '(^[a-z0-9/]+)\s+(.*)\#'; ($1,$2) } `smartctl --scan`; 
-
 
244
   };
-
 
245
   return if ( $@ ); # we failed to get anything back
-
 
246
      
242
 
247
 
243
   # output the drives and information as tab delimited,
248
   # output the drives and information as tab delimited,
244
   foreach my $thisDrive ( sort keys %allDrives ) {
249
   foreach my $thisDrive ( sort keys %allDrives ) {
245
      $driveDefinitions{$thisDrive}{'type'} = $allDrives{$thisDrive};
250
      $driveDefinitions{$thisDrive}{'type'} = $allDrives{$thisDrive};
246
      &getInformation( $thisDrive, $allDrives{$thisDrive} );
251
      &getInformation( $thisDrive, $allDrives{$thisDrive} );
Line 302... Line 307...
302
   next if ( defined( $driveDefinitions{$drive}{'Model'} ) && defined( $ignoreDriveTypes{ $driveDefinitions{$drive}{'Model'} }  ) );
307
   next if ( defined( $driveDefinitions{$drive}{'Model'} ) && defined( $ignoreDriveTypes{ $driveDefinitions{$drive}{'Model'} }  ) );
303
   
308
   
304
   # remove comma's from capacity
309
   # remove comma's from capacity
305
   $driveDefinitions{$drive}{'Capacity'} =~ s/,//g if $driveDefinitions{$drive}{'Capacity'};
310
   $driveDefinitions{$drive}{'Capacity'} =~ s/,//g if $driveDefinitions{$drive}{'Capacity'};
306
   foreach my $key ( sort keys %{$driveDefinitions{$drive}} ) {
311
   foreach my $key ( sort keys %{$driveDefinitions{$drive}} ) {
307
      print "$CATEGORY\t$drive $key\t$driveDefinitions{$drive}{$key}\n";
312
      print "$CATEGORY\t$drive $key\t$driveDefinitions{$drive}{$key}\n" if defined $driveDefinitions{$drive}{$key};
308
   }
313
   }
309
}
314
}
310
 
315
 
311
 
316
 
312
exit 0;
317
exit 0;