blob: a6c36749cde06dc95e38e98763e30d4a5d0d90a3 [file] [log] [blame]
Jason M. Bills70304cb2019-03-27 12:03:59 -07001/*
Ed Tanous6be832e2024-09-10 11:44:48 -07002Copyright (c) 2019 Intel Corporation
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
Jason M. Bills70304cb2019-03-27 12:03:59 -070015*/
16#pragma once
17
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "app.hpp"
19#include "query.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070020#include "registries.hpp"
21#include "registries/base_message_registry.hpp"
Myung Baefb546102024-10-29 10:21:26 -050022#include "registries/heartbeat_event_message_registry.hpp"
Jason M. Billsfbe83782019-03-27 14:14:53 -070023#include "registries/openbmc_message_registry.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080024#include "registries/privilege_registry.hpp"
Sunitha Harish74eec262020-06-25 10:00:01 -050025#include "registries/resource_event_message_registry.hpp"
James Feiste51c7102020-03-17 10:38:18 -070026#include "registries/task_event_message_registry.hpp"
Michal Orzel86987602024-06-24 08:19:49 +020027#include "registries/telemetry_message_registry.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070028
Ed Tanousef4c65b2023-04-24 15:28:50 -070029#include <boost/url/format.hpp>
30
Ed Tanous613dabe2022-07-09 11:17:36 -070031#include <array>
32
Jason M. Bills70304cb2019-03-27 12:03:59 -070033namespace redfish
34{
35
John Edward Broadbentdff07822021-07-13 11:20:47 -070036inline void handleMessageRegistryFileCollectionGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070037 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080038 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070039{
Carson Labrado3ba00072022-06-06 19:40:56 +000040 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070041 {
42 return;
43 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070044 // Collections don't include the static data added by SubRoute
45 // because it has a duplicate entry for members
46
Ed Tanous14766872022-03-15 10:44:42 -070047 asyncResp->res.jsonValue["@odata.type"] =
48 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
49 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
50 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
51 asyncResp->res.jsonValue["Description"] =
52 "Collection of MessageRegistryFiles";
Ed Tanous613dabe2022-07-09 11:17:36 -070053
54 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
Myung Baefb546102024-10-29 10:21:26 -050055
56 static constexpr const auto registryFiles = std::to_array(
57 {"Base", "TaskEvent", "ResourceEvent", "OpenBMC", "Telemetry",
58 "HeartbeatEvent"});
59
60 for (const char* memberName : registryFiles)
Ed Tanous613dabe2022-07-09 11:17:36 -070061 {
62 nlohmann::json::object_t member;
Patrick Williamsbd79bce2024-08-16 15:22:20 -040063 member["@odata.id"] =
64 boost::urls::format("/redfish/v1/Registries/{}", memberName);
Ed Tanous613dabe2022-07-09 11:17:36 -070065 members.emplace_back(std::move(member));
66 }
Myung Baefb546102024-10-29 10:21:26 -050067 asyncResp->res.jsonValue["Members@odata.count"] = members.size();
John Edward Broadbentdff07822021-07-13 11:20:47 -070068}
69
John Edward Broadbent7e860f12021-04-08 15:57:16 -070070inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070071{
Jason M. Bills70304cb2019-03-27 12:03:59 -070072 /**
73 * Functions triggers appropriate requests on DBus
74 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070075 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070076 .privileges(redfish::privileges::getMessageRegistryFileCollection)
Ed Tanous45ca1b82022-03-25 13:07:27 -070077 .methods(boost::beast::http::verb::get)(std::bind_front(
78 handleMessageRegistryFileCollectionGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -070079}
Ed Tanous14c8aee2019-06-13 13:39:16 -070080
John Edward Broadbentdff07822021-07-13 11:20:47 -070081inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070082 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080083 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070084 const std::string& registry)
85{
Carson Labrado3ba00072022-06-06 19:40:56 +000086 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070087 {
88 return;
89 }
Ed Tanousfffb8c12022-02-07 23:53:03 -080090 const registries::Header* header = nullptr;
John Edward Broadbentdff07822021-07-13 11:20:47 -070091 std::string dmtf = "DMTF ";
92 const char* url = nullptr;
93
94 if (registry == "Base")
95 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080096 header = &registries::base::header;
97 url = registries::base::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070098 }
99 else if (registry == "TaskEvent")
100 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800101 header = &registries::task_event::header;
102 url = registries::task_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700103 }
104 else if (registry == "OpenBMC")
105 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800106 header = &registries::openbmc::header;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700107 dmtf.clear();
108 }
109 else if (registry == "ResourceEvent")
110 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800111 header = &registries::resource_event::header;
112 url = registries::resource_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700113 }
Michal Orzel86987602024-06-24 08:19:49 +0200114 else if (registry == "Telemetry")
115 {
116 header = &registries::telemetry::header;
117 url = registries::telemetry::url;
118 }
Myung Baefb546102024-10-29 10:21:26 -0500119 else if (registry == "HeartbeatEvent")
120 {
121 header = &registries::heartbeat_event::header;
122 url = registries::heartbeat_event::url;
123 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700124 else
125 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800126 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
127 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700128 return;
129 }
130
Ed Tanous14766872022-03-15 10:44:42 -0700131 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700132 boost::urls::format("/redfish/v1/Registries/{}", registry);
Ed Tanous14766872022-03-15 10:44:42 -0700133 asyncResp->res.jsonValue["@odata.type"] =
134 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
135 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400136 asyncResp->res.jsonValue["Description"] =
137 dmtf + registry + " Message Registry File Location";
Ed Tanous14766872022-03-15 10:44:42 -0700138 asyncResp->res.jsonValue["Id"] = header->registryPrefix;
139 asyncResp->res.jsonValue["Registry"] = header->id;
Ed Tanous613dabe2022-07-09 11:17:36 -0700140 nlohmann::json::array_t languages;
Alexander Paramonov3ad903a2024-04-23 16:35:40 +0300141 languages.emplace_back(header->language);
Ed Tanous613dabe2022-07-09 11:17:36 -0700142 asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
143 asyncResp->res.jsonValue["Languages"] = std::move(languages);
144 nlohmann::json::array_t locationMembers;
145 nlohmann::json::object_t location;
Alexander Paramonov3ad903a2024-04-23 16:35:40 +0300146 location["Language"] = header->language;
Ed Tanous613dabe2022-07-09 11:17:36 -0700147 location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700148
149 if (url != nullptr)
150 {
Ed Tanous613dabe2022-07-09 11:17:36 -0700151 location["PublicationUri"] = url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700152 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700153 locationMembers.emplace_back(std::move(location));
154 asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
155 asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700156}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700157
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700158inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700159{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700160 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700161 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700162 .methods(boost::beast::http::verb::get)(std::bind_front(
163 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700164}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700165
John Edward Broadbentdff07822021-07-13 11:20:47 -0700166inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700167 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800168 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700169 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700170
John Edward Broadbentdff07822021-07-13 11:20:47 -0700171{
Carson Labrado3ba00072022-06-06 19:40:56 +0000172 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700173 {
174 return;
175 }
Ed Tanousfffb8c12022-02-07 23:53:03 -0800176 const registries::Header* header = nullptr;
177 std::vector<const registries::MessageEntry*> registryEntries;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700178 if (registry == "Base")
179 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800180 header = &registries::base::header;
181 for (const registries::MessageEntry& entry : registries::base::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700182 {
183 registryEntries.emplace_back(&entry);
184 }
185 }
186 else if (registry == "TaskEvent")
187 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800188 header = &registries::task_event::header;
189 for (const registries::MessageEntry& entry :
190 registries::task_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700191 {
192 registryEntries.emplace_back(&entry);
193 }
194 }
195 else if (registry == "OpenBMC")
196 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800197 header = &registries::openbmc::header;
198 for (const registries::MessageEntry& entry :
199 registries::openbmc::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700200 {
201 registryEntries.emplace_back(&entry);
202 }
203 }
204 else if (registry == "ResourceEvent")
205 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800206 header = &registries::resource_event::header;
207 for (const registries::MessageEntry& entry :
208 registries::resource_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700209 {
210 registryEntries.emplace_back(&entry);
211 }
212 }
Michal Orzel86987602024-06-24 08:19:49 +0200213 else if (registry == "Telemetry")
214 {
215 header = &registries::telemetry::header;
216 for (const registries::MessageEntry& entry :
217 registries::telemetry::registry)
218 {
219 registryEntries.emplace_back(&entry);
220 }
221 }
Myung Baefb546102024-10-29 10:21:26 -0500222 else if (registry == "HeartbeatEvent")
223 {
224 header = &registries::heartbeat_event::header;
225 for (const registries::MessageEntry& entry :
226 registries::heartbeat_event::registry)
227 {
228 registryEntries.emplace_back(&entry);
229 }
230 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700231 else
232 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800233 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
234 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700235 return;
236 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700237
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700238 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700239 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700240 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700241 return;
242 }
243
Ed Tanous14766872022-03-15 10:44:42 -0700244 asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright;
245 asyncResp->res.jsonValue["@odata.type"] = header->type;
246 asyncResp->res.jsonValue["Id"] = header->id;
247 asyncResp->res.jsonValue["Name"] = header->name;
248 asyncResp->res.jsonValue["Language"] = header->language;
249 asyncResp->res.jsonValue["Description"] = header->description;
250 asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix;
251 asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion;
252 asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700253
254 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
255
256 // Go through the Message Registry and populate each Message
Ed Tanousfffb8c12022-02-07 23:53:03 -0800257 for (const registries::MessageEntry* message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700258 {
259 nlohmann::json& obj = messageObj[message->first];
Ed Tanous14766872022-03-15 10:44:42 -0700260 obj["Description"] = message->second.description;
261 obj["Message"] = message->second.message;
262 obj["Severity"] = message->second.messageSeverity;
263 obj["MessageSeverity"] = message->second.messageSeverity;
264 obj["NumberOfArgs"] = message->second.numberOfArgs;
265 obj["Resolution"] = message->second.resolution;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700266 if (message->second.numberOfArgs > 0)
267 {
268 nlohmann::json& messageParamArray = obj["ParamTypes"];
269 messageParamArray = nlohmann::json::array();
270 for (const char* str : message->second.paramTypes)
271 {
272 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700273 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700274 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700275 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700276 messageParamArray.push_back(str);
277 }
278 }
279 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700280}
281
282inline void requestRoutesMessageRegistry(App& app)
283{
284 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700285 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700286 .methods(boost::beast::http::verb::get)(
287 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700288}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700289} // namespace redfish