PEL: Read the journal info from the registry

Add support to the Registry class to read the JournalCapture information
out of the registry entry for an error if it is there.  This will then
be used by the PEL class when creating a PEL.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I529e4fb352c6eb33ad73b2a04ac4467710865139
diff --git a/extensions/openpower-pels/registry.cpp b/extensions/openpower-pels/registry.cpp
index 87d9875..9cccb0b 100644
--- a/extensions/openpower-pels/registry.cpp
+++ b/extensions/openpower-pels/registry.cpp
@@ -578,6 +578,58 @@
     return getCalloutsWithoutAD((*it)["Callouts"], systemNames);
 }
 
+/**
+ * @brief Returns the journal capture information
+ *
+ *  The JSON looks like:
+ *    "JournalCapture": {
+ *        "NumLines": 30
+ *    }
+ *
+ *    "JournalCapture":
+ *    {
+ *        "Sections": [
+ *            {
+ *                "SyslogID": "phosphor-log-manager",
+ *                "NumLines": 20
+ *            }
+ *        ]
+ *    }
+ *
+ * @param json - The journal capture JSON
+ * @return JournalCapture - The filled in variant
+ */
+JournalCapture getJournalCapture(const nlohmann::json& json)
+{
+    JournalCapture capt;
+
+    // Primary key is either NumLines or Sections.
+    if (json.contains("NumLines"))
+    {
+        capt = json.at("NumLines").get<size_t>();
+    }
+    else if (json.contains("Sections"))
+    {
+        AppCaptureList captures;
+        for (const auto& capture : json.at("Sections"))
+        {
+            AppCapture ac;
+            ac.syslogID = capture.at("SyslogID").get<std::string>();
+            ac.numLines = capture.at("NumLines").get<size_t>();
+            captures.push_back(std::move(ac));
+        }
+
+        capt = captures;
+    }
+    else
+    {
+        log<level::ERR>("JournalCapture section not the right format");
+        throw std::runtime_error{"JournalCapture section not the right format"};
+    }
+
+    return capt;
+}
+
 } // namespace helper
 
 std::optional<Entry> Registry::lookup(const std::string& name, LookupType type,
@@ -704,6 +756,12 @@
                 }
             }
 
+            if (e->contains("JournalCapture"))
+            {
+                entry.journalCapture =
+                    helper::getJournalCapture((*e)["JournalCapture"]);
+            }
+
             return entry;
         }
         catch (const std::exception& ex)
diff --git a/extensions/openpower-pels/registry.hpp b/extensions/openpower-pels/registry.hpp
index f5888b3..7ee5979 100644
--- a/extensions/openpower-pels/registry.hpp
+++ b/extensions/openpower-pels/registry.hpp
@@ -6,6 +6,7 @@
 #include <filesystem>
 #include <optional>
 #include <string>
+#include <variant>
 #include <vector>
 
 namespace openpower
@@ -107,6 +108,17 @@
     SRC() : type(0), reasonCode(0) {}
 };
 
+struct AppCapture
+{
+    std::string syslogID;
+    size_t numLines;
+};
+
+// Can specify either the syslog IDs to capture along with how many
+// entries of each, or just how many entries to get the full journal.
+using AppCaptureList = std::vector<AppCapture>;
+using JournalCapture = std::variant<size_t, AppCaptureList>;
+
 /**
  * @brief Represents a message registry entry, which is used for creating a
  *        PEL from an OpenBMC event log.
@@ -180,6 +192,11 @@
      * @brief The callout JSON, if the entry has callouts.
      */
     std::optional<nlohmann::json> callouts;
+
+    /**
+     * @brief The journal capture instructions, if present.
+     */
+    std::optional<JournalCapture> journalCapture;
 };
 
 /**