xref: /openbmc/bmcweb/redfish-core/lib/systems_logservices_dbus_eventlog.hpp (revision 6926d43047446a1f08d4b157d48a30221ae8f87e)
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 "bmcweb_config.h"
7 
8 #include "app.hpp"
9 #include "async_resp.hpp"
10 #include "error_messages.hpp"
11 #include "http_request.hpp"
12 #include "query.hpp"
13 #include "registries/privilege_registry.hpp"
14 #include "utils/eventlog_utils.hpp"
15 
16 #include <boost/beast/http/field.hpp>
17 #include <boost/beast/http/status.hpp>
18 #include <boost/beast/http/verb.hpp>
19 #include <boost/system/linux_error.hpp>
20 #include <boost/url/format.hpp>
21 #include <boost/url/url.hpp>
22 #include <sdbusplus/message.hpp>
23 #include <sdbusplus/message/native_types.hpp>
24 #include <sdbusplus/unpack_properties.hpp>
25 
26 #include <string>
27 
28 namespace redfish
29 {
30 
handleSystemsDBusEventLogEntryCollection(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)31 inline void handleSystemsDBusEventLogEntryCollection(
32     crow::App& app, const crow::Request& req,
33     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
34     const std::string& systemName)
35 {
36     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
37     {
38         return;
39     }
40     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
41     {
42         // Option currently returns no systems.  TBD
43         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
44                                    systemName);
45         return;
46     }
47     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
48     {
49         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
50                                    systemName);
51         return;
52     }
53     eventlog_utils::dBusEventLogEntryCollection(
54         asyncResp, eventlog_utils::LogServiceParent::Systems);
55 }
56 
handleSystemsDBusEventLogEntryGet(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName,const std::string & entryId)57 inline void handleSystemsDBusEventLogEntryGet(
58     crow::App& app, const crow::Request& req,
59     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
60     const std::string& systemName, const std::string& entryId)
61 {
62     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
63     {
64         return;
65     }
66     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
67     {
68         // Option currently returns no systems.  TBD
69         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
70                                    systemName);
71         return;
72     }
73     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
74     {
75         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
76                                    systemName);
77         return;
78     }
79 
80     eventlog_utils::dBusEventLogEntryGet(
81         asyncResp, eventlog_utils::LogServiceParent::Systems, entryId);
82 }
83 
handleSystemsDBusEventLogEntryPatch(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName,const std::string & entryId)84 inline void handleSystemsDBusEventLogEntryPatch(
85     crow::App& app, const crow::Request& req,
86     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
87     const std::string& systemName, const std::string& entryId)
88 {
89     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
90     {
91         return;
92     }
93     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
94     {
95         // Option currently returns no systems.  TBD
96         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
97                                    systemName);
98         return;
99     }
100     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
101     {
102         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
103                                    systemName);
104         return;
105     }
106 
107     eventlog_utils::dBusEventLogEntryPatch(req, asyncResp, entryId);
108 }
109 
handleSystemsDBusEventLogEntryDelete(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName,const std::string & entryId)110 inline void handleSystemsDBusEventLogEntryDelete(
111     crow::App& app, const crow::Request& req,
112     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
113     const std::string& systemName, const std::string& entryId)
114 {
115     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
116     {
117         return;
118     }
119     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
120     {
121         // Option currently returns no systems.  TBD
122         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
123                                    systemName);
124         return;
125     }
126     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
127     {
128         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
129                                    systemName);
130         return;
131     }
132 
133     eventlog_utils::dBusEventLogEntryDelete(asyncResp, entryId);
134 }
135 
handleSystemsDBusLogServiceActionsClear(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)136 inline void handleSystemsDBusLogServiceActionsClear(
137     crow::App& app, const crow::Request& req,
138     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
139     const std::string& systemName)
140 {
141     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
142     {
143         return;
144     }
145     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
146     {
147         // Option currently returns no systems.  TBD
148         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
149                                    systemName);
150         return;
151     }
152     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
153     {
154         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
155                                    systemName);
156         return;
157     }
158 
159     eventlog_utils::dBusLogServiceActionsClear(asyncResp);
160 }
161 
handleSystemsDBusEventLogEntryDownloadGet(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName,const std::string & entryId)162 inline void handleSystemsDBusEventLogEntryDownloadGet(
163     crow::App& app, const crow::Request& req,
164     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
165     const std::string& systemName, const std::string& entryId)
166 {
167     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
168     {
169         return;
170     }
171     if (!http_helpers::isContentTypeAllowed(
172             req.getHeaderValue("Accept"),
173             http_helpers::ContentType::OctetStream, true))
174     {
175         asyncResp->res.result(boost::beast::http::status::bad_request);
176         return;
177     }
178     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
179     {
180         // Option currently returns no systems.  TBD
181         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
182                                    systemName);
183         return;
184     }
185     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
186     {
187         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
188                                    systemName);
189         return;
190     }
191 
192     eventlog_utils::downloadEventLogEntry(asyncResp, entryId, "System");
193 }
194 
requestRoutesSystemsDBusEventLog(App & app)195 inline void requestRoutesSystemsDBusEventLog(App& app)
196 {
197     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
198         .privileges(redfish::privileges::getLogEntryCollection)
199         .methods(boost::beast::http::verb::get)(std::bind_front(
200             handleSystemsDBusEventLogEntryCollection, std::ref(app)));
201 
202     BMCWEB_ROUTE(
203         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
204         .privileges(redfish::privileges::getLogEntry)
205         .methods(boost::beast::http::verb::get)(
206             std::bind_front(handleSystemsDBusEventLogEntryGet, std::ref(app)));
207 
208     BMCWEB_ROUTE(
209         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
210         .privileges(redfish::privileges::patchLogEntry)
211         .methods(boost::beast::http::verb::patch)(std::bind_front(
212             handleSystemsDBusEventLogEntryPatch, std::ref(app)));
213 
214     BMCWEB_ROUTE(
215         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
216         .privileges(
217             redfish::privileges::
218                 deleteLogEntrySubOverComputerSystemLogServiceCollectionLogServiceLogEntryCollection)
219         .methods(boost::beast::http::verb::delete_)(std::bind_front(
220             handleSystemsDBusEventLogEntryDelete, std::ref(app)));
221 
222     BMCWEB_ROUTE(
223         app,
224         "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
225         .privileges(redfish::privileges::
226                         postLogServiceSubOverComputerSystemLogServiceCollection)
227         .methods(boost::beast::http::verb::post)(std::bind_front(
228             handleSystemsDBusLogServiceActionsClear, std::ref(app)));
229 
230     BMCWEB_ROUTE(
231         app,
232         "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/")
233         .privileges(redfish::privileges::getLogEntry)
234         .methods(boost::beast::http::verb::get)(std::bind_front(
235             handleSystemsDBusEventLogEntryDownloadGet, std::ref(app)));
236 }
237 } // namespace redfish
238