xref: /openbmc/bmcweb/features/redfish/lib/message_registries.hpp (revision fb54610544f97b989b549d8fc94518e2d38c9467)
170304cb5SJason M. Bills /*
26be832e2SEd Tanous Copyright (c) 2019 Intel Corporation
36be832e2SEd Tanous 
46be832e2SEd Tanous Licensed under the Apache License, Version 2.0 (the "License");
56be832e2SEd Tanous you may not use this file except in compliance with the License.
66be832e2SEd Tanous You may obtain a copy of the License at
76be832e2SEd Tanous 
86be832e2SEd Tanous       http://www.apache.org/licenses/LICENSE-2.0
96be832e2SEd Tanous 
106be832e2SEd Tanous Unless required by applicable law or agreed to in writing, software
116be832e2SEd Tanous distributed under the License is distributed on an "AS IS" BASIS,
126be832e2SEd Tanous WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136be832e2SEd Tanous See the License for the specific language governing permissions and
146be832e2SEd Tanous limitations under the License.
1570304cb5SJason M. Bills */
1670304cb5SJason M. Bills #pragma once
1770304cb5SJason M. Bills 
183ccb3adbSEd Tanous #include "app.hpp"
193ccb3adbSEd Tanous #include "query.hpp"
2070304cb5SJason M. Bills #include "registries.hpp"
2170304cb5SJason M. Bills #include "registries/base_message_registry.hpp"
22*fb546105SMyung Bae #include "registries/heartbeat_event_message_registry.hpp"
23fbe8378fSJason M. Bills #include "registries/openbmc_message_registry.hpp"
243ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
2574eec26bSSunitha Harish #include "registries/resource_event_message_registry.hpp"
26e51c710eSJames Feist #include "registries/task_event_message_registry.hpp"
2786987606SMichal Orzel #include "registries/telemetry_message_registry.hpp"
2870304cb5SJason M. Bills 
29ef4c65b7SEd Tanous #include <boost/url/format.hpp>
30ef4c65b7SEd Tanous 
31613dabeaSEd Tanous #include <array>
32613dabeaSEd Tanous 
3370304cb5SJason M. Bills namespace redfish
3470304cb5SJason M. Bills {
3570304cb5SJason M. Bills 
36dff07827SJohn Edward Broadbent inline void handleMessageRegistryFileCollectionGet(
3745ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
38104f09c9SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
3970304cb5SJason M. Bills {
403ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
4145ca1b86SEd Tanous     {
4245ca1b86SEd Tanous         return;
4345ca1b86SEd Tanous     }
447e860f15SJohn Edward Broadbent     // Collections don't include the static data added by SubRoute
457e860f15SJohn Edward Broadbent     // because it has a duplicate entry for members
4614c8aee2SEd Tanous 
471476687dSEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
481476687dSEd Tanous         "#MessageRegistryFileCollection.MessageRegistryFileCollection";
491476687dSEd Tanous     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
501476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
511476687dSEd Tanous     asyncResp->res.jsonValue["Description"] =
521476687dSEd Tanous         "Collection of MessageRegistryFiles";
53613dabeaSEd Tanous 
54613dabeaSEd Tanous     nlohmann::json& members = asyncResp->res.jsonValue["Members"];
55*fb546105SMyung Bae 
56*fb546105SMyung Bae     static constexpr const auto registryFiles = std::to_array(
57*fb546105SMyung Bae         {"Base", "TaskEvent", "ResourceEvent", "OpenBMC", "Telemetry",
58*fb546105SMyung Bae          "HeartbeatEvent"});
59*fb546105SMyung Bae 
60*fb546105SMyung Bae     for (const char* memberName : registryFiles)
61613dabeaSEd Tanous     {
62613dabeaSEd Tanous         nlohmann::json::object_t member;
63bd79bce8SPatrick Williams         member["@odata.id"] =
64bd79bce8SPatrick Williams             boost::urls::format("/redfish/v1/Registries/{}", memberName);
65613dabeaSEd Tanous         members.emplace_back(std::move(member));
66613dabeaSEd Tanous     }
67*fb546105SMyung Bae     asyncResp->res.jsonValue["Members@odata.count"] = members.size();
6870304cb5SJason M. Bills }
6970304cb5SJason M. Bills 
70dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistryFileCollection(App& app)
7170304cb5SJason M. Bills {
72dff07827SJohn Edward Broadbent     /**
73dff07827SJohn Edward Broadbent      * Functions triggers appropriate requests on DBus
74dff07827SJohn Edward Broadbent      */
75dff07827SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
76dff07827SJohn Edward Broadbent         .privileges(redfish::privileges::getMessageRegistryFileCollection)
7745ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(std::bind_front(
7845ca1b86SEd Tanous             handleMessageRegistryFileCollectionGet, std::ref(app)));
79dff07827SJohn Edward Broadbent }
80dff07827SJohn Edward Broadbent 
81dff07827SJohn Edward Broadbent inline void handleMessageRoutesMessageRegistryFileGet(
8245ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
83104f09c9SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
84dff07827SJohn Edward Broadbent     const std::string& registry)
85dff07827SJohn Edward Broadbent {
863ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
8745ca1b86SEd Tanous     {
8845ca1b86SEd Tanous         return;
8945ca1b86SEd Tanous     }
90fffb8c1fSEd Tanous     const registries::Header* header = nullptr;
91e51c710eSJames Feist     std::string dmtf = "DMTF ";
92e51c710eSJames Feist     const char* url = nullptr;
93e51c710eSJames Feist 
94e51c710eSJames Feist     if (registry == "Base")
95e51c710eSJames Feist     {
96fffb8c1fSEd Tanous         header = &registries::base::header;
97fffb8c1fSEd Tanous         url = registries::base::url;
98e51c710eSJames Feist     }
99e51c710eSJames Feist     else if (registry == "TaskEvent")
100e51c710eSJames Feist     {
101fffb8c1fSEd Tanous         header = &registries::task_event::header;
102fffb8c1fSEd Tanous         url = registries::task_event::url;
103e51c710eSJames Feist     }
104e51c710eSJames Feist     else if (registry == "OpenBMC")
105e51c710eSJames Feist     {
106fffb8c1fSEd Tanous         header = &registries::openbmc::header;
107e51c710eSJames Feist         dmtf.clear();
108e51c710eSJames Feist     }
10974eec26bSSunitha Harish     else if (registry == "ResourceEvent")
11074eec26bSSunitha Harish     {
111fffb8c1fSEd Tanous         header = &registries::resource_event::header;
112fffb8c1fSEd Tanous         url = registries::resource_event::url;
11374eec26bSSunitha Harish     }
11486987606SMichal Orzel     else if (registry == "Telemetry")
11586987606SMichal Orzel     {
11686987606SMichal Orzel         header = &registries::telemetry::header;
11786987606SMichal Orzel         url = registries::telemetry::url;
11886987606SMichal Orzel     }
119*fb546105SMyung Bae     else if (registry == "HeartbeatEvent")
120*fb546105SMyung Bae     {
121*fb546105SMyung Bae         header = &registries::heartbeat_event::header;
122*fb546105SMyung Bae         url = registries::heartbeat_event::url;
123*fb546105SMyung Bae     }
124e51c710eSJames Feist     else
125e51c710eSJames Feist     {
126d8a5d5d8SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
1277e860f15SJohn Edward Broadbent                                    registry);
128e51c710eSJames Feist         return;
129e51c710eSJames Feist     }
130e51c710eSJames Feist 
1311476687dSEd Tanous     asyncResp->res.jsonValue["@odata.id"] =
132ef4c65b7SEd Tanous         boost::urls::format("/redfish/v1/Registries/{}", registry);
1331476687dSEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
1341476687dSEd Tanous         "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
1351476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
136bd79bce8SPatrick Williams     asyncResp->res.jsonValue["Description"] =
137bd79bce8SPatrick Williams         dmtf + registry + " Message Registry File Location";
1381476687dSEd Tanous     asyncResp->res.jsonValue["Id"] = header->registryPrefix;
1391476687dSEd Tanous     asyncResp->res.jsonValue["Registry"] = header->id;
140613dabeaSEd Tanous     nlohmann::json::array_t languages;
1413ad903a7SAlexander Paramonov     languages.emplace_back(header->language);
142613dabeaSEd Tanous     asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
143613dabeaSEd Tanous     asyncResp->res.jsonValue["Languages"] = std::move(languages);
144613dabeaSEd Tanous     nlohmann::json::array_t locationMembers;
145613dabeaSEd Tanous     nlohmann::json::object_t location;
1463ad903a7SAlexander Paramonov     location["Language"] = header->language;
147613dabeaSEd Tanous     location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
148e51c710eSJames Feist 
149e51c710eSJames Feist     if (url != nullptr)
150e51c710eSJames Feist     {
151613dabeaSEd Tanous         location["PublicationUri"] = url;
152e51c710eSJames Feist     }
153613dabeaSEd Tanous     locationMembers.emplace_back(std::move(location));
154613dabeaSEd Tanous     asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
155613dabeaSEd Tanous     asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
15670304cb5SJason M. Bills }
15770304cb5SJason M. Bills 
158dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistryFile(App& app)
15970304cb5SJason M. Bills {
160dff07827SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
161ed398213SEd Tanous         .privileges(redfish::privileges::getMessageRegistryFile)
16245ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(std::bind_front(
16345ca1b86SEd Tanous             handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
164dff07827SJohn Edward Broadbent }
165dff07827SJohn Edward Broadbent 
166dff07827SJohn Edward Broadbent inline void handleMessageRegistryGet(
16745ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
168104f09c9SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1696e8c18f0SJohn Edward Broadbent     const std::string& registry, const std::string& registryMatch)
1707e860f15SJohn Edward Broadbent 
171e51c710eSJames Feist {
1723ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
17345ca1b86SEd Tanous     {
17445ca1b86SEd Tanous         return;
17545ca1b86SEd Tanous     }
176fffb8c1fSEd Tanous     const registries::Header* header = nullptr;
177fffb8c1fSEd Tanous     std::vector<const registries::MessageEntry*> registryEntries;
178e51c710eSJames Feist     if (registry == "Base")
179e51c710eSJames Feist     {
180fffb8c1fSEd Tanous         header = &registries::base::header;
181fffb8c1fSEd Tanous         for (const registries::MessageEntry& entry : registries::base::registry)
182e51c710eSJames Feist         {
183e51c710eSJames Feist             registryEntries.emplace_back(&entry);
184e51c710eSJames Feist         }
185e51c710eSJames Feist     }
186e51c710eSJames Feist     else if (registry == "TaskEvent")
187e51c710eSJames Feist     {
188fffb8c1fSEd Tanous         header = &registries::task_event::header;
189fffb8c1fSEd Tanous         for (const registries::MessageEntry& entry :
190fffb8c1fSEd Tanous              registries::task_event::registry)
191e51c710eSJames Feist         {
192e51c710eSJames Feist             registryEntries.emplace_back(&entry);
193e51c710eSJames Feist         }
194e51c710eSJames Feist     }
195e51c710eSJames Feist     else if (registry == "OpenBMC")
196e51c710eSJames Feist     {
197fffb8c1fSEd Tanous         header = &registries::openbmc::header;
198fffb8c1fSEd Tanous         for (const registries::MessageEntry& entry :
199fffb8c1fSEd Tanous              registries::openbmc::registry)
200e51c710eSJames Feist         {
201e51c710eSJames Feist             registryEntries.emplace_back(&entry);
202e51c710eSJames Feist         }
203e51c710eSJames Feist     }
20474eec26bSSunitha Harish     else if (registry == "ResourceEvent")
20574eec26bSSunitha Harish     {
206fffb8c1fSEd Tanous         header = &registries::resource_event::header;
207fffb8c1fSEd Tanous         for (const registries::MessageEntry& entry :
208fffb8c1fSEd Tanous              registries::resource_event::registry)
20974eec26bSSunitha Harish         {
21074eec26bSSunitha Harish             registryEntries.emplace_back(&entry);
21174eec26bSSunitha Harish         }
21274eec26bSSunitha Harish     }
21386987606SMichal Orzel     else if (registry == "Telemetry")
21486987606SMichal Orzel     {
21586987606SMichal Orzel         header = &registries::telemetry::header;
21686987606SMichal Orzel         for (const registries::MessageEntry& entry :
21786987606SMichal Orzel              registries::telemetry::registry)
21886987606SMichal Orzel         {
21986987606SMichal Orzel             registryEntries.emplace_back(&entry);
22086987606SMichal Orzel         }
22186987606SMichal Orzel     }
222*fb546105SMyung Bae     else if (registry == "HeartbeatEvent")
223*fb546105SMyung Bae     {
224*fb546105SMyung Bae         header = &registries::heartbeat_event::header;
225*fb546105SMyung Bae         for (const registries::MessageEntry& entry :
226*fb546105SMyung Bae              registries::heartbeat_event::registry)
227*fb546105SMyung Bae         {
228*fb546105SMyung Bae             registryEntries.emplace_back(&entry);
229*fb546105SMyung Bae         }
230*fb546105SMyung Bae     }
231e51c710eSJames Feist     else
232e51c710eSJames Feist     {
233d8a5d5d8SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
2347e860f15SJohn Edward Broadbent                                    registry);
235e51c710eSJames Feist         return;
236e51c710eSJames Feist     }
237e51c710eSJames Feist 
2386e8c18f0SJohn Edward Broadbent     if (registry != registryMatch)
239e51c710eSJames Feist     {
2406e8c18f0SJohn Edward Broadbent         messages::resourceNotFound(asyncResp->res, header->type, registryMatch);
241e51c710eSJames Feist         return;
242e51c710eSJames Feist     }
243e51c710eSJames Feist 
2441476687dSEd Tanous     asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright;
2451476687dSEd Tanous     asyncResp->res.jsonValue["@odata.type"] = header->type;
2461476687dSEd Tanous     asyncResp->res.jsonValue["Id"] = header->id;
2471476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = header->name;
2481476687dSEd Tanous     asyncResp->res.jsonValue["Language"] = header->language;
2491476687dSEd Tanous     asyncResp->res.jsonValue["Description"] = header->description;
2501476687dSEd Tanous     asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix;
2511476687dSEd Tanous     asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion;
2521476687dSEd Tanous     asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity;
25370304cb5SJason M. Bills 
254dff07827SJohn Edward Broadbent     nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
25570304cb5SJason M. Bills 
25670304cb5SJason M. Bills     // Go through the Message Registry and populate each Message
257fffb8c1fSEd Tanous     for (const registries::MessageEntry* message : registryEntries)
25870304cb5SJason M. Bills     {
259e51c710eSJames Feist         nlohmann::json& obj = messageObj[message->first];
2601476687dSEd Tanous         obj["Description"] = message->second.description;
2611476687dSEd Tanous         obj["Message"] = message->second.message;
2621476687dSEd Tanous         obj["Severity"] = message->second.messageSeverity;
2631476687dSEd Tanous         obj["MessageSeverity"] = message->second.messageSeverity;
2641476687dSEd Tanous         obj["NumberOfArgs"] = message->second.numberOfArgs;
2651476687dSEd Tanous         obj["Resolution"] = message->second.resolution;
266e51c710eSJames Feist         if (message->second.numberOfArgs > 0)
26770304cb5SJason M. Bills         {
26814c8aee2SEd Tanous             nlohmann::json& messageParamArray = obj["ParamTypes"];
269938f2568SEd Tanous             messageParamArray = nlohmann::json::array();
270e51c710eSJames Feist             for (const char* str : message->second.paramTypes)
27170304cb5SJason M. Bills             {
27270304cb5SJason M. Bills                 if (str == nullptr)
27370304cb5SJason M. Bills                 {
27470304cb5SJason M. Bills                     break;
27570304cb5SJason M. Bills                 }
27670304cb5SJason M. Bills                 messageParamArray.push_back(str);
27770304cb5SJason M. Bills             }
27870304cb5SJason M. Bills         }
27970304cb5SJason M. Bills     }
28070304cb5SJason M. Bills }
28170304cb5SJason M. Bills 
282dff07827SJohn Edward Broadbent inline void requestRoutesMessageRegistry(App& app)
283dff07827SJohn Edward Broadbent {
284dff07827SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
285dff07827SJohn Edward Broadbent         .privileges(redfish::privileges::getMessageRegistryFile)
28645ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
28745ca1b86SEd Tanous             std::bind_front(handleMessageRegistryGet, std::ref(app)));
288dff07827SJohn Edward Broadbent }
28970304cb5SJason M. Bills } // namespace redfish
290