Only log input fault error when power is on

If the system power is on and a INPUT or VIN_UV fault is detected, log
an error with the appropriate metadata. If the power is off, just put an
informational message in the journal.

Resolves: openbmc/openbmc#2771

Change-Id: I1e30177e9f1f4d44a8b9cc1af9ef064d3eb37be4
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/power-supply/power_supply.cpp b/power-supply/power_supply.cpp
index 3d7673c..0c42ca0 100644
--- a/power-supply/power_supply.cpp
+++ b/power-supply/power_supply.cpp
@@ -293,6 +293,12 @@
         ((statusWord & status_word::INPUT_FAULT_WARN) ||
          (statusWord & status_word::VIN_UV_FAULT)))
     {
+        if (inputFault == 0)
+        {
+            log<level::INFO>("INPUT or VIN_UV fault",
+                             entry("STATUS_WORD=0x%04X", statusWord));
+        }
+
         inputFault++;
     }
     else
@@ -324,17 +330,22 @@
 
     if (!faultFound && (inputFault >= FAULT_COUNT))
     {
-        util::NamesValues nv;
-        nv.add("STATUS_WORD", statusWord);
-        captureCmd(nv, STATUS_INPUT, Type::Debug);
+        // If the power is on, report the fault in an error log entry.
+        if (powerOn)
+        {
+            util::NamesValues nv;
+            nv.add("STATUS_WORD", statusWord);
+            captureCmd(nv, STATUS_INPUT, Type::Debug);
 
-        using metadata = org::open_power::Witherspoon::Fault::
-                PowerSupplyInputFault;
+            using metadata = org::open_power::Witherspoon::Fault::
+                    PowerSupplyInputFault;
 
-        report<PowerSupplyInputFault>(
-                metadata::RAW_STATUS(nv.get().c_str()),
-                metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
-        faultFound = true;
+            report<PowerSupplyInputFault>(
+                    metadata::RAW_STATUS(nv.get().c_str()),
+                    metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
+
+            faultFound = true;
+        }
     }
 
 }