PHAL: Log Informational error for PEL created during poweroff

1)Log informational PELS in case system state is transitioning to
power-off for IPL procedures/hardware access failures

2) Don't add callouts to PEL's created during transition to
power-off as the CEC will not be in expected state.

Tested: transition to poweroff
root@xxxbmc:/usr# peltool -lfh
{
    "0x50003BEB": {
        "SRC":                  "BD503001",
        "Message":              "Failure occurred during boot process",
        "PLID":                 "0x50003BEB",
        "CreatorID":            "BMC",
        "Subsystem":            "CEC Hardware",
        "Commit Time":          "05/23/2022 13:57:53",
        "Sev":                  "Informational Event",
        "CompID":               "0x3000"
    }
}

root@xxxbmc:~# peltool -i 0x50003be0
{
"Private Header": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Created by":               "0x3000",
    "Created at":               "05/23/2022 13:48:12",
    "Committed at":             "05/23/2022 13:48:12",
    "Creator Subsystem":        "BMC",
    "CSSVER":                   "",
    "Platform Log Id":          "0x50003BE0",
    "Entry Id":                 "0x50003BE0",
    "BMC Event Log Id":         "510"
},
"User Header": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Log Committed by":         "0x2000",
    "Subsystem":                "CEC Hardware",
    "Event Scope":              "Entire Platform",
    "Event Severity":           "Informational Event",
    "Event Type":               "Miscellaneous, Informational Only",
    "Action Flags": [
                                "Event not customer viewable",
                                "Report Externally"
    ],
    "Host Transmission":        "Not Sent",
    "HMC Transmission":         "Not Sent"
},

.
.
.
Tested: transition to running
root@ever8bmc:/tmp# peltool -i 0x50003CF9
{
"Private Header": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Created by":               "0x3000",
},
"User Header": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Log Committed by":         "0x2000",
    "Subsystem":                "CEC Hardware",
    "Event Scope":              "Entire Platform",
    "Event Severity":           "Unrecoverable Error",
},

"User Data 0": {
    "Created by": "0x2000",
    "BMCState": "Ready",
    "BootState": "Unspecified",
    "ChassisState": "On",
    "FW Version ID": "fw1020.00-57.7-2-gd86188a773",
    "HostState": "TransitioningToRunning",
    "Process Name": "/usr/bin/openpower-proc-control",
    "System IM": "50003000"
},

Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
Change-Id: I078d5cba2e0fb705bf424d2f8f3010f2cd2063bb
diff --git a/util.cpp b/util.cpp
index 0c3e669..ed4eed9 100644
--- a/util.cpp
+++ b/util.cpp
@@ -43,5 +43,51 @@
     }
     return response.begin()->first;
 }
+
+bool isHostPoweringOff()
+{
+    try
+    {
+        constexpr auto object = "/xyz/openbmc_project/state/host0";
+        constexpr auto service = "xyz.openbmc_project.State.Host";
+        constexpr auto interface = "xyz.openbmc_project.State.Host";
+        constexpr auto property = "CurrentHostState";
+        auto bus = sdbusplus::bus::new_default();
+
+        std::variant<std::string> retval;
+        auto properties = bus.new_method_call(
+            service, object, "org.freedesktop.DBus.Properties", "Get");
+        properties.append(interface);
+        properties.append(property);
+        auto result = bus.call(properties);
+        result.read(retval);
+
+        const std::string* state = std::get_if<std::string>(&retval);
+        if (state == nullptr)
+        {
+            std::string err = fmt::format(
+                "CurrentHostState property is not set ({})", object);
+            log<level::ERR>(err.c_str());
+            return false;
+        }
+        if ((*state == "xyz.openbmc_project.State.Host.HostState."
+                       "TransitioningToOff") ||
+            (*state == "xyz.openbmc_project.State.Host.HostState."
+                       "Off") ||
+            (*state == "xyz.openbmc_project.State.Host.HostState."
+                       "Quiesced"))
+        {
+            return true;
+        }
+    }
+    catch (const std::exception& ex)
+    {
+        log<level::ERR>(
+            fmt::format("Failed to read CurrentHostState property ({})",
+                        ex.what())
+                .c_str());
+    }
+    return false;
+}
 } // namespace util
 } // namespace openpower