mirror of
https://github.com/librenms/librenms-agent.git
synced 2024-05-09 09:54:52 +00:00
tested and it appears to work properly... documentation updated
This commit is contained in:
43
snmp/smart
43
snmp/smart
@ -38,14 +38,17 @@ will be /etc/snmp/smart.config. Alternatively you can also specific a config via
|
|||||||
|
|
||||||
Anything starting with a # is comment. The format for variables is $variable=$value. Empty
|
Anything starting with a # is comment. The format for variables is $variable=$value. Empty
|
||||||
lines are ignored. Spaces and tabes at either the start or end of a line are ignored. Any
|
lines are ignored. Spaces and tabes at either the start or end of a line are ignored. Any
|
||||||
line with out a = or # are treated as a disk.
|
line with out a matched variable or # are treated as a disk.
|
||||||
|
|
||||||
#This is a comment
|
#This is a comment
|
||||||
cache=/var/cache/smart
|
cache=/var/cache/smart
|
||||||
smartctl=/usr/local/sbin/smartctl
|
smartctl=/usr/local/sbin/smartctl
|
||||||
useSN=0
|
useSN=0
|
||||||
ada0
|
ada0
|
||||||
ada1
|
da5 /dev/da5 -d sat
|
||||||
|
twl0,0 /dev/twl0 -d 3ware,0
|
||||||
|
twl0,1 /dev/twl0 -d 3ware,1
|
||||||
|
twl0,2 /dev/twl0 -d 3ware,2
|
||||||
|
|
||||||
The variables are as below.
|
The variables are as below.
|
||||||
|
|
||||||
@ -54,8 +57,13 @@ The variables are as below.
|
|||||||
useSN = If set to 1, it will use the disks SN for reporting instead of the device name.
|
useSN = If set to 1, it will use the disks SN for reporting instead of the device name.
|
||||||
1 is the default. 0 will use the device name.
|
1 is the default. 0 will use the device name.
|
||||||
|
|
||||||
|
A disk line is can be as simple as just a disk name under /dev/. Such as in the config above
|
||||||
|
The line "ada0" would resolve to "/dev/ada0" and would be called with no special argument. If
|
||||||
|
a line has a space in it, everything before the space is treated as the disk name and is what
|
||||||
|
used for reporting and everything after that is used as the argument to be passed to smartctl.
|
||||||
|
|
||||||
If you want to guess at the configuration, call it with -g and it will print out what it thinks
|
If you want to guess at the configuration, call it with -g and it will print out what it thinks
|
||||||
it should be.
|
it should be.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
@ -194,25 +202,30 @@ my @configA=split(/\n/, $config_file);
|
|||||||
my $configA_int=0;
|
my $configA_int=0;
|
||||||
while ( defined( $configA[$configA_int] ) ){
|
while ( defined( $configA[$configA_int] ) ){
|
||||||
my $line=$configA[$configA_int];
|
my $line=$configA[$configA_int];
|
||||||
|
chomp($line);
|
||||||
$line=~s/^[\t\s]+//;
|
$line=~s/^[\t\s]+//;
|
||||||
$line=~s/[\t\s]+$//;
|
$line=~s/[\t\s]+$//;
|
||||||
|
|
||||||
my ( $var, $val )=split(/=/, $line, 2);
|
my ( $var, $val )=split(/=/, $line, 2);
|
||||||
|
|
||||||
|
my $matched;
|
||||||
if ( $var eq 'cache' ){
|
if ( $var eq 'cache' ){
|
||||||
$cache=$val;
|
$cache=$val;
|
||||||
|
$matched=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $var eq 'smartctl' ){
|
if ( $var eq 'smartctl' ){
|
||||||
$smartctl=$val;
|
$smartctl=$val;
|
||||||
|
$matched=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $var eq 'useSN' ){
|
if ( $var eq 'useSN' ){
|
||||||
$useSN=$val;
|
$useSN=$val;
|
||||||
|
$matched=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !defined( $val ) ){
|
if ( !defined( $val ) ){
|
||||||
push(@disks, $var);
|
push(@disks, $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
$configA_int++;
|
$configA_int++;
|
||||||
@ -238,11 +251,22 @@ if ( ! defined( $opts{u} ) ){
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $toReturn='';
|
my $toReturn='';
|
||||||
my $int=0;
|
foreach my $line ( @disks ){
|
||||||
while ( defined($disks[$int]) ) {
|
my $disk;
|
||||||
my $disk=$disks[$int];
|
my $name;
|
||||||
|
if ( $line =~ /\ / ){
|
||||||
|
($name, $disk)=split(/\ /, $line, 2);
|
||||||
|
}else{
|
||||||
|
$disk=$line;
|
||||||
|
$name=$line;
|
||||||
|
}
|
||||||
my $disk_sn=$disk;
|
my $disk_sn=$disk;
|
||||||
my $output=`$smartctl -A /dev/$disk`;
|
my $output;
|
||||||
|
if ( $disk =~ /\// ){
|
||||||
|
$output=`$smartctl -A $disk`;
|
||||||
|
}else{
|
||||||
|
$output=`$smartctl -A /dev/$disk`;
|
||||||
|
}
|
||||||
|
|
||||||
my %IDs=( '5'=>'null',
|
my %IDs=( '5'=>'null',
|
||||||
'10'=>'null',
|
'10'=>'null',
|
||||||
@ -333,7 +357,7 @@ while ( defined($disks[$int]) ) {
|
|||||||
my $selective=scalar grep(/Selective/, @outputA);
|
my $selective=scalar grep(/Selective/, @outputA);
|
||||||
|
|
||||||
# get the drive serial number, if needed
|
# get the drive serial number, if needed
|
||||||
my $disk_id=$disk;
|
my $disk_id=$name;
|
||||||
if ( $useSN ){
|
if ( $useSN ){
|
||||||
while (`$smartctl -i /dev/$disk` =~ /Serial Number:(.*)/g) {
|
while (`$smartctl -i /dev/$disk` =~ /Serial Number:(.*)/g) {
|
||||||
$disk_id = $1;
|
$disk_id = $1;
|
||||||
@ -345,7 +369,6 @@ while ( defined($disks[$int]) ) {
|
|||||||
.','.$IDs{'190'} .','.$IDs{'194'}.','.$IDs{'196'}.','.$IDs{'197'}.','.$IDs{'198'}.','.$IDs{'199'}.','.$IDs{'231'}.','.$IDs{'233'}.','.
|
.','.$IDs{'190'} .','.$IDs{'194'}.','.$IDs{'196'}.','.$IDs{'197'}.','.$IDs{'198'}.','.$IDs{'199'}.','.$IDs{'231'}.','.$IDs{'233'}.','.
|
||||||
$completed.','.$interrupted.','.$read_failure.','.$unknown_failure.','.$extended.','.$short.','.$conveyance.','.$selective."\n";
|
$completed.','.$interrupted.','.$read_failure.','.$unknown_failure.','.$extended.','.$short.','.$conveyance.','.$selective."\n";
|
||||||
|
|
||||||
$int++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $noWrite ){
|
if ( ! $noWrite ){
|
||||||
|
Reference in New Issue
Block a user