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.hpp b/monitor/system.hpp
index ae2f4ce..744c775 100644
--- a/monitor/system.hpp
+++ b/monitor/system.hpp
@@ -16,6 +16,7 @@
 #pragma once
 
 #include "fan.hpp"
+#include "fan_error.hpp"
 #include "power_off_rule.hpp"
 #include "power_state.hpp"
 #include "tach_sensor.hpp"
@@ -40,11 +41,11 @@
 {
   public:
     System() = delete;
+    ~System() = default;
     System(const System&) = delete;
     System(System&&) = delete;
     System& operator=(const System&) = delete;
     System& operator=(System&&) = delete;
-    ~System() = default;
 
     /**
      * Constructor
@@ -91,6 +92,14 @@
      */
     void fanMissingErrorTimerExpired(const Fan& fan);
 
+    /**
+     * @brief Called by the power off actions to log an error when there is
+     *        a power off due to fan problems.
+     *
+     * The error it logs is just the last fan error that occurred.
+     */
+    void logShutdownError();
+
   private:
     /* The mode of fan monitor */
     Mode _mode;
@@ -132,6 +141,11 @@
     std::optional<size_t> _numNonfuncSensorsBeforeError;
 
     /**
+     * @brief The most recently committed fan error.
+     */
+    std::unique_ptr<FanError> _lastError;
+
+    /**
      * @brief Captures tach sensor data as JSON for use in
      *        fan fault and fan missing event logs.
      *