monitor: Re-log fan error on a power off
In the case where a power off rule runs to completion and powers off the
system due to either missing or faulted fans, at the point of power off
re-post the event log for the previous fan error.
This way, there can be an error associated with the power off, because
depending on the power off rule delays the original error could have
happened several minutes or more in the past.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I1a38062cf75ffd4a11baa417ef3983b6c1a47ada
diff --git a/monitor/system.cpp b/monitor/system.cpp
index 6502615..229eca8 100644
--- a/monitor/system.cpp
+++ b/monitor/system.cpp
@@ -24,8 +24,6 @@
#include "json_parser.hpp"
#endif
-#include "fan_error.hpp"
-
#include <nlohmann/json.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
@@ -190,7 +188,10 @@
std::shared_ptr<PowerInterfaceBase> powerInterface =
std::make_shared<PowerInterface>();
- _powerOffRules = getPowerOffRules(jsonObj, powerInterface);
+ PowerOffAction::PrePowerOffFunc func =
+ std::bind(std::mem_fn(&System::logShutdownError), this);
+
+ _powerOffRules = getPowerOffRules(jsonObj, powerInterface, func);
_numNonfuncSensorsBeforeError = getNumNonfuncRotorsBeforeError(jsonObj);
#endif
@@ -257,7 +258,8 @@
auto sensorData = captureSensorData();
error->commit(sensorData);
- // TODO: save error so it can be committed again on a power off
+ // Save the error so it can be committed again on a power off.
+ _lastError = std::move(error);
}
void System::fanMissingErrorTimerExpired(const Fan& fan)
@@ -274,7 +276,20 @@
auto sensorData = captureSensorData();
error->commit(sensorData);
- // TODO: save error so it can be committed again on a power off
+ // Save the error so it can be committed again on a power off.
+ _lastError = std::move(error);
+}
+
+void System::logShutdownError()
+{
+ if (_lastError)
+ {
+ getLogger().log("Re-committing previous fan error before power off");
+
+ // Still use the latest sensor data
+ auto sensorData = captureSensorData();
+ _lastError->commit(sensorData);
+ }
}
json System::captureSensorData()