|
1
2
3
4
5
|
#ifndef CHECK_SMART_H
#define CHECK_SMART_H
#include <iostream>
#include <sstream>
|
|
6
|
#include <map>
|
|
7
8
|
#include <stdio.h>
|
|
9
10
|
#include <string.h>
#include <stdlib.h>
|
|
11
12
13
14
|
#include <unistd.h>
#include <sys/time.h>
|
|
15
|
#include "auxiliar.h"
|
|
16
|
|
|
17
18
19
20
21
|
#define OK 0
#define WARN 1
#define CRIT 2
#define UNKN 3
|
|
22
|
#define VERSION "1.4"
|
|
23
24
25
26
27
28
29
30
31
32
33
|
#define SMARTCTL_CMD_ATTRS "/usr/sbin/smartctl -A "
#define SMARTCTL_CMD_INFO "/usr/sbin/smartctl -i "
#define ROTATION_INFO_STR "Rotation Rate:"
#define SSD_DEV_STR "Solid State Device"
#define REALLOC_SEC_COUNT_ID 5
#define CURRENT_PENDING_SEC_ID 197
#define OFFLINE_UNCORRECT_ID 198
#define WEAR_COUNT_ID 177
|
|
34
35
|
#define MEDIA_WEAROUT_ID 233
#define RUNTIME_BAD_BLOCKS_ID 183
|
|
36
37
38
39
|
#define REP_UNCORRECT_ID 187
#define HDD 0
#define SSD 1
|
|
40
41
42
|
using namespace std;
|
|
43
44
|
struct SMARTAttr
{
|
|
45
|
int id;
|
|
46
47
|
string name;
int value;
|
|
48
49
|
int threshold_warn;
int threshold_crit;
|
|
50
|
bool optional;
|
|
51
52
|
unsigned int col;
bool lower_than;
|
|
53
54
55
|
}; typedef struct SMARTAttr SMARTAttr;
|
|
56
57
58
59
60
61
62
63
|
// Attribute definitions
SMARTAttr reallocated = {
.id = REALLOC_SEC_COUNT_ID,
.name = "Reallocated_Sector_Ct",
.value = -1,
.threshold_warn = 0,
.threshold_crit = -1,
.optional = false,
|
|
64
65
|
.col = 9,
.lower_than = false,
|
|
66
67
68
69
70
71
72
|
};
SMARTAttr pending = {
.id = CURRENT_PENDING_SEC_ID,
.name = "Current_Pending_Sector",
.value = -1,
.threshold_warn = 0,
|
|
73
|
.threshold_crit = -1,
|
|
74
|
.optional = false,
|
|
75
76
|
.col = 9,
.lower_than = false,
|
|
77
78
79
80
81
82
83
84
85
|
};
SMARTAttr off_uncorrect = {
.id = OFFLINE_UNCORRECT_ID,
.name = "Offline_Uncorrectable",
.value = -1,
.threshold_warn = 0,
.threshold_crit = 0,
.optional = false,
|
|
86
87
|
.col = 9,
.lower_than = false,
|
|
88
89
90
91
92
93
|
};
SMARTAttr wear = {
.id = WEAR_COUNT_ID,
.name = "Wear_Leveling_Count",
.value = -1,
|
|
94
95
|
.threshold_warn = 20,
.threshold_crit = 10,
|
|
96
|
.optional = true,
|
|
97
98
|
.col = 3,
.lower_than = true,
|
|
99
100
101
102
103
104
|
};
SMARTAttr wearout = {
.id = MEDIA_WEAROUT_ID,
.name = "Media_Wearout_Indicator",
.value = -1,
|
|
105
106
|
.threshold_warn = 20,
.threshold_crit = 10,
|
|
107
|
.optional = true,
|
|
108
109
|
.col = 3,
.lower_than = true,
|
|
110
111
112
113
114
115
116
117
118
|
};
SMARTAttr badblocks = {
.id = RUNTIME_BAD_BLOCKS_ID,
.name = "Runtime_Bad_Block",
.value = -1,
.threshold_warn = 0,
.threshold_crit = 0,
.optional = false,
|
|
119
120
|
.col = 9,
.lower_than = false,
|
|
121
122
123
124
125
126
127
|
};
SMARTAttr rep_uncorrect = {
.id = REP_UNCORRECT_ID,
.name = "Reported_Uncorrect",
.value = -1,
.threshold_warn = 0,
|
|
128
|
.threshold_crit = -1,
|
|
129
|
.optional = false,
|
|
130
131
|
.col = 9,
.lower_than = false,
|
|
132
133
|
};
|
|
134
135
136
137
138
139
|
map<int,SMARTAttr> prepareAttrMap(int driveType);
int getSmartAttrValue(string line);
int getSmartAttrID(string line);
int run_smartctl_cmd(const string command, const char* disk, string* output);
int checkDriveType(const char* disk);
int evalStatus(const char* disk, int driveType, string* status);
|
|
140
141
|
void printVersion();
void printHelp(bool longVersion);
|
|
142
|
void set_timeout(unsigned int sec);
|
|
143
144
|
#endif
|