reuse working smartclt cmd
This commit is contained in:
parent
fe11419e37
commit
84a2da8bc2
@ -45,6 +45,7 @@ private:
|
|||||||
double d32TaskPercentage = 0U; // in percent for Shred (1 to 100)
|
double d32TaskPercentage = 0U; // in percent for Shred (1 to 100)
|
||||||
time_t u32TimestampTaskStart = 0U; // unix timestamp for duration of an action
|
time_t u32TimestampTaskStart = 0U; // unix timestamp for duration of an action
|
||||||
time_t u32TaskDuration = 0U; // time needed to complete the task
|
time_t u32TaskDuration = 0U; // time needed to complete the task
|
||||||
|
string desiredSmartctlCommand; //command used to gather S.M.A.R.T. values from drive
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -77,6 +78,7 @@ public:
|
|||||||
uint32_t getPowerOnHours(void); // in hours
|
uint32_t getPowerOnHours(void); // in hours
|
||||||
uint32_t getPowerCycles(void);
|
uint32_t getPowerCycles(void);
|
||||||
uint32_t getTemperature(void); // in Fahrenheit, just kidding: degree Celsius
|
uint32_t getTemperature(void); // in Fahrenheit, just kidding: degree Celsius
|
||||||
|
|
||||||
void checkFrozenDrive(void);
|
void checkFrozenDrive(void);
|
||||||
|
|
||||||
void setDriveSMARTData(string modelFamily,
|
void setDriveSMARTData(string modelFamily,
|
||||||
@ -100,6 +102,9 @@ public:
|
|||||||
void setActionStartTimestamp();
|
void setActionStartTimestamp();
|
||||||
time_t getActionStartTimestamp();
|
time_t getActionStartTimestamp();
|
||||||
|
|
||||||
|
void setSmartcltCommand(string cmd);
|
||||||
|
string getSmartcltCommand(void);
|
||||||
|
|
||||||
void calculateTaskDuration();
|
void calculateTaskDuration();
|
||||||
time_t getTaskDuration();
|
time_t getTaskDuration();
|
||||||
};
|
};
|
||||||
|
@ -161,6 +161,15 @@ time_t Drive::getActionStartTimestamp()
|
|||||||
return this->u32TimestampTaskStart;
|
return this->u32TimestampTaskStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Drive::setSmartcltCommand(string cmd)
|
||||||
|
{
|
||||||
|
this->desiredSmartctlCommand = cmd;
|
||||||
|
}
|
||||||
|
string Drive::getSmartcltCommand(void)
|
||||||
|
{
|
||||||
|
return this->desiredSmartctlCommand;
|
||||||
|
}
|
||||||
|
|
||||||
void Drive::calculateTaskDuration()
|
void Drive::calculateTaskDuration()
|
||||||
{
|
{
|
||||||
time_t u32localtime;
|
time_t u32localtime;
|
||||||
|
@ -27,6 +27,9 @@ void SMART::readSMARTData(Drive *drive)
|
|||||||
modelName.clear();
|
modelName.clear();
|
||||||
serial.clear();
|
serial.clear();
|
||||||
|
|
||||||
|
if (drive->getSmartcltCommand().empty())
|
||||||
|
{
|
||||||
|
// No working Smartctl command is known --> try all
|
||||||
string sSmartctlCommands[] = {" --json -a ", " --json -d sntjmicron -a ", " --json -d sntasmedia -a ", " --json -d sntrealtek -a ", " --json -d sat -a "};
|
string sSmartctlCommands[] = {" --json -a ", " --json -d sntjmicron -a ", " --json -d sntasmedia -a ", " --json -d sntrealtek -a ", " --json -d sat -a "};
|
||||||
|
|
||||||
for (string sSmartctlCommand : sSmartctlCommands)
|
for (string sSmartctlCommand : sSmartctlCommands)
|
||||||
@ -64,9 +67,34 @@ void SMART::readSMARTData(Drive *drive)
|
|||||||
{
|
{
|
||||||
// Found S.M.A.R.T. data with this command
|
// Found S.M.A.R.T. data with this command
|
||||||
// Logger::logThis()->info("Found S.M.A.R.T. data with this command");
|
// Logger::logThis()->info("Found S.M.A.R.T. data with this command");
|
||||||
|
drive->setSmartcltCommand(sCMD);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// A working Smartctl command is known
|
||||||
|
FILE *outputfileSmart = popen(drive->getSmartcltCommand().c_str(), "r");
|
||||||
|
size_t len = 0U; // length of found line
|
||||||
|
char *cLine = NULL; // found line
|
||||||
|
|
||||||
|
while ((getline(&cLine, &len, outputfileSmart)) != -1)
|
||||||
|
{
|
||||||
|
string sLine = string(cLine);
|
||||||
|
|
||||||
|
SMART::parseModelFamily(sLine, modelFamily);
|
||||||
|
SMART::parseModelName(sLine, modelName);
|
||||||
|
SMART::parseSerial(sLine, serial);
|
||||||
|
SMART::parseCapacity(sLine, capacity);
|
||||||
|
SMART::parseErrorCount(sLine, errorCount);
|
||||||
|
SMART::parsePowerOnHours(sLine, powerOnHours);
|
||||||
|
SMART::parsePowerCycles(sLine, powerCycles);
|
||||||
|
SMART::parseTemperature(sLine, temperature);
|
||||||
|
}
|
||||||
|
|
||||||
|
pclose(outputfileSmart);
|
||||||
|
}
|
||||||
|
|
||||||
drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycles, temperature); // write data in drive
|
drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycles, temperature); // write data in drive
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user