blob: e8230fa0590ffda17a20260b52db62111780e833 [file] [log] [blame]
#include <nlohmann/json.hpp>
#include <sdbusplus/bus.hpp>
#include <sdeventplus/event.hpp>
#include <xyz/openbmc_project/Sensor/Threshold/Critical/server.hpp>
#include <xyz/openbmc_project/Sensor/Threshold/Warning/server.hpp>
#include <xyz/openbmc_project/Sensor/Value/server.hpp>
#include <deque>
#include <map>
#include <string>
namespace phosphor
{
namespace health
{
using Json = nlohmann::json;
using ValueIface = sdbusplus::xyz::openbmc_project::Sensor::server::Value;
using CriticalInterface =
sdbusplus::xyz::openbmc_project::Sensor::Threshold::server::Critical;
using WarningInterface =
sdbusplus::xyz::openbmc_project::Sensor::Threshold::server::Warning;
using healthIfaces =
sdbusplus::server::object::object<ValueIface, CriticalInterface,
WarningInterface>;
struct HealthConfig
{
std::string name;
uint16_t freq;
uint16_t windowSize;
double criticalHigh;
double warningHigh;
bool criticalLog;
bool warningLog;
std::string criticalTgt;
std::string warningTgt;
};
class HealthSensor : public healthIfaces
{
public:
HealthSensor() = delete;
HealthSensor(const HealthSensor&) = delete;
HealthSensor& operator=(const HealthSensor&) = delete;
HealthSensor(HealthSensor&&) = delete;
HealthSensor& operator=(HealthSensor&&) = delete;
virtual ~HealthSensor() = default;
/** @brief Constructs HealthSensor
*
* @param[in] bus - Handle to system dbus
* @param[in] objPath - The Dbus path of health sensor
*/
HealthSensor(sdbusplus::bus::bus& bus, const char* objPath,
HealthConfig& sensorConfig) :
healthIfaces(bus, objPath),
bus(bus), sensorConfig(sensorConfig)
{
initHealthSensor();
}
/** @brief list of sensor data values */
std::deque<double> valQueue;
void initHealthSensor();
/** @brief Set sensor value utilization to health sensor D-bus */
void setSensorValueToDbus(const double value);
/** @brief Set Sensor Threshold to D-bus at beginning */
void setSensorThreshold(double criticalHigh, double warningHigh);
private:
sdbusplus::bus::bus& bus;
HealthConfig& sensorConfig;
};
class HealthMon
{
public:
HealthMon() = delete;
HealthMon(const HealthMon&) = delete;
HealthMon& operator=(const HealthMon&) = delete;
HealthMon(HealthMon&&) = delete;
HealthMon& operator=(HealthMon&&) = delete;
virtual ~HealthMon() = default;
/** @brief Constructs HealthMon
*
* @param[in] bus - Handle to system dbus
*/
HealthMon(sdbusplus::bus::bus& bus) : bus(bus)
{
// read json file
sensorConfigs = getHealthConfig();
createHealthSensors();
}
/** @brief Parsing Health config JSON file */
Json parseConfigFile(std::string configFile);
/** @brief reading config for each health sensor component */
void getConfigData(Json& data, HealthConfig& cfg);
/** @brief Map of the object HealthSensor */
std::unordered_map<std::string, std::shared_ptr<HealthSensor>>
healthSensors;
/** @brief Create sensors for health monitoring */
void createHealthSensors();
private:
sdbusplus::bus::bus& bus;
std::vector<HealthConfig> sensorConfigs;
std::vector<HealthConfig> getHealthConfig();
};
} // namespace health
} // namespace phosphor