blob: 6cacc179ad2fbda150cf4cb631ff86af09b676d5 [file] [log] [blame]
Jason M. Bills70304cb2019-03-27 12:03:59 -07001/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
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"
Jason M. Billsfbe83782019-03-27 14:14:53 -070022#include "registries/openbmc_message_registry.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080023#include "registries/privilege_registry.hpp"
Sunitha Harish74eec262020-06-25 10:00:01 -050024#include "registries/resource_event_message_registry.hpp"
James Feiste51c7102020-03-17 10:38:18 -070025#include "registries/task_event_message_registry.hpp"
Michal Orzel86987602024-06-24 08:19:49 +020026#include "registries/telemetry_message_registry.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070027
Ed Tanousef4c65b2023-04-24 15:28:50 -070028#include <boost/url/format.hpp>
29
Ed Tanous613dabe2022-07-09 11:17:36 -070030#include <array>
31
Jason M. Bills70304cb2019-03-27 12:03:59 -070032namespace redfish
33{
34
John Edward Broadbentdff07822021-07-13 11:20:47 -070035inline void handleMessageRegistryFileCollectionGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070036 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080037 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070038{
Carson Labrado3ba00072022-06-06 19:40:56 +000039 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070040 {
41 return;
42 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070043 // Collections don't include the static data added by SubRoute
44 // because it has a duplicate entry for members
45
Ed Tanous14766872022-03-15 10:44:42 -070046 asyncResp->res.jsonValue["@odata.type"] =
47 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
48 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
49 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
50 asyncResp->res.jsonValue["Description"] =
51 "Collection of MessageRegistryFiles";
Michal Orzel86987602024-06-24 08:19:49 +020052 asyncResp->res.jsonValue["Members@odata.count"] = 5;
Ed Tanous613dabe2022-07-09 11:17:36 -070053
54 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
Michal Orzel86987602024-06-24 08:19:49 +020055 for (const char* memberName : std::to_array(
56 {"Base", "TaskEvent", "ResourceEvent", "OpenBMC", "Telemetry"}))
Ed Tanous613dabe2022-07-09 11:17:36 -070057 {
58 nlohmann::json::object_t member;
Patrick Williamsbd79bce2024-08-16 15:22:20 -040059 member["@odata.id"] =
60 boost::urls::format("/redfish/v1/Registries/{}", memberName);
Ed Tanous613dabe2022-07-09 11:17:36 -070061 members.emplace_back(std::move(member));
62 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070063}
64
John Edward Broadbent7e860f12021-04-08 15:57:16 -070065inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070066{
Jason M. Bills70304cb2019-03-27 12:03:59 -070067 /**
68 * Functions triggers appropriate requests on DBus
69 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070070 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070071 .privileges(redfish::privileges::getMessageRegistryFileCollection)
Ed Tanous45ca1b82022-03-25 13:07:27 -070072 .methods(boost::beast::http::verb::get)(std::bind_front(
73 handleMessageRegistryFileCollectionGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -070074}
Ed Tanous14c8aee2019-06-13 13:39:16 -070075
John Edward Broadbentdff07822021-07-13 11:20:47 -070076inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070077 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080078 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070079 const std::string& registry)
80{
Carson Labrado3ba00072022-06-06 19:40:56 +000081 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070082 {
83 return;
84 }
Ed Tanousfffb8c12022-02-07 23:53:03 -080085 const registries::Header* header = nullptr;
John Edward Broadbentdff07822021-07-13 11:20:47 -070086 std::string dmtf = "DMTF ";
87 const char* url = nullptr;
88
89 if (registry == "Base")
90 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080091 header = &registries::base::header;
92 url = registries::base::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070093 }
94 else if (registry == "TaskEvent")
95 {
Ed Tanousfffb8c12022-02-07 23:53:03 -080096 header = &registries::task_event::header;
97 url = registries::task_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070098 }
99 else if (registry == "OpenBMC")
100 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800101 header = &registries::openbmc::header;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700102 dmtf.clear();
103 }
104 else if (registry == "ResourceEvent")
105 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800106 header = &registries::resource_event::header;
107 url = registries::resource_event::url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700108 }
Michal Orzel86987602024-06-24 08:19:49 +0200109 else if (registry == "Telemetry")
110 {
111 header = &registries::telemetry::header;
112 url = registries::telemetry::url;
113 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700114 else
115 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800116 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
117 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700118 return;
119 }
120
Ed Tanous14766872022-03-15 10:44:42 -0700121 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700122 boost::urls::format("/redfish/v1/Registries/{}", registry);
Ed Tanous14766872022-03-15 10:44:42 -0700123 asyncResp->res.jsonValue["@odata.type"] =
124 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
125 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400126 asyncResp->res.jsonValue["Description"] =
127 dmtf + registry + " Message Registry File Location";
Ed Tanous14766872022-03-15 10:44:42 -0700128 asyncResp->res.jsonValue["Id"] = header->registryPrefix;
129 asyncResp->res.jsonValue["Registry"] = header->id;
Ed Tanous613dabe2022-07-09 11:17:36 -0700130 nlohmann::json::array_t languages;
Alexander Paramonov3ad903a2024-04-23 16:35:40 +0300131 languages.emplace_back(header->language);
Ed Tanous613dabe2022-07-09 11:17:36 -0700132 asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
133 asyncResp->res.jsonValue["Languages"] = std::move(languages);
134 nlohmann::json::array_t locationMembers;
135 nlohmann::json::object_t location;
Alexander Paramonov3ad903a2024-04-23 16:35:40 +0300136 location["Language"] = header->language;
Ed Tanous613dabe2022-07-09 11:17:36 -0700137 location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700138
139 if (url != nullptr)
140 {
Ed Tanous613dabe2022-07-09 11:17:36 -0700141 location["PublicationUri"] = url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700142 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700143 locationMembers.emplace_back(std::move(location));
144 asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
145 asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700146}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700147
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700148inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700149{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700150 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700151 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700152 .methods(boost::beast::http::verb::get)(std::bind_front(
153 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700154}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700155
John Edward Broadbentdff07822021-07-13 11:20:47 -0700156inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700157 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800158 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700159 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700160
John Edward Broadbentdff07822021-07-13 11:20:47 -0700161{
Carson Labrado3ba00072022-06-06 19:40:56 +0000162 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700163 {
164 return;
165 }
Ed Tanousfffb8c12022-02-07 23:53:03 -0800166 const registries::Header* header = nullptr;
167 std::vector<const registries::MessageEntry*> registryEntries;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700168 if (registry == "Base")
169 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800170 header = &registries::base::header;
171 for (const registries::MessageEntry& entry : registries::base::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700172 {
173 registryEntries.emplace_back(&entry);
174 }
175 }
176 else if (registry == "TaskEvent")
177 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800178 header = &registries::task_event::header;
179 for (const registries::MessageEntry& entry :
180 registries::task_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700181 {
182 registryEntries.emplace_back(&entry);
183 }
184 }
185 else if (registry == "OpenBMC")
186 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800187 header = &registries::openbmc::header;
188 for (const registries::MessageEntry& entry :
189 registries::openbmc::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700190 {
191 registryEntries.emplace_back(&entry);
192 }
193 }
194 else if (registry == "ResourceEvent")
195 {
Ed Tanousfffb8c12022-02-07 23:53:03 -0800196 header = &registries::resource_event::header;
197 for (const registries::MessageEntry& entry :
198 registries::resource_event::registry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700199 {
200 registryEntries.emplace_back(&entry);
201 }
202 }
Michal Orzel86987602024-06-24 08:19:49 +0200203 else if (registry == "Telemetry")
204 {
205 header = &registries::telemetry::header;
206 for (const registries::MessageEntry& entry :
207 registries::telemetry::registry)
208 {
209 registryEntries.emplace_back(&entry);
210 }
211 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700212 else
213 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800214 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
215 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700216 return;
217 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700218
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700219 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700220 {
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700221 messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700222 return;
223 }
224
Ed Tanous14766872022-03-15 10:44:42 -0700225 asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright;
226 asyncResp->res.jsonValue["@odata.type"] = header->type;
227 asyncResp->res.jsonValue["Id"] = header->id;
228 asyncResp->res.jsonValue["Name"] = header->name;
229 asyncResp->res.jsonValue["Language"] = header->language;
230 asyncResp->res.jsonValue["Description"] = header->description;
231 asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix;
232 asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion;
233 asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700234
235 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
236
237 // Go through the Message Registry and populate each Message
Ed Tanousfffb8c12022-02-07 23:53:03 -0800238 for (const registries::MessageEntry* message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700239 {
240 nlohmann::json& obj = messageObj[message->first];
Ed Tanous14766872022-03-15 10:44:42 -0700241 obj["Description"] = message->second.description;
242 obj["Message"] = message->second.message;
243 obj["Severity"] = message->second.messageSeverity;
244 obj["MessageSeverity"] = message->second.messageSeverity;
245 obj["NumberOfArgs"] = message->second.numberOfArgs;
246 obj["Resolution"] = message->second.resolution;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700247 if (message->second.numberOfArgs > 0)
248 {
249 nlohmann::json& messageParamArray = obj["ParamTypes"];
250 messageParamArray = nlohmann::json::array();
251 for (const char* str : message->second.paramTypes)
252 {
253 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700254 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700255 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700256 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700257 messageParamArray.push_back(str);
258 }
259 }
260 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700261}
262
263inline void requestRoutesMessageRegistry(App& app)
264{
265 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700266 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700267 .methods(boost::beast::http::verb::get)(
268 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700269}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700270} // namespace redfish