crit-service: initial service and parsing
This is an initial commit in a series of commits that will introduce a
service monitoring feature within the current target monitoring
function.
This new feature will allow a user to pass in a json file with systemd
service names that they wish this function to monitor. If a monitored
services goes into an error state (exhausted all retries and service has
been stopped) then the monitor service will create an error and collect
appropriate debug data.
This commit focuses on defining the new json service file and adapting
the existing target monitor to take this file as input. Future commits
in this series will build on this.
Tested:
- Verified new service json could be input to application and it was
parsed correctly
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: Ifcc512b8fc868e2a1004a184fa50e4d4c826e8ee
diff --git a/systemd_service_parser.hpp b/systemd_service_parser.hpp
new file mode 100644
index 0000000..54d36b2
--- /dev/null
+++ b/systemd_service_parser.hpp
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <nlohmann/json.hpp>
+
+#include <map>
+#include <string>
+#include <vector>
+
+/** @brief Array of services to monitor */
+using ServiceMonitorData = std::vector<std::string>;
+
+using json = nlohmann::json;
+
+extern bool gVerbose;
+
+/** @brief Parse input json file(s) for services to monitor
+ *
+ * @note This function will throw exceptions for an invalid json file
+ * @note See phosphor-service-monitor-default.json for example of json file
+ * format
+ *
+ * @param[in] filePaths - The file(s) to parse
+ *
+ * @return Service(s) to monitor for errors
+ */
+ServiceMonitorData parseServiceFiles(const std::vector<std::string>& filePaths);