PEL: Fill in getPELJSON function

This D-Bus method will return the PEL parsed into a JSON string by
calling /usr/bin/peltool and capturing the output.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I47d2834a569c984a8bb71f06b73255ea5a9f5c7e
diff --git a/extensions/openpower-pels/manager.cpp b/extensions/openpower-pels/manager.cpp
index 7e42020..3b1e118 100644
--- a/extensions/openpower-pels/manager.cpp
+++ b/extensions/openpower-pels/manager.cpp
@@ -641,9 +641,38 @@
     return {_logManager.lastEntryID(), _repo.lastPelID()};
 }
 
-std::string Manager::getPELJSON(uint32_t /*obmcLogID*/)
+std::string Manager::getPELJSON(uint32_t obmcLogID)
 {
-    return std::string{};
+    Repository::LogID id{Repository::LogID::Obmc(obmcLogID)};
+
+    // Throws InvalidArgument if not found
+    auto pelID = getPELIdFromBMCLogId(obmcLogID);
+
+    auto cmd = fmt::format("/usr/bin/peltool -i {:#x}", pelID);
+
+    FILE* pipe = popen(cmd.c_str(), "r");
+    if (!pipe)
+    {
+        log<level::ERR>(fmt::format("Error running {}", cmd).c_str());
+        throw common_error::InternalFailure();
+    }
+
+    std::string output;
+    std::array<char, 1024> buffer;
+    while (fgets(buffer.data(), buffer.size(), pipe) != nullptr)
+    {
+        output.append(buffer.data());
+    }
+
+    int rc = pclose(pipe);
+    if (WEXITSTATUS(rc) != 0)
+    {
+        log<level::ERR>(
+            fmt::format("Error running {}, rc = {}", cmd, rc).c_str());
+        throw common_error::InternalFailure();
+    }
+
+    return output;
 }
 
 void Manager::checkPelAndQuiesce(std::unique_ptr<openpower::pels::PEL>& pel)
diff --git a/extensions/openpower-pels/manager.hpp b/extensions/openpower-pels/manager.hpp
index ae8670f..4432634 100644
--- a/extensions/openpower-pels/manager.hpp
+++ b/extensions/openpower-pels/manager.hpp
@@ -211,7 +211,7 @@
      *
      * @return std::string - The fully parsed PEL in JSON
      */
-    std::string getPELJSON(uint32_t obmcLogID);
+    std::string getPELJSON(uint32_t obmcLogID) override;
 
     /**
      * @brief Converts the ESEL field in an OpenBMC event log to a