Add ClearLog support for the Redfish Event Log Service

This change adds support for the LogService.ClearLog action to
clear the Redfish Event Log.

Tested:
   1. Added entries to the EventLog
   2. Sent the ClearLog action using Postman:
      /redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog
   3. Confirmed that the EventLog was empty
   4. Added entries to the EventLog
   5. Confirmed that the new entries logged successfully

Change-Id: I6ac4ea4aff8d7defbea693a2c8a755a712fb39a6
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index a2d083a..f65f3cc 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -496,6 +496,61 @@
         asyncResp->res.jsonValue["Entries"] = {
             {"@odata.id",
              "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}};
+        asyncResp->res.jsonValue["Actions"] = {
+            {{"#LogService.ClearLog",
+              {{"target", "/redfish/v1/Systems/system/LogServices/EventLog/"
+                          "Actions/LogService.ClearLog"}}}}};
+    }
+};
+
+class EventLogClear : public Node
+{
+  public:
+    EventLogClear(CrowApp &app) :
+        Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
+                  "LogService.ClearLog/")
+    {
+        entityPrivileges = {
+            {boost::beast::http::verb::get, {{"Login"}}},
+            {boost::beast::http::verb::head, {{"Login"}}},
+            {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
+            {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
+            {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
+            {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
+    }
+
+  private:
+    void doPost(crow::Response &res, const crow::Request &req,
+                const std::vector<std::string> &params) override
+    {
+        std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
+
+        // Clear the EventLog by deleting the log files
+        std::vector<std::filesystem::path> redfishLogFiles;
+        if (getRedfishLogFiles(redfishLogFiles))
+        {
+            for (const std::filesystem::path &file : redfishLogFiles)
+            {
+                std::error_code ec;
+                std::filesystem::remove(file, ec);
+            }
+        }
+
+        // Reload rsyslog so it knows to start new log files
+        crow::connections::systemBus->async_method_call(
+            [asyncResp](const boost::system::error_code ec) {
+                if (ec)
+                {
+                    BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec;
+                    messages::internalError(asyncResp->res);
+                    return;
+                }
+
+                messages::success(asyncResp->res);
+            },
+            "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
+            "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
+            "replace");
     }
 };