PEL: Print Extended User Header section to JSON

"Extended User Header": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Created by":               "0x4552",
    "Reporting Machine Type":   "OPWR-131",
    "Reporting Serial Number":  "1318ABA",
    "FW Released Ver":          "BE868_007",
    "FW SubSys Version":        "00040905079B0004",
    "Common Ref Time":          "00/00/0000 00:00:00",
    "Symptom Id Len":           "0",
    "Symptom Id":               ""
},

Verified peltool output and all testcases passed.
Signed-off-by: Harisuddin Mohamed Isa <harisuddin@gmail.com>
Change-Id: Id66b9da27d49c89befd157b0e94bbc9defed0d6a
diff --git a/extensions/openpower-pels/extended_user_header.cpp b/extensions/openpower-pels/extended_user_header.cpp
index c5c1938..282bb41 100644
--- a/extensions/openpower-pels/extended_user_header.cpp
+++ b/extensions/openpower-pels/extended_user_header.cpp
@@ -15,6 +15,7 @@
  */
 #include "extended_user_header.hpp"
 
+#include "json_utils.hpp"
 #include "pel_types.hpp"
 
 #include <phosphor-logging/log.hpp>
@@ -175,5 +176,35 @@
     _symptomIDSize = _symptomID.size();
 }
 
+std::optional<std::string> ExtendedUserHeader::getJSON() const
+{
+    std::string json;
+    jsonInsert(json, "Section Version", getNumberString("%d", _header.version),
+               1);
+    jsonInsert(json, "Sub-section type", getNumberString("%d", _header.subType),
+               1);
+    jsonInsert(json, "Created by", getNumberString("0x%X", _header.componentID),
+               1);
+    jsonInsert(json, "Reporting Machine Type", machineTypeModel(), 1);
+    jsonInsert(json, "Reporting Serial Number", trimEnd(machineSerialNumber()),
+               1);
+    jsonInsert(json, "FW Released Ver", serverFWVersion(), 1);
+    jsonInsert(json, "FW SubSys Version", subsystemFWVersion(), 1);
+    jsonInsert(json, "Common Ref Time",
+               getNumberString("%02X", _refTime.month) + '/' +
+                   getNumberString("%02X", _refTime.day) + '/' +
+                   getNumberString("%02X", _refTime.yearMSB) +
+                   getNumberString("%02X", _refTime.yearLSB) + ' ' +
+                   getNumberString("%02X", _refTime.hour) + ':' +
+                   getNumberString("%02X", _refTime.minutes) + ':' +
+                   getNumberString("%02X", _refTime.seconds),
+               1);
+    jsonInsert(json, "Symptom Id Len", getNumberString("%d", _symptomIDSize),
+               1);
+    jsonInsert(json, "Symptom Id", symptomID(), 1);
+    json.erase(json.size() - 2);
+    return json;
+}
+
 } // namespace pels
 } // namespace openpower