xref: /openbmc/bmcweb/redfish-core/lib/manager_logservices_dbus_eventlog.hpp (revision c621786ea25e9a82187a52a95e9810cf989ace72)
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
4 #pragma once
5 
6 #include "app.hpp"
7 #include "async_resp.hpp"
8 #include "error_messages.hpp"
9 #include "http_request.hpp"
10 #include "query.hpp"
11 #include "registries/privilege_registry.hpp"
12 #include "utils/eventlog_utils.hpp"
13 
14 #include <boost/beast/http/field.hpp>
15 #include <boost/beast/http/status.hpp>
16 #include <boost/beast/http/verb.hpp>
17 #include <boost/system/linux_error.hpp>
18 #include <boost/url/format.hpp>
19 #include <boost/url/url.hpp>
20 #include <sdbusplus/message.hpp>
21 #include <sdbusplus/message/native_types.hpp>
22 #include <sdbusplus/unpack_properties.hpp>
23 
24 #include <memory>
25 #include <string>
26 
27 namespace redfish
28 {
29 
handleManagersDBusEventLogEntryCollection(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & managerId)30 inline void handleManagersDBusEventLogEntryCollection(
31     crow::App& app, const crow::Request& req,
32     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
33     const std::string& managerId)
34 {
35     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
36     {
37         return;
38     }
39     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
40     {
41         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
42         return;
43     }
44     eventlog_utils::dBusEventLogEntryCollection(
45         asyncResp, eventlog_utils::LogServiceParent::Managers);
46 }
47 
handleManagersDBusEventLogEntryGet(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & managerId,const std::string & entryId)48 inline void handleManagersDBusEventLogEntryGet(
49     crow::App& app, const crow::Request& req,
50     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
51     const std::string& managerId, const std::string& entryId)
52 {
53     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
54     {
55         return;
56     }
57     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
58     {
59         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
60         return;
61     }
62 
63     eventlog_utils::dBusEventLogEntryGet(
64         asyncResp, eventlog_utils::LogServiceParent::Managers, entryId);
65 }
66 
handleManagersDBusEventLogEntryPatch(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & managerId,const std::string & entryId)67 inline void handleManagersDBusEventLogEntryPatch(
68     crow::App& app, const crow::Request& req,
69     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
70     const std::string& managerId, const std::string& entryId)
71 {
72     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
73     {
74         return;
75     }
76     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
77     {
78         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
79         return;
80     }
81 
82     eventlog_utils::dBusEventLogEntryPatch(req, asyncResp, entryId);
83 }
84 
handleManagersDBusEventLogEntryDelete(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & managerId,const std::string & entryId)85 inline void handleManagersDBusEventLogEntryDelete(
86     crow::App& app, const crow::Request& req,
87     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
88     const std::string& managerId, const std::string& entryId)
89 {
90     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
91     {
92         return;
93     }
94     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
95     {
96         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
97         return;
98     }
99 
100     eventlog_utils::dBusEventLogEntryDelete(asyncResp, entryId);
101 }
102 
handleManagersDBusLogServiceActionsClear(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & managerId)103 inline void handleManagersDBusLogServiceActionsClear(
104     crow::App& app, const crow::Request& req,
105     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
106     const std::string& managerId)
107 {
108     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
109     {
110         return;
111     }
112     if (!http_helpers::isContentTypeAllowed(
113             req.getHeaderValue("Accept"),
114             http_helpers::ContentType::OctetStream, true))
115     {
116         asyncResp->res.result(boost::beast::http::status::bad_request);
117     }
118     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
119     {
120         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
121         return;
122     }
123     eventlog_utils::dBusLogServiceActionsClear(asyncResp);
124 }
125 
handleManagersDBusEventLogEntryDownload(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & managerId,const std::string & entryId)126 inline void handleManagersDBusEventLogEntryDownload(
127     crow::App& app, const crow::Request& req,
128     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
129     const std::string& managerId, const std::string& entryId)
130 {
131     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
132     {
133         return;
134     }
135     if (!http_helpers::isContentTypeAllowed(
136             req.getHeaderValue("Accept"),
137             http_helpers::ContentType::OctetStream, true))
138     {
139         asyncResp->res.result(boost::beast::http::status::bad_request);
140     }
141     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
142     {
143         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
144         return;
145     }
146     eventlog_utils::downloadEventLogEntry(asyncResp, entryId, "System");
147 }
148 
requestRoutesManagersDBusEventLog(App & app)149 inline void requestRoutesManagersDBusEventLog(App& app)
150 {
151     BMCWEB_ROUTE(app,
152                  "/redfish/v1/Managers/<str>/LogServices/EventLog/Entries/")
153         .privileges(redfish::privileges::getLogEntryCollection)
154         .methods(boost::beast::http::verb::get)(std::bind_front(
155             handleManagersDBusEventLogEntryCollection, std::ref(app)));
156     BMCWEB_ROUTE(
157         app, "/redfish/v1/Managers/<str>/LogServices/EventLog/Entries/<str>/")
158         .privileges(redfish::privileges::getLogEntry)
159         .methods(boost::beast::http::verb::get)(
160             std::bind_front(handleManagersDBusEventLogEntryGet, std::ref(app)));
161 
162     BMCWEB_ROUTE(
163         app, "/redfish/v1/Managers/<str>/LogServices/EventLog/Entries/<str>/")
164         .privileges(redfish::privileges::patchLogEntry)
165         .methods(boost::beast::http::verb::patch)(std::bind_front(
166             handleManagersDBusEventLogEntryPatch, std::ref(app)));
167 
168     BMCWEB_ROUTE(
169         app, "/redfish/v1/Managers/<str>/LogServices/EventLog/Entries/<str>/")
170         .privileges(
171             redfish::privileges::
172                 deleteLogEntrySubOverComputerSystemLogServiceCollectionLogServiceLogEntryCollection)
173         .methods(boost::beast::http::verb::delete_)(std::bind_front(
174             handleManagersDBusEventLogEntryDelete, std::ref(app)));
175 
176     BMCWEB_ROUTE(
177         app,
178         "/redfish/v1/Managers/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
179         .privileges(redfish::privileges::
180                         postLogServiceSubOverComputerSystemLogServiceCollection)
181         .methods(boost::beast::http::verb::post)(std::bind_front(
182             handleManagersDBusLogServiceActionsClear, std::ref(app)));
183     BMCWEB_ROUTE(
184         app,
185         "/redfish/v1/Managers/<str>/LogServices/EventLog/Entries/<str>/attachment/")
186         .privileges(redfish::privileges::getLogEntry)
187         .methods(boost::beast::http::verb::get)(std::bind_front(
188             handleManagersDBusEventLogEntryDownload, std::ref(app)));
189 }
190 } // namespace redfish
191