monitor: Use USR1 signal to dump debug data

Similar to what fan control is already doing, this commit adds a handler
for the USR1 signal to write debug data to /tmp/fan_monitor_dump.json.
The data being written is the same data saved in an event log - the
current sensor status plus any of the Logger class's logs.

Example output, which shows fan0 recovering from previous faults:
{
    "logs": [
        ...
        [
            "Aug 26 17:04:47",
            "Setting tach sensor /xyz/openbmc_project/sensors/fan_tach/fan0_0 functional state to false. [target = 18000, input = 3446, allowed range = (10600 - NoMax) owned = true]"
        ],
        [
            "Aug 26 17:04:47",
            "Starting shutdown action 'EPOW Power Off: 60s/60s' due to cause '2 Nonfunctional Fan Rotors'"
        ],
        [
            "Aug 26 17:04:47",
            "Action EPOW Power Off: 60s/60s: Starting service mode timer"
        ],
        [
            "Aug 26 17:04:47",
            "Creating event log for faulted fan /xyz/openbmc_project/inventory/system/chassis/motherboard/fan0 sensor /xyz/openbmc_project/sensors/fan_tach/fan0_0"
        ]
    ],
    "sensors": {
        "sensors": {
            "/xyz/openbmc_project/sensors/fan_tach/fan0_0": {
                "functional": false,
                "in_range": true,
                "present": true,
                "prev_tachs": "[11829,11867,11829,11867,11829,11867,11718,11467]",
                "prev_targets": "[18000,9000,9040,10320,0,0,0,0]",
                "tach": 11829.0,
                "target": 18000,
                "ticks": 18
            },
            "/xyz/openbmc_project/sensors/fan_tach/fan0_1": {
                "functional": false,
                "in_range": true,
                "present": true,
                "prev_tachs": "[17857,17772,17857,17772,17201,17045,16741,16375]",
                "tach": 17857.0,
                "ticks": 20
            },
            "/xyz/openbmc_project/sensors/fan_tach/fan1_0": {
                "functional": true,
                "in_range": true,
                "present": true,
                "prev_tachs": "[11755,11792,11755,11792,11755,11792,11755,11792]",
                "prev_targets": "[18000,9000,9040,10320,0,0,0,0]",
                "tach": 11755.0,
                "target": 18000,
                "ticks": 0
            },
            ...
        }
    }
}

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I84179f78ec83ca6bab788052d0bebe677c1fd29f
diff --git a/monitor/system.hpp b/monitor/system.hpp
index df3e35f..bf6e6b6 100644
--- a/monitor/system.hpp
+++ b/monitor/system.hpp
@@ -26,6 +26,7 @@
 #include <nlohmann/json.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdeventplus/event.hpp>
+#include <sdeventplus/source/event.hpp>
 #include <sdeventplus/source/signal.hpp>
 
 #include <memory>
@@ -123,6 +124,13 @@
      */
     void load();
 
+    /**
+     * @brief Callback function to handle receiving a USR1 signal to dump
+     * debug data to a file.
+     */
+    void dumpDebugData(sdeventplus::source::Signal&,
+                       const struct signalfd_siginfo*);
+
   private:
     /**
      * @brief Callback from D-Bus when Inventory service comes online
@@ -199,6 +207,11 @@
     bool _loaded = false;
 
     /**
+     * @brief The name of the dump file
+     */
+    static const std::string dumpFile;
+
+    /**
      * @brief Captures tach sensor data as JSON for use in
      *        fan fault and fan missing event logs.
      *