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 #include "utils/query_param.hpp"
16
17 #include <boost/beast/http/field.hpp>
18 #include <boost/beast/http/status.hpp>
19 #include <boost/beast/http/verb.hpp>
20 #include <boost/system/linux_error.hpp>
21 #include <boost/url/format.hpp>
22 #include <boost/url/url.hpp>
23 #include <sdbusplus/message.hpp>
24 #include <sdbusplus/message/native_types.hpp>
25 #include <sdbusplus/unpack_properties.hpp>
26
27 #include <string>
28
29 namespace redfish
30 {
31
handleSystemsLogServiceEventLogLogEntryCollection(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)32 inline void handleSystemsLogServiceEventLogLogEntryCollection(
33 crow::App& app, const crow::Request& req,
34 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
35 const std::string& systemName)
36 {
37 query_param::QueryCapabilities capabilities = {
38 .canDelegateTop = true,
39 .canDelegateSkip = true,
40 };
41 query_param::Query delegatedQuery;
42 if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp,
43 delegatedQuery, capabilities))
44 {
45 return;
46 }
47 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
48 {
49 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
50 systemName);
51 return;
52 }
53 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
54 {
55 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
56 systemName);
57 return;
58 }
59
60 eventlog_utils::
61 handleSystemsAndManagersLogServiceEventLogLogEntryCollection(
62 asyncResp, delegatedQuery,
63 eventlog_utils::LogServiceParent::Systems);
64 }
65
handleSystemsLogServiceEventLogEntriesGet(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName,const std::string & param)66 inline void handleSystemsLogServiceEventLogEntriesGet(
67 crow::App& app, const crow::Request& req,
68 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
69 const std::string& systemName, const std::string& param)
70 {
71 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
72 {
73 return;
74 }
75 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
76 {
77 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
78 systemName);
79 return;
80 }
81
82 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
83 {
84 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
85 systemName);
86 return;
87 }
88
89 eventlog_utils::handleSystemsAndManagersLogServiceEventLogEntriesGet(
90 asyncResp, param, eventlog_utils::LogServiceParent::Systems);
91 }
92
handleSystemsLogServicesEventLogActionsClearPost(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)93 inline void handleSystemsLogServicesEventLogActionsClearPost(
94 crow::App& app, const crow::Request& req,
95 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
96 const std::string& systemName)
97 {
98 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
99 {
100 return;
101 }
102 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
103 {
104 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
105 systemName);
106 return;
107 }
108
109 eventlog_utils::handleSystemsAndManagersLogServicesEventLogActionsClearPost(
110 asyncResp);
111 }
112
requestRoutesSystemsJournalEventLog(App & app)113 inline void requestRoutesSystemsJournalEventLog(App& app)
114 {
115 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
116 .privileges(redfish::privileges::getLogEntryCollection)
117 .methods(boost::beast::http::verb::get)(std::bind_front(
118 handleSystemsLogServiceEventLogLogEntryCollection, std::ref(app)));
119
120 BMCWEB_ROUTE(
121 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
122 .privileges(redfish::privileges::getLogEntry)
123 .methods(boost::beast::http::verb::get)(std::bind_front(
124 handleSystemsLogServiceEventLogEntriesGet, std::ref(app)));
125
126 BMCWEB_ROUTE(
127 app,
128 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
129 .privileges(redfish::privileges::
130 postLogServiceSubOverComputerSystemLogServiceCollection)
131 .methods(boost::beast::http::verb::post)(std::bind_front(
132 handleSystemsLogServicesEventLogActionsClearPost, std::ref(app)));
133 }
134 } // namespace redfish
135