S.M.A.R.T. values are added to drive instace
This commit is contained in:
parent
5cf9a2c86f
commit
fdfdd0ca93
66
src/app.cpp
66
src/app.cpp
@ -9,38 +9,35 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief app constructor
|
* \brief app constructor
|
||||||
* \param void
|
* \param void
|
||||||
* \return instance of App
|
* \return instance of App
|
||||||
*/
|
*/
|
||||||
App::App(void) {
|
App::App(void)
|
||||||
|
{
|
||||||
cout << "created app" << endl;
|
cout << "created app" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief app logic
|
* \brief app logic
|
||||||
* \param void
|
* \param void
|
||||||
* \return void
|
* \return void
|
||||||
*/
|
*/
|
||||||
void App::app_logic(void)
|
void App::app_logic(void)
|
||||||
{
|
{
|
||||||
cout << "app logic" << endl;
|
cout << "app logic" << endl;
|
||||||
|
|
||||||
//Drive* tmp = new Drive("test");
|
searchDrives(&vecDrives); //search for new drives and store them in list
|
||||||
|
filterIgnoredDrives(&vecDrives); //filter out ignored drives
|
||||||
searchDrives(&listDrives); //search for new drives and store them in list
|
addSMARTData(&vecDrives); //add S.M.A.R.T. Data to the drives
|
||||||
filterIgnoredDrives(&listDrives); //filter out ignored drives
|
printDrives(&vecDrives); //print currently attached drives
|
||||||
|
|
||||||
addSMARTData(&listDrives);
|
|
||||||
|
|
||||||
printDrives(&listDrives); //print currently attached drives
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief search attached drives on /dev/sd*
|
* \brief search attached drives on /dev/sd*
|
||||||
* \param pointer of list <struct drive> *listDrives
|
* \param pointer of vector <Drive>* pvecDrives
|
||||||
* \return void
|
* \return void
|
||||||
*/
|
*/
|
||||||
void App::searchDrives(list <Drive> *listDrives)
|
void App::searchDrives(vector <Drive>* pvecDrives)
|
||||||
{
|
{
|
||||||
cout << "search drives ..." << endl;
|
cout << "search drives ..." << endl;
|
||||||
char * cLine = NULL;
|
char * cLine = NULL;
|
||||||
@ -58,7 +55,7 @@ void App::searchDrives(list <Drive> *listDrives)
|
|||||||
if (string(cLine).find("/dev/sd") != string::npos)
|
if (string(cLine).find("/dev/sd") != string::npos)
|
||||||
{
|
{
|
||||||
Drive* tmpDrive = new Drive(string(cLine).substr (2,8));
|
Drive* tmpDrive = new Drive(string(cLine).substr (2,8));
|
||||||
listDrives->push_back(*tmpDrive);
|
pvecDrives->push_back(*tmpDrive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(outputfileHwinfo);
|
fclose(outputfileHwinfo);
|
||||||
@ -66,10 +63,10 @@ void App::searchDrives(list <Drive> *listDrives)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief filter out drives that are listed in "ignoreDrives.conf"
|
* \brief filter out drives that are listed in "ignoreDrives.conf"
|
||||||
* \param pointer of list <struct drive> *listDrives
|
* \param pointer of vector <Drive>* pvecDrives
|
||||||
* \return void
|
* \return void
|
||||||
*/
|
*/
|
||||||
void App::filterIgnoredDrives(list <Drive> *listDrives)
|
void App::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
||||||
{
|
{
|
||||||
string sDelimiter = ":";
|
string sDelimiter = ":";
|
||||||
string sIgnoredDrivePath;
|
string sIgnoredDrivePath;
|
||||||
@ -101,11 +98,10 @@ void App::filterIgnoredDrives(list <Drive> *listDrives)
|
|||||||
//loop through found entries in ingnore file
|
//loop through found entries in ingnore file
|
||||||
for(auto row : vtlIgnoredDevices)
|
for(auto row : vtlIgnoredDevices)
|
||||||
{
|
{
|
||||||
//cout << get<0>(row) << " is " << get<1>(row) << endl;
|
auto it = pvecDrives->begin();
|
||||||
list <Drive>::iterator it;
|
while (it != pvecDrives->end())
|
||||||
// loop through found drives
|
|
||||||
for (it = listDrives->begin(); it != listDrives->end(); ++it)
|
|
||||||
{
|
{
|
||||||
|
it++;
|
||||||
string sUUID;
|
string sUUID;
|
||||||
if (!get<0>(row).compare(it->getPath())) //find same drive based on path
|
if (!get<0>(row).compare(it->getPath())) //find same drive based on path
|
||||||
{
|
{
|
||||||
@ -133,7 +129,7 @@ void App::filterIgnoredDrives(list <Drive> *listDrives)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(outputfileBlkid);
|
fclose(outputfileBlkid);
|
||||||
//cout << "blkid uuid:" << sUUID << endl;
|
// cout << "blkid uuid:" << sUUID << endl;
|
||||||
|
|
||||||
if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
|
if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
|
||||||
{
|
{
|
||||||
@ -143,8 +139,9 @@ void App::filterIgnoredDrives(list <Drive> *listDrives)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// same uuid found than in ignore file --> ignore this drive
|
// same uuid found than in ignore file --> ignore this drive
|
||||||
it = listDrives->erase(it);
|
it = pvecDrives->erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,14 +149,14 @@ void App::filterIgnoredDrives(list <Drive> *listDrives)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief print drives with all information
|
* \brief print drives with all information
|
||||||
* \param pointer of list <struct drive> *listDrives
|
* \param pointer of vector <Drive>* pvecDrives
|
||||||
* \return void
|
* \return void
|
||||||
*/
|
*/
|
||||||
void App::printDrives(list <Drive> *listDrives)
|
void App::printDrives(vector <Drive>* pvecDrives)
|
||||||
{
|
{
|
||||||
cout << "------------DRIVES---------------" << endl;
|
cout << "------------DRIVES---------------" << endl;
|
||||||
list <Drive>::iterator it;
|
vector <Drive>::iterator it;
|
||||||
for (it = listDrives->begin(); it != listDrives->end(); ++it)
|
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
||||||
{
|
{
|
||||||
cout << "Path: " << it->getPath() << endl;
|
cout << "Path: " << it->getPath() << endl;
|
||||||
cout << "ModelFamily: " << it->getModelFamily() << endl;
|
cout << "ModelFamily: " << it->getModelFamily() << endl;
|
||||||
@ -167,17 +164,24 @@ void App::printDrives(list <Drive> *listDrives)
|
|||||||
cout << "Capacity: " << it->getCapacity() << endl;
|
cout << "Capacity: " << it->getCapacity() << endl;
|
||||||
cout << "Serial: " << it->getSerial() << endl;
|
cout << "Serial: " << it->getSerial() << endl;
|
||||||
cout << "PowerOnHours: " << it->getPowerOnHours() << endl;
|
cout << "PowerOnHours: " << it->getPowerOnHours() << endl;
|
||||||
cout << "PowerCycle: " << it->getPowerCycles() << endl;
|
cout << "PowerCycle: " << it->getPowerCycles() << endl;
|
||||||
cout << "ErrorCount: " << it->getErrorCount() << endl;
|
cout << "ErrorCount: " << it->getErrorCount() << endl;
|
||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
cout << "---------------------------------" << endl;
|
cout << "---------------------------------" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::addSMARTData(list <Drive> *listDrives) {
|
/**
|
||||||
list <Drive>::iterator it;
|
* \brief add S.M.A.R.T data from SMART
|
||||||
for (it = listDrives->begin(); it != listDrives->end(); ++it)
|
* \param pointer of vector <Drive>* pvecDrives
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
|
void App::addSMARTData(vector <Drive>* pvecDrives)
|
||||||
|
{
|
||||||
|
vector <Drive>::iterator it;
|
||||||
|
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
||||||
{
|
{
|
||||||
SMART::readSMARTData(*it);
|
Drive* pTmpDrive = iterator_to_pointer<Drive, std::vector<Drive>::iterator > (it);
|
||||||
|
SMART::readSMARTData(pTmpDrive);
|
||||||
}
|
}
|
||||||
}
|
}
|
22
src/app.h
22
src/app.h
@ -12,9 +12,15 @@
|
|||||||
#include "drive.h"
|
#include "drive.h"
|
||||||
#include "smart.h"
|
#include "smart.h"
|
||||||
|
|
||||||
class App {
|
template <typename T, typename I>
|
||||||
protected:
|
T* iterator_to_pointer(I i)
|
||||||
|
{
|
||||||
|
return (&(*i));
|
||||||
|
}
|
||||||
|
|
||||||
|
class App
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
App(void);
|
App(void);
|
||||||
@ -22,15 +28,13 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
list <Drive> listDrives; //stores all drive data
|
vector <Drive> vecDrives; //stores all drive data
|
||||||
|
|
||||||
void searchDrives(list <Drive> *listDrives);
|
void searchDrives(vector <Drive>* pvecDrives);
|
||||||
void printDrives(list <Drive> *listDrives);
|
void printDrives(vector <Drive>* pvecDrives);
|
||||||
void filterIgnoredDrives(list <Drive> *listDrives);
|
void filterIgnoredDrives(vector <Drive>* pvecDrives);
|
||||||
void addSMARTData(list <Drive> *listDrives);
|
void addSMARTData(vector <Drive>* pvecDrives);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // APP_H_
|
#endif // APP_H_
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include "drive.h"
|
#include "drive.h"
|
||||||
|
|
||||||
|
|
||||||
string Drive::getPath(void)
|
string Drive::getPath(void)
|
||||||
{
|
{
|
||||||
return sPath;
|
return sPath;
|
||||||
@ -47,6 +46,17 @@ uint32_t Drive::getPowerCycles(void)
|
|||||||
return u32PowerCycles;
|
return u32PowerCycles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief set S.M.A.R.T. values in model
|
||||||
|
* \param string modelFamily
|
||||||
|
* \param string modelName
|
||||||
|
* \param string serial
|
||||||
|
* \param uint64_t capacity
|
||||||
|
* \param uint32_t errorCount
|
||||||
|
* \param uint32_t powerOnHours
|
||||||
|
* \param uint32_t powerCycle
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
void Drive::setDriveSMARTData( string modelFamily,
|
void Drive::setDriveSMARTData( string modelFamily,
|
||||||
string modelName,
|
string modelName,
|
||||||
string serial,
|
string serial,
|
||||||
@ -55,7 +65,7 @@ void Drive::setDriveSMARTData( string modelFamily,
|
|||||||
uint32_t powerOnHours,
|
uint32_t powerOnHours,
|
||||||
uint32_t powerCycle)
|
uint32_t powerCycle)
|
||||||
{
|
{
|
||||||
sModelFamily = modelFamily;
|
this->sModelFamily = modelFamily;
|
||||||
sModelName = modelName;
|
sModelName = modelName;
|
||||||
sSerial = serial;
|
sSerial = serial;
|
||||||
u64Capacity = capacity;
|
u64Capacity = capacity;
|
||||||
|
@ -10,12 +10,14 @@
|
|||||||
|
|
||||||
#include "refurbishingHddTool.h"
|
#include "refurbishingHddTool.h"
|
||||||
|
|
||||||
class Drive {
|
class Drive
|
||||||
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Drive(string path) {
|
Drive(string path)
|
||||||
sPath = path;
|
{
|
||||||
|
this->sPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
string getPath(void);
|
string getPath(void);
|
||||||
|
803
src/out.txt
803
src/out.txt
@ -1,803 +0,0 @@
|
|||||||
{
|
|
||||||
"json_format_version": [
|
|
||||||
1,
|
|
||||||
0
|
|
||||||
],
|
|
||||||
"smartctl": {
|
|
||||||
"version": [
|
|
||||||
7,
|
|
||||||
1
|
|
||||||
],
|
|
||||||
"svn_revision": "5022",
|
|
||||||
"platform_info": "x86_64-linux-5.6.4-1-default",
|
|
||||||
"build_info": "(SUSE RPM)",
|
|
||||||
"argv": [
|
|
||||||
"smartctl",
|
|
||||||
"--json",
|
|
||||||
"-a",
|
|
||||||
"/dev/sdd"
|
|
||||||
],
|
|
||||||
"exit_status": 0
|
|
||||||
},
|
|
||||||
"device": {
|
|
||||||
"name": "/dev/sdd",
|
|
||||||
"info_name": "/dev/sdd [SAT]",
|
|
||||||
"type": "sat",
|
|
||||||
"protocol": "ATA"
|
|
||||||
},
|
|
||||||
"model_family": "Western Digital Caviar Green",
|
|
||||||
"model_name": "WDC WD15EADS-22P8B0",
|
|
||||||
"serial_number": "WD-WMAVU2708194",
|
|
||||||
"wwn": {
|
|
||||||
"naa": 5,
|
|
||||||
"oui": 5358,
|
|
||||||
"id": 28633198579
|
|
||||||
},
|
|
||||||
"firmware_version": "01.00A01",
|
|
||||||
"user_capacity": {
|
|
||||||
"blocks": 2930277168,
|
|
||||||
"bytes": 1500301910016
|
|
||||||
},
|
|
||||||
"logical_block_size": 512,
|
|
||||||
"physical_block_size": 512,
|
|
||||||
"in_smartctl_database": true,
|
|
||||||
"ata_version": {
|
|
||||||
"string": "ATA8-ACS (minor revision not indicated)",
|
|
||||||
"major_value": 510,
|
|
||||||
"minor_value": 0
|
|
||||||
},
|
|
||||||
"sata_version": {
|
|
||||||
"string": "SATA 2.6",
|
|
||||||
"value": 30
|
|
||||||
},
|
|
||||||
"interface_speed": {
|
|
||||||
"max": {
|
|
||||||
"sata_value": 6,
|
|
||||||
"string": "3.0 Gb/s",
|
|
||||||
"units_per_second": 30,
|
|
||||||
"bits_per_unit": 100000000
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"local_time": {
|
|
||||||
"time_t": 1588412611,
|
|
||||||
"asctime": "Sat May 2 11:43:31 2020 CEST"
|
|
||||||
},
|
|
||||||
"smart_status": {
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"ata_smart_data": {
|
|
||||||
"offline_data_collection": {
|
|
||||||
"status": {
|
|
||||||
"value": 130,
|
|
||||||
"string": "was completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"completion_seconds": 31200
|
|
||||||
},
|
|
||||||
"self_test": {
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"polling_minutes": {
|
|
||||||
"short": 2,
|
|
||||||
"extended": 356,
|
|
||||||
"conveyance": 5
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"capabilities": {
|
|
||||||
"values": [
|
|
||||||
123,
|
|
||||||
3
|
|
||||||
],
|
|
||||||
"exec_offline_immediate_supported": true,
|
|
||||||
"offline_is_aborted_upon_new_cmd": false,
|
|
||||||
"offline_surface_scan_supported": true,
|
|
||||||
"self_tests_supported": true,
|
|
||||||
"conveyance_self_test_supported": true,
|
|
||||||
"selective_self_test_supported": true,
|
|
||||||
"attribute_autosave_enabled": true,
|
|
||||||
"error_logging_supported": true,
|
|
||||||
"gp_logging_supported": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ata_sct_capabilities": {
|
|
||||||
"value": 12343,
|
|
||||||
"error_recovery_control_supported": false,
|
|
||||||
"feature_control_supported": true,
|
|
||||||
"data_table_supported": true
|
|
||||||
},
|
|
||||||
"ata_smart_attributes": {
|
|
||||||
"revision": 16,
|
|
||||||
"table": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"name": "Raw_Read_Error_Rate",
|
|
||||||
"value": 200,
|
|
||||||
"worst": 200,
|
|
||||||
"thresh": 51,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 47,
|
|
||||||
"string": "POSR-K ",
|
|
||||||
"prefailure": true,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": true,
|
|
||||||
"error_rate": true,
|
|
||||||
"event_count": false,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"name": "Spin_Up_Time",
|
|
||||||
"value": 183,
|
|
||||||
"worst": 178,
|
|
||||||
"thresh": 21,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 39,
|
|
||||||
"string": "POS--K ",
|
|
||||||
"prefailure": true,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": true,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": false,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 5850,
|
|
||||||
"string": "5850"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 4,
|
|
||||||
"name": "Start_Stop_Count",
|
|
||||||
"value": 100,
|
|
||||||
"worst": 100,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 50,
|
|
||||||
"string": "-O--CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 731,
|
|
||||||
"string": "731"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 5,
|
|
||||||
"name": "Reallocated_Sector_Ct",
|
|
||||||
"value": 200,
|
|
||||||
"worst": 200,
|
|
||||||
"thresh": 140,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 51,
|
|
||||||
"string": "PO--CK ",
|
|
||||||
"prefailure": true,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 7,
|
|
||||||
"name": "Seek_Error_Rate",
|
|
||||||
"value": 100,
|
|
||||||
"worst": 253,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 46,
|
|
||||||
"string": "-OSR-K ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": true,
|
|
||||||
"error_rate": true,
|
|
||||||
"event_count": false,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 9,
|
|
||||||
"name": "Power_On_Hours",
|
|
||||||
"value": 99,
|
|
||||||
"worst": 99,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 50,
|
|
||||||
"string": "-O--CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 1227,
|
|
||||||
"string": "1227"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 10,
|
|
||||||
"name": "Spin_Retry_Count",
|
|
||||||
"value": 100,
|
|
||||||
"worst": 100,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 50,
|
|
||||||
"string": "-O--CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 11,
|
|
||||||
"name": "Calibration_Retry_Count",
|
|
||||||
"value": 100,
|
|
||||||
"worst": 100,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 50,
|
|
||||||
"string": "-O--CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 12,
|
|
||||||
"name": "Power_Cycle_Count",
|
|
||||||
"value": 100,
|
|
||||||
"worst": 100,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 50,
|
|
||||||
"string": "-O--CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 712,
|
|
||||||
"string": "712"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 192,
|
|
||||||
"name": "Power-Off_Retract_Count",
|
|
||||||
"value": 200,
|
|
||||||
"worst": 200,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 50,
|
|
||||||
"string": "-O--CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 351,
|
|
||||||
"string": "351"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 193,
|
|
||||||
"name": "Load_Cycle_Count",
|
|
||||||
"value": 193,
|
|
||||||
"worst": 193,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 50,
|
|
||||||
"string": "-O--CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 21656,
|
|
||||||
"string": "21656"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 194,
|
|
||||||
"name": "Temperature_Celsius",
|
|
||||||
"value": 120,
|
|
||||||
"worst": 86,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 34,
|
|
||||||
"string": "-O---K ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": false,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 30,
|
|
||||||
"string": "30"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 196,
|
|
||||||
"name": "Reallocated_Event_Count",
|
|
||||||
"value": 200,
|
|
||||||
"worst": 200,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 50,
|
|
||||||
"string": "-O--CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 197,
|
|
||||||
"name": "Current_Pending_Sector",
|
|
||||||
"value": 200,
|
|
||||||
"worst": 200,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 50,
|
|
||||||
"string": "-O--CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 198,
|
|
||||||
"name": "Offline_Uncorrectable",
|
|
||||||
"value": 200,
|
|
||||||
"worst": 200,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 48,
|
|
||||||
"string": "----CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": false,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 199,
|
|
||||||
"name": "UDMA_CRC_Error_Count",
|
|
||||||
"value": 200,
|
|
||||||
"worst": 199,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 50,
|
|
||||||
"string": "-O--CK ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": true,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": false,
|
|
||||||
"event_count": true,
|
|
||||||
"auto_keep": true
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 332,
|
|
||||||
"string": "332"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 200,
|
|
||||||
"name": "Multi_Zone_Error_Rate",
|
|
||||||
"value": 200,
|
|
||||||
"worst": 200,
|
|
||||||
"thresh": 0,
|
|
||||||
"when_failed": "",
|
|
||||||
"flags": {
|
|
||||||
"value": 8,
|
|
||||||
"string": "---R-- ",
|
|
||||||
"prefailure": false,
|
|
||||||
"updated_online": false,
|
|
||||||
"performance": false,
|
|
||||||
"error_rate": true,
|
|
||||||
"event_count": false,
|
|
||||||
"auto_keep": false
|
|
||||||
},
|
|
||||||
"raw": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"power_on_time": {
|
|
||||||
"hours": 1227
|
|
||||||
},
|
|
||||||
"power_cycle_count": 712,
|
|
||||||
"temperature": {
|
|
||||||
"current": 30
|
|
||||||
},
|
|
||||||
"ata_smart_error_log": {
|
|
||||||
"summary": {
|
|
||||||
"revision": 1,
|
|
||||||
"count": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ata_smart_self_test_log": {
|
|
||||||
"standard": {
|
|
||||||
"revision": 1,
|
|
||||||
"table": [
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1191
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1170
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1155
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1141
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1127
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1112
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1100
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1087
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1074
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1060
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1047
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1034
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1021
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1005
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 2,
|
|
||||||
"string": "Extended offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 1003
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 2,
|
|
||||||
"string": "Extended offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 992
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 987
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 975
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 234
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"value": 1,
|
|
||||||
"string": "Short offline"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Completed without error",
|
|
||||||
"passed": true
|
|
||||||
},
|
|
||||||
"lifetime_hours": 230
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"count": 20,
|
|
||||||
"error_count_total": 0,
|
|
||||||
"error_count_outdated": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ata_smart_selective_self_test_log": {
|
|
||||||
"revision": 1,
|
|
||||||
"table": [
|
|
||||||
{
|
|
||||||
"lba_min": 0,
|
|
||||||
"lba_max": 0,
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Not_testing"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lba_min": 0,
|
|
||||||
"lba_max": 0,
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Not_testing"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lba_min": 0,
|
|
||||||
"lba_max": 0,
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Not_testing"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lba_min": 0,
|
|
||||||
"lba_max": 0,
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Not_testing"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lba_min": 0,
|
|
||||||
"lba_max": 0,
|
|
||||||
"status": {
|
|
||||||
"value": 0,
|
|
||||||
"string": "Not_testing"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"flags": {
|
|
||||||
"value": 0,
|
|
||||||
"remainder_scan_enabled": false
|
|
||||||
},
|
|
||||||
"power_up_scan_resume_minutes": 0
|
|
||||||
}
|
|
||||||
}
|
|
110
src/smart.cpp
110
src/smart.cpp
@ -15,18 +15,32 @@ uint32_t SMART::errorCount = 0U;
|
|||||||
uint32_t SMART::powerOnHours = 0U;
|
uint32_t SMART::powerOnHours = 0U;
|
||||||
uint32_t SMART::powerCycle = 0U;
|
uint32_t SMART::powerCycle = 0U;
|
||||||
|
|
||||||
void SMART::readSMARTData(Drive drive)
|
/**
|
||||||
|
* \brief get and set S.M.A.R.T. values in Drive
|
||||||
|
* \param pointer of Drive instance
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
|
void SMART::readSMARTData(Drive* drive)
|
||||||
{
|
{
|
||||||
|
modelFamily.clear();
|
||||||
|
modelName.clear();
|
||||||
|
serial.clear();
|
||||||
|
capacity = 0U;
|
||||||
|
errorCount = 0U;
|
||||||
|
powerOnHours = 0U;
|
||||||
|
powerCycle = 0U;
|
||||||
|
|
||||||
size_t len = 0; //lenght of found line
|
size_t len = 0; //lenght of found line
|
||||||
char* cLine = NULL; //found line
|
char* cLine = NULL; //found line
|
||||||
|
|
||||||
string sCMD = ("./smartctl --json -a ");
|
string sCMD = ("./smartctl --json -a ");
|
||||||
sCMD.append(drive.getPath());
|
sCMD.append(drive->getPath());
|
||||||
const char* cpComand = sCMD.c_str();
|
const char* cpComand = sCMD.c_str();
|
||||||
|
|
||||||
FILE* outputfileSmart = popen(cpComand, "r");
|
FILE* outputfileSmart = popen(cpComand, "r");
|
||||||
|
|
||||||
while ((getline(&cLine, &len, outputfileSmart)) != -1) {
|
while ((getline(&cLine, &len, outputfileSmart)) != -1)
|
||||||
|
{
|
||||||
string sLine = string(cLine);
|
string sLine = string(cLine);
|
||||||
|
|
||||||
SMART::parseModelFamily(sLine);
|
SMART::parseModelFamily(sLine);
|
||||||
@ -38,97 +52,123 @@ void SMART::readSMARTData(Drive drive)
|
|||||||
SMART::parsePowerCycle(sLine);
|
SMART::parsePowerCycle(sLine);
|
||||||
}
|
}
|
||||||
fclose(outputfileSmart);
|
fclose(outputfileSmart);
|
||||||
//drive.setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, spinUpCount);
|
drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycle); //wirte data in drive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief parse ModelFamiliy
|
||||||
|
* \param string output line of smartctl
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
void SMART::parseModelFamily(string sLine)
|
void SMART::parseModelFamily(string sLine)
|
||||||
{
|
{
|
||||||
string search("\"model_family\": ");
|
string search("\"model_family\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos) {
|
if (found!=string::npos) {
|
||||||
// cout << sLine;
|
|
||||||
sLine.erase(0, sLine.find(": ") + 3);
|
sLine.erase(0, sLine.find(": ") + 3);
|
||||||
sLine.erase(sLine.length()-3, 3);
|
sLine.erase(sLine.length()-3, 3);
|
||||||
// modelFamily = sLine;
|
modelFamily = sLine;
|
||||||
cout << "ModelFamily |" << sLine << "|" << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief parse ModelName
|
||||||
|
* \param string output line of smartctl
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
void SMART::parseModelName(string sLine)
|
void SMART::parseModelName(string sLine)
|
||||||
{
|
{
|
||||||
string search("\"model_name\": ");
|
string search("\"model_name\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos) {
|
if (found!=string::npos) {
|
||||||
// cout << sLine;
|
|
||||||
sLine.erase(0, sLine.find(": ") + 3);
|
sLine.erase(0, sLine.find(": ") + 3);
|
||||||
sLine.erase(sLine.length()-3, 3);
|
sLine.erase(sLine.length()-3, 3);
|
||||||
// modelName = sLine;
|
modelName = sLine;
|
||||||
cout << "ModelName |" << sLine << "|" << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief parse Serial
|
||||||
|
* \param string output line of smartctl
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
void SMART::parseSerial(string sLine)
|
void SMART::parseSerial(string sLine)
|
||||||
{
|
{
|
||||||
string search("\"serial_number\": ");
|
string search("\"serial_number\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos) {
|
if (found!=string::npos) {
|
||||||
// cout << sLine;
|
|
||||||
sLine.erase(0, sLine.find(": ") + 3);
|
sLine.erase(0, sLine.find(": ") + 3);
|
||||||
sLine.erase(sLine.length()-3, 3);
|
sLine.erase(sLine.length()-3, 3);
|
||||||
// serial = sLine;
|
serial = sLine;
|
||||||
cout << "Serial |" << sLine << "|" << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief parse Capacity
|
||||||
|
* \param string output line of smartctl
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
void SMART::parseCapacity(string sLine)
|
void SMART::parseCapacity(string sLine)
|
||||||
{
|
{
|
||||||
string search("\"bytes\": ");
|
string search("\"bytes\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos) {
|
if (found!=string::npos) {
|
||||||
// cout << sLine;
|
|
||||||
sLine.erase(0, sLine.find(": ") + 2);
|
sLine.erase(0, sLine.find(": ") + 2);
|
||||||
sLine.erase(sLine.length()-1, 1);
|
sLine.erase(sLine.length()-1, 1);
|
||||||
// capacity = sLine;
|
capacity = stol(sLine);
|
||||||
cout << "Capacity |" << sLine << "|" << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief parse ErrorCount
|
||||||
|
* \param string output line of smartctl
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
void SMART::parseErrorCount(string sLine)
|
void SMART::parseErrorCount(string sLine)
|
||||||
{
|
{
|
||||||
string search("\"error_count_total\": ");
|
string search("\"error_count_total\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos) {
|
if (found!=string::npos)
|
||||||
//cout << sLine;
|
{
|
||||||
sLine.erase(0, sLine.find(": ")+2);
|
sLine.erase(0, sLine.find(": ")+2);
|
||||||
sLine.erase(sLine.length()-2, 2);
|
sLine.erase(sLine.length()-2, 2);
|
||||||
errorCount = stoi(sLine);
|
errorCount = stol(sLine);
|
||||||
cout << "ErrorCount |" << sLine << "|" << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief parse PowerOnHours
|
||||||
|
* \param string output line of smartctl
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
void SMART::parsePowerOnHours(string sLine)
|
void SMART::parsePowerOnHours(string sLine)
|
||||||
{
|
{
|
||||||
string search("\"hours\": ");
|
string search("\"hours\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos) {
|
if (found!=string::npos)
|
||||||
// cout << sLine;
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 2);
|
sLine.erase(0, sLine.find(": ") + 2);
|
||||||
sLine.erase(sLine.length()-1, 1);
|
sLine.erase(sLine.length()-1, 1);
|
||||||
// powerOnHours = stoi(sLine);
|
powerOnHours = stol(sLine);
|
||||||
cout << "PowerOnHours |" << sLine << "|" << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief parse PowerCycle
|
||||||
|
* \param string output line of smartctl
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
void SMART::parsePowerCycle(string sLine)
|
void SMART::parsePowerCycle(string sLine)
|
||||||
{
|
{
|
||||||
string search("\"power_cycle_count\": ");
|
string search("\"power_cycle_count\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos) {
|
if (found!=string::npos)
|
||||||
// cout << sLine;
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 2);
|
sLine.erase(0, sLine.find(": ") + 2);
|
||||||
sLine.erase(sLine.length()-2, 2);
|
sLine.erase(sLine.length()-2, 2);
|
||||||
//spinUpCount = stoi(sLine);
|
powerCycle = stol(sLine);
|
||||||
cout << "PowerCycle |" << sLine << "|" << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/smart.h
10
src/smart.h
@ -12,14 +12,13 @@
|
|||||||
#include "drive.h"
|
#include "drive.h"
|
||||||
|
|
||||||
|
|
||||||
class SMART {
|
class SMART
|
||||||
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static void readSMARTData(Drive* drive);
|
||||||
static void readSMARTData(Drive drive);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SMART(void);
|
SMART(void);
|
||||||
@ -39,9 +38,6 @@ private:
|
|||||||
static uint32_t errorCount;
|
static uint32_t errorCount;
|
||||||
static uint32_t powerOnHours;
|
static uint32_t powerOnHours;
|
||||||
static uint32_t powerCycle;
|
static uint32_t powerCycle;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SMART_H_
|
#endif // SMART_H_
|
@ -10,7 +10,8 @@
|
|||||||
"*.tcc": "cpp",
|
"*.tcc": "cpp",
|
||||||
"string": "cpp",
|
"string": "cpp",
|
||||||
"unordered_map": "cpp",
|
"unordered_map": "cpp",
|
||||||
"string_view": "cpp"
|
"string_view": "cpp",
|
||||||
|
"ostream": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user