blob: 8d29341c1658747363ceaad70d6960c9bea01b74 [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));
937 task->populateResp(asyncResp->res);
938 task->payload.emplace(payload);
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 }
1095 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001096 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Claire Weinan0d946212022-07-13 19:40:19 -07001097 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001098}
1099
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001100inline void parseCrashdumpParameters(
1101 const dbus::utility::DBusPropertiesMap& params, std::string& filename,
1102 std::string& timestamp, std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001103{
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001104 const std::string* filenamePtr = nullptr;
1105 const std::string* timestampPtr = nullptr;
1106 const std::string* logfilePtr = nullptr;
1107
1108 const bool success = sdbusplus::unpackPropertiesNoThrow(
1109 dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr,
1110 "Filename", filenamePtr, "Log", logfilePtr);
1111
1112 if (!success)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001113 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001114 return;
1115 }
1116
1117 if (filenamePtr != nullptr)
1118 {
1119 filename = *filenamePtr;
1120 }
1121
1122 if (timestampPtr != nullptr)
1123 {
1124 timestamp = *timestampPtr;
1125 }
1126
1127 if (logfilePtr != nullptr)
1128 {
1129 logfile = *logfilePtr;
Johnathan Mantey043a0532020-03-10 17:15:28 -07001130 }
1131}
1132
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001133inline void requestRoutesSystemLogServiceCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07001134{
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001135 /**
1136 * Functions triggers appropriate requests on DBus
1137 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001138 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
Ed Tanoused398212021-06-09 17:05:54 -07001139 .privileges(redfish::privileges::getLogServiceCollection)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001140 .methods(
1141 boost::beast::http::verb::
1142 get)([&app](const crow::Request& req,
1143 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1144 const std::string& systemName) {
1145 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001146 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001147 return;
1148 }
1149 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1150 {
1151 // Option currently returns no systems. TBD
1152 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1153 systemName);
1154 return;
1155 }
1156 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1157 {
1158 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1159 systemName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001160 return;
1161 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001162
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001163 // Collections don't include the static data added by SubRoute
1164 // because it has a duplicate entry for members
1165 asyncResp->res.jsonValue["@odata.type"] =
1166 "#LogServiceCollection.LogServiceCollection";
1167 asyncResp->res.jsonValue["@odata.id"] =
1168 std::format("/redfish/v1/Systems/{}/LogServices",
1169 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1170 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
1171 asyncResp->res.jsonValue["Description"] =
1172 "Collection of LogServices for this Computer System";
1173 nlohmann::json& logServiceArray =
1174 asyncResp->res.jsonValue["Members"];
1175 logServiceArray = nlohmann::json::array();
1176 nlohmann::json::object_t eventLog;
1177 eventLog["@odata.id"] =
1178 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1179 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1180 logServiceArray.emplace_back(std::move(eventLog));
1181 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
Ed Tanous002d39b2022-05-31 08:59:27 -07001182 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001183 nlohmann::json::object_t dumpLog;
1184 dumpLog["@odata.id"] =
1185 std::format("/redfish/v1/Systems/{}/LogServices/Dump",
1186 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1187 logServiceArray.emplace_back(std::move(dumpLog));
Ed Tanous002d39b2022-05-31 08:59:27 -07001188 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001189
1190 if constexpr (BMCWEB_REDFISH_CPU_LOG)
1191 {
1192 nlohmann::json::object_t crashdump;
1193 crashdump["@odata.id"] =
1194 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
1195 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1196 logServiceArray.emplace_back(std::move(crashdump));
1197 }
1198
1199 if constexpr (BMCWEB_REDFISH_HOST_LOGGER)
1200 {
1201 nlohmann::json::object_t hostlogger;
1202 hostlogger["@odata.id"] =
1203 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
1204 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1205 logServiceArray.emplace_back(std::move(hostlogger));
1206 }
1207 asyncResp->res.jsonValue["Members@odata.count"] =
1208 logServiceArray.size();
1209
1210 constexpr std::array<std::string_view, 1> interfaces = {
1211 "xyz.openbmc_project.State.Boot.PostCode"};
1212 dbus::utility::getSubTreePaths(
1213 "/", 0, interfaces,
1214 [asyncResp](const boost::system::error_code& ec,
1215 const dbus::utility::MapperGetSubTreePathsResponse&
1216 subtreePath) {
1217 if (ec)
1218 {
1219 BMCWEB_LOG_ERROR("{}", ec);
1220 return;
1221 }
1222
1223 for (const auto& pathStr : subtreePath)
1224 {
1225 if (pathStr.find("PostCode") != std::string::npos)
1226 {
1227 nlohmann::json& logServiceArrayLocal =
1228 asyncResp->res.jsonValue["Members"];
1229 nlohmann::json::object_t member;
1230 member["@odata.id"] = std::format(
1231 "/redfish/v1/Systems/{}/LogServices/PostCodes",
1232 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1233
1234 logServiceArrayLocal.emplace_back(
1235 std::move(member));
1236
1237 asyncResp->res.jsonValue["Members@odata.count"] =
1238 logServiceArrayLocal.size();
1239 return;
1240 }
1241 }
1242 });
Ed Tanous45ca1b82022-03-25 13:07:27 -07001243 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001244}
1245
1246inline void requestRoutesEventLogService(App& app)
1247{
Ed Tanous22d268c2022-05-19 09:39:07 -07001248 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/")
Ed Tanoused398212021-06-09 17:05:54 -07001249 .privileges(redfish::privileges::getLogService)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001250 .methods(
1251 boost::beast::http::verb::
1252 get)([&app](const crow::Request& req,
1253 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1254 const std::string& systemName) {
1255 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1256 {
1257 return;
1258 }
1259 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1260 {
1261 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1262 systemName);
1263 return;
1264 }
1265 asyncResp->res.jsonValue["@odata.id"] =
1266 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1267 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1268 asyncResp->res.jsonValue["@odata.type"] =
1269 "#LogService.v1_2_0.LogService";
1270 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1271 asyncResp->res.jsonValue["Description"] =
1272 "System Event Log Service";
1273 asyncResp->res.jsonValue["Id"] = "EventLog";
1274 asyncResp->res.jsonValue["OverWritePolicy"] =
1275 log_service::OverWritePolicy::WrapsWhenFull;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301276
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001277 std::pair<std::string, std::string> redfishDateTimeOffset =
1278 redfish::time_utils::getDateTimeOffsetNow();
Tejas Patil7c8c4052021-06-04 17:43:14 +05301279
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001280 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
1281 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
1282 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301283
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001284 asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format(
1285 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
Ed Tanous20fa6a22024-05-20 18:02:58 -07001286 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001287 asyncResp->res
1288 .jsonValue["Actions"]["#LogService.ClearLog"]["target"]
1289
1290 = std::format(
1291 "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog",
1292 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1293 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001294}
1295
Alexander Hansen599b9af2024-08-06 15:11:57 +02001296inline void handleSystemsLogServicesEventLogActionsClearPost(
1297 App& app, const crow::Request& req,
1298 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1299 const std::string& systemName)
1300{
1301 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1302 {
1303 return;
1304 }
1305 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1306 {
1307 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1308 systemName);
1309 return;
1310 }
1311
1312 // Clear the EventLog by deleting the log files
1313 std::vector<std::filesystem::path> redfishLogFiles;
1314 if (getRedfishLogFiles(redfishLogFiles))
1315 {
1316 for (const std::filesystem::path& file : redfishLogFiles)
1317 {
1318 std::error_code ec;
1319 std::filesystem::remove(file, ec);
1320 }
1321 }
1322
1323 // Reload rsyslog so it knows to start new log files
Ed Tanous177612a2025-02-14 15:16:09 -08001324 dbus::utility::async_method_call(
1325 asyncResp,
Alexander Hansen599b9af2024-08-06 15:11:57 +02001326 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001327 if (ec)
1328 {
1329 BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec);
1330 messages::internalError(asyncResp->res);
1331 return;
1332 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001333
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001334 messages::success(asyncResp->res);
1335 },
Alexander Hansen599b9af2024-08-06 15:11:57 +02001336 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1337 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1338 "replace");
1339}
1340
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001341inline void requestRoutesJournalEventLogClear(App& app)
1342{
Jason M. Bills4978b632022-02-22 14:17:43 -08001343 BMCWEB_ROUTE(
1344 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07001345 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Ed Tanous432a8902021-06-14 15:28:56 -07001346 .privileges({{"ConfigureComponents"}})
Alexander Hansen599b9af2024-08-06 15:11:57 +02001347 .methods(boost::beast::http::verb::post)(std::bind_front(
1348 handleSystemsLogServicesEventLogActionsClearPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001349}
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001350
Jason M. Billsac992cd2022-06-24 13:31:46 -07001351enum class LogParseError
1352{
1353 success,
1354 parseFailed,
1355 messageIdNotInRegistry,
1356};
1357
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001358static LogParseError fillEventLogEntryJson(
1359 const std::string& logEntryID, const std::string& logEntry,
1360 nlohmann::json::object_t& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001361{
Jason M. Bills95820182019-04-22 16:25:34 -07001362 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001363 // First get the Timestamp
Ed Tanousf23b7292020-10-15 09:41:17 -07001364 size_t space = logEntry.find_first_of(' ');
Jason M. Billscd225da2019-05-08 15:31:57 -07001365 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001366 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001367 return LogParseError::parseFailed;
Jason M. Bills95820182019-04-22 16:25:34 -07001368 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001369 std::string timestamp = logEntry.substr(0, space);
1370 // Then get the log contents
Ed Tanousf23b7292020-10-15 09:41:17 -07001371 size_t entryStart = logEntry.find_first_not_of(' ', space);
Jason M. Billscd225da2019-05-08 15:31:57 -07001372 if (entryStart == std::string::npos)
1373 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001374 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001375 }
1376 std::string_view entry(logEntry);
1377 entry.remove_prefix(entryStart);
1378 // Use split to separate the entry into its fields
1379 std::vector<std::string> logEntryFields;
Ed Tanous50ebd4a2023-01-19 19:03:17 -08001380 bmcweb::split(logEntryFields, entry, ',');
Jason M. Billscd225da2019-05-08 15:31:57 -07001381 // We need at least a MessageId to be valid
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001382 auto logEntryIter = logEntryFields.begin();
1383 if (logEntryIter == logEntryFields.end())
Jason M. Billscd225da2019-05-08 15:31:57 -07001384 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001385 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001386 }
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001387 std::string& messageID = *logEntryIter;
Jason M. Bills4851d452019-03-28 11:27:48 -07001388 // Get the Message from the MessageRegistry
Ed Tanousfffb8c12022-02-07 23:53:03 -08001389 const registries::Message* message = registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001390
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001391 logEntryIter++;
Sui Chen54417b02022-03-24 14:59:52 -07001392 if (message == nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001393 {
Ed Tanous62598e32023-07-17 17:06:25 -07001394 BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001395 return LogParseError::messageIdNotInRegistry;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001396 }
1397
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001398 std::vector<std::string_view> messageArgs(logEntryIter,
1399 logEntryFields.end());
Ed Tanousc05bba42023-06-28 08:33:29 -07001400 messageArgs.resize(message->numberOfArgs);
1401
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001402 std::string msg =
1403 redfish::registries::fillMessageArgs(messageArgs, message->message);
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001404 if (msg.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001405 {
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001406 return LogParseError::parseFailed;
Jason M. Bills4851d452019-03-28 11:27:48 -07001407 }
1408
Jason M. Bills95820182019-04-22 16:25:34 -07001409 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1410 // format which matches the Redfish format except for the fractional seconds
1411 // between the '.' and the '+', so just remove them.
Ed Tanousf23b7292020-10-15 09:41:17 -07001412 std::size_t dot = timestamp.find_first_of('.');
1413 std::size_t plus = timestamp.find_first_of('+');
Jason M. Bills95820182019-04-22 16:25:34 -07001414 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001415 {
Jason M. Bills95820182019-04-22 16:25:34 -07001416 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001417 }
1418
1419 // Fill in the log entry with the gathered data
Vijay Lobo9c11a172021-10-07 16:53:16 -05001420 logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001421 logEntryJson["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001422 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1423 BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
Jason M. Bills84afc482022-06-24 12:38:23 -07001424 logEntryJson["Name"] = "System Event Log Entry";
1425 logEntryJson["Id"] = logEntryID;
1426 logEntryJson["Message"] = std::move(msg);
1427 logEntryJson["MessageId"] = std::move(messageID);
1428 logEntryJson["MessageArgs"] = messageArgs;
1429 logEntryJson["EntryType"] = "Event";
1430 logEntryJson["Severity"] = message->messageSeverity;
1431 logEntryJson["Created"] = std::move(timestamp);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001432 return LogParseError::success;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001433}
1434
Igor Kanyuka90896602025-03-13 08:52:38 +00001435inline bool fillEventLogLogEntryFromPropertyMap(
Ed Tanous898f2aa2024-08-07 12:18:22 -07001436 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1437 const dbus::utility::DBusPropertiesMap& resp,
1438 nlohmann::json& objectToFillOut)
1439{
Alexander Hansen262dcc12024-09-19 12:04:03 +02001440 std::optional<DbusEventLogEntry> optEntry =
1441 fillDbusEventLogEntryFromPropertyMap(resp);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001442
Alexander Hansen262dcc12024-09-19 12:04:03 +02001443 if (!optEntry.has_value())
Ed Tanous898f2aa2024-08-07 12:18:22 -07001444 {
1445 messages::internalError(asyncResp->res);
Igor Kanyuka90896602025-03-13 08:52:38 +00001446 return false;
Ed Tanous898f2aa2024-08-07 12:18:22 -07001447 }
Alexander Hansen262dcc12024-09-19 12:04:03 +02001448 DbusEventLogEntry entry = optEntry.value();
Ed Tanous898f2aa2024-08-07 12:18:22 -07001449
1450 objectToFillOut["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1451 objectToFillOut["@odata.id"] = boost::urls::format(
1452 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
Alexander Hansen262dcc12024-09-19 12:04:03 +02001453 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
Ed Tanous898f2aa2024-08-07 12:18:22 -07001454 objectToFillOut["Name"] = "System Event Log Entry";
Alexander Hansen262dcc12024-09-19 12:04:03 +02001455 objectToFillOut["Id"] = std::to_string(entry.Id);
1456 objectToFillOut["Message"] = entry.Message;
1457 objectToFillOut["Resolved"] = entry.Resolved;
1458 std::optional<bool> notifyAction =
1459 getProviderNotifyAction(entry.ServiceProviderNotify);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001460 if (notifyAction)
1461 {
1462 objectToFillOut["ServiceProviderNotified"] = *notifyAction;
1463 }
Alexander Hansen262dcc12024-09-19 12:04:03 +02001464 if ((entry.Resolution != nullptr) && !entry.Resolution->empty())
Ed Tanous898f2aa2024-08-07 12:18:22 -07001465 {
Alexander Hansen262dcc12024-09-19 12:04:03 +02001466 objectToFillOut["Resolution"] = *entry.Resolution;
Ed Tanous898f2aa2024-08-07 12:18:22 -07001467 }
1468 objectToFillOut["EntryType"] = "Event";
Alexander Hansen262dcc12024-09-19 12:04:03 +02001469 objectToFillOut["Severity"] =
1470 translateSeverityDbusToRedfish(entry.Severity);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001471 objectToFillOut["Created"] =
Alexander Hansen262dcc12024-09-19 12:04:03 +02001472 redfish::time_utils::getDateTimeUintMs(entry.Timestamp);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001473 objectToFillOut["Modified"] =
Alexander Hansen262dcc12024-09-19 12:04:03 +02001474 redfish::time_utils::getDateTimeUintMs(entry.UpdateTimestamp);
1475 if (entry.Path != nullptr)
Ed Tanous898f2aa2024-08-07 12:18:22 -07001476 {
1477 objectToFillOut["AdditionalDataURI"] = boost::urls::format(
1478 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment",
Alexander Hansen262dcc12024-09-19 12:04:03 +02001479 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
Ed Tanous898f2aa2024-08-07 12:18:22 -07001480 }
Igor Kanyuka90896602025-03-13 08:52:38 +00001481 return true;
Ed Tanous898f2aa2024-08-07 12:18:22 -07001482}
1483
Ed Tanousb7290962024-08-07 11:09:51 -07001484inline void afterLogEntriesGetManagedObjects(
1485 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1486 const boost::system::error_code& ec,
1487 const dbus::utility::ManagedObjectType& resp)
1488{
1489 if (ec)
1490 {
1491 // TODO Handle for specific error code
1492 BMCWEB_LOG_ERROR("getLogEntriesIfaceData resp_handler got error {}",
1493 ec);
1494 messages::internalError(asyncResp->res);
1495 return;
1496 }
1497 nlohmann::json::array_t entriesArray;
1498 for (const auto& objectPath : resp)
1499 {
Ed Tanous898f2aa2024-08-07 12:18:22 -07001500 dbus::utility::DBusPropertiesMap propsFlattened;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001501 auto isEntry =
1502 std::ranges::find_if(objectPath.second, [](const auto& object) {
1503 return object.first == "xyz.openbmc_project.Logging.Entry";
1504 });
Ed Tanous898f2aa2024-08-07 12:18:22 -07001505 if (isEntry == objectPath.second.end())
Ed Tanousb7290962024-08-07 11:09:51 -07001506 {
1507 continue;
1508 }
Ed Tanous898f2aa2024-08-07 12:18:22 -07001509 for (const auto& interfaceMap : objectPath.second)
Ed Tanousb7290962024-08-07 11:09:51 -07001510 {
Ed Tanous898f2aa2024-08-07 12:18:22 -07001511 for (const auto& propertyMap : interfaceMap.second)
Ed Tanousb7290962024-08-07 11:09:51 -07001512 {
Ed Tanous898f2aa2024-08-07 12:18:22 -07001513 propsFlattened.emplace_back(propertyMap.first,
1514 propertyMap.second);
Ed Tanousb7290962024-08-07 11:09:51 -07001515 }
1516 }
Igor Kanyuka90896602025-03-13 08:52:38 +00001517 bool success = fillEventLogLogEntryFromPropertyMap(
1518 asyncResp, propsFlattened, entriesArray.emplace_back());
1519 if (!success)
1520 {
1521 return;
1522 }
Ed Tanousb7290962024-08-07 11:09:51 -07001523 }
Ed Tanous898f2aa2024-08-07 12:18:22 -07001524
Igor Kanyuka90896602025-03-13 08:52:38 +00001525 redfish::json_util::sortJsonArrayByKey(entriesArray, "Id");
Ed Tanousb7290962024-08-07 11:09:51 -07001526 asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
1527 asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
1528}
1529
Alexander Hansen599b9af2024-08-06 15:11:57 +02001530inline void handleSystemsLogServiceEventLogLogEntryCollection(
1531 App& app, const crow::Request& req,
1532 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1533 const std::string& systemName)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001534{
Alexander Hansen599b9af2024-08-06 15:11:57 +02001535 query_param::QueryCapabilities capabilities = {
1536 .canDelegateTop = true,
1537 .canDelegateSkip = true,
1538 };
1539 query_param::Query delegatedQuery;
1540 if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp,
1541 delegatedQuery, capabilities))
1542 {
1543 return;
1544 }
1545 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1546 {
1547 // Option currently returns no systems. TBD
1548 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1549 systemName);
1550 return;
1551 }
1552 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1553 {
1554 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1555 systemName);
1556 return;
1557 }
1558
1559 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
1560 size_t skip = delegatedQuery.skip.value_or(0);
1561
1562 // Collections don't include the static data added by SubRoute
1563 // because it has a duplicate entry for members
1564 asyncResp->res.jsonValue["@odata.type"] =
1565 "#LogEntryCollection.LogEntryCollection";
1566 asyncResp->res.jsonValue["@odata.id"] =
1567 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1568 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1569 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1570 asyncResp->res.jsonValue["Description"] =
1571 "Collection of System Event Log Entries";
1572
1573 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1574 logEntryArray = nlohmann::json::array();
1575 // Go through the log files and create a unique ID for each
1576 // entry
1577 std::vector<std::filesystem::path> redfishLogFiles;
1578 getRedfishLogFiles(redfishLogFiles);
1579 uint64_t entryCount = 0;
1580 std::string logEntry;
1581
1582 // Oldest logs are in the last file, so start there and loop
1583 // backwards
1584 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++)
1585 {
1586 std::ifstream logStream(*it);
1587 if (!logStream.is_open())
Ed Tanous002d39b2022-05-31 08:59:27 -07001588 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001589 continue;
Ed Tanous22d268c2022-05-19 09:39:07 -07001590 }
1591
Alexander Hansen599b9af2024-08-06 15:11:57 +02001592 // Reset the unique ID on the first entry
1593 bool firstEntry = true;
1594 while (std::getline(logStream, logEntry))
Ed Tanous002d39b2022-05-31 08:59:27 -07001595 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001596 std::string idStr;
1597 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1598 {
1599 continue;
1600 }
1601 firstEntry = false;
1602
1603 nlohmann::json::object_t bmcLogEntry;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001604 LogParseError status =
1605 fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
Alexander Hansen599b9af2024-08-06 15:11:57 +02001606 if (status == LogParseError::messageIdNotInRegistry)
1607 {
1608 continue;
1609 }
1610 if (status != LogParseError::success)
1611 {
1612 messages::internalError(asyncResp->res);
1613 return;
1614 }
1615
1616 entryCount++;
1617 // Handle paging using skip (number of entries to skip from the
1618 // start) and top (number of entries to display)
1619 if (entryCount <= skip || entryCount > skip + top)
Jason M. Bills4978b632022-02-22 14:17:43 -08001620 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001621 continue;
Jason M. Bills4978b632022-02-22 14:17:43 -08001622 }
Jason M. Bills897967d2019-07-29 17:05:30 -07001623
Alexander Hansen599b9af2024-08-06 15:11:57 +02001624 logEntryArray.emplace_back(std::move(bmcLogEntry));
1625 }
1626 }
1627 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1628 if (skip + top < entryCount)
1629 {
1630 asyncResp->res.jsonValue["Members@odata.nextLink"] =
1631 boost::urls::format(
1632 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}",
1633 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top));
1634 }
1635}
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001636
Alexander Hansen599b9af2024-08-06 15:11:57 +02001637inline void requestRoutesJournalEventLogEntryCollection(App& app)
1638{
1639 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
1640 .privileges(redfish::privileges::getLogEntryCollection)
1641 .methods(boost::beast::http::verb::get)(std::bind_front(
1642 handleSystemsLogServiceEventLogLogEntryCollection, std::ref(app)));
1643}
1644
1645inline void handleSystemsLogServiceEventLogEntriesGet(
1646 App& app, const crow::Request& req,
1647 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1648 const std::string& systemName, const std::string& param)
1649{
1650 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1651 {
1652 return;
1653 }
1654 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1655 {
1656 // Option currently returns no systems. TBD
1657 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1658 systemName);
1659 return;
1660 }
1661
1662 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1663 {
1664 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1665 systemName);
1666 return;
1667 }
1668
1669 const std::string& targetID = param;
1670
1671 // Go through the log files and check the unique ID for each
1672 // entry to find the target entry
1673 std::vector<std::filesystem::path> redfishLogFiles;
1674 getRedfishLogFiles(redfishLogFiles);
1675 std::string logEntry;
1676
1677 // Oldest logs are in the last file, so start there and loop
1678 // backwards
1679 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++)
1680 {
1681 std::ifstream logStream(*it);
1682 if (!logStream.is_open())
1683 {
1684 continue;
1685 }
1686
1687 // Reset the unique ID on the first entry
1688 bool firstEntry = true;
1689 while (std::getline(logStream, logEntry))
1690 {
1691 std::string idStr;
1692 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1693 {
1694 continue;
1695 }
1696 firstEntry = false;
1697
1698 if (idStr == targetID)
1699 {
Jason M. Billsde703c52022-06-23 14:19:04 -07001700 nlohmann::json::object_t bmcLogEntry;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001701 LogParseError status =
1702 fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001703 if (status != LogParseError::success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001704 {
1705 messages::internalError(asyncResp->res);
1706 return;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001707 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001708 asyncResp->res.jsonValue.update(bmcLogEntry);
1709 return;
Jason M. Bills4978b632022-02-22 14:17:43 -08001710 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001711 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001712 }
1713 // Requested ID was not found
1714 messages::resourceNotFound(asyncResp->res, "LogEntry", targetID);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001715}
Chicago Duan336e96c2019-07-15 14:22:08 +08001716
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001717inline void requestRoutesJournalEventLogEntry(App& app)
1718{
1719 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001720 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001721 .privileges(redfish::privileges::getLogEntry)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001722 .methods(boost::beast::http::verb::get)(std::bind_front(
1723 handleSystemsLogServiceEventLogEntriesGet, std::ref(app)));
1724}
1725
1726inline void dBusEventLogEntryCollection(
1727 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1728{
1729 // Collections don't include the static data added by SubRoute
1730 // because it has a duplicate entry for members
1731 asyncResp->res.jsonValue["@odata.type"] =
1732 "#LogEntryCollection.LogEntryCollection";
1733 asyncResp->res.jsonValue["@odata.id"] =
1734 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1735 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1736 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1737 asyncResp->res.jsonValue["Description"] =
1738 "Collection of System Event Log Entries";
1739
1740 // DBus implementation of EventLog/Entries
1741 // Make call to Logging Service to find all log entry objects
1742 sdbusplus::message::object_path path("/xyz/openbmc_project/logging");
1743 dbus::utility::getManagedObjects(
1744 "xyz.openbmc_project.Logging", path,
1745 [asyncResp](const boost::system::error_code& ec,
1746 const dbus::utility::ManagedObjectType& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001747 afterLogEntriesGetManagedObjects(asyncResp, ec, resp);
1748 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001749}
1750
1751inline void requestRoutesDBusEventLogEntryCollection(App& app)
1752{
Ed Tanous22d268c2022-05-19 09:39:07 -07001753 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07001754 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001755 .methods(boost::beast::http::verb::get)(
1756 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001757 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1758 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001759 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1760 {
1761 return;
1762 }
1763 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1764 {
1765 // Option currently returns no systems. TBD
1766 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1767 systemName);
1768 return;
1769 }
1770 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1771 {
1772 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1773 systemName);
1774 return;
1775 }
1776 dBusEventLogEntryCollection(asyncResp);
1777 });
Alexander Hansen599b9af2024-08-06 15:11:57 +02001778}
Ed Tanous22d268c2022-05-19 09:39:07 -07001779
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001780inline void dBusEventLogEntryGet(
1781 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001782{
1783 dbus::utility::escapePathForDbus(entryID);
Ed Tanous002d39b2022-05-31 08:59:27 -07001784
Alexander Hansen599b9af2024-08-06 15:11:57 +02001785 // DBus implementation of EventLog/Entries
1786 // Make call to Logging Service to find all log entry objects
Ed Tanousdeae6a72024-11-11 21:58:57 -08001787 dbus::utility::getAllProperties(
1788 "xyz.openbmc_project.Logging",
Alexander Hansen599b9af2024-08-06 15:11:57 +02001789 "/xyz/openbmc_project/logging/entry/" + entryID, "",
1790 [asyncResp, entryID](const boost::system::error_code& ec,
1791 const dbus::utility::DBusPropertiesMap& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001792 if (ec.value() == EBADR)
1793 {
1794 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1795 entryID);
1796 return;
1797 }
1798 if (ec)
1799 {
1800 BMCWEB_LOG_ERROR(
1801 "EventLogEntry (DBus) resp_handler got error {}", ec);
1802 messages::internalError(asyncResp->res);
1803 return;
1804 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001805
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001806 fillEventLogLogEntryFromPropertyMap(asyncResp, resp,
1807 asyncResp->res.jsonValue);
1808 });
Alexander Hansen599b9af2024-08-06 15:11:57 +02001809}
1810
Patrick Williams504af5a2025-02-03 14:29:03 -05001811inline void dBusEventLogEntryPatch(
1812 const crow::Request& req,
1813 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1814 const std::string& entryId)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001815{
1816 std::optional<bool> resolved;
1817
1818 if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", resolved))
1819 {
1820 return;
1821 }
1822 BMCWEB_LOG_DEBUG("Set Resolved");
1823
1824 setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging",
1825 "/xyz/openbmc_project/logging/entry/" + entryId,
1826 "xyz.openbmc_project.Logging.Entry", "Resolved",
1827 resolved.value_or(false));
1828}
1829
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001830inline void dBusEventLogEntryDelete(
1831 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001832{
1833 BMCWEB_LOG_DEBUG("Do delete single event entries.");
1834
1835 dbus::utility::escapePathForDbus(entryID);
1836
1837 // Process response from Logging service.
1838 auto respHandler = [asyncResp,
1839 entryID](const boost::system::error_code& ec) {
1840 BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done");
1841 if (ec)
1842 {
1843 if (ec.value() == EBADR)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001844 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001845 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001846 return;
1847 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001848 // TODO Handle for specific error code
1849 BMCWEB_LOG_ERROR(
1850 "EventLogEntry (DBus) doDelete respHandler got error {}", ec);
1851 asyncResp->res.result(
1852 boost::beast::http::status::internal_server_error);
1853 return;
1854 }
Abhishek Patel9017faf2021-09-14 22:48:55 -05001855
Alexander Hansen599b9af2024-08-06 15:11:57 +02001856 asyncResp->res.result(boost::beast::http::status::ok);
1857 };
1858
1859 // Make call to Logging service to request Delete Log
Ed Tanous177612a2025-02-14 15:16:09 -08001860 dbus::utility::async_method_call(
1861 asyncResp, respHandler, "xyz.openbmc_project.Logging",
Alexander Hansen599b9af2024-08-06 15:11:57 +02001862 "/xyz/openbmc_project/logging/entry/" + entryID,
1863 "xyz.openbmc_project.Object.Delete", "Delete");
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001864}
Xiaochao Ma75710de2021-01-21 17:56:02 +08001865
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001866inline void requestRoutesDBusEventLogEntry(App& app)
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001867{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001868 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001869 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001870 .privileges(redfish::privileges::getLogEntry)
Ed Tanous002d39b2022-05-31 08:59:27 -07001871 .methods(boost::beast::http::verb::get)(
1872 [&app](const crow::Request& req,
1873 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous898f2aa2024-08-07 12:18:22 -07001874 const std::string& systemName, const std::string& entryId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001875 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1876 {
1877 return;
1878 }
1879 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1880 {
1881 // Option currently returns no systems. TBD
1882 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1883 systemName);
1884 return;
1885 }
1886 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1887 {
1888 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1889 systemName);
1890 return;
1891 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001892
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001893 dBusEventLogEntryGet(asyncResp, entryId);
1894 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001895
1896 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001897 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001898 .privileges(redfish::privileges::patchLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001899 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001900 [&app](const crow::Request& req,
1901 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001902 const std::string& systemName, const std::string& entryId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001903 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1904 {
1905 return;
1906 }
1907 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1908 {
1909 // Option currently returns no systems. TBD
1910 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1911 systemName);
1912 return;
1913 }
1914 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1915 {
1916 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1917 systemName);
1918 return;
1919 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001920
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001921 dBusEventLogEntryPatch(req, asyncResp, entryId);
1922 });
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001923
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001924 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001925 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001926 .privileges(redfish::privileges::deleteLogEntry)
1927
Ed Tanous002d39b2022-05-31 08:59:27 -07001928 .methods(boost::beast::http::verb::delete_)(
1929 [&app](const crow::Request& req,
1930 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001931 const std::string& systemName, const std::string& param) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001932 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1933 {
1934 return;
1935 }
1936 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1937 {
1938 // Option currently returns no systems. TBD
1939 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1940 systemName);
1941 return;
1942 }
1943 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1944 {
1945 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1946 systemName);
1947 return;
1948 }
1949 dBusEventLogEntryDelete(asyncResp, param);
1950 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001951}
1952
Claire Weinandd72e872022-08-15 14:20:06 -07001953inline void handleBMCLogServicesCollectionGet(
Claire Weinanfdd26902022-03-01 14:18:25 -08001954 crow::App& app, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07001955 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1956 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08001957{
1958 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1959 {
1960 return;
1961 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001962
1963 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
1964 {
1965 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
1966 return;
1967 }
1968
Claire Weinanfdd26902022-03-01 14:18:25 -08001969 // Collections don't include the static data added by SubRoute
1970 // because it has a duplicate entry for members
1971 asyncResp->res.jsonValue["@odata.type"] =
1972 "#LogServiceCollection.LogServiceCollection";
Ed Tanous253f11b2024-05-16 09:38:31 -07001973 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1974 "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -08001975 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1976 asyncResp->res.jsonValue["Description"] =
1977 "Collection of LogServices for this Manager";
1978 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1979 logServiceArray = nlohmann::json::array();
1980
Ed Tanous25b54db2024-04-17 15:40:31 -07001981 if constexpr (BMCWEB_REDFISH_BMC_JOURNAL)
1982 {
1983 nlohmann::json::object_t journal;
Ed Tanous253f11b2024-05-16 09:38:31 -07001984 journal["@odata.id"] =
1985 boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal",
1986 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001987 logServiceArray.emplace_back(std::move(journal));
1988 }
Claire Weinanfdd26902022-03-01 14:18:25 -08001989
1990 asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
1991
Ed Tanous25b54db2024-04-17 15:40:31 -07001992 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
1993 {
1994 constexpr std::array<std::string_view, 1> interfaces = {
1995 "xyz.openbmc_project.Collection.DeleteAll"};
1996 dbus::utility::getSubTreePaths(
1997 "/xyz/openbmc_project/dump", 0, interfaces,
1998 [asyncResp](const boost::system::error_code& ec,
1999 const dbus::utility::MapperGetSubTreePathsResponse&
2000 subTreePaths) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002001 if (ec)
Ed Tanous25b54db2024-04-17 15:40:31 -07002002 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002003 BMCWEB_LOG_ERROR(
2004 "handleBMCLogServicesCollectionGet respHandler got error {}",
2005 ec);
2006 // Assume that getting an error simply means there are no
2007 // dump LogServices. Return without adding any error
2008 // response.
2009 return;
Ed Tanous25b54db2024-04-17 15:40:31 -07002010 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002011
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002012 nlohmann::json& logServiceArrayLocal =
2013 asyncResp->res.jsonValue["Members"];
2014
2015 for (const std::string& path : subTreePaths)
2016 {
2017 if (path == "/xyz/openbmc_project/dump/bmc")
2018 {
2019 nlohmann::json::object_t member;
2020 member["@odata.id"] = boost::urls::format(
2021 "/redfish/v1/Managers/{}/LogServices/Dump",
2022 BMCWEB_REDFISH_MANAGER_URI_NAME);
2023 logServiceArrayLocal.emplace_back(std::move(member));
2024 }
2025 else if (path == "/xyz/openbmc_project/dump/faultlog")
2026 {
2027 nlohmann::json::object_t member;
2028 member["@odata.id"] = boost::urls::format(
2029 "/redfish/v1/Managers/{}/LogServices/FaultLog",
2030 BMCWEB_REDFISH_MANAGER_URI_NAME);
2031 logServiceArrayLocal.emplace_back(std::move(member));
2032 }
2033 }
2034
2035 asyncResp->res.jsonValue["Members@odata.count"] =
2036 logServiceArrayLocal.size();
2037 });
Ed Tanous25b54db2024-04-17 15:40:31 -07002038 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002039}
2040
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002041inline void requestRoutesBMCLogServiceCollection(App& app)
2042{
Ed Tanous253f11b2024-05-16 09:38:31 -07002043 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/")
Gunnar Millsad89dcf2021-07-30 14:40:11 -05002044 .privileges(redfish::privileges::getLogServiceCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002045 .methods(boost::beast::http::verb::get)(
Claire Weinandd72e872022-08-15 14:20:06 -07002046 std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002047}
Ed Tanous1da66f72018-07-27 16:13:37 -07002048
Patrick Williams504af5a2025-02-03 14:29:03 -05002049inline void getDumpServiceInfo(
2050 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2051 const std::string& dumpType)
Claire Weinanfdd26902022-03-01 14:18:25 -08002052{
2053 std::string dumpPath;
Ed Tanous539d8c62024-06-19 14:38:27 -07002054 log_service::OverWritePolicy overWritePolicy =
2055 log_service::OverWritePolicy::Invalid;
Claire Weinanfdd26902022-03-01 14:18:25 -08002056 bool collectDiagnosticDataSupported = false;
2057
2058 if (dumpType == "BMC")
2059 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002060 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump",
2061 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002062 overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
Claire Weinanfdd26902022-03-01 14:18:25 -08002063 collectDiagnosticDataSupported = true;
2064 }
2065 else if (dumpType == "FaultLog")
2066 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002067 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog",
2068 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002069 overWritePolicy = log_service::OverWritePolicy::Unknown;
Claire Weinanfdd26902022-03-01 14:18:25 -08002070 collectDiagnosticDataSupported = false;
2071 }
2072 else if (dumpType == "System")
2073 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002074 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump",
2075 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002076 overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
Claire Weinanfdd26902022-03-01 14:18:25 -08002077 collectDiagnosticDataSupported = true;
2078 }
2079 else
2080 {
Ed Tanous62598e32023-07-17 17:06:25 -07002081 BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}",
2082 dumpType);
Claire Weinanfdd26902022-03-01 14:18:25 -08002083 messages::internalError(asyncResp->res);
2084 return;
2085 }
2086
2087 asyncResp->res.jsonValue["@odata.id"] = dumpPath;
2088 asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService";
2089 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2090 asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService";
2091 asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename();
Ed Tanous539d8c62024-06-19 14:38:27 -07002092 asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy;
Claire Weinanfdd26902022-03-01 14:18:25 -08002093
2094 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002095 redfish::time_utils::getDateTimeOffsetNow();
Claire Weinanfdd26902022-03-01 14:18:25 -08002096 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2097 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2098 redfishDateTimeOffset.second;
2099
2100 asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries";
Claire Weinanfdd26902022-03-01 14:18:25 -08002101
2102 if (collectDiagnosticDataSupported)
2103 {
2104 asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2105 ["target"] =
2106 dumpPath + "/Actions/LogService.CollectDiagnosticData";
2107 }
Claire Weinan0d946212022-07-13 19:40:19 -07002108
2109 constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface};
2110 dbus::utility::getSubTreePaths(
2111 "/xyz/openbmc_project/dump", 0, interfaces,
2112 [asyncResp, dumpType, dumpPath](
2113 const boost::system::error_code& ec,
2114 const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002115 if (ec)
Claire Weinan0d946212022-07-13 19:40:19 -07002116 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002117 BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}",
2118 ec);
2119 // Assume that getting an error simply means there are no dump
2120 // LogServices. Return without adding any error response.
2121 return;
Claire Weinan0d946212022-07-13 19:40:19 -07002122 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002123 std::string dbusDumpPath = getDumpPath(dumpType);
2124 for (const std::string& path : subTreePaths)
2125 {
2126 if (path == dbusDumpPath)
2127 {
2128 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2129 ["target"] =
2130 dumpPath + "/Actions/LogService.ClearLog";
2131 break;
2132 }
2133 }
2134 });
Claire Weinanfdd26902022-03-01 14:18:25 -08002135}
2136
2137inline void handleLogServicesDumpServiceGet(
2138 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002139 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2140 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002141{
2142 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2143 {
2144 return;
2145 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002146
2147 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2148 {
2149 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2150 return;
2151 }
2152
Claire Weinanfdd26902022-03-01 14:18:25 -08002153 getDumpServiceInfo(asyncResp, dumpType);
2154}
2155
Ed Tanous22d268c2022-05-19 09:39:07 -07002156inline void handleLogServicesDumpServiceComputerSystemGet(
2157 crow::App& app, const crow::Request& req,
2158 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2159 const std::string& chassisId)
2160{
2161 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2162 {
2163 return;
2164 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002165 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002166 {
2167 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2168 return;
2169 }
2170 getDumpServiceInfo(asyncResp, "System");
2171}
2172
Claire Weinanfdd26902022-03-01 14:18:25 -08002173inline void handleLogServicesDumpEntriesCollectionGet(
2174 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002175 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2176 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002177{
2178 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2179 {
2180 return;
2181 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002182
2183 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2184 {
2185 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2186 return;
2187 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002188 getDumpEntryCollection(asyncResp, dumpType);
2189}
2190
Ed Tanous22d268c2022-05-19 09:39:07 -07002191inline void handleLogServicesDumpEntriesCollectionComputerSystemGet(
2192 crow::App& app, const crow::Request& req,
2193 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2194 const std::string& chassisId)
2195{
2196 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2197 {
2198 return;
2199 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002200 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002201 {
2202 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2203 return;
2204 }
2205 getDumpEntryCollection(asyncResp, "System");
2206}
2207
Claire Weinanfdd26902022-03-01 14:18:25 -08002208inline void handleLogServicesDumpEntryGet(
2209 crow::App& app, const std::string& dumpType, const crow::Request& req,
2210 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002211 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002212{
2213 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2214 {
2215 return;
2216 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002217 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2218 {
2219 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2220 return;
2221 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002222 getDumpEntryById(asyncResp, dumpId, dumpType);
2223}
Carson Labrado168d1b12023-03-27 17:04:46 +00002224
Ed Tanous22d268c2022-05-19 09:39:07 -07002225inline void handleLogServicesDumpEntryComputerSystemGet(
2226 crow::App& app, const crow::Request& req,
2227 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2228 const std::string& chassisId, const std::string& dumpId)
2229{
2230 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2231 {
2232 return;
2233 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002234 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002235 {
2236 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2237 return;
2238 }
2239 getDumpEntryById(asyncResp, dumpId, "System");
2240}
Claire Weinanfdd26902022-03-01 14:18:25 -08002241
2242inline void handleLogServicesDumpEntryDelete(
2243 crow::App& app, const std::string& dumpType, const crow::Request& req,
2244 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002245 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002246{
2247 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2248 {
2249 return;
2250 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002251
2252 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2253 {
2254 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2255 return;
2256 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002257 deleteDumpEntry(asyncResp, dumpId, dumpType);
2258}
2259
Ed Tanous22d268c2022-05-19 09:39:07 -07002260inline void handleLogServicesDumpEntryComputerSystemDelete(
2261 crow::App& app, const crow::Request& req,
2262 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2263 const std::string& chassisId, const std::string& dumpId)
2264{
2265 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2266 {
2267 return;
2268 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002269 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002270 {
2271 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2272 return;
2273 }
2274 deleteDumpEntry(asyncResp, dumpId, "System");
2275}
2276
Carson Labrado168d1b12023-03-27 17:04:46 +00002277inline void handleLogServicesDumpEntryDownloadGet(
2278 crow::App& app, const std::string& dumpType, const crow::Request& req,
2279 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002280 const std::string& managerId, const std::string& dumpId)
Carson Labrado168d1b12023-03-27 17:04:46 +00002281{
2282 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2283 {
2284 return;
2285 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002286
2287 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2288 {
2289 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2290 return;
2291 }
Carson Labrado168d1b12023-03-27 17:04:46 +00002292 downloadDumpEntry(asyncResp, dumpId, dumpType);
2293}
2294
2295inline void handleDBusEventLogEntryDownloadGet(
2296 crow::App& app, const std::string& dumpType, const crow::Request& req,
2297 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2298 const std::string& systemName, const std::string& entryID)
2299{
2300 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2301 {
2302 return;
2303 }
2304 if (!http_helpers::isContentTypeAllowed(
2305 req.getHeaderValue("Accept"),
2306 http_helpers::ContentType::OctetStream, true))
2307 {
2308 asyncResp->res.result(boost::beast::http::status::bad_request);
2309 return;
2310 }
2311 downloadEventLogEntry(asyncResp, systemName, entryID, dumpType);
2312}
2313
Claire Weinanfdd26902022-03-01 14:18:25 -08002314inline void handleLogServicesDumpCollectDiagnosticDataPost(
2315 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002316 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2317 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002318{
2319 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2320 {
2321 return;
2322 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002323 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2324 {
2325 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2326 return;
2327 }
2328
Claire Weinanfdd26902022-03-01 14:18:25 -08002329 createDump(asyncResp, req, dumpType);
2330}
2331
Ed Tanous22d268c2022-05-19 09:39:07 -07002332inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost(
2333 crow::App& app, const crow::Request& req,
2334 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002335 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002336{
2337 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2338 {
2339 return;
2340 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002341
Ed Tanous25b54db2024-04-17 15:40:31 -07002342 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002343 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002344 // Option currently returns no systems. TBD
2345 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2346 systemName);
2347 return;
2348 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002349 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002350 {
2351 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2352 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002353 return;
2354 }
2355 createDump(asyncResp, req, "System");
2356}
2357
Claire Weinanfdd26902022-03-01 14:18:25 -08002358inline void handleLogServicesDumpClearLogPost(
2359 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002360 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2361 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002362{
2363 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2364 {
2365 return;
2366 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002367
2368 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2369 {
2370 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2371 return;
2372 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002373 clearDump(asyncResp, dumpType);
2374}
2375
Ed Tanous22d268c2022-05-19 09:39:07 -07002376inline void handleLogServicesDumpClearLogComputerSystemPost(
2377 crow::App& app, const crow::Request& req,
2378 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002379 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002380{
2381 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2382 {
2383 return;
2384 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002385 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002386 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002387 // Option currently returns no systems. TBD
2388 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2389 systemName);
2390 return;
2391 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002392 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002393 {
2394 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2395 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002396 return;
2397 }
2398 clearDump(asyncResp, "System");
2399}
2400
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002401inline void requestRoutesBMCDumpService(App& app)
2402{
Ed Tanous253f11b2024-05-16 09:38:31 -07002403 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002404 .privileges(redfish::privileges::getLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002405 .methods(boost::beast::http::verb::get)(std::bind_front(
2406 handleLogServicesDumpServiceGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002407}
2408
2409inline void requestRoutesBMCDumpEntryCollection(App& app)
2410{
Ed Tanous253f11b2024-05-16 09:38:31 -07002411 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002412 .privileges(redfish::privileges::getLogEntryCollection)
Claire Weinanfdd26902022-03-01 14:18:25 -08002413 .methods(boost::beast::http::verb::get)(std::bind_front(
2414 handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002415}
2416
2417inline void requestRoutesBMCDumpEntry(App& app)
2418{
2419 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002420 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002421 .privileges(redfish::privileges::getLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002422 .methods(boost::beast::http::verb::get)(std::bind_front(
2423 handleLogServicesDumpEntryGet, std::ref(app), "BMC"));
2424
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002425 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::deleteLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002428 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2429 handleLogServicesDumpEntryDelete, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002430}
2431
Carson Labrado168d1b12023-03-27 17:04:46 +00002432inline void requestRoutesBMCDumpEntryDownload(App& app)
2433{
2434 BMCWEB_ROUTE(
2435 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002436 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002437 .privileges(redfish::privileges::getLogEntry)
2438 .methods(boost::beast::http::verb::get)(std::bind_front(
2439 handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC"));
2440}
2441
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002442inline void requestRoutesBMCDumpCreate(App& app)
2443{
George Liu0fda0f12021-11-16 10:06:17 +08002444 BMCWEB_ROUTE(
2445 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002446 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002447 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002448 .methods(boost::beast::http::verb::post)(
Claire Weinanfdd26902022-03-01 14:18:25 -08002449 std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost,
2450 std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002451}
2452
2453inline void requestRoutesBMCDumpClear(App& app)
2454{
George Liu0fda0f12021-11-16 10:06:17 +08002455 BMCWEB_ROUTE(
2456 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002457 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002458 .privileges(redfish::privileges::postLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002459 .methods(boost::beast::http::verb::post)(std::bind_front(
2460 handleLogServicesDumpClearLogPost, std::ref(app), "BMC"));
2461}
2462
Carson Labrado168d1b12023-03-27 17:04:46 +00002463inline void requestRoutesDBusEventLogEntryDownload(App& app)
2464{
2465 BMCWEB_ROUTE(
2466 app,
Ravi Teja9e9d99d2023-11-08 05:33:59 -06002467 "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002468 .privileges(redfish::privileges::getLogEntry)
2469 .methods(boost::beast::http::verb::get)(std::bind_front(
2470 handleDBusEventLogEntryDownloadGet, std::ref(app), "System"));
2471}
2472
Claire Weinanfdd26902022-03-01 14:18:25 -08002473inline void requestRoutesFaultLogDumpService(App& app)
2474{
Ed Tanous253f11b2024-05-16 09:38:31 -07002475 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002476 .privileges(redfish::privileges::getLogService)
2477 .methods(boost::beast::http::verb::get)(std::bind_front(
2478 handleLogServicesDumpServiceGet, std::ref(app), "FaultLog"));
2479}
2480
2481inline void requestRoutesFaultLogDumpEntryCollection(App& app)
2482{
Ed Tanous253f11b2024-05-16 09:38:31 -07002483 BMCWEB_ROUTE(app,
2484 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002485 .privileges(redfish::privileges::getLogEntryCollection)
2486 .methods(boost::beast::http::verb::get)(
2487 std::bind_front(handleLogServicesDumpEntriesCollectionGet,
2488 std::ref(app), "FaultLog"));
2489}
2490
2491inline void requestRoutesFaultLogDumpEntry(App& app)
2492{
Ed Tanous253f11b2024-05-16 09:38:31 -07002493 BMCWEB_ROUTE(
2494 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002495 .privileges(redfish::privileges::getLogEntry)
2496 .methods(boost::beast::http::verb::get)(std::bind_front(
2497 handleLogServicesDumpEntryGet, std::ref(app), "FaultLog"));
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::deleteLogEntry)
2502 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2503 handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog"));
2504}
2505
2506inline void requestRoutesFaultLogDumpClear(App& app)
2507{
2508 BMCWEB_ROUTE(
2509 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002510 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002511 .privileges(redfish::privileges::postLogService)
2512 .methods(boost::beast::http::verb::post)(std::bind_front(
2513 handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002514}
2515
2516inline void requestRoutesSystemDumpService(App& app)
2517{
Ed Tanous22d268c2022-05-19 09:39:07 -07002518 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002519 .privileges(redfish::privileges::getLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002520 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002521 handleLogServicesDumpServiceComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002522}
2523
2524inline void requestRoutesSystemDumpEntryCollection(App& app)
2525{
Ed Tanous22d268c2022-05-19 09:39:07 -07002526 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002527 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous22d268c2022-05-19 09:39:07 -07002528 .methods(boost::beast::http::verb::get)(std::bind_front(
2529 handleLogServicesDumpEntriesCollectionComputerSystemGet,
2530 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002531}
2532
2533inline void requestRoutesSystemDumpEntry(App& app)
2534{
2535 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002536 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002537 .privileges(redfish::privileges::getLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002538 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002539 handleLogServicesDumpEntryComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002540
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::deleteLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002544 .methods(boost::beast::http::verb::delete_)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002545 handleLogServicesDumpEntryComputerSystemDelete, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002546}
2547
2548inline void requestRoutesSystemDumpCreate(App& app)
2549{
George Liu0fda0f12021-11-16 10:06:17 +08002550 BMCWEB_ROUTE(
2551 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002552 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002553 .privileges(redfish::privileges::postLogService)
Ed Tanous22d268c2022-05-19 09:39:07 -07002554 .methods(boost::beast::http::verb::post)(std::bind_front(
2555 handleLogServicesDumpCollectDiagnosticDataComputerSystemPost,
2556 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002557}
2558
2559inline void requestRoutesSystemDumpClear(App& app)
2560{
George Liu0fda0f12021-11-16 10:06:17 +08002561 BMCWEB_ROUTE(
2562 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002563 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002564 .privileges(redfish::privileges::postLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002565 .methods(boost::beast::http::verb::post)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002566 handleLogServicesDumpClearLogComputerSystemPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002567}
2568
2569inline void requestRoutesCrashdumpService(App& app)
2570{
2571 // Note: Deviated from redfish privilege registry for GET & HEAD
2572 // method for security reasons.
2573 /**
2574 * Functions triggers appropriate requests on DBus
2575 */
Ed Tanous22d268c2022-05-19 09:39:07 -07002576 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/")
Ed Tanoused398212021-06-09 17:05:54 -07002577 // This is incorrect, should be:
2578 //.privileges(redfish::privileges::getLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002579 .privileges({{"ConfigureManager"}})
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002580 .methods(
2581 boost::beast::http::verb::
2582 get)([&app](const crow::Request& req,
2583 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2584 const std::string& systemName) {
2585 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2586 {
2587 return;
2588 }
2589 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2590 {
2591 // Option currently returns no systems. TBD
2592 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2593 systemName);
2594 return;
2595 }
2596 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2597 {
2598 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2599 systemName);
2600 return;
2601 }
Ed Tanous22d268c2022-05-19 09:39:07 -07002602
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002603 // Copy over the static data to include the entries added by
2604 // SubRoute
2605 asyncResp->res.jsonValue["@odata.id"] =
2606 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
2607 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2608 asyncResp->res.jsonValue["@odata.type"] =
2609 "#LogService.v1_2_0.LogService";
2610 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2611 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
2612 asyncResp->res.jsonValue["Id"] = "Crashdump";
2613 asyncResp->res.jsonValue["OverWritePolicy"] =
2614 log_service::OverWritePolicy::WrapsWhenFull;
2615 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302616
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002617 std::pair<std::string, std::string> redfishDateTimeOffset =
2618 redfish::time_utils::getDateTimeOffsetNow();
2619 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2620 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2621 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302622
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002623 asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format(
2624 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2625 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2626 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2627 ["target"] = std::format(
2628 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog",
2629 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2630 asyncResp->res
2631 .jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2632 ["target"] = std::format(
2633 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData",
2634 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2635 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002636}
2637
2638void inline requestRoutesCrashdumpClear(App& app)
2639{
George Liu0fda0f12021-11-16 10:06:17 +08002640 BMCWEB_ROUTE(
2641 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002642 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002643 // This is incorrect, should be:
2644 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002645 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002646 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002647 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002648 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2649 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002650 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2651 {
2652 return;
2653 }
2654 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2655 {
2656 // Option currently returns no systems. TBD
2657 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2658 systemName);
2659 return;
2660 }
2661 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2662 {
2663 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2664 systemName);
2665 return;
2666 }
Ed Tanous177612a2025-02-14 15:16:09 -08002667 dbus::utility::async_method_call(
2668 asyncResp,
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002669 [asyncResp](const boost::system::error_code& ec,
2670 const std::string&) {
2671 if (ec)
2672 {
2673 messages::internalError(asyncResp->res);
2674 return;
2675 }
2676 messages::success(asyncResp->res);
2677 },
2678 crashdumpObject, crashdumpPath, deleteAllInterface,
2679 "DeleteAll");
2680 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002681}
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002682
Patrick Williams504af5a2025-02-03 14:29:03 -05002683inline void logCrashdumpEntry(
2684 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2685 const std::string& logID, nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07002686{
Johnathan Mantey043a0532020-03-10 17:15:28 -07002687 auto getStoredLogCallback =
Ed Tanousb9d36b42022-02-26 21:42:46 -08002688 [asyncResp, logID,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002689 &logEntryJson](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002690 const dbus::utility::DBusPropertiesMap& params) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002691 if (ec)
2692 {
2693 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
2694 if (ec.value() ==
2695 boost::system::linux_error::bad_request_descriptor)
2696 {
2697 messages::resourceNotFound(asyncResp->res, "LogEntry",
2698 logID);
2699 }
2700 else
2701 {
2702 messages::internalError(asyncResp->res);
2703 }
2704 return;
2705 }
2706
2707 std::string timestamp{};
2708 std::string filename{};
2709 std::string logfile{};
2710 parseCrashdumpParameters(params, filename, timestamp, logfile);
2711
2712 if (filename.empty() || timestamp.empty())
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002713 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002714 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002715 return;
2716 }
2717
2718 std::string crashdumpURI =
2719 std::format(
2720 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/",
2721 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
2722 logID + "/" + filename;
2723 nlohmann::json::object_t logEntry;
2724 logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
2725 logEntry["@odata.id"] = boost::urls::format(
2726 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}",
2727 BMCWEB_REDFISH_SYSTEM_URI_NAME, logID);
2728 logEntry["Name"] = "CPU Crashdump";
2729 logEntry["Id"] = logID;
2730 logEntry["EntryType"] = log_entry::LogEntryType::Oem;
2731 logEntry["AdditionalDataURI"] = std::move(crashdumpURI);
2732 logEntry["DiagnosticDataType"] = "OEM";
2733 logEntry["OEMDiagnosticDataType"] = "PECICrashdump";
2734 logEntry["Created"] = std::move(timestamp);
2735
2736 // If logEntryJson references an array of LogEntry resources
2737 // ('Members' list), then push this as a new entry, otherwise set it
2738 // directly
2739 if (logEntryJson.is_array())
2740 {
2741 logEntryJson.push_back(logEntry);
2742 asyncResp->res.jsonValue["Members@odata.count"] =
2743 logEntryJson.size();
Jason M. Bills2b20ef62022-01-06 15:48:07 -08002744 }
2745 else
2746 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002747 logEntryJson.update(logEntry);
Jason M. Bills2b20ef62022-01-06 15:48:07 -08002748 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002749 };
Ed Tanousdeae6a72024-11-11 21:58:57 -08002750 dbus::utility::getAllProperties(
2751 crashdumpObject, crashdumpPath + std::string("/") + logID,
2752 crashdumpInterface, std::move(getStoredLogCallback));
Jason M. Billse855dd22019-10-08 11:37:48 -07002753}
2754
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002755inline void requestRoutesCrashdumpEntryCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07002756{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002757 // Note: Deviated from redfish privilege registry for GET & HEAD
2758 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002759 /**
2760 * Functions triggers appropriate requests on DBus
2761 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002762 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002763 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002764 // This is incorrect, should be.
2765 //.privileges(redfish::privileges::postLogEntryCollection)
Ed Tanous432a8902021-06-14 15:28:56 -07002766 .privileges({{"ConfigureComponents"}})
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002767 .methods(
2768 boost::beast::http::verb::
2769 get)([&app](const crow::Request& req,
2770 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2771 const std::string& systemName) {
2772 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -07002773 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002774 return;
Ed Tanous45ca1b82022-03-25 13:07:27 -07002775 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002776 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07002777 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002778 // Option currently returns no systems. TBD
2779 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2780 systemName);
2781 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07002782 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002783 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2784 {
2785 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2786 systemName);
2787 return;
2788 }
2789
2790 constexpr std::array<std::string_view, 1> interfaces = {
2791 crashdumpInterface};
2792 dbus::utility::getSubTreePaths(
2793 "/", 0, interfaces,
2794 [asyncResp](const boost::system::error_code& ec,
2795 const std::vector<std::string>& resp) {
2796 if (ec)
2797 {
2798 if (ec.value() !=
2799 boost::system::errc::no_such_file_or_directory)
2800 {
2801 BMCWEB_LOG_DEBUG("failed to get entries ec: {}",
2802 ec.message());
2803 messages::internalError(asyncResp->res);
2804 return;
2805 }
2806 }
2807 asyncResp->res.jsonValue["@odata.type"] =
2808 "#LogEntryCollection.LogEntryCollection";
2809 asyncResp->res.jsonValue["@odata.id"] = std::format(
2810 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2811 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2812 asyncResp->res.jsonValue["Name"] =
2813 "Open BMC Crashdump Entries";
2814 asyncResp->res.jsonValue["Description"] =
2815 "Collection of Crashdump Entries";
2816 asyncResp->res.jsonValue["Members"] =
2817 nlohmann::json::array();
2818 asyncResp->res.jsonValue["Members@odata.count"] = 0;
2819
2820 for (const std::string& path : resp)
2821 {
2822 const sdbusplus::message::object_path objPath(path);
2823 // Get the log ID
2824 std::string logID = objPath.filename();
2825 if (logID.empty())
2826 {
2827 continue;
2828 }
2829 // Add the log entry to the array
2830 logCrashdumpEntry(asyncResp, logID,
2831 asyncResp->res.jsonValue["Members"]);
2832 }
2833 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002834 });
2835}
Ed Tanous1da66f72018-07-27 16:13:37 -07002836
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002837inline void requestRoutesCrashdumpEntry(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07002838{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002839 // Note: Deviated from redfish privilege registry for GET & HEAD
2840 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002841
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002842 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07002843 app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002844 // this is incorrect, should be
2845 // .privileges(redfish::privileges::getLogEntry)
Ed Tanous432a8902021-06-14 15:28:56 -07002846 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002847 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002848 [&app](const crow::Request& req,
2849 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07002850 const std::string& systemName, const std::string& param) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002851 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2852 {
2853 return;
2854 }
2855 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2856 {
2857 // Option currently returns no systems. TBD
2858 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2859 systemName);
2860 return;
2861 }
2862 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2863 {
2864 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2865 systemName);
2866 return;
2867 }
2868 const std::string& logID = param;
2869 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2870 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002871}
Ed Tanous1da66f72018-07-27 16:13:37 -07002872
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002873inline void requestRoutesCrashdumpFile(App& app)
2874{
2875 // Note: Deviated from redfish privilege registry for GET & HEAD
2876 // method for security reasons.
2877 BMCWEB_ROUTE(
2878 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002879 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002880 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002881 .methods(boost::beast::http::verb::get)(
Nan Zhoua4ce1142022-08-02 18:45:25 +00002882 [](const crow::Request& req,
2883 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07002884 const std::string& systemName, const std::string& logID,
2885 const std::string& fileName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002886 // Do not call getRedfishRoute here since the crashdump file is
2887 // not a Redfish resource.
Ed Tanous22d268c2022-05-19 09:39:07 -07002888
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002889 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2890 {
2891 // Option currently returns no systems. TBD
2892 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2893 systemName);
2894 return;
2895 }
2896 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2897 {
2898 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2899 systemName);
2900 return;
2901 }
Ed Tanous22d268c2022-05-19 09:39:07 -07002902
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002903 auto getStoredLogCallback =
2904 [asyncResp, logID, fileName,
2905 url(boost::urls::url(req.url()))](
2906 const boost::system::error_code& ec,
2907 const std::vector<std::pair<
2908 std::string, dbus::utility::DbusVariantType>>&
2909 resp) {
2910 if (ec)
2911 {
2912 BMCWEB_LOG_DEBUG("failed to get log ec: {}",
2913 ec.message());
2914 messages::internalError(asyncResp->res);
2915 return;
2916 }
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002917
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002918 std::string dbusFilename{};
2919 std::string dbusTimestamp{};
2920 std::string dbusFilepath{};
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002921
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002922 parseCrashdumpParameters(resp, dbusFilename,
2923 dbusTimestamp, dbusFilepath);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002924
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002925 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2926 dbusFilepath.empty())
2927 {
2928 messages::resourceNotFound(asyncResp->res,
2929 "LogEntry", logID);
2930 return;
2931 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002932
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002933 // Verify the file name parameter is correct
2934 if (fileName != dbusFilename)
2935 {
2936 messages::resourceNotFound(asyncResp->res,
2937 "LogEntry", logID);
2938 return;
2939 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002940
Myung Baed51c61b2024-09-13 10:35:34 -05002941 if (asyncResp->res.openFile(dbusFilepath) !=
2942 crow::OpenCode::Success)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002943 {
2944 messages::resourceNotFound(asyncResp->res,
2945 "LogEntry", logID);
2946 return;
2947 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002948
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002949 // Configure this to be a file download when accessed
2950 // from a browser
2951 asyncResp->res.addHeader(
2952 boost::beast::http::field::content_disposition,
2953 "attachment");
2954 };
Ed Tanousdeae6a72024-11-11 21:58:57 -08002955 dbus::utility::getAllProperties(
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002956 *crow::connections::systemBus, crashdumpObject,
2957 crashdumpPath + std::string("/") + logID,
2958 crashdumpInterface, std::move(getStoredLogCallback));
2959 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002960}
2961
Jason M. Billsc5a4c822022-01-06 15:51:23 -08002962enum class OEMDiagnosticType
2963{
2964 onDemand,
2965 telemetry,
2966 invalid,
2967};
2968
Ed Tanous26ccae32023-02-16 10:28:44 -08002969inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr)
Jason M. Billsc5a4c822022-01-06 15:51:23 -08002970{
2971 if (oemDiagStr == "OnDemand")
2972 {
2973 return OEMDiagnosticType::onDemand;
2974 }
2975 if (oemDiagStr == "Telemetry")
2976 {
2977 return OEMDiagnosticType::telemetry;
2978 }
2979
2980 return OEMDiagnosticType::invalid;
2981}
2982
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002983inline void requestRoutesCrashdumpCollect(App& app)
2984{
2985 // Note: Deviated from redfish privilege registry for GET & HEAD
2986 // method for security reasons.
George Liu0fda0f12021-11-16 10:06:17 +08002987 BMCWEB_ROUTE(
2988 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002989 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002990 // The below is incorrect; Should be ConfigureManager
2991 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002992 .privileges({{"ConfigureComponents"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07002993 .methods(boost::beast::http::verb::post)(
2994 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002995 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2996 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002997 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002998 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002999 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07003000 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003001
3002 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07003003 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003004 // Option currently returns no systems. TBD
3005 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3006 systemName);
3007 return;
3008 }
3009 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
3010 {
3011 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3012 systemName);
3013 return;
3014 }
3015
3016 std::string diagnosticDataType;
3017 std::string oemDiagnosticDataType;
Patrick Williams504af5a2025-02-03 14:29:03 -05003018 if (!redfish::json_util::readJsonAction( //
3019 req, asyncResp->res, //
3020 "DiagnosticDataType", diagnosticDataType, //
Myung Baeafc474a2024-10-09 00:53:29 -07003021 "OEMDiagnosticDataType", oemDiagnosticDataType //
3022 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003023 {
3024 return;
3025 }
3026
3027 if (diagnosticDataType != "OEM")
3028 {
3029 BMCWEB_LOG_ERROR(
3030 "Only OEM DiagnosticDataType supported for Crashdump");
3031 messages::actionParameterValueFormatError(
3032 asyncResp->res, diagnosticDataType,
3033 "DiagnosticDataType", "CollectDiagnosticData");
3034 return;
3035 }
3036
3037 OEMDiagnosticType oemDiagType =
3038 getOEMDiagnosticType(oemDiagnosticDataType);
3039
3040 std::string iface;
3041 std::string method;
3042 std::string taskMatchStr;
3043 if (oemDiagType == OEMDiagnosticType::onDemand)
3044 {
3045 iface = crashdumpOnDemandInterface;
3046 method = "GenerateOnDemandLog";
3047 taskMatchStr =
3048 "type='signal',"
3049 "interface='org.freedesktop.DBus.Properties',"
3050 "member='PropertiesChanged',"
3051 "arg0namespace='com.intel.crashdump'";
3052 }
3053 else if (oemDiagType == OEMDiagnosticType::telemetry)
3054 {
3055 iface = crashdumpTelemetryInterface;
3056 method = "GenerateTelemetryLog";
3057 taskMatchStr =
3058 "type='signal',"
3059 "interface='org.freedesktop.DBus.Properties',"
3060 "member='PropertiesChanged',"
3061 "arg0namespace='com.intel.crashdump'";
Ed Tanous002d39b2022-05-31 08:59:27 -07003062 }
3063 else
3064 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003065 BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}",
3066 oemDiagnosticDataType);
3067 messages::actionParameterValueFormatError(
3068 asyncResp->res, oemDiagnosticDataType,
3069 "OEMDiagnosticDataType", "CollectDiagnosticData");
3070 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07003071 }
Ed Tanous1da66f72018-07-27 16:13:37 -07003072
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003073 auto collectCrashdumpCallback =
3074 [asyncResp, payload(task::Payload(req)),
3075 taskMatchStr](const boost::system::error_code& ec,
3076 const std::string&) mutable {
3077 if (ec)
3078 {
3079 if (ec.value() ==
3080 boost::system::errc::operation_not_supported)
3081 {
3082 messages::resourceInStandby(asyncResp->res);
3083 }
3084 else if (ec.value() == boost::system::errc::
3085 device_or_resource_busy)
3086 {
3087 messages::serviceTemporarilyUnavailable(
3088 asyncResp->res, "60");
3089 }
3090 else
3091 {
3092 messages::internalError(asyncResp->res);
3093 }
3094 return;
3095 }
3096 std::shared_ptr<task::TaskData> task =
3097 task::TaskData::createTask(
3098 [](const boost::system::error_code& ec2,
3099 sdbusplus::message_t&,
3100 const std::shared_ptr<task::TaskData>&
3101 taskData) {
3102 if (!ec2)
3103 {
3104 taskData->messages.emplace_back(
3105 messages::taskCompletedOK(
3106 std::to_string(
3107 taskData->index)));
3108 taskData->state = "Completed";
3109 }
3110 return task::completed;
3111 },
3112 taskMatchStr);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003113
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003114 task->startTimer(std::chrono::minutes(5));
3115 task->populateResp(asyncResp->res);
3116 task->payload.emplace(std::move(payload));
3117 };
3118
Ed Tanous177612a2025-02-14 15:16:09 -08003119 dbus::utility::async_method_call(
3120 asyncResp, std::move(collectCrashdumpCallback),
3121 crashdumpObject, crashdumpPath, iface, method);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003122 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003123}
Kenny L. Ku6eda7682020-06-19 09:48:36 -07003124
Alexander Hansen599b9af2024-08-06 15:11:57 +02003125inline void dBusLogServiceActionsClear(
3126 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
3127{
3128 BMCWEB_LOG_DEBUG("Do delete all entries.");
3129
3130 // Process response from Logging service.
3131 auto respHandler = [asyncResp](const boost::system::error_code& ec) {
3132 BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done");
3133 if (ec)
3134 {
3135 // TODO Handle for specific error code
3136 BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec);
3137 asyncResp->res.result(
3138 boost::beast::http::status::internal_server_error);
3139 return;
3140 }
3141
3142 asyncResp->res.result(boost::beast::http::status::no_content);
3143 };
3144
3145 // Make call to Logging service to request Clear Log
Ed Tanous177612a2025-02-14 15:16:09 -08003146 dbus::utility::async_method_call(
3147 asyncResp, respHandler, "xyz.openbmc_project.Logging",
Alexander Hansen599b9af2024-08-06 15:11:57 +02003148 "/xyz/openbmc_project/logging",
3149 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3150}
3151
Andrew Geisslercb92c032018-08-17 07:56:14 -07003152/**
3153 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3154 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003155inline void requestRoutesDBusLogServiceActionsClear(App& app)
Andrew Geisslercb92c032018-08-17 07:56:14 -07003156{
Andrew Geisslercb92c032018-08-17 07:56:14 -07003157 /**
3158 * Function handles POST method request.
3159 * The Clear Log actions does not require any parameter.The action deletes
3160 * all entries found in the Entries collection for this Log Service.
3161 */
Andrew Geisslercb92c032018-08-17 07:56:14 -07003162
George Liu0fda0f12021-11-16 10:06:17 +08003163 BMCWEB_ROUTE(
3164 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003165 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07003166 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003167 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003168 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003169 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3170 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003171 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3172 {
3173 return;
3174 }
3175 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
3176 {
3177 // Option currently returns no systems. TBD
3178 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3179 systemName);
3180 return;
3181 }
3182 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
3183 {
3184 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3185 systemName);
3186 return;
3187 }
3188 dBusLogServiceActionsClear(asyncResp);
3189 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003190}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003191
Ed Tanous1da66f72018-07-27 16:13:37 -07003192} // namespace redfish