blob: fd76da510924e91f4482210dde60ed558a8d1bd1 [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
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500593 crow::connections::systemBus->async_method_call(
594 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
709 crow::connections::systemBus->async_method_call(
710 std::move(downloadDumpEntryHandler), "xyz.openbmc_project.Dump.Manager",
711 dumpEntryPath, "xyz.openbmc_project.Dump.Entry", "GetFileHandle");
712}
713
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400714inline void downloadEventLogEntry(
715 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
716 const std::string& systemName, const std::string& entryID,
717 const std::string& dumpType)
Carson Labrado168d1b12023-03-27 17:04:46 +0000718{
Ed Tanous25b54db2024-04-17 15:40:31 -0700719 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Carson Labrado168d1b12023-03-27 17:04:46 +0000720 {
721 // Option currently returns no systems. TBD
722 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
723 systemName);
724 return;
725 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700726 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Carson Labrado168d1b12023-03-27 17:04:46 +0000727 {
728 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
729 systemName);
730 return;
731 }
732
733 std::string entryPath =
734 sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") /
735 entryID;
736
737 auto downloadEventLogEntryHandler =
738 [asyncResp, entryID,
739 dumpType](const boost::system::error_code& ec,
740 const sdbusplus::message::unix_fd& unixfd) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400741 downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
742 };
Carson Labrado168d1b12023-03-27 17:04:46 +0000743
744 crow::connections::systemBus->async_method_call(
745 std::move(downloadEventLogEntryHandler), "xyz.openbmc_project.Logging",
746 entryPath, "xyz.openbmc_project.Logging.Entry", "GetEntry");
747}
748
Patrick Williams504af5a2025-02-03 14:29:03 -0500749inline DumpCreationProgress mapDbusStatusToDumpProgress(
750 const std::string& status)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500751{
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600752 if (status ==
753 "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" ||
754 status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted")
755 {
756 return DumpCreationProgress::DUMP_CREATE_FAILED;
757 }
758 if (status ==
759 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed")
760 {
761 return DumpCreationProgress::DUMP_CREATE_SUCCESS;
762 }
763 return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
764}
765
Patrick Williams504af5a2025-02-03 14:29:03 -0500766inline DumpCreationProgress getDumpCompletionStatus(
767 const dbus::utility::DBusPropertiesMap& values)
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600768{
769 for (const auto& [key, val] : values)
770 {
771 if (key == "Status")
Ed Tanous002d39b2022-05-31 08:59:27 -0700772 {
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600773 const std::string* value = std::get_if<std::string>(&val);
774 if (value == nullptr)
775 {
Ed Tanous62598e32023-07-17 17:06:25 -0700776 BMCWEB_LOG_ERROR("Status property value is null");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600777 return DumpCreationProgress::DUMP_CREATE_FAILED;
778 }
779 return mapDbusStatusToDumpProgress(*value);
780 }
781 }
782 return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
783}
784
785inline std::string getDumpEntryPath(const std::string& dumpPath)
786{
787 if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry")
788 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700789 return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
Ed Tanous9f565092024-07-12 22:06:53 -0700790 BMCWEB_REDFISH_MANAGER_URI_NAME);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600791 }
792 if (dumpPath == "/xyz/openbmc_project/dump/system/entry")
793 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700794 return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
795 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600796 }
797 return "";
798}
799
800inline void createDumpTaskCallback(
801 task::Payload&& payload,
802 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
803 const sdbusplus::message::object_path& createdObjPath)
804{
805 const std::string dumpPath = createdObjPath.parent_path().str;
806 const std::string dumpId = createdObjPath.filename();
807
808 std::string dumpEntryPath = getDumpEntryPath(dumpPath);
809
810 if (dumpEntryPath.empty())
811 {
Ed Tanous62598e32023-07-17 17:06:25 -0700812 BMCWEB_LOG_ERROR("Invalid dump type received");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600813 messages::internalError(asyncResp->res);
814 return;
815 }
816
817 crow::connections::systemBus->async_method_call(
Ed Tanous8cb2c022024-03-27 16:31:46 -0700818 [asyncResp, payload = std::move(payload), createdObjPath,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600819 dumpEntryPath{std::move(dumpEntryPath)},
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800820 dumpId](const boost::system::error_code& ec,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600821 const std::string& introspectXml) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400822 if (ec)
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600823 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400824 BMCWEB_LOG_ERROR("Introspect call failed with error: {}",
825 ec.message());
826 messages::internalError(asyncResp->res);
827 return;
828 }
829
830 // Check if the created dump object has implemented Progress
831 // interface to track dump completion. If yes, fetch the "Status"
832 // property of the interface, modify the task state accordingly.
833 // Else, return task completed.
834 tinyxml2::XMLDocument doc;
835
836 doc.Parse(introspectXml.data(), introspectXml.size());
837 tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
838 if (pRoot == nullptr)
839 {
840 BMCWEB_LOG_ERROR("XML document failed to parse");
841 messages::internalError(asyncResp->res);
842 return;
843 }
844 tinyxml2::XMLElement* interfaceNode =
845 pRoot->FirstChildElement("interface");
846
847 bool isProgressIntfPresent = false;
848 while (interfaceNode != nullptr)
849 {
850 const char* thisInterfaceName =
851 interfaceNode->Attribute("name");
852 if (thisInterfaceName != nullptr)
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600853 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400854 if (thisInterfaceName ==
855 std::string_view("xyz.openbmc_project.Common.Progress"))
856 {
857 interfaceNode =
858 interfaceNode->NextSiblingElement("interface");
859 continue;
860 }
861 isProgressIntfPresent = true;
862 break;
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600863 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400864 interfaceNode = interfaceNode->NextSiblingElement("interface");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600865 }
866
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400867 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
868 [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent](
869 const boost::system::error_code& ec2,
870 sdbusplus::message_t& msg,
871 const std::shared_ptr<task::TaskData>& taskData) {
872 if (ec2)
873 {
874 BMCWEB_LOG_ERROR("{}: Error in creating dump",
875 createdObjPath.str);
876 taskData->messages.emplace_back(
877 messages::internalError());
878 taskData->state = "Cancelled";
879 return task::completed;
880 }
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600881
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400882 if (isProgressIntfPresent)
883 {
884 dbus::utility::DBusPropertiesMap values;
885 std::string prop;
886 msg.read(prop, values);
887
888 DumpCreationProgress dumpStatus =
889 getDumpCompletionStatus(values);
890 if (dumpStatus ==
891 DumpCreationProgress::DUMP_CREATE_FAILED)
892 {
893 BMCWEB_LOG_ERROR("{}: Error in creating dump",
894 createdObjPath.str);
895 taskData->state = "Cancelled";
896 return task::completed;
897 }
898
899 if (dumpStatus ==
900 DumpCreationProgress::DUMP_CREATE_INPROGRESS)
901 {
902 BMCWEB_LOG_DEBUG(
903 "{}: Dump creation task is in progress",
904 createdObjPath.str);
905 return !task::completed;
906 }
907 }
908
909 nlohmann::json retMessage = messages::success();
910 taskData->messages.emplace_back(retMessage);
911
912 boost::urls::url url = boost::urls::format(
913 "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}",
914 BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId);
915
916 std::string headerLoc = "Location: ";
917 headerLoc += url.buffer();
918
919 taskData->payload->httpHeaders.emplace_back(
920 std::move(headerLoc));
921
922 BMCWEB_LOG_DEBUG("{}: Dump creation task completed",
Ed Tanous62598e32023-07-17 17:06:25 -0700923 createdObjPath.str);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400924 taskData->state = "Completed";
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600925 return task::completed;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400926 },
927 "type='signal',interface='org.freedesktop.DBus.Properties',"
928 "member='PropertiesChanged',path='" +
929 createdObjPath.str + "'");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600930
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400931 // The task timer is set to max time limit within which the
932 // requested dump will be collected.
933 task->startTimer(std::chrono::minutes(6));
934 task->populateResp(asyncResp->res);
935 task->payload.emplace(payload);
Patrick Williams5a39f772023-10-20 11:20:21 -0500936 },
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600937 "xyz.openbmc_project.Dump.Manager", createdObjPath,
938 "org.freedesktop.DBus.Introspectable", "Introspect");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500939}
940
zhanghch058d1b46d2021-04-01 11:18:24 +0800941inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
942 const crow::Request& req, const std::string& dumpType)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500943{
Claire Weinanfdd26902022-03-01 14:18:25 -0800944 std::string dumpPath = getDumpEntriesPath(dumpType);
945 if (dumpPath.empty())
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500946 {
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500947 messages::internalError(asyncResp->res);
948 return;
949 }
950
951 std::optional<std::string> diagnosticDataType;
952 std::optional<std::string> oemDiagnosticDataType;
953
Patrick Williams504af5a2025-02-03 14:29:03 -0500954 if (!redfish::json_util::readJsonAction( //
955 req, asyncResp->res, //
956 "DiagnosticDataType", diagnosticDataType, //
Myung Baeafc474a2024-10-09 00:53:29 -0700957 "OEMDiagnosticDataType", oemDiagnosticDataType //
958 ))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500959 {
960 return;
961 }
962
963 if (dumpType == "System")
964 {
965 if (!oemDiagnosticDataType || !diagnosticDataType)
966 {
Ed Tanous62598e32023-07-17 17:06:25 -0700967 BMCWEB_LOG_ERROR(
968 "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500969 messages::actionParameterMissing(
970 asyncResp->res, "CollectDiagnosticData",
971 "DiagnosticDataType & OEMDiagnosticDataType");
972 return;
973 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700974 if ((*oemDiagnosticDataType != "System") ||
975 (*diagnosticDataType != "OEM"))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500976 {
Ed Tanous62598e32023-07-17 17:06:25 -0700977 BMCWEB_LOG_ERROR("Wrong parameter values passed");
Ed Tanousace85d62021-10-26 12:45:59 -0700978 messages::internalError(asyncResp->res);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500979 return;
980 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700981 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/",
982 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500983 }
984 else if (dumpType == "BMC")
985 {
986 if (!diagnosticDataType)
987 {
Ed Tanous62598e32023-07-17 17:06:25 -0700988 BMCWEB_LOG_ERROR(
989 "CreateDump action parameter 'DiagnosticDataType' not found!");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500990 messages::actionParameterMissing(
991 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
992 return;
993 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700994 if (*diagnosticDataType != "Manager")
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500995 {
Ed Tanous62598e32023-07-17 17:06:25 -0700996 BMCWEB_LOG_ERROR(
997 "Wrong parameter value passed for 'DiagnosticDataType'");
Ed Tanousace85d62021-10-26 12:45:59 -0700998 messages::internalError(asyncResp->res);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500999 return;
1000 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001001 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/",
1002 BMCWEB_REDFISH_MANAGER_URI_NAME);
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001003 }
1004 else
1005 {
Ed Tanous62598e32023-07-17 17:06:25 -07001006 BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type");
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001007 messages::internalError(asyncResp->res);
1008 return;
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001009 }
1010
Asmitha Karunanithi8e317782020-12-10 03:35:05 -06001011 std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>>
1012 createDumpParamVec;
1013
Carson Labradof574a8e2023-03-22 02:26:00 +00001014 if (req.session != nullptr)
1015 {
1016 createDumpParamVec.emplace_back(
1017 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId",
1018 req.session->clientIp);
1019 createDumpParamVec.emplace_back(
1020 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType",
1021 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client");
1022 }
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -06001023
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001024 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001025 [asyncResp, payload(task::Payload(req)),
1026 dumpPath](const boost::system::error_code& ec,
1027 const sdbusplus::message_t& msg,
1028 const sdbusplus::message::object_path& objPath) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001029 if (ec)
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001030 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001031 BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec);
1032 const sd_bus_error* dbusError = msg.get_error();
1033 if (dbusError == nullptr)
1034 {
1035 messages::internalError(asyncResp->res);
1036 return;
1037 }
1038
1039 BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}",
1040 dbusError->name, dbusError->message);
1041 if (std::string_view(
1042 "xyz.openbmc_project.Common.Error.NotAllowed") ==
1043 dbusError->name)
1044 {
1045 messages::resourceInStandby(asyncResp->res);
1046 return;
1047 }
1048 if (std::string_view(
1049 "xyz.openbmc_project.Dump.Create.Error.Disabled") ==
1050 dbusError->name)
1051 {
1052 messages::serviceDisabled(asyncResp->res, dumpPath);
1053 return;
1054 }
1055 if (std::string_view(
1056 "xyz.openbmc_project.Common.Error.Unavailable") ==
1057 dbusError->name)
1058 {
1059 messages::resourceInUse(asyncResp->res);
1060 return;
1061 }
1062 // Other Dbus errors such as:
1063 // xyz.openbmc_project.Common.Error.InvalidArgument &
1064 // org.freedesktop.DBus.Error.InvalidArgs are all related to
1065 // the dbus call that is made here in the bmcweb
1066 // implementation and has nothing to do with the client's
1067 // input in the request. Hence, returning internal error
1068 // back to the client.
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001069 messages::internalError(asyncResp->res);
1070 return;
1071 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001072 BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str);
1073 createDumpTaskCallback(std::move(payload), asyncResp, objPath);
1074 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001075 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Asmitha Karunanithi8e317782020-12-10 03:35:05 -06001076 "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec);
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001077}
1078
zhanghch058d1b46d2021-04-01 11:18:24 +08001079inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1080 const std::string& dumpType)
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001081{
Claire Weinan0d946212022-07-13 19:40:19 -07001082 crow::connections::systemBus->async_method_call(
1083 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001084 if (ec)
1085 {
1086 BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec);
1087 messages::internalError(asyncResp->res);
1088 return;
1089 }
1090 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001091 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Claire Weinan0d946212022-07-13 19:40:19 -07001092 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001093}
1094
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001095inline void parseCrashdumpParameters(
1096 const dbus::utility::DBusPropertiesMap& params, std::string& filename,
1097 std::string& timestamp, std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001098{
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001099 const std::string* filenamePtr = nullptr;
1100 const std::string* timestampPtr = nullptr;
1101 const std::string* logfilePtr = nullptr;
1102
1103 const bool success = sdbusplus::unpackPropertiesNoThrow(
1104 dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr,
1105 "Filename", filenamePtr, "Log", logfilePtr);
1106
1107 if (!success)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001108 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001109 return;
1110 }
1111
1112 if (filenamePtr != nullptr)
1113 {
1114 filename = *filenamePtr;
1115 }
1116
1117 if (timestampPtr != nullptr)
1118 {
1119 timestamp = *timestampPtr;
1120 }
1121
1122 if (logfilePtr != nullptr)
1123 {
1124 logfile = *logfilePtr;
Johnathan Mantey043a0532020-03-10 17:15:28 -07001125 }
1126}
1127
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001128inline void requestRoutesSystemLogServiceCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07001129{
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001130 /**
1131 * Functions triggers appropriate requests on DBus
1132 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001133 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
Ed Tanoused398212021-06-09 17:05:54 -07001134 .privileges(redfish::privileges::getLogServiceCollection)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001135 .methods(
1136 boost::beast::http::verb::
1137 get)([&app](const crow::Request& req,
1138 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1139 const std::string& systemName) {
1140 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001141 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001142 return;
1143 }
1144 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1145 {
1146 // Option currently returns no systems. TBD
1147 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1148 systemName);
1149 return;
1150 }
1151 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1152 {
1153 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1154 systemName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001155 return;
1156 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001157
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001158 // Collections don't include the static data added by SubRoute
1159 // because it has a duplicate entry for members
1160 asyncResp->res.jsonValue["@odata.type"] =
1161 "#LogServiceCollection.LogServiceCollection";
1162 asyncResp->res.jsonValue["@odata.id"] =
1163 std::format("/redfish/v1/Systems/{}/LogServices",
1164 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1165 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
1166 asyncResp->res.jsonValue["Description"] =
1167 "Collection of LogServices for this Computer System";
1168 nlohmann::json& logServiceArray =
1169 asyncResp->res.jsonValue["Members"];
1170 logServiceArray = nlohmann::json::array();
1171 nlohmann::json::object_t eventLog;
1172 eventLog["@odata.id"] =
1173 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1174 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1175 logServiceArray.emplace_back(std::move(eventLog));
1176 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
Ed Tanous002d39b2022-05-31 08:59:27 -07001177 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001178 nlohmann::json::object_t dumpLog;
1179 dumpLog["@odata.id"] =
1180 std::format("/redfish/v1/Systems/{}/LogServices/Dump",
1181 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1182 logServiceArray.emplace_back(std::move(dumpLog));
Ed Tanous002d39b2022-05-31 08:59:27 -07001183 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001184
1185 if constexpr (BMCWEB_REDFISH_CPU_LOG)
1186 {
1187 nlohmann::json::object_t crashdump;
1188 crashdump["@odata.id"] =
1189 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
1190 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1191 logServiceArray.emplace_back(std::move(crashdump));
1192 }
1193
1194 if constexpr (BMCWEB_REDFISH_HOST_LOGGER)
1195 {
1196 nlohmann::json::object_t hostlogger;
1197 hostlogger["@odata.id"] =
1198 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
1199 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1200 logServiceArray.emplace_back(std::move(hostlogger));
1201 }
1202 asyncResp->res.jsonValue["Members@odata.count"] =
1203 logServiceArray.size();
1204
1205 constexpr std::array<std::string_view, 1> interfaces = {
1206 "xyz.openbmc_project.State.Boot.PostCode"};
1207 dbus::utility::getSubTreePaths(
1208 "/", 0, interfaces,
1209 [asyncResp](const boost::system::error_code& ec,
1210 const dbus::utility::MapperGetSubTreePathsResponse&
1211 subtreePath) {
1212 if (ec)
1213 {
1214 BMCWEB_LOG_ERROR("{}", ec);
1215 return;
1216 }
1217
1218 for (const auto& pathStr : subtreePath)
1219 {
1220 if (pathStr.find("PostCode") != std::string::npos)
1221 {
1222 nlohmann::json& logServiceArrayLocal =
1223 asyncResp->res.jsonValue["Members"];
1224 nlohmann::json::object_t member;
1225 member["@odata.id"] = std::format(
1226 "/redfish/v1/Systems/{}/LogServices/PostCodes",
1227 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1228
1229 logServiceArrayLocal.emplace_back(
1230 std::move(member));
1231
1232 asyncResp->res.jsonValue["Members@odata.count"] =
1233 logServiceArrayLocal.size();
1234 return;
1235 }
1236 }
1237 });
Ed Tanous45ca1b82022-03-25 13:07:27 -07001238 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001239}
1240
1241inline void requestRoutesEventLogService(App& app)
1242{
Ed Tanous22d268c2022-05-19 09:39:07 -07001243 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/")
Ed Tanoused398212021-06-09 17:05:54 -07001244 .privileges(redfish::privileges::getLogService)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001245 .methods(
1246 boost::beast::http::verb::
1247 get)([&app](const crow::Request& req,
1248 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1249 const std::string& systemName) {
1250 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1251 {
1252 return;
1253 }
1254 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1255 {
1256 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1257 systemName);
1258 return;
1259 }
1260 asyncResp->res.jsonValue["@odata.id"] =
1261 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1262 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1263 asyncResp->res.jsonValue["@odata.type"] =
1264 "#LogService.v1_2_0.LogService";
1265 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1266 asyncResp->res.jsonValue["Description"] =
1267 "System Event Log Service";
1268 asyncResp->res.jsonValue["Id"] = "EventLog";
1269 asyncResp->res.jsonValue["OverWritePolicy"] =
1270 log_service::OverWritePolicy::WrapsWhenFull;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301271
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001272 std::pair<std::string, std::string> redfishDateTimeOffset =
1273 redfish::time_utils::getDateTimeOffsetNow();
Tejas Patil7c8c4052021-06-04 17:43:14 +05301274
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001275 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
1276 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
1277 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301278
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001279 asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format(
1280 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
Ed Tanous20fa6a22024-05-20 18:02:58 -07001281 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001282 asyncResp->res
1283 .jsonValue["Actions"]["#LogService.ClearLog"]["target"]
1284
1285 = std::format(
1286 "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog",
1287 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1288 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001289}
1290
Alexander Hansen599b9af2024-08-06 15:11:57 +02001291inline void handleSystemsLogServicesEventLogActionsClearPost(
1292 App& app, const crow::Request& req,
1293 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1294 const std::string& systemName)
1295{
1296 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1297 {
1298 return;
1299 }
1300 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1301 {
1302 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1303 systemName);
1304 return;
1305 }
1306
1307 // Clear the EventLog by deleting the log files
1308 std::vector<std::filesystem::path> redfishLogFiles;
1309 if (getRedfishLogFiles(redfishLogFiles))
1310 {
1311 for (const std::filesystem::path& file : redfishLogFiles)
1312 {
1313 std::error_code ec;
1314 std::filesystem::remove(file, ec);
1315 }
1316 }
1317
1318 // Reload rsyslog so it knows to start new log files
1319 crow::connections::systemBus->async_method_call(
1320 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001321 if (ec)
1322 {
1323 BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec);
1324 messages::internalError(asyncResp->res);
1325 return;
1326 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001327
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001328 messages::success(asyncResp->res);
1329 },
Alexander Hansen599b9af2024-08-06 15:11:57 +02001330 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1331 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1332 "replace");
1333}
1334
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001335inline void requestRoutesJournalEventLogClear(App& app)
1336{
Jason M. Bills4978b632022-02-22 14:17:43 -08001337 BMCWEB_ROUTE(
1338 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07001339 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Ed Tanous432a8902021-06-14 15:28:56 -07001340 .privileges({{"ConfigureComponents"}})
Alexander Hansen599b9af2024-08-06 15:11:57 +02001341 .methods(boost::beast::http::verb::post)(std::bind_front(
1342 handleSystemsLogServicesEventLogActionsClearPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001343}
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001344
Jason M. Billsac992cd2022-06-24 13:31:46 -07001345enum class LogParseError
1346{
1347 success,
1348 parseFailed,
1349 messageIdNotInRegistry,
1350};
1351
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001352static LogParseError fillEventLogEntryJson(
1353 const std::string& logEntryID, const std::string& logEntry,
1354 nlohmann::json::object_t& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001355{
Jason M. Bills95820182019-04-22 16:25:34 -07001356 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001357 // First get the Timestamp
Ed Tanousf23b7292020-10-15 09:41:17 -07001358 size_t space = logEntry.find_first_of(' ');
Jason M. Billscd225da2019-05-08 15:31:57 -07001359 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001360 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001361 return LogParseError::parseFailed;
Jason M. Bills95820182019-04-22 16:25:34 -07001362 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001363 std::string timestamp = logEntry.substr(0, space);
1364 // Then get the log contents
Ed Tanousf23b7292020-10-15 09:41:17 -07001365 size_t entryStart = logEntry.find_first_not_of(' ', space);
Jason M. Billscd225da2019-05-08 15:31:57 -07001366 if (entryStart == std::string::npos)
1367 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001368 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001369 }
1370 std::string_view entry(logEntry);
1371 entry.remove_prefix(entryStart);
1372 // Use split to separate the entry into its fields
1373 std::vector<std::string> logEntryFields;
Ed Tanous50ebd4a2023-01-19 19:03:17 -08001374 bmcweb::split(logEntryFields, entry, ',');
Jason M. Billscd225da2019-05-08 15:31:57 -07001375 // We need at least a MessageId to be valid
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001376 auto logEntryIter = logEntryFields.begin();
1377 if (logEntryIter == logEntryFields.end())
Jason M. Billscd225da2019-05-08 15:31:57 -07001378 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001379 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001380 }
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001381 std::string& messageID = *logEntryIter;
Jason M. Bills4851d452019-03-28 11:27:48 -07001382 // Get the Message from the MessageRegistry
Ed Tanousfffb8c12022-02-07 23:53:03 -08001383 const registries::Message* message = registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001384
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001385 logEntryIter++;
Sui Chen54417b02022-03-24 14:59:52 -07001386 if (message == nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001387 {
Ed Tanous62598e32023-07-17 17:06:25 -07001388 BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001389 return LogParseError::messageIdNotInRegistry;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001390 }
1391
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001392 std::vector<std::string_view> messageArgs(logEntryIter,
1393 logEntryFields.end());
Ed Tanousc05bba42023-06-28 08:33:29 -07001394 messageArgs.resize(message->numberOfArgs);
1395
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001396 std::string msg =
1397 redfish::registries::fillMessageArgs(messageArgs, message->message);
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001398 if (msg.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001399 {
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001400 return LogParseError::parseFailed;
Jason M. Bills4851d452019-03-28 11:27:48 -07001401 }
1402
Jason M. Bills95820182019-04-22 16:25:34 -07001403 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1404 // format which matches the Redfish format except for the fractional seconds
1405 // between the '.' and the '+', so just remove them.
Ed Tanousf23b7292020-10-15 09:41:17 -07001406 std::size_t dot = timestamp.find_first_of('.');
1407 std::size_t plus = timestamp.find_first_of('+');
Jason M. Bills95820182019-04-22 16:25:34 -07001408 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001409 {
Jason M. Bills95820182019-04-22 16:25:34 -07001410 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001411 }
1412
1413 // Fill in the log entry with the gathered data
Vijay Lobo9c11a172021-10-07 16:53:16 -05001414 logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001415 logEntryJson["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001416 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1417 BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
Jason M. Bills84afc482022-06-24 12:38:23 -07001418 logEntryJson["Name"] = "System Event Log Entry";
1419 logEntryJson["Id"] = logEntryID;
1420 logEntryJson["Message"] = std::move(msg);
1421 logEntryJson["MessageId"] = std::move(messageID);
1422 logEntryJson["MessageArgs"] = messageArgs;
1423 logEntryJson["EntryType"] = "Event";
1424 logEntryJson["Severity"] = message->messageSeverity;
1425 logEntryJson["Created"] = std::move(timestamp);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001426 return LogParseError::success;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001427}
1428
Ed Tanous898f2aa2024-08-07 12:18:22 -07001429inline void fillEventLogLogEntryFromPropertyMap(
1430 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1431 const dbus::utility::DBusPropertiesMap& resp,
1432 nlohmann::json& objectToFillOut)
1433{
Alexander Hansen262dcc12024-09-19 12:04:03 +02001434 std::optional<DbusEventLogEntry> optEntry =
1435 fillDbusEventLogEntryFromPropertyMap(resp);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001436
Alexander Hansen262dcc12024-09-19 12:04:03 +02001437 if (!optEntry.has_value())
Ed Tanous898f2aa2024-08-07 12:18:22 -07001438 {
1439 messages::internalError(asyncResp->res);
1440 return;
1441 }
Alexander Hansen262dcc12024-09-19 12:04:03 +02001442 DbusEventLogEntry entry = optEntry.value();
Ed Tanous898f2aa2024-08-07 12:18:22 -07001443
1444 objectToFillOut["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1445 objectToFillOut["@odata.id"] = boost::urls::format(
1446 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
Alexander Hansen262dcc12024-09-19 12:04:03 +02001447 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
Ed Tanous898f2aa2024-08-07 12:18:22 -07001448 objectToFillOut["Name"] = "System Event Log Entry";
Alexander Hansen262dcc12024-09-19 12:04:03 +02001449 objectToFillOut["Id"] = std::to_string(entry.Id);
1450 objectToFillOut["Message"] = entry.Message;
1451 objectToFillOut["Resolved"] = entry.Resolved;
1452 std::optional<bool> notifyAction =
1453 getProviderNotifyAction(entry.ServiceProviderNotify);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001454 if (notifyAction)
1455 {
1456 objectToFillOut["ServiceProviderNotified"] = *notifyAction;
1457 }
Alexander Hansen262dcc12024-09-19 12:04:03 +02001458 if ((entry.Resolution != nullptr) && !entry.Resolution->empty())
Ed Tanous898f2aa2024-08-07 12:18:22 -07001459 {
Alexander Hansen262dcc12024-09-19 12:04:03 +02001460 objectToFillOut["Resolution"] = *entry.Resolution;
Ed Tanous898f2aa2024-08-07 12:18:22 -07001461 }
1462 objectToFillOut["EntryType"] = "Event";
Alexander Hansen262dcc12024-09-19 12:04:03 +02001463 objectToFillOut["Severity"] =
1464 translateSeverityDbusToRedfish(entry.Severity);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001465 objectToFillOut["Created"] =
Alexander Hansen262dcc12024-09-19 12:04:03 +02001466 redfish::time_utils::getDateTimeUintMs(entry.Timestamp);
Ed Tanous898f2aa2024-08-07 12:18:22 -07001467 objectToFillOut["Modified"] =
Alexander Hansen262dcc12024-09-19 12:04:03 +02001468 redfish::time_utils::getDateTimeUintMs(entry.UpdateTimestamp);
1469 if (entry.Path != nullptr)
Ed Tanous898f2aa2024-08-07 12:18:22 -07001470 {
1471 objectToFillOut["AdditionalDataURI"] = boost::urls::format(
1472 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment",
Alexander Hansen262dcc12024-09-19 12:04:03 +02001473 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
Ed Tanous898f2aa2024-08-07 12:18:22 -07001474 }
1475}
1476
Ed Tanousb7290962024-08-07 11:09:51 -07001477inline void afterLogEntriesGetManagedObjects(
1478 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1479 const boost::system::error_code& ec,
1480 const dbus::utility::ManagedObjectType& resp)
1481{
1482 if (ec)
1483 {
1484 // TODO Handle for specific error code
1485 BMCWEB_LOG_ERROR("getLogEntriesIfaceData resp_handler got error {}",
1486 ec);
1487 messages::internalError(asyncResp->res);
1488 return;
1489 }
1490 nlohmann::json::array_t entriesArray;
1491 for (const auto& objectPath : resp)
1492 {
Ed Tanous898f2aa2024-08-07 12:18:22 -07001493 dbus::utility::DBusPropertiesMap propsFlattened;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001494 auto isEntry =
1495 std::ranges::find_if(objectPath.second, [](const auto& object) {
1496 return object.first == "xyz.openbmc_project.Logging.Entry";
1497 });
Ed Tanous898f2aa2024-08-07 12:18:22 -07001498 if (isEntry == objectPath.second.end())
Ed Tanousb7290962024-08-07 11:09:51 -07001499 {
1500 continue;
1501 }
Ed Tanous898f2aa2024-08-07 12:18:22 -07001502 for (const auto& interfaceMap : objectPath.second)
Ed Tanousb7290962024-08-07 11:09:51 -07001503 {
Ed Tanous898f2aa2024-08-07 12:18:22 -07001504 for (const auto& propertyMap : interfaceMap.second)
Ed Tanousb7290962024-08-07 11:09:51 -07001505 {
Ed Tanous898f2aa2024-08-07 12:18:22 -07001506 propsFlattened.emplace_back(propertyMap.first,
1507 propertyMap.second);
Ed Tanousb7290962024-08-07 11:09:51 -07001508 }
1509 }
Ed Tanous898f2aa2024-08-07 12:18:22 -07001510 fillEventLogLogEntryFromPropertyMap(asyncResp, propsFlattened,
1511 entriesArray.emplace_back());
Ed Tanousb7290962024-08-07 11:09:51 -07001512 }
Ed Tanous898f2aa2024-08-07 12:18:22 -07001513
Ed Tanousb7290962024-08-07 11:09:51 -07001514 std::ranges::sort(entriesArray, [](const nlohmann::json& left,
1515 const nlohmann::json& right) {
1516 return (left["Id"] <= right["Id"]);
1517 });
1518 asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
1519 asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
1520}
1521
Alexander Hansen599b9af2024-08-06 15:11:57 +02001522inline void handleSystemsLogServiceEventLogLogEntryCollection(
1523 App& app, const crow::Request& req,
1524 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1525 const std::string& systemName)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001526{
Alexander Hansen599b9af2024-08-06 15:11:57 +02001527 query_param::QueryCapabilities capabilities = {
1528 .canDelegateTop = true,
1529 .canDelegateSkip = true,
1530 };
1531 query_param::Query delegatedQuery;
1532 if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp,
1533 delegatedQuery, capabilities))
1534 {
1535 return;
1536 }
1537 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1538 {
1539 // Option currently returns no systems. TBD
1540 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1541 systemName);
1542 return;
1543 }
1544 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1545 {
1546 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1547 systemName);
1548 return;
1549 }
1550
1551 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
1552 size_t skip = delegatedQuery.skip.value_or(0);
1553
1554 // Collections don't include the static data added by SubRoute
1555 // because it has a duplicate entry for members
1556 asyncResp->res.jsonValue["@odata.type"] =
1557 "#LogEntryCollection.LogEntryCollection";
1558 asyncResp->res.jsonValue["@odata.id"] =
1559 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1560 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1561 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1562 asyncResp->res.jsonValue["Description"] =
1563 "Collection of System Event Log Entries";
1564
1565 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1566 logEntryArray = nlohmann::json::array();
1567 // Go through the log files and create a unique ID for each
1568 // entry
1569 std::vector<std::filesystem::path> redfishLogFiles;
1570 getRedfishLogFiles(redfishLogFiles);
1571 uint64_t entryCount = 0;
1572 std::string logEntry;
1573
1574 // Oldest logs are in the last file, so start there and loop
1575 // backwards
1576 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++)
1577 {
1578 std::ifstream logStream(*it);
1579 if (!logStream.is_open())
Ed Tanous002d39b2022-05-31 08:59:27 -07001580 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001581 continue;
Ed Tanous22d268c2022-05-19 09:39:07 -07001582 }
1583
Alexander Hansen599b9af2024-08-06 15:11:57 +02001584 // Reset the unique ID on the first entry
1585 bool firstEntry = true;
1586 while (std::getline(logStream, logEntry))
Ed Tanous002d39b2022-05-31 08:59:27 -07001587 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001588 std::string idStr;
1589 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1590 {
1591 continue;
1592 }
1593 firstEntry = false;
1594
1595 nlohmann::json::object_t bmcLogEntry;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001596 LogParseError status =
1597 fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
Alexander Hansen599b9af2024-08-06 15:11:57 +02001598 if (status == LogParseError::messageIdNotInRegistry)
1599 {
1600 continue;
1601 }
1602 if (status != LogParseError::success)
1603 {
1604 messages::internalError(asyncResp->res);
1605 return;
1606 }
1607
1608 entryCount++;
1609 // Handle paging using skip (number of entries to skip from the
1610 // start) and top (number of entries to display)
1611 if (entryCount <= skip || entryCount > skip + top)
Jason M. Bills4978b632022-02-22 14:17:43 -08001612 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001613 continue;
Jason M. Bills4978b632022-02-22 14:17:43 -08001614 }
Jason M. Bills897967d2019-07-29 17:05:30 -07001615
Alexander Hansen599b9af2024-08-06 15:11:57 +02001616 logEntryArray.emplace_back(std::move(bmcLogEntry));
1617 }
1618 }
1619 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1620 if (skip + top < entryCount)
1621 {
1622 asyncResp->res.jsonValue["Members@odata.nextLink"] =
1623 boost::urls::format(
1624 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}",
1625 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top));
1626 }
1627}
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001628
Alexander Hansen599b9af2024-08-06 15:11:57 +02001629inline void requestRoutesJournalEventLogEntryCollection(App& app)
1630{
1631 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
1632 .privileges(redfish::privileges::getLogEntryCollection)
1633 .methods(boost::beast::http::verb::get)(std::bind_front(
1634 handleSystemsLogServiceEventLogLogEntryCollection, std::ref(app)));
1635}
1636
1637inline void handleSystemsLogServiceEventLogEntriesGet(
1638 App& app, const crow::Request& req,
1639 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1640 const std::string& systemName, const std::string& param)
1641{
1642 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1643 {
1644 return;
1645 }
1646 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1647 {
1648 // Option currently returns no systems. TBD
1649 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1650 systemName);
1651 return;
1652 }
1653
1654 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1655 {
1656 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1657 systemName);
1658 return;
1659 }
1660
1661 const std::string& targetID = param;
1662
1663 // Go through the log files and check the unique ID for each
1664 // entry to find the target entry
1665 std::vector<std::filesystem::path> redfishLogFiles;
1666 getRedfishLogFiles(redfishLogFiles);
1667 std::string logEntry;
1668
1669 // Oldest logs are in the last file, so start there and loop
1670 // backwards
1671 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++)
1672 {
1673 std::ifstream logStream(*it);
1674 if (!logStream.is_open())
1675 {
1676 continue;
1677 }
1678
1679 // Reset the unique ID on the first entry
1680 bool firstEntry = true;
1681 while (std::getline(logStream, logEntry))
1682 {
1683 std::string idStr;
1684 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1685 {
1686 continue;
1687 }
1688 firstEntry = false;
1689
1690 if (idStr == targetID)
1691 {
Jason M. Billsde703c52022-06-23 14:19:04 -07001692 nlohmann::json::object_t bmcLogEntry;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001693 LogParseError status =
1694 fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001695 if (status != LogParseError::success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001696 {
1697 messages::internalError(asyncResp->res);
1698 return;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001699 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001700 asyncResp->res.jsonValue.update(bmcLogEntry);
1701 return;
Jason M. Bills4978b632022-02-22 14:17:43 -08001702 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001703 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001704 }
1705 // Requested ID was not found
1706 messages::resourceNotFound(asyncResp->res, "LogEntry", targetID);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001707}
Chicago Duan336e96c2019-07-15 14:22:08 +08001708
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001709inline void requestRoutesJournalEventLogEntry(App& app)
1710{
1711 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001712 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001713 .privileges(redfish::privileges::getLogEntry)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001714 .methods(boost::beast::http::verb::get)(std::bind_front(
1715 handleSystemsLogServiceEventLogEntriesGet, std::ref(app)));
1716}
1717
1718inline void dBusEventLogEntryCollection(
1719 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1720{
1721 // Collections don't include the static data added by SubRoute
1722 // because it has a duplicate entry for members
1723 asyncResp->res.jsonValue["@odata.type"] =
1724 "#LogEntryCollection.LogEntryCollection";
1725 asyncResp->res.jsonValue["@odata.id"] =
1726 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1727 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1728 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1729 asyncResp->res.jsonValue["Description"] =
1730 "Collection of System Event Log Entries";
1731
1732 // DBus implementation of EventLog/Entries
1733 // Make call to Logging Service to find all log entry objects
1734 sdbusplus::message::object_path path("/xyz/openbmc_project/logging");
1735 dbus::utility::getManagedObjects(
1736 "xyz.openbmc_project.Logging", path,
1737 [asyncResp](const boost::system::error_code& ec,
1738 const dbus::utility::ManagedObjectType& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001739 afterLogEntriesGetManagedObjects(asyncResp, ec, resp);
1740 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001741}
1742
1743inline void requestRoutesDBusEventLogEntryCollection(App& app)
1744{
Ed Tanous22d268c2022-05-19 09:39:07 -07001745 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07001746 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001747 .methods(boost::beast::http::verb::get)(
1748 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001749 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1750 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001751 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1752 {
1753 return;
1754 }
1755 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1756 {
1757 // Option currently returns no systems. TBD
1758 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1759 systemName);
1760 return;
1761 }
1762 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1763 {
1764 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1765 systemName);
1766 return;
1767 }
1768 dBusEventLogEntryCollection(asyncResp);
1769 });
Alexander Hansen599b9af2024-08-06 15:11:57 +02001770}
Ed Tanous22d268c2022-05-19 09:39:07 -07001771
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001772inline void dBusEventLogEntryGet(
1773 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001774{
1775 dbus::utility::escapePathForDbus(entryID);
Ed Tanous002d39b2022-05-31 08:59:27 -07001776
Alexander Hansen599b9af2024-08-06 15:11:57 +02001777 // DBus implementation of EventLog/Entries
1778 // Make call to Logging Service to find all log entry objects
Ed Tanousdeae6a72024-11-11 21:58:57 -08001779 dbus::utility::getAllProperties(
1780 "xyz.openbmc_project.Logging",
Alexander Hansen599b9af2024-08-06 15:11:57 +02001781 "/xyz/openbmc_project/logging/entry/" + entryID, "",
1782 [asyncResp, entryID](const boost::system::error_code& ec,
1783 const dbus::utility::DBusPropertiesMap& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001784 if (ec.value() == EBADR)
1785 {
1786 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1787 entryID);
1788 return;
1789 }
1790 if (ec)
1791 {
1792 BMCWEB_LOG_ERROR(
1793 "EventLogEntry (DBus) resp_handler got error {}", ec);
1794 messages::internalError(asyncResp->res);
1795 return;
1796 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001797
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001798 fillEventLogLogEntryFromPropertyMap(asyncResp, resp,
1799 asyncResp->res.jsonValue);
1800 });
Alexander Hansen599b9af2024-08-06 15:11:57 +02001801}
1802
Patrick Williams504af5a2025-02-03 14:29:03 -05001803inline void dBusEventLogEntryPatch(
1804 const crow::Request& req,
1805 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1806 const std::string& entryId)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001807{
1808 std::optional<bool> resolved;
1809
1810 if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", resolved))
1811 {
1812 return;
1813 }
1814 BMCWEB_LOG_DEBUG("Set Resolved");
1815
1816 setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging",
1817 "/xyz/openbmc_project/logging/entry/" + entryId,
1818 "xyz.openbmc_project.Logging.Entry", "Resolved",
1819 resolved.value_or(false));
1820}
1821
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001822inline void dBusEventLogEntryDelete(
1823 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID)
Alexander Hansen599b9af2024-08-06 15:11:57 +02001824{
1825 BMCWEB_LOG_DEBUG("Do delete single event entries.");
1826
1827 dbus::utility::escapePathForDbus(entryID);
1828
1829 // Process response from Logging service.
1830 auto respHandler = [asyncResp,
1831 entryID](const boost::system::error_code& ec) {
1832 BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done");
1833 if (ec)
1834 {
1835 if (ec.value() == EBADR)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001836 {
Alexander Hansen599b9af2024-08-06 15:11:57 +02001837 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001838 return;
1839 }
Alexander Hansen599b9af2024-08-06 15:11:57 +02001840 // TODO Handle for specific error code
1841 BMCWEB_LOG_ERROR(
1842 "EventLogEntry (DBus) doDelete respHandler got error {}", ec);
1843 asyncResp->res.result(
1844 boost::beast::http::status::internal_server_error);
1845 return;
1846 }
Abhishek Patel9017faf2021-09-14 22:48:55 -05001847
Alexander Hansen599b9af2024-08-06 15:11:57 +02001848 asyncResp->res.result(boost::beast::http::status::ok);
1849 };
1850
1851 // Make call to Logging service to request Delete Log
1852 crow::connections::systemBus->async_method_call(
1853 respHandler, "xyz.openbmc_project.Logging",
1854 "/xyz/openbmc_project/logging/entry/" + entryID,
1855 "xyz.openbmc_project.Object.Delete", "Delete");
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001856}
Xiaochao Ma75710de2021-01-21 17:56:02 +08001857
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001858inline void requestRoutesDBusEventLogEntry(App& app)
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001859{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001860 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001861 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001862 .privileges(redfish::privileges::getLogEntry)
Ed Tanous002d39b2022-05-31 08:59:27 -07001863 .methods(boost::beast::http::verb::get)(
1864 [&app](const crow::Request& req,
1865 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous898f2aa2024-08-07 12:18:22 -07001866 const std::string& systemName, const std::string& entryId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001867 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1868 {
1869 return;
1870 }
1871 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1872 {
1873 // Option currently returns no systems. TBD
1874 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1875 systemName);
1876 return;
1877 }
1878 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1879 {
1880 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1881 systemName);
1882 return;
1883 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001884
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001885 dBusEventLogEntryGet(asyncResp, entryId);
1886 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001887
1888 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001889 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001890 .privileges(redfish::privileges::patchLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001891 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001892 [&app](const crow::Request& req,
1893 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001894 const std::string& systemName, const std::string& entryId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001895 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1896 {
1897 return;
1898 }
1899 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1900 {
1901 // Option currently returns no systems. TBD
1902 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1903 systemName);
1904 return;
1905 }
1906 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1907 {
1908 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1909 systemName);
1910 return;
1911 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001912
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001913 dBusEventLogEntryPatch(req, asyncResp, entryId);
1914 });
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001915
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001916 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001917 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001918 .privileges(redfish::privileges::deleteLogEntry)
1919
Ed Tanous002d39b2022-05-31 08:59:27 -07001920 .methods(boost::beast::http::verb::delete_)(
1921 [&app](const crow::Request& req,
1922 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001923 const std::string& systemName, const std::string& param) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001924 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1925 {
1926 return;
1927 }
1928 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1929 {
1930 // Option currently returns no systems. TBD
1931 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1932 systemName);
1933 return;
1934 }
1935 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1936 {
1937 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1938 systemName);
1939 return;
1940 }
1941 dBusEventLogEntryDelete(asyncResp, param);
1942 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001943}
1944
Claire Weinandd72e872022-08-15 14:20:06 -07001945inline void handleBMCLogServicesCollectionGet(
Claire Weinanfdd26902022-03-01 14:18:25 -08001946 crow::App& app, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07001947 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1948 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08001949{
1950 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1951 {
1952 return;
1953 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001954
1955 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
1956 {
1957 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
1958 return;
1959 }
1960
Claire Weinanfdd26902022-03-01 14:18:25 -08001961 // Collections don't include the static data added by SubRoute
1962 // because it has a duplicate entry for members
1963 asyncResp->res.jsonValue["@odata.type"] =
1964 "#LogServiceCollection.LogServiceCollection";
Ed Tanous253f11b2024-05-16 09:38:31 -07001965 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1966 "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -08001967 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1968 asyncResp->res.jsonValue["Description"] =
1969 "Collection of LogServices for this Manager";
1970 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1971 logServiceArray = nlohmann::json::array();
1972
Ed Tanous25b54db2024-04-17 15:40:31 -07001973 if constexpr (BMCWEB_REDFISH_BMC_JOURNAL)
1974 {
1975 nlohmann::json::object_t journal;
Ed Tanous253f11b2024-05-16 09:38:31 -07001976 journal["@odata.id"] =
1977 boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal",
1978 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001979 logServiceArray.emplace_back(std::move(journal));
1980 }
Claire Weinanfdd26902022-03-01 14:18:25 -08001981
1982 asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
1983
Ed Tanous25b54db2024-04-17 15:40:31 -07001984 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
1985 {
1986 constexpr std::array<std::string_view, 1> interfaces = {
1987 "xyz.openbmc_project.Collection.DeleteAll"};
1988 dbus::utility::getSubTreePaths(
1989 "/xyz/openbmc_project/dump", 0, interfaces,
1990 [asyncResp](const boost::system::error_code& ec,
1991 const dbus::utility::MapperGetSubTreePathsResponse&
1992 subTreePaths) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001993 if (ec)
Ed Tanous25b54db2024-04-17 15:40:31 -07001994 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001995 BMCWEB_LOG_ERROR(
1996 "handleBMCLogServicesCollectionGet respHandler got error {}",
1997 ec);
1998 // Assume that getting an error simply means there are no
1999 // dump LogServices. Return without adding any error
2000 // response.
2001 return;
Ed Tanous25b54db2024-04-17 15:40:31 -07002002 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002003
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002004 nlohmann::json& logServiceArrayLocal =
2005 asyncResp->res.jsonValue["Members"];
2006
2007 for (const std::string& path : subTreePaths)
2008 {
2009 if (path == "/xyz/openbmc_project/dump/bmc")
2010 {
2011 nlohmann::json::object_t member;
2012 member["@odata.id"] = boost::urls::format(
2013 "/redfish/v1/Managers/{}/LogServices/Dump",
2014 BMCWEB_REDFISH_MANAGER_URI_NAME);
2015 logServiceArrayLocal.emplace_back(std::move(member));
2016 }
2017 else if (path == "/xyz/openbmc_project/dump/faultlog")
2018 {
2019 nlohmann::json::object_t member;
2020 member["@odata.id"] = boost::urls::format(
2021 "/redfish/v1/Managers/{}/LogServices/FaultLog",
2022 BMCWEB_REDFISH_MANAGER_URI_NAME);
2023 logServiceArrayLocal.emplace_back(std::move(member));
2024 }
2025 }
2026
2027 asyncResp->res.jsonValue["Members@odata.count"] =
2028 logServiceArrayLocal.size();
2029 });
Ed Tanous25b54db2024-04-17 15:40:31 -07002030 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002031}
2032
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002033inline void requestRoutesBMCLogServiceCollection(App& app)
2034{
Ed Tanous253f11b2024-05-16 09:38:31 -07002035 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/")
Gunnar Millsad89dcf2021-07-30 14:40:11 -05002036 .privileges(redfish::privileges::getLogServiceCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002037 .methods(boost::beast::http::verb::get)(
Claire Weinandd72e872022-08-15 14:20:06 -07002038 std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002039}
Ed Tanous1da66f72018-07-27 16:13:37 -07002040
Patrick Williams504af5a2025-02-03 14:29:03 -05002041inline void getDumpServiceInfo(
2042 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2043 const std::string& dumpType)
Claire Weinanfdd26902022-03-01 14:18:25 -08002044{
2045 std::string dumpPath;
Ed Tanous539d8c62024-06-19 14:38:27 -07002046 log_service::OverWritePolicy overWritePolicy =
2047 log_service::OverWritePolicy::Invalid;
Claire Weinanfdd26902022-03-01 14:18:25 -08002048 bool collectDiagnosticDataSupported = false;
2049
2050 if (dumpType == "BMC")
2051 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002052 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump",
2053 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002054 overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
Claire Weinanfdd26902022-03-01 14:18:25 -08002055 collectDiagnosticDataSupported = true;
2056 }
2057 else if (dumpType == "FaultLog")
2058 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002059 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog",
2060 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002061 overWritePolicy = log_service::OverWritePolicy::Unknown;
Claire Weinanfdd26902022-03-01 14:18:25 -08002062 collectDiagnosticDataSupported = false;
2063 }
2064 else if (dumpType == "System")
2065 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002066 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump",
2067 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002068 overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
Claire Weinanfdd26902022-03-01 14:18:25 -08002069 collectDiagnosticDataSupported = true;
2070 }
2071 else
2072 {
Ed Tanous62598e32023-07-17 17:06:25 -07002073 BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}",
2074 dumpType);
Claire Weinanfdd26902022-03-01 14:18:25 -08002075 messages::internalError(asyncResp->res);
2076 return;
2077 }
2078
2079 asyncResp->res.jsonValue["@odata.id"] = dumpPath;
2080 asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService";
2081 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2082 asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService";
2083 asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename();
Ed Tanous539d8c62024-06-19 14:38:27 -07002084 asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy;
Claire Weinanfdd26902022-03-01 14:18:25 -08002085
2086 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002087 redfish::time_utils::getDateTimeOffsetNow();
Claire Weinanfdd26902022-03-01 14:18:25 -08002088 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2089 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2090 redfishDateTimeOffset.second;
2091
2092 asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries";
Claire Weinanfdd26902022-03-01 14:18:25 -08002093
2094 if (collectDiagnosticDataSupported)
2095 {
2096 asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2097 ["target"] =
2098 dumpPath + "/Actions/LogService.CollectDiagnosticData";
2099 }
Claire Weinan0d946212022-07-13 19:40:19 -07002100
2101 constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface};
2102 dbus::utility::getSubTreePaths(
2103 "/xyz/openbmc_project/dump", 0, interfaces,
2104 [asyncResp, dumpType, dumpPath](
2105 const boost::system::error_code& ec,
2106 const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002107 if (ec)
Claire Weinan0d946212022-07-13 19:40:19 -07002108 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002109 BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}",
2110 ec);
2111 // Assume that getting an error simply means there are no dump
2112 // LogServices. Return without adding any error response.
2113 return;
Claire Weinan0d946212022-07-13 19:40:19 -07002114 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002115 std::string dbusDumpPath = getDumpPath(dumpType);
2116 for (const std::string& path : subTreePaths)
2117 {
2118 if (path == dbusDumpPath)
2119 {
2120 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2121 ["target"] =
2122 dumpPath + "/Actions/LogService.ClearLog";
2123 break;
2124 }
2125 }
2126 });
Claire Weinanfdd26902022-03-01 14:18:25 -08002127}
2128
2129inline void handleLogServicesDumpServiceGet(
2130 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002131 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2132 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002133{
2134 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2135 {
2136 return;
2137 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002138
2139 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2140 {
2141 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2142 return;
2143 }
2144
Claire Weinanfdd26902022-03-01 14:18:25 -08002145 getDumpServiceInfo(asyncResp, dumpType);
2146}
2147
Ed Tanous22d268c2022-05-19 09:39:07 -07002148inline void handleLogServicesDumpServiceComputerSystemGet(
2149 crow::App& app, const crow::Request& req,
2150 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2151 const std::string& chassisId)
2152{
2153 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2154 {
2155 return;
2156 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002157 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002158 {
2159 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2160 return;
2161 }
2162 getDumpServiceInfo(asyncResp, "System");
2163}
2164
Claire Weinanfdd26902022-03-01 14:18:25 -08002165inline void handleLogServicesDumpEntriesCollectionGet(
2166 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002167 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2168 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002169{
2170 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2171 {
2172 return;
2173 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002174
2175 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2176 {
2177 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2178 return;
2179 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002180 getDumpEntryCollection(asyncResp, dumpType);
2181}
2182
Ed Tanous22d268c2022-05-19 09:39:07 -07002183inline void handleLogServicesDumpEntriesCollectionComputerSystemGet(
2184 crow::App& app, const crow::Request& req,
2185 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2186 const std::string& chassisId)
2187{
2188 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2189 {
2190 return;
2191 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002192 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002193 {
2194 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2195 return;
2196 }
2197 getDumpEntryCollection(asyncResp, "System");
2198}
2199
Claire Weinanfdd26902022-03-01 14:18:25 -08002200inline void handleLogServicesDumpEntryGet(
2201 crow::App& app, const std::string& dumpType, const crow::Request& req,
2202 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002203 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002204{
2205 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2206 {
2207 return;
2208 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002209 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2210 {
2211 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2212 return;
2213 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002214 getDumpEntryById(asyncResp, dumpId, dumpType);
2215}
Carson Labrado168d1b12023-03-27 17:04:46 +00002216
Ed Tanous22d268c2022-05-19 09:39:07 -07002217inline void handleLogServicesDumpEntryComputerSystemGet(
2218 crow::App& app, const crow::Request& req,
2219 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2220 const std::string& chassisId, const std::string& dumpId)
2221{
2222 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2223 {
2224 return;
2225 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002226 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002227 {
2228 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2229 return;
2230 }
2231 getDumpEntryById(asyncResp, dumpId, "System");
2232}
Claire Weinanfdd26902022-03-01 14:18:25 -08002233
2234inline void handleLogServicesDumpEntryDelete(
2235 crow::App& app, const std::string& dumpType, const crow::Request& req,
2236 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002237 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002238{
2239 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2240 {
2241 return;
2242 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002243
2244 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2245 {
2246 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2247 return;
2248 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002249 deleteDumpEntry(asyncResp, dumpId, dumpType);
2250}
2251
Ed Tanous22d268c2022-05-19 09:39:07 -07002252inline void handleLogServicesDumpEntryComputerSystemDelete(
2253 crow::App& app, const crow::Request& req,
2254 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2255 const std::string& chassisId, const std::string& dumpId)
2256{
2257 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2258 {
2259 return;
2260 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002261 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002262 {
2263 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2264 return;
2265 }
2266 deleteDumpEntry(asyncResp, dumpId, "System");
2267}
2268
Carson Labrado168d1b12023-03-27 17:04:46 +00002269inline void handleLogServicesDumpEntryDownloadGet(
2270 crow::App& app, const std::string& dumpType, const crow::Request& req,
2271 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002272 const std::string& managerId, const std::string& dumpId)
Carson Labrado168d1b12023-03-27 17:04:46 +00002273{
2274 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2275 {
2276 return;
2277 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002278
2279 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2280 {
2281 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2282 return;
2283 }
Carson Labrado168d1b12023-03-27 17:04:46 +00002284 downloadDumpEntry(asyncResp, dumpId, dumpType);
2285}
2286
2287inline void handleDBusEventLogEntryDownloadGet(
2288 crow::App& app, const std::string& dumpType, const crow::Request& req,
2289 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2290 const std::string& systemName, const std::string& entryID)
2291{
2292 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2293 {
2294 return;
2295 }
2296 if (!http_helpers::isContentTypeAllowed(
2297 req.getHeaderValue("Accept"),
2298 http_helpers::ContentType::OctetStream, true))
2299 {
2300 asyncResp->res.result(boost::beast::http::status::bad_request);
2301 return;
2302 }
2303 downloadEventLogEntry(asyncResp, systemName, entryID, dumpType);
2304}
2305
Claire Weinanfdd26902022-03-01 14:18:25 -08002306inline void handleLogServicesDumpCollectDiagnosticDataPost(
2307 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002308 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2309 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002310{
2311 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2312 {
2313 return;
2314 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002315 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2316 {
2317 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2318 return;
2319 }
2320
Claire Weinanfdd26902022-03-01 14:18:25 -08002321 createDump(asyncResp, req, dumpType);
2322}
2323
Ed Tanous22d268c2022-05-19 09:39:07 -07002324inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost(
2325 crow::App& app, const crow::Request& req,
2326 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002327 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002328{
2329 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2330 {
2331 return;
2332 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002333
Ed Tanous25b54db2024-04-17 15:40:31 -07002334 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002335 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002336 // Option currently returns no systems. TBD
2337 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2338 systemName);
2339 return;
2340 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002341 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002342 {
2343 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2344 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002345 return;
2346 }
2347 createDump(asyncResp, req, "System");
2348}
2349
Claire Weinanfdd26902022-03-01 14:18:25 -08002350inline void handleLogServicesDumpClearLogPost(
2351 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002352 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2353 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002354{
2355 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2356 {
2357 return;
2358 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002359
2360 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2361 {
2362 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2363 return;
2364 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002365 clearDump(asyncResp, dumpType);
2366}
2367
Ed Tanous22d268c2022-05-19 09:39:07 -07002368inline void handleLogServicesDumpClearLogComputerSystemPost(
2369 crow::App& app, const crow::Request& req,
2370 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002371 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002372{
2373 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2374 {
2375 return;
2376 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002377 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002378 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002379 // Option currently returns no systems. TBD
2380 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2381 systemName);
2382 return;
2383 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002384 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002385 {
2386 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2387 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002388 return;
2389 }
2390 clearDump(asyncResp, "System");
2391}
2392
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002393inline void requestRoutesBMCDumpService(App& app)
2394{
Ed Tanous253f11b2024-05-16 09:38:31 -07002395 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002396 .privileges(redfish::privileges::getLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002397 .methods(boost::beast::http::verb::get)(std::bind_front(
2398 handleLogServicesDumpServiceGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002399}
2400
2401inline void requestRoutesBMCDumpEntryCollection(App& app)
2402{
Ed Tanous253f11b2024-05-16 09:38:31 -07002403 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002404 .privileges(redfish::privileges::getLogEntryCollection)
Claire Weinanfdd26902022-03-01 14:18:25 -08002405 .methods(boost::beast::http::verb::get)(std::bind_front(
2406 handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002407}
2408
2409inline void requestRoutesBMCDumpEntry(App& app)
2410{
2411 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002412 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002413 .privileges(redfish::privileges::getLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002414 .methods(boost::beast::http::verb::get)(std::bind_front(
2415 handleLogServicesDumpEntryGet, std::ref(app), "BMC"));
2416
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002417 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002418 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002419 .privileges(redfish::privileges::deleteLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002420 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2421 handleLogServicesDumpEntryDelete, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002422}
2423
Carson Labrado168d1b12023-03-27 17:04:46 +00002424inline void requestRoutesBMCDumpEntryDownload(App& app)
2425{
2426 BMCWEB_ROUTE(
2427 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002428 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002429 .privileges(redfish::privileges::getLogEntry)
2430 .methods(boost::beast::http::verb::get)(std::bind_front(
2431 handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC"));
2432}
2433
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002434inline void requestRoutesBMCDumpCreate(App& app)
2435{
George Liu0fda0f12021-11-16 10:06:17 +08002436 BMCWEB_ROUTE(
2437 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002438 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002439 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002440 .methods(boost::beast::http::verb::post)(
Claire Weinanfdd26902022-03-01 14:18:25 -08002441 std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost,
2442 std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002443}
2444
2445inline void requestRoutesBMCDumpClear(App& app)
2446{
George Liu0fda0f12021-11-16 10:06:17 +08002447 BMCWEB_ROUTE(
2448 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002449 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002450 .privileges(redfish::privileges::postLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002451 .methods(boost::beast::http::verb::post)(std::bind_front(
2452 handleLogServicesDumpClearLogPost, std::ref(app), "BMC"));
2453}
2454
Carson Labrado168d1b12023-03-27 17:04:46 +00002455inline void requestRoutesDBusEventLogEntryDownload(App& app)
2456{
2457 BMCWEB_ROUTE(
2458 app,
Ravi Teja9e9d99d2023-11-08 05:33:59 -06002459 "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002460 .privileges(redfish::privileges::getLogEntry)
2461 .methods(boost::beast::http::verb::get)(std::bind_front(
2462 handleDBusEventLogEntryDownloadGet, std::ref(app), "System"));
2463}
2464
Claire Weinanfdd26902022-03-01 14:18:25 -08002465inline void requestRoutesFaultLogDumpService(App& app)
2466{
Ed Tanous253f11b2024-05-16 09:38:31 -07002467 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002468 .privileges(redfish::privileges::getLogService)
2469 .methods(boost::beast::http::verb::get)(std::bind_front(
2470 handleLogServicesDumpServiceGet, std::ref(app), "FaultLog"));
2471}
2472
2473inline void requestRoutesFaultLogDumpEntryCollection(App& app)
2474{
Ed Tanous253f11b2024-05-16 09:38:31 -07002475 BMCWEB_ROUTE(app,
2476 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002477 .privileges(redfish::privileges::getLogEntryCollection)
2478 .methods(boost::beast::http::verb::get)(
2479 std::bind_front(handleLogServicesDumpEntriesCollectionGet,
2480 std::ref(app), "FaultLog"));
2481}
2482
2483inline void requestRoutesFaultLogDumpEntry(App& app)
2484{
Ed Tanous253f11b2024-05-16 09:38:31 -07002485 BMCWEB_ROUTE(
2486 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002487 .privileges(redfish::privileges::getLogEntry)
2488 .methods(boost::beast::http::verb::get)(std::bind_front(
2489 handleLogServicesDumpEntryGet, std::ref(app), "FaultLog"));
2490
Ed Tanous253f11b2024-05-16 09:38:31 -07002491 BMCWEB_ROUTE(
2492 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002493 .privileges(redfish::privileges::deleteLogEntry)
2494 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2495 handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog"));
2496}
2497
2498inline void requestRoutesFaultLogDumpClear(App& app)
2499{
2500 BMCWEB_ROUTE(
2501 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002502 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002503 .privileges(redfish::privileges::postLogService)
2504 .methods(boost::beast::http::verb::post)(std::bind_front(
2505 handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002506}
2507
2508inline void requestRoutesSystemDumpService(App& app)
2509{
Ed Tanous22d268c2022-05-19 09:39:07 -07002510 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002511 .privileges(redfish::privileges::getLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002512 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002513 handleLogServicesDumpServiceComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002514}
2515
2516inline void requestRoutesSystemDumpEntryCollection(App& app)
2517{
Ed Tanous22d268c2022-05-19 09:39:07 -07002518 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002519 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous22d268c2022-05-19 09:39:07 -07002520 .methods(boost::beast::http::verb::get)(std::bind_front(
2521 handleLogServicesDumpEntriesCollectionComputerSystemGet,
2522 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002523}
2524
2525inline void requestRoutesSystemDumpEntry(App& app)
2526{
2527 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002528 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002529 .privileges(redfish::privileges::getLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002530 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002531 handleLogServicesDumpEntryComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002532
2533 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002534 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002535 .privileges(redfish::privileges::deleteLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002536 .methods(boost::beast::http::verb::delete_)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002537 handleLogServicesDumpEntryComputerSystemDelete, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002538}
2539
2540inline void requestRoutesSystemDumpCreate(App& app)
2541{
George Liu0fda0f12021-11-16 10:06:17 +08002542 BMCWEB_ROUTE(
2543 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002544 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002545 .privileges(redfish::privileges::postLogService)
Ed Tanous22d268c2022-05-19 09:39:07 -07002546 .methods(boost::beast::http::verb::post)(std::bind_front(
2547 handleLogServicesDumpCollectDiagnosticDataComputerSystemPost,
2548 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002549}
2550
2551inline void requestRoutesSystemDumpClear(App& app)
2552{
George Liu0fda0f12021-11-16 10:06:17 +08002553 BMCWEB_ROUTE(
2554 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002555 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002556 .privileges(redfish::privileges::postLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002557 .methods(boost::beast::http::verb::post)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002558 handleLogServicesDumpClearLogComputerSystemPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002559}
2560
2561inline void requestRoutesCrashdumpService(App& app)
2562{
2563 // Note: Deviated from redfish privilege registry for GET & HEAD
2564 // method for security reasons.
2565 /**
2566 * Functions triggers appropriate requests on DBus
2567 */
Ed Tanous22d268c2022-05-19 09:39:07 -07002568 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/")
Ed Tanoused398212021-06-09 17:05:54 -07002569 // This is incorrect, should be:
2570 //.privileges(redfish::privileges::getLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002571 .privileges({{"ConfigureManager"}})
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002572 .methods(
2573 boost::beast::http::verb::
2574 get)([&app](const crow::Request& req,
2575 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2576 const std::string& systemName) {
2577 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2578 {
2579 return;
2580 }
2581 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2582 {
2583 // Option currently returns no systems. TBD
2584 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2585 systemName);
2586 return;
2587 }
2588 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2589 {
2590 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2591 systemName);
2592 return;
2593 }
Ed Tanous22d268c2022-05-19 09:39:07 -07002594
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002595 // Copy over the static data to include the entries added by
2596 // SubRoute
2597 asyncResp->res.jsonValue["@odata.id"] =
2598 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
2599 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2600 asyncResp->res.jsonValue["@odata.type"] =
2601 "#LogService.v1_2_0.LogService";
2602 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2603 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
2604 asyncResp->res.jsonValue["Id"] = "Crashdump";
2605 asyncResp->res.jsonValue["OverWritePolicy"] =
2606 log_service::OverWritePolicy::WrapsWhenFull;
2607 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302608
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002609 std::pair<std::string, std::string> redfishDateTimeOffset =
2610 redfish::time_utils::getDateTimeOffsetNow();
2611 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2612 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2613 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302614
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002615 asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format(
2616 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2617 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2618 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2619 ["target"] = std::format(
2620 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog",
2621 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2622 asyncResp->res
2623 .jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2624 ["target"] = std::format(
2625 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData",
2626 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2627 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002628}
2629
2630void inline requestRoutesCrashdumpClear(App& app)
2631{
George Liu0fda0f12021-11-16 10:06:17 +08002632 BMCWEB_ROUTE(
2633 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002634 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002635 // This is incorrect, should be:
2636 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002637 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002638 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002639 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002640 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2641 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002642 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2643 {
2644 return;
2645 }
2646 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2647 {
2648 // Option currently returns no systems. TBD
2649 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2650 systemName);
2651 return;
2652 }
2653 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2654 {
2655 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2656 systemName);
2657 return;
2658 }
2659 crow::connections::systemBus->async_method_call(
2660 [asyncResp](const boost::system::error_code& ec,
2661 const std::string&) {
2662 if (ec)
2663 {
2664 messages::internalError(asyncResp->res);
2665 return;
2666 }
2667 messages::success(asyncResp->res);
2668 },
2669 crashdumpObject, crashdumpPath, deleteAllInterface,
2670 "DeleteAll");
2671 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002672}
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002673
Patrick Williams504af5a2025-02-03 14:29:03 -05002674inline void logCrashdumpEntry(
2675 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2676 const std::string& logID, nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07002677{
Johnathan Mantey043a0532020-03-10 17:15:28 -07002678 auto getStoredLogCallback =
Ed Tanousb9d36b42022-02-26 21:42:46 -08002679 [asyncResp, logID,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002680 &logEntryJson](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002681 const dbus::utility::DBusPropertiesMap& params) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002682 if (ec)
2683 {
2684 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
2685 if (ec.value() ==
2686 boost::system::linux_error::bad_request_descriptor)
2687 {
2688 messages::resourceNotFound(asyncResp->res, "LogEntry",
2689 logID);
2690 }
2691 else
2692 {
2693 messages::internalError(asyncResp->res);
2694 }
2695 return;
2696 }
2697
2698 std::string timestamp{};
2699 std::string filename{};
2700 std::string logfile{};
2701 parseCrashdumpParameters(params, filename, timestamp, logfile);
2702
2703 if (filename.empty() || timestamp.empty())
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002704 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002705 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002706 return;
2707 }
2708
2709 std::string crashdumpURI =
2710 std::format(
2711 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/",
2712 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
2713 logID + "/" + filename;
2714 nlohmann::json::object_t logEntry;
2715 logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
2716 logEntry["@odata.id"] = boost::urls::format(
2717 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}",
2718 BMCWEB_REDFISH_SYSTEM_URI_NAME, logID);
2719 logEntry["Name"] = "CPU Crashdump";
2720 logEntry["Id"] = logID;
2721 logEntry["EntryType"] = log_entry::LogEntryType::Oem;
2722 logEntry["AdditionalDataURI"] = std::move(crashdumpURI);
2723 logEntry["DiagnosticDataType"] = "OEM";
2724 logEntry["OEMDiagnosticDataType"] = "PECICrashdump";
2725 logEntry["Created"] = std::move(timestamp);
2726
2727 // If logEntryJson references an array of LogEntry resources
2728 // ('Members' list), then push this as a new entry, otherwise set it
2729 // directly
2730 if (logEntryJson.is_array())
2731 {
2732 logEntryJson.push_back(logEntry);
2733 asyncResp->res.jsonValue["Members@odata.count"] =
2734 logEntryJson.size();
Jason M. Bills2b20ef62022-01-06 15:48:07 -08002735 }
2736 else
2737 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002738 logEntryJson.update(logEntry);
Jason M. Bills2b20ef62022-01-06 15:48:07 -08002739 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002740 };
Ed Tanousdeae6a72024-11-11 21:58:57 -08002741 dbus::utility::getAllProperties(
2742 crashdumpObject, crashdumpPath + std::string("/") + logID,
2743 crashdumpInterface, std::move(getStoredLogCallback));
Jason M. Billse855dd22019-10-08 11:37:48 -07002744}
2745
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002746inline void requestRoutesCrashdumpEntryCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07002747{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002748 // Note: Deviated from redfish privilege registry for GET & HEAD
2749 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002750 /**
2751 * Functions triggers appropriate requests on DBus
2752 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002753 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002754 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002755 // This is incorrect, should be.
2756 //.privileges(redfish::privileges::postLogEntryCollection)
Ed Tanous432a8902021-06-14 15:28:56 -07002757 .privileges({{"ConfigureComponents"}})
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002758 .methods(
2759 boost::beast::http::verb::
2760 get)([&app](const crow::Request& req,
2761 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2762 const std::string& systemName) {
2763 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -07002764 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002765 return;
Ed Tanous45ca1b82022-03-25 13:07:27 -07002766 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002767 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07002768 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002769 // Option currently returns no systems. TBD
2770 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2771 systemName);
2772 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07002773 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002774 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2775 {
2776 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2777 systemName);
2778 return;
2779 }
2780
2781 constexpr std::array<std::string_view, 1> interfaces = {
2782 crashdumpInterface};
2783 dbus::utility::getSubTreePaths(
2784 "/", 0, interfaces,
2785 [asyncResp](const boost::system::error_code& ec,
2786 const std::vector<std::string>& resp) {
2787 if (ec)
2788 {
2789 if (ec.value() !=
2790 boost::system::errc::no_such_file_or_directory)
2791 {
2792 BMCWEB_LOG_DEBUG("failed to get entries ec: {}",
2793 ec.message());
2794 messages::internalError(asyncResp->res);
2795 return;
2796 }
2797 }
2798 asyncResp->res.jsonValue["@odata.type"] =
2799 "#LogEntryCollection.LogEntryCollection";
2800 asyncResp->res.jsonValue["@odata.id"] = std::format(
2801 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2802 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2803 asyncResp->res.jsonValue["Name"] =
2804 "Open BMC Crashdump Entries";
2805 asyncResp->res.jsonValue["Description"] =
2806 "Collection of Crashdump Entries";
2807 asyncResp->res.jsonValue["Members"] =
2808 nlohmann::json::array();
2809 asyncResp->res.jsonValue["Members@odata.count"] = 0;
2810
2811 for (const std::string& path : resp)
2812 {
2813 const sdbusplus::message::object_path objPath(path);
2814 // Get the log ID
2815 std::string logID = objPath.filename();
2816 if (logID.empty())
2817 {
2818 continue;
2819 }
2820 // Add the log entry to the array
2821 logCrashdumpEntry(asyncResp, logID,
2822 asyncResp->res.jsonValue["Members"]);
2823 }
2824 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002825 });
2826}
Ed Tanous1da66f72018-07-27 16:13:37 -07002827
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002828inline void requestRoutesCrashdumpEntry(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07002829{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002830 // Note: Deviated from redfish privilege registry for GET & HEAD
2831 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002832
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002833 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07002834 app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002835 // this is incorrect, should be
2836 // .privileges(redfish::privileges::getLogEntry)
Ed Tanous432a8902021-06-14 15:28:56 -07002837 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002838 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002839 [&app](const crow::Request& req,
2840 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07002841 const std::string& systemName, const std::string& param) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002842 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2843 {
2844 return;
2845 }
2846 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2847 {
2848 // Option currently returns no systems. TBD
2849 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2850 systemName);
2851 return;
2852 }
2853 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2854 {
2855 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2856 systemName);
2857 return;
2858 }
2859 const std::string& logID = param;
2860 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2861 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002862}
Ed Tanous1da66f72018-07-27 16:13:37 -07002863
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002864inline void requestRoutesCrashdumpFile(App& app)
2865{
2866 // Note: Deviated from redfish privilege registry for GET & HEAD
2867 // method for security reasons.
2868 BMCWEB_ROUTE(
2869 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002870 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002871 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002872 .methods(boost::beast::http::verb::get)(
Nan Zhoua4ce1142022-08-02 18:45:25 +00002873 [](const crow::Request& req,
2874 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07002875 const std::string& systemName, const std::string& logID,
2876 const std::string& fileName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002877 // Do not call getRedfishRoute here since the crashdump file is
2878 // not a Redfish resource.
Ed Tanous22d268c2022-05-19 09:39:07 -07002879
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002880 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2881 {
2882 // Option currently returns no systems. TBD
2883 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2884 systemName);
2885 return;
2886 }
2887 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2888 {
2889 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2890 systemName);
2891 return;
2892 }
Ed Tanous22d268c2022-05-19 09:39:07 -07002893
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002894 auto getStoredLogCallback =
2895 [asyncResp, logID, fileName,
2896 url(boost::urls::url(req.url()))](
2897 const boost::system::error_code& ec,
2898 const std::vector<std::pair<
2899 std::string, dbus::utility::DbusVariantType>>&
2900 resp) {
2901 if (ec)
2902 {
2903 BMCWEB_LOG_DEBUG("failed to get log ec: {}",
2904 ec.message());
2905 messages::internalError(asyncResp->res);
2906 return;
2907 }
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002908
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002909 std::string dbusFilename{};
2910 std::string dbusTimestamp{};
2911 std::string dbusFilepath{};
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002912
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002913 parseCrashdumpParameters(resp, dbusFilename,
2914 dbusTimestamp, dbusFilepath);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002915
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002916 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2917 dbusFilepath.empty())
2918 {
2919 messages::resourceNotFound(asyncResp->res,
2920 "LogEntry", logID);
2921 return;
2922 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002923
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002924 // Verify the file name parameter is correct
2925 if (fileName != dbusFilename)
2926 {
2927 messages::resourceNotFound(asyncResp->res,
2928 "LogEntry", logID);
2929 return;
2930 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002931
Myung Baed51c61b2024-09-13 10:35:34 -05002932 if (asyncResp->res.openFile(dbusFilepath) !=
2933 crow::OpenCode::Success)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002934 {
2935 messages::resourceNotFound(asyncResp->res,
2936 "LogEntry", logID);
2937 return;
2938 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002939
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002940 // Configure this to be a file download when accessed
2941 // from a browser
2942 asyncResp->res.addHeader(
2943 boost::beast::http::field::content_disposition,
2944 "attachment");
2945 };
Ed Tanousdeae6a72024-11-11 21:58:57 -08002946 dbus::utility::getAllProperties(
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002947 *crow::connections::systemBus, crashdumpObject,
2948 crashdumpPath + std::string("/") + logID,
2949 crashdumpInterface, std::move(getStoredLogCallback));
2950 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002951}
2952
Jason M. Billsc5a4c822022-01-06 15:51:23 -08002953enum class OEMDiagnosticType
2954{
2955 onDemand,
2956 telemetry,
2957 invalid,
2958};
2959
Ed Tanous26ccae32023-02-16 10:28:44 -08002960inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr)
Jason M. Billsc5a4c822022-01-06 15:51:23 -08002961{
2962 if (oemDiagStr == "OnDemand")
2963 {
2964 return OEMDiagnosticType::onDemand;
2965 }
2966 if (oemDiagStr == "Telemetry")
2967 {
2968 return OEMDiagnosticType::telemetry;
2969 }
2970
2971 return OEMDiagnosticType::invalid;
2972}
2973
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002974inline void requestRoutesCrashdumpCollect(App& app)
2975{
2976 // Note: Deviated from redfish privilege registry for GET & HEAD
2977 // method for security reasons.
George Liu0fda0f12021-11-16 10:06:17 +08002978 BMCWEB_ROUTE(
2979 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002980 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002981 // The below is incorrect; Should be ConfigureManager
2982 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002983 .privileges({{"ConfigureComponents"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07002984 .methods(boost::beast::http::verb::post)(
2985 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002986 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2987 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002988 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002989 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002990 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07002991 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002992
2993 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07002994 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002995 // Option currently returns no systems. TBD
2996 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2997 systemName);
2998 return;
2999 }
3000 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
3001 {
3002 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3003 systemName);
3004 return;
3005 }
3006
3007 std::string diagnosticDataType;
3008 std::string oemDiagnosticDataType;
Patrick Williams504af5a2025-02-03 14:29:03 -05003009 if (!redfish::json_util::readJsonAction( //
3010 req, asyncResp->res, //
3011 "DiagnosticDataType", diagnosticDataType, //
Myung Baeafc474a2024-10-09 00:53:29 -07003012 "OEMDiagnosticDataType", oemDiagnosticDataType //
3013 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003014 {
3015 return;
3016 }
3017
3018 if (diagnosticDataType != "OEM")
3019 {
3020 BMCWEB_LOG_ERROR(
3021 "Only OEM DiagnosticDataType supported for Crashdump");
3022 messages::actionParameterValueFormatError(
3023 asyncResp->res, diagnosticDataType,
3024 "DiagnosticDataType", "CollectDiagnosticData");
3025 return;
3026 }
3027
3028 OEMDiagnosticType oemDiagType =
3029 getOEMDiagnosticType(oemDiagnosticDataType);
3030
3031 std::string iface;
3032 std::string method;
3033 std::string taskMatchStr;
3034 if (oemDiagType == OEMDiagnosticType::onDemand)
3035 {
3036 iface = crashdumpOnDemandInterface;
3037 method = "GenerateOnDemandLog";
3038 taskMatchStr =
3039 "type='signal',"
3040 "interface='org.freedesktop.DBus.Properties',"
3041 "member='PropertiesChanged',"
3042 "arg0namespace='com.intel.crashdump'";
3043 }
3044 else if (oemDiagType == OEMDiagnosticType::telemetry)
3045 {
3046 iface = crashdumpTelemetryInterface;
3047 method = "GenerateTelemetryLog";
3048 taskMatchStr =
3049 "type='signal',"
3050 "interface='org.freedesktop.DBus.Properties',"
3051 "member='PropertiesChanged',"
3052 "arg0namespace='com.intel.crashdump'";
Ed Tanous002d39b2022-05-31 08:59:27 -07003053 }
3054 else
3055 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003056 BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}",
3057 oemDiagnosticDataType);
3058 messages::actionParameterValueFormatError(
3059 asyncResp->res, oemDiagnosticDataType,
3060 "OEMDiagnosticDataType", "CollectDiagnosticData");
3061 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07003062 }
Ed Tanous1da66f72018-07-27 16:13:37 -07003063
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003064 auto collectCrashdumpCallback =
3065 [asyncResp, payload(task::Payload(req)),
3066 taskMatchStr](const boost::system::error_code& ec,
3067 const std::string&) mutable {
3068 if (ec)
3069 {
3070 if (ec.value() ==
3071 boost::system::errc::operation_not_supported)
3072 {
3073 messages::resourceInStandby(asyncResp->res);
3074 }
3075 else if (ec.value() == boost::system::errc::
3076 device_or_resource_busy)
3077 {
3078 messages::serviceTemporarilyUnavailable(
3079 asyncResp->res, "60");
3080 }
3081 else
3082 {
3083 messages::internalError(asyncResp->res);
3084 }
3085 return;
3086 }
3087 std::shared_ptr<task::TaskData> task =
3088 task::TaskData::createTask(
3089 [](const boost::system::error_code& ec2,
3090 sdbusplus::message_t&,
3091 const std::shared_ptr<task::TaskData>&
3092 taskData) {
3093 if (!ec2)
3094 {
3095 taskData->messages.emplace_back(
3096 messages::taskCompletedOK(
3097 std::to_string(
3098 taskData->index)));
3099 taskData->state = "Completed";
3100 }
3101 return task::completed;
3102 },
3103 taskMatchStr);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003104
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003105 task->startTimer(std::chrono::minutes(5));
3106 task->populateResp(asyncResp->res);
3107 task->payload.emplace(std::move(payload));
3108 };
3109
3110 crow::connections::systemBus->async_method_call(
3111 std::move(collectCrashdumpCallback), crashdumpObject,
3112 crashdumpPath, iface, method);
3113 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003114}
Kenny L. Ku6eda7682020-06-19 09:48:36 -07003115
Alexander Hansen599b9af2024-08-06 15:11:57 +02003116inline void dBusLogServiceActionsClear(
3117 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
3118{
3119 BMCWEB_LOG_DEBUG("Do delete all entries.");
3120
3121 // Process response from Logging service.
3122 auto respHandler = [asyncResp](const boost::system::error_code& ec) {
3123 BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done");
3124 if (ec)
3125 {
3126 // TODO Handle for specific error code
3127 BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec);
3128 asyncResp->res.result(
3129 boost::beast::http::status::internal_server_error);
3130 return;
3131 }
3132
3133 asyncResp->res.result(boost::beast::http::status::no_content);
3134 };
3135
3136 // Make call to Logging service to request Clear Log
3137 crow::connections::systemBus->async_method_call(
3138 respHandler, "xyz.openbmc_project.Logging",
3139 "/xyz/openbmc_project/logging",
3140 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3141}
3142
Andrew Geisslercb92c032018-08-17 07:56:14 -07003143/**
3144 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3145 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003146inline void requestRoutesDBusLogServiceActionsClear(App& app)
Andrew Geisslercb92c032018-08-17 07:56:14 -07003147{
Andrew Geisslercb92c032018-08-17 07:56:14 -07003148 /**
3149 * Function handles POST method request.
3150 * The Clear Log actions does not require any parameter.The action deletes
3151 * all entries found in the Entries collection for this Log Service.
3152 */
Andrew Geisslercb92c032018-08-17 07:56:14 -07003153
George Liu0fda0f12021-11-16 10:06:17 +08003154 BMCWEB_ROUTE(
3155 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003156 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07003157 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003158 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003159 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003160 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3161 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04003162 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3163 {
3164 return;
3165 }
3166 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
3167 {
3168 // Option currently returns no systems. TBD
3169 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3170 systemName);
3171 return;
3172 }
3173 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
3174 {
3175 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3176 systemName);
3177 return;
3178 }
3179 dBusLogServiceActionsClear(asyncResp);
3180 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003181}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003182
Ed Tanous1da66f72018-07-27 16:13:37 -07003183} // namespace redfish