Skip to content

Commit

Permalink
Get smartclt output
Browse files Browse the repository at this point in the history
Call smartctl and fetch output for a specified device.
  • Loading branch information
gschoenberger committed Jul 23, 2013
1 parent 4fa65a8 commit fe89f86
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.boothen.jsonedit.validation.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.epic.perleditor.perlnature</nature>
<nature>com.boothen.jsonedit.validation.nature</nature>
</natures>
</projectDescription>
50 changes: 50 additions & 0 deletions check_smart_values
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;


}
6 changes: 6 additions & 0 deletions check_smart_values.README
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.

0 comments on commit fe89f86

Please sign in to comment.