Blame view

check_smart/check_smart.h 3.2 KB
Imanol-Mikel Barba Sabariego authored
1
2
3
4
5
#ifndef CHECK_SMART_H
#define CHECK_SMART_H

#include <iostream>
#include <sstream>
6
#include <map>
Imanol-Mikel Barba Sabariego authored
7
8

#include <stdio.h>
9
10
#include <string.h>
#include <stdlib.h>
Imanol-Mikel Barba Sabariego authored
11
12
13
14
#include <unistd.h>

#include <sys/time.h>
Imanol-Mikel Barba Sabariego authored
15
#include "auxiliar.h"
Imanol-Mikel Barba Sabariego authored
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
Imanol-Mikel Barba Sabariego authored
34
35
#define MEDIA_WEAROUT_ID 233
#define RUNTIME_BAD_BLOCKS_ID 183
36
37
#define REP_UNCORRECT_ID 187
Imanol-Mikel Barba Sabariego authored
38
39
40
41
42
43
44
45
46
#define REALLOC_SEC_COUNT_NAME "Reallocated_Sector_Ct"
#define CURRENT_PENDING_SEC_NAME "Current_Pending_Sector"
#define OFFLINE_UNCORRECT_NAME "Offline_Uncorrectable"
#define WEAR_COUNT_NAME "Wear_Leveling_Count"
#define MEDIA_WEAROUT_NAME "Media_Wearout_Indicator"
#define RUNTIME_BAD_BLOCKS_NAME "Runtime_Bad_Block"
#define REP_UNCORRECT_NAME "Reported_Uncorrect"
#define UNCORRECT_COUNT_NAME "Uncorrectable_Error_Cnt"
47
48
#define HDD 0
#define SSD 1
Imanol-Mikel Barba Sabariego authored
49
50
51

using namespace std;
52
53
struct SMARTAttr
{
Imanol-Mikel Barba Sabariego authored
54
  int id;
55
56
  string name;
  int value;
Imanol-Mikel Barba Sabariego authored
57
58
  int threshold_warn;
  int threshold_crit;
59
  bool optional;
60
61
  unsigned int col;
  bool lower_than;
62
63
64
}; typedef struct SMARTAttr SMARTAttr;
Imanol-Mikel Barba Sabariego authored
65
66
67
68
69
70
71
72
// Attribute definitions
SMARTAttr reallocated = {
  .id = REALLOC_SEC_COUNT_ID,
  .name = "Reallocated_Sector_Ct",
  .value = -1,
  .threshold_warn = 0,
  .threshold_crit = -1,
  .optional = false,
73
74
  .col = 9,
  .lower_than = false,
Imanol-Mikel Barba Sabariego authored
75
76
77
78
79
80
81
};

SMARTAttr pending = {
  .id = CURRENT_PENDING_SEC_ID,
  .name = "Current_Pending_Sector",
  .value = -1,
  .threshold_warn = 0,
82
  .threshold_crit = -1,
Imanol-Mikel Barba Sabariego authored
83
  .optional = false,
84
85
  .col = 9,
  .lower_than = false,
Imanol-Mikel Barba Sabariego authored
86
87
88
89
90
91
92
93
94
};

SMARTAttr off_uncorrect = {
  .id = OFFLINE_UNCORRECT_ID,
  .name = "Offline_Uncorrectable",
  .value = -1,
  .threshold_warn = 0,
  .threshold_crit = 0, 
  .optional = false,
95
96
  .col = 9,
  .lower_than = false,
Imanol-Mikel Barba Sabariego authored
97
98
99
100
101
102
};

SMARTAttr wear = {
  .id = WEAR_COUNT_ID,
  .name = "Wear_Leveling_Count",
  .value = -1,
103
104
  .threshold_warn = 20,
  .threshold_crit = 10, 
Imanol-Mikel Barba Sabariego authored
105
  .optional = true,
106
107
  .col = 3,
  .lower_than = true,
Imanol-Mikel Barba Sabariego authored
108
109
110
111
112
113
};

SMARTAttr wearout = {
  .id = MEDIA_WEAROUT_ID,
  .name = "Media_Wearout_Indicator",
  .value = -1,
114
115
  .threshold_warn = 20,
  .threshold_crit = 10,
Imanol-Mikel Barba Sabariego authored
116
  .optional = true,
117
118
  .col = 3,
  .lower_than = true,
Imanol-Mikel Barba Sabariego authored
119
120
121
122
123
124
125
126
};

SMARTAttr badblocks = {
  .id = RUNTIME_BAD_BLOCKS_ID,
  .name = "Runtime_Bad_Block",
  .value = -1,
  .threshold_warn = 0,
  .threshold_crit = 0, 
Imanol-Mikel Barba Sabariego authored
127
  .optional = true,
128
129
  .col = 9,
  .lower_than = false,
Imanol-Mikel Barba Sabariego authored
130
131
132
133
134
135
136
};

SMARTAttr rep_uncorrect = {
  .id = REP_UNCORRECT_ID,
  .name = "Reported_Uncorrect",
  .value = -1,
  .threshold_warn = 0,
137
  .threshold_crit = -1, 
Imanol-Mikel Barba Sabariego authored
138
  .optional = false,
139
140
  .col = 9,
  .lower_than = false,
Imanol-Mikel Barba Sabariego authored
141
142
};
Imanol-Mikel Barba Sabariego authored
143
map<std::string, SMARTAttr*> prepareAttrMap(int driveType);
144
145
146
147
148
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);
Imanol-Mikel Barba Sabariego authored
149
150
void printVersion();
void printHelp(bool longVersion);
151
void set_timeout(unsigned int sec);
Imanol-Mikel Barba Sabariego authored
152
153

#endif