PEL: Add 3 state fields to PEL UserData section

Add the following to the system info UserData section that gets added
for PELs created by BMC code:

* CurrentBMCState on /xyz/openbmc_project/state/bmc0
* CurrentHostState on /xyz/openbmc_project/state/host0
* CurrentPowerState on /xyz/openbmc_project/state/chassis0

The RequestedPowerTransition property is also read along with the
CurrentPowerState property since it's on the same interface and will
be used in a future commit.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Icdc225f2c9bb6d91e67a4cbe608df97803ccee6c
diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp
index e560d5e..60821b6 100644
--- a/extensions/openpower-pels/pel.cpp
+++ b/extensions/openpower-pels/pel.cpp
@@ -377,6 +377,24 @@
     json["BMC Version ID"] = std::move(id);
 }
 
+std::string lastSegment(char separator, std::string data)
+{
+    auto pos = data.find_last_of(separator);
+    if (pos != std::string::npos)
+    {
+        data = data.substr(pos + 1);
+    }
+
+    return data;
+}
+
+void addStatesToJSON(nlohmann::json& json, const DataInterfaceBase& dataIface)
+{
+    json["BMCState"] = lastSegment('.', dataIface.getBMCState());
+    json["ChassisState"] = lastSegment('.', dataIface.getChassisState());
+    json["HostState"] = lastSegment('.', dataIface.getHostState());
+}
+
 std::unique_ptr<UserData>
     makeSysInfoUserDataSection(const AdditionalData& ad,
                                const DataInterfaceBase& dataIface)
@@ -385,6 +403,7 @@
 
     addProcessNameToJSON(json, ad.getValue("_PID"), dataIface);
     addBMCFWVersionIDToJSON(json, dataIface);
+    addStatesToJSON(json, dataIface);
 
     return makeJSONUserDataSection(json);
 }