From 6fb46035f50ab26d177747df558d961bcbe2914a Mon Sep 17 00:00:00 2001 From: wangjue Date: Tue, 24 Dec 2024 16:57:11 +0800 Subject: [PATCH] Sync webui sensor status with ipmi Signed-off-by: wangjue --- redfish-core/lib/sensors.hpp | 122 +++++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 5 deletions(-) diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index 20f21a93..722a111d 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -672,11 +672,12 @@ void getChassis(const std::shared_ptr& asyncResp, } /** - * @brief Returns the Redfish State value for the specified inventory item. + * @brief Returns the Redfish PSU State value for the specified inventory item. * @param inventoryItem D-Bus inventory item associated with a sensor. + * available. * @return State value for inventory item. */ -inline std::string getState(const InventoryItem* inventoryItem) +inline std::string getPsuState(const InventoryItem* inventoryItem) { if ((inventoryItem != nullptr) && !(inventoryItem->isPresent)) { @@ -686,6 +687,76 @@ inline std::string getState(const InventoryItem* inventoryItem) return "Enabled"; } +/** + * @brief Returns the Redfish State value for the specified inventory item. + * @param inventoryItem D-Bus inventory item associated with a sensor. + * @return State value for inventory item. + */ +inline std::string getState(const dbus::utility::DBusPropertiesMap& valuesDict, + nlohmann::json& sensorJson) +{ + std::string currentstate; + auto statusIt = sensorJson.find("Status"); + if (statusIt != sensorJson.end()) + { + auto stateIt = statusIt->find("State"); + if (stateIt != statusIt->end()) + { + std::string* state = stateIt->get_ptr(); + if (state != nullptr) + { + currentstate = *state; + } + } + } + + auto nameIt = sensorJson.find("Name"); + if (nameIt != sensorJson.end()) + { + std::string* name = nameIt->get_ptr(); + if (name != nullptr && name->ends_with("_Supply")) + { + return currentstate; + } + } + + if (currentstate == "Disabled") + { + return "Disabled"; + } + + for (const auto& [property, value] : valuesDict) + { + if (property == "Available") + { + const bool* available = std::get_if(&value); + if ((available != nullptr) && !(*available)) + { + return "Disabled"; + } + } + } + + if (currentstate == "No Reading") + { + return "No Reading"; + } + + for (const auto& [property, value] : valuesDict) + { + if (property == "Functional") + { + const bool* functional = std::get_if(&value); + if ((functional != nullptr) && !(*functional)) + { + return "No Reading"; + } + } + } + + return "Enabled"; +} + /** * @brief Returns the Redfish Health value for the specified sensor. * @param sensorJson Sensor JSON object. @@ -702,9 +773,20 @@ inline std::string getHealth(nlohmann::json& sensorJson, // objects contain multiple sensors (such as PowerSupplies). We want to set // the overall health to be the most severe of any of the sensors. std::string currentHealth; + std::string currentstate; auto statusIt = sensorJson.find("Status"); if (statusIt != sensorJson.end()) { + auto stateIt = statusIt->find("State"); + if (stateIt != statusIt->end()) + { + std::string* state = stateIt->get_ptr(); + if (state != nullptr) + { + currentstate = *state; + } + } + auto healthIt = statusIt->find("Health"); if (healthIt != statusIt->end()) { @@ -716,6 +798,36 @@ inline std::string getHealth(nlohmann::json& sensorJson, } } + if (currentstate == "Disabled" || currentstate == "No Reading") + { + return "ns"; + } + + // If current health in JSON object is already NonRecoverable, return that. + // This should override the sensor health, which might be less severe. + if (currentHealth == "NonRecoverable") + { + return "NonRecoverable"; + } + + // Check if sensor has NonRecoverable threshold alarm + for (const auto& [prop, value] : valuesDict) + { + if (prop == "NonRecoverableAlarmHigh" || + prop == "NonRecoverableAlarmLow") + { + const bool* asserted = std::get_if(&value); + if (asserted == nullptr) + { + BMCWEB_LOG_ERROR("Illegal sensor threshold"); + } + else if (*asserted) + { + return "NonRecoverable"; + } + } + } + // If current health in JSON object is already Critical, return that. This // should override the sensor health, which might be less severe. if (currentHealth == "Critical") @@ -835,9 +947,9 @@ inline void objectPropertiesToJson( sensorJson["Name"] = std::move(sensorNameEs); } - sensorJson["Status"]["State"] = getState(inventoryItem); + sensorJson["Status"]["State"] = getState(propertiesDict, sensorJson); sensorJson["Status"]["Health"] = getHealth(sensorJson, propertiesDict, - inventoryItem); + nullptr); // Parameter to set to override the type we get from dbus, and force it to // int, regardless of what is available. This is used for schemas like fan, @@ -2294,7 +2406,7 @@ inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray, inventoryItem.powerSupplyEfficiencyPercent; } - powerSupply["Status"]["State"] = getState(&inventoryItem); + powerSupply["Status"]["State"] = getPsuState(&inventoryItem); const char* health = inventoryItem.isFunctional ? "OK" : "Critical"; powerSupply["Status"]["Health"] = health; -- 2.34.1