Set severity for PELs

This commit adds an option to pass severity while logging PEL.
This will help to classify PELs based on their severity.
By default severity of all the PELs logged for system VPD failure
is set to be unrecoverable where as other failures are flagged as
predictive errors.

Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I9cd10a29252a42f5031b91b9c7ad2e284ed5b861
diff --git a/ibm_vpd_app.cpp b/ibm_vpd_app.cpp
index c677ba2..237d001 100644
--- a/ibm_vpd_app.cpp
+++ b/ibm_vpd_app.cpp
@@ -622,7 +622,7 @@
         PelAdditionalData additionalData{};
         additionalData.emplace("CALLOUT_INVENTORY_PATH", objectName);
         additionalData.emplace("DESCRIPTION", what);
-        createPEL(additionalData, errIntfForBusFailure);
+        createPEL(additionalData, PelSeverity::WARNING, errIntfForBusFailure);
     }
 }
 
@@ -688,7 +688,8 @@
 
                                 additionalData.emplace("DESCRIPTION", errMsg);
 
-                                createPEL(additionalData, errIntfForInvalidVPD);
+                                createPEL(additionalData, PelSeverity::WARNING,
+                                          errIntfForInvalidVPD);
                             }
                         }
                         else
@@ -724,7 +725,8 @@
                         additionalData.emplace("DESCRIPTION", errMsg);
 
                         // log PEL TODO: Block IPL
-                        createPEL(additionalData, errIntfForBlankSystemVPD);
+                        createPEL(additionalData, PelSeverity::ERROR,
+                                  errIntfForBlankSystemVPD);
                         continue;
                     }
                 }
@@ -930,6 +932,9 @@
     // vpd exception while parsing the file
     std::string baseFruInventoryPath = {};
 
+    // severity for PEL
+    PelSeverity pelSeverity = PelSeverity::WARNING;
+
     try
     {
         App app{"ibm-read-vpd - App to read IPZ format VPD, parse it and store "
@@ -941,6 +946,12 @@
 
         CLI11_PARSE(app, argc, argv);
 
+        // PEL severity should be ERROR in case of any system VPD failure
+        if (file == systemVpdFilePath)
+        {
+            pelSeverity = PelSeverity::ERROR;
+        }
+
         auto jsonToParse = INVENTORY_JSON_DEFAULT;
 
         // If the symlink exists, it means it has been setup for us, switch the
@@ -954,8 +965,7 @@
         ifstream inventoryJson(jsonToParse);
         if (!inventoryJson)
         {
-            throw(
-                (VpdJsonException("Failed to access Json path", jsonToParse)));
+            throw(VpdJsonException("Failed to access Json path", jsonToParse));
         }
 
         try
@@ -964,7 +974,7 @@
         }
         catch (json::parse_error& ex)
         {
-            throw((VpdJsonException("Json parsing failed", jsonToParse)));
+            throw(VpdJsonException("Json parsing failed", jsonToParse));
         }
 
         if ((js.find("frus") == js.end()) ||
@@ -1029,7 +1039,7 @@
     {
         additionalData.emplace("JSON_PATH", ex.getJsonPath());
         additionalData.emplace("DESCRIPTION", ex.what());
-        createPEL(additionalData, errIntfForJsonFailure);
+        createPEL(additionalData, pelSeverity, errIntfForJsonFailure);
 
         cerr << ex.what() << "\n";
         rc = -1;
@@ -1039,7 +1049,7 @@
         additionalData.emplace("DESCRIPTION", "ECC check failed");
         additionalData.emplace("CALLOUT_INVENTORY_PATH",
                                INVENTORY_PATH + baseFruInventoryPath);
-        createPEL(additionalData, errIntfForEccCheckFail);
+        createPEL(additionalData, pelSeverity, errIntfForEccCheckFail);
 
         cerr << ex.what() << "\n";
         rc = -1;
@@ -1049,7 +1059,7 @@
         additionalData.emplace("DESCRIPTION", "Invalid VPD data");
         additionalData.emplace("CALLOUT_INVENTORY_PATH",
                                INVENTORY_PATH + baseFruInventoryPath);
-        createPEL(additionalData, errIntfForInvalidVPD);
+        createPEL(additionalData, pelSeverity, errIntfForInvalidVPD);
 
         cerr << ex.what() << "\n";
         rc = -1;