blob: d960aad59061cefba0fd66befb8680900c8ed61c [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
Ed Tanous1da66f72018-07-27 16:13:37 -07004#pragma once
5
Ed Tanousd7857202025-01-28 15:32:26 -08006#include "bmcweb_config.h"
7
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08008#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "async_resp.hpp"
10#include "dbus_singleton.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080011#include "dbus_utility.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080012#include "error_messages.hpp"
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -060013#include "generated/enums/log_entry.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070014#include "generated/enums/log_service.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080015#include "http_body.hpp"
16#include "http_request.hpp"
17#include "http_response.hpp"
George Liu647b3cd2021-07-05 12:43:56 +080018#include "http_utility.hpp"
Spencer Kub7028eb2021-10-26 15:27:35 +080019#include "human_sort.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080020#include "logging.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080021#include "query.hpp"
Jason M. Bills4851d452019-03-28 11:27:48 -070022#include "registries.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080023#include "registries/privilege_registry.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080024#include "str_utility.hpp"
James Feist46229572020-02-19 15:11:58 -080025#include "task.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070026#include "task_messages.hpp"
Alexander Hansen262dcc12024-09-19 12:04:03 +020027#include "utils/dbus_event_log_entry.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080028#include "utils/dbus_utils.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070029#include "utils/json_utils.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080030#include "utils/query_param.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080031#include "utils/time_utils.hpp"
Ed Tanous1da66f72018-07-27 16:13:37 -070032
Ed Tanousd7857202025-01-28 15:32:26 -080033#include <asm-generic/errno.h>
34#include <systemd/sd-bus.h>
Asmitha Karunanithi8e317782020-12-10 03:35:05 -060035#include <tinyxml2.h>
Adriana Kobylak400fd1f2021-01-29 09:01:30 -060036#include <unistd.h>
Jason M. Billse1f26342018-07-18 12:12:00 -070037
Ed Tanousd7857202025-01-28 15:32:26 -080038#include <boost/beast/http/field.hpp>
39#include <boost/beast/http/status.hpp>
Ed Tanous07c8c202022-07-11 10:08:08 -070040#include <boost/beast/http/verb.hpp>
Jason M. Bills1ddcf012019-11-26 14:59:21 -080041#include <boost/system/linux_error.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070042#include <boost/url/format.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080043#include <boost/url/url.hpp>
44#include <sdbusplus/message.hpp>
45#include <sdbusplus/message/native_types.hpp>
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +020046#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050047
Ed Tanousd7857202025-01-28 15:32:26 -080048#include <algorithm>
George Liu7a1dbc42022-12-07 16:03:22 +080049#include <array>
Ed Tanousd7857202025-01-28 15:32:26 -080050#include <chrono>
Abhilash Rajub5f288d2023-11-08 22:32:44 -060051#include <cstddef>
Ed Tanousd7857202025-01-28 15:32:26 -080052#include <cstdint>
53#include <cstdio>
54#include <ctime>
James Feist4418c7f2019-04-15 11:09:15 -070055#include <filesystem>
Ed Tanousd7857202025-01-28 15:32:26 -080056#include <format>
57#include <fstream>
58#include <functional>
59#include <iomanip>
Ed Tanous18f8f602023-07-18 10:07:23 -070060#include <iterator>
Ed Tanousd7857202025-01-28 15:32:26 -080061#include <memory>
Xiaochao Ma75710de2021-01-21 17:56:02 +080062#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070063#include <ranges>
Ed Tanous26702d02021-11-03 15:02:33 -070064#include <span>
Ed Tanousd7857202025-01-28 15:32:26 -080065#include <sstream>
Ed Tanous18f8f602023-07-18 10:07:23 -070066#include <string>
Jason M. Billscd225da2019-05-08 15:31:57 -070067#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080068#include <system_error>
69#include <utility>
Ed Tanousabf2add2019-01-22 16:40:12 -080070#include <variant>
Ed Tanousd7857202025-01-28 15:32:26 -080071#include <vector>
Ed Tanous1da66f72018-07-27 16:13:37 -070072
73namespace redfish
74{
75
Patrick Williams89492a12023-05-10 07:51:34 -050076constexpr const char* crashdumpObject = "com.intel.crashdump";
77constexpr const char* crashdumpPath = "/com/intel/crashdump";
78constexpr const char* crashdumpInterface = "com.intel.crashdump";
79constexpr const char* deleteAllInterface =
Jason M. Bills5b61b5e2019-10-16 10:59:02 -070080 "xyz.openbmc_project.Collection.DeleteAll";
Patrick Williams89492a12023-05-10 07:51:34 -050081constexpr const char* crashdumpOnDemandInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070082 "com.intel.crashdump.OnDemand";
Patrick Williams89492a12023-05-10 07:51:34 -050083constexpr const char* crashdumpTelemetryInterface =
Kenny L. Ku6eda7682020-06-19 09:48:36 -070084 "com.intel.crashdump.Telemetry";
Ed Tanous1da66f72018-07-27 16:13:37 -070085
Asmitha Karunanithi8e317782020-12-10 03:35:05 -060086enum class DumpCreationProgress
87{
88 DUMP_CREATE_SUCCESS,
89 DUMP_CREATE_FAILED,
90 DUMP_CREATE_INPROGRESS
91};
92
Gunnar Mills1214b7e2020-06-04 10:11:30 -050093inline std::string translateSeverityDbusToRedfish(const std::string& s)
Andrew Geisslercb92c032018-08-17 07:56:14 -070094{
Ed Tanousd4d25792020-09-29 15:15:03 -070095 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
96 (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
97 (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
98 (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
Andrew Geisslercb92c032018-08-17 07:56:14 -070099 {
100 return "Critical";
101 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700102 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
103 (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
104 (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
Andrew Geisslercb92c032018-08-17 07:56:14 -0700105 {
106 return "OK";
107 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700108 if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
Andrew Geisslercb92c032018-08-17 07:56:14 -0700109 {
110 return "Warning";
111 }
112 return "";
113}
114
Abhishek Patel9017faf2021-09-14 22:48:55 -0500115inline std::optional<bool> getProviderNotifyAction(const std::string& notify)
116{
117 std::optional<bool> notifyAction;
118 if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify")
119 {
120 notifyAction = true;
121 }
122 else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit")
123 {
124 notifyAction = false;
125 }
126
127 return notifyAction;
128}
129
Ed Tanous18f8f602023-07-18 10:07:23 -0700130inline std::string getDumpPath(std::string_view dumpType)
131{
132 std::string dbusDumpPath = "/xyz/openbmc_project/dump/";
133 std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath),
134 bmcweb::asciiToLower);
135
136 return dbusDumpPath;
137}
138
Ed Tanous055713e2024-07-17 17:19:36 -0700139inline bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700140 const bool firstEntry = true)
Jason M. Bills95820182019-04-22 16:25:34 -0700141{
Ed Tanous271584a2019-07-09 16:24:22 -0700142 static time_t prevTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700143 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700144 if (firstEntry)
145 {
146 prevTs = 0;
147 }
148
Jason M. Bills95820182019-04-22 16:25:34 -0700149 // Get the entry timestamp
Ed Tanous271584a2019-07-09 16:24:22 -0700150 std::time_t curTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700151 std::tm timeStruct = {};
152 std::istringstream entryStream(logEntry);
153 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
154 {
155 curTs = std::mktime(&timeStruct);
156 }
157 // If the timestamp isn't unique, increment the index
158 if (curTs == prevTs)
159 {
160 index++;
161 }
162 else
163 {
164 // Otherwise, reset it
165 index = 0;
166 }
167 // Save the timestamp
168 prevTs = curTs;
169
170 entryID = std::to_string(curTs);
171 if (index > 0)
172 {
173 entryID += "_" + std::to_string(index);
174 }
175 return true;
176}
177
Patrick Williams504af5a2025-02-03 14:29:03 -0500178inline bool getRedfishLogFiles(
179 std::vector<std::filesystem::path>& redfishLogFiles)
Jason M. Bills95820182019-04-22 16:25:34 -0700180{
181 static const std::filesystem::path redfishLogDir = "/var/log";
182 static const std::string redfishLogFilename = "redfish";
183
184 // Loop through the directory looking for redfish log files
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500185 for (const std::filesystem::directory_entry& dirEnt :
Jason M. Bills95820182019-04-22 16:25:34 -0700186 std::filesystem::directory_iterator(redfishLogDir))
187 {
188 // If we find a redfish log file, save the path
189 std::string filename = dirEnt.path().filename();
Ed Tanous11ba3972022-07-11 09:50:41 -0700190 if (filename.starts_with(redfishLogFilename))
Jason M. Bills95820182019-04-22 16:25:34 -0700191 {
192 redfishLogFiles.emplace_back(redfishLogDir / filename);
193 }
194 }
195 // As the log files rotate, they are appended with a ".#" that is higher for
196 // the older logs. Since we don't expect more than 10 log files, we
197 // can just sort the list to get them in order from newest to oldest
Ed Tanous3544d2a2023-08-06 18:12:20 -0700198 std::ranges::sort(redfishLogFiles);
Jason M. Bills95820182019-04-22 16:25:34 -0700199
200 return !redfishLogFiles.empty();
201}
202
Patrick Williams504af5a2025-02-03 14:29:03 -0500203inline log_entry::OriginatorTypes mapDbusOriginatorTypeToRedfish(
204 const std::string& originatorType)
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600205{
206 if (originatorType ==
207 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client")
208 {
209 return log_entry::OriginatorTypes::Client;
210 }
211 if (originatorType ==
212 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal")
213 {
214 return log_entry::OriginatorTypes::Internal;
215 }
216 if (originatorType ==
217 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService")
218 {
219 return log_entry::OriginatorTypes::SupportingService;
220 }
221 return log_entry::OriginatorTypes::Invalid;
222}
223
Claire Weinanaefe3782022-07-15 19:17:19 -0700224inline void parseDumpEntryFromDbusObject(
Jiaqing Zhao2d613eb2022-08-15 16:03:00 +0800225 const dbus::utility::ManagedObjectType::value_type& object,
Claire Weinanc6fecda2022-07-15 10:43:25 -0700226 std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs,
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600227 std::string& originatorId, log_entry::OriginatorTypes& originatorType,
Claire Weinanaefe3782022-07-15 19:17:19 -0700228 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
229{
230 for (const auto& interfaceMap : object.second)
231 {
232 if (interfaceMap.first == "xyz.openbmc_project.Common.Progress")
233 {
234 for (const auto& propertyMap : interfaceMap.second)
235 {
236 if (propertyMap.first == "Status")
237 {
238 const auto* status =
239 std::get_if<std::string>(&propertyMap.second);
240 if (status == nullptr)
241 {
242 messages::internalError(asyncResp->res);
243 break;
244 }
245 dumpStatus = *status;
246 }
247 }
248 }
249 else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
250 {
251 for (const auto& propertyMap : interfaceMap.second)
252 {
253 if (propertyMap.first == "Size")
254 {
255 const auto* sizePtr =
256 std::get_if<uint64_t>(&propertyMap.second);
257 if (sizePtr == nullptr)
258 {
259 messages::internalError(asyncResp->res);
260 break;
261 }
262 size = *sizePtr;
263 break;
264 }
265 }
266 }
267 else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime")
268 {
269 for (const auto& propertyMap : interfaceMap.second)
270 {
271 if (propertyMap.first == "Elapsed")
272 {
273 const uint64_t* usecsTimeStamp =
274 std::get_if<uint64_t>(&propertyMap.second);
275 if (usecsTimeStamp == nullptr)
276 {
277 messages::internalError(asyncResp->res);
278 break;
279 }
Claire Weinanc6fecda2022-07-15 10:43:25 -0700280 timestampUs = *usecsTimeStamp;
Claire Weinanaefe3782022-07-15 19:17:19 -0700281 break;
282 }
283 }
284 }
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600285 else if (interfaceMap.first ==
286 "xyz.openbmc_project.Common.OriginatedBy")
287 {
288 for (const auto& propertyMap : interfaceMap.second)
289 {
290 if (propertyMap.first == "OriginatorId")
291 {
292 const std::string* id =
293 std::get_if<std::string>(&propertyMap.second);
294 if (id == nullptr)
295 {
296 messages::internalError(asyncResp->res);
297 break;
298 }
299 originatorId = *id;
300 }
301
302 if (propertyMap.first == "OriginatorType")
303 {
304 const std::string* type =
305 std::get_if<std::string>(&propertyMap.second);
306 if (type == nullptr)
307 {
308 messages::internalError(asyncResp->res);
309 break;
310 }
311
312 originatorType = mapDbusOriginatorTypeToRedfish(*type);
313 if (originatorType == log_entry::OriginatorTypes::Invalid)
314 {
315 messages::internalError(asyncResp->res);
316 break;
317 }
318 }
319 }
320 }
Claire Weinanaefe3782022-07-15 19:17:19 -0700321 }
322}
323
Nan Zhou21ab4042022-06-26 23:07:40 +0000324static std::string getDumpEntriesPath(const std::string& dumpType)
Claire Weinanfdd26902022-03-01 14:18:25 -0800325{
326 std::string entriesPath;
327
328 if (dumpType == "BMC")
329 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700330 entriesPath =
331 std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
332 BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800333 }
334 else if (dumpType == "FaultLog")
335 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700336 entriesPath =
337 std::format("/redfish/v1/Managers/{}/LogServices/FaultLog/Entries/",
338 BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800339 }
340 else if (dumpType == "System")
341 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700342 entriesPath =
343 std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
344 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800345 }
346 else
347 {
Ed Tanous62598e32023-07-17 17:06:25 -0700348 BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}",
349 dumpType);
Claire Weinanfdd26902022-03-01 14:18:25 -0800350 }
351
352 // Returns empty string on error
353 return entriesPath;
354}
355
Patrick Williams504af5a2025-02-03 14:29:03 -0500356inline void getDumpEntryCollection(
357 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
358 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500359{
Claire Weinanfdd26902022-03-01 14:18:25 -0800360 std::string entriesPath = getDumpEntriesPath(dumpType);
361 if (entriesPath.empty())
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500362 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500363 messages::internalError(asyncResp->res);
364 return;
365 }
366
George Liu5eb468d2023-06-20 17:03:24 +0800367 sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
368 dbus::utility::getManagedObjects(
369 "xyz.openbmc_project.Dump.Manager", path,
Claire Weinanfdd26902022-03-01 14:18:25 -0800370 [asyncResp, entriesPath,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800371 dumpType](const boost::system::error_code& ec,
George Liu5eb468d2023-06-20 17:03:24 +0800372 const dbus::utility::ManagedObjectType& objects) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400373 if (ec)
374 {
375 BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
376 messages::internalError(asyncResp->res);
377 return;
378 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700379
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400380 // Remove ending slash
381 std::string odataIdStr = entriesPath;
382 if (!odataIdStr.empty())
383 {
384 odataIdStr.pop_back();
385 }
Claire Weinanfdd26902022-03-01 14:18:25 -0800386
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400387 asyncResp->res.jsonValue["@odata.type"] =
388 "#LogEntryCollection.LogEntryCollection";
389 asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr);
390 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries";
391 asyncResp->res.jsonValue["Description"] =
392 "Collection of " + dumpType + " Dump Entries";
Claire Weinanfdd26902022-03-01 14:18:25 -0800393
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400394 nlohmann::json::array_t entriesArray;
395 std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
Ed Tanous002d39b2022-05-31 08:59:27 -0700396
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400397 dbus::utility::ManagedObjectType resp(objects);
398 std::ranges::sort(resp, [](const auto& l, const auto& r) {
399 return AlphanumLess<std::string>()(l.first.filename(),
400 r.first.filename());
401 });
402
403 for (auto& object : resp)
404 {
405 if (object.first.str.find(dumpEntryPath) == std::string::npos)
406 {
407 continue;
408 }
409 uint64_t timestampUs = 0;
410 uint64_t size = 0;
411 std::string dumpStatus;
412 std::string originatorId;
413 log_entry::OriginatorTypes originatorType =
414 log_entry::OriginatorTypes::Internal;
415 nlohmann::json::object_t thisEntry;
416
417 std::string entryID = object.first.filename();
418 if (entryID.empty())
419 {
420 continue;
421 }
422
423 parseDumpEntryFromDbusObject(object, dumpStatus, size,
424 timestampUs, originatorId,
425 originatorType, asyncResp);
426
427 if (dumpStatus !=
428 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
429 !dumpStatus.empty())
430 {
431 // Dump status is not Complete, no need to enumerate
432 continue;
433 }
434
435 thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry";
436 thisEntry["@odata.id"] = entriesPath + entryID;
437 thisEntry["Id"] = entryID;
438 thisEntry["EntryType"] = "Event";
439 thisEntry["Name"] = dumpType + " Dump Entry";
440 thisEntry["Created"] =
441 redfish::time_utils::getDateTimeUintUs(timestampUs);
442
443 if (!originatorId.empty())
444 {
445 thisEntry["Originator"] = originatorId;
446 thisEntry["OriginatorType"] = originatorType;
447 }
448
449 if (dumpType == "BMC")
450 {
451 thisEntry["DiagnosticDataType"] = "Manager";
452 thisEntry["AdditionalDataURI"] =
453 entriesPath + entryID + "/attachment";
454 thisEntry["AdditionalDataSizeBytes"] = size;
455 }
456 else if (dumpType == "System")
457 {
458 thisEntry["DiagnosticDataType"] = "OEM";
459 thisEntry["OEMDiagnosticDataType"] = "System";
460 thisEntry["AdditionalDataURI"] =
461 entriesPath + entryID + "/attachment";
462 thisEntry["AdditionalDataSizeBytes"] = size;
463 }
464 entriesArray.emplace_back(std::move(thisEntry));
465 }
466 asyncResp->res.jsonValue["Members@odata.count"] =
467 entriesArray.size();
468 asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
Ed Tanous002d39b2022-05-31 08:59:27 -0700469 });
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500470}
471
Patrick Williams504af5a2025-02-03 14:29:03 -0500472inline void getDumpEntryById(
473 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
474 const std::string& entryID, const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500475{
Claire Weinanfdd26902022-03-01 14:18:25 -0800476 std::string entriesPath = getDumpEntriesPath(dumpType);
477 if (entriesPath.empty())
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500478 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500479 messages::internalError(asyncResp->res);
480 return;
481 }
482
George Liu5eb468d2023-06-20 17:03:24 +0800483 sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
484 dbus::utility::getManagedObjects(
485 "xyz.openbmc_project.Dump.Manager", path,
Claire Weinanfdd26902022-03-01 14:18:25 -0800486 [asyncResp, entryID, dumpType,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800487 entriesPath](const boost::system::error_code& ec,
Ed Tanous02cad962022-06-30 16:50:15 -0700488 const dbus::utility::ManagedObjectType& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400489 if (ec)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500490 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400491 BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
492 messages::internalError(asyncResp->res);
493 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700494 }
495
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400496 bool foundDumpEntry = false;
497 std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
Ed Tanous002d39b2022-05-31 08:59:27 -0700498
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400499 for (const auto& objectPath : resp)
Ed Tanous002d39b2022-05-31 08:59:27 -0700500 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400501 if (objectPath.first.str != dumpEntryPath + entryID)
502 {
503 continue;
504 }
505
506 foundDumpEntry = true;
507 uint64_t timestampUs = 0;
508 uint64_t size = 0;
509 std::string dumpStatus;
510 std::string originatorId;
511 log_entry::OriginatorTypes originatorType =
512 log_entry::OriginatorTypes::Internal;
513
514 parseDumpEntryFromDbusObject(objectPath, dumpStatus, size,
515 timestampUs, originatorId,
516 originatorType, asyncResp);
517
518 if (dumpStatus !=
519 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
520 !dumpStatus.empty())
521 {
522 // Dump status is not Complete
523 // return not found until status is changed to Completed
524 messages::resourceNotFound(asyncResp->res,
525 dumpType + " dump", entryID);
526 return;
527 }
528
529 asyncResp->res.jsonValue["@odata.type"] =
530 "#LogEntry.v1_11_0.LogEntry";
531 asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID;
532 asyncResp->res.jsonValue["Id"] = entryID;
533 asyncResp->res.jsonValue["EntryType"] = "Event";
534 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
535 asyncResp->res.jsonValue["Created"] =
536 redfish::time_utils::getDateTimeUintUs(timestampUs);
537
538 if (!originatorId.empty())
539 {
540 asyncResp->res.jsonValue["Originator"] = originatorId;
541 asyncResp->res.jsonValue["OriginatorType"] = originatorType;
542 }
543
544 if (dumpType == "BMC")
545 {
546 asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
547 asyncResp->res.jsonValue["AdditionalDataURI"] =
548 entriesPath + entryID + "/attachment";
549 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
550 }
551 else if (dumpType == "System")
552 {
553 asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
554 asyncResp->res.jsonValue["OEMDiagnosticDataType"] =
555 "System";
556 asyncResp->res.jsonValue["AdditionalDataURI"] =
557 entriesPath + entryID + "/attachment";
558 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
559 }
560 }
561 if (!foundDumpEntry)
562 {
563 BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200564 messages::resourceNotFound(asyncResp->res, dumpType + " dump",
565 entryID);
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500566 return;
567 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400568 });
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500569}
570
zhanghch058d1b46d2021-04-01 11:18:24 +0800571inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Stanley Chu98782562020-11-04 16:10:24 +0800572 const std::string& entryID,
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500573 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500574{
Patrick Williams5a39f772023-10-20 11:20:21 -0500575 auto respHandler = [asyncResp,
576 entryID](const boost::system::error_code& ec) {
Ed Tanous62598e32023-07-17 17:06:25 -0700577 BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done");
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500578 if (ec)
579 {
George Liu3de8d8b2021-03-22 17:49:39 +0800580 if (ec.value() == EBADR)
581 {
582 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
583 return;
584 }
Ed Tanous62598e32023-07-17 17:06:25 -0700585 BMCWEB_LOG_ERROR(
586 "Dump (DBus) doDelete respHandler got error {} entryID={}", ec,
587 entryID);
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500588 messages::internalError(asyncResp->res);
589 return;
590 }
591 };
Ed Tanous18f8f602023-07-18 10:07:23 -0700592
Ed Tanous177612a2025-02-14 15:16:09 -0800593 dbus::utility::async_method_call(
594 asyncResp, respHandler, "xyz.openbmc_project.Dump.Manager",
Ed Tanous18f8f602023-07-18 10:07:23 -0700595 std::format("{}/entry/{}", getDumpPath(dumpType), entryID),
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500596 "xyz.openbmc_project.Object.Delete", "Delete");
597}
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600598inline bool checkSizeLimit(int fd, crow::Response& res)
599{
600 long long int size = lseek(fd, 0, SEEK_END);
601 if (size <= 0)
602 {
603 BMCWEB_LOG_ERROR("Failed to get size of file, lseek() returned {}",
604 size);
605 messages::internalError(res);
606 return false;
607 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500608
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600609 // Arbitrary max size of 20MB to accommodate BMC dumps
610 constexpr long long int maxFileSize = 20LL * 1024LL * 1024LL;
611 if (size > maxFileSize)
612 {
613 BMCWEB_LOG_ERROR("File size {} exceeds maximum allowed size of {}",
614 size, maxFileSize);
615 messages::internalError(res);
616 return false;
617 }
618 off_t rc = lseek(fd, 0, SEEK_SET);
619 if (rc < 0)
620 {
621 BMCWEB_LOG_ERROR("Failed to reset file offset to 0");
622 messages::internalError(res);
623 return false;
624 }
625 return true;
626}
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400627inline void downloadEntryCallback(
628 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
629 const std::string& entryID, const std::string& downloadEntryType,
630 const boost::system::error_code& ec,
631 const sdbusplus::message::unix_fd& unixfd)
Carson Labrado168d1b12023-03-27 17:04:46 +0000632{
633 if (ec.value() == EBADR)
634 {
635 messages::resourceNotFound(asyncResp->res, "EntryAttachment", entryID);
636 return;
637 }
638 if (ec)
639 {
640 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
641 messages::internalError(asyncResp->res);
642 return;
643 }
644
645 // Make sure we know how to process the retrieved entry attachment
646 if ((downloadEntryType != "BMC") && (downloadEntryType != "System"))
647 {
648 BMCWEB_LOG_ERROR("downloadEntryCallback() invalid entry type: {}",
649 downloadEntryType);
650 messages::internalError(asyncResp->res);
651 }
652
653 int fd = -1;
654 fd = dup(unixfd);
655 if (fd < 0)
656 {
657 BMCWEB_LOG_ERROR("Failed to open file");
658 messages::internalError(asyncResp->res);
659 return;
660 }
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600661 if (!checkSizeLimit(fd, asyncResp->res))
Carson Labrado168d1b12023-03-27 17:04:46 +0000662 {
Carson Labrado168d1b12023-03-27 17:04:46 +0000663 close(fd);
664 return;
665 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000666 if (downloadEntryType == "System")
667 {
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600668 if (!asyncResp->res.openFd(fd, bmcweb::EncodingType::Base64))
669 {
670 messages::internalError(asyncResp->res);
671 close(fd);
672 return;
673 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000674 asyncResp->res.addHeader(
675 boost::beast::http::field::content_transfer_encoding, "Base64");
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600676 return;
Carson Labrado168d1b12023-03-27 17:04:46 +0000677 }
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600678 if (!asyncResp->res.openFd(fd))
Ed Tanous27b0cf92023-08-07 12:02:40 -0700679 {
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600680 messages::internalError(asyncResp->res);
681 close(fd);
682 return;
Ed Tanous27b0cf92023-08-07 12:02:40 -0700683 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000684 asyncResp->res.addHeader(boost::beast::http::field::content_type,
685 "application/octet-stream");
686}
687
Patrick Williams504af5a2025-02-03 14:29:03 -0500688inline void downloadDumpEntry(
689 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
690 const std::string& entryID, const std::string& dumpType)
Carson Labrado168d1b12023-03-27 17:04:46 +0000691{
692 if (dumpType != "BMC")
693 {
694 BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
695 messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID);
696 return;
697 }
698
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400699 std::string dumpEntryPath =
700 std::format("{}/entry/{}", getDumpPath(dumpType), entryID);
Carson Labrado168d1b12023-03-27 17:04:46 +0000701
702 auto downloadDumpEntryHandler =
703 [asyncResp, entryID,
704 dumpType](const boost::system::error_code& ec,
705 const sdbusplus::message::unix_fd& unixfd) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400706 downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
707 };
Carson Labrado168d1b12023-03-27 17:04:46 +0000708
Ed Tanous177612a2025-02-14 15:16:09 -0800709 dbus::utility::async_method_call(
710 asyncResp, std::move(downloadDumpEntryHandler),
711 "xyz.openbmc_project.Dump.Manager", dumpEntryPath,
712 "xyz.openbmc_project.Dump.Entry", "GetFileHandle");
Carson Labrado168d1b12023-03-27 17:04:46 +0000713}
714
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400715inline void downloadEventLogEntry(
716 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
717 const std::string& systemName, const std::string& entryID,
718 const std::string& dumpType)
Carson Labrado168d1b12023-03-27 17:04:46 +0000719{
Ed Tanous25b54db2024-04-17 15:40:31 -0700720 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Carson Labrado168d1b12023-03-27 17:04:46 +0000721 {
722 // Option currently returns no systems. TBD
723 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
724 systemName);
725 return;
726 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700727 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Carson Labrado168d1b12023-03-27 17:04:46 +0000728 {
729 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
730 systemName);
731 return;
732 }
733
734 std::string entryPath =
735 sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") /
736 entryID;
737
738 auto downloadEventLogEntryHandler =
739 [asyncResp, entryID,
740 dumpType](const boost::system::error_code& ec,
741 const sdbusplus::message::unix_fd& unixfd) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400742 downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
743 };
Carson Labrado168d1b12023-03-27 17:04:46 +0000744
Ed Tanous177612a2025-02-14 15:16:09 -0800745 dbus::utility::async_method_call(
746 asyncResp, std::move(downloadEventLogEntryHandler),
747 "xyz.openbmc_project.Logging", entryPath,
748 "xyz.openbmc_project.Logging.Entry", "GetEntry");
Carson Labrado168d1b12023-03-27 17:04:46 +0000749}
750
Patrick Williams504af5a2025-02-03 14:29:03 -0500751inline DumpCreationProgress mapDbusStatusToDumpProgress(
752 const std::string& status)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500753{
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600754 if (status ==
755 "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" ||
756 status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted")
757 {
758 return DumpCreationProgress::DUMP_CREATE_FAILED;
759 }
760 if (status ==
761 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed")
762 {
763 return DumpCreationProgress::DUMP_CREATE_SUCCESS;
764 }
765 return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
766}
767
Patrick Williams504af5a2025-02-03 14:29:03 -0500768inline DumpCreationProgress getDumpCompletionStatus(
769 const dbus::utility::DBusPropertiesMap& values)
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600770{
771 for (const auto& [key, val] : values)
772 {
773 if (key == "Status")
Ed Tanous002d39b2022-05-31 08:59:27 -0700774 {
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600775 const std::string* value = std::get_if<std::string>(&val);
776 if (value == nullptr)
777 {
Ed Tanous62598e32023-07-17 17:06:25 -0700778 BMCWEB_LOG_ERROR("Status property value is null");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600779 return DumpCreationProgress::DUMP_CREATE_FAILED;
780 }
781 return mapDbusStatusToDumpProgress(*value);
782 }
783 }
784 return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
785}
786
787inline std::string getDumpEntryPath(const std::string& dumpPath)
788{
789 if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry")
790 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700791 return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
Ed Tanous9f565092024-07-12 22:06:53 -0700792 BMCWEB_REDFISH_MANAGER_URI_NAME);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600793 }
794 if (dumpPath == "/xyz/openbmc_project/dump/system/entry")
795 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700796 return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
797 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600798 }
799 return "";
800}
801
802inline void createDumpTaskCallback(
803 task::Payload&& payload,
804 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
805 const sdbusplus::message::object_path& createdObjPath)
806{
807 const std::string dumpPath = createdObjPath.parent_path().str;
808 const std::string dumpId = createdObjPath.filename();
809
810 std::string dumpEntryPath = getDumpEntryPath(dumpPath);
811
812 if (dumpEntryPath.empty())
813 {
Ed Tanous62598e32023-07-17 17:06:25 -0700814 BMCWEB_LOG_ERROR("Invalid dump type received");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600815 messages::internalError(asyncResp->res);
816 return;
817 }
818
Ed Tanous177612a2025-02-14 15:16:09 -0800819 dbus::utility::async_method_call(
820 asyncResp,
Ed Tanous8cb2c022024-03-27 16:31:46 -0700821 [asyncResp, payload = std::move(payload), createdObjPath,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600822 dumpEntryPath{std::move(dumpEntryPath)},
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800823 dumpId](const boost::system::error_code& ec,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600824 const std::string& introspectXml) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400825 if (ec)
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600826 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400827 BMCWEB_LOG_ERROR("Introspect call failed with error: {}",
828 ec.message());
829 messages::internalError(asyncResp->res);
830 return;
831 }
832
833 // Check if the created dump object has implemented Progress
834 // interface to track dump completion. If yes, fetch the "Status"
835 // property of the interface, modify the task state accordingly.
836 // Else, return task completed.
837 tinyxml2::XMLDocument doc;
838
839 doc.Parse(introspectXml.data(), introspectXml.size());
840 tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
841 if (pRoot == nullptr)
842 {
843 BMCWEB_LOG_ERROR("XML document failed to parse");
844 messages::internalError(asyncResp->res);
845 return;
846 }
847 tinyxml2::XMLElement* interfaceNode =
848 pRoot->FirstChildElement("interface");
849
850 bool isProgressIntfPresent = false;
851 while (interfaceNode != nullptr)
852 {
853 const char* thisInterfaceName =
854 interfaceNode->Attribute("name");
855 if (thisInterfaceName != nullptr)
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600856 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400857 if (thisInterfaceName ==
858 std::string_view("xyz.openbmc_project.Common.Progress"))
859 {
860 interfaceNode =
861 interfaceNode->NextSiblingElement("interface");
862 continue;
863 }
864 isProgressIntfPresent = true;
865 break;
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600866 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400867 interfaceNode = interfaceNode->NextSiblingElement("interface");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600868 }
869
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400870 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
871 [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent](
872 const boost::system::error_code& ec2,
873 sdbusplus::message_t& msg,
874 const std::shared_ptr<task::TaskData>& taskData) {
875 if (ec2)
876 {
877 BMCWEB_LOG_ERROR("{}: Error in creating dump",
878 createdObjPath.str);
879 taskData->messages.emplace_back(
880 messages::internalError());
881 taskData->state = "Cancelled";
882 return task::completed;
883 }
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600884
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400885 if (isProgressIntfPresent)
886 {
887 dbus::utility::DBusPropertiesMap values;
888 std::string prop;
889 msg.read(prop, values);
890
891 DumpCreationProgress dumpStatus =
892 getDumpCompletionStatus(values);
893 if (dumpStatus ==
894 DumpCreationProgress::DUMP_CREATE_FAILED)
895 {
896 BMCWEB_LOG_ERROR("{}: Error in creating dump",
897 createdObjPath.str);
898 taskData->state = "Cancelled";
899 return task::completed;
900 }
901
902 if (dumpStatus ==
903 DumpCreationProgress::DUMP_CREATE_INPROGRESS)
904 {
905 BMCWEB_LOG_DEBUG(
906 "{}: Dump creation task is in progress",
907 createdObjPath.str);
908 return !task::completed;
909 }
910 }
911
912 nlohmann::json retMessage = messages::success();
913 taskData->messages.emplace_back(retMessage);
914
915 boost::urls::url url = boost::urls::format(
916 "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}",
917 BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId);
918
919 std::string headerLoc = "Location: ";
920 headerLoc += url.buffer();
921
922 taskData->payload->httpHeaders.emplace_back(
923 std::move(headerLoc));
924
925 BMCWEB_LOG_DEBUG("{}: Dump creation task completed",
Ed Tanous62598e32023-07-17 17:06:25 -0700926 createdObjPath.str);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400927 taskData->state = "Completed";
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600928 return task::completed;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400929 },
930 "type='signal',interface='org.freedesktop.DBus.Properties',"
931 "member='PropertiesChanged',path='" +
932 createdObjPath.str + "'");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600933
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400934 // The task timer is set to max time limit within which the
935 // requested dump will be collected.
936 task->startTimer(std::chrono::minutes(6));
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400937 task->payload.emplace(payload);
Chinmay Shripad Hegde29e2bdd2025-06-06 16:23:47 +0530938 task->populateResp(asyncResp->res);
Patrick Williams5a39f772023-10-20 11:20:21 -0500939 },
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600940 "xyz.openbmc_project.Dump.Manager", createdObjPath,
941 "org.freedesktop.DBus.Introspectable", "Introspect");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500942}
943
zhanghch058d1b46d2021-04-01 11:18:24 +0800944inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
945 const crow::Request& req, const std::string& dumpType)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500946{
Claire Weinanfdd26902022-03-01 14:18:25 -0800947 std::string dumpPath = getDumpEntriesPath(dumpType);
948 if (dumpPath.empty())
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500949 {
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500950 messages::internalError(asyncResp->res);
951 return;
952 }
953
954 std::optional<std::string> diagnosticDataType;
955 std::optional<std::string> oemDiagnosticDataType;
956
Patrick Williams504af5a2025-02-03 14:29:03 -0500957 if (!redfish::json_util::readJsonAction( //
958 req, asyncResp->res, //
959 "DiagnosticDataType", diagnosticDataType, //
Myung Baeafc474a2024-10-09 00:53:29 -0700960 "OEMDiagnosticDataType", oemDiagnosticDataType //
961 ))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500962 {
963 return;
964 }
965
966 if (dumpType == "System")
967 {
968 if (!oemDiagnosticDataType || !diagnosticDataType)
969 {
Ed Tanous62598e32023-07-17 17:06:25 -0700970 BMCWEB_LOG_ERROR(
971 "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500972 messages::actionParameterMissing(
973 asyncResp->res, "CollectDiagnosticData",
974 "DiagnosticDataType & OEMDiagnosticDataType");
975 return;
976 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700977 if ((*oemDiagnosticDataType != "System") ||
978 (*diagnosticDataType != "OEM"))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500979 {
Ed Tanous62598e32023-07-17 17:06:25 -0700980 BMCWEB_LOG_ERROR("Wrong parameter values passed");
Ed Tanousace85d62021-10-26 12:45:59 -0700981 messages::internalError(asyncResp->res);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500982 return;
983 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700984 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/",
985 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500986 }
987 else if (dumpType == "BMC")
988 {
989 if (!diagnosticDataType)
990 {
Ed Tanous62598e32023-07-17 17:06:25 -0700991 BMCWEB_LOG_ERROR(
992 "CreateDump action parameter 'DiagnosticDataType' not found!");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500993 messages::actionParameterMissing(
994 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
995 return;
996 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700997 if (*diagnosticDataType != "Manager")
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500998 {
Ed Tanous62598e32023-07-17 17:06:25 -0700999 BMCWEB_LOG_ERROR(
1000 "Wrong parameter value passed for 'DiagnosticDataType'");
Ed Tanousace85d62021-10-26 12:45:59 -07001001 messages::internalError(asyncResp->res);
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001002 return;
1003 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001004 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/",
1005 BMCWEB_REDFISH_MANAGER_URI_NAME);
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001006 }
1007 else
1008 {
Ed Tanous62598e32023-07-17 17:06:25 -07001009 BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type");
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001010 messages::internalError(asyncResp->res);
1011 return;
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001012 }
1013
Asmitha Karunanithi8e317782020-12-10 03:35:05 -06001014 std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>>
1015 createDumpParamVec;
1016
Carson Labradof574a8e2023-03-22 02:26:00 +00001017 if (req.session != nullptr)
1018 {
1019 createDumpParamVec.emplace_back(
1020 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId",
1021 req.session->clientIp);
1022 createDumpParamVec.emplace_back(
1023 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType",
1024 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client");
1025 }
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -06001026
Ed Tanous177612a2025-02-14 15:16:09 -08001027 dbus::utility::async_method_call(
1028 asyncResp,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001029 [asyncResp, payload(task::Payload(req)),
1030 dumpPath](const boost::system::error_code& ec,
1031 const sdbusplus::message_t& msg,
1032 const sdbusplus::message::object_path& objPath) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001033 if (ec)
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001034 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001035 BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec);
1036 const sd_bus_error* dbusError = msg.get_error();
1037 if (dbusError == nullptr)
1038 {
1039 messages::internalError(asyncResp->res);
1040 return;
1041 }
1042
1043 BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}",
1044 dbusError->name, dbusError->message);
1045 if (std::string_view(
1046 "xyz.openbmc_project.Common.Error.NotAllowed") ==
1047 dbusError->name)
1048 {
1049 messages::resourceInStandby(asyncResp->res);
1050 return;
1051 }
1052 if (std::string_view(
1053 "xyz.openbmc_project.Dump.Create.Error.Disabled") ==
1054 dbusError->name)
1055 {
1056 messages::serviceDisabled(asyncResp->res, dumpPath);
1057 return;
1058 }
1059 if (std::string_view(
1060 "xyz.openbmc_project.Common.Error.Unavailable") ==
1061 dbusError->name)
1062 {
1063 messages::resourceInUse(asyncResp->res);
1064 return;
1065 }
1066 // Other Dbus errors such as:
1067 // xyz.openbmc_project.Common.Error.InvalidArgument &
1068 // org.freedesktop.DBus.Error.InvalidArgs are all related to
1069 // the dbus call that is made here in the bmcweb
1070 // implementation and has nothing to do with the client's
1071 // input in the request. Hence, returning internal error
1072 // back to the client.
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001073 messages::internalError(asyncResp->res);
1074 return;
1075 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001076 BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str);
1077 createDumpTaskCallback(std::move(payload), asyncResp, objPath);
1078 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001079 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Asmitha Karunanithi8e317782020-12-10 03:35:05 -06001080 "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec);
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001081}
1082
zhanghch058d1b46d2021-04-01 11:18:24 +08001083inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1084 const std::string& dumpType)
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001085{
Ed Tanous177612a2025-02-14 15:16:09 -08001086 dbus::utility::async_method_call(
1087 asyncResp,
Claire Weinan0d946212022-07-13 19:40:19 -07001088 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001089 if (ec)
1090 {
1091 BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec);
1092 messages::internalError(asyncResp->res);
1093 return;
1094 }
Amy Change2460462025-05-06 00:10:13 -07001095 messages::success(asyncResp->res);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001096 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001097 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Claire Weinan0d946212022-07-13 19:40:19 -07001098 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001099}
1100
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001101inline void parseCrashdumpParameters(
1102 const dbus::utility::DBusPropertiesMap& params, std::string& filename,
1103 std::string& timestamp, std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001104{
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001105 const std::string* filenamePtr = nullptr;
1106 const std::string* timestampPtr = nullptr;
1107 const std::string* logfilePtr = nullptr;
1108
1109 const bool success = sdbusplus::unpackPropertiesNoThrow(
1110 dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr,
1111 "Filename", filenamePtr, "Log", logfilePtr);
1112
1113 if (!success)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001114 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001115 return;
1116 }
1117
1118 if (filenamePtr != nullptr)
1119 {
1120 filename = *filenamePtr;
1121 }
1122
1123 if (timestampPtr != nullptr)
1124 {
1125 timestamp = *timestampPtr;
1126 }
1127
1128 if (logfilePtr != nullptr)
1129 {
1130 logfile = *logfilePtr;
Johnathan Mantey043a0532020-03-10 17:15:28 -07001131 }
1132}
1133
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001134inline void requestRoutesSystemLogServiceCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07001135{
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001136 /**
1137 * Functions triggers appropriate requests on DBus
1138 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001139 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
Ed Tanoused398212021-06-09 17:05:54 -07001140 .privileges(redfish::privileges::getLogServiceCollection)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001141 .methods(
1142 boost::beast::http::verb::
1143 get)([&app](const crow::Request& req,
1144 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1145 const std::string& systemName) {
1146 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001147 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001148 return;
1149 }
1150 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1151 {
1152 // Option currently returns no systems. TBD
1153 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1154 systemName);
1155 return;
1156 }
1157 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1158 {
1159 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1160 systemName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001161 return;
1162 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001163
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001164 // Collections don't include the static data added by SubRoute
1165 // because it has a duplicate entry for members
1166 asyncResp->res.jsonValue["@odata.type"] =
1167 "#LogServiceCollection.LogServiceCollection";
1168 asyncResp->res.jsonValue["@odata.id"] =
1169 std::format("/redfish/v1/Systems/{}/LogServices",
1170 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1171 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
1172 asyncResp->res.jsonValue["Description"] =
1173 "Collection of LogServices for this Computer System";
1174 nlohmann::json& logServiceArray =
1175 asyncResp->res.jsonValue["Members"];
1176 logServiceArray = nlohmann::json::array();
1177 nlohmann::json::object_t eventLog;
1178 eventLog["@odata.id"] =
1179 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1180 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1181 logServiceArray.emplace_back(std::move(eventLog));
1182 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
Ed Tanous002d39b2022-05-31 08:59:27 -07001183 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001184 nlohmann::json::object_t dumpLog;
1185 dumpLog["@odata.id"] =
1186 std::format("/redfish/v1/Systems/{}/LogServices/Dump",
1187 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1188 logServiceArray.emplace_back(std::move(dumpLog));
Ed Tanous002d39b2022-05-31 08:59:27 -07001189 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001190
1191 if constexpr (BMCWEB_REDFISH_CPU_LOG)
1192 {
1193 nlohmann::json::object_t crashdump;
1194 crashdump["@odata.id"] =
1195 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
1196 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1197 logServiceArray.emplace_back(std::move(crashdump));
1198 }
1199
1200 if constexpr (BMCWEB_REDFISH_HOST_LOGGER)
1201 {
1202 nlohmann::json::object_t hostlogger;
1203 hostlogger["@odata.id"] =
1204 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
1205 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1206 logServiceArray.emplace_back(std::move(hostlogger));
1207 }
1208 asyncResp->res.jsonValue["Members@odata.count"] =
1209 logServiceArray.size();
1210
1211 constexpr std::array<std::string_view, 1> interfaces = {
1212 "xyz.openbmc_project.State.Boot.PostCode"};
1213 dbus::utility::getSubTreePaths(
1214 "/", 0, interfaces,
1215 [asyncResp](const boost::system::error_code& ec,
1216 const dbus::utility::MapperGetSubTreePathsResponse&
1217 subtreePath) {
1218 if (ec)
1219 {
1220 BMCWEB_LOG_ERROR("{}", ec);
1221 return;
1222 }
1223
1224 for (const auto& pathStr : subtreePath)
1225 {
1226 if (pathStr.find("PostCode") != std::string::npos)
1227 {
1228 nlohmann::json& logServiceArrayLocal =
1229 asyncResp->res.jsonValue["Members"];
1230 nlohmann::json::object_t member;
1231 member["@odata.id"] = std::format(
1232 "/redfish/v1/Systems/{}/LogServices/PostCodes",
1233 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1234
1235 logServiceArrayLocal.emplace_back(
1236 std::move(member));
1237
1238 asyncResp->res.jsonValue["Members@odata.count"] =
1239 logServiceArrayLocal.size();
1240 return;
1241 }
1242 }
1243 });
Ed Tanous45ca1b82022-03-25 13:07:27 -07001244 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001245}
1246
1247inline void requestRoutesEventLogService(App& app)
1248{
Ed Tanous22d268c2022-05-19 09:39:07 -07001249 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/")
Ed Tanoused398212021-06-09 17:05:54 -07001250 .privileges(redfish::privileges::getLogService)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001251 .methods(
1252 boost::beast::http::verb::
1253 get)([&app](const crow::Request& req,
1254 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1255 const std::string& systemName) {
1256 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1257 {
1258 return;
1259 }
1260 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1261 {
1262 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1263 systemName);
1264 return;
1265 }
1266 asyncResp->res.jsonValue["@odata.id"] =
1267 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1268 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1269 asyncResp->res.jsonValue["@odata.type"] =
1270 "#LogService.v1_2_0.LogService";
1271 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1272 asyncResp->res.jsonValue["Description"] =
1273 "System Event Log Service";
1274 asyncResp->res.jsonValue["Id"] = "EventLog";
1275 asyncResp->res.jsonValue["OverWritePolicy"] =
1276 log_service::OverWritePolicy::WrapsWhenFull;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301277
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001278 std::pair<std::string, std::string> redfishDateTimeOffset =
1279 redfish::time_utils::getDateTimeOffsetNow();
Tejas Patil7c8c4052021-06-04 17:43:14 +05301280
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001281 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
1282 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
1283 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301284
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001285 asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format(
1286 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
Ed Tanous20fa6a22024-05-20 18:02:58 -07001287 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001288 asyncResp->res
1289 .jsonValue["Actions"]["#LogService.ClearLog"]["target"]
1290
1291 = std::format(
1292 "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog",
1293 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1294 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001295}
1296
Alexander Hansen599b9af2024-08-06 15:11:57 +02001297inline void handleSystemsLogServicesEventLogActionsClearPost(
1298 App& app, const crow::Request& req,
1299 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1300 const std::string& systemName)
1301{
1302 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1303 {
1304 return;
1305 }
1306 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1307 {
1308 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1309 systemName);
1310 return;
1311 }
1312
1313 // Clear the EventLog by deleting the log files
1314 std::vector<std::filesystem::path> redfishLogFiles;
1315 if (getRedfishLogFiles(redfishLogFiles))
1316 {
1317 for (const std::filesystem::path& file : redfishLogFiles)
1318 {
1319 std::error_code ec;
1320 std::filesystem::remove(file, ec);
1321 }
1322 }
1323
1324 // Reload rsyslog so it knows to start new log files
Ed Tanous177612a2025-02-14 15:16:09 -08001325 dbus::utility::async_method_call(
1326 asyncResp,
Alexander Hansen599b9af2024-08-06 15:11:57 +02001327 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001328 if (ec)
1329 {
1330 BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec);
1331 messages::internalError(asyncResp->res);
1332 return;
1333 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001334
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001335 messages::success(asyncResp->res);
1336 },
Alexander Hansen599b9af2024-08-06 15:11:57 +02001337 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1338 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1339 "replace");
1340}
1341
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001342inline void requestRoutesJournalEventLogClear(App& app)
1343{
Jason M. Bills4978b632022-02-22 14:17:43 -08001344 BMCWEB_ROUTE(
1345 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07001346 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Abhishek Patelfff6a4d2021-07-21 11:29:45 -05001347 .privileges(redfish::privileges::
1348 postLogServiceSubOverComputerSystemLogServiceCollection)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001349 .methods(boost::beast::http::verb::post)(std::bind_front(
1350 handleSystemsLogServicesEventLogActionsClearPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001351}
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001352
Jason M. Billsac992cd2022-06-24 13:31:46 -07001353enum class LogParseError
1354{
1355 success,
1356 parseFailed,
1357 messageIdNotInRegistry,
1358};
1359
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001360static LogParseError fillEventLogEntryJson(
1361 const std::string& logEntryID, const std::string& logEntry,
1362 nlohmann::json::object_t& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001363{
Jason M. Bills95820182019-04-22 16:25:34 -07001364 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001365 // First get the Timestamp
Ed Tanousf23b7292020-10-15 09:41:17 -07001366 size_t space = logEntry.find_first_of(' ');
Jason M. Billscd225da2019-05-08 15:31:57 -07001367 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001368 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001369 return LogParseError::parseFailed;
Jason M. Bills95820182019-04-22 16:25:34 -07001370 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001371 std::string timestamp = logEntry.substr(0, space);
1372 // Then get the log contents
Ed Tanousf23b7292020-10-15 09:41:17 -07001373 size_t entryStart = logEntry.find_first_not_of(' ', space);
Jason M. Billscd225da2019-05-08 15:31:57 -07001374 if (entryStart == std::string::npos)
1375 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001376 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001377 }
1378 std::string_view entry(logEntry);
1379 entry.remove_prefix(entryStart);
1380 // Use split to separate the entry into its fields
1381 std::vector<std::string> logEntryFields;
Ed Tanous50ebd4a2023-01-19 19:03:17 -08001382 bmcweb::split(logEntryFields, entry, ',');
Jason M. Billscd225da2019-05-08 15:31:57 -07001383 // We need at least a MessageId to be valid
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001384 auto logEntryIter = logEntryFields.begin();
1385 if (logEntryIter == logEntryFields.end())
Jason M. Billscd225da2019-05-08 15:31:57 -07001386 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001387 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001388 }
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001389 std::string& messageID = *logEntryIter;
Jason M. Bills4851d452019-03-28 11:27:48 -07001390 // Get the Message from the MessageRegistry
Ed Tanousfffb8c12022-02-07 23:53:03 -08001391 const registries::Message* message = registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001392
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001393 logEntryIter++;
Sui Chen54417b02022-03-24 14:59:52 -07001394 if (message == nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001395 {
Ed Tanous62598e32023-07-17 17:06:25 -07001396 BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001397 return LogParseError::messageIdNotInRegistry;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001398 }
1399
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001400 std::vector<std::string_view> messageArgs(logEntryIter,
1401 logEntryFields.end());
Ed Tanousc05bba42023-06-28 08:33:29 -07001402 messageArgs.resize(message->numberOfArgs);
1403
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001404 std::string msg =
1405 redfish::registries::fillMessageArgs(messageArgs, message->message);
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001406 if (msg.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001407 {
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001408 return LogParseError::parseFailed;
Jason M. Bills4851d452019-03-28 11:27:48 -07001409 }
1410
Jason M. Bills95820182019-04-22 16:25:34 -07001411 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1412 // format which matches the Redfish format except for the fractional seconds
1413 // between the '.' and the '+', so just remove them.
Ed Tanousf23b7292020-10-15 09:41:17 -07001414 std::size_t dot = timestamp.find_first_of('.');
1415 std::size_t plus = timestamp.find_first_of('+');
Jason M. Bills95820182019-04-22 16:25:34 -07001416 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001417 {
Jason M. Bills95820182019-04-22 16:25:34 -07001418 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001419 }
1420
1421 // Fill in the log entry with the gathered data
Vijay Lobo9c11a172021-10-07 16:53:16 -05001422 logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001423 logEntryJson["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001424 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1425 BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
Jason M. Bills84afc482022-06-24 12:38:23 -07001426 logEntryJson["Name"] = "System Event Log Entry";
1427 logEntryJson["Id"] = logEntryID;
1428 logEntryJson["Message"] = std::move(msg);
1429 logEntryJson["MessageId"] = std::move(messageID);
1430 logEntryJson["MessageArgs"] = messageArgs;
1431 logEntryJson["EntryType"] = "Event";
1432 logEntryJson["Severity"] = message->messageSeverity;
1433 logEntryJson["Created"] = std::move(timestamp);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001434 return LogParseError::success;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001435}
1436
Myung Bae7f3726a2025-04-26 15:17:23 -05001437inline void fillEventLogLogEntryFromDbusLogEntry(
1438 const DbusEventLogEntry& entry, nlohmann::json& objectToFillOut)
Ed Tanous898f2aa2024-08-07 12:18:22 -07001439{
Ed Tanous898f2aa2024-08-07 12:18:22 -07001440 objectToFillOut["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1441 objectToFillOut["@odata.id"] = boost::urls::format(
1442 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
Alexander Hansen262dcc12024-09-19 12:04:03 +02001443 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
Ed Tanous898f2aa2024-08-07 12:18:22 -07001444 objectToFillOut["Name"] = "System Event Log Entry";
Alexander Hansen262dcc12024-09-19 12:04:03 +02001445 objectToFillOut["Id"] = std::to_string(entry.Id);
1446 objectToFillOut["Message"] = entry.Message;
1447 objectToFillOut["Resolved"] = entry.Resolved;
1448 std::optional<bool> notifyAction =
1449 getProviderNotifyAction(entry.ServiceProviderNotify);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001450 if (notifyAction)
1451 {
1452 objectToFillOut["ServiceProviderNotified"] = *notifyAction;
1453 }
Alexander Hansen262dcc12024-09-19 12:04:03 +02001454 if ((entry.Resolution != nullptr) && !entry.Resolution->empty())
Ed Tanous898f2aa2024-08-07 12:18:22 -07001455 {
Alexander Hansen262dcc12024-09-19 12:04:03 +02001456 objectToFillOut["Resolution"] = *entry.Resolution;
Ed Tanous898f2aa2024-08-07 12:18:22 -07001457 }
1458 objectToFillOut["EntryType"] = "Event";
Alexander Hansen262dcc12024-09-19 12:04:03 +02001459 objectToFillOut["Severity"] =
1460 translateSeverityDbusToRedfish(entry.Severity);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001461 objectToFillOut["Created"] =
Alexander Hansen262dcc12024-09-19 12:04:03 +02001462 redfish::time_utils::getDateTimeUintMs(entry.Timestamp);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001463 objectToFillOut["Modified"] =
Alexander Hansen262dcc12024-09-19 12:04:03 +02001464 redfish::time_utils::getDateTimeUintMs(entry.UpdateTimestamp);
1465 if (entry.Path != nullptr)
Ed Tanous898f2aa2024-08-07 12:18:22 -07001466 {
1467 objectToFillOut["AdditionalDataURI"] = boost::urls::format(
1468 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment",
Alexander Hansen262dcc12024-09-19 12:04:03 +02001469 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
Ed Tanous898f2aa2024-08-07 12:18:22 -07001470 }
1471}
1472
Ed Tanousb7290962024-08-07 11:09:51 -07001473inline void afterLogEntriesGetManagedObjects(
1474 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1475 const boost::system::error_code& ec,
1476 const dbus::utility::ManagedObjectType& resp)
1477{
1478 if (ec)
1479 {
1480 // TODO Handle for specific error code
1481 BMCWEB_LOG_ERROR("getLogEntriesIfaceData resp_handler got error {}",
1482 ec);
1483 messages::internalError(asyncResp->res);
1484 return;
1485 }
1486 nlohmann::json::array_t entriesArray;
1487 for (const auto& objectPath : resp)
1488 {
Ed Tanous898f2aa2024-08-07 12:18:22 -07001489 dbus::utility::DBusPropertiesMap propsFlattened;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001490 auto isEntry =
1491 std::ranges::find_if(objectPath.second, [](const auto& object) {
1492 return object.first == "xyz.openbmc_project.Logging.Entry";
1493 });
Ed Tanous898f2aa2024-08-07 12:18:22 -07001494 if (isEntry == objectPath.second.end())
Ed Tanousb7290962024-08-07 11:09:51 -07001495 {
1496 continue;
1497 }
Myung Bae7f3726a2025-04-26 15:17:23 -05001498
Ed Tanous898f2aa2024-08-07 12:18:22 -07001499 for (const auto& interfaceMap : objectPath.second)
Ed Tanousb7290962024-08-07 11:09:51 -07001500 {
Ed Tanous898f2aa2024-08-07 12:18:22 -07001501 for (const auto& propertyMap : interfaceMap.second)
Ed Tanousb7290962024-08-07 11:09:51 -07001502 {
Ed Tanous898f2aa2024-08-07 12:18:22 -07001503 propsFlattened.emplace_back(propertyMap.first,
1504 propertyMap.second);
Ed Tanousb7290962024-08-07 11:09:51 -07001505 }
1506 }
Myung Bae7f3726a2025-04-26 15:17:23 -05001507 std::optional<DbusEventLogEntry> optEntry =
1508 fillDbusEventLogEntryFromPropertyMap(propsFlattened);
1509
1510 if (!optEntry.has_value())
Igor Kanyuka90896602025-03-13 08:52:38 +00001511 {
Myung Bae7f3726a2025-04-26 15:17:23 -05001512 messages::internalError(asyncResp->res);
Igor Kanyuka90896602025-03-13 08:52:38 +00001513 return;
1514 }
Myung Bae7f3726a2025-04-26 15:17:23 -05001515 fillEventLogLogEntryFromDbusLogEntry(*optEntry,
1516 entriesArray.emplace_back());
Ed Tanousb7290962024-08-07 11:09:51 -07001517 }
Ed Tanous898f2aa2024-08-07 12:18:22 -07001518
Igor Kanyuka90896602025-03-13 08:52:38 +00001519 redfish::json_util::sortJsonArrayByKey(entriesArray, "Id");
Ed Tanousb7290962024-08-07 11:09:51 -07001520 asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
1521 asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
1522}
1523
Alexander Hansen599b9af2024-08-06 15:11:57 +02001524inline void handleSystemsLogServiceEventLogLogEntryCollection(
1525 App& app, const crow::Request& req,
1526 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1527 const std::string& systemName)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001528{
Alexander Hansen599b9af2024-08-06 15:11:57 +02001529 query_param::QueryCapabilities capabilities = {
1530 .canDelegateTop = true,
1531 .canDelegateSkip = true,
1532 };
1533 query_param::Query delegatedQuery;
1534 if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp,
1535 delegatedQuery, capabilities))
1536 {
1537 return;
1538 }
1539 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1540 {
1541 // Option currently returns no systems. TBD
1542 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1543 systemName);
1544 return;
1545 }
1546 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1547 {
1548 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1549 systemName);
1550 return;
1551 }
1552
1553 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
1554 size_t skip = delegatedQuery.skip.value_or(0);
1555
1556 // Collections don't include the static data added by SubRoute
1557 // because it has a duplicate entry for members
1558 asyncResp->res.jsonValue["@odata.type"] =
1559 "#LogEntryCollection.LogEntryCollection";
1560 asyncResp->res.jsonValue["@odata.id"] =
1561 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1562 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1563 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1564 asyncResp->res.jsonValue["Description"] =
1565 "Collection of System Event Log Entries";
1566
1567 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1568 logEntryArray = nlohmann::json::array();
1569 // Go through the log files and create a unique ID for each
1570 // entry
1571 std::vector<std::filesystem::path> redfishLogFiles;
1572 getRedfishLogFiles(redfishLogFiles);
1573 uint64_t entryCount = 0;
1574 std::string logEntry;
1575
1576 // Oldest logs are in the last file, so start there and loop
1577 // backwards
1578 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++)
1579 {
1580 std::ifstream logStream(*it);
1581 if (!logStream.is_open())
Ed Tanous002d39b2022-05-31 08:59:27 -07001582 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001583 continue;
Ed Tanous22d268c2022-05-19 09:39:07 -07001584 }
1585
Alexander Hansen599b9af2024-08-06 15:11:57 +02001586 // Reset the unique ID on the first entry
1587 bool firstEntry = true;
1588 while (std::getline(logStream, logEntry))
Ed Tanous002d39b2022-05-31 08:59:27 -07001589 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001590 std::string idStr;
1591 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1592 {
1593 continue;
1594 }
1595 firstEntry = false;
1596
1597 nlohmann::json::object_t bmcLogEntry;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001598 LogParseError status =
1599 fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
Alexander Hansen599b9af2024-08-06 15:11:57 +02001600 if (status == LogParseError::messageIdNotInRegistry)
1601 {
1602 continue;
1603 }
1604 if (status != LogParseError::success)
1605 {
1606 messages::internalError(asyncResp->res);
1607 return;
1608 }
1609
1610 entryCount++;
1611 // Handle paging using skip (number of entries to skip from the
1612 // start) and top (number of entries to display)
1613 if (entryCount <= skip || entryCount > skip + top)
Jason M. Bills4978b632022-02-22 14:17:43 -08001614 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001615 continue;
Jason M. Bills4978b632022-02-22 14:17:43 -08001616 }
Jason M. Bills897967d2019-07-29 17:05:30 -07001617
Alexander Hansen599b9af2024-08-06 15:11:57 +02001618 logEntryArray.emplace_back(std::move(bmcLogEntry));
1619 }
1620 }
1621 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1622 if (skip + top < entryCount)
1623 {
1624 asyncResp->res.jsonValue["Members@odata.nextLink"] =
1625 boost::urls::format(
1626 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}",
1627 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top));
1628 }
1629}
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001630
Alexander Hansen599b9af2024-08-06 15:11:57 +02001631inline void requestRoutesJournalEventLogEntryCollection(App& app)
1632{
1633 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
1634 .privileges(redfish::privileges::getLogEntryCollection)
1635 .methods(boost::beast::http::verb::get)(std::bind_front(
1636 handleSystemsLogServiceEventLogLogEntryCollection, std::ref(app)));
1637}
1638
1639inline void handleSystemsLogServiceEventLogEntriesGet(
1640 App& app, const crow::Request& req,
1641 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1642 const std::string& systemName, const std::string& param)
1643{
1644 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1645 {
1646 return;
1647 }
1648 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1649 {
1650 // Option currently returns no systems. TBD
1651 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1652 systemName);
1653 return;
1654 }
1655
1656 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1657 {
1658 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1659 systemName);
1660 return;
1661 }
1662
1663 const std::string& targetID = param;
1664
1665 // Go through the log files and check the unique ID for each
1666 // entry to find the target entry
1667 std::vector<std::filesystem::path> redfishLogFiles;
1668 getRedfishLogFiles(redfishLogFiles);
1669 std::string logEntry;
1670
1671 // Oldest logs are in the last file, so start there and loop
1672 // backwards
1673 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++)
1674 {
1675 std::ifstream logStream(*it);
1676 if (!logStream.is_open())
1677 {
1678 continue;
1679 }
1680
1681 // Reset the unique ID on the first entry
1682 bool firstEntry = true;
1683 while (std::getline(logStream, logEntry))
1684 {
1685 std::string idStr;
1686 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1687 {
1688 continue;
1689 }
1690 firstEntry = false;
1691
1692 if (idStr == targetID)
1693 {
Jason M. Billsde703c52022-06-23 14:19:04 -07001694 nlohmann::json::object_t bmcLogEntry;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001695 LogParseError status =
1696 fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001697 if (status != LogParseError::success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001698 {
1699 messages::internalError(asyncResp->res);
1700 return;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001701 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001702 asyncResp->res.jsonValue.update(bmcLogEntry);
1703 return;
Jason M. Bills4978b632022-02-22 14:17:43 -08001704 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001705 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001706 }
1707 // Requested ID was not found
1708 messages::resourceNotFound(asyncResp->res, "LogEntry", targetID);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001709}
Chicago Duan336e96c2019-07-15 14:22:08 +08001710
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001711inline void requestRoutesJournalEventLogEntry(App& app)
1712{
1713 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001714 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001715 .privileges(redfish::privileges::getLogEntry)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001716 .methods(boost::beast::http::verb::get)(std::bind_front(
1717 handleSystemsLogServiceEventLogEntriesGet, std::ref(app)));
1718}
1719
1720inline void dBusEventLogEntryCollection(
1721 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1722{
1723 // Collections don't include the static data added by SubRoute
1724 // because it has a duplicate entry for members
1725 asyncResp->res.jsonValue["@odata.type"] =
1726 "#LogEntryCollection.LogEntryCollection";
1727 asyncResp->res.jsonValue["@odata.id"] =
1728 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1729 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1730 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1731 asyncResp->res.jsonValue["Description"] =
1732 "Collection of System Event Log Entries";
1733
1734 // DBus implementation of EventLog/Entries
1735 // Make call to Logging Service to find all log entry objects
1736 sdbusplus::message::object_path path("/xyz/openbmc_project/logging");
1737 dbus::utility::getManagedObjects(
1738 "xyz.openbmc_project.Logging", path,
1739 [asyncResp](const boost::system::error_code& ec,
1740 const dbus::utility::ManagedObjectType& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001741 afterLogEntriesGetManagedObjects(asyncResp, ec, resp);
1742 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001743}
1744
1745inline void requestRoutesDBusEventLogEntryCollection(App& app)
1746{
Ed Tanous22d268c2022-05-19 09:39:07 -07001747 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07001748 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001749 .methods(boost::beast::http::verb::get)(
1750 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001751 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1752 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001753 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1754 {
1755 return;
1756 }
1757 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1758 {
1759 // Option currently returns no systems. TBD
1760 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1761 systemName);
1762 return;
1763 }
1764 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1765 {
1766 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1767 systemName);
1768 return;
1769 }
1770 dBusEventLogEntryCollection(asyncResp);
1771 });
Alexander Hansen599b9af2024-08-06 15:11:57 +02001772}
Ed Tanous22d268c2022-05-19 09:39:07 -07001773
Myung Baec6b7cae2025-06-05 15:46:57 -05001774inline void afterDBusEventLogEntryGet(
1775 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1776 const std::string& entryID, const boost::system::error_code& ec,
1777 const dbus::utility::DBusPropertiesMap& resp)
1778{
1779 if (ec.value() == EBADR)
1780 {
1781 messages::resourceNotFound(asyncResp->res, "EventLogEntry", entryID);
1782 return;
1783 }
1784 if (ec)
1785 {
1786 BMCWEB_LOG_ERROR("EventLogEntry (DBus) resp_handler got error {}", ec);
1787 messages::internalError(asyncResp->res);
1788 return;
1789 }
1790
Myung Bae7f3726a2025-04-26 15:17:23 -05001791 std::optional<DbusEventLogEntry> optEntry =
1792 fillDbusEventLogEntryFromPropertyMap(resp);
1793
1794 if (!optEntry.has_value())
1795 {
1796 messages::internalError(asyncResp->res);
1797 return;
1798 }
1799
1800 fillEventLogLogEntryFromDbusLogEntry(*optEntry, asyncResp->res.jsonValue);
Myung Baec6b7cae2025-06-05 15:46:57 -05001801}
1802
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001803inline void dBusEventLogEntryGet(
1804 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001805{
1806 dbus::utility::escapePathForDbus(entryID);
Ed Tanous002d39b2022-05-31 08:59:27 -07001807
Alexander Hansen599b9af2024-08-06 15:11:57 +02001808 // DBus implementation of EventLog/Entries
1809 // Make call to Logging Service to find all log entry objects
Ed Tanousdeae6a72024-11-11 21:58:57 -08001810 dbus::utility::getAllProperties(
1811 "xyz.openbmc_project.Logging",
Alexander Hansen599b9af2024-08-06 15:11:57 +02001812 "/xyz/openbmc_project/logging/entry/" + entryID, "",
Myung Baec6b7cae2025-06-05 15:46:57 -05001813 std::bind_front(afterDBusEventLogEntryGet, asyncResp, entryID));
Alexander Hansen599b9af2024-08-06 15:11:57 +02001814}
1815
Patrick Williams504af5a2025-02-03 14:29:03 -05001816inline void dBusEventLogEntryPatch(
1817 const crow::Request& req,
1818 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1819 const std::string& entryId)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001820{
1821 std::optional<bool> resolved;
1822
1823 if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", resolved))
1824 {
1825 return;
1826 }
1827 BMCWEB_LOG_DEBUG("Set Resolved");
1828
1829 setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging",
1830 "/xyz/openbmc_project/logging/entry/" + entryId,
1831 "xyz.openbmc_project.Logging.Entry", "Resolved",
1832 resolved.value_or(false));
1833}
1834
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001835inline void dBusEventLogEntryDelete(
1836 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001837{
1838 BMCWEB_LOG_DEBUG("Do delete single event entries.");
1839
1840 dbus::utility::escapePathForDbus(entryID);
1841
1842 // Process response from Logging service.
1843 auto respHandler = [asyncResp,
1844 entryID](const boost::system::error_code& ec) {
1845 BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done");
1846 if (ec)
1847 {
1848 if (ec.value() == EBADR)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001849 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001850 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001851 return;
1852 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001853 // TODO Handle for specific error code
1854 BMCWEB_LOG_ERROR(
1855 "EventLogEntry (DBus) doDelete respHandler got error {}", ec);
1856 asyncResp->res.result(
1857 boost::beast::http::status::internal_server_error);
1858 return;
1859 }
Abhishek Patel9017faf2021-09-14 22:48:55 -05001860
Alexander Hansen599b9af2024-08-06 15:11:57 +02001861 asyncResp->res.result(boost::beast::http::status::ok);
1862 };
1863
1864 // Make call to Logging service to request Delete Log
Ed Tanous177612a2025-02-14 15:16:09 -08001865 dbus::utility::async_method_call(
1866 asyncResp, respHandler, "xyz.openbmc_project.Logging",
Alexander Hansen599b9af2024-08-06 15:11:57 +02001867 "/xyz/openbmc_project/logging/entry/" + entryID,
1868 "xyz.openbmc_project.Object.Delete", "Delete");
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001869}
Xiaochao Ma75710de2021-01-21 17:56:02 +08001870
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001871inline void requestRoutesDBusEventLogEntry(App& app)
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001872{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001873 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001874 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001875 .privileges(redfish::privileges::getLogEntry)
Ed Tanous002d39b2022-05-31 08:59:27 -07001876 .methods(boost::beast::http::verb::get)(
1877 [&app](const crow::Request& req,
1878 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous898f2aa2024-08-07 12:18:22 -07001879 const std::string& systemName, const std::string& entryId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001880 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1881 {
1882 return;
1883 }
1884 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1885 {
1886 // Option currently returns no systems. TBD
1887 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1888 systemName);
1889 return;
1890 }
1891 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1892 {
1893 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1894 systemName);
1895 return;
1896 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001897
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001898 dBusEventLogEntryGet(asyncResp, entryId);
1899 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001900
1901 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001902 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001903 .privileges(redfish::privileges::patchLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001904 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001905 [&app](const crow::Request& req,
1906 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001907 const std::string& systemName, const std::string& entryId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001908 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1909 {
1910 return;
1911 }
1912 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1913 {
1914 // Option currently returns no systems. TBD
1915 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1916 systemName);
1917 return;
1918 }
1919 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1920 {
1921 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1922 systemName);
1923 return;
1924 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001925
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001926 dBusEventLogEntryPatch(req, asyncResp, entryId);
1927 });
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001928
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001929 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001930 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Abhishek Patelfff6a4d2021-07-21 11:29:45 -05001931 .privileges(
1932 redfish::privileges::
1933 deleteLogEntrySubOverComputerSystemLogServiceCollectionLogServiceLogEntryCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001934 .methods(boost::beast::http::verb::delete_)(
1935 [&app](const crow::Request& req,
1936 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001937 const std::string& systemName, const std::string& param) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001938 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1939 {
1940 return;
1941 }
1942 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1943 {
1944 // Option currently returns no systems. TBD
1945 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1946 systemName);
1947 return;
1948 }
1949 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1950 {
1951 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1952 systemName);
1953 return;
1954 }
1955 dBusEventLogEntryDelete(asyncResp, param);
1956 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001957}
1958
Claire Weinandd72e872022-08-15 14:20:06 -07001959inline void handleBMCLogServicesCollectionGet(
Claire Weinanfdd26902022-03-01 14:18:25 -08001960 crow::App& app, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07001961 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1962 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08001963{
1964 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1965 {
1966 return;
1967 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001968
1969 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
1970 {
1971 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
1972 return;
1973 }
1974
Claire Weinanfdd26902022-03-01 14:18:25 -08001975 // Collections don't include the static data added by SubRoute
1976 // because it has a duplicate entry for members
1977 asyncResp->res.jsonValue["@odata.type"] =
1978 "#LogServiceCollection.LogServiceCollection";
Ed Tanous253f11b2024-05-16 09:38:31 -07001979 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1980 "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -08001981 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1982 asyncResp->res.jsonValue["Description"] =
1983 "Collection of LogServices for this Manager";
1984 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1985 logServiceArray = nlohmann::json::array();
1986
Ed Tanous25b54db2024-04-17 15:40:31 -07001987 if constexpr (BMCWEB_REDFISH_BMC_JOURNAL)
1988 {
1989 nlohmann::json::object_t journal;
Ed Tanous253f11b2024-05-16 09:38:31 -07001990 journal["@odata.id"] =
1991 boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal",
1992 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001993 logServiceArray.emplace_back(std::move(journal));
1994 }
Claire Weinanfdd26902022-03-01 14:18:25 -08001995
1996 asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
1997
Ed Tanous25b54db2024-04-17 15:40:31 -07001998 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
1999 {
2000 constexpr std::array<std::string_view, 1> interfaces = {
2001 "xyz.openbmc_project.Collection.DeleteAll"};
2002 dbus::utility::getSubTreePaths(
2003 "/xyz/openbmc_project/dump", 0, interfaces,
2004 [asyncResp](const boost::system::error_code& ec,
2005 const dbus::utility::MapperGetSubTreePathsResponse&
2006 subTreePaths) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002007 if (ec)
Ed Tanous25b54db2024-04-17 15:40:31 -07002008 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002009 BMCWEB_LOG_ERROR(
2010 "handleBMCLogServicesCollectionGet respHandler got error {}",
2011 ec);
2012 // Assume that getting an error simply means there are no
2013 // dump LogServices. Return without adding any error
2014 // response.
2015 return;
Ed Tanous25b54db2024-04-17 15:40:31 -07002016 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002017
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002018 nlohmann::json& logServiceArrayLocal =
2019 asyncResp->res.jsonValue["Members"];
2020
2021 for (const std::string& path : subTreePaths)
2022 {
2023 if (path == "/xyz/openbmc_project/dump/bmc")
2024 {
2025 nlohmann::json::object_t member;
2026 member["@odata.id"] = boost::urls::format(
2027 "/redfish/v1/Managers/{}/LogServices/Dump",
2028 BMCWEB_REDFISH_MANAGER_URI_NAME);
2029 logServiceArrayLocal.emplace_back(std::move(member));
2030 }
2031 else if (path == "/xyz/openbmc_project/dump/faultlog")
2032 {
2033 nlohmann::json::object_t member;
2034 member["@odata.id"] = boost::urls::format(
2035 "/redfish/v1/Managers/{}/LogServices/FaultLog",
2036 BMCWEB_REDFISH_MANAGER_URI_NAME);
2037 logServiceArrayLocal.emplace_back(std::move(member));
2038 }
2039 }
2040
2041 asyncResp->res.jsonValue["Members@odata.count"] =
2042 logServiceArrayLocal.size();
2043 });
Ed Tanous25b54db2024-04-17 15:40:31 -07002044 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002045}
2046
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002047inline void requestRoutesBMCLogServiceCollection(App& app)
2048{
Ed Tanous253f11b2024-05-16 09:38:31 -07002049 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/")
Gunnar Millsad89dcf2021-07-30 14:40:11 -05002050 .privileges(redfish::privileges::getLogServiceCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002051 .methods(boost::beast::http::verb::get)(
Claire Weinandd72e872022-08-15 14:20:06 -07002052 std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002053}
Ed Tanous1da66f72018-07-27 16:13:37 -07002054
Patrick Williams504af5a2025-02-03 14:29:03 -05002055inline void getDumpServiceInfo(
2056 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2057 const std::string& dumpType)
Claire Weinanfdd26902022-03-01 14:18:25 -08002058{
2059 std::string dumpPath;
Ed Tanous539d8c62024-06-19 14:38:27 -07002060 log_service::OverWritePolicy overWritePolicy =
2061 log_service::OverWritePolicy::Invalid;
Claire Weinanfdd26902022-03-01 14:18:25 -08002062 bool collectDiagnosticDataSupported = false;
2063
2064 if (dumpType == "BMC")
2065 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002066 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump",
2067 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002068 overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
Claire Weinanfdd26902022-03-01 14:18:25 -08002069 collectDiagnosticDataSupported = true;
2070 }
2071 else if (dumpType == "FaultLog")
2072 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002073 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog",
2074 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002075 overWritePolicy = log_service::OverWritePolicy::Unknown;
Claire Weinanfdd26902022-03-01 14:18:25 -08002076 collectDiagnosticDataSupported = false;
2077 }
2078 else if (dumpType == "System")
2079 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002080 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump",
2081 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002082 overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
Claire Weinanfdd26902022-03-01 14:18:25 -08002083 collectDiagnosticDataSupported = true;
2084 }
2085 else
2086 {
Ed Tanous62598e32023-07-17 17:06:25 -07002087 BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}",
2088 dumpType);
Claire Weinanfdd26902022-03-01 14:18:25 -08002089 messages::internalError(asyncResp->res);
2090 return;
2091 }
2092
2093 asyncResp->res.jsonValue["@odata.id"] = dumpPath;
2094 asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService";
2095 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2096 asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService";
2097 asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename();
Ed Tanous539d8c62024-06-19 14:38:27 -07002098 asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy;
Claire Weinanfdd26902022-03-01 14:18:25 -08002099
2100 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002101 redfish::time_utils::getDateTimeOffsetNow();
Claire Weinanfdd26902022-03-01 14:18:25 -08002102 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2103 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2104 redfishDateTimeOffset.second;
2105
2106 asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries";
Claire Weinanfdd26902022-03-01 14:18:25 -08002107
2108 if (collectDiagnosticDataSupported)
2109 {
2110 asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2111 ["target"] =
2112 dumpPath + "/Actions/LogService.CollectDiagnosticData";
2113 }
Claire Weinan0d946212022-07-13 19:40:19 -07002114
2115 constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface};
2116 dbus::utility::getSubTreePaths(
2117 "/xyz/openbmc_project/dump", 0, interfaces,
2118 [asyncResp, dumpType, dumpPath](
2119 const boost::system::error_code& ec,
2120 const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002121 if (ec)
Claire Weinan0d946212022-07-13 19:40:19 -07002122 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002123 BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}",
2124 ec);
2125 // Assume that getting an error simply means there are no dump
2126 // LogServices. Return without adding any error response.
2127 return;
Claire Weinan0d946212022-07-13 19:40:19 -07002128 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002129 std::string dbusDumpPath = getDumpPath(dumpType);
2130 for (const std::string& path : subTreePaths)
2131 {
2132 if (path == dbusDumpPath)
2133 {
2134 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2135 ["target"] =
2136 dumpPath + "/Actions/LogService.ClearLog";
2137 break;
2138 }
2139 }
2140 });
Claire Weinanfdd26902022-03-01 14:18:25 -08002141}
2142
2143inline void handleLogServicesDumpServiceGet(
2144 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002145 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2146 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002147{
2148 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2149 {
2150 return;
2151 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002152
2153 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2154 {
2155 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2156 return;
2157 }
2158
Claire Weinanfdd26902022-03-01 14:18:25 -08002159 getDumpServiceInfo(asyncResp, dumpType);
2160}
2161
Ed Tanous22d268c2022-05-19 09:39:07 -07002162inline void handleLogServicesDumpServiceComputerSystemGet(
2163 crow::App& app, const crow::Request& req,
2164 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2165 const std::string& chassisId)
2166{
2167 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2168 {
2169 return;
2170 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002171 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002172 {
2173 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2174 return;
2175 }
2176 getDumpServiceInfo(asyncResp, "System");
2177}
2178
Claire Weinanfdd26902022-03-01 14:18:25 -08002179inline void handleLogServicesDumpEntriesCollectionGet(
2180 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002181 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2182 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002183{
2184 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2185 {
2186 return;
2187 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002188
2189 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2190 {
2191 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2192 return;
2193 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002194 getDumpEntryCollection(asyncResp, dumpType);
2195}
2196
Ed Tanous22d268c2022-05-19 09:39:07 -07002197inline void handleLogServicesDumpEntriesCollectionComputerSystemGet(
2198 crow::App& app, const crow::Request& req,
2199 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2200 const std::string& chassisId)
2201{
2202 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2203 {
2204 return;
2205 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002206 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002207 {
2208 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2209 return;
2210 }
2211 getDumpEntryCollection(asyncResp, "System");
2212}
2213
Claire Weinanfdd26902022-03-01 14:18:25 -08002214inline void handleLogServicesDumpEntryGet(
2215 crow::App& app, const std::string& dumpType, const crow::Request& req,
2216 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002217 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002218{
2219 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2220 {
2221 return;
2222 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002223 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2224 {
2225 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2226 return;
2227 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002228 getDumpEntryById(asyncResp, dumpId, dumpType);
2229}
Carson Labrado168d1b12023-03-27 17:04:46 +00002230
Ed Tanous22d268c2022-05-19 09:39:07 -07002231inline void handleLogServicesDumpEntryComputerSystemGet(
2232 crow::App& app, const crow::Request& req,
2233 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2234 const std::string& chassisId, const std::string& dumpId)
2235{
2236 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2237 {
2238 return;
2239 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002240 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002241 {
2242 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2243 return;
2244 }
2245 getDumpEntryById(asyncResp, dumpId, "System");
2246}
Claire Weinanfdd26902022-03-01 14:18:25 -08002247
2248inline void handleLogServicesDumpEntryDelete(
2249 crow::App& app, const std::string& dumpType, const crow::Request& req,
2250 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002251 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002252{
2253 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2254 {
2255 return;
2256 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002257
2258 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2259 {
2260 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2261 return;
2262 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002263 deleteDumpEntry(asyncResp, dumpId, dumpType);
2264}
2265
Ed Tanous22d268c2022-05-19 09:39:07 -07002266inline void handleLogServicesDumpEntryComputerSystemDelete(
2267 crow::App& app, const crow::Request& req,
2268 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2269 const std::string& chassisId, const std::string& dumpId)
2270{
2271 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2272 {
2273 return;
2274 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002275 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002276 {
2277 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2278 return;
2279 }
2280 deleteDumpEntry(asyncResp, dumpId, "System");
2281}
2282
Carson Labrado168d1b12023-03-27 17:04:46 +00002283inline void handleLogServicesDumpEntryDownloadGet(
2284 crow::App& app, const std::string& dumpType, const crow::Request& req,
2285 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002286 const std::string& managerId, const std::string& dumpId)
Carson Labrado168d1b12023-03-27 17:04:46 +00002287{
2288 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2289 {
2290 return;
2291 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002292
2293 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2294 {
2295 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2296 return;
2297 }
Carson Labrado168d1b12023-03-27 17:04:46 +00002298 downloadDumpEntry(asyncResp, dumpId, dumpType);
2299}
2300
2301inline void handleDBusEventLogEntryDownloadGet(
2302 crow::App& app, const std::string& dumpType, const crow::Request& req,
2303 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2304 const std::string& systemName, const std::string& entryID)
2305{
2306 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2307 {
2308 return;
2309 }
2310 if (!http_helpers::isContentTypeAllowed(
2311 req.getHeaderValue("Accept"),
2312 http_helpers::ContentType::OctetStream, true))
2313 {
2314 asyncResp->res.result(boost::beast::http::status::bad_request);
2315 return;
2316 }
2317 downloadEventLogEntry(asyncResp, systemName, entryID, dumpType);
2318}
2319
Claire Weinanfdd26902022-03-01 14:18:25 -08002320inline void handleLogServicesDumpCollectDiagnosticDataPost(
2321 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002322 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2323 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002324{
2325 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2326 {
2327 return;
2328 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002329 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 createDump(asyncResp, req, dumpType);
2336}
2337
Ed Tanous22d268c2022-05-19 09:39:07 -07002338inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost(
2339 crow::App& app, const crow::Request& req,
2340 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002341 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002342{
2343 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2344 {
2345 return;
2346 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002347
Ed Tanous25b54db2024-04-17 15:40:31 -07002348 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002349 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002350 // Option currently returns no systems. TBD
2351 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2352 systemName);
2353 return;
2354 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002355 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002356 {
2357 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2358 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002359 return;
2360 }
2361 createDump(asyncResp, req, "System");
2362}
2363
Claire Weinanfdd26902022-03-01 14:18:25 -08002364inline void handleLogServicesDumpClearLogPost(
2365 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002366 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2367 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002368{
2369 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2370 {
2371 return;
2372 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002373
2374 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2375 {
2376 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2377 return;
2378 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002379 clearDump(asyncResp, dumpType);
2380}
2381
Ed Tanous22d268c2022-05-19 09:39:07 -07002382inline void handleLogServicesDumpClearLogComputerSystemPost(
2383 crow::App& app, const crow::Request& req,
2384 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002385 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002386{
2387 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2388 {
2389 return;
2390 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002391 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002392 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002393 // Option currently returns no systems. TBD
2394 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2395 systemName);
2396 return;
2397 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002398 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002399 {
2400 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2401 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002402 return;
2403 }
2404 clearDump(asyncResp, "System");
2405}
2406
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002407inline void requestRoutesBMCDumpService(App& app)
2408{
Ed Tanous253f11b2024-05-16 09:38:31 -07002409 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002410 .privileges(redfish::privileges::getLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002411 .methods(boost::beast::http::verb::get)(std::bind_front(
2412 handleLogServicesDumpServiceGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002413}
2414
2415inline void requestRoutesBMCDumpEntryCollection(App& app)
2416{
Ed Tanous253f11b2024-05-16 09:38:31 -07002417 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002418 .privileges(redfish::privileges::getLogEntryCollection)
Claire Weinanfdd26902022-03-01 14:18:25 -08002419 .methods(boost::beast::http::verb::get)(std::bind_front(
2420 handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002421}
2422
2423inline void requestRoutesBMCDumpEntry(App& app)
2424{
2425 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002426 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002427 .privileges(redfish::privileges::getLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002428 .methods(boost::beast::http::verb::get)(std::bind_front(
2429 handleLogServicesDumpEntryGet, std::ref(app), "BMC"));
2430
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002431 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002432 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002433 .privileges(redfish::privileges::deleteLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002434 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2435 handleLogServicesDumpEntryDelete, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002436}
2437
Carson Labrado168d1b12023-03-27 17:04:46 +00002438inline void requestRoutesBMCDumpEntryDownload(App& app)
2439{
2440 BMCWEB_ROUTE(
2441 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002442 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002443 .privileges(redfish::privileges::getLogEntry)
2444 .methods(boost::beast::http::verb::get)(std::bind_front(
2445 handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC"));
2446}
2447
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002448inline void requestRoutesBMCDumpCreate(App& app)
2449{
George Liu0fda0f12021-11-16 10:06:17 +08002450 BMCWEB_ROUTE(
2451 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002452 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002453 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002454 .methods(boost::beast::http::verb::post)(
Claire Weinanfdd26902022-03-01 14:18:25 -08002455 std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost,
2456 std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002457}
2458
2459inline void requestRoutesBMCDumpClear(App& app)
2460{
George Liu0fda0f12021-11-16 10:06:17 +08002461 BMCWEB_ROUTE(
2462 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002463 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002464 .privileges(redfish::privileges::postLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002465 .methods(boost::beast::http::verb::post)(std::bind_front(
2466 handleLogServicesDumpClearLogPost, std::ref(app), "BMC"));
2467}
2468
Carson Labrado168d1b12023-03-27 17:04:46 +00002469inline void requestRoutesDBusEventLogEntryDownload(App& app)
2470{
2471 BMCWEB_ROUTE(
2472 app,
Ravi Teja9e9d99d2023-11-08 05:33:59 -06002473 "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002474 .privileges(redfish::privileges::getLogEntry)
2475 .methods(boost::beast::http::verb::get)(std::bind_front(
2476 handleDBusEventLogEntryDownloadGet, std::ref(app), "System"));
2477}
2478
Claire Weinanfdd26902022-03-01 14:18:25 -08002479inline void requestRoutesFaultLogDumpService(App& app)
2480{
Ed Tanous253f11b2024-05-16 09:38:31 -07002481 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002482 .privileges(redfish::privileges::getLogService)
2483 .methods(boost::beast::http::verb::get)(std::bind_front(
2484 handleLogServicesDumpServiceGet, std::ref(app), "FaultLog"));
2485}
2486
2487inline void requestRoutesFaultLogDumpEntryCollection(App& app)
2488{
Ed Tanous253f11b2024-05-16 09:38:31 -07002489 BMCWEB_ROUTE(app,
2490 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002491 .privileges(redfish::privileges::getLogEntryCollection)
2492 .methods(boost::beast::http::verb::get)(
2493 std::bind_front(handleLogServicesDumpEntriesCollectionGet,
2494 std::ref(app), "FaultLog"));
2495}
2496
2497inline void requestRoutesFaultLogDumpEntry(App& app)
2498{
Ed Tanous253f11b2024-05-16 09:38:31 -07002499 BMCWEB_ROUTE(
2500 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002501 .privileges(redfish::privileges::getLogEntry)
2502 .methods(boost::beast::http::verb::get)(std::bind_front(
2503 handleLogServicesDumpEntryGet, std::ref(app), "FaultLog"));
2504
Ed Tanous253f11b2024-05-16 09:38:31 -07002505 BMCWEB_ROUTE(
2506 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002507 .privileges(redfish::privileges::deleteLogEntry)
2508 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2509 handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog"));
2510}
2511
2512inline void requestRoutesFaultLogDumpClear(App& app)
2513{
2514 BMCWEB_ROUTE(
2515 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002516 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002517 .privileges(redfish::privileges::postLogService)
2518 .methods(boost::beast::http::verb::post)(std::bind_front(
2519 handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002520}
2521
2522inline void requestRoutesSystemDumpService(App& app)
2523{
Ed Tanous22d268c2022-05-19 09:39:07 -07002524 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002525 .privileges(redfish::privileges::getLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002526 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002527 handleLogServicesDumpServiceComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002528}
2529
2530inline void requestRoutesSystemDumpEntryCollection(App& app)
2531{
Ed Tanous22d268c2022-05-19 09:39:07 -07002532 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002533 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous22d268c2022-05-19 09:39:07 -07002534 .methods(boost::beast::http::verb::get)(std::bind_front(
2535 handleLogServicesDumpEntriesCollectionComputerSystemGet,
2536 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002537}
2538
2539inline void requestRoutesSystemDumpEntry(App& app)
2540{
2541 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002542 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002543 .privileges(redfish::privileges::getLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002544 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002545 handleLogServicesDumpEntryComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002546
2547 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002548 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002549 .privileges(redfish::privileges::deleteLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002550 .methods(boost::beast::http::verb::delete_)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002551 handleLogServicesDumpEntryComputerSystemDelete, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002552}
2553
2554inline void requestRoutesSystemDumpCreate(App& app)
2555{
George Liu0fda0f12021-11-16 10:06:17 +08002556 BMCWEB_ROUTE(
2557 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002558 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Abhishek Patelfff6a4d2021-07-21 11:29:45 -05002559 .privileges(redfish::privileges::
2560 postLogServiceSubOverComputerSystemLogServiceCollection)
Ed Tanous22d268c2022-05-19 09:39:07 -07002561 .methods(boost::beast::http::verb::post)(std::bind_front(
2562 handleLogServicesDumpCollectDiagnosticDataComputerSystemPost,
2563 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002564}
2565
2566inline void requestRoutesSystemDumpClear(App& app)
2567{
George Liu0fda0f12021-11-16 10:06:17 +08002568 BMCWEB_ROUTE(
2569 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002570 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Abhishek Patelfff6a4d2021-07-21 11:29:45 -05002571 .privileges(redfish::privileges::
2572 postLogServiceSubOverComputerSystemLogServiceCollection)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002573 .methods(boost::beast::http::verb::post)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002574 handleLogServicesDumpClearLogComputerSystemPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002575}
2576
2577inline void requestRoutesCrashdumpService(App& app)
2578{
2579 // Note: Deviated from redfish privilege registry for GET & HEAD
2580 // method for security reasons.
2581 /**
2582 * Functions triggers appropriate requests on DBus
2583 */
Ed Tanous22d268c2022-05-19 09:39:07 -07002584 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/")
Ed Tanoused398212021-06-09 17:05:54 -07002585 // This is incorrect, should be:
2586 //.privileges(redfish::privileges::getLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002587 .privileges({{"ConfigureManager"}})
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002588 .methods(
2589 boost::beast::http::verb::
2590 get)([&app](const crow::Request& req,
2591 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2592 const std::string& systemName) {
2593 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2594 {
2595 return;
2596 }
2597 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2598 {
2599 // Option currently returns no systems. TBD
2600 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2601 systemName);
2602 return;
2603 }
2604 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2605 {
2606 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2607 systemName);
2608 return;
2609 }
Ed Tanous22d268c2022-05-19 09:39:07 -07002610
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002611 // Copy over the static data to include the entries added by
2612 // SubRoute
2613 asyncResp->res.jsonValue["@odata.id"] =
2614 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
2615 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2616 asyncResp->res.jsonValue["@odata.type"] =
2617 "#LogService.v1_2_0.LogService";
2618 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2619 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
2620 asyncResp->res.jsonValue["Id"] = "Crashdump";
2621 asyncResp->res.jsonValue["OverWritePolicy"] =
2622 log_service::OverWritePolicy::WrapsWhenFull;
2623 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302624
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002625 std::pair<std::string, std::string> redfishDateTimeOffset =
2626 redfish::time_utils::getDateTimeOffsetNow();
2627 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2628 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2629 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302630
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002631 asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format(
2632 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2633 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2634 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2635 ["target"] = std::format(
2636 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog",
2637 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2638 asyncResp->res
2639 .jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2640 ["target"] = std::format(
2641 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData",
2642 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2643 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002644}
2645
2646void inline requestRoutesCrashdumpClear(App& app)
2647{
George Liu0fda0f12021-11-16 10:06:17 +08002648 BMCWEB_ROUTE(
2649 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002650 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002651 // This is incorrect, should be:
2652 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002653 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002654 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002655 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002656 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2657 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002658 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2659 {
2660 return;
2661 }
2662 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2663 {
2664 // Option currently returns no systems. TBD
2665 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2666 systemName);
2667 return;
2668 }
2669 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2670 {
2671 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2672 systemName);
2673 return;
2674 }
Ed Tanous177612a2025-02-14 15:16:09 -08002675 dbus::utility::async_method_call(
2676 asyncResp,
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002677 [asyncResp](const boost::system::error_code& ec,
2678 const std::string&) {
2679 if (ec)
2680 {
2681 messages::internalError(asyncResp->res);
2682 return;
2683 }
2684 messages::success(asyncResp->res);
2685 },
2686 crashdumpObject, crashdumpPath, deleteAllInterface,
2687 "DeleteAll");
2688 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002689}
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002690
Patrick Williams504af5a2025-02-03 14:29:03 -05002691inline void logCrashdumpEntry(
2692 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2693 const std::string& logID, nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07002694{
Johnathan Mantey043a0532020-03-10 17:15:28 -07002695 auto getStoredLogCallback =
Ed Tanousb9d36b42022-02-26 21:42:46 -08002696 [asyncResp, logID,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002697 &logEntryJson](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002698 const dbus::utility::DBusPropertiesMap& params) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002699 if (ec)
2700 {
2701 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
2702 if (ec.value() ==
2703 boost::system::linux_error::bad_request_descriptor)
2704 {
2705 messages::resourceNotFound(asyncResp->res, "LogEntry",
2706 logID);
2707 }
2708 else
2709 {
2710 messages::internalError(asyncResp->res);
2711 }
2712 return;
2713 }
2714
2715 std::string timestamp{};
2716 std::string filename{};
2717 std::string logfile{};
2718 parseCrashdumpParameters(params, filename, timestamp, logfile);
2719
2720 if (filename.empty() || timestamp.empty())
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002721 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002722 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002723 return;
2724 }
2725
2726 std::string crashdumpURI =
2727 std::format(
2728 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/",
2729 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
2730 logID + "/" + filename;
2731 nlohmann::json::object_t logEntry;
2732 logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
2733 logEntry["@odata.id"] = boost::urls::format(
2734 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}",
2735 BMCWEB_REDFISH_SYSTEM_URI_NAME, logID);
2736 logEntry["Name"] = "CPU Crashdump";
2737 logEntry["Id"] = logID;
2738 logEntry["EntryType"] = log_entry::LogEntryType::Oem;
2739 logEntry["AdditionalDataURI"] = std::move(crashdumpURI);
2740 logEntry["DiagnosticDataType"] = "OEM";
2741 logEntry["OEMDiagnosticDataType"] = "PECICrashdump";
2742 logEntry["Created"] = std::move(timestamp);
2743
2744 // If logEntryJson references an array of LogEntry resources
2745 // ('Members' list), then push this as a new entry, otherwise set it
2746 // directly
2747 if (logEntryJson.is_array())
2748 {
2749 logEntryJson.push_back(logEntry);
2750 asyncResp->res.jsonValue["Members@odata.count"] =
2751 logEntryJson.size();
Jason M. Bills2b20ef62022-01-06 15:48:07 -08002752 }
2753 else
2754 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002755 logEntryJson.update(logEntry);
Jason M. Bills2b20ef62022-01-06 15:48:07 -08002756 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002757 };
Ed Tanousdeae6a72024-11-11 21:58:57 -08002758 dbus::utility::getAllProperties(
2759 crashdumpObject, crashdumpPath + std::string("/") + logID,
2760 crashdumpInterface, std::move(getStoredLogCallback));
Jason M. Billse855dd22019-10-08 11:37:48 -07002761}
2762
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002763inline void requestRoutesCrashdumpEntryCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07002764{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002765 // Note: Deviated from redfish privilege registry for GET & HEAD
2766 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002767 /**
2768 * Functions triggers appropriate requests on DBus
2769 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002770 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002771 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002772 // This is incorrect, should be.
2773 //.privileges(redfish::privileges::postLogEntryCollection)
Ed Tanous432a8902021-06-14 15:28:56 -07002774 .privileges({{"ConfigureComponents"}})
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002775 .methods(
2776 boost::beast::http::verb::
2777 get)([&app](const crow::Request& req,
2778 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2779 const std::string& systemName) {
2780 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -07002781 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002782 return;
Ed Tanous45ca1b82022-03-25 13:07:27 -07002783 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002784 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07002785 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002786 // Option currently returns no systems. TBD
2787 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2788 systemName);
2789 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07002790 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002791 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2792 {
2793 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2794 systemName);
2795 return;
2796 }
2797
2798 constexpr std::array<std::string_view, 1> interfaces = {
2799 crashdumpInterface};
2800 dbus::utility::getSubTreePaths(
2801 "/", 0, interfaces,
2802 [asyncResp](const boost::system::error_code& ec,
2803 const std::vector<std::string>& resp) {
2804 if (ec)
2805 {
2806 if (ec.value() !=
2807 boost::system::errc::no_such_file_or_directory)
2808 {
2809 BMCWEB_LOG_DEBUG("failed to get entries ec: {}",
2810 ec.message());
2811 messages::internalError(asyncResp->res);
2812 return;
2813 }
2814 }
2815 asyncResp->res.jsonValue["@odata.type"] =
2816 "#LogEntryCollection.LogEntryCollection";
2817 asyncResp->res.jsonValue["@odata.id"] = std::format(
2818 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2819 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2820 asyncResp->res.jsonValue["Name"] =
2821 "Open BMC Crashdump Entries";
2822 asyncResp->res.jsonValue["Description"] =
2823 "Collection of Crashdump Entries";
2824 asyncResp->res.jsonValue["Members"] =
2825 nlohmann::json::array();
2826 asyncResp->res.jsonValue["Members@odata.count"] = 0;
2827
2828 for (const std::string& path : resp)
2829 {
2830 const sdbusplus::message::object_path objPath(path);
2831 // Get the log ID
2832 std::string logID = objPath.filename();
2833 if (logID.empty())
2834 {
2835 continue;
2836 }
2837 // Add the log entry to the array
2838 logCrashdumpEntry(asyncResp, logID,
2839 asyncResp->res.jsonValue["Members"]);
2840 }
2841 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002842 });
2843}
Ed Tanous1da66f72018-07-27 16:13:37 -07002844
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002845inline void requestRoutesCrashdumpEntry(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07002846{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002847 // Note: Deviated from redfish privilege registry for GET & HEAD
2848 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002849
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002850 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07002851 app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002852 // this is incorrect, should be
2853 // .privileges(redfish::privileges::getLogEntry)
Ed Tanous432a8902021-06-14 15:28:56 -07002854 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002855 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002856 [&app](const crow::Request& req,
2857 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07002858 const std::string& systemName, const std::string& param) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002859 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2860 {
2861 return;
2862 }
2863 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2864 {
2865 // Option currently returns no systems. TBD
2866 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2867 systemName);
2868 return;
2869 }
2870 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2871 {
2872 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2873 systemName);
2874 return;
2875 }
2876 const std::string& logID = param;
2877 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2878 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002879}
Ed Tanous1da66f72018-07-27 16:13:37 -07002880
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002881inline void requestRoutesCrashdumpFile(App& app)
2882{
2883 // Note: Deviated from redfish privilege registry for GET & HEAD
2884 // method for security reasons.
2885 BMCWEB_ROUTE(
2886 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002887 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002888 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002889 .methods(boost::beast::http::verb::get)(
Nan Zhoua4ce1142022-08-02 18:45:25 +00002890 [](const crow::Request& req,
2891 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07002892 const std::string& systemName, const std::string& logID,
2893 const std::string& fileName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002894 // Do not call getRedfishRoute here since the crashdump file is
2895 // not a Redfish resource.
Ed Tanous22d268c2022-05-19 09:39:07 -07002896
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002897 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2898 {
2899 // Option currently returns no systems. TBD
2900 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2901 systemName);
2902 return;
2903 }
2904 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2905 {
2906 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2907 systemName);
2908 return;
2909 }
Ed Tanous22d268c2022-05-19 09:39:07 -07002910
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002911 auto getStoredLogCallback =
2912 [asyncResp, logID, fileName,
2913 url(boost::urls::url(req.url()))](
2914 const boost::system::error_code& ec,
2915 const std::vector<std::pair<
2916 std::string, dbus::utility::DbusVariantType>>&
2917 resp) {
2918 if (ec)
2919 {
2920 BMCWEB_LOG_DEBUG("failed to get log ec: {}",
2921 ec.message());
2922 messages::internalError(asyncResp->res);
2923 return;
2924 }
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002925
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002926 std::string dbusFilename{};
2927 std::string dbusTimestamp{};
2928 std::string dbusFilepath{};
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002929
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002930 parseCrashdumpParameters(resp, dbusFilename,
2931 dbusTimestamp, dbusFilepath);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002932
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002933 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2934 dbusFilepath.empty())
2935 {
2936 messages::resourceNotFound(asyncResp->res,
2937 "LogEntry", logID);
2938 return;
2939 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002940
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002941 // Verify the file name parameter is correct
2942 if (fileName != dbusFilename)
2943 {
2944 messages::resourceNotFound(asyncResp->res,
2945 "LogEntry", logID);
2946 return;
2947 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002948
Myung Baed51c61b2024-09-13 10:35:34 -05002949 if (asyncResp->res.openFile(dbusFilepath) !=
2950 crow::OpenCode::Success)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002951 {
2952 messages::resourceNotFound(asyncResp->res,
2953 "LogEntry", logID);
2954 return;
2955 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002956
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002957 // Configure this to be a file download when accessed
2958 // from a browser
2959 asyncResp->res.addHeader(
2960 boost::beast::http::field::content_disposition,
2961 "attachment");
2962 };
Ed Tanousdeae6a72024-11-11 21:58:57 -08002963 dbus::utility::getAllProperties(
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002964 *crow::connections::systemBus, crashdumpObject,
2965 crashdumpPath + std::string("/") + logID,
2966 crashdumpInterface, std::move(getStoredLogCallback));
2967 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002968}
2969
Jason M. Billsc5a4c822022-01-06 15:51:23 -08002970enum class OEMDiagnosticType
2971{
2972 onDemand,
2973 telemetry,
2974 invalid,
2975};
2976
Ed Tanous26ccae32023-02-16 10:28:44 -08002977inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr)
Jason M. Billsc5a4c822022-01-06 15:51:23 -08002978{
2979 if (oemDiagStr == "OnDemand")
2980 {
2981 return OEMDiagnosticType::onDemand;
2982 }
2983 if (oemDiagStr == "Telemetry")
2984 {
2985 return OEMDiagnosticType::telemetry;
2986 }
2987
2988 return OEMDiagnosticType::invalid;
2989}
2990
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002991inline void requestRoutesCrashdumpCollect(App& app)
2992{
2993 // Note: Deviated from redfish privilege registry for GET & HEAD
2994 // method for security reasons.
George Liu0fda0f12021-11-16 10:06:17 +08002995 BMCWEB_ROUTE(
2996 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002997 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002998 // The below is incorrect; Should be ConfigureManager
2999 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07003000 .privileges({{"ConfigureComponents"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07003001 .methods(boost::beast::http::verb::post)(
3002 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003003 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3004 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003005 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003006 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003007 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07003008 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003009
3010 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07003011 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003012 // Option currently returns no systems. TBD
3013 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3014 systemName);
3015 return;
3016 }
3017 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
3018 {
3019 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3020 systemName);
3021 return;
3022 }
3023
3024 std::string diagnosticDataType;
3025 std::string oemDiagnosticDataType;
Patrick Williams504af5a2025-02-03 14:29:03 -05003026 if (!redfish::json_util::readJsonAction( //
3027 req, asyncResp->res, //
3028 "DiagnosticDataType", diagnosticDataType, //
Myung Baeafc474a2024-10-09 00:53:29 -07003029 "OEMDiagnosticDataType", oemDiagnosticDataType //
3030 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003031 {
3032 return;
3033 }
3034
3035 if (diagnosticDataType != "OEM")
3036 {
3037 BMCWEB_LOG_ERROR(
3038 "Only OEM DiagnosticDataType supported for Crashdump");
3039 messages::actionParameterValueFormatError(
3040 asyncResp->res, diagnosticDataType,
3041 "DiagnosticDataType", "CollectDiagnosticData");
3042 return;
3043 }
3044
3045 OEMDiagnosticType oemDiagType =
3046 getOEMDiagnosticType(oemDiagnosticDataType);
3047
3048 std::string iface;
3049 std::string method;
3050 std::string taskMatchStr;
3051 if (oemDiagType == OEMDiagnosticType::onDemand)
3052 {
3053 iface = crashdumpOnDemandInterface;
3054 method = "GenerateOnDemandLog";
3055 taskMatchStr =
3056 "type='signal',"
3057 "interface='org.freedesktop.DBus.Properties',"
3058 "member='PropertiesChanged',"
3059 "arg0namespace='com.intel.crashdump'";
3060 }
3061 else if (oemDiagType == OEMDiagnosticType::telemetry)
3062 {
3063 iface = crashdumpTelemetryInterface;
3064 method = "GenerateTelemetryLog";
3065 taskMatchStr =
3066 "type='signal',"
3067 "interface='org.freedesktop.DBus.Properties',"
3068 "member='PropertiesChanged',"
3069 "arg0namespace='com.intel.crashdump'";
Ed Tanous002d39b2022-05-31 08:59:27 -07003070 }
3071 else
3072 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003073 BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}",
3074 oemDiagnosticDataType);
3075 messages::actionParameterValueFormatError(
3076 asyncResp->res, oemDiagnosticDataType,
3077 "OEMDiagnosticDataType", "CollectDiagnosticData");
3078 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07003079 }
Ed Tanous1da66f72018-07-27 16:13:37 -07003080
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003081 auto collectCrashdumpCallback =
3082 [asyncResp, payload(task::Payload(req)),
3083 taskMatchStr](const boost::system::error_code& ec,
3084 const std::string&) mutable {
3085 if (ec)
3086 {
3087 if (ec.value() ==
3088 boost::system::errc::operation_not_supported)
3089 {
3090 messages::resourceInStandby(asyncResp->res);
3091 }
3092 else if (ec.value() == boost::system::errc::
3093 device_or_resource_busy)
3094 {
3095 messages::serviceTemporarilyUnavailable(
3096 asyncResp->res, "60");
3097 }
3098 else
3099 {
3100 messages::internalError(asyncResp->res);
3101 }
3102 return;
3103 }
3104 std::shared_ptr<task::TaskData> task =
3105 task::TaskData::createTask(
3106 [](const boost::system::error_code& ec2,
3107 sdbusplus::message_t&,
3108 const std::shared_ptr<task::TaskData>&
3109 taskData) {
3110 if (!ec2)
3111 {
3112 taskData->messages.emplace_back(
3113 messages::taskCompletedOK(
3114 std::to_string(
3115 taskData->index)));
3116 taskData->state = "Completed";
3117 }
3118 return task::completed;
3119 },
3120 taskMatchStr);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003121
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003122 task->startTimer(std::chrono::minutes(5));
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003123 task->payload.emplace(std::move(payload));
Chinmay Shripad Hegde29e2bdd2025-06-06 16:23:47 +05303124 task->populateResp(asyncResp->res);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003125 };
3126
Ed Tanous177612a2025-02-14 15:16:09 -08003127 dbus::utility::async_method_call(
3128 asyncResp, std::move(collectCrashdumpCallback),
3129 crashdumpObject, crashdumpPath, iface, method);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003130 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003131}
Kenny L. Ku6eda7682020-06-19 09:48:36 -07003132
Alexander Hansen599b9af2024-08-06 15:11:57 +02003133inline void dBusLogServiceActionsClear(
3134 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
3135{
3136 BMCWEB_LOG_DEBUG("Do delete all entries.");
3137
3138 // Process response from Logging service.
3139 auto respHandler = [asyncResp](const boost::system::error_code& ec) {
3140 BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done");
3141 if (ec)
3142 {
3143 // TODO Handle for specific error code
3144 BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec);
3145 asyncResp->res.result(
3146 boost::beast::http::status::internal_server_error);
3147 return;
3148 }
3149
Amy Change2460462025-05-06 00:10:13 -07003150 messages::success(asyncResp->res);
Alexander Hansen599b9af2024-08-06 15:11:57 +02003151 };
3152
3153 // Make call to Logging service to request Clear Log
Ed Tanous177612a2025-02-14 15:16:09 -08003154 dbus::utility::async_method_call(
3155 asyncResp, respHandler, "xyz.openbmc_project.Logging",
Alexander Hansen599b9af2024-08-06 15:11:57 +02003156 "/xyz/openbmc_project/logging",
3157 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3158}
3159
Andrew Geisslercb92c032018-08-17 07:56:14 -07003160/**
3161 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3162 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003163inline void requestRoutesDBusLogServiceActionsClear(App& app)
Andrew Geisslercb92c032018-08-17 07:56:14 -07003164{
Andrew Geisslercb92c032018-08-17 07:56:14 -07003165 /**
3166 * Function handles POST method request.
3167 * The Clear Log actions does not require any parameter.The action deletes
3168 * all entries found in the Entries collection for this Log Service.
3169 */
Andrew Geisslercb92c032018-08-17 07:56:14 -07003170
George Liu0fda0f12021-11-16 10:06:17 +08003171 BMCWEB_ROUTE(
3172 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003173 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Abhishek Patelfff6a4d2021-07-21 11:29:45 -05003174 .privileges(redfish::privileges::
3175 postLogServiceSubOverComputerSystemLogServiceCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003176 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003177 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003178 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3179 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003180 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3181 {
3182 return;
3183 }
3184 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
3185 {
3186 // Option currently returns no systems. TBD
3187 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3188 systemName);
3189 return;
3190 }
3191 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
3192 {
3193 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3194 systemName);
3195 return;
3196 }
3197 dBusLogServiceActionsClear(asyncResp);
3198 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003199}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003200
Ed Tanous1da66f72018-07-27 16:13:37 -07003201} // namespace redfish