Skip to content
Snippets Groups Projects
Commit ed903e97 authored by Eric Sproul's avatar Eric Sproul
Browse files

Allow escaped commas in config parameters. Update Core::SMART docs and stop...

Allow escaped commas in config parameters.  Update Core::SMART docs and stop prefixing metrics with the disk name, as Resmon already uses check_name in the final metric output.
parent a911b45c
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ Core::SMART - pulls SMART values from disk drives ...@@ -16,7 +16,7 @@ Core::SMART - pulls SMART values from disk drives
=head1 SYNOPSIS =head1 SYNOPSIS
Core::SMART { Core::SMART {
sda : smartctl_cmd => /usr/sbin/smartctl , smartctl_args => -d sat sda : smartctl_cmd => /usr/sbin/smartctl , smartctl_args => -d sat\,12
} }
=head1 DESCRIPTION =head1 DESCRIPTION
...@@ -46,14 +46,17 @@ Optional list of additional arguments that will be passed to smartctl. ...@@ -46,14 +46,17 @@ Optional list of additional arguments that will be passed to smartctl.
The default arguments are "-i -A". Any arguments specified here will be The default arguments are "-i -A". Any arguments specified here will be
added to this list. added to this list.
If the argument contains a comma, it must be escaped with a backslash.
=back =back
=head1 METRICS =head1 METRICS
Each of the following metric names will be prefixed with the disk name. The SMART attribute data is highly vendor-specific. Each attribute will produce
two metrics, one with the normalized value and one with the raw value.
The SMART attribute data is highly vendor-specific. Post-processing may be Post-processing may be desirable in specific cases, such as when the value as
desirable in specific cases, such as when the value as hex has special meaning. hex has special meaning.
=over =over
...@@ -71,8 +74,7 @@ Device firmware version as reported in the information section. ...@@ -71,8 +74,7 @@ Device firmware version as reported in the information section.
=item (attribute) =item (attribute)
Each attribute reported in the data section will be returned by name. The value The normalized value of the attribute, expected to be an integer.
will be the normalized value and is expected to be an integer.
=item (attribute)_raw =item (attribute)_raw
...@@ -82,18 +84,6 @@ The raw value of the attribute, expected to be an integer. ...@@ -82,18 +84,6 @@ The raw value of the attribute, expected to be an integer.
=cut =cut
sub new {
# This is only needed if you have initialization code. Most of the time,
# you can skip the new method and just implement a handler method.
my ($class, $check_name, $config) = @_;
my $self = $class->SUPER::new($check_name, $config);
# Add initialization code here
bless($self, $class);
return $self;
}
sub handler { sub handler {
my $self = shift; my $self = shift;
my $config = $self->{config}; my $config = $self->{config};
...@@ -109,18 +99,18 @@ sub handler { ...@@ -109,18 +99,18 @@ sub handler {
foreach my $line (split(/\n/, $output)) { foreach my $line (split(/\n/, $output)) {
if ($line =~ /^Device Model:\s+(.+)$/) { if ($line =~ /^Device Model:\s+(.+)$/) {
$smartdata->{"$self->{check_name}_model"} = [$1, "s"]; $smartdata->{"model"} = [$1, "s"];
} }
elsif ($line =~ /^Serial Number:\s+(.+)$/) { elsif ($line =~ /^Serial Number:\s+(.+)$/) {
$smartdata->{"$self->{check_name}_serial"} = [$1, "s"]; $smartdata->{"serial"} = [$1, "s"];
} }
elsif ($line =~ /^Firmware Version:\s+(.+)$/) { elsif ($line =~ /^Firmware Version:\s+(.+)$/) {
$smartdata->{"$self->{check_name}_fw"} = [$1, "s"]; $smartdata->{"fw"} = [$1, "s"];
} }
# Capture attribute_name, value, raw_value (columns 2,4,10) # Capture attribute_name, value, raw_value (columns 2,4,10)
elsif ($line =~ /^\s*\d+\s(\S+)\s+\S+\s+(\S+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)/) { elsif ($line =~ /^\s*\d+\s(\S+)\s+\S+\s+(\S+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)/) {
$smartdata->{"$self->{check_name}_$1"} = [$2, "i"]; $smartdata->{"$1"} = [$2, "i"];
$smartdata->{"$self->{check_name}_$1_raw"} = [$3, "i"]; $smartdata->{"$1_raw"} = [$3, "i"];
} }
} }
......
...@@ -62,7 +62,8 @@ sub new { ...@@ -62,7 +62,8 @@ sub new {
next if $current eq "BAD_MODULE"; next if $current eq "BAD_MODULE";
my $kvs = {}; my $kvs = {};
my $check_name = $1; my $check_name = $1;
my @params = split(/,/, $2); my @params = split(/(?<!\\),/, $2);
grep { s/\\(.)/$1/ } @params;
grep { $kvs->{$1} = $2 if /^\s*(\S+)\s*=>\s*(\S(?:.*\S)?)\s*$/ } grep { $kvs->{$1} = $2 if /^\s*(\S+)\s*=>\s*(\S(?:.*\S)?)\s*$/ }
@params; @params;
my $object; my $object;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment