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