| 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" |
| Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 18 | #include "human_sort.hpp" |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 19 | #include "logging.hpp" |
| Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 20 | #include "query.hpp" |
| Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 21 | #include "registries/privilege_registry.hpp" |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 22 | #include "str_utility.hpp" |
| James Feist | 4622957 | 2020-02-19 15:11:58 -0800 | [diff] [blame] | 23 | #include "task.hpp" |
| Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 24 | #include "task_messages.hpp" |
| Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 25 | #include "utils/dbus_utils.hpp" |
| Corey Ethington | 08fad5d | 2025-07-31 12:14:27 -0400 | [diff] [blame] | 26 | #include "utils/etag_utils.hpp" |
| Oliver Brewka | 9d6459e | 2025-08-27 13:39:15 +0200 | [diff] [blame] | 27 | #include "utils/eventlog_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 | |
| Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 85 | inline std::string getDumpPath(std::string_view dumpType) |
| 86 | { |
| 87 | std::string dbusDumpPath = "/xyz/openbmc_project/dump/"; |
| 88 | std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath), |
| 89 | bmcweb::asciiToLower); |
| 90 | |
| 91 | return dbusDumpPath; |
| 92 | } |
| 93 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 94 | inline log_entry::OriginatorTypes mapDbusOriginatorTypeToRedfish( |
| 95 | const std::string& originatorType) |
| Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 96 | { |
| 97 | if (originatorType == |
| 98 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client") |
| 99 | { |
| 100 | return log_entry::OriginatorTypes::Client; |
| 101 | } |
| 102 | if (originatorType == |
| 103 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal") |
| 104 | { |
| 105 | return log_entry::OriginatorTypes::Internal; |
| 106 | } |
| 107 | if (originatorType == |
| 108 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService") |
| 109 | { |
| 110 | return log_entry::OriginatorTypes::SupportingService; |
| 111 | } |
| 112 | return log_entry::OriginatorTypes::Invalid; |
| 113 | } |
| 114 | |
| Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 115 | inline void parseDumpEntryFromDbusObject( |
| Jiaqing Zhao | 2d613eb | 2022-08-15 16:03:00 +0800 | [diff] [blame] | 116 | const dbus::utility::ManagedObjectType::value_type& object, |
| Claire Weinan | c6fecda | 2022-07-15 10:43:25 -0700 | [diff] [blame] | 117 | std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs, |
| Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 118 | std::string& originatorId, log_entry::OriginatorTypes& originatorType, |
| Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 119 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 120 | { |
| 121 | for (const auto& interfaceMap : object.second) |
| 122 | { |
| 123 | if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") |
| 124 | { |
| 125 | for (const auto& propertyMap : interfaceMap.second) |
| 126 | { |
| 127 | if (propertyMap.first == "Status") |
| 128 | { |
| 129 | const auto* status = |
| 130 | std::get_if<std::string>(&propertyMap.second); |
| 131 | if (status == nullptr) |
| 132 | { |
| 133 | messages::internalError(asyncResp->res); |
| 134 | break; |
| 135 | } |
| 136 | dumpStatus = *status; |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") |
| 141 | { |
| 142 | for (const auto& propertyMap : interfaceMap.second) |
| 143 | { |
| 144 | if (propertyMap.first == "Size") |
| 145 | { |
| 146 | const auto* sizePtr = |
| 147 | std::get_if<uint64_t>(&propertyMap.second); |
| 148 | if (sizePtr == nullptr) |
| 149 | { |
| 150 | messages::internalError(asyncResp->res); |
| 151 | break; |
| 152 | } |
| 153 | size = *sizePtr; |
| 154 | break; |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") |
| 159 | { |
| 160 | for (const auto& propertyMap : interfaceMap.second) |
| 161 | { |
| 162 | if (propertyMap.first == "Elapsed") |
| 163 | { |
| 164 | const uint64_t* usecsTimeStamp = |
| 165 | std::get_if<uint64_t>(&propertyMap.second); |
| 166 | if (usecsTimeStamp == nullptr) |
| 167 | { |
| 168 | messages::internalError(asyncResp->res); |
| 169 | break; |
| 170 | } |
| Claire Weinan | c6fecda | 2022-07-15 10:43:25 -0700 | [diff] [blame] | 171 | timestampUs = *usecsTimeStamp; |
| Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 172 | break; |
| 173 | } |
| 174 | } |
| 175 | } |
| Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 176 | else if (interfaceMap.first == |
| 177 | "xyz.openbmc_project.Common.OriginatedBy") |
| 178 | { |
| 179 | for (const auto& propertyMap : interfaceMap.second) |
| 180 | { |
| 181 | if (propertyMap.first == "OriginatorId") |
| 182 | { |
| 183 | const std::string* id = |
| 184 | std::get_if<std::string>(&propertyMap.second); |
| 185 | if (id == nullptr) |
| 186 | { |
| 187 | messages::internalError(asyncResp->res); |
| 188 | break; |
| 189 | } |
| 190 | originatorId = *id; |
| 191 | } |
| 192 | |
| 193 | if (propertyMap.first == "OriginatorType") |
| 194 | { |
| 195 | const std::string* type = |
| 196 | std::get_if<std::string>(&propertyMap.second); |
| 197 | if (type == nullptr) |
| 198 | { |
| 199 | messages::internalError(asyncResp->res); |
| 200 | break; |
| 201 | } |
| 202 | |
| 203 | originatorType = mapDbusOriginatorTypeToRedfish(*type); |
| 204 | if (originatorType == log_entry::OriginatorTypes::Invalid) |
| 205 | { |
| 206 | messages::internalError(asyncResp->res); |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | } |
| Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
| Nan Zhou | 21ab404 | 2022-06-26 23:07:40 +0000 | [diff] [blame] | 215 | static std::string getDumpEntriesPath(const std::string& dumpType) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 216 | { |
| 217 | std::string entriesPath; |
| 218 | |
| 219 | if (dumpType == "BMC") |
| 220 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 221 | entriesPath = |
| 222 | std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/", |
| 223 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 224 | } |
| 225 | else if (dumpType == "FaultLog") |
| 226 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 227 | entriesPath = |
| 228 | std::format("/redfish/v1/Managers/{}/LogServices/FaultLog/Entries/", |
| 229 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 230 | } |
| 231 | else if (dumpType == "System") |
| 232 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 233 | entriesPath = |
| 234 | std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/", |
| 235 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 236 | } |
| 237 | else |
| 238 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 239 | BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}", |
| 240 | dumpType); |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | // Returns empty string on error |
| 244 | return entriesPath; |
| 245 | } |
| 246 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 247 | inline void getDumpEntryCollection( |
| 248 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 249 | const std::string& dumpType) |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 250 | { |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 251 | std::string entriesPath = getDumpEntriesPath(dumpType); |
| 252 | if (entriesPath.empty()) |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 253 | { |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 254 | messages::internalError(asyncResp->res); |
| 255 | return; |
| 256 | } |
| 257 | |
| George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 258 | sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); |
| 259 | dbus::utility::getManagedObjects( |
| 260 | "xyz.openbmc_project.Dump.Manager", path, |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 261 | [asyncResp, entriesPath, |
| Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 262 | dumpType](const boost::system::error_code& ec, |
| George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 263 | const dbus::utility::ManagedObjectType& objects) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 264 | if (ec) |
| 265 | { |
| 266 | BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec); |
| 267 | messages::internalError(asyncResp->res); |
| 268 | return; |
| 269 | } |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 270 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 271 | // Remove ending slash |
| 272 | std::string odataIdStr = entriesPath; |
| 273 | if (!odataIdStr.empty()) |
| 274 | { |
| 275 | odataIdStr.pop_back(); |
| 276 | } |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 277 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 278 | asyncResp->res.jsonValue["@odata.type"] = |
| 279 | "#LogEntryCollection.LogEntryCollection"; |
| 280 | asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr); |
| 281 | asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries"; |
| 282 | asyncResp->res.jsonValue["Description"] = |
| 283 | "Collection of " + dumpType + " Dump Entries"; |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 284 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 285 | nlohmann::json::array_t entriesArray; |
| 286 | std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/"; |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 287 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 288 | dbus::utility::ManagedObjectType resp(objects); |
| 289 | std::ranges::sort(resp, [](const auto& l, const auto& r) { |
| 290 | return AlphanumLess<std::string>()(l.first.filename(), |
| 291 | r.first.filename()); |
| 292 | }); |
| 293 | |
| 294 | for (auto& object : resp) |
| 295 | { |
| 296 | if (object.first.str.find(dumpEntryPath) == std::string::npos) |
| 297 | { |
| 298 | continue; |
| 299 | } |
| 300 | uint64_t timestampUs = 0; |
| 301 | uint64_t size = 0; |
| 302 | std::string dumpStatus; |
| 303 | std::string originatorId; |
| 304 | log_entry::OriginatorTypes originatorType = |
| 305 | log_entry::OriginatorTypes::Internal; |
| 306 | nlohmann::json::object_t thisEntry; |
| 307 | |
| 308 | std::string entryID = object.first.filename(); |
| 309 | if (entryID.empty()) |
| 310 | { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | parseDumpEntryFromDbusObject(object, dumpStatus, size, |
| 315 | timestampUs, originatorId, |
| 316 | originatorType, asyncResp); |
| 317 | |
| 318 | if (dumpStatus != |
| 319 | "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && |
| 320 | !dumpStatus.empty()) |
| 321 | { |
| 322 | // Dump status is not Complete, no need to enumerate |
| 323 | continue; |
| 324 | } |
| 325 | |
| 326 | thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry"; |
| 327 | thisEntry["@odata.id"] = entriesPath + entryID; |
| 328 | thisEntry["Id"] = entryID; |
| 329 | thisEntry["EntryType"] = "Event"; |
| 330 | thisEntry["Name"] = dumpType + " Dump Entry"; |
| 331 | thisEntry["Created"] = |
| 332 | redfish::time_utils::getDateTimeUintUs(timestampUs); |
| 333 | |
| 334 | if (!originatorId.empty()) |
| 335 | { |
| 336 | thisEntry["Originator"] = originatorId; |
| 337 | thisEntry["OriginatorType"] = originatorType; |
| 338 | } |
| 339 | |
| 340 | if (dumpType == "BMC") |
| 341 | { |
| 342 | thisEntry["DiagnosticDataType"] = "Manager"; |
| 343 | thisEntry["AdditionalDataURI"] = |
| 344 | entriesPath + entryID + "/attachment"; |
| 345 | thisEntry["AdditionalDataSizeBytes"] = size; |
| 346 | } |
| 347 | else if (dumpType == "System") |
| 348 | { |
| 349 | thisEntry["DiagnosticDataType"] = "OEM"; |
| 350 | thisEntry["OEMDiagnosticDataType"] = "System"; |
| 351 | thisEntry["AdditionalDataURI"] = |
| 352 | entriesPath + entryID + "/attachment"; |
| 353 | thisEntry["AdditionalDataSizeBytes"] = size; |
| 354 | } |
| 355 | entriesArray.emplace_back(std::move(thisEntry)); |
| 356 | } |
| 357 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 358 | entriesArray.size(); |
| 359 | asyncResp->res.jsonValue["Members"] = std::move(entriesArray); |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 360 | }); |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 361 | } |
| 362 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 363 | inline void getDumpEntryById( |
| 364 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 365 | const std::string& entryID, const std::string& dumpType) |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 366 | { |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 367 | std::string entriesPath = getDumpEntriesPath(dumpType); |
| 368 | if (entriesPath.empty()) |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 369 | { |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 370 | messages::internalError(asyncResp->res); |
| 371 | return; |
| 372 | } |
| 373 | |
| George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 374 | sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); |
| 375 | dbus::utility::getManagedObjects( |
| 376 | "xyz.openbmc_project.Dump.Manager", path, |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 377 | [asyncResp, entryID, dumpType, |
| Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 378 | entriesPath](const boost::system::error_code& ec, |
| Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 379 | const dbus::utility::ManagedObjectType& resp) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 380 | if (ec) |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 381 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 382 | BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec); |
| 383 | messages::internalError(asyncResp->res); |
| 384 | return; |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 387 | bool foundDumpEntry = false; |
| 388 | std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/"; |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 389 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 390 | for (const auto& objectPath : resp) |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 391 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 392 | if (objectPath.first.str != dumpEntryPath + entryID) |
| 393 | { |
| 394 | continue; |
| 395 | } |
| 396 | |
| 397 | foundDumpEntry = true; |
| 398 | uint64_t timestampUs = 0; |
| 399 | uint64_t size = 0; |
| 400 | std::string dumpStatus; |
| 401 | std::string originatorId; |
| 402 | log_entry::OriginatorTypes originatorType = |
| 403 | log_entry::OriginatorTypes::Internal; |
| 404 | |
| 405 | parseDumpEntryFromDbusObject(objectPath, dumpStatus, size, |
| 406 | timestampUs, originatorId, |
| 407 | originatorType, asyncResp); |
| 408 | |
| 409 | if (dumpStatus != |
| 410 | "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && |
| 411 | !dumpStatus.empty()) |
| 412 | { |
| 413 | // Dump status is not Complete |
| 414 | // return not found until status is changed to Completed |
| 415 | messages::resourceNotFound(asyncResp->res, |
| 416 | dumpType + " dump", entryID); |
| 417 | return; |
| 418 | } |
| 419 | |
| 420 | asyncResp->res.jsonValue["@odata.type"] = |
| 421 | "#LogEntry.v1_11_0.LogEntry"; |
| 422 | asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID; |
| 423 | asyncResp->res.jsonValue["Id"] = entryID; |
| 424 | asyncResp->res.jsonValue["EntryType"] = "Event"; |
| 425 | asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; |
| 426 | asyncResp->res.jsonValue["Created"] = |
| 427 | redfish::time_utils::getDateTimeUintUs(timestampUs); |
| 428 | |
| 429 | if (!originatorId.empty()) |
| 430 | { |
| 431 | asyncResp->res.jsonValue["Originator"] = originatorId; |
| 432 | asyncResp->res.jsonValue["OriginatorType"] = originatorType; |
| 433 | } |
| 434 | |
| 435 | if (dumpType == "BMC") |
| 436 | { |
| 437 | asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; |
| 438 | asyncResp->res.jsonValue["AdditionalDataURI"] = |
| 439 | entriesPath + entryID + "/attachment"; |
| 440 | asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; |
| 441 | } |
| 442 | else if (dumpType == "System") |
| 443 | { |
| 444 | asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; |
| 445 | asyncResp->res.jsonValue["OEMDiagnosticDataType"] = |
| 446 | "System"; |
| 447 | asyncResp->res.jsonValue["AdditionalDataURI"] = |
| 448 | entriesPath + entryID + "/attachment"; |
| 449 | asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; |
| 450 | } |
| 451 | } |
| 452 | if (!foundDumpEntry) |
| 453 | { |
| 454 | BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID); |
| Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 455 | messages::resourceNotFound(asyncResp->res, dumpType + " dump", |
| 456 | entryID); |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 457 | return; |
| 458 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 459 | }); |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 460 | } |
| 461 | |
| zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 462 | inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Stanley Chu | 9878256 | 2020-11-04 16:10:24 +0800 | [diff] [blame] | 463 | const std::string& entryID, |
| Asmitha Karunanithi | b47452b | 2020-09-25 02:02:19 -0500 | [diff] [blame] | 464 | const std::string& dumpType) |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 465 | { |
| Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 466 | auto respHandler = [asyncResp, |
| 467 | entryID](const boost::system::error_code& ec) { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 468 | BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done"); |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 469 | if (ec) |
| 470 | { |
| George Liu | 3de8d8b | 2021-03-22 17:49:39 +0800 | [diff] [blame] | 471 | if (ec.value() == EBADR) |
| 472 | { |
| 473 | messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); |
| 474 | return; |
| 475 | } |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 476 | BMCWEB_LOG_ERROR( |
| 477 | "Dump (DBus) doDelete respHandler got error {} entryID={}", ec, |
| 478 | entryID); |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 479 | messages::internalError(asyncResp->res); |
| 480 | return; |
| 481 | } |
| 482 | }; |
| Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 483 | |
| Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 484 | dbus::utility::async_method_call( |
| 485 | asyncResp, respHandler, "xyz.openbmc_project.Dump.Manager", |
| Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 486 | std::format("{}/entry/{}", getDumpPath(dumpType), entryID), |
| Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 487 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 488 | } |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 489 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 490 | inline void downloadDumpEntry( |
| 491 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 492 | const std::string& entryID, const std::string& dumpType) |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 493 | { |
| 494 | if (dumpType != "BMC") |
| 495 | { |
| 496 | BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID); |
| 497 | messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID); |
| 498 | return; |
| 499 | } |
| 500 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 501 | std::string dumpEntryPath = |
| 502 | std::format("{}/entry/{}", getDumpPath(dumpType), entryID); |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 503 | |
| 504 | auto downloadDumpEntryHandler = |
| 505 | [asyncResp, entryID, |
| 506 | dumpType](const boost::system::error_code& ec, |
| 507 | const sdbusplus::message::unix_fd& unixfd) { |
| Oliver Brewka | ff35df9 | 2025-08-26 08:21:30 +0200 | [diff] [blame] | 508 | log_services_utils::downloadEntryCallback(asyncResp, entryID, |
| 509 | dumpType, ec, unixfd); |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 510 | }; |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 511 | |
| Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 512 | dbus::utility::async_method_call( |
| 513 | asyncResp, std::move(downloadDumpEntryHandler), |
| 514 | "xyz.openbmc_project.Dump.Manager", dumpEntryPath, |
| 515 | "xyz.openbmc_project.Dump.Entry", "GetFileHandle"); |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 518 | inline DumpCreationProgress mapDbusStatusToDumpProgress( |
| 519 | const std::string& status) |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 520 | { |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 521 | if (status == |
| 522 | "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" || |
| 523 | status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted") |
| 524 | { |
| 525 | return DumpCreationProgress::DUMP_CREATE_FAILED; |
| 526 | } |
| 527 | if (status == |
| 528 | "xyz.openbmc_project.Common.Progress.OperationStatus.Completed") |
| 529 | { |
| 530 | return DumpCreationProgress::DUMP_CREATE_SUCCESS; |
| 531 | } |
| 532 | return DumpCreationProgress::DUMP_CREATE_INPROGRESS; |
| 533 | } |
| 534 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 535 | inline DumpCreationProgress getDumpCompletionStatus( |
| 536 | const dbus::utility::DBusPropertiesMap& values) |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 537 | { |
| 538 | for (const auto& [key, val] : values) |
| 539 | { |
| 540 | if (key == "Status") |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 541 | { |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 542 | const std::string* value = std::get_if<std::string>(&val); |
| 543 | if (value == nullptr) |
| 544 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 545 | BMCWEB_LOG_ERROR("Status property value is null"); |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 546 | return DumpCreationProgress::DUMP_CREATE_FAILED; |
| 547 | } |
| 548 | return mapDbusStatusToDumpProgress(*value); |
| 549 | } |
| 550 | } |
| 551 | return DumpCreationProgress::DUMP_CREATE_INPROGRESS; |
| 552 | } |
| 553 | |
| 554 | inline std::string getDumpEntryPath(const std::string& dumpPath) |
| 555 | { |
| 556 | if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry") |
| 557 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 558 | return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/", |
| Ed Tanous | 9f56509 | 2024-07-12 22:06:53 -0700 | [diff] [blame] | 559 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 560 | } |
| 561 | if (dumpPath == "/xyz/openbmc_project/dump/system/entry") |
| 562 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 563 | return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/", |
| 564 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 565 | } |
| 566 | return ""; |
| 567 | } |
| 568 | |
| 569 | inline void createDumpTaskCallback( |
| 570 | task::Payload&& payload, |
| 571 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 572 | const sdbusplus::message::object_path& createdObjPath) |
| 573 | { |
| 574 | const std::string dumpPath = createdObjPath.parent_path().str; |
| 575 | const std::string dumpId = createdObjPath.filename(); |
| 576 | |
| 577 | std::string dumpEntryPath = getDumpEntryPath(dumpPath); |
| 578 | |
| 579 | if (dumpEntryPath.empty()) |
| 580 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 581 | BMCWEB_LOG_ERROR("Invalid dump type received"); |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 582 | messages::internalError(asyncResp->res); |
| 583 | return; |
| 584 | } |
| 585 | |
| Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 586 | dbus::utility::async_method_call( |
| 587 | asyncResp, |
| Ed Tanous | 8cb2c02 | 2024-03-27 16:31:46 -0700 | [diff] [blame] | 588 | [asyncResp, payload = std::move(payload), createdObjPath, |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 589 | dumpEntryPath{std::move(dumpEntryPath)}, |
| Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 590 | dumpId](const boost::system::error_code& ec, |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 591 | const std::string& introspectXml) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 592 | if (ec) |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 593 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 594 | BMCWEB_LOG_ERROR("Introspect call failed with error: {}", |
| 595 | ec.message()); |
| 596 | messages::internalError(asyncResp->res); |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | // Check if the created dump object has implemented Progress |
| 601 | // interface to track dump completion. If yes, fetch the "Status" |
| 602 | // property of the interface, modify the task state accordingly. |
| 603 | // Else, return task completed. |
| 604 | tinyxml2::XMLDocument doc; |
| 605 | |
| 606 | doc.Parse(introspectXml.data(), introspectXml.size()); |
| 607 | tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node"); |
| 608 | if (pRoot == nullptr) |
| 609 | { |
| 610 | BMCWEB_LOG_ERROR("XML document failed to parse"); |
| 611 | messages::internalError(asyncResp->res); |
| 612 | return; |
| 613 | } |
| 614 | tinyxml2::XMLElement* interfaceNode = |
| 615 | pRoot->FirstChildElement("interface"); |
| 616 | |
| 617 | bool isProgressIntfPresent = false; |
| 618 | while (interfaceNode != nullptr) |
| 619 | { |
| 620 | const char* thisInterfaceName = |
| 621 | interfaceNode->Attribute("name"); |
| 622 | if (thisInterfaceName != nullptr) |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 623 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 624 | if (thisInterfaceName == |
| 625 | std::string_view("xyz.openbmc_project.Common.Progress")) |
| 626 | { |
| 627 | interfaceNode = |
| 628 | interfaceNode->NextSiblingElement("interface"); |
| 629 | continue; |
| 630 | } |
| 631 | isProgressIntfPresent = true; |
| 632 | break; |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 633 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 634 | interfaceNode = interfaceNode->NextSiblingElement("interface"); |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 635 | } |
| 636 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 637 | std::shared_ptr<task::TaskData> task = task::TaskData::createTask( |
| 638 | [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent]( |
| 639 | const boost::system::error_code& ec2, |
| 640 | sdbusplus::message_t& msg, |
| 641 | const std::shared_ptr<task::TaskData>& taskData) { |
| 642 | if (ec2) |
| 643 | { |
| 644 | BMCWEB_LOG_ERROR("{}: Error in creating dump", |
| 645 | createdObjPath.str); |
| 646 | taskData->messages.emplace_back( |
| 647 | messages::internalError()); |
| 648 | taskData->state = "Cancelled"; |
| 649 | return task::completed; |
| 650 | } |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 651 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 652 | if (isProgressIntfPresent) |
| 653 | { |
| 654 | dbus::utility::DBusPropertiesMap values; |
| 655 | std::string prop; |
| 656 | msg.read(prop, values); |
| 657 | |
| 658 | DumpCreationProgress dumpStatus = |
| 659 | getDumpCompletionStatus(values); |
| 660 | if (dumpStatus == |
| 661 | DumpCreationProgress::DUMP_CREATE_FAILED) |
| 662 | { |
| 663 | BMCWEB_LOG_ERROR("{}: Error in creating dump", |
| 664 | createdObjPath.str); |
| 665 | taskData->state = "Cancelled"; |
| 666 | return task::completed; |
| 667 | } |
| 668 | |
| 669 | if (dumpStatus == |
| 670 | DumpCreationProgress::DUMP_CREATE_INPROGRESS) |
| 671 | { |
| 672 | BMCWEB_LOG_DEBUG( |
| 673 | "{}: Dump creation task is in progress", |
| 674 | createdObjPath.str); |
| 675 | return !task::completed; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | nlohmann::json retMessage = messages::success(); |
| 680 | taskData->messages.emplace_back(retMessage); |
| 681 | |
| 682 | boost::urls::url url = boost::urls::format( |
| 683 | "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}", |
| 684 | BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId); |
| 685 | |
| 686 | std::string headerLoc = "Location: "; |
| 687 | headerLoc += url.buffer(); |
| 688 | |
| 689 | taskData->payload->httpHeaders.emplace_back( |
| 690 | std::move(headerLoc)); |
| 691 | |
| 692 | BMCWEB_LOG_DEBUG("{}: Dump creation task completed", |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 693 | createdObjPath.str); |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 694 | taskData->state = "Completed"; |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 695 | return task::completed; |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 696 | }, |
| 697 | "type='signal',interface='org.freedesktop.DBus.Properties'," |
| 698 | "member='PropertiesChanged',path='" + |
| 699 | createdObjPath.str + "'"); |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 700 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 701 | // The task timer is set to max time limit within which the |
| 702 | // requested dump will be collected. |
| 703 | task->startTimer(std::chrono::minutes(6)); |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 704 | task->payload.emplace(payload); |
| Chinmay Shripad Hegde | 29e2bdd | 2025-06-06 16:23:47 +0530 | [diff] [blame] | 705 | task->populateResp(asyncResp->res); |
| Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 706 | }, |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 707 | "xyz.openbmc_project.Dump.Manager", createdObjPath, |
| 708 | "org.freedesktop.DBus.Introspectable", "Introspect"); |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 709 | } |
| 710 | |
| zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 711 | inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 712 | const crow::Request& req, const std::string& dumpType) |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 713 | { |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 714 | std::string dumpPath = getDumpEntriesPath(dumpType); |
| 715 | if (dumpPath.empty()) |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 716 | { |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 717 | messages::internalError(asyncResp->res); |
| 718 | return; |
| 719 | } |
| 720 | |
| 721 | std::optional<std::string> diagnosticDataType; |
| 722 | std::optional<std::string> oemDiagnosticDataType; |
| 723 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 724 | if (!redfish::json_util::readJsonAction( // |
| 725 | req, asyncResp->res, // |
| 726 | "DiagnosticDataType", diagnosticDataType, // |
| Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 727 | "OEMDiagnosticDataType", oemDiagnosticDataType // |
| 728 | )) |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 729 | { |
| 730 | return; |
| 731 | } |
| 732 | |
| 733 | if (dumpType == "System") |
| 734 | { |
| 735 | if (!oemDiagnosticDataType || !diagnosticDataType) |
| 736 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 737 | BMCWEB_LOG_ERROR( |
| 738 | "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"); |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 739 | messages::actionParameterMissing( |
| 740 | asyncResp->res, "CollectDiagnosticData", |
| 741 | "DiagnosticDataType & OEMDiagnosticDataType"); |
| 742 | return; |
| 743 | } |
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 744 | if ((*oemDiagnosticDataType != "System") || |
| 745 | (*diagnosticDataType != "OEM")) |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 746 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 747 | BMCWEB_LOG_ERROR("Wrong parameter values passed"); |
| Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 748 | messages::internalError(asyncResp->res); |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 749 | return; |
| 750 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 751 | dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/", |
| 752 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 753 | } |
| 754 | else if (dumpType == "BMC") |
| 755 | { |
| 756 | if (!diagnosticDataType) |
| 757 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 758 | BMCWEB_LOG_ERROR( |
| 759 | "CreateDump action parameter 'DiagnosticDataType' not found!"); |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 760 | messages::actionParameterMissing( |
| 761 | asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); |
| 762 | return; |
| 763 | } |
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 764 | if (*diagnosticDataType != "Manager") |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 765 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 766 | BMCWEB_LOG_ERROR( |
| 767 | "Wrong parameter value passed for 'DiagnosticDataType'"); |
| Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 768 | messages::internalError(asyncResp->res); |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 769 | return; |
| 770 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 771 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/", |
| 772 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 773 | } |
| 774 | else |
| 775 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 776 | BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type"); |
| Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 777 | messages::internalError(asyncResp->res); |
| 778 | return; |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 779 | } |
| 780 | |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 781 | std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>> |
| 782 | createDumpParamVec; |
| 783 | |
| Carson Labrado | f574a8e | 2023-03-22 02:26:00 +0000 | [diff] [blame] | 784 | if (req.session != nullptr) |
| 785 | { |
| 786 | createDumpParamVec.emplace_back( |
| 787 | "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId", |
| 788 | req.session->clientIp); |
| 789 | createDumpParamVec.emplace_back( |
| 790 | "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType", |
| 791 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client"); |
| 792 | } |
| Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 793 | |
| Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 794 | dbus::utility::async_method_call( |
| 795 | asyncResp, |
| Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 796 | [asyncResp, payload(task::Payload(req)), |
| 797 | dumpPath](const boost::system::error_code& ec, |
| 798 | const sdbusplus::message_t& msg, |
| 799 | const sdbusplus::message::object_path& objPath) mutable { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 800 | if (ec) |
| Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 801 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 802 | BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec); |
| 803 | const sd_bus_error* dbusError = msg.get_error(); |
| 804 | if (dbusError == nullptr) |
| 805 | { |
| 806 | messages::internalError(asyncResp->res); |
| 807 | return; |
| 808 | } |
| 809 | |
| 810 | BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}", |
| 811 | dbusError->name, dbusError->message); |
| 812 | if (std::string_view( |
| 813 | "xyz.openbmc_project.Common.Error.NotAllowed") == |
| 814 | dbusError->name) |
| 815 | { |
| 816 | messages::resourceInStandby(asyncResp->res); |
| 817 | return; |
| 818 | } |
| 819 | if (std::string_view( |
| 820 | "xyz.openbmc_project.Dump.Create.Error.Disabled") == |
| 821 | dbusError->name) |
| 822 | { |
| 823 | messages::serviceDisabled(asyncResp->res, dumpPath); |
| 824 | return; |
| 825 | } |
| 826 | if (std::string_view( |
| 827 | "xyz.openbmc_project.Common.Error.Unavailable") == |
| 828 | dbusError->name) |
| 829 | { |
| 830 | messages::resourceInUse(asyncResp->res); |
| 831 | return; |
| 832 | } |
| 833 | // Other Dbus errors such as: |
| 834 | // xyz.openbmc_project.Common.Error.InvalidArgument & |
| 835 | // org.freedesktop.DBus.Error.InvalidArgs are all related to |
| 836 | // the dbus call that is made here in the bmcweb |
| 837 | // implementation and has nothing to do with the client's |
| 838 | // input in the request. Hence, returning internal error |
| 839 | // back to the client. |
| Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 840 | messages::internalError(asyncResp->res); |
| 841 | return; |
| 842 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 843 | BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str); |
| 844 | createDumpTaskCallback(std::move(payload), asyncResp, objPath); |
| 845 | }, |
| Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 846 | "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType), |
| Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 847 | "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec); |
| Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 848 | } |
| 849 | |
| zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 850 | inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 851 | const std::string& dumpType) |
| Asmitha Karunanithi | 80319af | 2020-05-07 05:30:21 -0500 | [diff] [blame] | 852 | { |
| Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 853 | dbus::utility::async_method_call( |
| 854 | asyncResp, |
| Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 855 | [asyncResp](const boost::system::error_code& ec) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 856 | if (ec) |
| 857 | { |
| 858 | BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec); |
| 859 | messages::internalError(asyncResp->res); |
| 860 | return; |
| 861 | } |
| Amy Chang | e246046 | 2025-05-06 00:10:13 -0700 | [diff] [blame] | 862 | messages::success(asyncResp->res); |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 863 | }, |
| Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 864 | "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType), |
| Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 865 | "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); |
| Asmitha Karunanithi | 80319af | 2020-05-07 05:30:21 -0500 | [diff] [blame] | 866 | } |
| 867 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 868 | inline void parseCrashdumpParameters( |
| 869 | const dbus::utility::DBusPropertiesMap& params, std::string& filename, |
| 870 | std::string& timestamp, std::string& logfile) |
| Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 871 | { |
| Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 872 | const std::string* filenamePtr = nullptr; |
| 873 | const std::string* timestampPtr = nullptr; |
| 874 | const std::string* logfilePtr = nullptr; |
| 875 | |
| 876 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 877 | dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr, |
| 878 | "Filename", filenamePtr, "Log", logfilePtr); |
| 879 | |
| 880 | if (!success) |
| Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 881 | { |
| Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 882 | return; |
| 883 | } |
| 884 | |
| 885 | if (filenamePtr != nullptr) |
| 886 | { |
| 887 | filename = *filenamePtr; |
| 888 | } |
| 889 | |
| 890 | if (timestampPtr != nullptr) |
| 891 | { |
| 892 | timestamp = *timestampPtr; |
| 893 | } |
| 894 | |
| 895 | if (logfilePtr != nullptr) |
| 896 | { |
| 897 | logfile = *logfilePtr; |
| Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 901 | inline void requestRoutesSystemLogServiceCollection(App& app) |
| Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 902 | { |
| Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 903 | /** |
| 904 | * Functions triggers appropriate requests on DBus |
| 905 | */ |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 906 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 907 | .privileges(redfish::privileges::getLogServiceCollection) |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 908 | .methods( |
| 909 | boost::beast::http::verb:: |
| 910 | get)([&app](const crow::Request& req, |
| 911 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 912 | const std::string& systemName) { |
| 913 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 914 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 915 | return; |
| 916 | } |
| 917 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 918 | { |
| 919 | // Option currently returns no systems. TBD |
| 920 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 921 | systemName); |
| 922 | return; |
| 923 | } |
| 924 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 925 | { |
| 926 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 927 | systemName); |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 928 | return; |
| 929 | } |
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 930 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 931 | // Collections don't include the static data added by SubRoute |
| 932 | // because it has a duplicate entry for members |
| 933 | asyncResp->res.jsonValue["@odata.type"] = |
| 934 | "#LogServiceCollection.LogServiceCollection"; |
| 935 | asyncResp->res.jsonValue["@odata.id"] = |
| 936 | std::format("/redfish/v1/Systems/{}/LogServices", |
| 937 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 938 | asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; |
| 939 | asyncResp->res.jsonValue["Description"] = |
| 940 | "Collection of LogServices for this Computer System"; |
| 941 | nlohmann::json& logServiceArray = |
| 942 | asyncResp->res.jsonValue["Members"]; |
| 943 | logServiceArray = nlohmann::json::array(); |
| 944 | nlohmann::json::object_t eventLog; |
| 945 | eventLog["@odata.id"] = |
| 946 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog", |
| 947 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 948 | logServiceArray.emplace_back(std::move(eventLog)); |
| 949 | if constexpr (BMCWEB_REDFISH_DUMP_LOG) |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 950 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 951 | nlohmann::json::object_t dumpLog; |
| 952 | dumpLog["@odata.id"] = |
| 953 | std::format("/redfish/v1/Systems/{}/LogServices/Dump", |
| 954 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 955 | logServiceArray.emplace_back(std::move(dumpLog)); |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 956 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 957 | |
| 958 | if constexpr (BMCWEB_REDFISH_CPU_LOG) |
| 959 | { |
| 960 | nlohmann::json::object_t crashdump; |
| 961 | crashdump["@odata.id"] = |
| 962 | std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", |
| 963 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 964 | logServiceArray.emplace_back(std::move(crashdump)); |
| 965 | } |
| 966 | |
| 967 | if constexpr (BMCWEB_REDFISH_HOST_LOGGER) |
| 968 | { |
| 969 | nlohmann::json::object_t hostlogger; |
| 970 | hostlogger["@odata.id"] = |
| 971 | std::format("/redfish/v1/Systems/{}/LogServices/HostLogger", |
| 972 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 973 | logServiceArray.emplace_back(std::move(hostlogger)); |
| 974 | } |
| 975 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 976 | logServiceArray.size(); |
| 977 | |
| 978 | constexpr std::array<std::string_view, 1> interfaces = { |
| 979 | "xyz.openbmc_project.State.Boot.PostCode"}; |
| 980 | dbus::utility::getSubTreePaths( |
| 981 | "/", 0, interfaces, |
| 982 | [asyncResp](const boost::system::error_code& ec, |
| 983 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 984 | subtreePath) { |
| 985 | if (ec) |
| 986 | { |
| 987 | BMCWEB_LOG_ERROR("{}", ec); |
| 988 | return; |
| 989 | } |
| 990 | |
| 991 | for (const auto& pathStr : subtreePath) |
| 992 | { |
| 993 | if (pathStr.find("PostCode") != std::string::npos) |
| 994 | { |
| 995 | nlohmann::json& logServiceArrayLocal = |
| 996 | asyncResp->res.jsonValue["Members"]; |
| 997 | nlohmann::json::object_t member; |
| 998 | member["@odata.id"] = std::format( |
| 999 | "/redfish/v1/Systems/{}/LogServices/PostCodes", |
| 1000 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1001 | |
| 1002 | logServiceArrayLocal.emplace_back( |
| 1003 | std::move(member)); |
| 1004 | |
| 1005 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1006 | logServiceArrayLocal.size(); |
| 1007 | return; |
| 1008 | } |
| 1009 | } |
| 1010 | }); |
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1011 | }); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| Oliver Brewka | 9d6459e | 2025-08-27 13:39:15 +0200 | [diff] [blame] | 1014 | inline void requestRoutesSystemsEventLogService(App& app) |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1015 | { |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1016 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1017 | .privileges(redfish::privileges::getLogService) |
| Oliver Brewka | 9d6459e | 2025-08-27 13:39:15 +0200 | [diff] [blame] | 1018 | .methods(boost::beast::http::verb::get)( |
| 1019 | [&app](const crow::Request& req, |
| 1020 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1021 | const std::string& systemName) { |
| 1022 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1023 | { |
| 1024 | return; |
| 1025 | } |
| 1026 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1027 | { |
| 1028 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1029 | systemName); |
| 1030 | return; |
| 1031 | } |
| 1032 | eventlog_utils::handleSystemsAndManagersEventLogServiceGet( |
| 1033 | asyncResp, eventlog_utils::LogServiceParent::Systems); |
| 1034 | }); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
| Claire Weinan | dd72e87 | 2022-08-15 14:20:06 -0700 | [diff] [blame] | 1037 | inline void handleBMCLogServicesCollectionGet( |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1038 | crow::App& app, const crow::Request& req, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1039 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1040 | const std::string& managerId) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1041 | { |
| 1042 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1043 | { |
| 1044 | return; |
| 1045 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1046 | |
| 1047 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1048 | { |
| 1049 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1050 | return; |
| 1051 | } |
| 1052 | |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1053 | // Collections don't include the static data added by SubRoute |
| 1054 | // because it has a duplicate entry for members |
| 1055 | asyncResp->res.jsonValue["@odata.type"] = |
| 1056 | "#LogServiceCollection.LogServiceCollection"; |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1057 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 1058 | "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME); |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1059 | asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; |
| 1060 | asyncResp->res.jsonValue["Description"] = |
| 1061 | "Collection of LogServices for this Manager"; |
| 1062 | nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; |
| 1063 | logServiceArray = nlohmann::json::array(); |
| 1064 | |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1065 | if constexpr (BMCWEB_REDFISH_BMC_JOURNAL) |
| 1066 | { |
| 1067 | nlohmann::json::object_t journal; |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1068 | journal["@odata.id"] = |
| 1069 | boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal", |
| 1070 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1071 | logServiceArray.emplace_back(std::move(journal)); |
| 1072 | } |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1073 | |
| 1074 | asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); |
| 1075 | |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1076 | if constexpr (BMCWEB_REDFISH_DUMP_LOG) |
| 1077 | { |
| 1078 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1079 | "xyz.openbmc_project.Collection.DeleteAll"}; |
| 1080 | dbus::utility::getSubTreePaths( |
| 1081 | "/xyz/openbmc_project/dump", 0, interfaces, |
| 1082 | [asyncResp](const boost::system::error_code& ec, |
| 1083 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 1084 | subTreePaths) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1085 | if (ec) |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1086 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1087 | BMCWEB_LOG_ERROR( |
| 1088 | "handleBMCLogServicesCollectionGet respHandler got error {}", |
| 1089 | ec); |
| 1090 | // Assume that getting an error simply means there are no |
| 1091 | // dump LogServices. Return without adding any error |
| 1092 | // response. |
| 1093 | return; |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1094 | } |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1095 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1096 | nlohmann::json& logServiceArrayLocal = |
| 1097 | asyncResp->res.jsonValue["Members"]; |
| 1098 | |
| 1099 | for (const std::string& path : subTreePaths) |
| 1100 | { |
| 1101 | if (path == "/xyz/openbmc_project/dump/bmc") |
| 1102 | { |
| 1103 | nlohmann::json::object_t member; |
| 1104 | member["@odata.id"] = boost::urls::format( |
| 1105 | "/redfish/v1/Managers/{}/LogServices/Dump", |
| 1106 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 1107 | logServiceArrayLocal.emplace_back(std::move(member)); |
| 1108 | } |
| 1109 | else if (path == "/xyz/openbmc_project/dump/faultlog") |
| 1110 | { |
| 1111 | nlohmann::json::object_t member; |
| 1112 | member["@odata.id"] = boost::urls::format( |
| 1113 | "/redfish/v1/Managers/{}/LogServices/FaultLog", |
| 1114 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 1115 | logServiceArrayLocal.emplace_back(std::move(member)); |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1120 | logServiceArrayLocal.size(); |
| 1121 | }); |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1122 | } |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1123 | } |
| 1124 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1125 | inline void requestRoutesBMCLogServiceCollection(App& app) |
| 1126 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1127 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/") |
| Gunnar Mills | ad89dcf | 2021-07-30 14:40:11 -0500 | [diff] [blame] | 1128 | .privileges(redfish::privileges::getLogServiceCollection) |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1129 | .methods(boost::beast::http::verb::get)( |
| Claire Weinan | dd72e87 | 2022-08-15 14:20:06 -0700 | [diff] [blame] | 1130 | std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1131 | } |
| Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 1132 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1133 | inline void getDumpServiceInfo( |
| 1134 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1135 | const std::string& dumpType) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1136 | { |
| 1137 | std::string dumpPath; |
| Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1138 | log_service::OverWritePolicy overWritePolicy = |
| 1139 | log_service::OverWritePolicy::Invalid; |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1140 | bool collectDiagnosticDataSupported = false; |
| 1141 | |
| 1142 | if (dumpType == "BMC") |
| 1143 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1144 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump", |
| 1145 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1146 | overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1147 | collectDiagnosticDataSupported = true; |
| 1148 | } |
| 1149 | else if (dumpType == "FaultLog") |
| 1150 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1151 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog", |
| 1152 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1153 | overWritePolicy = log_service::OverWritePolicy::Unknown; |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1154 | collectDiagnosticDataSupported = false; |
| 1155 | } |
| 1156 | else if (dumpType == "System") |
| 1157 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1158 | dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump", |
| 1159 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1160 | overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1161 | collectDiagnosticDataSupported = true; |
| 1162 | } |
| 1163 | else |
| 1164 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1165 | BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}", |
| 1166 | dumpType); |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1167 | messages::internalError(asyncResp->res); |
| 1168 | return; |
| 1169 | } |
| 1170 | |
| 1171 | asyncResp->res.jsonValue["@odata.id"] = dumpPath; |
| 1172 | asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; |
| 1173 | asyncResp->res.jsonValue["Name"] = "Dump LogService"; |
| 1174 | asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; |
| 1175 | asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); |
| Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1176 | asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy; |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1177 | |
| 1178 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| Ed Tanous | 2b82937 | 2022-08-03 14:22:34 -0700 | [diff] [blame] | 1179 | redfish::time_utils::getDateTimeOffsetNow(); |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1180 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 1181 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 1182 | redfishDateTimeOffset.second; |
| 1183 | |
| 1184 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1185 | |
| 1186 | if (collectDiagnosticDataSupported) |
| 1187 | { |
| 1188 | asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] |
| 1189 | ["target"] = |
| 1190 | dumpPath + "/Actions/LogService.CollectDiagnosticData"; |
| 1191 | } |
| Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 1192 | |
| Corey Ethington | 08fad5d | 2025-07-31 12:14:27 -0400 | [diff] [blame] | 1193 | etag_utils::setEtagOmitDateTimeHandler(asyncResp); |
| 1194 | |
| Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 1195 | constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface}; |
| 1196 | dbus::utility::getSubTreePaths( |
| 1197 | "/xyz/openbmc_project/dump", 0, interfaces, |
| 1198 | [asyncResp, dumpType, dumpPath]( |
| 1199 | const boost::system::error_code& ec, |
| 1200 | const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1201 | if (ec) |
| Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 1202 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1203 | BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", |
| 1204 | ec); |
| 1205 | // Assume that getting an error simply means there are no dump |
| 1206 | // LogServices. Return without adding any error response. |
| 1207 | return; |
| Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 1208 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1209 | std::string dbusDumpPath = getDumpPath(dumpType); |
| 1210 | for (const std::string& path : subTreePaths) |
| 1211 | { |
| 1212 | if (path == dbusDumpPath) |
| 1213 | { |
| 1214 | asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] |
| 1215 | ["target"] = |
| 1216 | dumpPath + "/Actions/LogService.ClearLog"; |
| 1217 | break; |
| 1218 | } |
| 1219 | } |
| 1220 | }); |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | inline void handleLogServicesDumpServiceGet( |
| 1224 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1225 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1226 | const std::string& managerId) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1227 | { |
| 1228 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1229 | { |
| 1230 | return; |
| 1231 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1232 | |
| 1233 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1234 | { |
| 1235 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1236 | return; |
| 1237 | } |
| 1238 | |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1239 | getDumpServiceInfo(asyncResp, dumpType); |
| 1240 | } |
| 1241 | |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1242 | inline void handleLogServicesDumpServiceComputerSystemGet( |
| 1243 | crow::App& app, const crow::Request& req, |
| 1244 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1245 | const std::string& chassisId) |
| 1246 | { |
| 1247 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1248 | { |
| 1249 | return; |
| 1250 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1251 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1252 | { |
| 1253 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 1254 | return; |
| 1255 | } |
| 1256 | getDumpServiceInfo(asyncResp, "System"); |
| 1257 | } |
| 1258 | |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1259 | inline void handleLogServicesDumpEntriesCollectionGet( |
| 1260 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1261 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1262 | const std::string& managerId) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1263 | { |
| 1264 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1265 | { |
| 1266 | return; |
| 1267 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1268 | |
| 1269 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1270 | { |
| 1271 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1272 | return; |
| 1273 | } |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1274 | getDumpEntryCollection(asyncResp, dumpType); |
| 1275 | } |
| 1276 | |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1277 | inline void handleLogServicesDumpEntriesCollectionComputerSystemGet( |
| 1278 | crow::App& app, const crow::Request& req, |
| 1279 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1280 | const std::string& chassisId) |
| 1281 | { |
| 1282 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1283 | { |
| 1284 | return; |
| 1285 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1286 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1287 | { |
| 1288 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 1289 | return; |
| 1290 | } |
| 1291 | getDumpEntryCollection(asyncResp, "System"); |
| 1292 | } |
| 1293 | |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1294 | inline void handleLogServicesDumpEntryGet( |
| 1295 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 1296 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1297 | const std::string& managerId, const std::string& dumpId) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1298 | { |
| 1299 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1300 | { |
| 1301 | return; |
| 1302 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1303 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1304 | { |
| 1305 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1306 | return; |
| 1307 | } |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1308 | getDumpEntryById(asyncResp, dumpId, dumpType); |
| 1309 | } |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1310 | |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1311 | inline void handleLogServicesDumpEntryComputerSystemGet( |
| 1312 | crow::App& app, const crow::Request& req, |
| 1313 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1314 | const std::string& chassisId, const std::string& dumpId) |
| 1315 | { |
| 1316 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1317 | { |
| 1318 | return; |
| 1319 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1320 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1321 | { |
| 1322 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 1323 | return; |
| 1324 | } |
| 1325 | getDumpEntryById(asyncResp, dumpId, "System"); |
| 1326 | } |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1327 | |
| 1328 | inline void handleLogServicesDumpEntryDelete( |
| 1329 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 1330 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1331 | const std::string& managerId, const std::string& dumpId) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1332 | { |
| 1333 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1334 | { |
| 1335 | return; |
| 1336 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1337 | |
| 1338 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1339 | { |
| 1340 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1341 | return; |
| 1342 | } |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1343 | deleteDumpEntry(asyncResp, dumpId, dumpType); |
| 1344 | } |
| 1345 | |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1346 | inline void handleLogServicesDumpEntryComputerSystemDelete( |
| 1347 | crow::App& app, const crow::Request& req, |
| 1348 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1349 | const std::string& chassisId, const std::string& dumpId) |
| 1350 | { |
| 1351 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1352 | { |
| 1353 | return; |
| 1354 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1355 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1356 | { |
| 1357 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 1358 | return; |
| 1359 | } |
| 1360 | deleteDumpEntry(asyncResp, dumpId, "System"); |
| 1361 | } |
| 1362 | |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1363 | inline void handleLogServicesDumpEntryDownloadGet( |
| 1364 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 1365 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1366 | const std::string& managerId, const std::string& dumpId) |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1367 | { |
| 1368 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1369 | { |
| 1370 | return; |
| 1371 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1372 | |
| 1373 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1374 | { |
| 1375 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1376 | return; |
| 1377 | } |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1378 | downloadDumpEntry(asyncResp, dumpId, dumpType); |
| 1379 | } |
| 1380 | |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1381 | inline void handleLogServicesDumpCollectDiagnosticDataPost( |
| 1382 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1383 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1384 | const std::string& managerId) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1385 | { |
| 1386 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1387 | { |
| 1388 | return; |
| 1389 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1390 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1391 | { |
| 1392 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1393 | return; |
| 1394 | } |
| 1395 | |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1396 | createDump(asyncResp, req, dumpType); |
| 1397 | } |
| 1398 | |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1399 | inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost( |
| 1400 | crow::App& app, const crow::Request& req, |
| 1401 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1402 | const std::string& systemName) |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1403 | { |
| 1404 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1405 | { |
| 1406 | return; |
| 1407 | } |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1408 | |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1409 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1410 | { |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1411 | // Option currently returns no systems. TBD |
| 1412 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1413 | systemName); |
| 1414 | return; |
| 1415 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1416 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1417 | { |
| 1418 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1419 | systemName); |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1420 | return; |
| 1421 | } |
| 1422 | createDump(asyncResp, req, "System"); |
| 1423 | } |
| 1424 | |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1425 | inline void handleLogServicesDumpClearLogPost( |
| 1426 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1427 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1428 | const std::string& managerId) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1429 | { |
| 1430 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1431 | { |
| 1432 | return; |
| 1433 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1434 | |
| 1435 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1436 | { |
| 1437 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1438 | return; |
| 1439 | } |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1440 | clearDump(asyncResp, dumpType); |
| 1441 | } |
| 1442 | |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1443 | inline void handleLogServicesDumpClearLogComputerSystemPost( |
| 1444 | crow::App& app, const crow::Request& req, |
| 1445 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1446 | const std::string& systemName) |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1447 | { |
| 1448 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1449 | { |
| 1450 | return; |
| 1451 | } |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1452 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1453 | { |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1454 | // Option currently returns no systems. TBD |
| 1455 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1456 | systemName); |
| 1457 | return; |
| 1458 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1459 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1460 | { |
| 1461 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1462 | systemName); |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1463 | return; |
| 1464 | } |
| 1465 | clearDump(asyncResp, "System"); |
| 1466 | } |
| 1467 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1468 | inline void requestRoutesBMCDumpService(App& app) |
| 1469 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1470 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1471 | .privileges(redfish::privileges::getLogService) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1472 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1473 | handleLogServicesDumpServiceGet, std::ref(app), "BMC")); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | inline void requestRoutesBMCDumpEntryCollection(App& app) |
| 1477 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1478 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1479 | .privileges(redfish::privileges::getLogEntryCollection) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1480 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1481 | handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | inline void requestRoutesBMCDumpEntry(App& app) |
| 1485 | { |
| 1486 | BMCWEB_ROUTE(app, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1487 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1488 | .privileges(redfish::privileges::getLogEntry) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1489 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1490 | handleLogServicesDumpEntryGet, std::ref(app), "BMC")); |
| 1491 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1492 | BMCWEB_ROUTE(app, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1493 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1494 | .privileges(redfish::privileges::deleteLogEntry) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1495 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
| 1496 | handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1499 | inline void requestRoutesBMCDumpEntryDownload(App& app) |
| 1500 | { |
| 1501 | BMCWEB_ROUTE( |
| 1502 | app, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1503 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/") |
| Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 1504 | .privileges(redfish::privileges::getLogEntry) |
| 1505 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1506 | handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC")); |
| 1507 | } |
| 1508 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1509 | inline void requestRoutesBMCDumpCreate(App& app) |
| 1510 | { |
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1511 | BMCWEB_ROUTE( |
| 1512 | app, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1513 | "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1514 | .privileges(redfish::privileges::postLogService) |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1515 | .methods(boost::beast::http::verb::post)( |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1516 | std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, |
| 1517 | std::ref(app), "BMC")); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | inline void requestRoutesBMCDumpClear(App& app) |
| 1521 | { |
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1522 | BMCWEB_ROUTE( |
| 1523 | app, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1524 | "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1525 | .privileges(redfish::privileges::postLogService) |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1526 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 1527 | handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); |
| 1528 | } |
| 1529 | |
| 1530 | inline void requestRoutesFaultLogDumpService(App& app) |
| 1531 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1532 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/") |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1533 | .privileges(redfish::privileges::getLogService) |
| 1534 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1535 | handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); |
| 1536 | } |
| 1537 | |
| 1538 | inline void requestRoutesFaultLogDumpEntryCollection(App& app) |
| 1539 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1540 | BMCWEB_ROUTE(app, |
| 1541 | "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/") |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1542 | .privileges(redfish::privileges::getLogEntryCollection) |
| 1543 | .methods(boost::beast::http::verb::get)( |
| 1544 | std::bind_front(handleLogServicesDumpEntriesCollectionGet, |
| 1545 | std::ref(app), "FaultLog")); |
| 1546 | } |
| 1547 | |
| 1548 | inline void requestRoutesFaultLogDumpEntry(App& app) |
| 1549 | { |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1550 | BMCWEB_ROUTE( |
| 1551 | app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1552 | .privileges(redfish::privileges::getLogEntry) |
| 1553 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1554 | handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); |
| 1555 | |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1556 | BMCWEB_ROUTE( |
| 1557 | app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1558 | .privileges(redfish::privileges::deleteLogEntry) |
| 1559 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
| 1560 | handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); |
| 1561 | } |
| 1562 | |
| 1563 | inline void requestRoutesFaultLogDumpClear(App& app) |
| 1564 | { |
| 1565 | BMCWEB_ROUTE( |
| 1566 | app, |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1567 | "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/") |
| Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1568 | .privileges(redfish::privileges::postLogService) |
| 1569 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 1570 | handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | inline void requestRoutesSystemDumpService(App& app) |
| 1574 | { |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1575 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1576 | .privileges(redfish::privileges::getLogService) |
| Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 1577 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1578 | handleLogServicesDumpServiceComputerSystemGet, std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | inline void requestRoutesSystemDumpEntryCollection(App& app) |
| 1582 | { |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1583 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1584 | .privileges(redfish::privileges::getLogEntryCollection) |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1585 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1586 | handleLogServicesDumpEntriesCollectionComputerSystemGet, |
| 1587 | std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | inline void requestRoutesSystemDumpEntry(App& app) |
| 1591 | { |
| 1592 | BMCWEB_ROUTE(app, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1593 | "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1594 | .privileges(redfish::privileges::getLogEntry) |
| Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 1595 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1596 | handleLogServicesDumpEntryComputerSystemGet, std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1597 | |
| 1598 | BMCWEB_ROUTE(app, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1599 | "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1600 | .privileges(redfish::privileges::deleteLogEntry) |
| Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 1601 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1602 | handleLogServicesDumpEntryComputerSystemDelete, std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | inline void requestRoutesSystemDumpCreate(App& app) |
| 1606 | { |
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1607 | BMCWEB_ROUTE( |
| 1608 | app, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1609 | "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") |
| Abhishek Patel | fff6a4d | 2021-07-21 11:29:45 -0500 | [diff] [blame] | 1610 | .privileges(redfish::privileges:: |
| 1611 | postLogServiceSubOverComputerSystemLogServiceCollection) |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1612 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 1613 | handleLogServicesDumpCollectDiagnosticDataComputerSystemPost, |
| 1614 | std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | inline void requestRoutesSystemDumpClear(App& app) |
| 1618 | { |
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1619 | BMCWEB_ROUTE( |
| 1620 | app, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1621 | "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/") |
| Abhishek Patel | fff6a4d | 2021-07-21 11:29:45 -0500 | [diff] [blame] | 1622 | .privileges(redfish::privileges:: |
| 1623 | postLogServiceSubOverComputerSystemLogServiceCollection) |
| Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 1624 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1625 | handleLogServicesDumpClearLogComputerSystemPost, std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | inline void requestRoutesCrashdumpService(App& app) |
| 1629 | { |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1630 | /** |
| 1631 | * Functions triggers appropriate requests on DBus |
| 1632 | */ |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1633 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/") |
| Myung Bae | 50d9f38 | 2025-06-13 09:40:18 -0400 | [diff] [blame] | 1634 | .privileges(redfish::privileges::getLogService) |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1635 | .methods( |
| 1636 | boost::beast::http::verb:: |
| 1637 | get)([&app](const crow::Request& req, |
| 1638 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1639 | const std::string& systemName) { |
| 1640 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1641 | { |
| 1642 | return; |
| 1643 | } |
| 1644 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1645 | { |
| 1646 | // Option currently returns no systems. TBD |
| 1647 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1648 | systemName); |
| 1649 | return; |
| 1650 | } |
| 1651 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1652 | { |
| 1653 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1654 | systemName); |
| 1655 | return; |
| 1656 | } |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1657 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1658 | // Copy over the static data to include the entries added by |
| 1659 | // SubRoute |
| 1660 | asyncResp->res.jsonValue["@odata.id"] = |
| 1661 | std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", |
| 1662 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1663 | asyncResp->res.jsonValue["@odata.type"] = |
| 1664 | "#LogService.v1_2_0.LogService"; |
| 1665 | asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; |
| 1666 | asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; |
| 1667 | asyncResp->res.jsonValue["Id"] = "Crashdump"; |
| 1668 | asyncResp->res.jsonValue["OverWritePolicy"] = |
| 1669 | log_service::OverWritePolicy::WrapsWhenFull; |
| 1670 | asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; |
| Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1671 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1672 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| 1673 | redfish::time_utils::getDateTimeOffsetNow(); |
| 1674 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 1675 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 1676 | redfishDateTimeOffset.second; |
| Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1677 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1678 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format( |
| 1679 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", |
| 1680 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1681 | asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] |
| 1682 | ["target"] = std::format( |
| 1683 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog", |
| 1684 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1685 | asyncResp->res |
| 1686 | .jsonValue["Actions"]["#LogService.CollectDiagnosticData"] |
| 1687 | ["target"] = std::format( |
| 1688 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData", |
| 1689 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| Corey Ethington | 08fad5d | 2025-07-31 12:14:27 -0400 | [diff] [blame] | 1690 | |
| 1691 | etag_utils::setEtagOmitDateTimeHandler(asyncResp); |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1692 | }); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| Ed Tanous | 8e4736b | 2025-08-19 10:14:02 -0700 | [diff] [blame] | 1695 | inline void requestRoutesCrashdumpClear(App& app) |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1696 | { |
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1697 | BMCWEB_ROUTE( |
| 1698 | app, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1699 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/") |
| Myung Bae | 50d9f38 | 2025-06-13 09:40:18 -0400 | [diff] [blame] | 1700 | .privileges(redfish::privileges:: |
| 1701 | postLogServiceSubOverComputerSystemLogServiceCollection) |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1702 | .methods(boost::beast::http::verb::post)( |
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1703 | [&app](const crow::Request& req, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1704 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1705 | const std::string& systemName) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1706 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1707 | { |
| 1708 | return; |
| 1709 | } |
| 1710 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1711 | { |
| 1712 | // Option currently returns no systems. TBD |
| 1713 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1714 | systemName); |
| 1715 | return; |
| 1716 | } |
| 1717 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1718 | { |
| 1719 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1720 | systemName); |
| 1721 | return; |
| 1722 | } |
| Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 1723 | dbus::utility::async_method_call( |
| 1724 | asyncResp, |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1725 | [asyncResp](const boost::system::error_code& ec, |
| 1726 | const std::string&) { |
| 1727 | if (ec) |
| 1728 | { |
| 1729 | messages::internalError(asyncResp->res); |
| 1730 | return; |
| 1731 | } |
| 1732 | messages::success(asyncResp->res); |
| 1733 | }, |
| 1734 | crashdumpObject, crashdumpPath, deleteAllInterface, |
| 1735 | "DeleteAll"); |
| 1736 | }); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1737 | } |
| Jason M. Bills | 5b61b5e | 2019-10-16 10:59:02 -0700 | [diff] [blame] | 1738 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1739 | inline void logCrashdumpEntry( |
| 1740 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1741 | const std::string& logID, nlohmann::json& logEntryJson) |
| Jason M. Bills | e855dd2 | 2019-10-08 11:37:48 -0700 | [diff] [blame] | 1742 | { |
| Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 1743 | auto getStoredLogCallback = |
| Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1744 | [asyncResp, logID, |
| Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1745 | &logEntryJson](const boost::system::error_code& ec, |
| Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1746 | const dbus::utility::DBusPropertiesMap& params) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1747 | if (ec) |
| 1748 | { |
| 1749 | BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message()); |
| 1750 | if (ec.value() == |
| 1751 | boost::system::linux_error::bad_request_descriptor) |
| 1752 | { |
| 1753 | messages::resourceNotFound(asyncResp->res, "LogEntry", |
| 1754 | logID); |
| 1755 | } |
| 1756 | else |
| 1757 | { |
| 1758 | messages::internalError(asyncResp->res); |
| 1759 | } |
| 1760 | return; |
| 1761 | } |
| 1762 | |
| 1763 | std::string timestamp{}; |
| 1764 | std::string filename{}; |
| 1765 | std::string logfile{}; |
| 1766 | parseCrashdumpParameters(params, filename, timestamp, logfile); |
| 1767 | |
| 1768 | if (filename.empty() || timestamp.empty()) |
| Jason M. Bills | 1ddcf01 | 2019-11-26 14:59:21 -0800 | [diff] [blame] | 1769 | { |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1770 | messages::resourceNotFound(asyncResp->res, "LogEntry", logID); |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1771 | return; |
| 1772 | } |
| 1773 | |
| 1774 | std::string crashdumpURI = |
| 1775 | std::format( |
| 1776 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/", |
| 1777 | BMCWEB_REDFISH_SYSTEM_URI_NAME) + |
| 1778 | logID + "/" + filename; |
| 1779 | nlohmann::json::object_t logEntry; |
| 1780 | logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
| 1781 | logEntry["@odata.id"] = boost::urls::format( |
| 1782 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}", |
| 1783 | BMCWEB_REDFISH_SYSTEM_URI_NAME, logID); |
| 1784 | logEntry["Name"] = "CPU Crashdump"; |
| 1785 | logEntry["Id"] = logID; |
| 1786 | logEntry["EntryType"] = log_entry::LogEntryType::Oem; |
| 1787 | logEntry["AdditionalDataURI"] = std::move(crashdumpURI); |
| 1788 | logEntry["DiagnosticDataType"] = "OEM"; |
| 1789 | logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; |
| 1790 | logEntry["Created"] = std::move(timestamp); |
| 1791 | |
| 1792 | // If logEntryJson references an array of LogEntry resources |
| 1793 | // ('Members' list), then push this as a new entry, otherwise set it |
| 1794 | // directly |
| 1795 | if (logEntryJson.is_array()) |
| 1796 | { |
| 1797 | logEntryJson.push_back(logEntry); |
| 1798 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1799 | logEntryJson.size(); |
| Jason M. Bills | 2b20ef6 | 2022-01-06 15:48:07 -0800 | [diff] [blame] | 1800 | } |
| 1801 | else |
| 1802 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1803 | logEntryJson.update(logEntry); |
| Jason M. Bills | 2b20ef6 | 2022-01-06 15:48:07 -0800 | [diff] [blame] | 1804 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1805 | }; |
| Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1806 | dbus::utility::getAllProperties( |
| 1807 | crashdumpObject, crashdumpPath + std::string("/") + logID, |
| 1808 | crashdumpInterface, std::move(getStoredLogCallback)); |
| Jason M. Bills | e855dd2 | 2019-10-08 11:37:48 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1811 | inline void requestRoutesCrashdumpEntryCollection(App& app) |
| Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 1812 | { |
| Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 1813 | /** |
| 1814 | * Functions triggers appropriate requests on DBus |
| 1815 | */ |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1816 | BMCWEB_ROUTE(app, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1817 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/") |
| Myung Bae | 50d9f38 | 2025-06-13 09:40:18 -0400 | [diff] [blame] | 1818 | .privileges(redfish::privileges::getLogEntryCollection) |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1819 | .methods( |
| 1820 | boost::beast::http::verb:: |
| 1821 | get)([&app](const crow::Request& req, |
| 1822 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1823 | const std::string& systemName) { |
| 1824 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1825 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1826 | return; |
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1827 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1828 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1829 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1830 | // Option currently returns no systems. TBD |
| 1831 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1832 | systemName); |
| 1833 | return; |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1834 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1835 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1836 | { |
| 1837 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1838 | systemName); |
| 1839 | return; |
| 1840 | } |
| 1841 | |
| 1842 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1843 | crashdumpInterface}; |
| 1844 | dbus::utility::getSubTreePaths( |
| 1845 | "/", 0, interfaces, |
| 1846 | [asyncResp](const boost::system::error_code& ec, |
| 1847 | const std::vector<std::string>& resp) { |
| 1848 | if (ec) |
| 1849 | { |
| 1850 | if (ec.value() != |
| 1851 | boost::system::errc::no_such_file_or_directory) |
| 1852 | { |
| 1853 | BMCWEB_LOG_DEBUG("failed to get entries ec: {}", |
| 1854 | ec.message()); |
| 1855 | messages::internalError(asyncResp->res); |
| 1856 | return; |
| 1857 | } |
| 1858 | } |
| 1859 | asyncResp->res.jsonValue["@odata.type"] = |
| 1860 | "#LogEntryCollection.LogEntryCollection"; |
| 1861 | asyncResp->res.jsonValue["@odata.id"] = std::format( |
| 1862 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", |
| 1863 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1864 | asyncResp->res.jsonValue["Name"] = |
| 1865 | "Open BMC Crashdump Entries"; |
| 1866 | asyncResp->res.jsonValue["Description"] = |
| 1867 | "Collection of Crashdump Entries"; |
| 1868 | asyncResp->res.jsonValue["Members"] = |
| 1869 | nlohmann::json::array(); |
| 1870 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
| 1871 | |
| 1872 | for (const std::string& path : resp) |
| 1873 | { |
| 1874 | const sdbusplus::message::object_path objPath(path); |
| 1875 | // Get the log ID |
| 1876 | std::string logID = objPath.filename(); |
| 1877 | if (logID.empty()) |
| 1878 | { |
| 1879 | continue; |
| 1880 | } |
| 1881 | // Add the log entry to the array |
| 1882 | logCrashdumpEntry(asyncResp, logID, |
| 1883 | asyncResp->res.jsonValue["Members"]); |
| 1884 | } |
| 1885 | }); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1886 | }); |
| 1887 | } |
| Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 1888 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1889 | inline void requestRoutesCrashdumpEntry(App& app) |
| Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 1890 | { |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1891 | BMCWEB_ROUTE( |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1892 | app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/") |
| Myung Bae | 50d9f38 | 2025-06-13 09:40:18 -0400 | [diff] [blame] | 1893 | .privileges(redfish::privileges::getLogEntry) |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1894 | .methods(boost::beast::http::verb::get)( |
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1895 | [&app](const crow::Request& req, |
| 1896 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1897 | const std::string& systemName, const std::string& param) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1898 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1899 | { |
| 1900 | return; |
| 1901 | } |
| 1902 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1903 | { |
| 1904 | // Option currently returns no systems. TBD |
| 1905 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1906 | systemName); |
| 1907 | return; |
| 1908 | } |
| 1909 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1910 | { |
| 1911 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1912 | systemName); |
| 1913 | return; |
| 1914 | } |
| 1915 | const std::string& logID = param; |
| 1916 | logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); |
| 1917 | }); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1918 | } |
| Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 1919 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1920 | inline void requestRoutesCrashdumpFile(App& app) |
| 1921 | { |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1922 | BMCWEB_ROUTE( |
| 1923 | app, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1924 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1925 | .privileges(redfish::privileges::getLogEntry) |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1926 | .methods(boost::beast::http::verb::get)( |
| Nan Zhou | a4ce114 | 2022-08-02 18:45:25 +0000 | [diff] [blame] | 1927 | [](const crow::Request& req, |
| 1928 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1929 | const std::string& systemName, const std::string& logID, |
| 1930 | const std::string& fileName) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1931 | // Do not call getRedfishRoute here since the crashdump file is |
| 1932 | // not a Redfish resource. |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1933 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1934 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1935 | { |
| 1936 | // Option currently returns no systems. TBD |
| 1937 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1938 | systemName); |
| 1939 | return; |
| 1940 | } |
| 1941 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1942 | { |
| 1943 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1944 | systemName); |
| 1945 | return; |
| 1946 | } |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1947 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1948 | auto getStoredLogCallback = |
| 1949 | [asyncResp, logID, fileName, |
| 1950 | url(boost::urls::url(req.url()))]( |
| 1951 | const boost::system::error_code& ec, |
| 1952 | const std::vector<std::pair< |
| 1953 | std::string, dbus::utility::DbusVariantType>>& |
| 1954 | resp) { |
| 1955 | if (ec) |
| 1956 | { |
| 1957 | BMCWEB_LOG_DEBUG("failed to get log ec: {}", |
| 1958 | ec.message()); |
| 1959 | messages::internalError(asyncResp->res); |
| 1960 | return; |
| 1961 | } |
| Jason M. Bills | 8e6c099 | 2021-03-11 16:26:53 -0800 | [diff] [blame] | 1962 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1963 | std::string dbusFilename{}; |
| 1964 | std::string dbusTimestamp{}; |
| 1965 | std::string dbusFilepath{}; |
| Jason M. Bills | 8e6c099 | 2021-03-11 16:26:53 -0800 | [diff] [blame] | 1966 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1967 | parseCrashdumpParameters(resp, dbusFilename, |
| 1968 | dbusTimestamp, dbusFilepath); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1969 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1970 | if (dbusFilename.empty() || dbusTimestamp.empty() || |
| 1971 | dbusFilepath.empty()) |
| 1972 | { |
| 1973 | messages::resourceNotFound(asyncResp->res, |
| 1974 | "LogEntry", logID); |
| 1975 | return; |
| 1976 | } |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1977 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1978 | // Verify the file name parameter is correct |
| 1979 | if (fileName != dbusFilename) |
| 1980 | { |
| 1981 | messages::resourceNotFound(asyncResp->res, |
| 1982 | "LogEntry", logID); |
| 1983 | return; |
| 1984 | } |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1985 | |
| Myung Bae | d51c61b | 2024-09-13 10:35:34 -0500 | [diff] [blame] | 1986 | if (asyncResp->res.openFile(dbusFilepath) != |
| 1987 | crow::OpenCode::Success) |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1988 | { |
| 1989 | messages::resourceNotFound(asyncResp->res, |
| 1990 | "LogEntry", logID); |
| 1991 | return; |
| 1992 | } |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1993 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1994 | // Configure this to be a file download when accessed |
| 1995 | // from a browser |
| 1996 | asyncResp->res.addHeader( |
| 1997 | boost::beast::http::field::content_disposition, |
| 1998 | "attachment"); |
| 1999 | }; |
| Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2000 | dbus::utility::getAllProperties( |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2001 | *crow::connections::systemBus, crashdumpObject, |
| 2002 | crashdumpPath + std::string("/") + logID, |
| 2003 | crashdumpInterface, std::move(getStoredLogCallback)); |
| 2004 | }); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| Jason M. Bills | c5a4c82 | 2022-01-06 15:51:23 -0800 | [diff] [blame] | 2007 | enum class OEMDiagnosticType |
| 2008 | { |
| 2009 | onDemand, |
| 2010 | telemetry, |
| 2011 | invalid, |
| 2012 | }; |
| 2013 | |
| Ed Tanous | 26ccae3 | 2023-02-16 10:28:44 -0800 | [diff] [blame] | 2014 | inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr) |
| Jason M. Bills | c5a4c82 | 2022-01-06 15:51:23 -0800 | [diff] [blame] | 2015 | { |
| 2016 | if (oemDiagStr == "OnDemand") |
| 2017 | { |
| 2018 | return OEMDiagnosticType::onDemand; |
| 2019 | } |
| 2020 | if (oemDiagStr == "Telemetry") |
| 2021 | { |
| 2022 | return OEMDiagnosticType::telemetry; |
| 2023 | } |
| 2024 | |
| 2025 | return OEMDiagnosticType::invalid; |
| 2026 | } |
| 2027 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2028 | inline void requestRoutesCrashdumpCollect(App& app) |
| 2029 | { |
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2030 | BMCWEB_ROUTE( |
| 2031 | app, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2032 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") |
| Myung Bae | 50d9f38 | 2025-06-13 09:40:18 -0400 | [diff] [blame] | 2033 | .privileges(redfish::privileges:: |
| 2034 | postLogServiceSubOverComputerSystemLogServiceCollection) |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2035 | .methods(boost::beast::http::verb::post)( |
| 2036 | [&app](const crow::Request& req, |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2037 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2038 | const std::string& systemName) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2039 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2040 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2041 | return; |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2042 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2043 | |
| 2044 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2045 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2046 | // Option currently returns no systems. TBD |
| 2047 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2048 | systemName); |
| 2049 | return; |
| 2050 | } |
| 2051 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2052 | { |
| 2053 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2054 | systemName); |
| 2055 | return; |
| 2056 | } |
| 2057 | |
| 2058 | std::string diagnosticDataType; |
| 2059 | std::string oemDiagnosticDataType; |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2060 | if (!redfish::json_util::readJsonAction( // |
| 2061 | req, asyncResp->res, // |
| 2062 | "DiagnosticDataType", diagnosticDataType, // |
| Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 2063 | "OEMDiagnosticDataType", oemDiagnosticDataType // |
| 2064 | )) |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2065 | { |
| 2066 | return; |
| 2067 | } |
| 2068 | |
| 2069 | if (diagnosticDataType != "OEM") |
| 2070 | { |
| 2071 | BMCWEB_LOG_ERROR( |
| 2072 | "Only OEM DiagnosticDataType supported for Crashdump"); |
| 2073 | messages::actionParameterValueFormatError( |
| 2074 | asyncResp->res, diagnosticDataType, |
| 2075 | "DiagnosticDataType", "CollectDiagnosticData"); |
| 2076 | return; |
| 2077 | } |
| 2078 | |
| 2079 | OEMDiagnosticType oemDiagType = |
| 2080 | getOEMDiagnosticType(oemDiagnosticDataType); |
| 2081 | |
| 2082 | std::string iface; |
| 2083 | std::string method; |
| 2084 | std::string taskMatchStr; |
| 2085 | if (oemDiagType == OEMDiagnosticType::onDemand) |
| 2086 | { |
| 2087 | iface = crashdumpOnDemandInterface; |
| 2088 | method = "GenerateOnDemandLog"; |
| 2089 | taskMatchStr = |
| 2090 | "type='signal'," |
| 2091 | "interface='org.freedesktop.DBus.Properties'," |
| 2092 | "member='PropertiesChanged'," |
| 2093 | "arg0namespace='com.intel.crashdump'"; |
| 2094 | } |
| 2095 | else if (oemDiagType == OEMDiagnosticType::telemetry) |
| 2096 | { |
| 2097 | iface = crashdumpTelemetryInterface; |
| 2098 | method = "GenerateTelemetryLog"; |
| 2099 | taskMatchStr = |
| 2100 | "type='signal'," |
| 2101 | "interface='org.freedesktop.DBus.Properties'," |
| 2102 | "member='PropertiesChanged'," |
| 2103 | "arg0namespace='com.intel.crashdump'"; |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2104 | } |
| 2105 | else |
| 2106 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2107 | BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}", |
| 2108 | oemDiagnosticDataType); |
| 2109 | messages::actionParameterValueFormatError( |
| 2110 | asyncResp->res, oemDiagnosticDataType, |
| 2111 | "OEMDiagnosticDataType", "CollectDiagnosticData"); |
| 2112 | return; |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2113 | } |
| Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2114 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2115 | auto collectCrashdumpCallback = |
| 2116 | [asyncResp, payload(task::Payload(req)), |
| 2117 | taskMatchStr](const boost::system::error_code& ec, |
| 2118 | const std::string&) mutable { |
| 2119 | if (ec) |
| 2120 | { |
| 2121 | if (ec.value() == |
| 2122 | boost::system::errc::operation_not_supported) |
| 2123 | { |
| 2124 | messages::resourceInStandby(asyncResp->res); |
| 2125 | } |
| 2126 | else if (ec.value() == boost::system::errc:: |
| 2127 | device_or_resource_busy) |
| 2128 | { |
| 2129 | messages::serviceTemporarilyUnavailable( |
| 2130 | asyncResp->res, "60"); |
| 2131 | } |
| 2132 | else |
| 2133 | { |
| 2134 | messages::internalError(asyncResp->res); |
| 2135 | } |
| 2136 | return; |
| 2137 | } |
| 2138 | std::shared_ptr<task::TaskData> task = |
| 2139 | task::TaskData::createTask( |
| 2140 | [](const boost::system::error_code& ec2, |
| 2141 | sdbusplus::message_t&, |
| 2142 | const std::shared_ptr<task::TaskData>& |
| 2143 | taskData) { |
| 2144 | if (!ec2) |
| 2145 | { |
| 2146 | taskData->messages.emplace_back( |
| 2147 | messages::taskCompletedOK( |
| 2148 | std::to_string( |
| 2149 | taskData->index))); |
| 2150 | taskData->state = "Completed"; |
| 2151 | } |
| 2152 | return task::completed; |
| 2153 | }, |
| 2154 | taskMatchStr); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2155 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2156 | task->startTimer(std::chrono::minutes(5)); |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2157 | task->payload.emplace(std::move(payload)); |
| Chinmay Shripad Hegde | 29e2bdd | 2025-06-06 16:23:47 +0530 | [diff] [blame] | 2158 | task->populateResp(asyncResp->res); |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2159 | }; |
| 2160 | |
| Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 2161 | dbus::utility::async_method_call( |
| 2162 | asyncResp, std::move(collectCrashdumpCallback), |
| 2163 | crashdumpObject, crashdumpPath, iface, method); |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2164 | }); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2165 | } |
| Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2166 | } // namespace redfish |