blob: 26ddc0adf063a08acda7e728ab6d594d8aba8416 [file] [log] [blame]
Ed Tanous1da66f72018-07-27 16:13:37 -07001/*
2// Copyright (c) 2018 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"
George Liu7a1dbc42022-12-07 16:03:22 +080019#include "dbus_utility.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080020#include "error_messages.hpp"
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -060021#include "generated/enums/log_entry.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070022#include "generated/enums/log_service.hpp"
Spencer Kub7028eb2021-10-26 15:27:35 +080023#include "gzfile.hpp"
George Liu647b3cd2021-07-05 12:43:56 +080024#include "http_utility.hpp"
Spencer Kub7028eb2021-10-26 15:27:35 +080025#include "human_sort.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080026#include "query.hpp"
Jason M. Bills4851d452019-03-28 11:27:48 -070027#include "registries.hpp"
28#include "registries/base_message_registry.hpp"
29#include "registries/openbmc_message_registry.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080030#include "registries/privilege_registry.hpp"
James Feist46229572020-02-19 15:11:58 -080031#include "task.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070032#include "task_messages.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080033#include "utils/dbus_utils.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070034#include "utils/json_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080035#include "utils/time_utils.hpp"
Ed Tanous1da66f72018-07-27 16:13:37 -070036
Myung Bae75e8e212023-11-30 12:53:46 -080037#include <systemd/sd-id128.h>
Asmitha Karunanithi8e317782020-12-10 03:35:05 -060038#include <tinyxml2.h>
Adriana Kobylak400fd1f2021-01-29 09:01:30 -060039#include <unistd.h>
Jason M. Billse1f26342018-07-18 12:12:00 -070040
Ed Tanous07c8c202022-07-11 10:08:08 -070041#include <boost/beast/http/verb.hpp>
Ed Tanous1da66f72018-07-27 16:13:37 -070042#include <boost/container/flat_map.hpp>
Jason M. Bills1ddcf012019-11-26 14:59:21 -080043#include <boost/system/linux_error.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070044#include <boost/url/format.hpp>
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +020045#include <sdbusplus/asio/property.hpp>
46#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050047
George Liu7a1dbc42022-12-07 16:03:22 +080048#include <array>
George Liu647b3cd2021-07-05 12:43:56 +080049#include <charconv>
Abhilash Rajub5f288d2023-11-08 22:32:44 -060050#include <cstddef>
James Feist4418c7f2019-04-15 11:09:15 -070051#include <filesystem>
Ed Tanous18f8f602023-07-18 10:07:23 -070052#include <iterator>
Xiaochao Ma75710de2021-01-21 17:56:02 +080053#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070054#include <ranges>
Ed Tanous26702d02021-11-03 15:02:33 -070055#include <span>
Ed Tanous18f8f602023-07-18 10:07:23 -070056#include <string>
Jason M. Billscd225da2019-05-08 15:31:57 -070057#include <string_view>
Ed Tanousabf2add2019-01-22 16:40:12 -080058#include <variant>
Ed Tanous1da66f72018-07-27 16:13:37 -070059
60namespace redfish
61{
62
Patrick Williams89492a12023-05-10 07:51:34 -050063constexpr const char* crashdumpObject = "com.intel.crashdump";
64constexpr const char* crashdumpPath = "/com/intel/crashdump";
65constexpr const char* crashdumpInterface = "com.intel.crashdump";
66constexpr const char* deleteAllInterface =
Jason M. Bills5b61b5e2019-10-16 10:59:02 -070067 "xyz.openbmc_project.Collection.DeleteAll";
Patrick Williams89492a12023-05-10 07:51:34 -050068constexpr const char* crashdumpOnDemandInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070069 "com.intel.crashdump.OnDemand";
Patrick Williams89492a12023-05-10 07:51:34 -050070constexpr const char* crashdumpTelemetryInterface =
Kenny L. Ku6eda7682020-06-19 09:48:36 -070071 "com.intel.crashdump.Telemetry";
Ed Tanous1da66f72018-07-27 16:13:37 -070072
Asmitha Karunanithi8e317782020-12-10 03:35:05 -060073enum class DumpCreationProgress
74{
75 DUMP_CREATE_SUCCESS,
76 DUMP_CREATE_FAILED,
77 DUMP_CREATE_INPROGRESS
78};
79
James Feistf6150402019-01-08 10:36:20 -080080namespace fs = std::filesystem;
Ed Tanous1da66f72018-07-27 16:13:37 -070081
Gunnar Mills1214b7e2020-06-04 10:11:30 -050082inline std::string translateSeverityDbusToRedfish(const std::string& s)
Andrew Geisslercb92c032018-08-17 07:56:14 -070083{
Ed Tanousd4d25792020-09-29 15:15:03 -070084 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
85 (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
86 (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
87 (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
Andrew Geisslercb92c032018-08-17 07:56:14 -070088 {
89 return "Critical";
90 }
Ed Tanous3174e4d2020-10-07 11:41:22 -070091 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
92 (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
93 (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
Andrew Geisslercb92c032018-08-17 07:56:14 -070094 {
95 return "OK";
96 }
Ed Tanous3174e4d2020-10-07 11:41:22 -070097 if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
Andrew Geisslercb92c032018-08-17 07:56:14 -070098 {
99 return "Warning";
100 }
101 return "";
102}
103
Abhishek Patel9017faf2021-09-14 22:48:55 -0500104inline std::optional<bool> getProviderNotifyAction(const std::string& notify)
105{
106 std::optional<bool> notifyAction;
107 if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify")
108 {
109 notifyAction = true;
110 }
111 else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit")
112 {
113 notifyAction = false;
114 }
115
116 return notifyAction;
117}
118
Ed Tanous18f8f602023-07-18 10:07:23 -0700119inline std::string getDumpPath(std::string_view dumpType)
120{
121 std::string dbusDumpPath = "/xyz/openbmc_project/dump/";
122 std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath),
123 bmcweb::asciiToLower);
124
125 return dbusDumpPath;
126}
127
Ed Tanous055713e2024-07-17 17:19:36 -0700128inline bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700129 const bool firstEntry = true)
Jason M. Bills95820182019-04-22 16:25:34 -0700130{
Ed Tanous271584a2019-07-09 16:24:22 -0700131 static time_t prevTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700132 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700133 if (firstEntry)
134 {
135 prevTs = 0;
136 }
137
Jason M. Bills95820182019-04-22 16:25:34 -0700138 // Get the entry timestamp
Ed Tanous271584a2019-07-09 16:24:22 -0700139 std::time_t curTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700140 std::tm timeStruct = {};
141 std::istringstream entryStream(logEntry);
142 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
143 {
144 curTs = std::mktime(&timeStruct);
145 }
146 // If the timestamp isn't unique, increment the index
147 if (curTs == prevTs)
148 {
149 index++;
150 }
151 else
152 {
153 // Otherwise, reset it
154 index = 0;
155 }
156 // Save the timestamp
157 prevTs = curTs;
158
159 entryID = std::to_string(curTs);
160 if (index > 0)
161 {
162 entryID += "_" + std::to_string(index);
163 }
164 return true;
165}
166
Jason M. Bills95820182019-04-22 16:25:34 -0700167static bool
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500168 getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
Jason M. Bills95820182019-04-22 16:25:34 -0700169{
170 static const std::filesystem::path redfishLogDir = "/var/log";
171 static const std::string redfishLogFilename = "redfish";
172
173 // Loop through the directory looking for redfish log files
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500174 for (const std::filesystem::directory_entry& dirEnt :
Jason M. Bills95820182019-04-22 16:25:34 -0700175 std::filesystem::directory_iterator(redfishLogDir))
176 {
177 // If we find a redfish log file, save the path
178 std::string filename = dirEnt.path().filename();
Ed Tanous11ba3972022-07-11 09:50:41 -0700179 if (filename.starts_with(redfishLogFilename))
Jason M. Bills95820182019-04-22 16:25:34 -0700180 {
181 redfishLogFiles.emplace_back(redfishLogDir / filename);
182 }
183 }
184 // As the log files rotate, they are appended with a ".#" that is higher for
185 // the older logs. Since we don't expect more than 10 log files, we
186 // can just sort the list to get them in order from newest to oldest
Ed Tanous3544d2a2023-08-06 18:12:20 -0700187 std::ranges::sort(redfishLogFiles);
Jason M. Bills95820182019-04-22 16:25:34 -0700188
189 return !redfishLogFiles.empty();
190}
191
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600192inline log_entry::OriginatorTypes
193 mapDbusOriginatorTypeToRedfish(const std::string& originatorType)
194{
195 if (originatorType ==
196 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client")
197 {
198 return log_entry::OriginatorTypes::Client;
199 }
200 if (originatorType ==
201 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal")
202 {
203 return log_entry::OriginatorTypes::Internal;
204 }
205 if (originatorType ==
206 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService")
207 {
208 return log_entry::OriginatorTypes::SupportingService;
209 }
210 return log_entry::OriginatorTypes::Invalid;
211}
212
Claire Weinanaefe3782022-07-15 19:17:19 -0700213inline void parseDumpEntryFromDbusObject(
Jiaqing Zhao2d613eb2022-08-15 16:03:00 +0800214 const dbus::utility::ManagedObjectType::value_type& object,
Claire Weinanc6fecda2022-07-15 10:43:25 -0700215 std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs,
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600216 std::string& originatorId, log_entry::OriginatorTypes& originatorType,
Claire Weinanaefe3782022-07-15 19:17:19 -0700217 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
218{
219 for (const auto& interfaceMap : object.second)
220 {
221 if (interfaceMap.first == "xyz.openbmc_project.Common.Progress")
222 {
223 for (const auto& propertyMap : interfaceMap.second)
224 {
225 if (propertyMap.first == "Status")
226 {
227 const auto* status =
228 std::get_if<std::string>(&propertyMap.second);
229 if (status == nullptr)
230 {
231 messages::internalError(asyncResp->res);
232 break;
233 }
234 dumpStatus = *status;
235 }
236 }
237 }
238 else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
239 {
240 for (const auto& propertyMap : interfaceMap.second)
241 {
242 if (propertyMap.first == "Size")
243 {
244 const auto* sizePtr =
245 std::get_if<uint64_t>(&propertyMap.second);
246 if (sizePtr == nullptr)
247 {
248 messages::internalError(asyncResp->res);
249 break;
250 }
251 size = *sizePtr;
252 break;
253 }
254 }
255 }
256 else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime")
257 {
258 for (const auto& propertyMap : interfaceMap.second)
259 {
260 if (propertyMap.first == "Elapsed")
261 {
262 const uint64_t* usecsTimeStamp =
263 std::get_if<uint64_t>(&propertyMap.second);
264 if (usecsTimeStamp == nullptr)
265 {
266 messages::internalError(asyncResp->res);
267 break;
268 }
Claire Weinanc6fecda2022-07-15 10:43:25 -0700269 timestampUs = *usecsTimeStamp;
Claire Weinanaefe3782022-07-15 19:17:19 -0700270 break;
271 }
272 }
273 }
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600274 else if (interfaceMap.first ==
275 "xyz.openbmc_project.Common.OriginatedBy")
276 {
277 for (const auto& propertyMap : interfaceMap.second)
278 {
279 if (propertyMap.first == "OriginatorId")
280 {
281 const std::string* id =
282 std::get_if<std::string>(&propertyMap.second);
283 if (id == nullptr)
284 {
285 messages::internalError(asyncResp->res);
286 break;
287 }
288 originatorId = *id;
289 }
290
291 if (propertyMap.first == "OriginatorType")
292 {
293 const std::string* type =
294 std::get_if<std::string>(&propertyMap.second);
295 if (type == nullptr)
296 {
297 messages::internalError(asyncResp->res);
298 break;
299 }
300
301 originatorType = mapDbusOriginatorTypeToRedfish(*type);
302 if (originatorType == log_entry::OriginatorTypes::Invalid)
303 {
304 messages::internalError(asyncResp->res);
305 break;
306 }
307 }
308 }
309 }
Claire Weinanaefe3782022-07-15 19:17:19 -0700310 }
311}
312
Nan Zhou21ab4042022-06-26 23:07:40 +0000313static std::string getDumpEntriesPath(const std::string& dumpType)
Claire Weinanfdd26902022-03-01 14:18:25 -0800314{
315 std::string entriesPath;
316
317 if (dumpType == "BMC")
318 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700319 entriesPath =
320 std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
321 BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800322 }
323 else if (dumpType == "FaultLog")
324 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700325 entriesPath =
326 std::format("/redfish/v1/Managers/{}/LogServices/FaultLog/Entries/",
327 BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800328 }
329 else if (dumpType == "System")
330 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700331 entriesPath =
332 std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
333 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800334 }
335 else
336 {
Ed Tanous62598e32023-07-17 17:06:25 -0700337 BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}",
338 dumpType);
Claire Weinanfdd26902022-03-01 14:18:25 -0800339 }
340
341 // Returns empty string on error
342 return entriesPath;
343}
344
zhanghch058d1b46d2021-04-01 11:18:24 +0800345inline void
346 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
347 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500348{
Claire Weinanfdd26902022-03-01 14:18:25 -0800349 std::string entriesPath = getDumpEntriesPath(dumpType);
350 if (entriesPath.empty())
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500351 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500352 messages::internalError(asyncResp->res);
353 return;
354 }
355
George Liu5eb468d2023-06-20 17:03:24 +0800356 sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
357 dbus::utility::getManagedObjects(
358 "xyz.openbmc_project.Dump.Manager", path,
Claire Weinanfdd26902022-03-01 14:18:25 -0800359 [asyncResp, entriesPath,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800360 dumpType](const boost::system::error_code& ec,
George Liu5eb468d2023-06-20 17:03:24 +0800361 const dbus::utility::ManagedObjectType& objects) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700362 if (ec)
363 {
Ed Tanous62598e32023-07-17 17:06:25 -0700364 BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700365 messages::internalError(asyncResp->res);
366 return;
367 }
368
Claire Weinanfdd26902022-03-01 14:18:25 -0800369 // Remove ending slash
370 std::string odataIdStr = entriesPath;
371 if (!odataIdStr.empty())
372 {
373 odataIdStr.pop_back();
374 }
375
376 asyncResp->res.jsonValue["@odata.type"] =
377 "#LogEntryCollection.LogEntryCollection";
378 asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr);
379 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries";
Patrick Williams89492a12023-05-10 07:51:34 -0500380 asyncResp->res.jsonValue["Description"] = "Collection of " + dumpType +
381 " Dump Entries";
Claire Weinanfdd26902022-03-01 14:18:25 -0800382
Ed Tanous3544d2a2023-08-06 18:12:20 -0700383 nlohmann::json::array_t entriesArray;
Ed Tanous18f8f602023-07-18 10:07:23 -0700384 std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
Ed Tanous002d39b2022-05-31 08:59:27 -0700385
George Liu5eb468d2023-06-20 17:03:24 +0800386 dbus::utility::ManagedObjectType resp(objects);
Ed Tanous3544d2a2023-08-06 18:12:20 -0700387 std::ranges::sort(resp, [](const auto& l, const auto& r) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700388 return AlphanumLess<std::string>()(l.first.filename(),
389 r.first.filename());
390 });
391
392 for (auto& object : resp)
393 {
394 if (object.first.str.find(dumpEntryPath) == std::string::npos)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500395 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700396 continue;
397 }
Claire Weinanc6fecda2022-07-15 10:43:25 -0700398 uint64_t timestampUs = 0;
Ed Tanous002d39b2022-05-31 08:59:27 -0700399 uint64_t size = 0;
400 std::string dumpStatus;
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600401 std::string originatorId;
402 log_entry::OriginatorTypes originatorType =
403 log_entry::OriginatorTypes::Internal;
Jason M. Bills433b68b2022-06-28 12:24:26 -0700404 nlohmann::json::object_t thisEntry;
Ed Tanous002d39b2022-05-31 08:59:27 -0700405
406 std::string entryID = object.first.filename();
407 if (entryID.empty())
408 {
409 continue;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500410 }
411
Claire Weinanc6fecda2022-07-15 10:43:25 -0700412 parseDumpEntryFromDbusObject(object, dumpStatus, size, timestampUs,
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600413 originatorId, originatorType,
Claire Weinanaefe3782022-07-15 19:17:19 -0700414 asyncResp);
Ed Tanous002d39b2022-05-31 08:59:27 -0700415
416 if (dumpStatus !=
417 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
418 !dumpStatus.empty())
419 {
420 // Dump status is not Complete, no need to enumerate
421 continue;
422 }
423
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600424 thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry";
Claire Weinanfdd26902022-03-01 14:18:25 -0800425 thisEntry["@odata.id"] = entriesPath + entryID;
Ed Tanous002d39b2022-05-31 08:59:27 -0700426 thisEntry["Id"] = entryID;
427 thisEntry["EntryType"] = "Event";
Ed Tanous002d39b2022-05-31 08:59:27 -0700428 thisEntry["Name"] = dumpType + " Dump Entry";
Claire Weinanbbd80db2022-10-26 16:55:52 -0700429 thisEntry["Created"] =
430 redfish::time_utils::getDateTimeUintUs(timestampUs);
Ed Tanous002d39b2022-05-31 08:59:27 -0700431
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600432 if (!originatorId.empty())
433 {
434 thisEntry["Originator"] = originatorId;
435 thisEntry["OriginatorType"] = originatorType;
436 }
437
Ed Tanous002d39b2022-05-31 08:59:27 -0700438 if (dumpType == "BMC")
439 {
440 thisEntry["DiagnosticDataType"] = "Manager";
Patrick Williams89492a12023-05-10 07:51:34 -0500441 thisEntry["AdditionalDataURI"] = entriesPath + entryID +
442 "/attachment";
Claire Weinanfdd26902022-03-01 14:18:25 -0800443 thisEntry["AdditionalDataSizeBytes"] = size;
Ed Tanous002d39b2022-05-31 08:59:27 -0700444 }
445 else if (dumpType == "System")
446 {
447 thisEntry["DiagnosticDataType"] = "OEM";
448 thisEntry["OEMDiagnosticDataType"] = "System";
Patrick Williams89492a12023-05-10 07:51:34 -0500449 thisEntry["AdditionalDataURI"] = entriesPath + entryID +
450 "/attachment";
Claire Weinanfdd26902022-03-01 14:18:25 -0800451 thisEntry["AdditionalDataSizeBytes"] = size;
Ed Tanous002d39b2022-05-31 08:59:27 -0700452 }
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500453 entriesArray.emplace_back(std::move(thisEntry));
Ed Tanous002d39b2022-05-31 08:59:27 -0700454 }
455 asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
Ed Tanous3544d2a2023-08-06 18:12:20 -0700456 asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
Patrick Williams5a39f772023-10-20 11:20:21 -0500457 });
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500458}
459
zhanghch058d1b46d2021-04-01 11:18:24 +0800460inline void
Claire Weinanc7a6d662022-06-13 16:36:39 -0700461 getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
zhanghch058d1b46d2021-04-01 11:18:24 +0800462 const std::string& entryID, const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500463{
Claire Weinanfdd26902022-03-01 14:18:25 -0800464 std::string entriesPath = getDumpEntriesPath(dumpType);
465 if (entriesPath.empty())
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500466 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500467 messages::internalError(asyncResp->res);
468 return;
469 }
470
George Liu5eb468d2023-06-20 17:03:24 +0800471 sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
472 dbus::utility::getManagedObjects(
473 "xyz.openbmc_project.Dump.Manager", path,
Claire Weinanfdd26902022-03-01 14:18:25 -0800474 [asyncResp, entryID, dumpType,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800475 entriesPath](const boost::system::error_code& ec,
Ed Tanous02cad962022-06-30 16:50:15 -0700476 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700477 if (ec)
478 {
Ed Tanous62598e32023-07-17 17:06:25 -0700479 BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700480 messages::internalError(asyncResp->res);
481 return;
482 }
483
484 bool foundDumpEntry = false;
Ed Tanous18f8f602023-07-18 10:07:23 -0700485 std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
Ed Tanous002d39b2022-05-31 08:59:27 -0700486
487 for (const auto& objectPath : resp)
488 {
489 if (objectPath.first.str != dumpEntryPath + entryID)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500490 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700491 continue;
492 }
493
494 foundDumpEntry = true;
Claire Weinanc6fecda2022-07-15 10:43:25 -0700495 uint64_t timestampUs = 0;
Ed Tanous002d39b2022-05-31 08:59:27 -0700496 uint64_t size = 0;
497 std::string dumpStatus;
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600498 std::string originatorId;
499 log_entry::OriginatorTypes originatorType =
500 log_entry::OriginatorTypes::Internal;
Ed Tanous002d39b2022-05-31 08:59:27 -0700501
Claire Weinanaefe3782022-07-15 19:17:19 -0700502 parseDumpEntryFromDbusObject(objectPath, dumpStatus, size,
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600503 timestampUs, originatorId,
504 originatorType, asyncResp);
Ed Tanous002d39b2022-05-31 08:59:27 -0700505
506 if (dumpStatus !=
507 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
508 !dumpStatus.empty())
509 {
510 // Dump status is not Complete
511 // return not found until status is changed to Completed
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200512 messages::resourceNotFound(asyncResp->res, dumpType + " dump",
513 entryID);
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500514 return;
515 }
516
Ed Tanous002d39b2022-05-31 08:59:27 -0700517 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600518 "#LogEntry.v1_11_0.LogEntry";
Claire Weinanfdd26902022-03-01 14:18:25 -0800519 asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID;
Ed Tanous002d39b2022-05-31 08:59:27 -0700520 asyncResp->res.jsonValue["Id"] = entryID;
521 asyncResp->res.jsonValue["EntryType"] = "Event";
Ed Tanous002d39b2022-05-31 08:59:27 -0700522 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
Claire Weinanbbd80db2022-10-26 16:55:52 -0700523 asyncResp->res.jsonValue["Created"] =
524 redfish::time_utils::getDateTimeUintUs(timestampUs);
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500525
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600526 if (!originatorId.empty())
527 {
528 asyncResp->res.jsonValue["Originator"] = originatorId;
529 asyncResp->res.jsonValue["OriginatorType"] = originatorType;
530 }
531
Ed Tanous002d39b2022-05-31 08:59:27 -0700532 if (dumpType == "BMC")
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500533 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700534 asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
535 asyncResp->res.jsonValue["AdditionalDataURI"] =
Claire Weinanfdd26902022-03-01 14:18:25 -0800536 entriesPath + entryID + "/attachment";
537 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500538 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700539 else if (dumpType == "System")
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500540 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700541 asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
542 asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System";
543 asyncResp->res.jsonValue["AdditionalDataURI"] =
Claire Weinanfdd26902022-03-01 14:18:25 -0800544 entriesPath + entryID + "/attachment";
545 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500546 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700547 }
548 if (!foundDumpEntry)
549 {
Ed Tanous62598e32023-07-17 17:06:25 -0700550 BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
Myung Baeb90d14f2023-05-31 14:40:39 -0500551 messages::resourceNotFound(asyncResp->res, dumpType + " dump",
552 entryID);
Ed Tanous002d39b2022-05-31 08:59:27 -0700553 return;
554 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500555 });
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500556}
557
zhanghch058d1b46d2021-04-01 11:18:24 +0800558inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Stanley Chu98782562020-11-04 16:10:24 +0800559 const std::string& entryID,
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500560 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500561{
Patrick Williams5a39f772023-10-20 11:20:21 -0500562 auto respHandler = [asyncResp,
563 entryID](const boost::system::error_code& ec) {
Ed Tanous62598e32023-07-17 17:06:25 -0700564 BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done");
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500565 if (ec)
566 {
George Liu3de8d8b2021-03-22 17:49:39 +0800567 if (ec.value() == EBADR)
568 {
569 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
570 return;
571 }
Ed Tanous62598e32023-07-17 17:06:25 -0700572 BMCWEB_LOG_ERROR(
573 "Dump (DBus) doDelete respHandler got error {} entryID={}", ec,
574 entryID);
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500575 messages::internalError(asyncResp->res);
576 return;
577 }
578 };
Ed Tanous18f8f602023-07-18 10:07:23 -0700579
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500580 crow::connections::systemBus->async_method_call(
581 respHandler, "xyz.openbmc_project.Dump.Manager",
Ed Tanous18f8f602023-07-18 10:07:23 -0700582 std::format("{}/entry/{}", getDumpPath(dumpType), entryID),
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500583 "xyz.openbmc_project.Object.Delete", "Delete");
584}
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600585inline bool checkSizeLimit(int fd, crow::Response& res)
586{
587 long long int size = lseek(fd, 0, SEEK_END);
588 if (size <= 0)
589 {
590 BMCWEB_LOG_ERROR("Failed to get size of file, lseek() returned {}",
591 size);
592 messages::internalError(res);
593 return false;
594 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500595
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600596 // Arbitrary max size of 20MB to accommodate BMC dumps
597 constexpr long long int maxFileSize = 20LL * 1024LL * 1024LL;
598 if (size > maxFileSize)
599 {
600 BMCWEB_LOG_ERROR("File size {} exceeds maximum allowed size of {}",
601 size, maxFileSize);
602 messages::internalError(res);
603 return false;
604 }
605 off_t rc = lseek(fd, 0, SEEK_SET);
606 if (rc < 0)
607 {
608 BMCWEB_LOG_ERROR("Failed to reset file offset to 0");
609 messages::internalError(res);
610 return false;
611 }
612 return true;
613}
Carson Labrado168d1b12023-03-27 17:04:46 +0000614inline void
615 downloadEntryCallback(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
616 const std::string& entryID,
617 const std::string& downloadEntryType,
618 const boost::system::error_code& ec,
619 const sdbusplus::message::unix_fd& unixfd)
620{
621 if (ec.value() == EBADR)
622 {
623 messages::resourceNotFound(asyncResp->res, "EntryAttachment", entryID);
624 return;
625 }
626 if (ec)
627 {
628 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
629 messages::internalError(asyncResp->res);
630 return;
631 }
632
633 // Make sure we know how to process the retrieved entry attachment
634 if ((downloadEntryType != "BMC") && (downloadEntryType != "System"))
635 {
636 BMCWEB_LOG_ERROR("downloadEntryCallback() invalid entry type: {}",
637 downloadEntryType);
638 messages::internalError(asyncResp->res);
639 }
640
641 int fd = -1;
642 fd = dup(unixfd);
643 if (fd < 0)
644 {
645 BMCWEB_LOG_ERROR("Failed to open file");
646 messages::internalError(asyncResp->res);
647 return;
648 }
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600649 if (!checkSizeLimit(fd, asyncResp->res))
Carson Labrado168d1b12023-03-27 17:04:46 +0000650 {
Carson Labrado168d1b12023-03-27 17:04:46 +0000651 close(fd);
652 return;
653 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000654 if (downloadEntryType == "System")
655 {
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600656 if (!asyncResp->res.openFd(fd, bmcweb::EncodingType::Base64))
657 {
658 messages::internalError(asyncResp->res);
659 close(fd);
660 return;
661 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000662 asyncResp->res.addHeader(
663 boost::beast::http::field::content_transfer_encoding, "Base64");
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600664 return;
Carson Labrado168d1b12023-03-27 17:04:46 +0000665 }
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600666 if (!asyncResp->res.openFd(fd))
Ed Tanous27b0cf92023-08-07 12:02:40 -0700667 {
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600668 messages::internalError(asyncResp->res);
669 close(fd);
670 return;
Ed Tanous27b0cf92023-08-07 12:02:40 -0700671 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000672 asyncResp->res.addHeader(boost::beast::http::field::content_type,
673 "application/octet-stream");
674}
675
676inline void
677 downloadDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
678 const std::string& entryID, const std::string& dumpType)
679{
680 if (dumpType != "BMC")
681 {
682 BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
683 messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID);
684 return;
685 }
686
Ed Tanous18f8f602023-07-18 10:07:23 -0700687 std::string dumpEntryPath = std::format("{}/entry/{}",
688 getDumpPath(dumpType), entryID);
Carson Labrado168d1b12023-03-27 17:04:46 +0000689
690 auto downloadDumpEntryHandler =
691 [asyncResp, entryID,
692 dumpType](const boost::system::error_code& ec,
693 const sdbusplus::message::unix_fd& unixfd) {
694 downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
695 };
696
697 crow::connections::systemBus->async_method_call(
698 std::move(downloadDumpEntryHandler), "xyz.openbmc_project.Dump.Manager",
699 dumpEntryPath, "xyz.openbmc_project.Dump.Entry", "GetFileHandle");
700}
701
702inline void
703 downloadEventLogEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
704 const std::string& systemName,
705 const std::string& entryID,
706 const std::string& dumpType)
707{
Ed Tanous25b54db2024-04-17 15:40:31 -0700708 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Carson Labrado168d1b12023-03-27 17:04:46 +0000709 {
710 // Option currently returns no systems. TBD
711 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
712 systemName);
713 return;
714 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700715 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Carson Labrado168d1b12023-03-27 17:04:46 +0000716 {
717 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
718 systemName);
719 return;
720 }
721
722 std::string entryPath =
723 sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") /
724 entryID;
725
726 auto downloadEventLogEntryHandler =
727 [asyncResp, entryID,
728 dumpType](const boost::system::error_code& ec,
729 const sdbusplus::message::unix_fd& unixfd) {
730 downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
731 };
732
733 crow::connections::systemBus->async_method_call(
734 std::move(downloadEventLogEntryHandler), "xyz.openbmc_project.Logging",
735 entryPath, "xyz.openbmc_project.Logging.Entry", "GetEntry");
736}
737
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600738inline DumpCreationProgress
739 mapDbusStatusToDumpProgress(const std::string& status)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500740{
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600741 if (status ==
742 "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" ||
743 status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted")
744 {
745 return DumpCreationProgress::DUMP_CREATE_FAILED;
746 }
747 if (status ==
748 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed")
749 {
750 return DumpCreationProgress::DUMP_CREATE_SUCCESS;
751 }
752 return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
753}
754
755inline DumpCreationProgress
756 getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values)
757{
758 for (const auto& [key, val] : values)
759 {
760 if (key == "Status")
Ed Tanous002d39b2022-05-31 08:59:27 -0700761 {
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600762 const std::string* value = std::get_if<std::string>(&val);
763 if (value == nullptr)
764 {
Ed Tanous62598e32023-07-17 17:06:25 -0700765 BMCWEB_LOG_ERROR("Status property value is null");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600766 return DumpCreationProgress::DUMP_CREATE_FAILED;
767 }
768 return mapDbusStatusToDumpProgress(*value);
769 }
770 }
771 return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
772}
773
774inline std::string getDumpEntryPath(const std::string& dumpPath)
775{
776 if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry")
777 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700778 return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
Ed Tanous9f565092024-07-12 22:06:53 -0700779 BMCWEB_REDFISH_MANAGER_URI_NAME);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600780 }
781 if (dumpPath == "/xyz/openbmc_project/dump/system/entry")
782 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700783 return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
784 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600785 }
786 return "";
787}
788
789inline void createDumpTaskCallback(
790 task::Payload&& payload,
791 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
792 const sdbusplus::message::object_path& createdObjPath)
793{
794 const std::string dumpPath = createdObjPath.parent_path().str;
795 const std::string dumpId = createdObjPath.filename();
796
797 std::string dumpEntryPath = getDumpEntryPath(dumpPath);
798
799 if (dumpEntryPath.empty())
800 {
Ed Tanous62598e32023-07-17 17:06:25 -0700801 BMCWEB_LOG_ERROR("Invalid dump type received");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600802 messages::internalError(asyncResp->res);
803 return;
804 }
805
806 crow::connections::systemBus->async_method_call(
Ed Tanous8cb2c022024-03-27 16:31:46 -0700807 [asyncResp, payload = std::move(payload), createdObjPath,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600808 dumpEntryPath{std::move(dumpEntryPath)},
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800809 dumpId](const boost::system::error_code& ec,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600810 const std::string& introspectXml) {
811 if (ec)
812 {
Ed Tanous62598e32023-07-17 17:06:25 -0700813 BMCWEB_LOG_ERROR("Introspect call failed with error: {}",
814 ec.message());
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600815 messages::internalError(asyncResp->res);
816 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700817 }
818
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600819 // Check if the created dump object has implemented Progress
820 // interface to track dump completion. If yes, fetch the "Status"
821 // property of the interface, modify the task state accordingly.
822 // Else, return task completed.
823 tinyxml2::XMLDocument doc;
Ed Tanous002d39b2022-05-31 08:59:27 -0700824
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600825 doc.Parse(introspectXml.data(), introspectXml.size());
826 tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
827 if (pRoot == nullptr)
Ed Tanous002d39b2022-05-31 08:59:27 -0700828 {
Ed Tanous62598e32023-07-17 17:06:25 -0700829 BMCWEB_LOG_ERROR("XML document failed to parse");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600830 messages::internalError(asyncResp->res);
831 return;
832 }
833 tinyxml2::XMLElement* interfaceNode =
834 pRoot->FirstChildElement("interface");
835
836 bool isProgressIntfPresent = false;
837 while (interfaceNode != nullptr)
838 {
839 const char* thisInterfaceName = interfaceNode->Attribute("name");
840 if (thisInterfaceName != nullptr)
841 {
842 if (thisInterfaceName ==
843 std::string_view("xyz.openbmc_project.Common.Progress"))
844 {
845 interfaceNode =
846 interfaceNode->NextSiblingElement("interface");
847 continue;
848 }
849 isProgressIntfPresent = true;
850 break;
851 }
852 interfaceNode = interfaceNode->NextSiblingElement("interface");
853 }
854
855 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
856 [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent](
Ed Tanous8b242752023-06-27 17:17:13 -0700857 const boost::system::error_code& ec2, sdbusplus::message_t& msg,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600858 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanous8b242752023-06-27 17:17:13 -0700859 if (ec2)
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600860 {
Ed Tanous62598e32023-07-17 17:06:25 -0700861 BMCWEB_LOG_ERROR("{}: Error in creating dump",
862 createdObjPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600863 taskData->messages.emplace_back(messages::internalError());
864 taskData->state = "Cancelled";
865 return task::completed;
866 }
867
868 if (isProgressIntfPresent)
869 {
870 dbus::utility::DBusPropertiesMap values;
871 std::string prop;
872 msg.read(prop, values);
873
874 DumpCreationProgress dumpStatus =
875 getDumpCompletionStatus(values);
876 if (dumpStatus == DumpCreationProgress::DUMP_CREATE_FAILED)
877 {
Ed Tanous62598e32023-07-17 17:06:25 -0700878 BMCWEB_LOG_ERROR("{}: Error in creating dump",
879 createdObjPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600880 taskData->state = "Cancelled";
881 return task::completed;
882 }
883
884 if (dumpStatus == DumpCreationProgress::DUMP_CREATE_INPROGRESS)
885 {
Ed Tanous62598e32023-07-17 17:06:25 -0700886 BMCWEB_LOG_DEBUG("{}: Dump creation task is in progress",
887 createdObjPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600888 return !task::completed;
889 }
890 }
891
Ed Tanous002d39b2022-05-31 08:59:27 -0700892 nlohmann::json retMessage = messages::success();
893 taskData->messages.emplace_back(retMessage);
894
Ed Tanousc51a58e2023-03-27 14:43:19 -0700895 boost::urls::url url = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -0700896 "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}",
897 BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId);
Ed Tanousc51a58e2023-03-27 14:43:19 -0700898
899 std::string headerLoc = "Location: ";
900 headerLoc += url.buffer();
901
Ed Tanous002d39b2022-05-31 08:59:27 -0700902 taskData->payload->httpHeaders.emplace_back(std::move(headerLoc));
903
Ed Tanous62598e32023-07-17 17:06:25 -0700904 BMCWEB_LOG_DEBUG("{}: Dump creation task completed",
905 createdObjPath.str);
Ed Tanous002d39b2022-05-31 08:59:27 -0700906 taskData->state = "Completed";
907 return task::completed;
Patrick Williams5a39f772023-10-20 11:20:21 -0500908 },
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600909 "type='signal',interface='org.freedesktop.DBus.Properties',"
910 "member='PropertiesChanged',path='" +
911 createdObjPath.str + "'");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500912
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600913 // The task timer is set to max time limit within which the
914 // requested dump will be collected.
915 task->startTimer(std::chrono::minutes(6));
916 task->populateResp(asyncResp->res);
917 task->payload.emplace(payload);
Patrick Williams5a39f772023-10-20 11:20:21 -0500918 },
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600919 "xyz.openbmc_project.Dump.Manager", createdObjPath,
920 "org.freedesktop.DBus.Introspectable", "Introspect");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500921}
922
zhanghch058d1b46d2021-04-01 11:18:24 +0800923inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
924 const crow::Request& req, const std::string& dumpType)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500925{
Claire Weinanfdd26902022-03-01 14:18:25 -0800926 std::string dumpPath = getDumpEntriesPath(dumpType);
927 if (dumpPath.empty())
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500928 {
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500929 messages::internalError(asyncResp->res);
930 return;
931 }
932
933 std::optional<std::string> diagnosticDataType;
934 std::optional<std::string> oemDiagnosticDataType;
935
Willy Tu15ed6782021-12-14 11:03:16 -0800936 if (!redfish::json_util::readJsonAction(
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500937 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
938 "OEMDiagnosticDataType", oemDiagnosticDataType))
939 {
940 return;
941 }
942
943 if (dumpType == "System")
944 {
945 if (!oemDiagnosticDataType || !diagnosticDataType)
946 {
Ed Tanous62598e32023-07-17 17:06:25 -0700947 BMCWEB_LOG_ERROR(
948 "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500949 messages::actionParameterMissing(
950 asyncResp->res, "CollectDiagnosticData",
951 "DiagnosticDataType & OEMDiagnosticDataType");
952 return;
953 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700954 if ((*oemDiagnosticDataType != "System") ||
955 (*diagnosticDataType != "OEM"))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500956 {
Ed Tanous62598e32023-07-17 17:06:25 -0700957 BMCWEB_LOG_ERROR("Wrong parameter values passed");
Ed Tanousace85d62021-10-26 12:45:59 -0700958 messages::internalError(asyncResp->res);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500959 return;
960 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700961 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/",
962 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500963 }
964 else if (dumpType == "BMC")
965 {
966 if (!diagnosticDataType)
967 {
Ed Tanous62598e32023-07-17 17:06:25 -0700968 BMCWEB_LOG_ERROR(
969 "CreateDump action parameter 'DiagnosticDataType' not found!");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500970 messages::actionParameterMissing(
971 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
972 return;
973 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700974 if (*diagnosticDataType != "Manager")
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500975 {
Ed Tanous62598e32023-07-17 17:06:25 -0700976 BMCWEB_LOG_ERROR(
977 "Wrong parameter value passed for 'DiagnosticDataType'");
Ed Tanousace85d62021-10-26 12:45:59 -0700978 messages::internalError(asyncResp->res);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500979 return;
980 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700981 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/",
982 BMCWEB_REDFISH_MANAGER_URI_NAME);
Asmitha Karunanithi59075712021-10-22 01:17:41 -0500983 }
984 else
985 {
Ed Tanous62598e32023-07-17 17:06:25 -0700986 BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type");
Asmitha Karunanithi59075712021-10-22 01:17:41 -0500987 messages::internalError(asyncResp->res);
988 return;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500989 }
990
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600991 std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>>
992 createDumpParamVec;
993
Carson Labradof574a8e2023-03-22 02:26:00 +0000994 if (req.session != nullptr)
995 {
996 createDumpParamVec.emplace_back(
997 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId",
998 req.session->clientIp);
999 createDumpParamVec.emplace_back(
1000 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType",
1001 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client");
1002 }
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -06001003
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001004 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001005 [asyncResp, payload(task::Payload(req)),
1006 dumpPath](const boost::system::error_code& ec,
1007 const sdbusplus::message_t& msg,
1008 const sdbusplus::message::object_path& objPath) mutable {
Ed Tanous002d39b2022-05-31 08:59:27 -07001009 if (ec)
1010 {
Ed Tanous62598e32023-07-17 17:06:25 -07001011 BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec);
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001012 const sd_bus_error* dbusError = msg.get_error();
1013 if (dbusError == nullptr)
1014 {
1015 messages::internalError(asyncResp->res);
1016 return;
1017 }
1018
Ed Tanous62598e32023-07-17 17:06:25 -07001019 BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}",
1020 dbusError->name, dbusError->message);
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001021 if (std::string_view(
1022 "xyz.openbmc_project.Common.Error.NotAllowed") ==
1023 dbusError->name)
1024 {
1025 messages::resourceInStandby(asyncResp->res);
1026 return;
1027 }
1028 if (std::string_view(
1029 "xyz.openbmc_project.Dump.Create.Error.Disabled") ==
1030 dbusError->name)
1031 {
1032 messages::serviceDisabled(asyncResp->res, dumpPath);
1033 return;
1034 }
1035 if (std::string_view(
1036 "xyz.openbmc_project.Common.Error.Unavailable") ==
1037 dbusError->name)
1038 {
1039 messages::resourceInUse(asyncResp->res);
1040 return;
1041 }
1042 // Other Dbus errors such as:
1043 // xyz.openbmc_project.Common.Error.InvalidArgument &
1044 // org.freedesktop.DBus.Error.InvalidArgs are all related to
1045 // the dbus call that is made here in the bmcweb
1046 // implementation and has nothing to do with the client's
1047 // input in the request. Hence, returning internal error
1048 // back to the client.
Ed Tanous002d39b2022-05-31 08:59:27 -07001049 messages::internalError(asyncResp->res);
1050 return;
1051 }
Ed Tanous62598e32023-07-17 17:06:25 -07001052 BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -06001053 createDumpTaskCallback(std::move(payload), asyncResp, objPath);
Patrick Williams5a39f772023-10-20 11:20:21 -05001054 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001055 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Asmitha Karunanithi8e317782020-12-10 03:35:05 -06001056 "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec);
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001057}
1058
zhanghch058d1b46d2021-04-01 11:18:24 +08001059inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1060 const std::string& dumpType)
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001061{
Claire Weinan0d946212022-07-13 19:40:19 -07001062 crow::connections::systemBus->async_method_call(
1063 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001064 if (ec)
1065 {
Ed Tanous62598e32023-07-17 17:06:25 -07001066 BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001067 messages::internalError(asyncResp->res);
1068 return;
1069 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001070 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001071 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Claire Weinan0d946212022-07-13 19:40:19 -07001072 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001073}
1074
Ed Tanousdf254f22024-04-01 13:25:46 -07001075inline void
Ed Tanousb9d36b42022-02-26 21:42:46 -08001076 parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params,
1077 std::string& filename, std::string& timestamp,
1078 std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001079{
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001080 const std::string* filenamePtr = nullptr;
1081 const std::string* timestampPtr = nullptr;
1082 const std::string* logfilePtr = nullptr;
1083
1084 const bool success = sdbusplus::unpackPropertiesNoThrow(
1085 dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr,
1086 "Filename", filenamePtr, "Log", logfilePtr);
1087
1088 if (!success)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001089 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001090 return;
1091 }
1092
1093 if (filenamePtr != nullptr)
1094 {
1095 filename = *filenamePtr;
1096 }
1097
1098 if (timestampPtr != nullptr)
1099 {
1100 timestamp = *timestampPtr;
1101 }
1102
1103 if (logfilePtr != nullptr)
1104 {
1105 logfile = *logfilePtr;
Johnathan Mantey043a0532020-03-10 17:15:28 -07001106 }
1107}
1108
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001109inline void requestRoutesSystemLogServiceCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07001110{
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001111 /**
1112 * Functions triggers appropriate requests on DBus
1113 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001114 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
Ed Tanoused398212021-06-09 17:05:54 -07001115 .privileges(redfish::privileges::getLogServiceCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001116 .methods(boost::beast::http::verb::get)(
1117 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001118 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1119 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001120 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001121 {
1122 return;
1123 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001124 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001125 {
1126 // Option currently returns no systems. TBD
1127 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1128 systemName);
1129 return;
1130 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001131 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001132 {
1133 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1134 systemName);
1135 return;
1136 }
1137
Ed Tanous002d39b2022-05-31 08:59:27 -07001138 // Collections don't include the static data added by SubRoute
1139 // because it has a duplicate entry for members
1140 asyncResp->res.jsonValue["@odata.type"] =
1141 "#LogServiceCollection.LogServiceCollection";
1142 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001143 std::format("/redfish/v1/Systems/{}/LogServices",
1144 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07001145 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
1146 asyncResp->res.jsonValue["Description"] =
1147 "Collection of LogServices for this Computer System";
1148 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1149 logServiceArray = nlohmann::json::array();
1150 nlohmann::json::object_t eventLog;
1151 eventLog["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001152 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1153 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001154 logServiceArray.emplace_back(std::move(eventLog));
Ed Tanous25b54db2024-04-17 15:40:31 -07001155 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
1156 {
1157 nlohmann::json::object_t dumpLog;
1158 dumpLog["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001159 std::format("/redfish/v1/Systems/{}/LogServices/Dump",
1160 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001161 logServiceArray.emplace_back(std::move(dumpLog));
1162 }
raviteja-bc9bb6862020-02-03 11:53:32 -06001163
Gunnar Mills5ffd11f2024-05-02 08:26:12 -05001164 if constexpr (BMCWEB_REDFISH_CPU_LOG)
Ed Tanous25b54db2024-04-17 15:40:31 -07001165 {
1166 nlohmann::json::object_t crashdump;
1167 crashdump["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001168 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
1169 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001170 logServiceArray.emplace_back(std::move(crashdump));
1171 }
Spencer Kub7028eb2021-10-26 15:27:35 +08001172
Ed Tanous25b54db2024-04-17 15:40:31 -07001173 if constexpr (BMCWEB_REDFISH_HOST_LOGGER)
1174 {
1175 nlohmann::json::object_t hostlogger;
1176 hostlogger["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001177 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
1178 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001179 logServiceArray.emplace_back(std::move(hostlogger));
1180 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001181 asyncResp->res.jsonValue["Members@odata.count"] =
1182 logServiceArray.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -08001183
George Liu7a1dbc42022-12-07 16:03:22 +08001184 constexpr std::array<std::string_view, 1> interfaces = {
1185 "xyz.openbmc_project.State.Boot.PostCode"};
1186 dbus::utility::getSubTreePaths(
1187 "/", 0, interfaces,
1188 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001189 const dbus::utility::MapperGetSubTreePathsResponse&
1190 subtreePath) {
1191 if (ec)
1192 {
Ed Tanous62598e32023-07-17 17:06:25 -07001193 BMCWEB_LOG_ERROR("{}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001194 return;
1195 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001196
Ed Tanous002d39b2022-05-31 08:59:27 -07001197 for (const auto& pathStr : subtreePath)
1198 {
1199 if (pathStr.find("PostCode") != std::string::npos)
1200 {
1201 nlohmann::json& logServiceArrayLocal =
1202 asyncResp->res.jsonValue["Members"];
Ed Tanous613dabe2022-07-09 11:17:36 -07001203 nlohmann::json::object_t member;
Ed Tanous253f11b2024-05-16 09:38:31 -07001204 member["@odata.id"] = std::format(
1205 "/redfish/v1/Systems/{}/LogServices/PostCodes",
1206 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous613dabe2022-07-09 11:17:36 -07001207
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001208 logServiceArrayLocal.emplace_back(std::move(member));
Ed Tanous613dabe2022-07-09 11:17:36 -07001209
Ed Tanous002d39b2022-05-31 08:59:27 -07001210 asyncResp->res.jsonValue["Members@odata.count"] =
1211 logServiceArrayLocal.size();
1212 return;
1213 }
1214 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001215 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001216 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001217}
1218
1219inline void requestRoutesEventLogService(App& app)
1220{
Ed Tanous22d268c2022-05-19 09:39:07 -07001221 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/")
Ed Tanoused398212021-06-09 17:05:54 -07001222 .privileges(redfish::privileges::getLogService)
Ed Tanous002d39b2022-05-31 08:59:27 -07001223 .methods(boost::beast::http::verb::get)(
1224 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001225 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1226 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001227 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001228 {
1229 return;
1230 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001231 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001232 {
1233 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1234 systemName);
1235 return;
1236 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001237 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001238 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1239 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07001240 asyncResp->res.jsonValue["@odata.type"] =
Janet Adkinsb25644a2023-08-16 11:23:45 -05001241 "#LogService.v1_2_0.LogService";
Ed Tanous002d39b2022-05-31 08:59:27 -07001242 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1243 asyncResp->res.jsonValue["Description"] = "System Event Log Service";
1244 asyncResp->res.jsonValue["Id"] = "EventLog";
Ed Tanous539d8c62024-06-19 14:38:27 -07001245 asyncResp->res.jsonValue["OverWritePolicy"] =
1246 log_service::OverWritePolicy::WrapsWhenFull;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301247
Ed Tanous002d39b2022-05-31 08:59:27 -07001248 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07001249 redfish::time_utils::getDateTimeOffsetNow();
Tejas Patil7c8c4052021-06-04 17:43:14 +05301250
Ed Tanous002d39b2022-05-31 08:59:27 -07001251 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
1252 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
1253 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301254
Ed Tanous002d39b2022-05-31 08:59:27 -07001255 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001256 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1257 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous20fa6a22024-05-20 18:02:58 -07001258 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"]
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001259
Ed Tanous20fa6a22024-05-20 18:02:58 -07001260 = std::format(
1261 "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog",
1262 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05001263 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001264}
1265
Alexander Hansen599b9af2024-08-06 15:11:57 +02001266inline void handleSystemsLogServicesEventLogActionsClearPost(
1267 App& app, const crow::Request& req,
1268 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1269 const std::string& systemName)
1270{
1271 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1272 {
1273 return;
1274 }
1275 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1276 {
1277 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1278 systemName);
1279 return;
1280 }
1281
1282 // Clear the EventLog by deleting the log files
1283 std::vector<std::filesystem::path> redfishLogFiles;
1284 if (getRedfishLogFiles(redfishLogFiles))
1285 {
1286 for (const std::filesystem::path& file : redfishLogFiles)
1287 {
1288 std::error_code ec;
1289 std::filesystem::remove(file, ec);
1290 }
1291 }
1292
1293 // Reload rsyslog so it knows to start new log files
1294 crow::connections::systemBus->async_method_call(
1295 [asyncResp](const boost::system::error_code& ec) {
1296 if (ec)
1297 {
1298 BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec);
1299 messages::internalError(asyncResp->res);
1300 return;
1301 }
1302
1303 messages::success(asyncResp->res);
1304 },
1305 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1306 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1307 "replace");
1308}
1309
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001310inline void requestRoutesJournalEventLogClear(App& app)
1311{
Jason M. Bills4978b632022-02-22 14:17:43 -08001312 BMCWEB_ROUTE(
1313 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07001314 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Ed Tanous432a8902021-06-14 15:28:56 -07001315 .privileges({{"ConfigureComponents"}})
Alexander Hansen599b9af2024-08-06 15:11:57 +02001316 .methods(boost::beast::http::verb::post)(std::bind_front(
1317 handleSystemsLogServicesEventLogActionsClearPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001318}
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001319
Jason M. Billsac992cd2022-06-24 13:31:46 -07001320enum class LogParseError
1321{
1322 success,
1323 parseFailed,
1324 messageIdNotInRegistry,
1325};
1326
1327static LogParseError
1328 fillEventLogEntryJson(const std::string& logEntryID,
1329 const std::string& logEntry,
1330 nlohmann::json::object_t& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001331{
Jason M. Bills95820182019-04-22 16:25:34 -07001332 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001333 // First get the Timestamp
Ed Tanousf23b7292020-10-15 09:41:17 -07001334 size_t space = logEntry.find_first_of(' ');
Jason M. Billscd225da2019-05-08 15:31:57 -07001335 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001336 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001337 return LogParseError::parseFailed;
Jason M. Bills95820182019-04-22 16:25:34 -07001338 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001339 std::string timestamp = logEntry.substr(0, space);
1340 // Then get the log contents
Ed Tanousf23b7292020-10-15 09:41:17 -07001341 size_t entryStart = logEntry.find_first_not_of(' ', space);
Jason M. Billscd225da2019-05-08 15:31:57 -07001342 if (entryStart == std::string::npos)
1343 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001344 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001345 }
1346 std::string_view entry(logEntry);
1347 entry.remove_prefix(entryStart);
1348 // Use split to separate the entry into its fields
1349 std::vector<std::string> logEntryFields;
Ed Tanous50ebd4a2023-01-19 19:03:17 -08001350 bmcweb::split(logEntryFields, entry, ',');
Jason M. Billscd225da2019-05-08 15:31:57 -07001351 // We need at least a MessageId to be valid
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001352 auto logEntryIter = logEntryFields.begin();
1353 if (logEntryIter == logEntryFields.end())
Jason M. Billscd225da2019-05-08 15:31:57 -07001354 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001355 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001356 }
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001357 std::string& messageID = *logEntryIter;
Jason M. Bills4851d452019-03-28 11:27:48 -07001358 // Get the Message from the MessageRegistry
Ed Tanousfffb8c12022-02-07 23:53:03 -08001359 const registries::Message* message = registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001360
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001361 logEntryIter++;
Sui Chen54417b02022-03-24 14:59:52 -07001362 if (message == nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001363 {
Ed Tanous62598e32023-07-17 17:06:25 -07001364 BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001365 return LogParseError::messageIdNotInRegistry;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001366 }
1367
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001368 std::vector<std::string_view> messageArgs(logEntryIter,
1369 logEntryFields.end());
Ed Tanousc05bba42023-06-28 08:33:29 -07001370 messageArgs.resize(message->numberOfArgs);
1371
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001372 std::string msg = redfish::registries::fillMessageArgs(messageArgs,
1373 message->message);
1374 if (msg.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001375 {
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001376 return LogParseError::parseFailed;
Jason M. Bills4851d452019-03-28 11:27:48 -07001377 }
1378
Jason M. Bills95820182019-04-22 16:25:34 -07001379 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1380 // format which matches the Redfish format except for the fractional seconds
1381 // between the '.' and the '+', so just remove them.
Ed Tanousf23b7292020-10-15 09:41:17 -07001382 std::size_t dot = timestamp.find_first_of('.');
1383 std::size_t plus = timestamp.find_first_of('+');
Jason M. Bills95820182019-04-22 16:25:34 -07001384 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001385 {
Jason M. Bills95820182019-04-22 16:25:34 -07001386 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001387 }
1388
1389 // Fill in the log entry with the gathered data
Vijay Lobo9c11a172021-10-07 16:53:16 -05001390 logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001391 logEntryJson["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001392 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1393 BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
Jason M. Bills84afc482022-06-24 12:38:23 -07001394 logEntryJson["Name"] = "System Event Log Entry";
1395 logEntryJson["Id"] = logEntryID;
1396 logEntryJson["Message"] = std::move(msg);
1397 logEntryJson["MessageId"] = std::move(messageID);
1398 logEntryJson["MessageArgs"] = messageArgs;
1399 logEntryJson["EntryType"] = "Event";
1400 logEntryJson["Severity"] = message->messageSeverity;
1401 logEntryJson["Created"] = std::move(timestamp);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001402 return LogParseError::success;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001403}
1404
Alexander Hansen599b9af2024-08-06 15:11:57 +02001405inline void handleSystemsLogServiceEventLogLogEntryCollection(
1406 App& app, const crow::Request& req,
1407 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1408 const std::string& systemName)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001409{
Alexander Hansen599b9af2024-08-06 15:11:57 +02001410 query_param::QueryCapabilities capabilities = {
1411 .canDelegateTop = true,
1412 .canDelegateSkip = true,
1413 };
1414 query_param::Query delegatedQuery;
1415 if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp,
1416 delegatedQuery, capabilities))
1417 {
1418 return;
1419 }
1420 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1421 {
1422 // Option currently returns no systems. TBD
1423 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1424 systemName);
1425 return;
1426 }
1427 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1428 {
1429 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1430 systemName);
1431 return;
1432 }
1433
1434 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
1435 size_t skip = delegatedQuery.skip.value_or(0);
1436
1437 // Collections don't include the static data added by SubRoute
1438 // because it has a duplicate entry for members
1439 asyncResp->res.jsonValue["@odata.type"] =
1440 "#LogEntryCollection.LogEntryCollection";
1441 asyncResp->res.jsonValue["@odata.id"] =
1442 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1443 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1444 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1445 asyncResp->res.jsonValue["Description"] =
1446 "Collection of System Event Log Entries";
1447
1448 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1449 logEntryArray = nlohmann::json::array();
1450 // Go through the log files and create a unique ID for each
1451 // entry
1452 std::vector<std::filesystem::path> redfishLogFiles;
1453 getRedfishLogFiles(redfishLogFiles);
1454 uint64_t entryCount = 0;
1455 std::string logEntry;
1456
1457 // Oldest logs are in the last file, so start there and loop
1458 // backwards
1459 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++)
1460 {
1461 std::ifstream logStream(*it);
1462 if (!logStream.is_open())
Ed Tanous002d39b2022-05-31 08:59:27 -07001463 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001464 continue;
Ed Tanous22d268c2022-05-19 09:39:07 -07001465 }
1466
Alexander Hansen599b9af2024-08-06 15:11:57 +02001467 // Reset the unique ID on the first entry
1468 bool firstEntry = true;
1469 while (std::getline(logStream, logEntry))
Ed Tanous002d39b2022-05-31 08:59:27 -07001470 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001471 std::string idStr;
1472 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1473 {
1474 continue;
1475 }
1476 firstEntry = false;
1477
1478 nlohmann::json::object_t bmcLogEntry;
1479 LogParseError status = fillEventLogEntryJson(idStr, logEntry,
1480 bmcLogEntry);
1481 if (status == LogParseError::messageIdNotInRegistry)
1482 {
1483 continue;
1484 }
1485 if (status != LogParseError::success)
1486 {
1487 messages::internalError(asyncResp->res);
1488 return;
1489 }
1490
1491 entryCount++;
1492 // Handle paging using skip (number of entries to skip from the
1493 // start) and top (number of entries to display)
1494 if (entryCount <= skip || entryCount > skip + top)
Jason M. Bills4978b632022-02-22 14:17:43 -08001495 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001496 continue;
Jason M. Bills4978b632022-02-22 14:17:43 -08001497 }
Jason M. Bills897967d2019-07-29 17:05:30 -07001498
Alexander Hansen599b9af2024-08-06 15:11:57 +02001499 logEntryArray.emplace_back(std::move(bmcLogEntry));
1500 }
1501 }
1502 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1503 if (skip + top < entryCount)
1504 {
1505 asyncResp->res.jsonValue["Members@odata.nextLink"] =
1506 boost::urls::format(
1507 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}",
1508 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top));
1509 }
1510}
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001511
Alexander Hansen599b9af2024-08-06 15:11:57 +02001512inline void requestRoutesJournalEventLogEntryCollection(App& app)
1513{
1514 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
1515 .privileges(redfish::privileges::getLogEntryCollection)
1516 .methods(boost::beast::http::verb::get)(std::bind_front(
1517 handleSystemsLogServiceEventLogLogEntryCollection, std::ref(app)));
1518}
1519
1520inline void handleSystemsLogServiceEventLogEntriesGet(
1521 App& app, const crow::Request& req,
1522 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1523 const std::string& systemName, const std::string& param)
1524{
1525 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1526 {
1527 return;
1528 }
1529 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1530 {
1531 // Option currently returns no systems. TBD
1532 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1533 systemName);
1534 return;
1535 }
1536
1537 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1538 {
1539 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1540 systemName);
1541 return;
1542 }
1543
1544 const std::string& targetID = param;
1545
1546 // Go through the log files and check the unique ID for each
1547 // entry to find the target entry
1548 std::vector<std::filesystem::path> redfishLogFiles;
1549 getRedfishLogFiles(redfishLogFiles);
1550 std::string logEntry;
1551
1552 // Oldest logs are in the last file, so start there and loop
1553 // backwards
1554 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++)
1555 {
1556 std::ifstream logStream(*it);
1557 if (!logStream.is_open())
1558 {
1559 continue;
1560 }
1561
1562 // Reset the unique ID on the first entry
1563 bool firstEntry = true;
1564 while (std::getline(logStream, logEntry))
1565 {
1566 std::string idStr;
1567 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1568 {
1569 continue;
1570 }
1571 firstEntry = false;
1572
1573 if (idStr == targetID)
1574 {
Jason M. Billsde703c52022-06-23 14:19:04 -07001575 nlohmann::json::object_t bmcLogEntry;
Patrick Williams89492a12023-05-10 07:51:34 -05001576 LogParseError status = fillEventLogEntryJson(idStr, logEntry,
1577 bmcLogEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001578 if (status != LogParseError::success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001579 {
1580 messages::internalError(asyncResp->res);
1581 return;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001582 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001583 asyncResp->res.jsonValue.update(bmcLogEntry);
1584 return;
Jason M. Bills4978b632022-02-22 14:17:43 -08001585 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001586 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001587 }
1588 // Requested ID was not found
1589 messages::resourceNotFound(asyncResp->res, "LogEntry", targetID);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001590}
Chicago Duan336e96c2019-07-15 14:22:08 +08001591
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001592inline void requestRoutesJournalEventLogEntry(App& app)
1593{
1594 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001595 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001596 .privileges(redfish::privileges::getLogEntry)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001597 .methods(boost::beast::http::verb::get)(std::bind_front(
1598 handleSystemsLogServiceEventLogEntriesGet, std::ref(app)));
1599}
1600
1601inline void dBusEventLogEntryCollection(
1602 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1603{
1604 // Collections don't include the static data added by SubRoute
1605 // because it has a duplicate entry for members
1606 asyncResp->res.jsonValue["@odata.type"] =
1607 "#LogEntryCollection.LogEntryCollection";
1608 asyncResp->res.jsonValue["@odata.id"] =
1609 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1610 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1611 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1612 asyncResp->res.jsonValue["Description"] =
1613 "Collection of System Event Log Entries";
1614
1615 // DBus implementation of EventLog/Entries
1616 // Make call to Logging Service to find all log entry objects
1617 sdbusplus::message::object_path path("/xyz/openbmc_project/logging");
1618 dbus::utility::getManagedObjects(
1619 "xyz.openbmc_project.Logging", path,
1620 [asyncResp](const boost::system::error_code& ec,
1621 const dbus::utility::ManagedObjectType& resp) {
1622 if (ec)
Ed Tanous002d39b2022-05-31 08:59:27 -07001623 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001624 // TODO Handle for specific error code
1625 BMCWEB_LOG_ERROR("getLogEntriesIfaceData resp_handler got error {}",
1626 ec);
1627 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -07001628 return;
1629 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001630 nlohmann::json::array_t entriesArray;
1631 for (const auto& objectPath : resp)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001632 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001633 const uint32_t* id = nullptr;
1634 const uint64_t* timestamp = nullptr;
1635 const uint64_t* updateTimestamp = nullptr;
1636 const std::string* severity = nullptr;
1637 const std::string* message = nullptr;
1638 const std::string* filePath = nullptr;
1639 const std::string* resolution = nullptr;
1640 bool resolved = false;
1641 const std::string* notify = nullptr;
Ed Tanous22d268c2022-05-19 09:39:07 -07001642
Alexander Hansen599b9af2024-08-06 15:11:57 +02001643 for (const auto& interfaceMap : objectPath.second)
Ed Tanous002d39b2022-05-31 08:59:27 -07001644 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001645 if (interfaceMap.first == "xyz.openbmc_project.Logging.Entry")
Ed Tanous45ca1b82022-03-25 13:07:27 -07001646 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001647 for (const auto& propertyMap : interfaceMap.second)
1648 {
1649 if (propertyMap.first == "Id")
1650 {
1651 id = std::get_if<uint32_t>(&propertyMap.second);
1652 }
1653 else if (propertyMap.first == "Timestamp")
1654 {
1655 timestamp =
1656 std::get_if<uint64_t>(&propertyMap.second);
1657 }
1658 else if (propertyMap.first == "UpdateTimestamp")
1659 {
1660 updateTimestamp =
1661 std::get_if<uint64_t>(&propertyMap.second);
1662 }
1663 else if (propertyMap.first == "Severity")
1664 {
1665 severity =
1666 std::get_if<std::string>(&propertyMap.second);
1667 }
1668 else if (propertyMap.first == "Resolution")
1669 {
1670 resolution =
1671 std::get_if<std::string>(&propertyMap.second);
1672 }
1673 else if (propertyMap.first == "Message")
1674 {
1675 message =
1676 std::get_if<std::string>(&propertyMap.second);
1677 }
1678 else if (propertyMap.first == "Resolved")
1679 {
1680 const bool* resolveptr =
1681 std::get_if<bool>(&propertyMap.second);
1682 if (resolveptr == nullptr)
1683 {
1684 messages::internalError(asyncResp->res);
1685 return;
1686 }
1687 resolved = *resolveptr;
1688 }
1689 else if (propertyMap.first == "ServiceProviderNotify")
1690 {
1691 notify =
1692 std::get_if<std::string>(&propertyMap.second);
1693 if (notify == nullptr)
1694 {
1695 messages::internalError(asyncResp->res);
1696 return;
1697 }
1698 }
1699 }
1700 if (id == nullptr || message == nullptr ||
1701 severity == nullptr)
Ed Tanous002d39b2022-05-31 08:59:27 -07001702 {
1703 messages::internalError(asyncResp->res);
1704 return;
1705 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001706 }
1707 else if (interfaceMap.first ==
1708 "xyz.openbmc_project.Common.FilePath")
1709 {
1710 for (const auto& propertyMap : interfaceMap.second)
1711 {
1712 if (propertyMap.first == "Path")
1713 {
1714 filePath =
1715 std::get_if<std::string>(&propertyMap.second);
1716 }
1717 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001718 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001719 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001720 // Object path without the
1721 // xyz.openbmc_project.Logging.Entry interface, ignore
1722 // and continue.
1723 if (id == nullptr || message == nullptr || severity == nullptr ||
1724 timestamp == nullptr || updateTimestamp == nullptr)
1725 {
1726 continue;
1727 }
1728 nlohmann::json& thisEntry = entriesArray.emplace_back();
1729 thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1730 thisEntry["@odata.id"] = boost::urls::format(
1731 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1732 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(*id));
1733 thisEntry["Name"] = "System Event Log Entry";
1734 thisEntry["Id"] = std::to_string(*id);
1735 thisEntry["Message"] = *message;
1736 thisEntry["Resolved"] = resolved;
1737 if ((resolution != nullptr) && (!(*resolution).empty()))
1738 {
1739 thisEntry["Resolution"] = *resolution;
1740 }
1741 if (notify != nullptr)
1742 {
1743 std::optional<bool> notifyAction =
1744 getProviderNotifyAction(*notify);
1745 if (notifyAction)
1746 {
1747 thisEntry["ServiceProviderNotified"] = *notifyAction;
1748 }
1749 }
1750 thisEntry["EntryType"] = "Event";
1751 thisEntry["Severity"] = translateSeverityDbusToRedfish(*severity);
1752 thisEntry["Created"] =
1753 redfish::time_utils::getDateTimeUintMs(*timestamp);
1754 thisEntry["Modified"] =
1755 redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
1756 if (filePath != nullptr)
1757 {
1758 thisEntry["AdditionalDataURI"] =
1759 std::format(
1760 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/",
1761 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
1762 std::to_string(*id) + "/attachment";
1763 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001764 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001765 std::ranges::sort(entriesArray, [](const nlohmann::json& left,
1766 const nlohmann::json& right) {
1767 return (left["Id"] <= right["Id"]);
1768 });
1769 asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
1770 asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
Patrick Williams5a39f772023-10-20 11:20:21 -05001771 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001772}
1773
1774inline void requestRoutesDBusEventLogEntryCollection(App& app)
1775{
Ed Tanous22d268c2022-05-19 09:39:07 -07001776 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07001777 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001778 .methods(boost::beast::http::verb::get)(
1779 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001780 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1781 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001782 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001783 {
1784 return;
1785 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001786 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001787 {
1788 // Option currently returns no systems. TBD
1789 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1790 systemName);
1791 return;
1792 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001793 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001794 {
1795 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1796 systemName);
1797 return;
1798 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001799 dBusEventLogEntryCollection(asyncResp);
1800 });
1801}
Ed Tanous22d268c2022-05-19 09:39:07 -07001802
Alexander Hansen599b9af2024-08-06 15:11:57 +02001803inline void
1804 dBusEventLogEntryGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1805 std::string& entryID)
1806{
1807 dbus::utility::escapePathForDbus(entryID);
Ed Tanous002d39b2022-05-31 08:59:27 -07001808
Alexander Hansen599b9af2024-08-06 15:11:57 +02001809 // DBus implementation of EventLog/Entries
1810 // Make call to Logging Service to find all log entry objects
1811 sdbusplus::asio::getAllProperties(
1812 *crow::connections::systemBus, "xyz.openbmc_project.Logging",
1813 "/xyz/openbmc_project/logging/entry/" + entryID, "",
1814 [asyncResp, entryID](const boost::system::error_code& ec,
1815 const dbus::utility::DBusPropertiesMap& resp) {
1816 if (ec.value() == EBADR)
1817 {
1818 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1819 entryID);
1820 return;
1821 }
1822 if (ec)
1823 {
1824 BMCWEB_LOG_ERROR("EventLogEntry (DBus) resp_handler got error {}",
1825 ec);
1826 messages::internalError(asyncResp->res);
1827 return;
1828 }
1829 const uint32_t* id = nullptr;
1830 const uint64_t* timestamp = nullptr;
1831 const uint64_t* updateTimestamp = nullptr;
1832 const std::string* severity = nullptr;
1833 const std::string* message = nullptr;
1834 const std::string* filePath = nullptr;
1835 const std::string* resolution = nullptr;
1836 bool resolved = false;
1837 const std::string* notify = nullptr;
1838
1839 const bool success = sdbusplus::unpackPropertiesNoThrow(
1840 dbus_utils::UnpackErrorPrinter(), resp, "Id", id, "Timestamp",
1841 timestamp, "UpdateTimestamp", updateTimestamp, "Severity", severity,
1842 "Message", message, "Resolved", resolved, "Resolution", resolution,
1843 "Path", filePath, "ServiceProviderNotify", notify);
1844
1845 if (!success)
1846 {
1847 messages::internalError(asyncResp->res);
1848 return;
1849 }
1850
1851 if (id == nullptr || message == nullptr || severity == nullptr ||
1852 timestamp == nullptr || updateTimestamp == nullptr ||
1853 notify == nullptr)
1854 {
1855 messages::internalError(asyncResp->res);
1856 return;
1857 }
1858
1859 asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1860 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1861 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1862 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(*id));
1863 asyncResp->res.jsonValue["Name"] = "System Event Log Entry";
1864 asyncResp->res.jsonValue["Id"] = std::to_string(*id);
1865 asyncResp->res.jsonValue["Message"] = *message;
1866 asyncResp->res.jsonValue["Resolved"] = resolved;
1867 std::optional<bool> notifyAction = getProviderNotifyAction(*notify);
1868 if (notifyAction)
1869 {
1870 asyncResp->res.jsonValue["ServiceProviderNotified"] = *notifyAction;
1871 }
1872 if ((resolution != nullptr) && (!(*resolution).empty()))
1873 {
1874 asyncResp->res.jsonValue["Resolution"] = *resolution;
1875 }
1876 asyncResp->res.jsonValue["EntryType"] = "Event";
1877 asyncResp->res.jsonValue["Severity"] =
1878 translateSeverityDbusToRedfish(*severity);
1879 asyncResp->res.jsonValue["Created"] =
1880 redfish::time_utils::getDateTimeUintMs(*timestamp);
1881 asyncResp->res.jsonValue["Modified"] =
1882 redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
1883 if (filePath != nullptr)
1884 {
1885 asyncResp->res.jsonValue["AdditionalDataURI"] =
1886 std::format(
1887 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/",
1888 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
1889 std::to_string(*id) + "/attachment";
1890 }
1891 });
1892}
1893
1894inline void
1895 dBusEventLogEntryPatch(const crow::Request& req,
1896 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1897 const std::string& entryId)
1898{
1899 std::optional<bool> resolved;
1900
1901 if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", resolved))
1902 {
1903 return;
1904 }
1905 BMCWEB_LOG_DEBUG("Set Resolved");
1906
1907 setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging",
1908 "/xyz/openbmc_project/logging/entry/" + entryId,
1909 "xyz.openbmc_project.Logging.Entry", "Resolved",
1910 resolved.value_or(false));
1911}
1912
1913inline void
1914 dBusEventLogEntryDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1915 std::string entryID)
1916{
1917 BMCWEB_LOG_DEBUG("Do delete single event entries.");
1918
1919 dbus::utility::escapePathForDbus(entryID);
1920
1921 // Process response from Logging service.
1922 auto respHandler = [asyncResp,
1923 entryID](const boost::system::error_code& ec) {
1924 BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done");
1925 if (ec)
1926 {
1927 if (ec.value() == EBADR)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001928 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001929 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001930 return;
1931 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001932 // TODO Handle for specific error code
1933 BMCWEB_LOG_ERROR(
1934 "EventLogEntry (DBus) doDelete respHandler got error {}", ec);
1935 asyncResp->res.result(
1936 boost::beast::http::status::internal_server_error);
1937 return;
1938 }
Abhishek Patel9017faf2021-09-14 22:48:55 -05001939
Alexander Hansen599b9af2024-08-06 15:11:57 +02001940 asyncResp->res.result(boost::beast::http::status::ok);
1941 };
1942
1943 // Make call to Logging service to request Delete Log
1944 crow::connections::systemBus->async_method_call(
1945 respHandler, "xyz.openbmc_project.Logging",
1946 "/xyz/openbmc_project/logging/entry/" + entryID,
1947 "xyz.openbmc_project.Object.Delete", "Delete");
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001948}
Xiaochao Ma75710de2021-01-21 17:56:02 +08001949
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001950inline void requestRoutesDBusEventLogEntry(App& app)
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001951{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001952 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001953 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001954 .privileges(redfish::privileges::getLogEntry)
Ed Tanous002d39b2022-05-31 08:59:27 -07001955 .methods(boost::beast::http::verb::get)(
1956 [&app](const crow::Request& req,
1957 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001958 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001959 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001960 {
1961 return;
1962 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001963 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001964 {
1965 // Option currently returns no systems. TBD
1966 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1967 systemName);
1968 return;
1969 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001970 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001971 {
1972 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1973 systemName);
1974 return;
1975 }
1976
Ed Tanous002d39b2022-05-31 08:59:27 -07001977 std::string entryID = param;
Ed Tanous002d39b2022-05-31 08:59:27 -07001978
Alexander Hansen599b9af2024-08-06 15:11:57 +02001979 dBusEventLogEntryGet(asyncResp, entryID);
Patrick Williams5a39f772023-10-20 11:20:21 -05001980 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001981
1982 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001983 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001984 .privileges(redfish::privileges::patchLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001985 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001986 [&app](const crow::Request& req,
1987 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001988 const std::string& systemName, const std::string& entryId) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001989 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001990 {
1991 return;
1992 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001993 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001994 {
1995 // Option currently returns no systems. TBD
1996 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1997 systemName);
1998 return;
1999 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002000 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002001 {
2002 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2003 systemName);
2004 return;
2005 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002006
Alexander Hansen599b9af2024-08-06 15:11:57 +02002007 dBusEventLogEntryPatch(req, asyncResp, entryId);
Patrick Williams5a39f772023-10-20 11:20:21 -05002008 });
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06002009
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002010 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07002011 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002012 .privileges(redfish::privileges::deleteLogEntry)
2013
Ed Tanous002d39b2022-05-31 08:59:27 -07002014 .methods(boost::beast::http::verb::delete_)(
2015 [&app](const crow::Request& req,
2016 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07002017 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002018 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002019 {
2020 return;
2021 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002022 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002023 {
2024 // Option currently returns no systems. TBD
2025 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2026 systemName);
2027 return;
2028 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002029 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002030 {
2031 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2032 systemName);
2033 return;
2034 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02002035 dBusEventLogEntryDelete(asyncResp, param);
Patrick Williams5a39f772023-10-20 11:20:21 -05002036 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002037}
2038
Spencer Kub7028eb2021-10-26 15:27:35 +08002039constexpr const char* hostLoggerFolderPath = "/var/log/console";
2040
2041inline bool
2042 getHostLoggerFiles(const std::string& hostLoggerFilePath,
2043 std::vector<std::filesystem::path>& hostLoggerFiles)
2044{
2045 std::error_code ec;
2046 std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec);
2047 if (ec)
2048 {
Carson Labradobf2dded2023-08-10 00:37:06 +00002049 BMCWEB_LOG_WARNING("{}", ec.message());
Spencer Kub7028eb2021-10-26 15:27:35 +08002050 return false;
2051 }
2052 for (const std::filesystem::directory_entry& it : logPath)
2053 {
2054 std::string filename = it.path().filename();
2055 // Prefix of each log files is "log". Find the file and save the
2056 // path
Ed Tanous11ba3972022-07-11 09:50:41 -07002057 if (filename.starts_with("log"))
Spencer Kub7028eb2021-10-26 15:27:35 +08002058 {
2059 hostLoggerFiles.emplace_back(it.path());
2060 }
2061 }
2062 // As the log files rotate, they are appended with a ".#" that is higher for
2063 // the older logs. Since we start from oldest logs, sort the name in
2064 // descending order.
2065 std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(),
2066 AlphanumLess<std::string>());
2067
2068 return true;
2069}
2070
Ed Tanous02cad962022-06-30 16:50:15 -07002071inline bool getHostLoggerEntries(
2072 const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip,
2073 uint64_t top, std::vector<std::string>& logEntries, size_t& logCount)
Spencer Kub7028eb2021-10-26 15:27:35 +08002074{
2075 GzFileReader logFile;
2076
2077 // Go though all log files and expose host logs.
2078 for (const std::filesystem::path& it : hostLoggerFiles)
2079 {
2080 if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount))
2081 {
Ed Tanous62598e32023-07-17 17:06:25 -07002082 BMCWEB_LOG_ERROR("fail to expose host logs");
Spencer Kub7028eb2021-10-26 15:27:35 +08002083 return false;
2084 }
2085 }
2086 // Get lastMessage from constructor by getter
2087 std::string lastMessage = logFile.getLastMessage();
2088 if (!lastMessage.empty())
2089 {
2090 logCount++;
2091 if (logCount > skip && logCount <= (skip + top))
2092 {
2093 logEntries.push_back(lastMessage);
2094 }
2095 }
2096 return true;
2097}
2098
Ed Tanous6f056f22024-04-07 13:35:51 -07002099inline void fillHostLoggerEntryJson(std::string_view logEntryID,
2100 std::string_view msg,
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002101 nlohmann::json::object_t& logEntryJson)
Spencer Kub7028eb2021-10-26 15:27:35 +08002102{
2103 // Fill in the log entry with the gathered data.
Vijay Lobo9c11a172021-10-07 16:53:16 -05002104 logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07002105 logEntryJson["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07002106 "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries/{}",
2107 BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002108 logEntryJson["Name"] = "Host Logger Entry";
2109 logEntryJson["Id"] = logEntryID;
2110 logEntryJson["Message"] = msg;
Ed Tanous539d8c62024-06-19 14:38:27 -07002111 logEntryJson["EntryType"] = log_entry::LogEntryType::Oem;
2112 logEntryJson["Severity"] = log_entry::EventSeverity::OK;
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002113 logEntryJson["OemRecordFormat"] = "Host Logger Entry";
Spencer Kub7028eb2021-10-26 15:27:35 +08002114}
2115
2116inline void requestRoutesSystemHostLogger(App& app)
2117{
Ed Tanous22d268c2022-05-19 09:39:07 -07002118 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/")
Spencer Kub7028eb2021-10-26 15:27:35 +08002119 .privileges(redfish::privileges::getLogService)
Ed Tanous14766872022-03-15 10:44:42 -07002120 .methods(boost::beast::http::verb::get)(
2121 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002122 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2123 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002124 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002125 {
2126 return;
2127 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002128 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002129 {
2130 // Option currently returns no systems. TBD
2131 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2132 systemName);
2133 return;
2134 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002135 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002136 {
2137 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2138 systemName);
2139 return;
2140 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002141 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002142 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
2143 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002144 asyncResp->res.jsonValue["@odata.type"] =
Janet Adkinsb25644a2023-08-16 11:23:45 -05002145 "#LogService.v1_2_0.LogService";
Ed Tanous002d39b2022-05-31 08:59:27 -07002146 asyncResp->res.jsonValue["Name"] = "Host Logger Service";
2147 asyncResp->res.jsonValue["Description"] = "Host Logger Service";
2148 asyncResp->res.jsonValue["Id"] = "HostLogger";
2149 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002150 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
2151 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05002152 });
Spencer Kub7028eb2021-10-26 15:27:35 +08002153}
2154
2155inline void requestRoutesSystemHostLoggerCollection(App& app)
2156{
2157 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002158 "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/")
Spencer Kub7028eb2021-10-26 15:27:35 +08002159 .privileges(redfish::privileges::getLogEntry)
Ed Tanous002d39b2022-05-31 08:59:27 -07002160 .methods(boost::beast::http::verb::get)(
2161 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002162 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2163 const std::string& systemName) {
Ed Tanous002d39b2022-05-31 08:59:27 -07002164 query_param::QueryCapabilities capabilities = {
2165 .canDelegateTop = true,
2166 .canDelegateSkip = true,
2167 };
2168 query_param::Query delegatedQuery;
2169 if (!redfish::setUpRedfishRouteWithDelegation(
Carson Labrado3ba00072022-06-06 19:40:56 +00002170 app, req, asyncResp, delegatedQuery, capabilities))
Ed Tanous002d39b2022-05-31 08:59:27 -07002171 {
2172 return;
2173 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002174 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002175 {
2176 // Option currently returns no systems. TBD
2177 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2178 systemName);
2179 return;
2180 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002181 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002182 {
2183 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2184 systemName);
2185 return;
2186 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002187 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002188 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
2189 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002190 asyncResp->res.jsonValue["@odata.type"] =
2191 "#LogEntryCollection.LogEntryCollection";
2192 asyncResp->res.jsonValue["Name"] = "HostLogger Entries";
2193 asyncResp->res.jsonValue["Description"] =
2194 "Collection of HostLogger Entries";
2195 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
2196 logEntryArray = nlohmann::json::array();
2197 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Spencer Kub7028eb2021-10-26 15:27:35 +08002198
Ed Tanous002d39b2022-05-31 08:59:27 -07002199 std::vector<std::filesystem::path> hostLoggerFiles;
2200 if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
2201 {
Carson Labradobf2dded2023-08-10 00:37:06 +00002202 BMCWEB_LOG_DEBUG("Failed to get host log file path");
Ed Tanous002d39b2022-05-31 08:59:27 -07002203 return;
2204 }
Ed Tanous3648c8b2022-07-25 13:39:59 -07002205 // If we weren't provided top and skip limits, use the defaults.
2206 size_t skip = delegatedQuery.skip.value_or(0);
Jiaqing Zhao5143f7a2022-07-22 09:33:33 +08002207 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
Ed Tanous002d39b2022-05-31 08:59:27 -07002208 size_t logCount = 0;
2209 // This vector only store the entries we want to expose that
2210 // control by skip and top.
2211 std::vector<std::string> logEntries;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002212 if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries,
2213 logCount))
Ed Tanous002d39b2022-05-31 08:59:27 -07002214 {
2215 messages::internalError(asyncResp->res);
2216 return;
2217 }
2218 // If vector is empty, that means skip value larger than total
2219 // log count
2220 if (logEntries.empty())
2221 {
2222 asyncResp->res.jsonValue["Members@odata.count"] = logCount;
2223 return;
2224 }
2225 if (!logEntries.empty())
2226 {
2227 for (size_t i = 0; i < logEntries.size(); i++)
George Liu0fda0f12021-11-16 10:06:17 +08002228 {
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002229 nlohmann::json::object_t hostLogEntry;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002230 fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i],
2231 hostLogEntry);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002232 logEntryArray.emplace_back(std::move(hostLogEntry));
George Liu0fda0f12021-11-16 10:06:17 +08002233 }
2234
Ed Tanous002d39b2022-05-31 08:59:27 -07002235 asyncResp->res.jsonValue["Members@odata.count"] = logCount;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002236 if (skip + top < logCount)
George Liu0fda0f12021-11-16 10:06:17 +08002237 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002238 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002239 std::format(
2240 "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries?$skip=",
2241 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous3648c8b2022-07-25 13:39:59 -07002242 std::to_string(skip + top);
George Liu0fda0f12021-11-16 10:06:17 +08002243 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002244 }
Patrick Williams5a39f772023-10-20 11:20:21 -05002245 });
Spencer Kub7028eb2021-10-26 15:27:35 +08002246}
2247
2248inline void requestRoutesSystemHostLoggerLogEntry(App& app)
2249{
2250 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07002251 app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/")
Spencer Kub7028eb2021-10-26 15:27:35 +08002252 .privileges(redfish::privileges::getLogEntry)
2253 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002254 [&app](const crow::Request& req,
2255 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07002256 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002257 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002258 {
2259 return;
2260 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002261 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002262 {
2263 // Option currently returns no systems. TBD
2264 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2265 systemName);
2266 return;
2267 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002268 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002269 {
2270 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2271 systemName);
2272 return;
2273 }
Ed Tanous6f056f22024-04-07 13:35:51 -07002274 std::string_view targetID = param;
Spencer Kub7028eb2021-10-26 15:27:35 +08002275
Ed Tanous002d39b2022-05-31 08:59:27 -07002276 uint64_t idInt = 0;
Ed Tanousca45aa32022-01-07 09:28:45 -08002277
Ed Tanous6f056f22024-04-07 13:35:51 -07002278 auto [ptr, ec] = std::from_chars(targetID.begin(), targetID.end(),
Patrick Williams84396af2023-05-11 11:47:45 -05002279 idInt);
Ed Tanous6f056f22024-04-07 13:35:51 -07002280 if (ec != std::errc{} || ptr != targetID.end())
Ed Tanous002d39b2022-05-31 08:59:27 -07002281 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08002282 messages::resourceNotFound(asyncResp->res, "LogEntry", param);
Ed Tanous002d39b2022-05-31 08:59:27 -07002283 return;
2284 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002285
Ed Tanous002d39b2022-05-31 08:59:27 -07002286 std::vector<std::filesystem::path> hostLoggerFiles;
2287 if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
2288 {
Carson Labradobf2dded2023-08-10 00:37:06 +00002289 BMCWEB_LOG_DEBUG("Failed to get host log file path");
Ed Tanous002d39b2022-05-31 08:59:27 -07002290 return;
2291 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002292
Ed Tanous002d39b2022-05-31 08:59:27 -07002293 size_t logCount = 0;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002294 size_t top = 1;
Ed Tanous002d39b2022-05-31 08:59:27 -07002295 std::vector<std::string> logEntries;
2296 // We can get specific entry by skip and top. For example, if we
2297 // want to get nth entry, we can set skip = n-1 and top = 1 to
2298 // get that entry
2299 if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries,
2300 logCount))
2301 {
2302 messages::internalError(asyncResp->res);
2303 return;
2304 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002305
Ed Tanous002d39b2022-05-31 08:59:27 -07002306 if (!logEntries.empty())
2307 {
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002308 nlohmann::json::object_t hostLogEntry;
2309 fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry);
2310 asyncResp->res.jsonValue.update(hostLogEntry);
Ed Tanous002d39b2022-05-31 08:59:27 -07002311 return;
2312 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002313
Ed Tanous002d39b2022-05-31 08:59:27 -07002314 // Requested ID was not found
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08002315 messages::resourceNotFound(asyncResp->res, "LogEntry", param);
Patrick Williams5a39f772023-10-20 11:20:21 -05002316 });
Spencer Kub7028eb2021-10-26 15:27:35 +08002317}
2318
Claire Weinandd72e872022-08-15 14:20:06 -07002319inline void handleBMCLogServicesCollectionGet(
Claire Weinanfdd26902022-03-01 14:18:25 -08002320 crow::App& app, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002321 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2322 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002323{
2324 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2325 {
2326 return;
2327 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002328
2329 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2330 {
2331 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2332 return;
2333 }
2334
Claire Weinanfdd26902022-03-01 14:18:25 -08002335 // Collections don't include the static data added by SubRoute
2336 // because it has a duplicate entry for members
2337 asyncResp->res.jsonValue["@odata.type"] =
2338 "#LogServiceCollection.LogServiceCollection";
Ed Tanous253f11b2024-05-16 09:38:31 -07002339 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2340 "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -08002341 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
2342 asyncResp->res.jsonValue["Description"] =
2343 "Collection of LogServices for this Manager";
2344 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
2345 logServiceArray = nlohmann::json::array();
2346
Ed Tanous25b54db2024-04-17 15:40:31 -07002347 if constexpr (BMCWEB_REDFISH_BMC_JOURNAL)
2348 {
2349 nlohmann::json::object_t journal;
Ed Tanous253f11b2024-05-16 09:38:31 -07002350 journal["@odata.id"] =
2351 boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal",
2352 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07002353 logServiceArray.emplace_back(std::move(journal));
2354 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002355
2356 asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
2357
Ed Tanous25b54db2024-04-17 15:40:31 -07002358 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
2359 {
2360 constexpr std::array<std::string_view, 1> interfaces = {
2361 "xyz.openbmc_project.Collection.DeleteAll"};
2362 dbus::utility::getSubTreePaths(
2363 "/xyz/openbmc_project/dump", 0, interfaces,
2364 [asyncResp](const boost::system::error_code& ec,
2365 const dbus::utility::MapperGetSubTreePathsResponse&
2366 subTreePaths) {
2367 if (ec)
Claire Weinanfdd26902022-03-01 14:18:25 -08002368 {
Ed Tanous25b54db2024-04-17 15:40:31 -07002369 BMCWEB_LOG_ERROR(
2370 "handleBMCLogServicesCollectionGet respHandler got error {}",
2371 ec);
2372 // Assume that getting an error simply means there are no dump
2373 // LogServices. Return without adding any error response.
2374 return;
Claire Weinanfdd26902022-03-01 14:18:25 -08002375 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002376
Ed Tanous25b54db2024-04-17 15:40:31 -07002377 nlohmann::json& logServiceArrayLocal =
2378 asyncResp->res.jsonValue["Members"];
2379
2380 for (const std::string& path : subTreePaths)
2381 {
2382 if (path == "/xyz/openbmc_project/dump/bmc")
2383 {
2384 nlohmann::json::object_t member;
Ed Tanous253f11b2024-05-16 09:38:31 -07002385 member["@odata.id"] = boost::urls::format(
2386 "/redfish/v1/Managers/{}/LogServices/Dump",
2387 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07002388 logServiceArrayLocal.emplace_back(std::move(member));
2389 }
2390 else if (path == "/xyz/openbmc_project/dump/faultlog")
2391 {
2392 nlohmann::json::object_t member;
Ed Tanous253f11b2024-05-16 09:38:31 -07002393 member["@odata.id"] = boost::urls::format(
2394 "/redfish/v1/Managers/{}/LogServices/FaultLog",
2395 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07002396 logServiceArrayLocal.emplace_back(std::move(member));
2397 }
2398 }
2399
2400 asyncResp->res.jsonValue["Members@odata.count"] =
2401 logServiceArrayLocal.size();
2402 });
2403 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002404}
2405
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002406inline void requestRoutesBMCLogServiceCollection(App& app)
2407{
Ed Tanous253f11b2024-05-16 09:38:31 -07002408 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/")
Gunnar Millsad89dcf2021-07-30 14:40:11 -05002409 .privileges(redfish::privileges::getLogServiceCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002410 .methods(boost::beast::http::verb::get)(
Claire Weinandd72e872022-08-15 14:20:06 -07002411 std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002412}
Ed Tanous1da66f72018-07-27 16:13:37 -07002413
Claire Weinanfdd26902022-03-01 14:18:25 -08002414inline void
2415 getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2416 const std::string& dumpType)
2417{
2418 std::string dumpPath;
Ed Tanous539d8c62024-06-19 14:38:27 -07002419 log_service::OverWritePolicy overWritePolicy =
2420 log_service::OverWritePolicy::Invalid;
Claire Weinanfdd26902022-03-01 14:18:25 -08002421 bool collectDiagnosticDataSupported = false;
2422
2423 if (dumpType == "BMC")
2424 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002425 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump",
2426 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002427 overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
Claire Weinanfdd26902022-03-01 14:18:25 -08002428 collectDiagnosticDataSupported = true;
2429 }
2430 else if (dumpType == "FaultLog")
2431 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002432 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog",
2433 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002434 overWritePolicy = log_service::OverWritePolicy::Unknown;
Claire Weinanfdd26902022-03-01 14:18:25 -08002435 collectDiagnosticDataSupported = false;
2436 }
2437 else if (dumpType == "System")
2438 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002439 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump",
2440 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002441 overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
Claire Weinanfdd26902022-03-01 14:18:25 -08002442 collectDiagnosticDataSupported = true;
2443 }
2444 else
2445 {
Ed Tanous62598e32023-07-17 17:06:25 -07002446 BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}",
2447 dumpType);
Claire Weinanfdd26902022-03-01 14:18:25 -08002448 messages::internalError(asyncResp->res);
2449 return;
2450 }
2451
2452 asyncResp->res.jsonValue["@odata.id"] = dumpPath;
2453 asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService";
2454 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2455 asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService";
2456 asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename();
Ed Tanous539d8c62024-06-19 14:38:27 -07002457 asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy;
Claire Weinanfdd26902022-03-01 14:18:25 -08002458
2459 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002460 redfish::time_utils::getDateTimeOffsetNow();
Claire Weinanfdd26902022-03-01 14:18:25 -08002461 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2462 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2463 redfishDateTimeOffset.second;
2464
2465 asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries";
Claire Weinanfdd26902022-03-01 14:18:25 -08002466
2467 if (collectDiagnosticDataSupported)
2468 {
2469 asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2470 ["target"] =
2471 dumpPath + "/Actions/LogService.CollectDiagnosticData";
2472 }
Claire Weinan0d946212022-07-13 19:40:19 -07002473
2474 constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface};
2475 dbus::utility::getSubTreePaths(
2476 "/xyz/openbmc_project/dump", 0, interfaces,
2477 [asyncResp, dumpType, dumpPath](
2478 const boost::system::error_code& ec,
2479 const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
2480 if (ec)
2481 {
Ed Tanous62598e32023-07-17 17:06:25 -07002482 BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", ec);
Claire Weinan0d946212022-07-13 19:40:19 -07002483 // Assume that getting an error simply means there are no dump
2484 // LogServices. Return without adding any error response.
2485 return;
2486 }
Ed Tanous18f8f602023-07-18 10:07:23 -07002487 std::string dbusDumpPath = getDumpPath(dumpType);
Claire Weinan0d946212022-07-13 19:40:19 -07002488 for (const std::string& path : subTreePaths)
2489 {
2490 if (path == dbusDumpPath)
2491 {
2492 asyncResp->res
2493 .jsonValue["Actions"]["#LogService.ClearLog"]["target"] =
2494 dumpPath + "/Actions/LogService.ClearLog";
2495 break;
2496 }
2497 }
Patrick Williams5a39f772023-10-20 11:20:21 -05002498 });
Claire Weinanfdd26902022-03-01 14:18:25 -08002499}
2500
2501inline void handleLogServicesDumpServiceGet(
2502 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002503 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2504 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002505{
2506 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2507 {
2508 return;
2509 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002510
2511 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2512 {
2513 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2514 return;
2515 }
2516
Claire Weinanfdd26902022-03-01 14:18:25 -08002517 getDumpServiceInfo(asyncResp, dumpType);
2518}
2519
Ed Tanous22d268c2022-05-19 09:39:07 -07002520inline void handleLogServicesDumpServiceComputerSystemGet(
2521 crow::App& app, const crow::Request& req,
2522 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2523 const std::string& chassisId)
2524{
2525 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2526 {
2527 return;
2528 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002529 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002530 {
2531 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2532 return;
2533 }
2534 getDumpServiceInfo(asyncResp, "System");
2535}
2536
Claire Weinanfdd26902022-03-01 14:18:25 -08002537inline void handleLogServicesDumpEntriesCollectionGet(
2538 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002539 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2540 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002541{
2542 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2543 {
2544 return;
2545 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002546
2547 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2548 {
2549 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2550 return;
2551 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002552 getDumpEntryCollection(asyncResp, dumpType);
2553}
2554
Ed Tanous22d268c2022-05-19 09:39:07 -07002555inline void handleLogServicesDumpEntriesCollectionComputerSystemGet(
2556 crow::App& app, const crow::Request& req,
2557 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2558 const std::string& chassisId)
2559{
2560 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2561 {
2562 return;
2563 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002564 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002565 {
2566 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2567 return;
2568 }
2569 getDumpEntryCollection(asyncResp, "System");
2570}
2571
Claire Weinanfdd26902022-03-01 14:18:25 -08002572inline void handleLogServicesDumpEntryGet(
2573 crow::App& app, const std::string& dumpType, const crow::Request& req,
2574 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002575 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002576{
2577 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2578 {
2579 return;
2580 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002581 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2582 {
2583 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2584 return;
2585 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002586 getDumpEntryById(asyncResp, dumpId, dumpType);
2587}
Carson Labrado168d1b12023-03-27 17:04:46 +00002588
Ed Tanous22d268c2022-05-19 09:39:07 -07002589inline void handleLogServicesDumpEntryComputerSystemGet(
2590 crow::App& app, const crow::Request& req,
2591 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2592 const std::string& chassisId, const std::string& dumpId)
2593{
2594 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2595 {
2596 return;
2597 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002598 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002599 {
2600 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2601 return;
2602 }
2603 getDumpEntryById(asyncResp, dumpId, "System");
2604}
Claire Weinanfdd26902022-03-01 14:18:25 -08002605
2606inline void handleLogServicesDumpEntryDelete(
2607 crow::App& app, const std::string& dumpType, const crow::Request& req,
2608 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002609 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002610{
2611 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2612 {
2613 return;
2614 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002615
2616 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2617 {
2618 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2619 return;
2620 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002621 deleteDumpEntry(asyncResp, dumpId, dumpType);
2622}
2623
Ed Tanous22d268c2022-05-19 09:39:07 -07002624inline void handleLogServicesDumpEntryComputerSystemDelete(
2625 crow::App& app, const crow::Request& req,
2626 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2627 const std::string& chassisId, const std::string& dumpId)
2628{
2629 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2630 {
2631 return;
2632 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002633 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002634 {
2635 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2636 return;
2637 }
2638 deleteDumpEntry(asyncResp, dumpId, "System");
2639}
2640
Carson Labrado168d1b12023-03-27 17:04:46 +00002641inline void handleLogServicesDumpEntryDownloadGet(
2642 crow::App& app, const std::string& dumpType, const crow::Request& req,
2643 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002644 const std::string& managerId, const std::string& dumpId)
Carson Labrado168d1b12023-03-27 17:04:46 +00002645{
2646 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2647 {
2648 return;
2649 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002650
2651 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2652 {
2653 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2654 return;
2655 }
Carson Labrado168d1b12023-03-27 17:04:46 +00002656 downloadDumpEntry(asyncResp, dumpId, dumpType);
2657}
2658
2659inline void handleDBusEventLogEntryDownloadGet(
2660 crow::App& app, const std::string& dumpType, const crow::Request& req,
2661 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2662 const std::string& systemName, const std::string& entryID)
2663{
2664 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2665 {
2666 return;
2667 }
2668 if (!http_helpers::isContentTypeAllowed(
2669 req.getHeaderValue("Accept"),
2670 http_helpers::ContentType::OctetStream, true))
2671 {
2672 asyncResp->res.result(boost::beast::http::status::bad_request);
2673 return;
2674 }
2675 downloadEventLogEntry(asyncResp, systemName, entryID, dumpType);
2676}
2677
Claire Weinanfdd26902022-03-01 14:18:25 -08002678inline void handleLogServicesDumpCollectDiagnosticDataPost(
2679 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002680 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2681 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002682{
2683 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2684 {
2685 return;
2686 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002687 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2688 {
2689 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2690 return;
2691 }
2692
Claire Weinanfdd26902022-03-01 14:18:25 -08002693 createDump(asyncResp, req, dumpType);
2694}
2695
Ed Tanous22d268c2022-05-19 09:39:07 -07002696inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost(
2697 crow::App& app, const crow::Request& req,
2698 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002699 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002700{
2701 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2702 {
2703 return;
2704 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002705
Ed Tanous25b54db2024-04-17 15:40:31 -07002706 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002707 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002708 // Option currently returns no systems. TBD
2709 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2710 systemName);
2711 return;
2712 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002713 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002714 {
2715 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2716 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002717 return;
2718 }
2719 createDump(asyncResp, req, "System");
2720}
2721
Claire Weinanfdd26902022-03-01 14:18:25 -08002722inline void handleLogServicesDumpClearLogPost(
2723 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002724 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2725 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002726{
2727 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2728 {
2729 return;
2730 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002731
2732 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2733 {
2734 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2735 return;
2736 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002737 clearDump(asyncResp, dumpType);
2738}
2739
Ed Tanous22d268c2022-05-19 09:39:07 -07002740inline void handleLogServicesDumpClearLogComputerSystemPost(
2741 crow::App& app, const crow::Request& req,
2742 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002743 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002744{
2745 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2746 {
2747 return;
2748 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002749 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002750 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002751 // Option currently returns no systems. TBD
2752 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2753 systemName);
2754 return;
2755 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002756 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002757 {
2758 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2759 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002760 return;
2761 }
2762 clearDump(asyncResp, "System");
2763}
2764
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002765inline void requestRoutesBMCDumpService(App& app)
2766{
Ed Tanous253f11b2024-05-16 09:38:31 -07002767 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002768 .privileges(redfish::privileges::getLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002769 .methods(boost::beast::http::verb::get)(std::bind_front(
2770 handleLogServicesDumpServiceGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002771}
2772
2773inline void requestRoutesBMCDumpEntryCollection(App& app)
2774{
Ed Tanous253f11b2024-05-16 09:38:31 -07002775 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002776 .privileges(redfish::privileges::getLogEntryCollection)
Claire Weinanfdd26902022-03-01 14:18:25 -08002777 .methods(boost::beast::http::verb::get)(std::bind_front(
2778 handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002779}
2780
2781inline void requestRoutesBMCDumpEntry(App& app)
2782{
2783 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002784 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002785 .privileges(redfish::privileges::getLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002786 .methods(boost::beast::http::verb::get)(std::bind_front(
2787 handleLogServicesDumpEntryGet, std::ref(app), "BMC"));
2788
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002789 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002790 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002791 .privileges(redfish::privileges::deleteLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002792 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2793 handleLogServicesDumpEntryDelete, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002794}
2795
Carson Labrado168d1b12023-03-27 17:04:46 +00002796inline void requestRoutesBMCDumpEntryDownload(App& app)
2797{
2798 BMCWEB_ROUTE(
2799 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002800 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002801 .privileges(redfish::privileges::getLogEntry)
2802 .methods(boost::beast::http::verb::get)(std::bind_front(
2803 handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC"));
2804}
2805
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002806inline void requestRoutesBMCDumpCreate(App& app)
2807{
George Liu0fda0f12021-11-16 10:06:17 +08002808 BMCWEB_ROUTE(
2809 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002810 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002811 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002812 .methods(boost::beast::http::verb::post)(
Claire Weinanfdd26902022-03-01 14:18:25 -08002813 std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost,
2814 std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002815}
2816
2817inline void requestRoutesBMCDumpClear(App& app)
2818{
George Liu0fda0f12021-11-16 10:06:17 +08002819 BMCWEB_ROUTE(
2820 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002821 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002822 .privileges(redfish::privileges::postLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002823 .methods(boost::beast::http::verb::post)(std::bind_front(
2824 handleLogServicesDumpClearLogPost, std::ref(app), "BMC"));
2825}
2826
Carson Labrado168d1b12023-03-27 17:04:46 +00002827inline void requestRoutesDBusEventLogEntryDownload(App& app)
2828{
2829 BMCWEB_ROUTE(
2830 app,
Ravi Teja9e9d99d2023-11-08 05:33:59 -06002831 "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002832 .privileges(redfish::privileges::getLogEntry)
2833 .methods(boost::beast::http::verb::get)(std::bind_front(
2834 handleDBusEventLogEntryDownloadGet, std::ref(app), "System"));
2835}
2836
Claire Weinanfdd26902022-03-01 14:18:25 -08002837inline void requestRoutesFaultLogDumpService(App& app)
2838{
Ed Tanous253f11b2024-05-16 09:38:31 -07002839 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002840 .privileges(redfish::privileges::getLogService)
2841 .methods(boost::beast::http::verb::get)(std::bind_front(
2842 handleLogServicesDumpServiceGet, std::ref(app), "FaultLog"));
2843}
2844
2845inline void requestRoutesFaultLogDumpEntryCollection(App& app)
2846{
Ed Tanous253f11b2024-05-16 09:38:31 -07002847 BMCWEB_ROUTE(app,
2848 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002849 .privileges(redfish::privileges::getLogEntryCollection)
2850 .methods(boost::beast::http::verb::get)(
2851 std::bind_front(handleLogServicesDumpEntriesCollectionGet,
2852 std::ref(app), "FaultLog"));
2853}
2854
2855inline void requestRoutesFaultLogDumpEntry(App& app)
2856{
Ed Tanous253f11b2024-05-16 09:38:31 -07002857 BMCWEB_ROUTE(
2858 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002859 .privileges(redfish::privileges::getLogEntry)
2860 .methods(boost::beast::http::verb::get)(std::bind_front(
2861 handleLogServicesDumpEntryGet, std::ref(app), "FaultLog"));
2862
Ed Tanous253f11b2024-05-16 09:38:31 -07002863 BMCWEB_ROUTE(
2864 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002865 .privileges(redfish::privileges::deleteLogEntry)
2866 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2867 handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog"));
2868}
2869
2870inline void requestRoutesFaultLogDumpClear(App& app)
2871{
2872 BMCWEB_ROUTE(
2873 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002874 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002875 .privileges(redfish::privileges::postLogService)
2876 .methods(boost::beast::http::verb::post)(std::bind_front(
2877 handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002878}
2879
2880inline void requestRoutesSystemDumpService(App& app)
2881{
Ed Tanous22d268c2022-05-19 09:39:07 -07002882 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002883 .privileges(redfish::privileges::getLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002884 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002885 handleLogServicesDumpServiceComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002886}
2887
2888inline void requestRoutesSystemDumpEntryCollection(App& app)
2889{
Ed Tanous22d268c2022-05-19 09:39:07 -07002890 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002891 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous22d268c2022-05-19 09:39:07 -07002892 .methods(boost::beast::http::verb::get)(std::bind_front(
2893 handleLogServicesDumpEntriesCollectionComputerSystemGet,
2894 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002895}
2896
2897inline void requestRoutesSystemDumpEntry(App& app)
2898{
2899 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002900 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002901 .privileges(redfish::privileges::getLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002902 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002903 handleLogServicesDumpEntryComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002904
2905 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002906 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002907 .privileges(redfish::privileges::deleteLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002908 .methods(boost::beast::http::verb::delete_)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002909 handleLogServicesDumpEntryComputerSystemDelete, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002910}
2911
2912inline void requestRoutesSystemDumpCreate(App& app)
2913{
George Liu0fda0f12021-11-16 10:06:17 +08002914 BMCWEB_ROUTE(
2915 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002916 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002917 .privileges(redfish::privileges::postLogService)
Ed Tanous22d268c2022-05-19 09:39:07 -07002918 .methods(boost::beast::http::verb::post)(std::bind_front(
2919 handleLogServicesDumpCollectDiagnosticDataComputerSystemPost,
2920 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002921}
2922
2923inline void requestRoutesSystemDumpClear(App& app)
2924{
George Liu0fda0f12021-11-16 10:06:17 +08002925 BMCWEB_ROUTE(
2926 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002927 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002928 .privileges(redfish::privileges::postLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002929 .methods(boost::beast::http::verb::post)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002930 handleLogServicesDumpClearLogComputerSystemPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002931}
2932
2933inline void requestRoutesCrashdumpService(App& app)
2934{
2935 // Note: Deviated from redfish privilege registry for GET & HEAD
2936 // method for security reasons.
2937 /**
2938 * Functions triggers appropriate requests on DBus
2939 */
Ed Tanous22d268c2022-05-19 09:39:07 -07002940 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/")
Ed Tanoused398212021-06-09 17:05:54 -07002941 // This is incorrect, should be:
2942 //.privileges(redfish::privileges::getLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002943 .privileges({{"ConfigureManager"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07002944 .methods(boost::beast::http::verb::get)(
2945 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002946 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2947 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002948 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002949 {
2950 return;
2951 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002952 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002953 {
2954 // Option currently returns no systems. TBD
2955 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2956 systemName);
2957 return;
2958 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002959 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002960 {
2961 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2962 systemName);
2963 return;
2964 }
2965
Ed Tanous002d39b2022-05-31 08:59:27 -07002966 // Copy over the static data to include the entries added by
2967 // SubRoute
2968 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002969 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
2970 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002971 asyncResp->res.jsonValue["@odata.type"] =
2972 "#LogService.v1_2_0.LogService";
2973 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2974 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
V-Sanjana15b89722023-05-11 16:27:03 +05302975 asyncResp->res.jsonValue["Id"] = "Crashdump";
Ed Tanous539d8c62024-06-19 14:38:27 -07002976 asyncResp->res.jsonValue["OverWritePolicy"] =
2977 log_service::OverWritePolicy::WrapsWhenFull;
Ed Tanous002d39b2022-05-31 08:59:27 -07002978 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302979
Ed Tanous002d39b2022-05-31 08:59:27 -07002980 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002981 redfish::time_utils::getDateTimeOffsetNow();
Ed Tanous002d39b2022-05-31 08:59:27 -07002982 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2983 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2984 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302985
Ed Tanous002d39b2022-05-31 08:59:27 -07002986 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002987 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2988 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2989 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2990 ["target"] = std::format(
2991 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog",
2992 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002993 asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
Ed Tanous253f11b2024-05-16 09:38:31 -07002994 ["target"] = std::format(
2995 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData",
2996 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05002997 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002998}
2999
3000void inline requestRoutesCrashdumpClear(App& app)
3001{
George Liu0fda0f12021-11-16 10:06:17 +08003002 BMCWEB_ROUTE(
3003 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003004 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07003005 // This is incorrect, should be:
3006 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07003007 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003008 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003009 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003010 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3011 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003012 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003013 {
3014 return;
3015 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003016 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003017 {
3018 // Option currently returns no systems. TBD
3019 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3020 systemName);
3021 return;
3022 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003023 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003024 {
3025 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3026 systemName);
3027 return;
3028 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003029 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003030 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003031 const std::string&) {
3032 if (ec)
3033 {
3034 messages::internalError(asyncResp->res);
3035 return;
3036 }
3037 messages::success(asyncResp->res);
Patrick Williams5a39f772023-10-20 11:20:21 -05003038 },
Ed Tanous002d39b2022-05-31 08:59:27 -07003039 crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
Patrick Williams5a39f772023-10-20 11:20:21 -05003040 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003041}
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07003042
zhanghch058d1b46d2021-04-01 11:18:24 +08003043static void
3044 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3045 const std::string& logID, nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07003046{
Johnathan Mantey043a0532020-03-10 17:15:28 -07003047 auto getStoredLogCallback =
Ed Tanousb9d36b42022-02-26 21:42:46 -08003048 [asyncResp, logID,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003049 &logEntryJson](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08003050 const dbus::utility::DBusPropertiesMap& params) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003051 if (ec)
3052 {
Ed Tanous62598e32023-07-17 17:06:25 -07003053 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07003054 if (ec.value() ==
3055 boost::system::linux_error::bad_request_descriptor)
Jason M. Bills1ddcf012019-11-26 14:59:21 -08003056 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003057 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Jason M. Bills2b20ef62022-01-06 15:48:07 -08003058 }
3059 else
3060 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003061 messages::internalError(asyncResp->res);
Jason M. Bills2b20ef62022-01-06 15:48:07 -08003062 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003063 return;
3064 }
3065
3066 std::string timestamp{};
3067 std::string filename{};
3068 std::string logfile{};
3069 parseCrashdumpParameters(params, filename, timestamp, logfile);
3070
3071 if (filename.empty() || timestamp.empty())
3072 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003073 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003074 return;
3075 }
3076
3077 std::string crashdumpURI =
Ed Tanous253f11b2024-05-16 09:38:31 -07003078 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/",
3079 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous002d39b2022-05-31 08:59:27 -07003080 logID + "/" + filename;
Jason M. Bills84afc482022-06-24 12:38:23 -07003081 nlohmann::json::object_t logEntry;
Vijay Lobo9c11a172021-10-07 16:53:16 -05003082 logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07003083 logEntry["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07003084 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}",
3085 BMCWEB_REDFISH_SYSTEM_URI_NAME, logID);
Jason M. Bills84afc482022-06-24 12:38:23 -07003086 logEntry["Name"] = "CPU Crashdump";
3087 logEntry["Id"] = logID;
Ed Tanous539d8c62024-06-19 14:38:27 -07003088 logEntry["EntryType"] = log_entry::LogEntryType::Oem;
Jason M. Bills84afc482022-06-24 12:38:23 -07003089 logEntry["AdditionalDataURI"] = std::move(crashdumpURI);
3090 logEntry["DiagnosticDataType"] = "OEM";
3091 logEntry["OEMDiagnosticDataType"] = "PECICrashdump";
3092 logEntry["Created"] = std::move(timestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07003093
3094 // If logEntryJson references an array of LogEntry resources
3095 // ('Members' list), then push this as a new entry, otherwise set it
3096 // directly
3097 if (logEntryJson.is_array())
3098 {
3099 logEntryJson.push_back(logEntry);
3100 asyncResp->res.jsonValue["Members@odata.count"] =
3101 logEntryJson.size();
3102 }
3103 else
3104 {
Jason M. Billsd405bb52022-06-24 10:52:05 -07003105 logEntryJson.update(logEntry);
Ed Tanous002d39b2022-05-31 08:59:27 -07003106 }
3107 };
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02003108 sdbusplus::asio::getAllProperties(
3109 *crow::connections::systemBus, crashdumpObject,
3110 crashdumpPath + std::string("/") + logID, crashdumpInterface,
3111 std::move(getStoredLogCallback));
Jason M. Billse855dd22019-10-08 11:37:48 -07003112}
3113
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003114inline void requestRoutesCrashdumpEntryCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07003115{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003116 // Note: Deviated from redfish privilege registry for GET & HEAD
3117 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07003118 /**
3119 * Functions triggers appropriate requests on DBus
3120 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003121 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003122 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07003123 // This is incorrect, should be.
3124 //.privileges(redfish::privileges::postLogEntryCollection)
Ed Tanous432a8902021-06-14 15:28:56 -07003125 .privileges({{"ConfigureComponents"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07003126 .methods(boost::beast::http::verb::get)(
3127 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003128 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3129 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003130 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003131 {
3132 return;
3133 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003134 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003135 {
3136 // Option currently returns no systems. TBD
3137 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3138 systemName);
3139 return;
3140 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003141 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003142 {
3143 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3144 systemName);
3145 return;
3146 }
3147
George Liu7a1dbc42022-12-07 16:03:22 +08003148 constexpr std::array<std::string_view, 1> interfaces = {
3149 crashdumpInterface};
3150 dbus::utility::getSubTreePaths(
3151 "/", 0, interfaces,
3152 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003153 const std::vector<std::string>& resp) {
3154 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07003155 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003156 if (ec.value() !=
3157 boost::system::errc::no_such_file_or_directory)
3158 {
Ed Tanous62598e32023-07-17 17:06:25 -07003159 BMCWEB_LOG_DEBUG("failed to get entries ec: {}",
3160 ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07003161 messages::internalError(asyncResp->res);
3162 return;
3163 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07003164 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003165 asyncResp->res.jsonValue["@odata.type"] =
3166 "#LogEntryCollection.LogEntryCollection";
Ed Tanous253f11b2024-05-16 09:38:31 -07003167 asyncResp->res.jsonValue["@odata.id"] = std::format(
3168 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
3169 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07003170 asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
3171 asyncResp->res.jsonValue["Description"] =
3172 "Collection of Crashdump Entries";
3173 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3174 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Jason M. Bills2b20ef62022-01-06 15:48:07 -08003175
Ed Tanous002d39b2022-05-31 08:59:27 -07003176 for (const std::string& path : resp)
3177 {
3178 const sdbusplus::message::object_path objPath(path);
3179 // Get the log ID
3180 std::string logID = objPath.filename();
3181 if (logID.empty())
3182 {
3183 continue;
3184 }
3185 // Add the log entry to the array
3186 logCrashdumpEntry(asyncResp, logID,
3187 asyncResp->res.jsonValue["Members"]);
3188 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003189 });
Patrick Williams5a39f772023-10-20 11:20:21 -05003190 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003191}
Ed Tanous1da66f72018-07-27 16:13:37 -07003192
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003193inline void requestRoutesCrashdumpEntry(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07003194{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003195 // Note: Deviated from redfish privilege registry for GET & HEAD
3196 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07003197
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003198 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07003199 app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07003200 // this is incorrect, should be
3201 // .privileges(redfish::privileges::getLogEntry)
Ed Tanous432a8902021-06-14 15:28:56 -07003202 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003203 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003204 [&app](const crow::Request& req,
3205 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07003206 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003207 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003208 {
3209 return;
3210 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003211 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003212 {
3213 // Option currently returns no systems. TBD
3214 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3215 systemName);
3216 return;
3217 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003218 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003219 {
3220 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3221 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003222 return;
3223 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003224 const std::string& logID = param;
3225 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
Patrick Williams5a39f772023-10-20 11:20:21 -05003226 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003227}
Ed Tanous1da66f72018-07-27 16:13:37 -07003228
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003229inline void requestRoutesCrashdumpFile(App& app)
3230{
3231 // Note: Deviated from redfish privilege registry for GET & HEAD
3232 // method for security reasons.
3233 BMCWEB_ROUTE(
3234 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003235 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07003236 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003237 .methods(boost::beast::http::verb::get)(
Nan Zhoua4ce1142022-08-02 18:45:25 +00003238 [](const crow::Request& req,
3239 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07003240 const std::string& systemName, const std::string& logID,
3241 const std::string& fileName) {
Shounak Mitra2a9beee2022-07-20 18:41:30 +00003242 // Do not call getRedfishRoute here since the crashdump file is not a
3243 // Redfish resource.
Ed Tanous22d268c2022-05-19 09:39:07 -07003244
Ed Tanous25b54db2024-04-17 15:40:31 -07003245 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003246 {
3247 // Option currently returns no systems. TBD
3248 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3249 systemName);
3250 return;
3251 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003252 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003253 {
3254 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3255 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003256 return;
3257 }
3258
Ed Tanous002d39b2022-05-31 08:59:27 -07003259 auto getStoredLogCallback =
Ed Tanous39662a32023-02-06 15:09:46 -08003260 [asyncResp, logID, fileName, url(boost::urls::url(req.url()))](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003261 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003262 const std::vector<
3263 std::pair<std::string, dbus::utility::DbusVariantType>>&
3264 resp) {
3265 if (ec)
3266 {
Ed Tanous62598e32023-07-17 17:06:25 -07003267 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07003268 messages::internalError(asyncResp->res);
3269 return;
3270 }
Jason M. Bills8e6c0992021-03-11 16:26:53 -08003271
Ed Tanous002d39b2022-05-31 08:59:27 -07003272 std::string dbusFilename{};
3273 std::string dbusTimestamp{};
3274 std::string dbusFilepath{};
Jason M. Bills8e6c0992021-03-11 16:26:53 -08003275
Ed Tanous002d39b2022-05-31 08:59:27 -07003276 parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
3277 dbusFilepath);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003278
Ed Tanous002d39b2022-05-31 08:59:27 -07003279 if (dbusFilename.empty() || dbusTimestamp.empty() ||
3280 dbusFilepath.empty())
3281 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003282 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003283 return;
3284 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003285
Ed Tanous002d39b2022-05-31 08:59:27 -07003286 // Verify the file name parameter is correct
3287 if (fileName != dbusFilename)
3288 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003289 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003290 return;
3291 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003292
Ed Tanous27b0cf92023-08-07 12:02:40 -07003293 if (!asyncResp->res.openFile(dbusFilepath))
Ed Tanous002d39b2022-05-31 08:59:27 -07003294 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003295 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003296 return;
3297 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003298
Ed Tanous002d39b2022-05-31 08:59:27 -07003299 // Configure this to be a file download when accessed
3300 // from a browser
Ed Tanousd9f6c622022-03-17 09:12:17 -07003301 asyncResp->res.addHeader(
3302 boost::beast::http::field::content_disposition, "attachment");
Ed Tanous002d39b2022-05-31 08:59:27 -07003303 };
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02003304 sdbusplus::asio::getAllProperties(
3305 *crow::connections::systemBus, crashdumpObject,
3306 crashdumpPath + std::string("/") + logID, crashdumpInterface,
3307 std::move(getStoredLogCallback));
Patrick Williams5a39f772023-10-20 11:20:21 -05003308 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003309}
3310
Jason M. Billsc5a4c822022-01-06 15:51:23 -08003311enum class OEMDiagnosticType
3312{
3313 onDemand,
3314 telemetry,
3315 invalid,
3316};
3317
Ed Tanous26ccae32023-02-16 10:28:44 -08003318inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr)
Jason M. Billsc5a4c822022-01-06 15:51:23 -08003319{
3320 if (oemDiagStr == "OnDemand")
3321 {
3322 return OEMDiagnosticType::onDemand;
3323 }
3324 if (oemDiagStr == "Telemetry")
3325 {
3326 return OEMDiagnosticType::telemetry;
3327 }
3328
3329 return OEMDiagnosticType::invalid;
3330}
3331
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003332inline void requestRoutesCrashdumpCollect(App& app)
3333{
3334 // Note: Deviated from redfish privilege registry for GET & HEAD
3335 // method for security reasons.
George Liu0fda0f12021-11-16 10:06:17 +08003336 BMCWEB_ROUTE(
3337 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003338 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07003339 // The below is incorrect; Should be ConfigureManager
3340 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07003341 .privileges({{"ConfigureComponents"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07003342 .methods(boost::beast::http::verb::post)(
3343 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003344 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3345 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003346 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003347 {
3348 return;
3349 }
Ed Tanous22d268c2022-05-19 09:39:07 -07003350
Ed Tanous25b54db2024-04-17 15:40:31 -07003351 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003352 {
3353 // Option currently returns no systems. TBD
3354 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3355 systemName);
3356 return;
3357 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003358 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003359 {
3360 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3361 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003362 return;
3363 }
3364
Ed Tanous002d39b2022-05-31 08:59:27 -07003365 std::string diagnosticDataType;
3366 std::string oemDiagnosticDataType;
3367 if (!redfish::json_util::readJsonAction(
3368 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
3369 "OEMDiagnosticDataType", oemDiagnosticDataType))
3370 {
3371 return;
3372 }
3373
3374 if (diagnosticDataType != "OEM")
3375 {
Ed Tanous62598e32023-07-17 17:06:25 -07003376 BMCWEB_LOG_ERROR(
3377 "Only OEM DiagnosticDataType supported for Crashdump");
Ed Tanous002d39b2022-05-31 08:59:27 -07003378 messages::actionParameterValueFormatError(
3379 asyncResp->res, diagnosticDataType, "DiagnosticDataType",
3380 "CollectDiagnosticData");
3381 return;
3382 }
3383
3384 OEMDiagnosticType oemDiagType =
3385 getOEMDiagnosticType(oemDiagnosticDataType);
3386
3387 std::string iface;
3388 std::string method;
3389 std::string taskMatchStr;
3390 if (oemDiagType == OEMDiagnosticType::onDemand)
3391 {
3392 iface = crashdumpOnDemandInterface;
3393 method = "GenerateOnDemandLog";
3394 taskMatchStr = "type='signal',"
3395 "interface='org.freedesktop.DBus.Properties',"
3396 "member='PropertiesChanged',"
3397 "arg0namespace='com.intel.crashdump'";
3398 }
3399 else if (oemDiagType == OEMDiagnosticType::telemetry)
3400 {
3401 iface = crashdumpTelemetryInterface;
3402 method = "GenerateTelemetryLog";
3403 taskMatchStr = "type='signal',"
3404 "interface='org.freedesktop.DBus.Properties',"
3405 "member='PropertiesChanged',"
3406 "arg0namespace='com.intel.crashdump'";
3407 }
3408 else
3409 {
Ed Tanous62598e32023-07-17 17:06:25 -07003410 BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}",
3411 oemDiagnosticDataType);
Ed Tanous002d39b2022-05-31 08:59:27 -07003412 messages::actionParameterValueFormatError(
3413 asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType",
3414 "CollectDiagnosticData");
3415 return;
3416 }
3417
3418 auto collectCrashdumpCallback =
3419 [asyncResp, payload(task::Payload(req)),
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003420 taskMatchStr](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003421 const std::string&) mutable {
3422 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07003423 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003424 if (ec.value() == boost::system::errc::operation_not_supported)
3425 {
3426 messages::resourceInStandby(asyncResp->res);
3427 }
3428 else if (ec.value() ==
3429 boost::system::errc::device_or_resource_busy)
3430 {
3431 messages::serviceTemporarilyUnavailable(asyncResp->res,
3432 "60");
3433 }
3434 else
3435 {
3436 messages::internalError(asyncResp->res);
3437 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07003438 return;
3439 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003440 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Ed Tanous8b242752023-06-27 17:17:13 -07003441 [](const boost::system::error_code& ec2, sdbusplus::message_t&,
Ed Tanous002d39b2022-05-31 08:59:27 -07003442 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanous8b242752023-06-27 17:17:13 -07003443 if (!ec2)
Ed Tanous002d39b2022-05-31 08:59:27 -07003444 {
3445 taskData->messages.emplace_back(messages::taskCompletedOK(
3446 std::to_string(taskData->index)));
3447 taskData->state = "Completed";
3448 }
3449 return task::completed;
Patrick Williams5a39f772023-10-20 11:20:21 -05003450 },
Ed Tanous002d39b2022-05-31 08:59:27 -07003451 taskMatchStr);
Ed Tanous1da66f72018-07-27 16:13:37 -07003452
Ed Tanous002d39b2022-05-31 08:59:27 -07003453 task->startTimer(std::chrono::minutes(5));
3454 task->populateResp(asyncResp->res);
3455 task->payload.emplace(std::move(payload));
3456 };
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003457
Ed Tanous002d39b2022-05-31 08:59:27 -07003458 crow::connections::systemBus->async_method_call(
3459 std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath,
3460 iface, method);
Patrick Williams5a39f772023-10-20 11:20:21 -05003461 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003462}
Kenny L. Ku6eda7682020-06-19 09:48:36 -07003463
Alexander Hansen599b9af2024-08-06 15:11:57 +02003464inline void dBusLogServiceActionsClear(
3465 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
3466{
3467 BMCWEB_LOG_DEBUG("Do delete all entries.");
3468
3469 // Process response from Logging service.
3470 auto respHandler = [asyncResp](const boost::system::error_code& ec) {
3471 BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done");
3472 if (ec)
3473 {
3474 // TODO Handle for specific error code
3475 BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec);
3476 asyncResp->res.result(
3477 boost::beast::http::status::internal_server_error);
3478 return;
3479 }
3480
3481 asyncResp->res.result(boost::beast::http::status::no_content);
3482 };
3483
3484 // Make call to Logging service to request Clear Log
3485 crow::connections::systemBus->async_method_call(
3486 respHandler, "xyz.openbmc_project.Logging",
3487 "/xyz/openbmc_project/logging",
3488 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3489}
3490
Andrew Geisslercb92c032018-08-17 07:56:14 -07003491/**
3492 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3493 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003494inline void requestRoutesDBusLogServiceActionsClear(App& app)
Andrew Geisslercb92c032018-08-17 07:56:14 -07003495{
Andrew Geisslercb92c032018-08-17 07:56:14 -07003496 /**
3497 * Function handles POST method request.
3498 * The Clear Log actions does not require any parameter.The action deletes
3499 * all entries found in the Entries collection for this Log Service.
3500 */
Andrew Geisslercb92c032018-08-17 07:56:14 -07003501
George Liu0fda0f12021-11-16 10:06:17 +08003502 BMCWEB_ROUTE(
3503 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003504 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07003505 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003506 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003507 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003508 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3509 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003510 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003511 {
3512 return;
3513 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003514 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003515 {
3516 // Option currently returns no systems. TBD
3517 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3518 systemName);
3519 return;
3520 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003521 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003522 {
3523 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3524 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003525 return;
3526 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02003527 dBusLogServiceActionsClear(asyncResp);
Patrick Williams5a39f772023-10-20 11:20:21 -05003528 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003529}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003530
3531/****************************************************
3532 * Redfish PostCode interfaces
3533 * using DBUS interface: getPostCodesTS
3534 ******************************************************/
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003535inline void requestRoutesPostCodesLogService(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003536{
Ed Tanous22d268c2022-05-19 09:39:07 -07003537 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/")
Ed Tanoused398212021-06-09 17:05:54 -07003538 .privileges(redfish::privileges::getLogService)
Ed Tanous002d39b2022-05-31 08:59:27 -07003539 .methods(boost::beast::http::verb::get)(
3540 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003541 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3542 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003543 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003544 {
3545 return;
3546 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003547 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003548 {
3549 // Option currently returns no systems. TBD
3550 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3551 systemName);
3552 return;
3553 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003554 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003555 {
3556 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3557 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003558 return;
3559 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003560 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003561 std::format("/redfish/v1/Systems/{}/LogServices/PostCodes",
3562 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07003563 asyncResp->res.jsonValue["@odata.type"] =
Janet Adkinsb25644a2023-08-16 11:23:45 -05003564 "#LogService.v1_2_0.LogService";
Ed Tanous002d39b2022-05-31 08:59:27 -07003565 asyncResp->res.jsonValue["Name"] = "POST Code Log Service";
3566 asyncResp->res.jsonValue["Description"] = "POST Code Log Service";
Ed Tanoused34a4a2023-02-08 15:43:27 -08003567 asyncResp->res.jsonValue["Id"] = "PostCodes";
Ed Tanous539d8c62024-06-19 14:38:27 -07003568 asyncResp->res.jsonValue["OverWritePolicy"] =
3569 log_service::OverWritePolicy::WrapsWhenFull;
Ed Tanous002d39b2022-05-31 08:59:27 -07003570 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003571 std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries",
3572 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Tejas Patil7c8c4052021-06-04 17:43:14 +05303573
Ed Tanous002d39b2022-05-31 08:59:27 -07003574 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07003575 redfish::time_utils::getDateTimeOffsetNow();
Ed Tanous002d39b2022-05-31 08:59:27 -07003576 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
3577 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
3578 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05303579
Ed Tanous20fa6a22024-05-20 18:02:58 -07003580 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
3581 ["target"] = std::format(
3582 "/redfish/v1/Systems/{}/LogServices/PostCodes/Actions/LogService.ClearLog",
3583 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05003584 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003585}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003586
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003587inline void requestRoutesPostCodesClear(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003588{
George Liu0fda0f12021-11-16 10:06:17 +08003589 BMCWEB_ROUTE(
3590 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003591 "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07003592 // The following privilege is incorrect; It should be ConfigureManager
3593 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07003594 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003595 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003596 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003597 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3598 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003599 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003600 {
3601 return;
3602 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003603 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003604 {
3605 // Option currently returns no systems. TBD
3606 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3607 systemName);
3608 return;
3609 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003610 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003611 {
3612 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3613 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003614 return;
3615 }
Ed Tanous62598e32023-07-17 17:06:25 -07003616 BMCWEB_LOG_DEBUG("Do delete all postcodes entries.");
ZhikuiRena3316fc2020-01-29 14:58:08 -08003617
Ed Tanous002d39b2022-05-31 08:59:27 -07003618 // Make call to post-code service to request clear all
3619 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003620 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003621 if (ec)
3622 {
3623 // TODO Handle for specific error code
Ed Tanous62598e32023-07-17 17:06:25 -07003624 BMCWEB_LOG_ERROR("doClearPostCodes resp_handler got error {}",
3625 ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07003626 asyncResp->res.result(
3627 boost::beast::http::status::internal_server_error);
3628 messages::internalError(asyncResp->res);
3629 return;
3630 }
Tony Lee18fc70c2023-08-24 16:15:54 +08003631 messages::success(asyncResp->res);
Patrick Williams5a39f772023-10-20 11:20:21 -05003632 },
Ed Tanous002d39b2022-05-31 08:59:27 -07003633 "xyz.openbmc_project.State.Boot.PostCode0",
3634 "/xyz/openbmc_project/State/Boot/PostCode0",
3635 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Patrick Williams5a39f772023-10-20 11:20:21 -05003636 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003637}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003638
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003639/**
3640 * @brief Parse post code ID and get the current value and index value
3641 * eg: postCodeID=B1-2, currentValue=1, index=2
3642 *
3643 * @param[in] postCodeID Post Code ID
3644 * @param[out] currentValue Current value
3645 * @param[out] index Index value
3646 *
3647 * @return bool true if the parsing is successful, false the parsing fails
3648 */
Ed Tanous6f056f22024-04-07 13:35:51 -07003649inline bool parsePostCode(std::string_view postCodeID, uint64_t& currentValue,
Ed Tanousdf254f22024-04-01 13:25:46 -07003650 uint16_t& index)
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003651{
3652 std::vector<std::string> split;
Ed Tanous50ebd4a2023-01-19 19:03:17 -08003653 bmcweb::split(split, postCodeID, '-');
Ed Tanous6f056f22024-04-07 13:35:51 -07003654 if (split.size() != 2)
3655 {
3656 return false;
3657 }
3658 std::string_view postCodeNumber = split[0];
3659 if (postCodeNumber.size() < 2)
3660 {
3661 return false;
3662 }
3663 if (postCodeNumber[0] != 'B')
3664 {
3665 return false;
3666 }
3667 postCodeNumber.remove_prefix(1);
3668 auto [ptrIndex, ecIndex] = std::from_chars(postCodeNumber.begin(),
3669 postCodeNumber.end(), index);
3670 if (ptrIndex != postCodeNumber.end() || ecIndex != std::errc())
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003671 {
3672 return false;
3673 }
3674
Ed Tanous6f056f22024-04-07 13:35:51 -07003675 std::string_view postCodeIndex = split[1];
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003676
Ed Tanous6f056f22024-04-07 13:35:51 -07003677 auto [ptrValue, ecValue] = std::from_chars(
3678 postCodeIndex.begin(), postCodeIndex.end(), currentValue);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003679
Ed Tanous6f056f22024-04-07 13:35:51 -07003680 return ptrValue == postCodeIndex.end() && ecValue == std::errc();
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003681}
3682
3683static bool fillPostCodeEntry(
Ed Tanousac106bf2023-06-07 09:24:59 -07003684 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303685 const boost::container::flat_map<
3686 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003687 const uint16_t bootIndex, const uint64_t codeIndex = 0,
3688 const uint64_t skip = 0, const uint64_t top = 0)
3689{
3690 // Get the Message from the MessageRegistry
Ed Tanousfffb8c12022-02-07 23:53:03 -08003691 const registries::Message* message =
3692 registries::getMessage("OpenBMC.0.2.BIOSPOSTCode");
Ed Tanousdc8cfa62024-04-07 13:37:25 -07003693 if (message == nullptr)
3694 {
3695 BMCWEB_LOG_ERROR("Couldn't find known message?");
3696 return false;
3697 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003698 uint64_t currentCodeIndex = 0;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003699 uint64_t firstCodeTimeUs = 0;
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303700 for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3701 code : postcode)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003702 {
3703 currentCodeIndex++;
3704 std::string postcodeEntryID =
3705 "B" + std::to_string(bootIndex) + "-" +
3706 std::to_string(currentCodeIndex); // 1 based index in EntryID string
3707
3708 uint64_t usecSinceEpoch = code.first;
3709 uint64_t usTimeOffset = 0;
3710
3711 if (1 == currentCodeIndex)
3712 { // already incremented
3713 firstCodeTimeUs = code.first;
3714 }
3715 else
3716 {
3717 usTimeOffset = code.first - firstCodeTimeUs;
3718 }
3719
3720 // skip if no specific codeIndex is specified and currentCodeIndex does
3721 // not fall between top and skip
3722 if ((codeIndex == 0) &&
3723 (currentCodeIndex <= skip || currentCodeIndex > top))
3724 {
3725 continue;
3726 }
3727
Gunnar Mills4e0453b2020-07-08 14:00:30 -05003728 // skip if a specific codeIndex is specified and does not match the
ZhikuiRena3316fc2020-01-29 14:58:08 -08003729 // currentIndex
3730 if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3731 {
3732 // This is done for simplicity. 1st entry is needed to calculate
3733 // time offset. To improve efficiency, one can get to the entry
3734 // directly (possibly with flatmap's nth method)
3735 continue;
3736 }
3737
3738 // currentCodeIndex is within top and skip or equal to specified code
3739 // index
3740
3741 // Get the Created time from the timestamp
3742 std::string entryTimeStr;
Konstantin Aladyshev2a025612023-02-15 11:52:58 +03003743 entryTimeStr = redfish::time_utils::getDateTimeUintUs(usecSinceEpoch);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003744
3745 // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3746 std::ostringstream hexCode;
3747 hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303748 << std::get<0>(code.second);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003749 std::ostringstream timeOffsetStr;
3750 // Set Fixed -Point Notation
3751 timeOffsetStr << std::fixed;
3752 // Set precision to 4 digits
3753 timeOffsetStr << std::setprecision(4);
3754 // Add double to stream
3755 timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003756
Ed Tanous1e6deaf2022-02-17 11:32:37 -08003757 std::string bootIndexStr = std::to_string(bootIndex);
3758 std::string timeOffsetString = timeOffsetStr.str();
3759 std::string hexCodeStr = hexCode.str();
3760
3761 std::array<std::string_view, 3> messageArgs = {
3762 bootIndexStr, timeOffsetString, hexCodeStr};
3763
3764 std::string msg =
3765 redfish::registries::fillMessageArgs(messageArgs, message->message);
3766 if (msg.empty())
ZhikuiRena3316fc2020-01-29 14:58:08 -08003767 {
Ed Tanous1e6deaf2022-02-17 11:32:37 -08003768 messages::internalError(asyncResp->res);
3769 return false;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003770 }
3771
Tim Leed4342a92020-04-27 11:47:58 +08003772 // Get Severity template from message registry
3773 std::string severity;
3774 if (message != nullptr)
3775 {
Ed Tanous5f2b84e2022-02-08 00:41:53 -08003776 severity = message->messageSeverity;
Tim Leed4342a92020-04-27 11:47:58 +08003777 }
3778
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003779 // Format entry
3780 nlohmann::json::object_t bmcLogEntry;
Vijay Lobo9c11a172021-10-07 16:53:16 -05003781 bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07003782 bmcLogEntry["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07003783 "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/{}",
3784 BMCWEB_REDFISH_SYSTEM_URI_NAME, postcodeEntryID);
Jason M. Bills84afc482022-06-24 12:38:23 -07003785 bmcLogEntry["Name"] = "POST Code Log Entry";
3786 bmcLogEntry["Id"] = postcodeEntryID;
3787 bmcLogEntry["Message"] = std::move(msg);
3788 bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode";
Ed Tanous1e6deaf2022-02-17 11:32:37 -08003789 bmcLogEntry["MessageArgs"] = messageArgs;
Jason M. Bills84afc482022-06-24 12:38:23 -07003790 bmcLogEntry["EntryType"] = "Event";
3791 bmcLogEntry["Severity"] = std::move(severity);
3792 bmcLogEntry["Created"] = entryTimeStr;
George Liu647b3cd2021-07-05 12:43:56 +08003793 if (!std::get<std::vector<uint8_t>>(code.second).empty())
3794 {
3795 bmcLogEntry["AdditionalDataURI"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003796 std::format(
3797 "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/",
3798 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
George Liu647b3cd2021-07-05 12:43:56 +08003799 postcodeEntryID + "/attachment";
3800 }
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003801
3802 // codeIndex is only specified when querying single entry, return only
3803 // that entry in this case
3804 if (codeIndex != 0)
3805 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003806 asyncResp->res.jsonValue.update(bmcLogEntry);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003807 return true;
3808 }
3809
Ed Tanousac106bf2023-06-07 09:24:59 -07003810 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Patrick Williamsb2ba3072023-05-12 10:27:39 -05003811 logEntryArray.emplace_back(std::move(bmcLogEntry));
ZhikuiRena3316fc2020-01-29 14:58:08 -08003812 }
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003813
3814 // Return value is always false when querying multiple entries
3815 return false;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003816}
3817
Ed Tanousac106bf2023-06-07 09:24:59 -07003818static void
3819 getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3820 const std::string& entryId)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003821{
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003822 uint16_t bootIndex = 0;
3823 uint64_t codeIndex = 0;
3824 if (!parsePostCode(entryId, codeIndex, bootIndex))
3825 {
3826 // Requested ID was not found
Ed Tanousac106bf2023-06-07 09:24:59 -07003827 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003828 return;
3829 }
3830
3831 if (bootIndex == 0 || codeIndex == 0)
3832 {
3833 // 0 is an invalid index
Ed Tanousac106bf2023-06-07 09:24:59 -07003834 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003835 return;
3836 }
3837
ZhikuiRena3316fc2020-01-29 14:58:08 -08003838 crow::connections::systemBus->async_method_call(
Ed Tanousac106bf2023-06-07 09:24:59 -07003839 [asyncResp, entryId, bootIndex,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003840 codeIndex](const boost::system::error_code& ec,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303841 const boost::container::flat_map<
3842 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3843 postcode) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003844 if (ec)
3845 {
Ed Tanous62598e32023-07-17 17:06:25 -07003846 BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error");
Ed Tanousac106bf2023-06-07 09:24:59 -07003847 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -07003848 return;
3849 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003850
Ed Tanous002d39b2022-05-31 08:59:27 -07003851 if (postcode.empty())
3852 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003853 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Ed Tanous002d39b2022-05-31 08:59:27 -07003854 return;
3855 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003856
Ed Tanousac106bf2023-06-07 09:24:59 -07003857 if (!fillPostCodeEntry(asyncResp, postcode, bootIndex, codeIndex))
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003858 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003859 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003860 return;
3861 }
Patrick Williams5a39f772023-10-20 11:20:21 -05003862 },
Jonathan Doman15124762021-01-07 17:54:17 -08003863 "xyz.openbmc_project.State.Boot.PostCode0",
3864 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003865 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3866 bootIndex);
3867}
3868
Ed Tanousac106bf2023-06-07 09:24:59 -07003869static void
3870 getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3871 const uint16_t bootIndex, const uint16_t bootCount,
3872 const uint64_t entryCount, size_t skip, size_t top)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003873{
3874 crow::connections::systemBus->async_method_call(
Ed Tanousac106bf2023-06-07 09:24:59 -07003875 [asyncResp, bootIndex, bootCount, entryCount, skip,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003876 top](const boost::system::error_code& ec,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303877 const boost::container::flat_map<
3878 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3879 postcode) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003880 if (ec)
3881 {
Ed Tanous62598e32023-07-17 17:06:25 -07003882 BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error");
Ed Tanousac106bf2023-06-07 09:24:59 -07003883 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -07003884 return;
3885 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003886
Ed Tanous002d39b2022-05-31 08:59:27 -07003887 uint64_t endCount = entryCount;
3888 if (!postcode.empty())
3889 {
3890 endCount = entryCount + postcode.size();
Ed Tanous3648c8b2022-07-25 13:39:59 -07003891 if (skip < endCount && (top + skip) > entryCount)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003892 {
Patrick Williams89492a12023-05-10 07:51:34 -05003893 uint64_t thisBootSkip = std::max(static_cast<uint64_t>(skip),
3894 entryCount) -
3895 entryCount;
Ed Tanous002d39b2022-05-31 08:59:27 -07003896 uint64_t thisBootTop =
Ed Tanous3648c8b2022-07-25 13:39:59 -07003897 std::min(static_cast<uint64_t>(top + skip), endCount) -
3898 entryCount;
Ed Tanous002d39b2022-05-31 08:59:27 -07003899
Ed Tanousac106bf2023-06-07 09:24:59 -07003900 fillPostCodeEntry(asyncResp, postcode, bootIndex, 0,
3901 thisBootSkip, thisBootTop);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003902 }
Ed Tanousac106bf2023-06-07 09:24:59 -07003903 asyncResp->res.jsonValue["Members@odata.count"] = endCount;
Ed Tanous002d39b2022-05-31 08:59:27 -07003904 }
3905
3906 // continue to previous bootIndex
3907 if (bootIndex < bootCount)
3908 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003909 getPostCodeForBoot(asyncResp, static_cast<uint16_t>(bootIndex + 1),
Ed Tanous002d39b2022-05-31 08:59:27 -07003910 bootCount, endCount, skip, top);
3911 }
Jiaqing Zhao81584ab2022-07-28 00:33:45 +08003912 else if (skip + top < endCount)
Ed Tanous002d39b2022-05-31 08:59:27 -07003913 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003914 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003915 std::format(
3916 "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries?$skip=",
3917 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous002d39b2022-05-31 08:59:27 -07003918 std::to_string(skip + top);
3919 }
Patrick Williams5a39f772023-10-20 11:20:21 -05003920 },
Jonathan Doman15124762021-01-07 17:54:17 -08003921 "xyz.openbmc_project.State.Boot.PostCode0",
3922 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003923 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3924 bootIndex);
3925}
3926
zhanghch058d1b46d2021-04-01 11:18:24 +08003927static void
Ed Tanousac106bf2023-06-07 09:24:59 -07003928 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous3648c8b2022-07-25 13:39:59 -07003929 size_t skip, size_t top)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003930{
3931 uint64_t entryCount = 0;
Jonathan Doman1e1e5982021-06-11 09:36:17 -07003932 sdbusplus::asio::getProperty<uint16_t>(
3933 *crow::connections::systemBus,
3934 "xyz.openbmc_project.State.Boot.PostCode0",
3935 "/xyz/openbmc_project/State/Boot/PostCode0",
3936 "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount",
Ed Tanousac106bf2023-06-07 09:24:59 -07003937 [asyncResp, entryCount, skip, top](const boost::system::error_code& ec,
3938 const uint16_t bootCount) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003939 if (ec)
3940 {
Ed Tanous62598e32023-07-17 17:06:25 -07003941 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
Ed Tanousac106bf2023-06-07 09:24:59 -07003942 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -07003943 return;
3944 }
Ed Tanousac106bf2023-06-07 09:24:59 -07003945 getPostCodeForBoot(asyncResp, 1, bootCount, entryCount, skip, top);
Patrick Williams5a39f772023-10-20 11:20:21 -05003946 });
ZhikuiRena3316fc2020-01-29 14:58:08 -08003947}
3948
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003949inline void requestRoutesPostCodesEntryCollection(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003950{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003951 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003952 "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07003953 .privileges(redfish::privileges::getLogEntryCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003954 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003955 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003956 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3957 const std::string& systemName) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003958 query_param::QueryCapabilities capabilities = {
3959 .canDelegateTop = true,
3960 .canDelegateSkip = true,
3961 };
3962 query_param::Query delegatedQuery;
3963 if (!redfish::setUpRedfishRouteWithDelegation(
Carson Labrado3ba00072022-06-06 19:40:56 +00003964 app, req, asyncResp, delegatedQuery, capabilities))
Ed Tanous002d39b2022-05-31 08:59:27 -07003965 {
3966 return;
3967 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003968 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003969 {
3970 // Option currently returns no systems. TBD
3971 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3972 systemName);
3973 return;
3974 }
Ed Tanous22d268c2022-05-19 09:39:07 -07003975
Ed Tanous253f11b2024-05-16 09:38:31 -07003976 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003977 {
3978 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3979 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003980 return;
3981 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003982 asyncResp->res.jsonValue["@odata.type"] =
3983 "#LogEntryCollection.LogEntryCollection";
3984 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003985 std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries",
3986 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07003987 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3988 asyncResp->res.jsonValue["Description"] =
3989 "Collection of POST Code Log Entries";
3990 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3991 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Ed Tanous3648c8b2022-07-25 13:39:59 -07003992 size_t skip = delegatedQuery.skip.value_or(0);
Jiaqing Zhao5143f7a2022-07-22 09:33:33 +08003993 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
Ed Tanous3648c8b2022-07-25 13:39:59 -07003994 getCurrentBootNumber(asyncResp, skip, top);
Patrick Williams5a39f772023-10-20 11:20:21 -05003995 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003996}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003997
George Liu647b3cd2021-07-05 12:43:56 +08003998inline void requestRoutesPostCodesEntryAdditionalData(App& app)
3999{
George Liu0fda0f12021-11-16 10:06:17 +08004000 BMCWEB_ROUTE(
4001 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07004002 "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/")
George Liu647b3cd2021-07-05 12:43:56 +08004003 .privileges(redfish::privileges::getLogEntry)
4004 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07004005 [&app](const crow::Request& req,
4006 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07004007 const std::string& systemName,
Ed Tanous45ca1b82022-03-25 13:07:27 -07004008 const std::string& postCodeID) {
Carson Labrado3ba00072022-06-06 19:40:56 +00004009 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07004010 {
4011 return;
4012 }
Matt Spinler72e21372023-04-19 12:53:33 -05004013 if (!http_helpers::isContentTypeAllowed(
Ed Tanous99351cd2022-08-07 16:42:51 -07004014 req.getHeaderValue("Accept"),
Ed Tanous4a0e1a02022-09-21 15:28:04 -07004015 http_helpers::ContentType::OctetStream, true))
Ed Tanous002d39b2022-05-31 08:59:27 -07004016 {
4017 asyncResp->res.result(boost::beast::http::status::bad_request);
4018 return;
4019 }
Ed Tanous25b54db2024-04-17 15:40:31 -07004020 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08004021 {
4022 // Option currently returns no systems. TBD
4023 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
4024 systemName);
4025 return;
4026 }
Ed Tanous253f11b2024-05-16 09:38:31 -07004027 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07004028 {
4029 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
4030 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07004031 return;
4032 }
George Liu647b3cd2021-07-05 12:43:56 +08004033
Ed Tanous002d39b2022-05-31 08:59:27 -07004034 uint64_t currentValue = 0;
4035 uint16_t index = 0;
4036 if (!parsePostCode(postCodeID, currentValue, index))
4037 {
4038 messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID);
4039 return;
4040 }
George Liu647b3cd2021-07-05 12:43:56 +08004041
Ed Tanous002d39b2022-05-31 08:59:27 -07004042 crow::connections::systemBus->async_method_call(
4043 [asyncResp, postCodeID, currentValue](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08004044 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07004045 const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>&
4046 postcodes) {
4047 if (ec.value() == EBADR)
4048 {
4049 messages::resourceNotFound(asyncResp->res, "LogEntry",
4050 postCodeID);
4051 return;
4052 }
4053 if (ec)
4054 {
Ed Tanous62598e32023-07-17 17:06:25 -07004055 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07004056 messages::internalError(asyncResp->res);
4057 return;
4058 }
George Liu647b3cd2021-07-05 12:43:56 +08004059
Ed Tanous002d39b2022-05-31 08:59:27 -07004060 size_t value = static_cast<size_t>(currentValue) - 1;
4061 if (value == std::string::npos || postcodes.size() < currentValue)
4062 {
Ed Tanous62598e32023-07-17 17:06:25 -07004063 BMCWEB_LOG_WARNING("Wrong currentValue value");
Ed Tanous002d39b2022-05-31 08:59:27 -07004064 messages::resourceNotFound(asyncResp->res, "LogEntry",
4065 postCodeID);
4066 return;
4067 }
George Liu647b3cd2021-07-05 12:43:56 +08004068
Ed Tanous002d39b2022-05-31 08:59:27 -07004069 const auto& [tID, c] = postcodes[value];
4070 if (c.empty())
4071 {
Ed Tanous62598e32023-07-17 17:06:25 -07004072 BMCWEB_LOG_WARNING("No found post code data");
Ed Tanous002d39b2022-05-31 08:59:27 -07004073 messages::resourceNotFound(asyncResp->res, "LogEntry",
4074 postCodeID);
4075 return;
4076 }
4077 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
4078 const char* d = reinterpret_cast<const char*>(c.data());
4079 std::string_view strData(d, c.size());
George Liu647b3cd2021-07-05 12:43:56 +08004080
Ed Tanousd9f6c622022-03-17 09:12:17 -07004081 asyncResp->res.addHeader(boost::beast::http::field::content_type,
Ed Tanous002d39b2022-05-31 08:59:27 -07004082 "application/octet-stream");
Ed Tanousd9f6c622022-03-17 09:12:17 -07004083 asyncResp->res.addHeader(
4084 boost::beast::http::field::content_transfer_encoding, "Base64");
Ed Tanous27b0cf92023-08-07 12:02:40 -07004085 asyncResp->res.write(crow::utility::base64encode(strData));
Patrick Williams5a39f772023-10-20 11:20:21 -05004086 },
Ed Tanous002d39b2022-05-31 08:59:27 -07004087 "xyz.openbmc_project.State.Boot.PostCode0",
4088 "/xyz/openbmc_project/State/Boot/PostCode0",
4089 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index);
Patrick Williams5a39f772023-10-20 11:20:21 -05004090 });
George Liu647b3cd2021-07-05 12:43:56 +08004091}
4092
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004093inline void requestRoutesPostCodesEntry(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08004094{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004095 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07004096 app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07004097 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004098 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07004099 [&app](const crow::Request& req,
4100 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07004101 const std::string& systemName, const std::string& targetID) {
Carson Labrado3ba00072022-06-06 19:40:56 +00004102 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07004103 {
4104 return;
4105 }
Ed Tanous25b54db2024-04-17 15:40:31 -07004106 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08004107 {
4108 // Option currently returns no systems. TBD
4109 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
4110 systemName);
4111 return;
4112 }
Ed Tanous253f11b2024-05-16 09:38:31 -07004113 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07004114 {
4115 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
4116 systemName);
4117 return;
4118 }
4119
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08004120 getPostCodeForEntry(asyncResp, targetID);
Patrick Williams5a39f772023-10-20 11:20:21 -05004121 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004122}
ZhikuiRena3316fc2020-01-29 14:58:08 -08004123
Ed Tanous1da66f72018-07-27 16:13:37 -07004124} // namespace redfish