#ifndef CHECK_SMART_H #define CHECK_SMART_H #include #include #include #include #include #include #include #include #include "auxiliar.h" #define OK 0 #define WARN 1 #define CRIT 2 #define UNKN 3 #define VERSION "1.4" #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 #define MEDIA_WEAROUT_ID 233 #define RUNTIME_BAD_BLOCKS_ID 183 #define REP_UNCORRECT_ID 187 #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" #define HDD 0 #define SSD 1 using namespace std; struct SMARTAttr { int id; string name; int value; int threshold_warn; int threshold_crit; bool optional; unsigned int col; bool lower_than; }; typedef struct SMARTAttr SMARTAttr; // Attribute definitions SMARTAttr reallocated = { .id = REALLOC_SEC_COUNT_ID, .name = "Reallocated_Sector_Ct", .value = -1, .threshold_warn = 0, .threshold_crit = -1, .optional = false, .col = 9, .lower_than = false, }; SMARTAttr pending = { .id = CURRENT_PENDING_SEC_ID, .name = "Current_Pending_Sector", .value = -1, .threshold_warn = 0, .threshold_crit = -1, .optional = false, .col = 9, .lower_than = false, }; SMARTAttr off_uncorrect = { .id = OFFLINE_UNCORRECT_ID, .name = "Offline_Uncorrectable", .value = -1, .threshold_warn = 0, .threshold_crit = 0, .optional = false, .col = 9, .lower_than = false, }; SMARTAttr wear = { .id = WEAR_COUNT_ID, .name = "Wear_Leveling_Count", .value = -1, .threshold_warn = 20, .threshold_crit = 10, .optional = true, .col = 3, .lower_than = true, }; SMARTAttr wearout = { .id = MEDIA_WEAROUT_ID, .name = "Media_Wearout_Indicator", .value = -1, .threshold_warn = 20, .threshold_crit = 10, .optional = true, .col = 3, .lower_than = true, }; SMARTAttr badblocks = { .id = RUNTIME_BAD_BLOCKS_ID, .name = "Runtime_Bad_Block", .value = -1, .threshold_warn = 0, .threshold_crit = 0, .optional = true, .col = 9, .lower_than = false, }; SMARTAttr rep_uncorrect = { .id = REP_UNCORRECT_ID, .name = "Reported_Uncorrect", .value = -1, .threshold_warn = 0, .threshold_crit = -1, .optional = false, .col = 9, .lower_than = false, }; map 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); void printVersion(); void printHelp(bool longVersion); void set_timeout(unsigned int sec); #endif