-
Notifications
You must be signed in to change notification settings - Fork 11
/
check_ssd_attribs.pl
executable file
·125 lines (107 loc) · 3.97 KB
/
check_ssd_attribs.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/perl -w
# check_ssd_attribs
# Copyright (C) 2016 Mark Janssen -- Sig-I/O Automatisering, [email protected]
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
use strict;
use Getopt::Std;
use lib qw(/usr/lib/nagios/plugins /usr/lib64/nagios/plugins); # possible pathes to your Nagios plugins and utils.pm
use utils qw(%ERRORS);
our($opt_h, $opt_d, $opt_t, $opt_T, $opt_D);
our $failcount = 0;
our $warntext = "";
our $status = "OK";
getopts('hd:t:T:D');
if ( $opt_h ) {
print "Usage: $0 -d drives [-t smartctl-device] [-T TBWritten]\n";
print " -d is the device to check (ex: /dev/sdb)\n";
print " -t is the device type for smartctl (ex: sat+megaraid,3)\n";
print " -T Warranted number of TB's written\n";
exit;
}
our $warrantytbs = 100;
$warrantytbs = $opt_T if $opt_T;
my $smartctl = '/usr/sbin/smartctl'; # Path to smartctl
my $deviceopts = "";
$deviceopts .= "-d $opt_t " if $opt_t;
$deviceopts .= "$opt_d" if $opt_d;
open (SMARTDATA, "$smartctl $deviceopts -A -f brief |") || exitreport('UNKNOWN', "error: Could not execute $smartctl $deviceopts");
while( <SMARTDATA> )
{
next if $_ =~ /^smartctl/;
next if $_ =~ /^Copyright/;
next if $_ =~ /^$/;
next if $_ =~ /^=== START/;
next if $_ =~ /^SMART Attri/;
next if $_ =~ /^Vendor Spec/;
next if $_ =~ /^ID#/;
next if $_ =~ /^ /;
chomp;
print "Got line: '$_'\n" if $opt_D;
my ($id, $attr, $flags, $value, $worst, $thresh, $fail, $raw) = split;
print "ID = $id, Attr = $attr, Fail = $fail, Raw = $raw\n" if $opt_D;
if( $fail ne "-" )
{
$failcount++;
$warntext .= "Attr $attr fail: $fail ";
}
# 177: Wear leveling count
# The value attribute is a percentage, starting at 100
# A disk will continue running when it reaches <20% but then
# Used-Block-Reserve will be going up.
# Link: http://techreport.com/review/27436/the-ssd-endurance-experiment-two-freaking-petabytes/2
if( $id == '177' ) # Wear Leveling count
{
$failcount++ if ( $value <= 60 );
$failcount++ if ( $value <= 20 );
$warntext .= "WLC: $value " if ( $value <= 70 );
}
# 179: Used_Rsvd_Blk_Cnt_Tot
# Total reserved block percentage still available
if ( $id == '179' ) # Used_Rsvd_Blk_Cnt_Tot
{
$failcount++ if ( $value <= 80 );
$failcount++ if ( $value <= 40 );
$warntext .= "Reserved Blocks: $value% " if ($value <= 80);
}
# 181: Program_Fail_Cnt_Total
# 182: Erase_Fail_Count_Total
# 183: Runtime_Bad_Block
# 187: Reported_Uncorrect
if ( $id =~ /181|182|183|187/)
{
$failcount++ if ( $value <= 50 );
$warntext .= "$attr $value " if ($value <= 50);
}
# 241: TOTAL LBA's Written
# Total number of LBA's (512 byte sectors) written to disk
# SSD's are warranted against a MAX number of writes
# SAMSUNG 840 PRO's are warranted against 72 TB or 40GB/day for 5 years
if( $id == '241' ) # Total LBA's written / Samsung
{
my $tbs = int($raw * 512 / 1024 / 1024 / 1024 / 1024);
my $warrantypercentage = int( $tbs / $warrantytbs * 100 );
$warntext .= "Total TB's written: $tbs out of warranted $warrantytbs ($warrantypercentage%)\n";
$failcount++ if ( $warrantypercentage >= 90 );
$failcount++ if ( $warrantypercentage >= 130 );
}
}
my $retval = $failcount;
$retval = 2 if ($failcount >= 2 );
$status = "CRITICAL" if ($retval == 2);
$status = "WARNING" if ($retval == 1);
print STDOUT "$status: $warntext";
exit $retval;