Subversion Repositories camp_sysinfo_client_3

Rev

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

Rev 153 Rev 157
Line 6... Line 6...
6
 
6
 
7
our $VERSION = '1.0';
7
our $VERSION = '1.0';
8
 
8
 
9
# R. W. Rodolico
9
# R. W. Rodolico
10
# grabs smart readings from all drives in system
10
# grabs smart readings from all drives in system
-
 
11
# note that in the case of some hardware RAID controller, will list the components of a "drive" and the drive itself,
-
 
12
# so you may have up to twice the number of entries than you have physical drives, for example, if you have a megaraid
-
 
13
# controller where each physical drive is also a single logical drive.
11
 
14
 
12
BEGIN {
15
BEGIN {
13
   push @INC, shift;
16
   push @INC, shift;
14
}
17
}
15
 
18
 
Line 22... Line 25...
22
 $value =~ s/^\s+|\s+$//g;
25
 $value =~ s/^\s+|\s+$//g;
23
 return $value;
26
 return $value;
24
}
27
}
25
 
28
 
26
sub getSmartReport {
29
sub getSmartReport {
27
   my $drive = shift;
30
   my ($drive, $type) = @_;
28
   my @report = `smartctl -a /dev/$drive`;
31
   my @report = `smartctl -a $drive $type`;
-
 
32
   chomp @report;
29
   return @report;
33
   return @report;
30
}
34
}
31
 
35
 
32
 
36
 
33
sub getTotalWrites {
37
sub getTotalWrites {
Line 63... Line 67...
63
                                      },
67
                                      },
64
                  'Device Model:'  => { 
68
                  'Device Model:'  => { 
65
                                          'tag' => 'Model',
69
                                          'tag' => 'Model',
66
                                          'regex' => '(.*)'
70
                                          'regex' => '(.*)'
67
                                      },
71
                                      },
-
 
72
                  'Serial number:' => { 
-
 
73
                                          'tag' => 'Serial',
-
 
74
                                          'regex' => '(.*)'
-
 
75
                                      },
68
                  'Serial Number:' => { 
76
                  'Serial Number:' => { 
69
                                          'tag' => 'Serial',
77
                                          'tag' => 'Serial',
70
                                          'regex' => '(.*)'
78
                                          'regex' => '(.*)'
71
                                      },
79
                                      },
72
                  'User Capacity:' => { 
80
                  'User Capacity:' => { 
73
                                          'tag' => 'Capacity',
81
                                          'tag' => 'Capacity',
74
                                          'regex' => '([0-9,]+)'
82
                                          'regex' => '([0-9,]+)'
75
                                      },
83
                                      },
-
 
84
                  'Logical block size:' =>{ 
-
 
85
                                          'tag' => 'Sector Size',
-
 
86
                                          'regex' => '(\d+)'
-
 
87
                                      },
76
                  'Sector Size:'   => { 
88
                  'Sector Size:'   => { 
77
                                          'tag' => 'Sector Size',
89
                                          'tag' => 'Sector Size',
78
                                          'regex' => '(\d+)'
90
                                          'regex' => '(\d+)'
79
                                      },
91
                                      },
80
                  'Rotation Rate:' => { 
92
                  'Rotation Rate:' => { 
Line 98... Line 110...
98
 
110
 
99
 
111
 
100
 
112
 
101
# category we will use for all values found
113
# category we will use for all values found
102
# see sysinfo for a list of valid categories
114
# see sysinfo for a list of valid categories
103
my $CATEGORY = 'system';
115
my $CATEGORY = 'attributes';
104
 
116
 
105
# run the commands necessary to do whatever you want to do
117
# run the commands necessary to do whatever you want to do
106
# The library entered above has some helper routines
118
# The library entered above has some helper routines
107
# validCommandOnSystem -- passed a name, returns the fully qualified path or '' if it does not exist
119
# validCommandOnSystem -- passed a name, returns the fully qualified path or '' if it does not exist
108
# cleanUp - passed a delimiter and a string, does the following (delimiter can be '')
120
# cleanUp - passed a delimiter and a string, does the following (delimiter can be '')
Line 116... Line 128...
116
# the last one. For multiple entries, place on separate lines (ie, newline separated)
128
# the last one. For multiple entries, place on separate lines (ie, newline separated)
117
 
129
 
118
# check for commands we want to run
130
# check for commands we want to run
119
my %commands = ( 
131
my %commands = ( 
120
                  'smartctl' => '',
132
                  'smartctl' => '',
121
                  'geom'     => '',
-
 
122
                  'lsblk'    => '',
-
 
123
               );
133
               );
124
 
134
 
125
# check the commands for validity
135
# check the commands for validity
126
foreach my $command ( keys %commands ) {
136
foreach my $command ( keys %commands ) {
127
   $commands{$command} = &validCommandOnSystem( $command );
137
   $commands{$command} = &validCommandOnSystem( $command );
128
}
138
}
129
 
139
 
130
$commands{'getDrives'} = $commands{ 'lsblk' } ? $commands{'lsblk'} . " | grep disk | cut -d' ' -f1" :
-
 
131
                                  ( $commands{'geom'} ? $commands{'geom'} . " disk list | grep 'Geom name:' | cut -d':' -f 2" : '' );
-
 
132
   
-
 
133
# bail if we don't have the commands we need
140
# bail if we don't have the commands we need
134
exit 1 unless $commands{'getDrives'} and $commands{'smartctl'};
141
exit 1 unless $commands{'smartctl'};
135
 
142
 
136
# Get all the drives on the system
143
# Get all the drives on the system
137
my %allDrives = map { &trim($_) => 0 } `$commands{'getDrives'}`;
144
my %allDrives = map { $_ =~ '(^[a-z0-9/]+)\s+(.*)\#'; ($1,$2) } `smartctl --scan`;
138
 
145
 
-
 
146
#foreach my $key ( keys %allDrives ) { print "$key\t$allDrives{$key}\n"; } die;
139
 
147
 
140
# output the drives and information as tab delimited,
148
# output the drives and information as tab delimited,
141
foreach my $thisDrive ( sort keys %allDrives ) {
149
foreach my $thisDrive ( sort keys %allDrives ) {
142
 #print "$thisDrive\n";
150
 #print "$thisDrive\n";
-
 
151
 print "$CATEGORY\t$thisDrive Type\t$allDrives{$thisDrive}\n";
143
 my @report = &getSmartReport( $thisDrive );
152
 my @report = &getSmartReport( $thisDrive, $allDrives{$thisDrive} );
-
 
153
 #print join( "\n", @report ) . "\n"; die;
144
 my $writes = &getTotalWrites( @report );
154
 my $writes = &getTotalWrites( @report );
145
 my $info = &getInformation( @report );
155
 my $info = &getInformation( @report );
146
 $info->{'writes'} = $writes if $writes > 0;
156
 $info->{'writes'} = $writes if $writes > 0;
147
 #print Dumper( $info );
157
 #print Dumper( $info );
148
 foreach my $key ( keys %$info ) {
158
 foreach my $key ( keys %$info ) {