Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions check_smart.pl
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@
# Jun 12, 2025: Alexander Kanevskiy - Add usbjmicron devices (6.16.0)
# Dec 15, 2025: Florian Sager - Fix evaluating ATA Error Count: 0 as a warning (6.17.0)
# Dec 15, 2025: Philippe Beaumont - Add areca devices (6.17.0)
# Apr 21, 2026: Claudio Kuenzler - Fix sys path for sudo command (6.17.1)

use strict;
use Getopt::Long;
use File::Basename qw(basename);

my $basename = basename($0);
my $revision = '6.17.0';
my $revision = '6.17.1';

# Standard Nagios return codes
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
Expand Down Expand Up @@ -117,6 +118,24 @@
exit $ERRORS{'OK'};
}

my $sudo_command = '';
my $smart_command = undef;

foreach my $path (@sys_path) {
$sudo_command = "$path/sudo" if ($sudo_command eq '' && -x "$path/sudo");
$smart_command = "$path/smartctl" if (!defined($smart_command) && -x "$path/smartctl");
last if ($sudo_command ne '' && defined($smart_command));
}

if (!defined($smart_command)) {
print "UNKNOWN - Could not find executable smartctl in " . join(", ", @sys_path) . "\n";
exit $ERRORS{'UNKNOWN'};
}

if ($sudo_command ne '') {
$smart_command = "$sudo_command $smart_command";
}

my ($device, $interface) = qw// // '';
if ($opt_d || $opt_g ) {
unless($opt_i){
Expand Down Expand Up @@ -211,18 +230,6 @@
exit $ERRORS{'UNKNOWN'};
}

my $smart_command = undef;
foreach my $path (@sys_path) {
if (-x "$path/smartctl") {
$smart_command = "sudo $path/smartctl";
last;
}
}

if (!defined($smart_command)) {
print "UNKNOWN - Could not find executable smartctl in " . join(", ", @sys_path) . "\n";
exit $ERRORS{'UNKNOWN'};
}

my $exit_status = 'OK';
my $exit_status_local = 'OK';
Expand Down