Add Group Event Support for PSU
Some group events such as PSU Fan Fault will only have one event but
have more than one target to trigger redfish log. For example, PSU Fan
only has one event PSU Fan Fault, any Fan failure will trigger PSU Fan
Fault and change the functional property to false. But if another PSU
Fan failure happens, we still need to trigger a redfish log to indicate
the specific fan number. So change the PSU Event logic to support this
feature.
Tested:
Remove one of the PSU, Redfish Log show PSU Fan Fault on Fan1 and Fan2.
Insert the PSU and Redfish Log show PSU Fan1 and Fan2 recovered.
Signed-off-by: Cheng C Yang <cheng.c.yang@linux.intel.com>
Change-Id: I1a21d5a2a8172183b05b37a5ef747bd4f3510368
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index a2c3de4..141b2ea 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -61,6 +61,10 @@
static boost::container::flat_map<std::string, std::string> pwmTable;
static boost::container::flat_map<std::string, std::vector<std::string>>
eventMatch;
+static boost::container::flat_map<
+ std::string,
+ boost::container::flat_map<std::string, std::vector<std::string>>>
+ groupEventMatch;
static boost::container::flat_map<std::string, std::vector<std::string>>
limitEventMatch;
@@ -95,6 +99,46 @@
}
}
+// Check Group Events which contains more than one targets in each combine
+// events.
+void checkGroupEvent(
+ const std::string& directory,
+ const boost::container::flat_map<
+ std::string,
+ boost::container::flat_map<std::string, std::vector<std::string>>>&
+ groupEventMatch,
+ boost::container::flat_map<
+ std::string,
+ boost::container::flat_map<std::string, std::vector<std::string>>>&
+ groupEventPathList)
+{
+ for (const auto& match : groupEventMatch)
+ {
+ const std::string& groupEventName = match.first;
+ const boost::container::flat_map<std::string, std::vector<std::string>>
+ events = match.second;
+ boost::container::flat_map<std::string, std::vector<std::string>>
+ pathList;
+ for (const auto& match : events)
+ {
+ const std::string& eventName = match.first;
+ const std::vector<std::string>& eventAttrs = match.second;
+ for (const auto& eventAttr : eventAttrs)
+ {
+ auto eventPath = directory + "/" + eventAttr;
+ std::ifstream eventFile(eventPath);
+ if (!eventFile.good())
+ {
+ continue;
+ }
+
+ pathList[eventName].push_back(eventPath);
+ }
+ }
+ groupEventPathList[groupEventName] = pathList;
+ }
+}
+
// Function checkEventLimits will check all the psu related xxx_input attributes
// in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm
// xxx_min_alarm exist, then store the existing paths of the alarm attributes
@@ -192,6 +236,10 @@
{
boost::container::flat_map<std::string, std::vector<std::string>>
eventPathList;
+ boost::container::flat_map<
+ std::string,
+ boost::container::flat_map<std::string, std::vector<std::string>>>
+ groupEventPathList;
std::ifstream nameFile(pmbusPath);
if (!nameFile.good())
@@ -331,6 +379,8 @@
continue;
}
checkEvent(directory.string(), eventMatch, eventPathList);
+ checkGroupEvent(directory.string(), groupEventMatch,
+ groupEventPathList);
/* Check if there are more sensors in the same interface */
int i = 1;
@@ -680,8 +730,9 @@
// OperationalStatus event
combineEvents[*psuName + "OperationalStatus"] = nullptr;
combineEvents[*psuName + "OperationalStatus"] =
- std::make_unique<PSUCombineEvent>(
- objectServer, io, *psuName, eventPathList, "OperationalStatus");
+ std::make_unique<PSUCombineEvent>(objectServer, io, *psuName,
+ eventPathList, groupEventPathList,
+ "OperationalStatus");
}
if constexpr (DEBUG)
@@ -740,12 +791,14 @@
limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}},
{"Failure", {"crit_alarm", "lcrit_alarm"}}};
- eventMatch = {
- {"PredictiveFailure", {"power1_alarm"}},
- {"Failure", {"in2_alarm"}},
- {"ACLost", {"in1_beep"}},
- {"FanFault", {"fan1_alarm", "fan2_alarm", "fan1_fault", "fan2_fault"}},
- {"ConfigureError", {"in1_fault"}}};
+ eventMatch = {{"PredictiveFailure", {"power1_alarm"}},
+ {"Failure", {"in2_alarm"}},
+ {"ACLost", {"in1_beep"}},
+ {"ConfigureError", {"in1_fault"}}};
+
+ groupEventMatch = {{"FanFault",
+ {{"fan1", {"fan1_alarm", "fan1_fault"}},
+ {"fan2", {"fan2_alarm", "fan2_fault"}}}}};
}
int main()