-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call smartctl and fetch output for a specified device.
- Loading branch information
1 parent
4fa65a8
commit fe89f86
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/perl -w | ||
|
||
use strict; | ||
use warnings; | ||
use Getopt::Long qw(:config no_ignore_case); | ||
|
||
our $VERBOSITY = 0; | ||
|
||
use constant { | ||
STATE_OK => 0, | ||
STATE_WARNING => 1, | ||
STATE_CRITICAL => 2, | ||
STATE_UNKNOWN => 3, | ||
}; | ||
|
||
sub getSmartctl{ | ||
my $smartctl = shift; | ||
my $device = shift; | ||
my $output = `$smartctl -a $device`; | ||
return $output; | ||
} | ||
|
||
MAIN: { | ||
my ($smartctl, $device); | ||
if ( !(GetOptions( | ||
'v|verbose' => sub { $VERBOSITY = 1 }, | ||
'vv' => sub { $VERBOSITY = 2 }, | ||
'vvv' => sub { $VERBOSITY = 3 }, | ||
'h|help' => sub {displayHelp();}, | ||
'p|path=s' => \$smartctl, | ||
'd|device=s' => \$device, | ||
))) { | ||
displayUsage(); | ||
exit(STATE_UNKNOWN); | ||
} | ||
# Check smartclt tool | ||
if(!defined($smartctl)){ | ||
$smartctl = "/usr/sbin/smartctl"; | ||
} | ||
# The device must be present | ||
if(!defined($device)){ | ||
print "Error: Valid device to check is required.\n"; | ||
displayUsage(); | ||
exit(STATE_UNKNOWN); | ||
} | ||
my $output = getSmartctl($smartctl,$device); | ||
print $output; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
= README = | ||
|
||
* Installation hints | ||
** On Ubuntu use | ||
sudo apt-get install libconfig-json-perl | ||
to install the perl library for parsing JSON config files. |