Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| 3 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 4 | #pragma once |
| 5 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 6 | #include "bmcweb_config.h" |
| 7 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 8 | #include "app.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 9 | #include "async_resp.hpp" |
| 10 | #include "dbus_singleton.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 11 | #include "dbus_utility.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 12 | #include "error_messages.hpp" |
Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 13 | #include "generated/enums/log_entry.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 14 | #include "generated/enums/log_service.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 15 | #include "http_body.hpp" |
| 16 | #include "http_request.hpp" |
| 17 | #include "http_response.hpp" |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 18 | #include "http_utility.hpp" |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 19 | #include "human_sort.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 20 | #include "logging.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 21 | #include "query.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 22 | #include "registries/privilege_registry.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 23 | #include "str_utility.hpp" |
James Feist | 4622957 | 2020-02-19 15:11:58 -0800 | [diff] [blame] | 24 | #include "task.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 25 | #include "task_messages.hpp" |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 26 | #include "utils/dbus_event_log_entry.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 27 | #include "utils/dbus_utils.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 28 | #include "utils/json_utils.hpp" |
Oliver Brewka | ff35df9 | 2025-08-26 08:21:30 +0200 | [diff] [blame] | 29 | #include "utils/log_services_utils.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 30 | #include "utils/time_utils.hpp" |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 31 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 32 | #include <asm-generic/errno.h> |
| 33 | #include <systemd/sd-bus.h> |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 34 | #include <tinyxml2.h> |
Adriana Kobylak | 400fd1f | 2021-01-29 09:01:30 -0600 | [diff] [blame] | 35 | #include <unistd.h> |
Jason M. Bills | e1f2634 | 2018-07-18 12:12:00 -0700 | [diff] [blame] | 36 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 37 | #include <boost/beast/http/field.hpp> |
| 38 | #include <boost/beast/http/status.hpp> |
Ed Tanous | 07c8c20 | 2022-07-11 10:08:08 -0700 | [diff] [blame] | 39 | #include <boost/beast/http/verb.hpp> |
Jason M. Bills | 1ddcf01 | 2019-11-26 14:59:21 -0800 | [diff] [blame] | 40 | #include <boost/system/linux_error.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 41 | #include <boost/url/format.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 42 | #include <boost/url/url.hpp> |
| 43 | #include <sdbusplus/message.hpp> |
| 44 | #include <sdbusplus/message/native_types.hpp> |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 45 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 46 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 47 | #include <algorithm> |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 48 | #include <array> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 49 | #include <chrono> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 50 | #include <cstdint> |
James Feist | 4418c7f | 2019-04-15 11:09:15 -0700 | [diff] [blame] | 51 | #include <filesystem> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 52 | #include <format> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 53 | #include <functional> |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 54 | #include <iterator> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 55 | #include <memory> |
Xiaochao Ma | 75710de | 2021-01-21 17:56:02 +0800 | [diff] [blame] | 56 | #include <optional> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 57 | #include <ranges> |
Ed Tanous | 26702d0 | 2021-11-03 15:02:33 -0700 | [diff] [blame] | 58 | #include <span> |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 59 | #include <string> |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 60 | #include <string_view> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 61 | #include <utility> |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 62 | #include <variant> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 63 | #include <vector> |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 64 | |
| 65 | namespace redfish |
| 66 | { |
| 67 | |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 68 | constexpr const char* crashdumpObject = "com.intel.crashdump"; |
| 69 | constexpr const char* crashdumpPath = "/com/intel/crashdump"; |
| 70 | constexpr const char* crashdumpInterface = "com.intel.crashdump"; |
| 71 | constexpr const char* deleteAllInterface = |
Jason M. Bills | 5b61b5e | 2019-10-16 10:59:02 -0700 | [diff] [blame] | 72 | "xyz.openbmc_project.Collection.DeleteAll"; |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 73 | constexpr const char* crashdumpOnDemandInterface = |
Jason M. Bills | 424c417 | 2019-03-21 13:50:33 -0700 | [diff] [blame] | 74 | "com.intel.crashdump.OnDemand"; |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 75 | constexpr const char* crashdumpTelemetryInterface = |
Kenny L. Ku | 6eda768 | 2020-06-19 09:48:36 -0700 | [diff] [blame] | 76 | "com.intel.crashdump.Telemetry"; |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 77 | |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 78 | enum class DumpCreationProgress |
| 79 | { |
| 80 | DUMP_CREATE_SUCCESS, |
| 81 | DUMP_CREATE_FAILED, |
| 82 | DUMP_CREATE_INPROGRESS |
| 83 | }; |
| 84 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 85 | inline std::string translateSeverityDbusToRedfish(const std::string& s) |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 86 | { |
Ed Tanous | d4d2579 | 2020-09-29 15:15:03 -0700 | [diff] [blame] | 87 | if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || |
| 88 | (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || |
| 89 | (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || |
| 90 | (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 91 | { |
| 92 | return "Critical"; |
| 93 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 94 | if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || |
| 95 | (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || |
| 96 | (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 97 | { |
| 98 | return "OK"; |
| 99 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 100 | if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 101 | { |
| 102 | return "Warning"; |
| 103 | } |
| 104 | return ""; |
| 105 | } |
| 106 | |
Abhishek Patel | 9017faf | 2021-09-14 22:48:55 -0500 | [diff] [blame] | 107 | inline std::optional<bool> getProviderNotifyAction(const std::string& notify) |
| 108 | { |
| 109 | std::optional<bool> notifyAction; |
| 110 | if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify") |
| 111 | { |
| 112 | notifyAction = true; |
| 113 | } |
| 114 | else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit") |
| 115 | { |
| 116 | notifyAction = false; |
| 117 | } |
| 118 | |
| 119 | return notifyAction; |
| 120 | } |
| 121 | |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 122 | inline std::string getDumpPath(std::string_view dumpType) |
| 123 | { |
| 124 | std::string dbusDumpPath = "/xyz/openbmc_project/dump/"; |
| 125 | std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath), |
| 126 | bmcweb::asciiToLower); |
| 127 | |
| 128 | return dbusDumpPath; |
| 129 | } |
| 130 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 131 | inline log_entry::OriginatorTypes mapDbusOriginatorTypeToRedfish( |
| 132 | const std::string& originatorType) |
Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 133 | { |
| 134 | if (originatorType == |
| 135 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client") |
| 136 | { |
| 137 | return log_entry::OriginatorTypes::Client; |
| 138 | } |
| 139 | if (originatorType == |
| 140 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal") |
| 141 | { |
| 142 | return log_entry::OriginatorTypes::Internal; |
| 143 | } |
| 144 | if (originatorType == |
| 145 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService") |
| 146 | { |
| 147 | return log_entry::OriginatorTypes::SupportingService; |
| 148 | } |
| 149 | return log_entry::OriginatorTypes::Invalid; |
| 150 | } |
| 151 | |
Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 152 | inline void parseDumpEntryFromDbusObject( |
Jiaqing Zhao | 2d613eb | 2022-08-15 16:03:00 +0800 | [diff] [blame] | 153 | const dbus::utility::ManagedObjectType::value_type& object, |
Claire Weinan | c6fecda | 2022-07-15 10:43:25 -0700 | [diff] [blame] | 154 | std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs, |
Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 155 | std::string& originatorId, log_entry::OriginatorTypes& originatorType, |
Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 156 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 157 | { |
| 158 | for (const auto& interfaceMap : object.second) |
| 159 | { |
| 160 | if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") |
| 161 | { |
| 162 | for (const auto& propertyMap : interfaceMap.second) |
| 163 | { |
| 164 | if (propertyMap.first == "Status") |
| 165 | { |
| 166 | const auto* status = |
| 167 | std::get_if<std::string>(&propertyMap.second); |
| 168 | if (status == nullptr) |
| 169 | { |
| 170 | messages::internalError(asyncResp->res); |
| 171 | break; |
| 172 | } |
| 173 | dumpStatus = *status; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") |
| 178 | { |
| 179 | for (const auto& propertyMap : interfaceMap.second) |
| 180 | { |
| 181 | if (propertyMap.first == "Size") |
| 182 | { |
| 183 | const auto* sizePtr = |
| 184 | std::get_if<uint64_t>(&propertyMap.second); |
| 185 | if (sizePtr == nullptr) |
| 186 | { |
| 187 | messages::internalError(asyncResp->res); |
| 188 | break; |
| 189 | } |
| 190 | size = *sizePtr; |
| 191 | break; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") |
| 196 | { |
| 197 | for (const auto& propertyMap : interfaceMap.second) |
| 198 | { |
| 199 | if (propertyMap.first == "Elapsed") |
| 200 | { |
| 201 | const uint64_t* usecsTimeStamp = |
| 202 | std::get_if<uint64_t>(&propertyMap.second); |
| 203 | if (usecsTimeStamp == nullptr) |
| 204 | { |
| 205 | messages::internalError(asyncResp->res); |
| 206 | break; |
| 207 | } |
Claire Weinan | c6fecda | 2022-07-15 10:43:25 -0700 | [diff] [blame] | 208 | timestampUs = *usecsTimeStamp; |
Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 209 | break; |
| 210 | } |
| 211 | } |
| 212 | } |
Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 213 | else if (interfaceMap.first == |
| 214 | "xyz.openbmc_project.Common.OriginatedBy") |
| 215 | { |
| 216 | for (const auto& propertyMap : interfaceMap.second) |
| 217 | { |
| 218 | if (propertyMap.first == "OriginatorId") |
| 219 | { |
| 220 | const std::string* id = |
| 221 | std::get_if<std::string>(&propertyMap.second); |
| 222 | if (id == nullptr) |
| 223 | { |
| 224 | messages::internalError(asyncResp->res); |
| 225 | break; |
| 226 | } |
| 227 | originatorId = *id; |
| 228 | } |
| 229 | |
| 230 | if (propertyMap.first == "OriginatorType") |
| 231 | { |
| 232 | const std::string* type = |
| 233 | std::get_if<std::string>(&propertyMap.second); |
| 234 | if (type == nullptr) |
| 235 | { |
| 236 | messages::internalError(asyncResp->res); |
| 237 | break; |
| 238 | } |
| 239 | |
| 240 | originatorType = mapDbusOriginatorTypeToRedfish(*type); |
| 241 | if (originatorType == log_entry::OriginatorTypes::Invalid) |
| 242 | { |
| 243 | messages::internalError(asyncResp->res); |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | } |
Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Nan Zhou | 21ab404 | 2022-06-26 23:07:40 +0000 | [diff] [blame] | 252 | static std::string getDumpEntriesPath(const std::string& dumpType) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 253 | { |
| 254 | std::string entriesPath; |
| 255 | |
| 256 | if (dumpType == "BMC") |
| 257 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 258 | entriesPath = |
| 259 | std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/", |
| 260 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 261 | } |
| 262 | else if (dumpType == "FaultLog") |
| 263 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 264 | entriesPath = |
| 265 | std::format("/redfish/v1/Managers/{}/LogServices/FaultLog/Entries/", |
| 266 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 267 | } |
| 268 | else if (dumpType == "System") |
| 269 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 270 | entriesPath = |
| 271 | std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/", |
| 272 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 273 | } |
| 274 | else |
| 275 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 276 | BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}", |
| 277 | dumpType); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | // Returns empty string on error |
| 281 | return entriesPath; |
| 282 | } |
| 283 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 284 | inline void getDumpEntryCollection( |
| 285 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 286 | const std::string& dumpType) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 287 | { |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 288 | std::string entriesPath = getDumpEntriesPath(dumpType); |
| 289 | if (entriesPath.empty()) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 290 | { |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 291 | messages::internalError(asyncResp->res); |
| 292 | return; |
| 293 | } |
| 294 | |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 295 | sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); |
| 296 | dbus::utility::getManagedObjects( |
| 297 | "xyz.openbmc_project.Dump.Manager", path, |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 298 | [asyncResp, entriesPath, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 299 | dumpType](const boost::system::error_code& ec, |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 300 | const dbus::utility::ManagedObjectType& objects) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 301 | if (ec) |
| 302 | { |
| 303 | BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec); |
| 304 | messages::internalError(asyncResp->res); |
| 305 | return; |
| 306 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 307 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 308 | // Remove ending slash |
| 309 | std::string odataIdStr = entriesPath; |
| 310 | if (!odataIdStr.empty()) |
| 311 | { |
| 312 | odataIdStr.pop_back(); |
| 313 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 314 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 315 | asyncResp->res.jsonValue["@odata.type"] = |
| 316 | "#LogEntryCollection.LogEntryCollection"; |
| 317 | asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr); |
| 318 | asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries"; |
| 319 | asyncResp->res.jsonValue["Description"] = |
| 320 | "Collection of " + dumpType + " Dump Entries"; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 321 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 322 | nlohmann::json::array_t entriesArray; |
| 323 | std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 324 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 325 | dbus::utility::ManagedObjectType resp(objects); |
| 326 | std::ranges::sort(resp, [](const auto& l, const auto& r) { |
| 327 | return AlphanumLess<std::string>()(l.first.filename(), |
| 328 | r.first.filename()); |
| 329 | }); |
| 330 | |
| 331 | for (auto& object : resp) |
| 332 | { |
| 333 | if (object.first.str.find(dumpEntryPath) == std::string::npos) |
| 334 | { |
| 335 | continue; |
| 336 | } |
| 337 | uint64_t timestampUs = 0; |
| 338 | uint64_t size = 0; |
| 339 | std::string dumpStatus; |
| 340 | std::string originatorId; |
| 341 | log_entry::OriginatorTypes originatorType = |
| 342 | log_entry::OriginatorTypes::Internal; |
| 343 | nlohmann::json::object_t thisEntry; |
| 344 | |
| 345 | std::string entryID = object.first.filename(); |
| 346 | if (entryID.empty()) |
| 347 | { |
| 348 | continue; |
| 349 | } |
| 350 | |
| 351 | parseDumpEntryFromDbusObject(object, dumpStatus, size, |
| 352 | timestampUs, originatorId, |
| 353 | originatorType, asyncResp); |
| 354 | |
| 355 | if (dumpStatus != |
| 356 | "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && |
| 357 | !dumpStatus.empty()) |
| 358 | { |
| 359 | // Dump status is not Complete, no need to enumerate |
| 360 | continue; |
| 361 | } |
| 362 | |
| 363 | thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry"; |
| 364 | thisEntry["@odata.id"] = entriesPath + entryID; |
| 365 | thisEntry["Id"] = entryID; |
| 366 | thisEntry["EntryType"] = "Event"; |
| 367 | thisEntry["Name"] = dumpType + " Dump Entry"; |
| 368 | thisEntry["Created"] = |
| 369 | redfish::time_utils::getDateTimeUintUs(timestampUs); |
| 370 | |
| 371 | if (!originatorId.empty()) |
| 372 | { |
| 373 | thisEntry["Originator"] = originatorId; |
| 374 | thisEntry["OriginatorType"] = originatorType; |
| 375 | } |
| 376 | |
| 377 | if (dumpType == "BMC") |
| 378 | { |
| 379 | thisEntry["DiagnosticDataType"] = "Manager"; |
| 380 | thisEntry["AdditionalDataURI"] = |
| 381 | entriesPath + entryID + "/attachment"; |
| 382 | thisEntry["AdditionalDataSizeBytes"] = size; |
| 383 | } |
| 384 | else if (dumpType == "System") |
| 385 | { |
| 386 | thisEntry["DiagnosticDataType"] = "OEM"; |
| 387 | thisEntry["OEMDiagnosticDataType"] = "System"; |
| 388 | thisEntry["AdditionalDataURI"] = |
| 389 | entriesPath + entryID + "/attachment"; |
| 390 | thisEntry["AdditionalDataSizeBytes"] = size; |
| 391 | } |
| 392 | entriesArray.emplace_back(std::move(thisEntry)); |
| 393 | } |
| 394 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 395 | entriesArray.size(); |
| 396 | asyncResp->res.jsonValue["Members"] = std::move(entriesArray); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 397 | }); |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 398 | } |
| 399 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 400 | inline void getDumpEntryById( |
| 401 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 402 | const std::string& entryID, const std::string& dumpType) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 403 | { |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 404 | std::string entriesPath = getDumpEntriesPath(dumpType); |
| 405 | if (entriesPath.empty()) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 406 | { |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 407 | messages::internalError(asyncResp->res); |
| 408 | return; |
| 409 | } |
| 410 | |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 411 | sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); |
| 412 | dbus::utility::getManagedObjects( |
| 413 | "xyz.openbmc_project.Dump.Manager", path, |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 414 | [asyncResp, entryID, dumpType, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 415 | entriesPath](const boost::system::error_code& ec, |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 416 | const dbus::utility::ManagedObjectType& resp) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 417 | if (ec) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 418 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 419 | BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec); |
| 420 | messages::internalError(asyncResp->res); |
| 421 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 424 | bool foundDumpEntry = false; |
| 425 | std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 426 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 427 | for (const auto& objectPath : resp) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 428 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 429 | if (objectPath.first.str != dumpEntryPath + entryID) |
| 430 | { |
| 431 | continue; |
| 432 | } |
| 433 | |
| 434 | foundDumpEntry = true; |
| 435 | uint64_t timestampUs = 0; |
| 436 | uint64_t size = 0; |
| 437 | std::string dumpStatus; |
| 438 | std::string originatorId; |
| 439 | log_entry::OriginatorTypes originatorType = |
| 440 | log_entry::OriginatorTypes::Internal; |
| 441 | |
| 442 | parseDumpEntryFromDbusObject(objectPath, dumpStatus, size, |
| 443 | timestampUs, originatorId, |
| 444 | originatorType, asyncResp); |
| 445 | |
| 446 | if (dumpStatus != |
| 447 | "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && |
| 448 | !dumpStatus.empty()) |
| 449 | { |
| 450 | // Dump status is not Complete |
| 451 | // return not found until status is changed to Completed |
| 452 | messages::resourceNotFound(asyncResp->res, |
| 453 | dumpType + " dump", entryID); |
| 454 | return; |
| 455 | } |
| 456 | |
| 457 | asyncResp->res.jsonValue["@odata.type"] = |
| 458 | "#LogEntry.v1_11_0.LogEntry"; |
| 459 | asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID; |
| 460 | asyncResp->res.jsonValue["Id"] = entryID; |
| 461 | asyncResp->res.jsonValue["EntryType"] = "Event"; |
| 462 | asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; |
| 463 | asyncResp->res.jsonValue["Created"] = |
| 464 | redfish::time_utils::getDateTimeUintUs(timestampUs); |
| 465 | |
| 466 | if (!originatorId.empty()) |
| 467 | { |
| 468 | asyncResp->res.jsonValue["Originator"] = originatorId; |
| 469 | asyncResp->res.jsonValue["OriginatorType"] = originatorType; |
| 470 | } |
| 471 | |
| 472 | if (dumpType == "BMC") |
| 473 | { |
| 474 | asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; |
| 475 | asyncResp->res.jsonValue["AdditionalDataURI"] = |
| 476 | entriesPath + entryID + "/attachment"; |
| 477 | asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; |
| 478 | } |
| 479 | else if (dumpType == "System") |
| 480 | { |
| 481 | asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; |
| 482 | asyncResp->res.jsonValue["OEMDiagnosticDataType"] = |
| 483 | "System"; |
| 484 | asyncResp->res.jsonValue["AdditionalDataURI"] = |
| 485 | entriesPath + entryID + "/attachment"; |
| 486 | asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; |
| 487 | } |
| 488 | } |
| 489 | if (!foundDumpEntry) |
| 490 | { |
| 491 | BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID); |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 492 | messages::resourceNotFound(asyncResp->res, dumpType + " dump", |
| 493 | entryID); |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 494 | return; |
| 495 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 496 | }); |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 497 | } |
| 498 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 499 | inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Stanley Chu | 9878256 | 2020-11-04 16:10:24 +0800 | [diff] [blame] | 500 | const std::string& entryID, |
Asmitha Karunanithi | b47452b | 2020-09-25 02:02:19 -0500 | [diff] [blame] | 501 | const std::string& dumpType) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 502 | { |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 503 | auto respHandler = [asyncResp, |
| 504 | entryID](const boost::system::error_code& ec) { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 505 | BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done"); |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 506 | if (ec) |
| 507 | { |
George Liu | 3de8d8b | 2021-03-22 17:49:39 +0800 | [diff] [blame] | 508 | if (ec.value() == EBADR) |
| 509 | { |
| 510 | messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); |
| 511 | return; |
| 512 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 513 | BMCWEB_LOG_ERROR( |
| 514 | "Dump (DBus) doDelete respHandler got error {} entryID={}", ec, |
| 515 | entryID); |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 516 | messages::internalError(asyncResp->res); |
| 517 | return; |
| 518 | } |
| 519 | }; |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 520 | |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 521 | dbus::utility::async_method_call( |
| 522 | asyncResp, respHandler, "xyz.openbmc_project.Dump.Manager", |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 523 | std::format("{}/entry/{}", getDumpPath(dumpType), entryID), |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 524 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 525 | } |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 526 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 527 | inline void downloadDumpEntry( |
| 528 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 529 | const std::string& entryID, const std::string& dumpType) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 530 | { |
| 531 | if (dumpType != "BMC") |
| 532 | { |
| 533 | BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID); |
| 534 | messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID); |
| 535 | return; |
| 536 | } |
| 537 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 538 | std::string dumpEntryPath = |
| 539 | std::format("{}/entry/{}", getDumpPath(dumpType), entryID); |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 540 | |
| 541 | auto downloadDumpEntryHandler = |
| 542 | [asyncResp, entryID, |
| 543 | dumpType](const boost::system::error_code& ec, |
| 544 | const sdbusplus::message::unix_fd& unixfd) { |
Oliver Brewka | ff35df9 | 2025-08-26 08:21:30 +0200 | [diff] [blame] | 545 | log_services_utils::downloadEntryCallback(asyncResp, entryID, |
| 546 | dumpType, ec, unixfd); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 547 | }; |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 548 | |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 549 | dbus::utility::async_method_call( |
| 550 | asyncResp, std::move(downloadDumpEntryHandler), |
| 551 | "xyz.openbmc_project.Dump.Manager", dumpEntryPath, |
| 552 | "xyz.openbmc_project.Dump.Entry", "GetFileHandle"); |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 555 | inline void downloadEventLogEntry( |
| 556 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 557 | const std::string& systemName, const std::string& entryID, |
| 558 | const std::string& dumpType) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 559 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 560 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 561 | { |
| 562 | // Option currently returns no systems. TBD |
| 563 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 564 | systemName); |
| 565 | return; |
| 566 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 567 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 568 | { |
| 569 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 570 | systemName); |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | std::string entryPath = |
| 575 | sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") / |
| 576 | entryID; |
| 577 | |
| 578 | auto downloadEventLogEntryHandler = |
| 579 | [asyncResp, entryID, |
| 580 | dumpType](const boost::system::error_code& ec, |
| 581 | const sdbusplus::message::unix_fd& unixfd) { |
Oliver Brewka | ff35df9 | 2025-08-26 08:21:30 +0200 | [diff] [blame] | 582 | log_services_utils::downloadEntryCallback(asyncResp, entryID, |
| 583 | dumpType, ec, unixfd); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 584 | }; |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 585 | |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 586 | dbus::utility::async_method_call( |
| 587 | asyncResp, std::move(downloadEventLogEntryHandler), |
| 588 | "xyz.openbmc_project.Logging", entryPath, |
| 589 | "xyz.openbmc_project.Logging.Entry", "GetEntry"); |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 592 | inline DumpCreationProgress mapDbusStatusToDumpProgress( |
| 593 | const std::string& status) |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 594 | { |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 595 | if (status == |
| 596 | "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" || |
| 597 | status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted") |
| 598 | { |
| 599 | return DumpCreationProgress::DUMP_CREATE_FAILED; |
| 600 | } |
| 601 | if (status == |
| 602 | "xyz.openbmc_project.Common.Progress.OperationStatus.Completed") |
| 603 | { |
| 604 | return DumpCreationProgress::DUMP_CREATE_SUCCESS; |
| 605 | } |
| 606 | return DumpCreationProgress::DUMP_CREATE_INPROGRESS; |
| 607 | } |
| 608 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 609 | inline DumpCreationProgress getDumpCompletionStatus( |
| 610 | const dbus::utility::DBusPropertiesMap& values) |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 611 | { |
| 612 | for (const auto& [key, val] : values) |
| 613 | { |
| 614 | if (key == "Status") |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 615 | { |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 616 | const std::string* value = std::get_if<std::string>(&val); |
| 617 | if (value == nullptr) |
| 618 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 619 | BMCWEB_LOG_ERROR("Status property value is null"); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 620 | return DumpCreationProgress::DUMP_CREATE_FAILED; |
| 621 | } |
| 622 | return mapDbusStatusToDumpProgress(*value); |
| 623 | } |
| 624 | } |
| 625 | return DumpCreationProgress::DUMP_CREATE_INPROGRESS; |
| 626 | } |
| 627 | |
| 628 | inline std::string getDumpEntryPath(const std::string& dumpPath) |
| 629 | { |
| 630 | if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry") |
| 631 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 632 | return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/", |
Ed Tanous | 9f56509 | 2024-07-12 22:06:53 -0700 | [diff] [blame] | 633 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 634 | } |
| 635 | if (dumpPath == "/xyz/openbmc_project/dump/system/entry") |
| 636 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 637 | return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/", |
| 638 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 639 | } |
| 640 | return ""; |
| 641 | } |
| 642 | |
| 643 | inline void createDumpTaskCallback( |
| 644 | task::Payload&& payload, |
| 645 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 646 | const sdbusplus::message::object_path& createdObjPath) |
| 647 | { |
| 648 | const std::string dumpPath = createdObjPath.parent_path().str; |
| 649 | const std::string dumpId = createdObjPath.filename(); |
| 650 | |
| 651 | std::string dumpEntryPath = getDumpEntryPath(dumpPath); |
| 652 | |
| 653 | if (dumpEntryPath.empty()) |
| 654 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 655 | BMCWEB_LOG_ERROR("Invalid dump type received"); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 656 | messages::internalError(asyncResp->res); |
| 657 | return; |
| 658 | } |
| 659 | |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 660 | dbus::utility::async_method_call( |
| 661 | asyncResp, |
Ed Tanous | 8cb2c02 | 2024-03-27 16:31:46 -0700 | [diff] [blame] | 662 | [asyncResp, payload = std::move(payload), createdObjPath, |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 663 | dumpEntryPath{std::move(dumpEntryPath)}, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 664 | dumpId](const boost::system::error_code& ec, |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 665 | const std::string& introspectXml) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 666 | if (ec) |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 667 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 668 | BMCWEB_LOG_ERROR("Introspect call failed with error: {}", |
| 669 | ec.message()); |
| 670 | messages::internalError(asyncResp->res); |
| 671 | return; |
| 672 | } |
| 673 | |
| 674 | // Check if the created dump object has implemented Progress |
| 675 | // interface to track dump completion. If yes, fetch the "Status" |
| 676 | // property of the interface, modify the task state accordingly. |
| 677 | // Else, return task completed. |
| 678 | tinyxml2::XMLDocument doc; |
| 679 | |
| 680 | doc.Parse(introspectXml.data(), introspectXml.size()); |
| 681 | tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node"); |
| 682 | if (pRoot == nullptr) |
| 683 | { |
| 684 | BMCWEB_LOG_ERROR("XML document failed to parse"); |
| 685 | messages::internalError(asyncResp->res); |
| 686 | return; |
| 687 | } |
| 688 | tinyxml2::XMLElement* interfaceNode = |
| 689 | pRoot->FirstChildElement("interface"); |
| 690 | |
| 691 | bool isProgressIntfPresent = false; |
| 692 | while (interfaceNode != nullptr) |
| 693 | { |
| 694 | const char* thisInterfaceName = |
| 695 | interfaceNode->Attribute("name"); |
| 696 | if (thisInterfaceName != nullptr) |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 697 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 698 | if (thisInterfaceName == |
| 699 | std::string_view("xyz.openbmc_project.Common.Progress")) |
| 700 | { |
| 701 | interfaceNode = |
| 702 | interfaceNode->NextSiblingElement("interface"); |
| 703 | continue; |
| 704 | } |
| 705 | isProgressIntfPresent = true; |
| 706 | break; |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 707 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 708 | interfaceNode = interfaceNode->NextSiblingElement("interface"); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 709 | } |
| 710 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 711 | std::shared_ptr<task::TaskData> task = task::TaskData::createTask( |
| 712 | [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent]( |
| 713 | const boost::system::error_code& ec2, |
| 714 | sdbusplus::message_t& msg, |
| 715 | const std::shared_ptr<task::TaskData>& taskData) { |
| 716 | if (ec2) |
| 717 | { |
| 718 | BMCWEB_LOG_ERROR("{}: Error in creating dump", |
| 719 | createdObjPath.str); |
| 720 | taskData->messages.emplace_back( |
| 721 | messages::internalError()); |
| 722 | taskData->state = "Cancelled"; |
| 723 | return task::completed; |
| 724 | } |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 725 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 726 | if (isProgressIntfPresent) |
| 727 | { |
| 728 | dbus::utility::DBusPropertiesMap values; |
| 729 | std::string prop; |
| 730 | msg.read(prop, values); |
| 731 | |
| 732 | DumpCreationProgress dumpStatus = |
| 733 | getDumpCompletionStatus(values); |
| 734 | if (dumpStatus == |
| 735 | DumpCreationProgress::DUMP_CREATE_FAILED) |
| 736 | { |
| 737 | BMCWEB_LOG_ERROR("{}: Error in creating dump", |
| 738 | createdObjPath.str); |
| 739 | taskData->state = "Cancelled"; |
| 740 | return task::completed; |
| 741 | } |
| 742 | |
| 743 | if (dumpStatus == |
| 744 | DumpCreationProgress::DUMP_CREATE_INPROGRESS) |
| 745 | { |
| 746 | BMCWEB_LOG_DEBUG( |
| 747 | "{}: Dump creation task is in progress", |
| 748 | createdObjPath.str); |
| 749 | return !task::completed; |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | nlohmann::json retMessage = messages::success(); |
| 754 | taskData->messages.emplace_back(retMessage); |
| 755 | |
| 756 | boost::urls::url url = boost::urls::format( |
| 757 | "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}", |
| 758 | BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId); |
| 759 | |
| 760 | std::string headerLoc = "Location: "; |
| 761 | headerLoc += url.buffer(); |
| 762 | |
| 763 | taskData->payload->httpHeaders.emplace_back( |
| 764 | std::move(headerLoc)); |
| 765 | |
| 766 | BMCWEB_LOG_DEBUG("{}: Dump creation task completed", |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 767 | createdObjPath.str); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 768 | taskData->state = "Completed"; |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 769 | return task::completed; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 770 | }, |
| 771 | "type='signal',interface='org.freedesktop.DBus.Properties'," |
| 772 | "member='PropertiesChanged',path='" + |
| 773 | createdObjPath.str + "'"); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 774 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 775 | // The task timer is set to max time limit within which the |
| 776 | // requested dump will be collected. |
| 777 | task->startTimer(std::chrono::minutes(6)); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 778 | task->payload.emplace(payload); |
Chinmay Shripad Hegde | 29e2bdd | 2025-06-06 16:23:47 +0530 | [diff] [blame] | 779 | task->populateResp(asyncResp->res); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 780 | }, |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 781 | "xyz.openbmc_project.Dump.Manager", createdObjPath, |
| 782 | "org.freedesktop.DBus.Introspectable", "Introspect"); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 783 | } |
| 784 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 785 | inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 786 | const crow::Request& req, const std::string& dumpType) |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 787 | { |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 788 | std::string dumpPath = getDumpEntriesPath(dumpType); |
| 789 | if (dumpPath.empty()) |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 790 | { |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 791 | messages::internalError(asyncResp->res); |
| 792 | return; |
| 793 | } |
| 794 | |
| 795 | std::optional<std::string> diagnosticDataType; |
| 796 | std::optional<std::string> oemDiagnosticDataType; |
| 797 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 798 | if (!redfish::json_util::readJsonAction( // |
| 799 | req, asyncResp->res, // |
| 800 | "DiagnosticDataType", diagnosticDataType, // |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 801 | "OEMDiagnosticDataType", oemDiagnosticDataType // |
| 802 | )) |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 803 | { |
| 804 | return; |
| 805 | } |
| 806 | |
| 807 | if (dumpType == "System") |
| 808 | { |
| 809 | if (!oemDiagnosticDataType || !diagnosticDataType) |
| 810 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 811 | BMCWEB_LOG_ERROR( |
| 812 | "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 813 | messages::actionParameterMissing( |
| 814 | asyncResp->res, "CollectDiagnosticData", |
| 815 | "DiagnosticDataType & OEMDiagnosticDataType"); |
| 816 | return; |
| 817 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 818 | if ((*oemDiagnosticDataType != "System") || |
| 819 | (*diagnosticDataType != "OEM")) |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 820 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 821 | BMCWEB_LOG_ERROR("Wrong parameter values passed"); |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 822 | messages::internalError(asyncResp->res); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 823 | return; |
| 824 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 825 | dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/", |
| 826 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 827 | } |
| 828 | else if (dumpType == "BMC") |
| 829 | { |
| 830 | if (!diagnosticDataType) |
| 831 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 832 | BMCWEB_LOG_ERROR( |
| 833 | "CreateDump action parameter 'DiagnosticDataType' not found!"); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 834 | messages::actionParameterMissing( |
| 835 | asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); |
| 836 | return; |
| 837 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 838 | if (*diagnosticDataType != "Manager") |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 839 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 840 | BMCWEB_LOG_ERROR( |
| 841 | "Wrong parameter value passed for 'DiagnosticDataType'"); |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 842 | messages::internalError(asyncResp->res); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 843 | return; |
| 844 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 845 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/", |
| 846 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 847 | } |
| 848 | else |
| 849 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 850 | BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type"); |
Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 851 | messages::internalError(asyncResp->res); |
| 852 | return; |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 853 | } |
| 854 | |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 855 | std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>> |
| 856 | createDumpParamVec; |
| 857 | |
Carson Labrado | f574a8e | 2023-03-22 02:26:00 +0000 | [diff] [blame] | 858 | if (req.session != nullptr) |
| 859 | { |
| 860 | createDumpParamVec.emplace_back( |
| 861 | "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId", |
| 862 | req.session->clientIp); |
| 863 | createDumpParamVec.emplace_back( |
| 864 | "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType", |
| 865 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client"); |
| 866 | } |
Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 867 | |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 868 | dbus::utility::async_method_call( |
| 869 | asyncResp, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 870 | [asyncResp, payload(task::Payload(req)), |
| 871 | dumpPath](const boost::system::error_code& ec, |
| 872 | const sdbusplus::message_t& msg, |
| 873 | const sdbusplus::message::object_path& objPath) mutable { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 874 | if (ec) |
Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 875 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 876 | BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec); |
| 877 | const sd_bus_error* dbusError = msg.get_error(); |
| 878 | if (dbusError == nullptr) |
| 879 | { |
| 880 | messages::internalError(asyncResp->res); |
| 881 | return; |
| 882 | } |
| 883 | |
| 884 | BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}", |
| 885 | dbusError->name, dbusError->message); |
| 886 | if (std::string_view( |
| 887 | "xyz.openbmc_project.Common.Error.NotAllowed") == |
| 888 | dbusError->name) |
| 889 | { |
| 890 | messages::resourceInStandby(asyncResp->res); |
| 891 | return; |
| 892 | } |
| 893 | if (std::string_view( |
| 894 | "xyz.openbmc_project.Dump.Create.Error.Disabled") == |
| 895 | dbusError->name) |
| 896 | { |
| 897 | messages::serviceDisabled(asyncResp->res, dumpPath); |
| 898 | return; |
| 899 | } |
| 900 | if (std::string_view( |
| 901 | "xyz.openbmc_project.Common.Error.Unavailable") == |
| 902 | dbusError->name) |
| 903 | { |
| 904 | messages::resourceInUse(asyncResp->res); |
| 905 | return; |
| 906 | } |
| 907 | // Other Dbus errors such as: |
| 908 | // xyz.openbmc_project.Common.Error.InvalidArgument & |
| 909 | // org.freedesktop.DBus.Error.InvalidArgs are all related to |
| 910 | // the dbus call that is made here in the bmcweb |
| 911 | // implementation and has nothing to do with the client's |
| 912 | // input in the request. Hence, returning internal error |
| 913 | // back to the client. |
Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 914 | messages::internalError(asyncResp->res); |
| 915 | return; |
| 916 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 917 | BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str); |
| 918 | createDumpTaskCallback(std::move(payload), asyncResp, objPath); |
| 919 | }, |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 920 | "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType), |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 921 | "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 922 | } |
| 923 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 924 | inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 925 | const std::string& dumpType) |
Asmitha Karunanithi | 80319af | 2020-05-07 05:30:21 -0500 | [diff] [blame] | 926 | { |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 927 | dbus::utility::async_method_call( |
| 928 | asyncResp, |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 929 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 930 | if (ec) |
| 931 | { |
| 932 | BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec); |
| 933 | messages::internalError(asyncResp->res); |
| 934 | return; |
| 935 | } |
Amy Chang | e246046 | 2025-05-06 00:10:13 -0700 | [diff] [blame] | 936 | messages::success(asyncResp->res); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 937 | }, |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 938 | "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType), |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 939 | "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); |
Asmitha Karunanithi | 80319af | 2020-05-07 05:30:21 -0500 | [diff] [blame] | 940 | } |
| 941 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 942 | inline void parseCrashdumpParameters( |
| 943 | const dbus::utility::DBusPropertiesMap& params, std::string& filename, |
| 944 | std::string& timestamp, std::string& logfile) |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 945 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 946 | const std::string* filenamePtr = nullptr; |
| 947 | const std::string* timestampPtr = nullptr; |
| 948 | const std::string* logfilePtr = nullptr; |
| 949 | |
| 950 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 951 | dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr, |
| 952 | "Filename", filenamePtr, "Log", logfilePtr); |
| 953 | |
| 954 | if (!success) |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 955 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 956 | return; |
| 957 | } |
| 958 | |
| 959 | if (filenamePtr != nullptr) |
| 960 | { |
| 961 | filename = *filenamePtr; |
| 962 | } |
| 963 | |
| 964 | if (timestampPtr != nullptr) |
| 965 | { |
| 966 | timestamp = *timestampPtr; |
| 967 | } |
| 968 | |
| 969 | if (logfilePtr != nullptr) |
| 970 | { |
| 971 | logfile = *logfilePtr; |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 972 | } |
| 973 | } |
| 974 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 975 | inline void requestRoutesSystemLogServiceCollection(App& app) |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 976 | { |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 977 | /** |
| 978 | * Functions triggers appropriate requests on DBus |
| 979 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 980 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 981 | .privileges(redfish::privileges::getLogServiceCollection) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 982 | .methods( |
| 983 | boost::beast::http::verb:: |
| 984 | get)([&app](const crow::Request& req, |
| 985 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 986 | const std::string& systemName) { |
| 987 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 988 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 989 | return; |
| 990 | } |
| 991 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 992 | { |
| 993 | // Option currently returns no systems. TBD |
| 994 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 995 | systemName); |
| 996 | return; |
| 997 | } |
| 998 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 999 | { |
| 1000 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1001 | systemName); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1002 | return; |
| 1003 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1004 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1005 | // Collections don't include the static data added by SubRoute |
| 1006 | // because it has a duplicate entry for members |
| 1007 | asyncResp->res.jsonValue["@odata.type"] = |
| 1008 | "#LogServiceCollection.LogServiceCollection"; |
| 1009 | asyncResp->res.jsonValue["@odata.id"] = |
| 1010 | std::format("/redfish/v1/Systems/{}/LogServices", |
| 1011 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1012 | asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; |
| 1013 | asyncResp->res.jsonValue["Description"] = |
| 1014 | "Collection of LogServices for this Computer System"; |
| 1015 | nlohmann::json& logServiceArray = |
| 1016 | asyncResp->res.jsonValue["Members"]; |
| 1017 | logServiceArray = nlohmann::json::array(); |
| 1018 | nlohmann::json::object_t eventLog; |
| 1019 | eventLog["@odata.id"] = |
| 1020 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog", |
| 1021 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1022 | logServiceArray.emplace_back(std::move(eventLog)); |
| 1023 | if constexpr (BMCWEB_REDFISH_DUMP_LOG) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1024 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1025 | nlohmann::json::object_t dumpLog; |
| 1026 | dumpLog["@odata.id"] = |
| 1027 | std::format("/redfish/v1/Systems/{}/LogServices/Dump", |
| 1028 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1029 | logServiceArray.emplace_back(std::move(dumpLog)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1030 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1031 | |
| 1032 | if constexpr (BMCWEB_REDFISH_CPU_LOG) |
| 1033 | { |
| 1034 | nlohmann::json::object_t crashdump; |
| 1035 | crashdump["@odata.id"] = |
| 1036 | std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", |
| 1037 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1038 | logServiceArray.emplace_back(std::move(crashdump)); |
| 1039 | } |
| 1040 | |
| 1041 | if constexpr (BMCWEB_REDFISH_HOST_LOGGER) |
| 1042 | { |
| 1043 | nlohmann::json::object_t hostlogger; |
| 1044 | hostlogger["@odata.id"] = |
| 1045 | std::format("/redfish/v1/Systems/{}/LogServices/HostLogger", |
| 1046 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1047 | logServiceArray.emplace_back(std::move(hostlogger)); |
| 1048 | } |
| 1049 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1050 | logServiceArray.size(); |
| 1051 | |
| 1052 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1053 | "xyz.openbmc_project.State.Boot.PostCode"}; |
| 1054 | dbus::utility::getSubTreePaths( |
| 1055 | "/", 0, interfaces, |
| 1056 | [asyncResp](const boost::system::error_code& ec, |
| 1057 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 1058 | subtreePath) { |
| 1059 | if (ec) |
| 1060 | { |
| 1061 | BMCWEB_LOG_ERROR("{}", ec); |
| 1062 | return; |
| 1063 | } |
| 1064 | |
| 1065 | for (const auto& pathStr : subtreePath) |
| 1066 | { |
| 1067 | if (pathStr.find("PostCode") != std::string::npos) |
| 1068 | { |
| 1069 | nlohmann::json& logServiceArrayLocal = |
| 1070 | asyncResp->res.jsonValue["Members"]; |
| 1071 | nlohmann::json::object_t member; |
| 1072 | member["@odata.id"] = std::format( |
| 1073 | "/redfish/v1/Systems/{}/LogServices/PostCodes", |
| 1074 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1075 | |
| 1076 | logServiceArrayLocal.emplace_back( |
| 1077 | std::move(member)); |
| 1078 | |
| 1079 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1080 | logServiceArrayLocal.size(); |
| 1081 | return; |
| 1082 | } |
| 1083 | } |
| 1084 | }); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1085 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | inline void requestRoutesEventLogService(App& app) |
| 1089 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1090 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1091 | .privileges(redfish::privileges::getLogService) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1092 | .methods( |
| 1093 | boost::beast::http::verb:: |
| 1094 | get)([&app](const crow::Request& req, |
| 1095 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1096 | const std::string& systemName) { |
| 1097 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1098 | { |
| 1099 | return; |
| 1100 | } |
| 1101 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1102 | { |
| 1103 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1104 | systemName); |
| 1105 | return; |
| 1106 | } |
| 1107 | asyncResp->res.jsonValue["@odata.id"] = |
| 1108 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog", |
| 1109 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1110 | asyncResp->res.jsonValue["@odata.type"] = |
| 1111 | "#LogService.v1_2_0.LogService"; |
| 1112 | asyncResp->res.jsonValue["Name"] = "Event Log Service"; |
| 1113 | asyncResp->res.jsonValue["Description"] = |
| 1114 | "System Event Log Service"; |
| 1115 | asyncResp->res.jsonValue["Id"] = "EventLog"; |
| 1116 | asyncResp->res.jsonValue["OverWritePolicy"] = |
| 1117 | log_service::OverWritePolicy::WrapsWhenFull; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1118 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1119 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| 1120 | redfish::time_utils::getDateTimeOffsetNow(); |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1121 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1122 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 1123 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 1124 | redfishDateTimeOffset.second; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1125 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1126 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format( |
| 1127 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries", |
Ed Tanous | 20fa6a2 | 2024-05-20 18:02:58 -0700 | [diff] [blame] | 1128 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1129 | asyncResp->res |
| 1130 | .jsonValue["Actions"]["#LogService.ClearLog"]["target"] |
| 1131 | |
| 1132 | = std::format( |
| 1133 | "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog", |
| 1134 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1135 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
Myung Bae | 7f3726a | 2025-04-26 15:17:23 -0500 | [diff] [blame] | 1138 | inline void fillEventLogLogEntryFromDbusLogEntry( |
| 1139 | const DbusEventLogEntry& entry, nlohmann::json& objectToFillOut) |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1140 | { |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1141 | objectToFillOut["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
| 1142 | objectToFillOut["@odata.id"] = boost::urls::format( |
| 1143 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}", |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1144 | BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id)); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1145 | objectToFillOut["Name"] = "System Event Log Entry"; |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1146 | objectToFillOut["Id"] = std::to_string(entry.Id); |
| 1147 | objectToFillOut["Message"] = entry.Message; |
| 1148 | objectToFillOut["Resolved"] = entry.Resolved; |
| 1149 | std::optional<bool> notifyAction = |
| 1150 | getProviderNotifyAction(entry.ServiceProviderNotify); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1151 | if (notifyAction) |
| 1152 | { |
| 1153 | objectToFillOut["ServiceProviderNotified"] = *notifyAction; |
| 1154 | } |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1155 | if ((entry.Resolution != nullptr) && !entry.Resolution->empty()) |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1156 | { |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1157 | objectToFillOut["Resolution"] = *entry.Resolution; |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1158 | } |
| 1159 | objectToFillOut["EntryType"] = "Event"; |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1160 | objectToFillOut["Severity"] = |
| 1161 | translateSeverityDbusToRedfish(entry.Severity); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1162 | objectToFillOut["Created"] = |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1163 | redfish::time_utils::getDateTimeUintMs(entry.Timestamp); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1164 | objectToFillOut["Modified"] = |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1165 | redfish::time_utils::getDateTimeUintMs(entry.UpdateTimestamp); |
| 1166 | if (entry.Path != nullptr) |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1167 | { |
| 1168 | objectToFillOut["AdditionalDataURI"] = boost::urls::format( |
| 1169 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment", |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1170 | BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id)); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1174 | inline void afterLogEntriesGetManagedObjects( |
| 1175 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1176 | const boost::system::error_code& ec, |
| 1177 | const dbus::utility::ManagedObjectType& resp) |
| 1178 | { |
| 1179 | if (ec) |
| 1180 | { |
| 1181 | // TODO Handle for specific error code |
| 1182 | BMCWEB_LOG_ERROR("getLogEntriesIfaceData resp_handler got error {}", |
| 1183 | ec); |
| 1184 | messages::internalError(asyncResp->res); |
| 1185 | return; |
| 1186 | } |
| 1187 | nlohmann::json::array_t entriesArray; |
| 1188 | for (const auto& objectPath : resp) |
| 1189 | { |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1190 | dbus::utility::DBusPropertiesMap propsFlattened; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1191 | auto isEntry = |
| 1192 | std::ranges::find_if(objectPath.second, [](const auto& object) { |
| 1193 | return object.first == "xyz.openbmc_project.Logging.Entry"; |
| 1194 | }); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1195 | if (isEntry == objectPath.second.end()) |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1196 | { |
| 1197 | continue; |
| 1198 | } |
Myung Bae | 7f3726a | 2025-04-26 15:17:23 -0500 | [diff] [blame] | 1199 | |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1200 | for (const auto& interfaceMap : objectPath.second) |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1201 | { |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1202 | for (const auto& propertyMap : interfaceMap.second) |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1203 | { |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1204 | propsFlattened.emplace_back(propertyMap.first, |
| 1205 | propertyMap.second); |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1206 | } |
| 1207 | } |
Myung Bae | 7f3726a | 2025-04-26 15:17:23 -0500 | [diff] [blame] | 1208 | std::optional<DbusEventLogEntry> optEntry = |
| 1209 | fillDbusEventLogEntryFromPropertyMap(propsFlattened); |
| 1210 | |
| 1211 | if (!optEntry.has_value()) |
Igor Kanyuka | 9089660 | 2025-03-13 08:52:38 +0000 | [diff] [blame] | 1212 | { |
Myung Bae | 7f3726a | 2025-04-26 15:17:23 -0500 | [diff] [blame] | 1213 | messages::internalError(asyncResp->res); |
Igor Kanyuka | 9089660 | 2025-03-13 08:52:38 +0000 | [diff] [blame] | 1214 | return; |
| 1215 | } |
Myung Bae | 7f3726a | 2025-04-26 15:17:23 -0500 | [diff] [blame] | 1216 | fillEventLogLogEntryFromDbusLogEntry(*optEntry, |
| 1217 | entriesArray.emplace_back()); |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1218 | } |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1219 | |
Igor Kanyuka | 9089660 | 2025-03-13 08:52:38 +0000 | [diff] [blame] | 1220 | redfish::json_util::sortJsonArrayByKey(entriesArray, "Id"); |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1221 | asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size(); |
| 1222 | asyncResp->res.jsonValue["Members"] = std::move(entriesArray); |
| 1223 | } |
| 1224 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1225 | inline void dBusEventLogEntryCollection( |
| 1226 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1227 | { |
| 1228 | // Collections don't include the static data added by SubRoute |
| 1229 | // because it has a duplicate entry for members |
| 1230 | asyncResp->res.jsonValue["@odata.type"] = |
| 1231 | "#LogEntryCollection.LogEntryCollection"; |
| 1232 | asyncResp->res.jsonValue["@odata.id"] = |
| 1233 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries", |
| 1234 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1235 | asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; |
| 1236 | asyncResp->res.jsonValue["Description"] = |
| 1237 | "Collection of System Event Log Entries"; |
| 1238 | |
| 1239 | // DBus implementation of EventLog/Entries |
| 1240 | // Make call to Logging Service to find all log entry objects |
| 1241 | sdbusplus::message::object_path path("/xyz/openbmc_project/logging"); |
| 1242 | dbus::utility::getManagedObjects( |
| 1243 | "xyz.openbmc_project.Logging", path, |
| 1244 | [asyncResp](const boost::system::error_code& ec, |
| 1245 | const dbus::utility::ManagedObjectType& resp) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1246 | afterLogEntriesGetManagedObjects(asyncResp, ec, resp); |
| 1247 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | inline void requestRoutesDBusEventLogEntryCollection(App& app) |
| 1251 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1252 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1253 | .privileges(redfish::privileges::getLogEntryCollection) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1254 | .methods(boost::beast::http::verb::get)( |
| 1255 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1256 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1257 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1258 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1259 | { |
| 1260 | return; |
| 1261 | } |
| 1262 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1263 | { |
| 1264 | // Option currently returns no systems. TBD |
| 1265 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1266 | systemName); |
| 1267 | return; |
| 1268 | } |
| 1269 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1270 | { |
| 1271 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1272 | systemName); |
| 1273 | return; |
| 1274 | } |
| 1275 | dBusEventLogEntryCollection(asyncResp); |
| 1276 | }); |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1277 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1278 | |
Myung Bae | c6b7cae | 2025-06-05 15:46:57 -0500 | [diff] [blame] | 1279 | inline void afterDBusEventLogEntryGet( |
| 1280 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1281 | const std::string& entryID, const boost::system::error_code& ec, |
| 1282 | const dbus::utility::DBusPropertiesMap& resp) |
| 1283 | { |
| 1284 | if (ec.value() == EBADR) |
| 1285 | { |
| 1286 | messages::resourceNotFound(asyncResp->res, "EventLogEntry", entryID); |
| 1287 | return; |
| 1288 | } |
| 1289 | if (ec) |
| 1290 | { |
| 1291 | BMCWEB_LOG_ERROR("EventLogEntry (DBus) resp_handler got error {}", ec); |
| 1292 | messages::internalError(asyncResp->res); |
| 1293 | return; |
| 1294 | } |
| 1295 | |
Myung Bae | 7f3726a | 2025-04-26 15:17:23 -0500 | [diff] [blame] | 1296 | std::optional<DbusEventLogEntry> optEntry = |
| 1297 | fillDbusEventLogEntryFromPropertyMap(resp); |
| 1298 | |
| 1299 | if (!optEntry.has_value()) |
| 1300 | { |
| 1301 | messages::internalError(asyncResp->res); |
| 1302 | return; |
| 1303 | } |
| 1304 | |
| 1305 | fillEventLogLogEntryFromDbusLogEntry(*optEntry, asyncResp->res.jsonValue); |
Myung Bae | c6b7cae | 2025-06-05 15:46:57 -0500 | [diff] [blame] | 1306 | } |
| 1307 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1308 | inline void dBusEventLogEntryGet( |
| 1309 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1310 | { |
| 1311 | dbus::utility::escapePathForDbus(entryID); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1312 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1313 | // DBus implementation of EventLog/Entries |
| 1314 | // Make call to Logging Service to find all log entry objects |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1315 | dbus::utility::getAllProperties( |
| 1316 | "xyz.openbmc_project.Logging", |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1317 | "/xyz/openbmc_project/logging/entry/" + entryID, "", |
Myung Bae | c6b7cae | 2025-06-05 15:46:57 -0500 | [diff] [blame] | 1318 | std::bind_front(afterDBusEventLogEntryGet, asyncResp, entryID)); |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1319 | } |
| 1320 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1321 | inline void dBusEventLogEntryPatch( |
| 1322 | const crow::Request& req, |
| 1323 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1324 | const std::string& entryId) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1325 | { |
| 1326 | std::optional<bool> resolved; |
| 1327 | |
| 1328 | if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", resolved)) |
| 1329 | { |
| 1330 | return; |
| 1331 | } |
| 1332 | BMCWEB_LOG_DEBUG("Set Resolved"); |
| 1333 | |
| 1334 | setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging", |
| 1335 | "/xyz/openbmc_project/logging/entry/" + entryId, |
| 1336 | "xyz.openbmc_project.Logging.Entry", "Resolved", |
| 1337 | resolved.value_or(false)); |
| 1338 | } |
| 1339 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1340 | inline void dBusEventLogEntryDelete( |
| 1341 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1342 | { |
| 1343 | BMCWEB_LOG_DEBUG("Do delete single event entries."); |
| 1344 | |
| 1345 | dbus::utility::escapePathForDbus(entryID); |
| 1346 | |
| 1347 | // Process response from Logging service. |
| 1348 | auto respHandler = [asyncResp, |
| 1349 | entryID](const boost::system::error_code& ec) { |
| 1350 | BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done"); |
| 1351 | if (ec) |
| 1352 | { |
| 1353 | if (ec.value() == EBADR) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1354 | { |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1355 | messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1356 | return; |
| 1357 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1358 | // TODO Handle for specific error code |
| 1359 | BMCWEB_LOG_ERROR( |
| 1360 | "EventLogEntry (DBus) doDelete respHandler got error {}", ec); |
| 1361 | asyncResp->res.result( |
| 1362 | boost::beast::http::status::internal_server_error); |
| 1363 | return; |
| 1364 | } |
Abhishek Patel | 9017faf | 2021-09-14 22:48:55 -0500 | [diff] [blame] | 1365 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1366 | asyncResp->res.result(boost::beast::http::status::ok); |
| 1367 | }; |
| 1368 | |
| 1369 | // Make call to Logging service to request Delete Log |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 1370 | dbus::utility::async_method_call( |
| 1371 | asyncResp, respHandler, "xyz.openbmc_project.Logging", |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1372 | "/xyz/openbmc_project/logging/entry/" + entryID, |
| 1373 | "xyz.openbmc_project.Object.Delete", "Delete"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1374 | } |
Xiaochao Ma | 75710de | 2021-01-21 17:56:02 +0800 | [diff] [blame] | 1375 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1376 | inline void requestRoutesDBusEventLogEntry(App& app) |
Adriana Kobylak | 400fd1f | 2021-01-29 09:01:30 -0600 | [diff] [blame] | 1377 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1378 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1379 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1380 | .privileges(redfish::privileges::getLogEntry) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1381 | .methods(boost::beast::http::verb::get)( |
| 1382 | [&app](const crow::Request& req, |
| 1383 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1384 | const std::string& systemName, const std::string& entryId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1385 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1386 | { |
| 1387 | return; |
| 1388 | } |
| 1389 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1390 | { |
| 1391 | // Option currently returns no systems. TBD |
| 1392 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1393 | systemName); |
| 1394 | return; |
| 1395 | } |
| 1396 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1397 | { |
| 1398 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1399 | systemName); |
| 1400 | return; |
| 1401 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1402 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1403 | dBusEventLogEntryGet(asyncResp, entryId); |
| 1404 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1405 | |
| 1406 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1407 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1408 | .privileges(redfish::privileges::patchLogEntry) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1409 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1410 | [&app](const crow::Request& req, |
| 1411 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1412 | const std::string& systemName, const std::string& entryId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1413 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1414 | { |
| 1415 | return; |
| 1416 | } |
| 1417 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1418 | { |
| 1419 | // Option currently returns no systems. TBD |
| 1420 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1421 | systemName); |
| 1422 | return; |
| 1423 | } |
| 1424 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1425 | { |
| 1426 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1427 | systemName); |
| 1428 | return; |
| 1429 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1430 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1431 | dBusEventLogEntryPatch(req, asyncResp, entryId); |
| 1432 | }); |
Adriana Kobylak | 400fd1f | 2021-01-29 09:01:30 -0600 | [diff] [blame] | 1433 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1434 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1435 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Abhishek Patel | fff6a4d | 2021-07-21 11:29:45 -0500 | [diff] [blame] | 1436 | .privileges( |
| 1437 | redfish::privileges:: |
| 1438 | deleteLogEntrySubOverComputerSystemLogServiceCollectionLogServiceLogEntryCollection) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1439 | .methods(boost::beast::http::verb::delete_)( |
| 1440 | [&app](const crow::Request& req, |
| 1441 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1442 | const std::string& systemName, const std::string& param) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1443 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1444 | { |
| 1445 | return; |
| 1446 | } |
| 1447 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1448 | { |
| 1449 | // Option currently returns no systems. TBD |
| 1450 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1451 | systemName); |
| 1452 | return; |
| 1453 | } |
| 1454 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1455 | { |
| 1456 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1457 | systemName); |
| 1458 | return; |
| 1459 | } |
| 1460 | dBusEventLogEntryDelete(asyncResp, param); |
| 1461 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Claire Weinan | dd72e87 | 2022-08-15 14:20:06 -0700 | [diff] [blame] | 1464 | inline void handleBMCLogServicesCollectionGet( |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1465 | crow::App& app, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1466 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1467 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1468 | { |
| 1469 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1470 | { |
| 1471 | return; |
| 1472 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1473 | |
| 1474 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1475 | { |
| 1476 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1477 | return; |
| 1478 | } |
| 1479 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1480 | // Collections don't include the static data added by SubRoute |
| 1481 | // because it has a duplicate entry for members |
| 1482 | asyncResp->res.jsonValue["@odata.type"] = |
| 1483 | "#LogServiceCollection.LogServiceCollection"; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1484 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 1485 | "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1486 | asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; |
| 1487 | asyncResp->res.jsonValue["Description"] = |
| 1488 | "Collection of LogServices for this Manager"; |
| 1489 | nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; |
| 1490 | logServiceArray = nlohmann::json::array(); |
| 1491 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1492 | if constexpr (BMCWEB_REDFISH_BMC_JOURNAL) |
| 1493 | { |
| 1494 | nlohmann::json::object_t journal; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1495 | journal["@odata.id"] = |
| 1496 | boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal", |
| 1497 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1498 | logServiceArray.emplace_back(std::move(journal)); |
| 1499 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1500 | |
| 1501 | asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); |
| 1502 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1503 | if constexpr (BMCWEB_REDFISH_DUMP_LOG) |
| 1504 | { |
| 1505 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1506 | "xyz.openbmc_project.Collection.DeleteAll"}; |
| 1507 | dbus::utility::getSubTreePaths( |
| 1508 | "/xyz/openbmc_project/dump", 0, interfaces, |
| 1509 | [asyncResp](const boost::system::error_code& ec, |
| 1510 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 1511 | subTreePaths) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1512 | if (ec) |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1513 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1514 | BMCWEB_LOG_ERROR( |
| 1515 | "handleBMCLogServicesCollectionGet respHandler got error {}", |
| 1516 | ec); |
| 1517 | // Assume that getting an error simply means there are no |
| 1518 | // dump LogServices. Return without adding any error |
| 1519 | // response. |
| 1520 | return; |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1521 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1522 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1523 | nlohmann::json& logServiceArrayLocal = |
| 1524 | asyncResp->res.jsonValue["Members"]; |
| 1525 | |
| 1526 | for (const std::string& path : subTreePaths) |
| 1527 | { |
| 1528 | if (path == "/xyz/openbmc_project/dump/bmc") |
| 1529 | { |
| 1530 | nlohmann::json::object_t member; |
| 1531 | member["@odata.id"] = boost::urls::format( |
| 1532 | "/redfish/v1/Managers/{}/LogServices/Dump", |
| 1533 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 1534 | logServiceArrayLocal.emplace_back(std::move(member)); |
| 1535 | } |
| 1536 | else if (path == "/xyz/openbmc_project/dump/faultlog") |
| 1537 | { |
| 1538 | nlohmann::json::object_t member; |
| 1539 | member["@odata.id"] = boost::urls::format( |
| 1540 | "/redfish/v1/Managers/{}/LogServices/FaultLog", |
| 1541 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 1542 | logServiceArrayLocal.emplace_back(std::move(member)); |
| 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1547 | logServiceArrayLocal.size(); |
| 1548 | }); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1549 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1550 | } |
| 1551 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1552 | inline void requestRoutesBMCLogServiceCollection(App& app) |
| 1553 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1554 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/") |
Gunnar Mills | ad89dcf | 2021-07-30 14:40:11 -0500 | [diff] [blame] | 1555 | .privileges(redfish::privileges::getLogServiceCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1556 | .methods(boost::beast::http::verb::get)( |
Claire Weinan | dd72e87 | 2022-08-15 14:20:06 -0700 | [diff] [blame] | 1557 | std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1558 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 1559 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1560 | inline void getDumpServiceInfo( |
| 1561 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1562 | const std::string& dumpType) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1563 | { |
| 1564 | std::string dumpPath; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1565 | log_service::OverWritePolicy overWritePolicy = |
| 1566 | log_service::OverWritePolicy::Invalid; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1567 | bool collectDiagnosticDataSupported = false; |
| 1568 | |
| 1569 | if (dumpType == "BMC") |
| 1570 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1571 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump", |
| 1572 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1573 | overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1574 | collectDiagnosticDataSupported = true; |
| 1575 | } |
| 1576 | else if (dumpType == "FaultLog") |
| 1577 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1578 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog", |
| 1579 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1580 | overWritePolicy = log_service::OverWritePolicy::Unknown; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1581 | collectDiagnosticDataSupported = false; |
| 1582 | } |
| 1583 | else if (dumpType == "System") |
| 1584 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1585 | dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump", |
| 1586 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1587 | overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1588 | collectDiagnosticDataSupported = true; |
| 1589 | } |
| 1590 | else |
| 1591 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1592 | BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}", |
| 1593 | dumpType); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1594 | messages::internalError(asyncResp->res); |
| 1595 | return; |
| 1596 | } |
| 1597 | |
| 1598 | asyncResp->res.jsonValue["@odata.id"] = dumpPath; |
| 1599 | asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; |
| 1600 | asyncResp->res.jsonValue["Name"] = "Dump LogService"; |
| 1601 | asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; |
| 1602 | asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1603 | asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1604 | |
| 1605 | std::pair<std::string, std::string> redfishDateTimeOffset = |
Ed Tanous | 2b82937 | 2022-08-03 14:22:34 -0700 | [diff] [blame] | 1606 | redfish::time_utils::getDateTimeOffsetNow(); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1607 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 1608 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 1609 | redfishDateTimeOffset.second; |
| 1610 | |
| 1611 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1612 | |
| 1613 | if (collectDiagnosticDataSupported) |
| 1614 | { |
| 1615 | asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] |
| 1616 | ["target"] = |
| 1617 | dumpPath + "/Actions/LogService.CollectDiagnosticData"; |
| 1618 | } |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 1619 | |
| 1620 | constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface}; |
| 1621 | dbus::utility::getSubTreePaths( |
| 1622 | "/xyz/openbmc_project/dump", 0, interfaces, |
| 1623 | [asyncResp, dumpType, dumpPath]( |
| 1624 | const boost::system::error_code& ec, |
| 1625 | const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1626 | if (ec) |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 1627 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1628 | BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", |
| 1629 | ec); |
| 1630 | // Assume that getting an error simply means there are no dump |
| 1631 | // LogServices. Return without adding any error response. |
| 1632 | return; |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 1633 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1634 | std::string dbusDumpPath = getDumpPath(dumpType); |
| 1635 | for (const std::string& path : subTreePaths) |
| 1636 | { |
| 1637 | if (path == dbusDumpPath) |
| 1638 | { |
| 1639 | asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] |
| 1640 | ["target"] = |
| 1641 | dumpPath + "/Actions/LogService.ClearLog"; |
| 1642 | break; |
| 1643 | } |
| 1644 | } |
| 1645 | }); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | inline void handleLogServicesDumpServiceGet( |
| 1649 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1650 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1651 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1652 | { |
| 1653 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1654 | { |
| 1655 | return; |
| 1656 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1657 | |
| 1658 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1659 | { |
| 1660 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1661 | return; |
| 1662 | } |
| 1663 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1664 | getDumpServiceInfo(asyncResp, dumpType); |
| 1665 | } |
| 1666 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1667 | inline void handleLogServicesDumpServiceComputerSystemGet( |
| 1668 | crow::App& app, const crow::Request& req, |
| 1669 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1670 | const std::string& chassisId) |
| 1671 | { |
| 1672 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1673 | { |
| 1674 | return; |
| 1675 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1676 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1677 | { |
| 1678 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 1679 | return; |
| 1680 | } |
| 1681 | getDumpServiceInfo(asyncResp, "System"); |
| 1682 | } |
| 1683 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1684 | inline void handleLogServicesDumpEntriesCollectionGet( |
| 1685 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1686 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1687 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1688 | { |
| 1689 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1690 | { |
| 1691 | return; |
| 1692 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1693 | |
| 1694 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1695 | { |
| 1696 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1697 | return; |
| 1698 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1699 | getDumpEntryCollection(asyncResp, dumpType); |
| 1700 | } |
| 1701 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1702 | inline void handleLogServicesDumpEntriesCollectionComputerSystemGet( |
| 1703 | crow::App& app, const crow::Request& req, |
| 1704 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1705 | const std::string& chassisId) |
| 1706 | { |
| 1707 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1708 | { |
| 1709 | return; |
| 1710 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1711 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1712 | { |
| 1713 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 1714 | return; |
| 1715 | } |
| 1716 | getDumpEntryCollection(asyncResp, "System"); |
| 1717 | } |
| 1718 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1719 | inline void handleLogServicesDumpEntryGet( |
| 1720 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 1721 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1722 | const std::string& managerId, const std::string& dumpId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1723 | { |
| 1724 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1725 | { |
| 1726 | return; |
| 1727 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1728 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1729 | { |
| 1730 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1731 | return; |
| 1732 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1733 | getDumpEntryById(asyncResp, dumpId, dumpType); |
| 1734 | } |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1735 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1736 | inline void handleLogServicesDumpEntryComputerSystemGet( |
| 1737 | crow::App& app, const crow::Request& req, |
| 1738 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1739 | const std::string& chassisId, const std::string& dumpId) |
| 1740 | { |
| 1741 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1742 | { |
| 1743 | return; |
| 1744 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1745 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1746 | { |
| 1747 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 1748 | return; |
| 1749 | } |
| 1750 | getDumpEntryById(asyncResp, dumpId, "System"); |
| 1751 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1752 | |
| 1753 | inline void handleLogServicesDumpEntryDelete( |
| 1754 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 1755 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1756 | const std::string& managerId, const std::string& dumpId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1757 | { |
| 1758 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1759 | { |
| 1760 | return; |
| 1761 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1762 | |
| 1763 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1764 | { |
| 1765 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1766 | return; |
| 1767 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1768 | deleteDumpEntry(asyncResp, dumpId, dumpType); |
| 1769 | } |
| 1770 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1771 | inline void handleLogServicesDumpEntryComputerSystemDelete( |
| 1772 | crow::App& app, const crow::Request& req, |
| 1773 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1774 | const std::string& chassisId, const std::string& dumpId) |
| 1775 | { |
| 1776 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1777 | { |
| 1778 | return; |
| 1779 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1780 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1781 | { |
| 1782 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 1783 | return; |
| 1784 | } |
| 1785 | deleteDumpEntry(asyncResp, dumpId, "System"); |
| 1786 | } |
| 1787 | |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1788 | inline void handleLogServicesDumpEntryDownloadGet( |
| 1789 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 1790 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1791 | const std::string& managerId, const std::string& dumpId) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1792 | { |
| 1793 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1794 | { |
| 1795 | return; |
| 1796 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1797 | |
| 1798 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1799 | { |
| 1800 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1801 | return; |
| 1802 | } |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1803 | downloadDumpEntry(asyncResp, dumpId, dumpType); |
| 1804 | } |
| 1805 | |
| 1806 | inline void handleDBusEventLogEntryDownloadGet( |
| 1807 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 1808 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1809 | const std::string& systemName, const std::string& entryID) |
| 1810 | { |
| 1811 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1812 | { |
| 1813 | return; |
| 1814 | } |
| 1815 | if (!http_helpers::isContentTypeAllowed( |
| 1816 | req.getHeaderValue("Accept"), |
| 1817 | http_helpers::ContentType::OctetStream, true)) |
| 1818 | { |
| 1819 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 1820 | return; |
| 1821 | } |
| 1822 | downloadEventLogEntry(asyncResp, systemName, entryID, dumpType); |
| 1823 | } |
| 1824 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1825 | inline void handleLogServicesDumpCollectDiagnosticDataPost( |
| 1826 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1827 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1828 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1829 | { |
| 1830 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1831 | { |
| 1832 | return; |
| 1833 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1834 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1835 | { |
| 1836 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1837 | return; |
| 1838 | } |
| 1839 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1840 | createDump(asyncResp, req, dumpType); |
| 1841 | } |
| 1842 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1843 | inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost( |
| 1844 | crow::App& app, const crow::Request& req, |
| 1845 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1846 | const std::string& systemName) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1847 | { |
| 1848 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1849 | { |
| 1850 | return; |
| 1851 | } |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1852 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1853 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1854 | { |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1855 | // Option currently returns no systems. TBD |
| 1856 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1857 | systemName); |
| 1858 | return; |
| 1859 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1860 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1861 | { |
| 1862 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1863 | systemName); |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1864 | return; |
| 1865 | } |
| 1866 | createDump(asyncResp, req, "System"); |
| 1867 | } |
| 1868 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1869 | inline void handleLogServicesDumpClearLogPost( |
| 1870 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1871 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1872 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1873 | { |
| 1874 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1875 | { |
| 1876 | return; |
| 1877 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1878 | |
| 1879 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1880 | { |
| 1881 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1882 | return; |
| 1883 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1884 | clearDump(asyncResp, dumpType); |
| 1885 | } |
| 1886 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1887 | inline void handleLogServicesDumpClearLogComputerSystemPost( |
| 1888 | crow::App& app, const crow::Request& req, |
| 1889 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1890 | const std::string& systemName) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1891 | { |
| 1892 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1893 | { |
| 1894 | return; |
| 1895 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1896 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1897 | { |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1898 | // Option currently returns no systems. TBD |
| 1899 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1900 | systemName); |
| 1901 | return; |
| 1902 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1903 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1904 | { |
| 1905 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1906 | systemName); |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1907 | return; |
| 1908 | } |
| 1909 | clearDump(asyncResp, "System"); |
| 1910 | } |
| 1911 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1912 | inline void requestRoutesBMCDumpService(App& app) |
| 1913 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1914 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1915 | .privileges(redfish::privileges::getLogService) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1916 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1917 | handleLogServicesDumpServiceGet, std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | inline void requestRoutesBMCDumpEntryCollection(App& app) |
| 1921 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1922 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1923 | .privileges(redfish::privileges::getLogEntryCollection) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1924 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1925 | handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | inline void requestRoutesBMCDumpEntry(App& app) |
| 1929 | { |
| 1930 | BMCWEB_ROUTE(app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1931 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1932 | .privileges(redfish::privileges::getLogEntry) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1933 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1934 | handleLogServicesDumpEntryGet, std::ref(app), "BMC")); |
| 1935 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1936 | BMCWEB_ROUTE(app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1937 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1938 | .privileges(redfish::privileges::deleteLogEntry) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1939 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
| 1940 | handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1943 | inline void requestRoutesBMCDumpEntryDownload(App& app) |
| 1944 | { |
| 1945 | BMCWEB_ROUTE( |
| 1946 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1947 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/") |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1948 | .privileges(redfish::privileges::getLogEntry) |
| 1949 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1950 | handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC")); |
| 1951 | } |
| 1952 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1953 | inline void requestRoutesBMCDumpCreate(App& app) |
| 1954 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1955 | BMCWEB_ROUTE( |
| 1956 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1957 | "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1958 | .privileges(redfish::privileges::postLogService) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1959 | .methods(boost::beast::http::verb::post)( |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1960 | std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, |
| 1961 | std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | inline void requestRoutesBMCDumpClear(App& app) |
| 1965 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1966 | BMCWEB_ROUTE( |
| 1967 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1968 | "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1969 | .privileges(redfish::privileges::postLogService) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1970 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 1971 | handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); |
| 1972 | } |
| 1973 | |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1974 | inline void requestRoutesDBusEventLogEntryDownload(App& app) |
| 1975 | { |
| 1976 | BMCWEB_ROUTE( |
| 1977 | app, |
Ravi Teja | 9e9d99d | 2023-11-08 05:33:59 -0600 | [diff] [blame] | 1978 | "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/") |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1979 | .privileges(redfish::privileges::getLogEntry) |
| 1980 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1981 | handleDBusEventLogEntryDownloadGet, std::ref(app), "System")); |
| 1982 | } |
| 1983 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1984 | inline void requestRoutesFaultLogDumpService(App& app) |
| 1985 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1986 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1987 | .privileges(redfish::privileges::getLogService) |
| 1988 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1989 | handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); |
| 1990 | } |
| 1991 | |
| 1992 | inline void requestRoutesFaultLogDumpEntryCollection(App& app) |
| 1993 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1994 | BMCWEB_ROUTE(app, |
| 1995 | "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1996 | .privileges(redfish::privileges::getLogEntryCollection) |
| 1997 | .methods(boost::beast::http::verb::get)( |
| 1998 | std::bind_front(handleLogServicesDumpEntriesCollectionGet, |
| 1999 | std::ref(app), "FaultLog")); |
| 2000 | } |
| 2001 | |
| 2002 | inline void requestRoutesFaultLogDumpEntry(App& app) |
| 2003 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2004 | BMCWEB_ROUTE( |
| 2005 | app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2006 | .privileges(redfish::privileges::getLogEntry) |
| 2007 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2008 | handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); |
| 2009 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2010 | BMCWEB_ROUTE( |
| 2011 | app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2012 | .privileges(redfish::privileges::deleteLogEntry) |
| 2013 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
| 2014 | handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); |
| 2015 | } |
| 2016 | |
| 2017 | inline void requestRoutesFaultLogDumpClear(App& app) |
| 2018 | { |
| 2019 | BMCWEB_ROUTE( |
| 2020 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2021 | "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2022 | .privileges(redfish::privileges::postLogService) |
| 2023 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 2024 | handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | inline void requestRoutesSystemDumpService(App& app) |
| 2028 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2029 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2030 | .privileges(redfish::privileges::getLogService) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2031 | .methods(boost::beast::http::verb::get)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2032 | handleLogServicesDumpServiceComputerSystemGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | inline void requestRoutesSystemDumpEntryCollection(App& app) |
| 2036 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2037 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2038 | .privileges(redfish::privileges::getLogEntryCollection) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2039 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2040 | handleLogServicesDumpEntriesCollectionComputerSystemGet, |
| 2041 | std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | inline void requestRoutesSystemDumpEntry(App& app) |
| 2045 | { |
| 2046 | BMCWEB_ROUTE(app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2047 | "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2048 | .privileges(redfish::privileges::getLogEntry) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2049 | .methods(boost::beast::http::verb::get)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2050 | handleLogServicesDumpEntryComputerSystemGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2051 | |
| 2052 | BMCWEB_ROUTE(app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2053 | "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2054 | .privileges(redfish::privileges::deleteLogEntry) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2055 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2056 | handleLogServicesDumpEntryComputerSystemDelete, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | inline void requestRoutesSystemDumpCreate(App& app) |
| 2060 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2061 | BMCWEB_ROUTE( |
| 2062 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2063 | "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") |
Abhishek Patel | fff6a4d | 2021-07-21 11:29:45 -0500 | [diff] [blame] | 2064 | .privileges(redfish::privileges:: |
| 2065 | postLogServiceSubOverComputerSystemLogServiceCollection) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2066 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 2067 | handleLogServicesDumpCollectDiagnosticDataComputerSystemPost, |
| 2068 | std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | inline void requestRoutesSystemDumpClear(App& app) |
| 2072 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2073 | BMCWEB_ROUTE( |
| 2074 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2075 | "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/") |
Abhishek Patel | fff6a4d | 2021-07-21 11:29:45 -0500 | [diff] [blame] | 2076 | .privileges(redfish::privileges:: |
| 2077 | postLogServiceSubOverComputerSystemLogServiceCollection) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2078 | .methods(boost::beast::http::verb::post)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2079 | handleLogServicesDumpClearLogComputerSystemPost, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | inline void requestRoutesCrashdumpService(App& app) |
| 2083 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2084 | /** |
| 2085 | * Functions triggers appropriate requests on DBus |
| 2086 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2087 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/") |
Myung Bae | 50d9f38 | 2025-06-13 09:40:18 -0400 | [diff] [blame] | 2088 | .privileges(redfish::privileges::getLogService) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2089 | .methods( |
| 2090 | boost::beast::http::verb:: |
| 2091 | get)([&app](const crow::Request& req, |
| 2092 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2093 | const std::string& systemName) { |
| 2094 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2095 | { |
| 2096 | return; |
| 2097 | } |
| 2098 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2099 | { |
| 2100 | // Option currently returns no systems. TBD |
| 2101 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2102 | systemName); |
| 2103 | return; |
| 2104 | } |
| 2105 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2106 | { |
| 2107 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2108 | systemName); |
| 2109 | return; |
| 2110 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2111 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2112 | // Copy over the static data to include the entries added by |
| 2113 | // SubRoute |
| 2114 | asyncResp->res.jsonValue["@odata.id"] = |
| 2115 | std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", |
| 2116 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2117 | asyncResp->res.jsonValue["@odata.type"] = |
| 2118 | "#LogService.v1_2_0.LogService"; |
| 2119 | asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; |
| 2120 | asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; |
| 2121 | asyncResp->res.jsonValue["Id"] = "Crashdump"; |
| 2122 | asyncResp->res.jsonValue["OverWritePolicy"] = |
| 2123 | log_service::OverWritePolicy::WrapsWhenFull; |
| 2124 | asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 2125 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2126 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| 2127 | redfish::time_utils::getDateTimeOffsetNow(); |
| 2128 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 2129 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 2130 | redfishDateTimeOffset.second; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 2131 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2132 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format( |
| 2133 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", |
| 2134 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2135 | asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] |
| 2136 | ["target"] = std::format( |
| 2137 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog", |
| 2138 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2139 | asyncResp->res |
| 2140 | .jsonValue["Actions"]["#LogService.CollectDiagnosticData"] |
| 2141 | ["target"] = std::format( |
| 2142 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData", |
| 2143 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2144 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
Ed Tanous | 8e4736b | 2025-08-19 10:14:02 -0700 | [diff] [blame] | 2147 | inline void requestRoutesCrashdumpClear(App& app) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2148 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2149 | BMCWEB_ROUTE( |
| 2150 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2151 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/") |
Myung Bae | 50d9f38 | 2025-06-13 09:40:18 -0400 | [diff] [blame] | 2152 | .privileges(redfish::privileges:: |
| 2153 | postLogServiceSubOverComputerSystemLogServiceCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2154 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2155 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2156 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2157 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2158 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2159 | { |
| 2160 | return; |
| 2161 | } |
| 2162 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2163 | { |
| 2164 | // Option currently returns no systems. TBD |
| 2165 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2166 | systemName); |
| 2167 | return; |
| 2168 | } |
| 2169 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2170 | { |
| 2171 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2172 | systemName); |
| 2173 | return; |
| 2174 | } |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 2175 | dbus::utility::async_method_call( |
| 2176 | asyncResp, |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2177 | [asyncResp](const boost::system::error_code& ec, |
| 2178 | const std::string&) { |
| 2179 | if (ec) |
| 2180 | { |
| 2181 | messages::internalError(asyncResp->res); |
| 2182 | return; |
| 2183 | } |
| 2184 | messages::success(asyncResp->res); |
| 2185 | }, |
| 2186 | crashdumpObject, crashdumpPath, deleteAllInterface, |
| 2187 | "DeleteAll"); |
| 2188 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2189 | } |
Jason M. Bills | 5b61b5e | 2019-10-16 10:59:02 -0700 | [diff] [blame] | 2190 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2191 | inline void logCrashdumpEntry( |
| 2192 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2193 | const std::string& logID, nlohmann::json& logEntryJson) |
Jason M. Bills | e855dd2 | 2019-10-08 11:37:48 -0700 | [diff] [blame] | 2194 | { |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 2195 | auto getStoredLogCallback = |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 2196 | [asyncResp, logID, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 2197 | &logEntryJson](const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 2198 | const dbus::utility::DBusPropertiesMap& params) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2199 | if (ec) |
| 2200 | { |
| 2201 | BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message()); |
| 2202 | if (ec.value() == |
| 2203 | boost::system::linux_error::bad_request_descriptor) |
| 2204 | { |
| 2205 | messages::resourceNotFound(asyncResp->res, "LogEntry", |
| 2206 | logID); |
| 2207 | } |
| 2208 | else |
| 2209 | { |
| 2210 | messages::internalError(asyncResp->res); |
| 2211 | } |
| 2212 | return; |
| 2213 | } |
| 2214 | |
| 2215 | std::string timestamp{}; |
| 2216 | std::string filename{}; |
| 2217 | std::string logfile{}; |
| 2218 | parseCrashdumpParameters(params, filename, timestamp, logfile); |
| 2219 | |
| 2220 | if (filename.empty() || timestamp.empty()) |
Jason M. Bills | 1ddcf01 | 2019-11-26 14:59:21 -0800 | [diff] [blame] | 2221 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2222 | messages::resourceNotFound(asyncResp->res, "LogEntry", logID); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2223 | return; |
| 2224 | } |
| 2225 | |
| 2226 | std::string crashdumpURI = |
| 2227 | std::format( |
| 2228 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/", |
| 2229 | BMCWEB_REDFISH_SYSTEM_URI_NAME) + |
| 2230 | logID + "/" + filename; |
| 2231 | nlohmann::json::object_t logEntry; |
| 2232 | logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
| 2233 | logEntry["@odata.id"] = boost::urls::format( |
| 2234 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}", |
| 2235 | BMCWEB_REDFISH_SYSTEM_URI_NAME, logID); |
| 2236 | logEntry["Name"] = "CPU Crashdump"; |
| 2237 | logEntry["Id"] = logID; |
| 2238 | logEntry["EntryType"] = log_entry::LogEntryType::Oem; |
| 2239 | logEntry["AdditionalDataURI"] = std::move(crashdumpURI); |
| 2240 | logEntry["DiagnosticDataType"] = "OEM"; |
| 2241 | logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; |
| 2242 | logEntry["Created"] = std::move(timestamp); |
| 2243 | |
| 2244 | // If logEntryJson references an array of LogEntry resources |
| 2245 | // ('Members' list), then push this as a new entry, otherwise set it |
| 2246 | // directly |
| 2247 | if (logEntryJson.is_array()) |
| 2248 | { |
| 2249 | logEntryJson.push_back(logEntry); |
| 2250 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 2251 | logEntryJson.size(); |
Jason M. Bills | 2b20ef6 | 2022-01-06 15:48:07 -0800 | [diff] [blame] | 2252 | } |
| 2253 | else |
| 2254 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2255 | logEntryJson.update(logEntry); |
Jason M. Bills | 2b20ef6 | 2022-01-06 15:48:07 -0800 | [diff] [blame] | 2256 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2257 | }; |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2258 | dbus::utility::getAllProperties( |
| 2259 | crashdumpObject, crashdumpPath + std::string("/") + logID, |
| 2260 | crashdumpInterface, std::move(getStoredLogCallback)); |
Jason M. Bills | e855dd2 | 2019-10-08 11:37:48 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2263 | inline void requestRoutesCrashdumpEntryCollection(App& app) |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2264 | { |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2265 | /** |
| 2266 | * Functions triggers appropriate requests on DBus |
| 2267 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2268 | BMCWEB_ROUTE(app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2269 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/") |
Myung Bae | 50d9f38 | 2025-06-13 09:40:18 -0400 | [diff] [blame] | 2270 | .privileges(redfish::privileges::getLogEntryCollection) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2271 | .methods( |
| 2272 | boost::beast::http::verb:: |
| 2273 | get)([&app](const crow::Request& req, |
| 2274 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2275 | const std::string& systemName) { |
| 2276 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2277 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2278 | return; |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2279 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2280 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2281 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2282 | // Option currently returns no systems. TBD |
| 2283 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2284 | systemName); |
| 2285 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2286 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2287 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2288 | { |
| 2289 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2290 | systemName); |
| 2291 | return; |
| 2292 | } |
| 2293 | |
| 2294 | constexpr std::array<std::string_view, 1> interfaces = { |
| 2295 | crashdumpInterface}; |
| 2296 | dbus::utility::getSubTreePaths( |
| 2297 | "/", 0, interfaces, |
| 2298 | [asyncResp](const boost::system::error_code& ec, |
| 2299 | const std::vector<std::string>& resp) { |
| 2300 | if (ec) |
| 2301 | { |
| 2302 | if (ec.value() != |
| 2303 | boost::system::errc::no_such_file_or_directory) |
| 2304 | { |
| 2305 | BMCWEB_LOG_DEBUG("failed to get entries ec: {}", |
| 2306 | ec.message()); |
| 2307 | messages::internalError(asyncResp->res); |
| 2308 | return; |
| 2309 | } |
| 2310 | } |
| 2311 | asyncResp->res.jsonValue["@odata.type"] = |
| 2312 | "#LogEntryCollection.LogEntryCollection"; |
| 2313 | asyncResp->res.jsonValue["@odata.id"] = std::format( |
| 2314 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", |
| 2315 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2316 | asyncResp->res.jsonValue["Name"] = |
| 2317 | "Open BMC Crashdump Entries"; |
| 2318 | asyncResp->res.jsonValue["Description"] = |
| 2319 | "Collection of Crashdump Entries"; |
| 2320 | asyncResp->res.jsonValue["Members"] = |
| 2321 | nlohmann::json::array(); |
| 2322 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
| 2323 | |
| 2324 | for (const std::string& path : resp) |
| 2325 | { |
| 2326 | const sdbusplus::message::object_path objPath(path); |
| 2327 | // Get the log ID |
| 2328 | std::string logID = objPath.filename(); |
| 2329 | if (logID.empty()) |
| 2330 | { |
| 2331 | continue; |
| 2332 | } |
| 2333 | // Add the log entry to the array |
| 2334 | logCrashdumpEntry(asyncResp, logID, |
| 2335 | asyncResp->res.jsonValue["Members"]); |
| 2336 | } |
| 2337 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2338 | }); |
| 2339 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2340 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2341 | inline void requestRoutesCrashdumpEntry(App& app) |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2342 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2343 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2344 | app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/") |
Myung Bae | 50d9f38 | 2025-06-13 09:40:18 -0400 | [diff] [blame] | 2345 | .privileges(redfish::privileges::getLogEntry) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2346 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2347 | [&app](const crow::Request& req, |
| 2348 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2349 | const std::string& systemName, const std::string& param) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2350 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2351 | { |
| 2352 | return; |
| 2353 | } |
| 2354 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2355 | { |
| 2356 | // Option currently returns no systems. TBD |
| 2357 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2358 | systemName); |
| 2359 | return; |
| 2360 | } |
| 2361 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2362 | { |
| 2363 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2364 | systemName); |
| 2365 | return; |
| 2366 | } |
| 2367 | const std::string& logID = param; |
| 2368 | logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); |
| 2369 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2370 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2371 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2372 | inline void requestRoutesCrashdumpFile(App& app) |
| 2373 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2374 | BMCWEB_ROUTE( |
| 2375 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2376 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2377 | .privileges(redfish::privileges::getLogEntry) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2378 | .methods(boost::beast::http::verb::get)( |
Nan Zhou | a4ce114 | 2022-08-02 18:45:25 +0000 | [diff] [blame] | 2379 | [](const crow::Request& req, |
| 2380 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2381 | const std::string& systemName, const std::string& logID, |
| 2382 | const std::string& fileName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2383 | // Do not call getRedfishRoute here since the crashdump file is |
| 2384 | // not a Redfish resource. |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2385 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2386 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2387 | { |
| 2388 | // Option currently returns no systems. TBD |
| 2389 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2390 | systemName); |
| 2391 | return; |
| 2392 | } |
| 2393 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2394 | { |
| 2395 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2396 | systemName); |
| 2397 | return; |
| 2398 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2399 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2400 | auto getStoredLogCallback = |
| 2401 | [asyncResp, logID, fileName, |
| 2402 | url(boost::urls::url(req.url()))]( |
| 2403 | const boost::system::error_code& ec, |
| 2404 | const std::vector<std::pair< |
| 2405 | std::string, dbus::utility::DbusVariantType>>& |
| 2406 | resp) { |
| 2407 | if (ec) |
| 2408 | { |
| 2409 | BMCWEB_LOG_DEBUG("failed to get log ec: {}", |
| 2410 | ec.message()); |
| 2411 | messages::internalError(asyncResp->res); |
| 2412 | return; |
| 2413 | } |
Jason M. Bills | 8e6c099 | 2021-03-11 16:26:53 -0800 | [diff] [blame] | 2414 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2415 | std::string dbusFilename{}; |
| 2416 | std::string dbusTimestamp{}; |
| 2417 | std::string dbusFilepath{}; |
Jason M. Bills | 8e6c099 | 2021-03-11 16:26:53 -0800 | [diff] [blame] | 2418 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2419 | parseCrashdumpParameters(resp, dbusFilename, |
| 2420 | dbusTimestamp, dbusFilepath); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2421 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2422 | if (dbusFilename.empty() || dbusTimestamp.empty() || |
| 2423 | dbusFilepath.empty()) |
| 2424 | { |
| 2425 | messages::resourceNotFound(asyncResp->res, |
| 2426 | "LogEntry", logID); |
| 2427 | return; |
| 2428 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2429 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2430 | // Verify the file name parameter is correct |
| 2431 | if (fileName != dbusFilename) |
| 2432 | { |
| 2433 | messages::resourceNotFound(asyncResp->res, |
| 2434 | "LogEntry", logID); |
| 2435 | return; |
| 2436 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2437 | |
Myung Bae | d51c61b | 2024-09-13 10:35:34 -0500 | [diff] [blame] | 2438 | if (asyncResp->res.openFile(dbusFilepath) != |
| 2439 | crow::OpenCode::Success) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2440 | { |
| 2441 | messages::resourceNotFound(asyncResp->res, |
| 2442 | "LogEntry", logID); |
| 2443 | return; |
| 2444 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2445 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2446 | // Configure this to be a file download when accessed |
| 2447 | // from a browser |
| 2448 | asyncResp->res.addHeader( |
| 2449 | boost::beast::http::field::content_disposition, |
| 2450 | "attachment"); |
| 2451 | }; |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2452 | dbus::utility::getAllProperties( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2453 | *crow::connections::systemBus, crashdumpObject, |
| 2454 | crashdumpPath + std::string("/") + logID, |
| 2455 | crashdumpInterface, std::move(getStoredLogCallback)); |
| 2456 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
Jason M. Bills | c5a4c82 | 2022-01-06 15:51:23 -0800 | [diff] [blame] | 2459 | enum class OEMDiagnosticType |
| 2460 | { |
| 2461 | onDemand, |
| 2462 | telemetry, |
| 2463 | invalid, |
| 2464 | }; |
| 2465 | |
Ed Tanous | 26ccae3 | 2023-02-16 10:28:44 -0800 | [diff] [blame] | 2466 | inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr) |
Jason M. Bills | c5a4c82 | 2022-01-06 15:51:23 -0800 | [diff] [blame] | 2467 | { |
| 2468 | if (oemDiagStr == "OnDemand") |
| 2469 | { |
| 2470 | return OEMDiagnosticType::onDemand; |
| 2471 | } |
| 2472 | if (oemDiagStr == "Telemetry") |
| 2473 | { |
| 2474 | return OEMDiagnosticType::telemetry; |
| 2475 | } |
| 2476 | |
| 2477 | return OEMDiagnosticType::invalid; |
| 2478 | } |
| 2479 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2480 | inline void requestRoutesCrashdumpCollect(App& app) |
| 2481 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2482 | BMCWEB_ROUTE( |
| 2483 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2484 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") |
Myung Bae | 50d9f38 | 2025-06-13 09:40:18 -0400 | [diff] [blame] | 2485 | .privileges(redfish::privileges:: |
| 2486 | postLogServiceSubOverComputerSystemLogServiceCollection) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2487 | .methods(boost::beast::http::verb::post)( |
| 2488 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2489 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2490 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2491 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2492 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2493 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2494 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2495 | |
| 2496 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2497 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2498 | // Option currently returns no systems. TBD |
| 2499 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2500 | systemName); |
| 2501 | return; |
| 2502 | } |
| 2503 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2504 | { |
| 2505 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2506 | systemName); |
| 2507 | return; |
| 2508 | } |
| 2509 | |
| 2510 | std::string diagnosticDataType; |
| 2511 | std::string oemDiagnosticDataType; |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2512 | if (!redfish::json_util::readJsonAction( // |
| 2513 | req, asyncResp->res, // |
| 2514 | "DiagnosticDataType", diagnosticDataType, // |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 2515 | "OEMDiagnosticDataType", oemDiagnosticDataType // |
| 2516 | )) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2517 | { |
| 2518 | return; |
| 2519 | } |
| 2520 | |
| 2521 | if (diagnosticDataType != "OEM") |
| 2522 | { |
| 2523 | BMCWEB_LOG_ERROR( |
| 2524 | "Only OEM DiagnosticDataType supported for Crashdump"); |
| 2525 | messages::actionParameterValueFormatError( |
| 2526 | asyncResp->res, diagnosticDataType, |
| 2527 | "DiagnosticDataType", "CollectDiagnosticData"); |
| 2528 | return; |
| 2529 | } |
| 2530 | |
| 2531 | OEMDiagnosticType oemDiagType = |
| 2532 | getOEMDiagnosticType(oemDiagnosticDataType); |
| 2533 | |
| 2534 | std::string iface; |
| 2535 | std::string method; |
| 2536 | std::string taskMatchStr; |
| 2537 | if (oemDiagType == OEMDiagnosticType::onDemand) |
| 2538 | { |
| 2539 | iface = crashdumpOnDemandInterface; |
| 2540 | method = "GenerateOnDemandLog"; |
| 2541 | taskMatchStr = |
| 2542 | "type='signal'," |
| 2543 | "interface='org.freedesktop.DBus.Properties'," |
| 2544 | "member='PropertiesChanged'," |
| 2545 | "arg0namespace='com.intel.crashdump'"; |
| 2546 | } |
| 2547 | else if (oemDiagType == OEMDiagnosticType::telemetry) |
| 2548 | { |
| 2549 | iface = crashdumpTelemetryInterface; |
| 2550 | method = "GenerateTelemetryLog"; |
| 2551 | taskMatchStr = |
| 2552 | "type='signal'," |
| 2553 | "interface='org.freedesktop.DBus.Properties'," |
| 2554 | "member='PropertiesChanged'," |
| 2555 | "arg0namespace='com.intel.crashdump'"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2556 | } |
| 2557 | else |
| 2558 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2559 | BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}", |
| 2560 | oemDiagnosticDataType); |
| 2561 | messages::actionParameterValueFormatError( |
| 2562 | asyncResp->res, oemDiagnosticDataType, |
| 2563 | "OEMDiagnosticDataType", "CollectDiagnosticData"); |
| 2564 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2565 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2566 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2567 | auto collectCrashdumpCallback = |
| 2568 | [asyncResp, payload(task::Payload(req)), |
| 2569 | taskMatchStr](const boost::system::error_code& ec, |
| 2570 | const std::string&) mutable { |
| 2571 | if (ec) |
| 2572 | { |
| 2573 | if (ec.value() == |
| 2574 | boost::system::errc::operation_not_supported) |
| 2575 | { |
| 2576 | messages::resourceInStandby(asyncResp->res); |
| 2577 | } |
| 2578 | else if (ec.value() == boost::system::errc:: |
| 2579 | device_or_resource_busy) |
| 2580 | { |
| 2581 | messages::serviceTemporarilyUnavailable( |
| 2582 | asyncResp->res, "60"); |
| 2583 | } |
| 2584 | else |
| 2585 | { |
| 2586 | messages::internalError(asyncResp->res); |
| 2587 | } |
| 2588 | return; |
| 2589 | } |
| 2590 | std::shared_ptr<task::TaskData> task = |
| 2591 | task::TaskData::createTask( |
| 2592 | [](const boost::system::error_code& ec2, |
| 2593 | sdbusplus::message_t&, |
| 2594 | const std::shared_ptr<task::TaskData>& |
| 2595 | taskData) { |
| 2596 | if (!ec2) |
| 2597 | { |
| 2598 | taskData->messages.emplace_back( |
| 2599 | messages::taskCompletedOK( |
| 2600 | std::to_string( |
| 2601 | taskData->index))); |
| 2602 | taskData->state = "Completed"; |
| 2603 | } |
| 2604 | return task::completed; |
| 2605 | }, |
| 2606 | taskMatchStr); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2607 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2608 | task->startTimer(std::chrono::minutes(5)); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2609 | task->payload.emplace(std::move(payload)); |
Chinmay Shripad Hegde | 29e2bdd | 2025-06-06 16:23:47 +0530 | [diff] [blame] | 2610 | task->populateResp(asyncResp->res); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2611 | }; |
| 2612 | |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 2613 | dbus::utility::async_method_call( |
| 2614 | asyncResp, std::move(collectCrashdumpCallback), |
| 2615 | crashdumpObject, crashdumpPath, iface, method); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2616 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2617 | } |
Kenny L. Ku | 6eda768 | 2020-06-19 09:48:36 -0700 | [diff] [blame] | 2618 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 2619 | inline void dBusLogServiceActionsClear( |
| 2620 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 2621 | { |
| 2622 | BMCWEB_LOG_DEBUG("Do delete all entries."); |
| 2623 | |
| 2624 | // Process response from Logging service. |
| 2625 | auto respHandler = [asyncResp](const boost::system::error_code& ec) { |
| 2626 | BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done"); |
| 2627 | if (ec) |
| 2628 | { |
| 2629 | // TODO Handle for specific error code |
| 2630 | BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec); |
| 2631 | asyncResp->res.result( |
| 2632 | boost::beast::http::status::internal_server_error); |
| 2633 | return; |
| 2634 | } |
| 2635 | |
Amy Chang | e246046 | 2025-05-06 00:10:13 -0700 | [diff] [blame] | 2636 | messages::success(asyncResp->res); |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 2637 | }; |
| 2638 | |
| 2639 | // Make call to Logging service to request Clear Log |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 2640 | dbus::utility::async_method_call( |
| 2641 | asyncResp, respHandler, "xyz.openbmc_project.Logging", |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 2642 | "/xyz/openbmc_project/logging", |
| 2643 | "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); |
| 2644 | } |
| 2645 | |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 2646 | /** |
| 2647 | * DBusLogServiceActionsClear class supports POST method for ClearLog action. |
| 2648 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2649 | inline void requestRoutesDBusLogServiceActionsClear(App& app) |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 2650 | { |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 2651 | /** |
| 2652 | * Function handles POST method request. |
| 2653 | * The Clear Log actions does not require any parameter.The action deletes |
| 2654 | * all entries found in the Entries collection for this Log Service. |
| 2655 | */ |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 2656 | |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2657 | BMCWEB_ROUTE( |
| 2658 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2659 | "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") |
Abhishek Patel | fff6a4d | 2021-07-21 11:29:45 -0500 | [diff] [blame] | 2660 | .privileges(redfish::privileges:: |
| 2661 | postLogServiceSubOverComputerSystemLogServiceCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2662 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2663 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2664 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2665 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2666 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2667 | { |
| 2668 | return; |
| 2669 | } |
| 2670 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2671 | { |
| 2672 | // Option currently returns no systems. TBD |
| 2673 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2674 | systemName); |
| 2675 | return; |
| 2676 | } |
| 2677 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2678 | { |
| 2679 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2680 | systemName); |
| 2681 | return; |
| 2682 | } |
| 2683 | dBusLogServiceActionsClear(asyncResp); |
| 2684 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2685 | } |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 2686 | |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2687 | } // namespace redfish |