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)); |
| 937 | task->populateResp(asyncResp->res); |
| 938 | task->payload.emplace(payload); |
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 | } |
| 1095 | }, |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 1096 | "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType), |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 1097 | "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); |
Asmitha Karunanithi | 80319af | 2020-05-07 05:30:21 -0500 | [diff] [blame] | 1098 | } |
| 1099 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1100 | inline void parseCrashdumpParameters( |
| 1101 | const dbus::utility::DBusPropertiesMap& params, std::string& filename, |
| 1102 | std::string& timestamp, std::string& logfile) |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 1103 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1104 | const std::string* filenamePtr = nullptr; |
| 1105 | const std::string* timestampPtr = nullptr; |
| 1106 | const std::string* logfilePtr = nullptr; |
| 1107 | |
| 1108 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 1109 | dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr, |
| 1110 | "Filename", filenamePtr, "Log", logfilePtr); |
| 1111 | |
| 1112 | if (!success) |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 1113 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1114 | return; |
| 1115 | } |
| 1116 | |
| 1117 | if (filenamePtr != nullptr) |
| 1118 | { |
| 1119 | filename = *filenamePtr; |
| 1120 | } |
| 1121 | |
| 1122 | if (timestampPtr != nullptr) |
| 1123 | { |
| 1124 | timestamp = *timestampPtr; |
| 1125 | } |
| 1126 | |
| 1127 | if (logfilePtr != nullptr) |
| 1128 | { |
| 1129 | logfile = *logfilePtr; |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1133 | inline void requestRoutesSystemLogServiceCollection(App& app) |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 1134 | { |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1135 | /** |
| 1136 | * Functions triggers appropriate requests on DBus |
| 1137 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1138 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1139 | .privileges(redfish::privileges::getLogServiceCollection) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1140 | .methods( |
| 1141 | boost::beast::http::verb:: |
| 1142 | get)([&app](const crow::Request& req, |
| 1143 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1144 | const std::string& systemName) { |
| 1145 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1146 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1147 | return; |
| 1148 | } |
| 1149 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1150 | { |
| 1151 | // Option currently returns no systems. TBD |
| 1152 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1153 | systemName); |
| 1154 | return; |
| 1155 | } |
| 1156 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1157 | { |
| 1158 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1159 | systemName); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1160 | return; |
| 1161 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1162 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1163 | // Collections don't include the static data added by SubRoute |
| 1164 | // because it has a duplicate entry for members |
| 1165 | asyncResp->res.jsonValue["@odata.type"] = |
| 1166 | "#LogServiceCollection.LogServiceCollection"; |
| 1167 | asyncResp->res.jsonValue["@odata.id"] = |
| 1168 | std::format("/redfish/v1/Systems/{}/LogServices", |
| 1169 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1170 | asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; |
| 1171 | asyncResp->res.jsonValue["Description"] = |
| 1172 | "Collection of LogServices for this Computer System"; |
| 1173 | nlohmann::json& logServiceArray = |
| 1174 | asyncResp->res.jsonValue["Members"]; |
| 1175 | logServiceArray = nlohmann::json::array(); |
| 1176 | nlohmann::json::object_t eventLog; |
| 1177 | eventLog["@odata.id"] = |
| 1178 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog", |
| 1179 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1180 | logServiceArray.emplace_back(std::move(eventLog)); |
| 1181 | if constexpr (BMCWEB_REDFISH_DUMP_LOG) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1182 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1183 | nlohmann::json::object_t dumpLog; |
| 1184 | dumpLog["@odata.id"] = |
| 1185 | std::format("/redfish/v1/Systems/{}/LogServices/Dump", |
| 1186 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1187 | logServiceArray.emplace_back(std::move(dumpLog)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1188 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1189 | |
| 1190 | if constexpr (BMCWEB_REDFISH_CPU_LOG) |
| 1191 | { |
| 1192 | nlohmann::json::object_t crashdump; |
| 1193 | crashdump["@odata.id"] = |
| 1194 | std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", |
| 1195 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1196 | logServiceArray.emplace_back(std::move(crashdump)); |
| 1197 | } |
| 1198 | |
| 1199 | if constexpr (BMCWEB_REDFISH_HOST_LOGGER) |
| 1200 | { |
| 1201 | nlohmann::json::object_t hostlogger; |
| 1202 | hostlogger["@odata.id"] = |
| 1203 | std::format("/redfish/v1/Systems/{}/LogServices/HostLogger", |
| 1204 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1205 | logServiceArray.emplace_back(std::move(hostlogger)); |
| 1206 | } |
| 1207 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1208 | logServiceArray.size(); |
| 1209 | |
| 1210 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1211 | "xyz.openbmc_project.State.Boot.PostCode"}; |
| 1212 | dbus::utility::getSubTreePaths( |
| 1213 | "/", 0, interfaces, |
| 1214 | [asyncResp](const boost::system::error_code& ec, |
| 1215 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 1216 | subtreePath) { |
| 1217 | if (ec) |
| 1218 | { |
| 1219 | BMCWEB_LOG_ERROR("{}", ec); |
| 1220 | return; |
| 1221 | } |
| 1222 | |
| 1223 | for (const auto& pathStr : subtreePath) |
| 1224 | { |
| 1225 | if (pathStr.find("PostCode") != std::string::npos) |
| 1226 | { |
| 1227 | nlohmann::json& logServiceArrayLocal = |
| 1228 | asyncResp->res.jsonValue["Members"]; |
| 1229 | nlohmann::json::object_t member; |
| 1230 | member["@odata.id"] = std::format( |
| 1231 | "/redfish/v1/Systems/{}/LogServices/PostCodes", |
| 1232 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1233 | |
| 1234 | logServiceArrayLocal.emplace_back( |
| 1235 | std::move(member)); |
| 1236 | |
| 1237 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1238 | logServiceArrayLocal.size(); |
| 1239 | return; |
| 1240 | } |
| 1241 | } |
| 1242 | }); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1243 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | inline void requestRoutesEventLogService(App& app) |
| 1247 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1248 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1249 | .privileges(redfish::privileges::getLogService) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1250 | .methods( |
| 1251 | boost::beast::http::verb:: |
| 1252 | get)([&app](const crow::Request& req, |
| 1253 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1254 | const std::string& systemName) { |
| 1255 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1256 | { |
| 1257 | return; |
| 1258 | } |
| 1259 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1260 | { |
| 1261 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1262 | systemName); |
| 1263 | return; |
| 1264 | } |
| 1265 | asyncResp->res.jsonValue["@odata.id"] = |
| 1266 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog", |
| 1267 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1268 | asyncResp->res.jsonValue["@odata.type"] = |
| 1269 | "#LogService.v1_2_0.LogService"; |
| 1270 | asyncResp->res.jsonValue["Name"] = "Event Log Service"; |
| 1271 | asyncResp->res.jsonValue["Description"] = |
| 1272 | "System Event Log Service"; |
| 1273 | asyncResp->res.jsonValue["Id"] = "EventLog"; |
| 1274 | asyncResp->res.jsonValue["OverWritePolicy"] = |
| 1275 | log_service::OverWritePolicy::WrapsWhenFull; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1276 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1277 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| 1278 | redfish::time_utils::getDateTimeOffsetNow(); |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1279 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1280 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 1281 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 1282 | redfishDateTimeOffset.second; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1283 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1284 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format( |
| 1285 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries", |
Ed Tanous | 20fa6a2 | 2024-05-20 18:02:58 -0700 | [diff] [blame] | 1286 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1287 | asyncResp->res |
| 1288 | .jsonValue["Actions"]["#LogService.ClearLog"]["target"] |
| 1289 | |
| 1290 | = std::format( |
| 1291 | "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog", |
| 1292 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1293 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1296 | inline void handleSystemsLogServicesEventLogActionsClearPost( |
| 1297 | App& app, const crow::Request& req, |
| 1298 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1299 | const std::string& systemName) |
| 1300 | { |
| 1301 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1302 | { |
| 1303 | return; |
| 1304 | } |
| 1305 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1306 | { |
| 1307 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1308 | systemName); |
| 1309 | return; |
| 1310 | } |
| 1311 | |
| 1312 | // Clear the EventLog by deleting the log files |
| 1313 | std::vector<std::filesystem::path> redfishLogFiles; |
| 1314 | if (getRedfishLogFiles(redfishLogFiles)) |
| 1315 | { |
| 1316 | for (const std::filesystem::path& file : redfishLogFiles) |
| 1317 | { |
| 1318 | std::error_code ec; |
| 1319 | std::filesystem::remove(file, ec); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | // Reload rsyslog so it knows to start new log files |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 1324 | dbus::utility::async_method_call( |
| 1325 | asyncResp, |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1326 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1327 | if (ec) |
| 1328 | { |
| 1329 | BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec); |
| 1330 | messages::internalError(asyncResp->res); |
| 1331 | return; |
| 1332 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1333 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1334 | messages::success(asyncResp->res); |
| 1335 | }, |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1336 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 1337 | "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", |
| 1338 | "replace"); |
| 1339 | } |
| 1340 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1341 | inline void requestRoutesJournalEventLogClear(App& app) |
| 1342 | { |
Jason M. Bills | 4978b63 | 2022-02-22 14:17:43 -0800 | [diff] [blame] | 1343 | BMCWEB_ROUTE( |
| 1344 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1345 | "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 1346 | .privileges({{"ConfigureComponents"}}) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1347 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 1348 | handleSystemsLogServicesEventLogActionsClearPost, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1349 | } |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1350 | |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1351 | enum class LogParseError |
| 1352 | { |
| 1353 | success, |
| 1354 | parseFailed, |
| 1355 | messageIdNotInRegistry, |
| 1356 | }; |
| 1357 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1358 | static LogParseError fillEventLogEntryJson( |
| 1359 | const std::string& logEntryID, const std::string& logEntry, |
| 1360 | nlohmann::json::object_t& logEntryJson) |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1361 | { |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1362 | // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1363 | // First get the Timestamp |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 1364 | size_t space = logEntry.find_first_of(' '); |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1365 | if (space == std::string::npos) |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1366 | { |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1367 | return LogParseError::parseFailed; |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1368 | } |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1369 | std::string timestamp = logEntry.substr(0, space); |
| 1370 | // Then get the log contents |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 1371 | size_t entryStart = logEntry.find_first_not_of(' ', space); |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1372 | if (entryStart == std::string::npos) |
| 1373 | { |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1374 | return LogParseError::parseFailed; |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1375 | } |
| 1376 | std::string_view entry(logEntry); |
| 1377 | entry.remove_prefix(entryStart); |
| 1378 | // Use split to separate the entry into its fields |
| 1379 | std::vector<std::string> logEntryFields; |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 1380 | bmcweb::split(logEntryFields, entry, ','); |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1381 | // We need at least a MessageId to be valid |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1382 | auto logEntryIter = logEntryFields.begin(); |
| 1383 | if (logEntryIter == logEntryFields.end()) |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1384 | { |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1385 | return LogParseError::parseFailed; |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1386 | } |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1387 | std::string& messageID = *logEntryIter; |
Jason M. Bills | 4851d45 | 2019-03-28 11:27:48 -0700 | [diff] [blame] | 1388 | // Get the Message from the MessageRegistry |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 1389 | const registries::Message* message = registries::getMessage(messageID); |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1390 | |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1391 | logEntryIter++; |
Sui Chen | 54417b0 | 2022-03-24 14:59:52 -0700 | [diff] [blame] | 1392 | if (message == nullptr) |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1393 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1394 | BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry); |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1395 | return LogParseError::messageIdNotInRegistry; |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1396 | } |
| 1397 | |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1398 | std::vector<std::string_view> messageArgs(logEntryIter, |
| 1399 | logEntryFields.end()); |
Ed Tanous | c05bba4 | 2023-06-28 08:33:29 -0700 | [diff] [blame] | 1400 | messageArgs.resize(message->numberOfArgs); |
| 1401 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1402 | std::string msg = |
| 1403 | redfish::registries::fillMessageArgs(messageArgs, message->message); |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1404 | if (msg.empty()) |
Jason M. Bills | 4851d45 | 2019-03-28 11:27:48 -0700 | [diff] [blame] | 1405 | { |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1406 | return LogParseError::parseFailed; |
Jason M. Bills | 4851d45 | 2019-03-28 11:27:48 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1409 | // Get the Created time from the timestamp. The log timestamp is in RFC3339 |
| 1410 | // format which matches the Redfish format except for the fractional seconds |
| 1411 | // between the '.' and the '+', so just remove them. |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 1412 | std::size_t dot = timestamp.find_first_of('.'); |
| 1413 | std::size_t plus = timestamp.find_first_of('+'); |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1414 | if (dot != std::string::npos && plus != std::string::npos) |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1415 | { |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1416 | timestamp.erase(dot, plus - dot); |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | // Fill in the log entry with the gathered data |
Vijay Lobo | 9c11a17 | 2021-10-07 16:53:16 -0500 | [diff] [blame] | 1420 | logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 1421 | logEntryJson["@odata.id"] = boost::urls::format( |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1422 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}", |
| 1423 | BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID); |
Jason M. Bills | 84afc48 | 2022-06-24 12:38:23 -0700 | [diff] [blame] | 1424 | logEntryJson["Name"] = "System Event Log Entry"; |
| 1425 | logEntryJson["Id"] = logEntryID; |
| 1426 | logEntryJson["Message"] = std::move(msg); |
| 1427 | logEntryJson["MessageId"] = std::move(messageID); |
| 1428 | logEntryJson["MessageArgs"] = messageArgs; |
| 1429 | logEntryJson["EntryType"] = "Event"; |
| 1430 | logEntryJson["Severity"] = message->messageSeverity; |
| 1431 | logEntryJson["Created"] = std::move(timestamp); |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1432 | return LogParseError::success; |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1433 | } |
| 1434 | |
Igor Kanyuka | 9089660 | 2025-03-13 08:52:38 +0000 | [diff] [blame] | 1435 | inline bool fillEventLogLogEntryFromPropertyMap( |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1436 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1437 | const dbus::utility::DBusPropertiesMap& resp, |
| 1438 | nlohmann::json& objectToFillOut) |
| 1439 | { |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1440 | std::optional<DbusEventLogEntry> optEntry = |
| 1441 | fillDbusEventLogEntryFromPropertyMap(resp); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1442 | |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1443 | if (!optEntry.has_value()) |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1444 | { |
| 1445 | messages::internalError(asyncResp->res); |
Igor Kanyuka | 9089660 | 2025-03-13 08:52:38 +0000 | [diff] [blame] | 1446 | return false; |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1447 | } |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1448 | DbusEventLogEntry entry = optEntry.value(); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1449 | |
| 1450 | objectToFillOut["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
| 1451 | objectToFillOut["@odata.id"] = boost::urls::format( |
| 1452 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}", |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1453 | BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id)); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1454 | objectToFillOut["Name"] = "System Event Log Entry"; |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1455 | objectToFillOut["Id"] = std::to_string(entry.Id); |
| 1456 | objectToFillOut["Message"] = entry.Message; |
| 1457 | objectToFillOut["Resolved"] = entry.Resolved; |
| 1458 | std::optional<bool> notifyAction = |
| 1459 | getProviderNotifyAction(entry.ServiceProviderNotify); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1460 | if (notifyAction) |
| 1461 | { |
| 1462 | objectToFillOut["ServiceProviderNotified"] = *notifyAction; |
| 1463 | } |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1464 | if ((entry.Resolution != nullptr) && !entry.Resolution->empty()) |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1465 | { |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1466 | objectToFillOut["Resolution"] = *entry.Resolution; |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1467 | } |
| 1468 | objectToFillOut["EntryType"] = "Event"; |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1469 | objectToFillOut["Severity"] = |
| 1470 | translateSeverityDbusToRedfish(entry.Severity); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1471 | objectToFillOut["Created"] = |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1472 | redfish::time_utils::getDateTimeUintMs(entry.Timestamp); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1473 | objectToFillOut["Modified"] = |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1474 | redfish::time_utils::getDateTimeUintMs(entry.UpdateTimestamp); |
| 1475 | if (entry.Path != nullptr) |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1476 | { |
| 1477 | objectToFillOut["AdditionalDataURI"] = boost::urls::format( |
| 1478 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment", |
Alexander Hansen | 262dcc1 | 2024-09-19 12:04:03 +0200 | [diff] [blame] | 1479 | BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id)); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1480 | } |
Igor Kanyuka | 9089660 | 2025-03-13 08:52:38 +0000 | [diff] [blame] | 1481 | return true; |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1484 | inline void afterLogEntriesGetManagedObjects( |
| 1485 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1486 | const boost::system::error_code& ec, |
| 1487 | const dbus::utility::ManagedObjectType& resp) |
| 1488 | { |
| 1489 | if (ec) |
| 1490 | { |
| 1491 | // TODO Handle for specific error code |
| 1492 | BMCWEB_LOG_ERROR("getLogEntriesIfaceData resp_handler got error {}", |
| 1493 | ec); |
| 1494 | messages::internalError(asyncResp->res); |
| 1495 | return; |
| 1496 | } |
| 1497 | nlohmann::json::array_t entriesArray; |
| 1498 | for (const auto& objectPath : resp) |
| 1499 | { |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1500 | dbus::utility::DBusPropertiesMap propsFlattened; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1501 | auto isEntry = |
| 1502 | std::ranges::find_if(objectPath.second, [](const auto& object) { |
| 1503 | return object.first == "xyz.openbmc_project.Logging.Entry"; |
| 1504 | }); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1505 | if (isEntry == objectPath.second.end()) |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1506 | { |
| 1507 | continue; |
| 1508 | } |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1509 | for (const auto& interfaceMap : objectPath.second) |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1510 | { |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1511 | for (const auto& propertyMap : interfaceMap.second) |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1512 | { |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1513 | propsFlattened.emplace_back(propertyMap.first, |
| 1514 | propertyMap.second); |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1515 | } |
| 1516 | } |
Igor Kanyuka | 9089660 | 2025-03-13 08:52:38 +0000 | [diff] [blame] | 1517 | bool success = fillEventLogLogEntryFromPropertyMap( |
| 1518 | asyncResp, propsFlattened, entriesArray.emplace_back()); |
| 1519 | if (!success) |
| 1520 | { |
| 1521 | return; |
| 1522 | } |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1523 | } |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1524 | |
Igor Kanyuka | 9089660 | 2025-03-13 08:52:38 +0000 | [diff] [blame] | 1525 | redfish::json_util::sortJsonArrayByKey(entriesArray, "Id"); |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1526 | asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size(); |
| 1527 | asyncResp->res.jsonValue["Members"] = std::move(entriesArray); |
| 1528 | } |
| 1529 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1530 | inline void handleSystemsLogServiceEventLogLogEntryCollection( |
| 1531 | App& app, const crow::Request& req, |
| 1532 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1533 | const std::string& systemName) |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1534 | { |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1535 | query_param::QueryCapabilities capabilities = { |
| 1536 | .canDelegateTop = true, |
| 1537 | .canDelegateSkip = true, |
| 1538 | }; |
| 1539 | query_param::Query delegatedQuery; |
| 1540 | if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp, |
| 1541 | delegatedQuery, capabilities)) |
| 1542 | { |
| 1543 | return; |
| 1544 | } |
| 1545 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1546 | { |
| 1547 | // Option currently returns no systems. TBD |
| 1548 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1549 | systemName); |
| 1550 | return; |
| 1551 | } |
| 1552 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1553 | { |
| 1554 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1555 | systemName); |
| 1556 | return; |
| 1557 | } |
| 1558 | |
| 1559 | size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); |
| 1560 | size_t skip = delegatedQuery.skip.value_or(0); |
| 1561 | |
| 1562 | // Collections don't include the static data added by SubRoute |
| 1563 | // because it has a duplicate entry for members |
| 1564 | asyncResp->res.jsonValue["@odata.type"] = |
| 1565 | "#LogEntryCollection.LogEntryCollection"; |
| 1566 | asyncResp->res.jsonValue["@odata.id"] = |
| 1567 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries", |
| 1568 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1569 | asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; |
| 1570 | asyncResp->res.jsonValue["Description"] = |
| 1571 | "Collection of System Event Log Entries"; |
| 1572 | |
| 1573 | nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; |
| 1574 | logEntryArray = nlohmann::json::array(); |
| 1575 | // Go through the log files and create a unique ID for each |
| 1576 | // entry |
| 1577 | std::vector<std::filesystem::path> redfishLogFiles; |
| 1578 | getRedfishLogFiles(redfishLogFiles); |
| 1579 | uint64_t entryCount = 0; |
| 1580 | std::string logEntry; |
| 1581 | |
| 1582 | // Oldest logs are in the last file, so start there and loop |
| 1583 | // backwards |
| 1584 | for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++) |
| 1585 | { |
| 1586 | std::ifstream logStream(*it); |
| 1587 | if (!logStream.is_open()) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1588 | { |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1589 | continue; |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1592 | // Reset the unique ID on the first entry |
| 1593 | bool firstEntry = true; |
| 1594 | while (std::getline(logStream, logEntry)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1595 | { |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1596 | std::string idStr; |
| 1597 | if (!getUniqueEntryID(logEntry, idStr, firstEntry)) |
| 1598 | { |
| 1599 | continue; |
| 1600 | } |
| 1601 | firstEntry = false; |
| 1602 | |
| 1603 | nlohmann::json::object_t bmcLogEntry; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1604 | LogParseError status = |
| 1605 | fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1606 | if (status == LogParseError::messageIdNotInRegistry) |
| 1607 | { |
| 1608 | continue; |
| 1609 | } |
| 1610 | if (status != LogParseError::success) |
| 1611 | { |
| 1612 | messages::internalError(asyncResp->res); |
| 1613 | return; |
| 1614 | } |
| 1615 | |
| 1616 | entryCount++; |
| 1617 | // Handle paging using skip (number of entries to skip from the |
| 1618 | // start) and top (number of entries to display) |
| 1619 | if (entryCount <= skip || entryCount > skip + top) |
Jason M. Bills | 4978b63 | 2022-02-22 14:17:43 -0800 | [diff] [blame] | 1620 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1621 | continue; |
Jason M. Bills | 4978b63 | 2022-02-22 14:17:43 -0800 | [diff] [blame] | 1622 | } |
Jason M. Bills | 897967d | 2019-07-29 17:05:30 -0700 | [diff] [blame] | 1623 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1624 | logEntryArray.emplace_back(std::move(bmcLogEntry)); |
| 1625 | } |
| 1626 | } |
| 1627 | asyncResp->res.jsonValue["Members@odata.count"] = entryCount; |
| 1628 | if (skip + top < entryCount) |
| 1629 | { |
| 1630 | asyncResp->res.jsonValue["Members@odata.nextLink"] = |
| 1631 | boost::urls::format( |
| 1632 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}", |
| 1633 | BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top)); |
| 1634 | } |
| 1635 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1636 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1637 | inline void requestRoutesJournalEventLogEntryCollection(App& app) |
| 1638 | { |
| 1639 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") |
| 1640 | .privileges(redfish::privileges::getLogEntryCollection) |
| 1641 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1642 | handleSystemsLogServiceEventLogLogEntryCollection, std::ref(app))); |
| 1643 | } |
| 1644 | |
| 1645 | inline void handleSystemsLogServiceEventLogEntriesGet( |
| 1646 | App& app, const crow::Request& req, |
| 1647 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1648 | const std::string& systemName, const std::string& param) |
| 1649 | { |
| 1650 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1651 | { |
| 1652 | return; |
| 1653 | } |
| 1654 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1655 | { |
| 1656 | // Option currently returns no systems. TBD |
| 1657 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1658 | systemName); |
| 1659 | return; |
| 1660 | } |
| 1661 | |
| 1662 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1663 | { |
| 1664 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1665 | systemName); |
| 1666 | return; |
| 1667 | } |
| 1668 | |
| 1669 | const std::string& targetID = param; |
| 1670 | |
| 1671 | // Go through the log files and check the unique ID for each |
| 1672 | // entry to find the target entry |
| 1673 | std::vector<std::filesystem::path> redfishLogFiles; |
| 1674 | getRedfishLogFiles(redfishLogFiles); |
| 1675 | std::string logEntry; |
| 1676 | |
| 1677 | // Oldest logs are in the last file, so start there and loop |
| 1678 | // backwards |
| 1679 | for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++) |
| 1680 | { |
| 1681 | std::ifstream logStream(*it); |
| 1682 | if (!logStream.is_open()) |
| 1683 | { |
| 1684 | continue; |
| 1685 | } |
| 1686 | |
| 1687 | // Reset the unique ID on the first entry |
| 1688 | bool firstEntry = true; |
| 1689 | while (std::getline(logStream, logEntry)) |
| 1690 | { |
| 1691 | std::string idStr; |
| 1692 | if (!getUniqueEntryID(logEntry, idStr, firstEntry)) |
| 1693 | { |
| 1694 | continue; |
| 1695 | } |
| 1696 | firstEntry = false; |
| 1697 | |
| 1698 | if (idStr == targetID) |
| 1699 | { |
Jason M. Bills | de703c5 | 2022-06-23 14:19:04 -0700 | [diff] [blame] | 1700 | nlohmann::json::object_t bmcLogEntry; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1701 | LogParseError status = |
| 1702 | fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1703 | if (status != LogParseError::success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1704 | { |
| 1705 | messages::internalError(asyncResp->res); |
| 1706 | return; |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 1707 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1708 | asyncResp->res.jsonValue.update(bmcLogEntry); |
| 1709 | return; |
Jason M. Bills | 4978b63 | 2022-02-22 14:17:43 -0800 | [diff] [blame] | 1710 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1711 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1712 | } |
| 1713 | // Requested ID was not found |
| 1714 | messages::resourceNotFound(asyncResp->res, "LogEntry", targetID); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1715 | } |
Chicago Duan | 336e96c | 2019-07-15 14:22:08 +0800 | [diff] [blame] | 1716 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1717 | inline void requestRoutesJournalEventLogEntry(App& app) |
| 1718 | { |
| 1719 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1720 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1721 | .privileges(redfish::privileges::getLogEntry) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1722 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1723 | handleSystemsLogServiceEventLogEntriesGet, std::ref(app))); |
| 1724 | } |
| 1725 | |
| 1726 | inline void dBusEventLogEntryCollection( |
| 1727 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1728 | { |
| 1729 | // Collections don't include the static data added by SubRoute |
| 1730 | // because it has a duplicate entry for members |
| 1731 | asyncResp->res.jsonValue["@odata.type"] = |
| 1732 | "#LogEntryCollection.LogEntryCollection"; |
| 1733 | asyncResp->res.jsonValue["@odata.id"] = |
| 1734 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries", |
| 1735 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1736 | asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; |
| 1737 | asyncResp->res.jsonValue["Description"] = |
| 1738 | "Collection of System Event Log Entries"; |
| 1739 | |
| 1740 | // DBus implementation of EventLog/Entries |
| 1741 | // Make call to Logging Service to find all log entry objects |
| 1742 | sdbusplus::message::object_path path("/xyz/openbmc_project/logging"); |
| 1743 | dbus::utility::getManagedObjects( |
| 1744 | "xyz.openbmc_project.Logging", path, |
| 1745 | [asyncResp](const boost::system::error_code& ec, |
| 1746 | const dbus::utility::ManagedObjectType& resp) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1747 | afterLogEntriesGetManagedObjects(asyncResp, ec, resp); |
| 1748 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | inline void requestRoutesDBusEventLogEntryCollection(App& app) |
| 1752 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1753 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1754 | .privileges(redfish::privileges::getLogEntryCollection) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1755 | .methods(boost::beast::http::verb::get)( |
| 1756 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1757 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1758 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1759 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1760 | { |
| 1761 | return; |
| 1762 | } |
| 1763 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1764 | { |
| 1765 | // Option currently returns no systems. TBD |
| 1766 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1767 | systemName); |
| 1768 | return; |
| 1769 | } |
| 1770 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1771 | { |
| 1772 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1773 | systemName); |
| 1774 | return; |
| 1775 | } |
| 1776 | dBusEventLogEntryCollection(asyncResp); |
| 1777 | }); |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1778 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1779 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1780 | inline void dBusEventLogEntryGet( |
| 1781 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1782 | { |
| 1783 | dbus::utility::escapePathForDbus(entryID); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1784 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1785 | // DBus implementation of EventLog/Entries |
| 1786 | // Make call to Logging Service to find all log entry objects |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1787 | dbus::utility::getAllProperties( |
| 1788 | "xyz.openbmc_project.Logging", |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1789 | "/xyz/openbmc_project/logging/entry/" + entryID, "", |
| 1790 | [asyncResp, entryID](const boost::system::error_code& ec, |
| 1791 | const dbus::utility::DBusPropertiesMap& resp) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1792 | if (ec.value() == EBADR) |
| 1793 | { |
| 1794 | messages::resourceNotFound(asyncResp->res, "EventLogEntry", |
| 1795 | entryID); |
| 1796 | return; |
| 1797 | } |
| 1798 | if (ec) |
| 1799 | { |
| 1800 | BMCWEB_LOG_ERROR( |
| 1801 | "EventLogEntry (DBus) resp_handler got error {}", ec); |
| 1802 | messages::internalError(asyncResp->res); |
| 1803 | return; |
| 1804 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1805 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1806 | fillEventLogLogEntryFromPropertyMap(asyncResp, resp, |
| 1807 | asyncResp->res.jsonValue); |
| 1808 | }); |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1809 | } |
| 1810 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1811 | inline void dBusEventLogEntryPatch( |
| 1812 | const crow::Request& req, |
| 1813 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1814 | const std::string& entryId) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1815 | { |
| 1816 | std::optional<bool> resolved; |
| 1817 | |
| 1818 | if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", resolved)) |
| 1819 | { |
| 1820 | return; |
| 1821 | } |
| 1822 | BMCWEB_LOG_DEBUG("Set Resolved"); |
| 1823 | |
| 1824 | setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging", |
| 1825 | "/xyz/openbmc_project/logging/entry/" + entryId, |
| 1826 | "xyz.openbmc_project.Logging.Entry", "Resolved", |
| 1827 | resolved.value_or(false)); |
| 1828 | } |
| 1829 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1830 | inline void dBusEventLogEntryDelete( |
| 1831 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1832 | { |
| 1833 | BMCWEB_LOG_DEBUG("Do delete single event entries."); |
| 1834 | |
| 1835 | dbus::utility::escapePathForDbus(entryID); |
| 1836 | |
| 1837 | // Process response from Logging service. |
| 1838 | auto respHandler = [asyncResp, |
| 1839 | entryID](const boost::system::error_code& ec) { |
| 1840 | BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done"); |
| 1841 | if (ec) |
| 1842 | { |
| 1843 | if (ec.value() == EBADR) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1844 | { |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1845 | messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1846 | return; |
| 1847 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1848 | // TODO Handle for specific error code |
| 1849 | BMCWEB_LOG_ERROR( |
| 1850 | "EventLogEntry (DBus) doDelete respHandler got error {}", ec); |
| 1851 | asyncResp->res.result( |
| 1852 | boost::beast::http::status::internal_server_error); |
| 1853 | return; |
| 1854 | } |
Abhishek Patel | 9017faf | 2021-09-14 22:48:55 -0500 | [diff] [blame] | 1855 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1856 | asyncResp->res.result(boost::beast::http::status::ok); |
| 1857 | }; |
| 1858 | |
| 1859 | // Make call to Logging service to request Delete Log |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 1860 | dbus::utility::async_method_call( |
| 1861 | asyncResp, respHandler, "xyz.openbmc_project.Logging", |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1862 | "/xyz/openbmc_project/logging/entry/" + entryID, |
| 1863 | "xyz.openbmc_project.Object.Delete", "Delete"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1864 | } |
Xiaochao Ma | 75710de | 2021-01-21 17:56:02 +0800 | [diff] [blame] | 1865 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1866 | inline void requestRoutesDBusEventLogEntry(App& app) |
Adriana Kobylak | 400fd1f | 2021-01-29 09:01:30 -0600 | [diff] [blame] | 1867 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1868 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1869 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1870 | .privileges(redfish::privileges::getLogEntry) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1871 | .methods(boost::beast::http::verb::get)( |
| 1872 | [&app](const crow::Request& req, |
| 1873 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1874 | const std::string& systemName, const std::string& entryId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1875 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1876 | { |
| 1877 | return; |
| 1878 | } |
| 1879 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1880 | { |
| 1881 | // Option currently returns no systems. TBD |
| 1882 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1883 | systemName); |
| 1884 | return; |
| 1885 | } |
| 1886 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1887 | { |
| 1888 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1889 | systemName); |
| 1890 | return; |
| 1891 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1892 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1893 | dBusEventLogEntryGet(asyncResp, entryId); |
| 1894 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1895 | |
| 1896 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1897 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1898 | .privileges(redfish::privileges::patchLogEntry) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1899 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1900 | [&app](const crow::Request& req, |
| 1901 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1902 | const std::string& systemName, const std::string& entryId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1903 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1904 | { |
| 1905 | return; |
| 1906 | } |
| 1907 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1908 | { |
| 1909 | // Option currently returns no systems. TBD |
| 1910 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1911 | systemName); |
| 1912 | return; |
| 1913 | } |
| 1914 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1915 | { |
| 1916 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1917 | systemName); |
| 1918 | return; |
| 1919 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1920 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1921 | dBusEventLogEntryPatch(req, asyncResp, entryId); |
| 1922 | }); |
Adriana Kobylak | 400fd1f | 2021-01-29 09:01:30 -0600 | [diff] [blame] | 1923 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1924 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1925 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1926 | .privileges(redfish::privileges::deleteLogEntry) |
| 1927 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1928 | .methods(boost::beast::http::verb::delete_)( |
| 1929 | [&app](const crow::Request& req, |
| 1930 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1931 | const std::string& systemName, const std::string& param) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1932 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1933 | { |
| 1934 | return; |
| 1935 | } |
| 1936 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1937 | { |
| 1938 | // Option currently returns no systems. TBD |
| 1939 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1940 | systemName); |
| 1941 | return; |
| 1942 | } |
| 1943 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1944 | { |
| 1945 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1946 | systemName); |
| 1947 | return; |
| 1948 | } |
| 1949 | dBusEventLogEntryDelete(asyncResp, param); |
| 1950 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Claire Weinan | dd72e87 | 2022-08-15 14:20:06 -0700 | [diff] [blame] | 1953 | inline void handleBMCLogServicesCollectionGet( |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1954 | crow::App& app, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1955 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1956 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1957 | { |
| 1958 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1959 | { |
| 1960 | return; |
| 1961 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1962 | |
| 1963 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 1964 | { |
| 1965 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 1966 | return; |
| 1967 | } |
| 1968 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1969 | // Collections don't include the static data added by SubRoute |
| 1970 | // because it has a duplicate entry for members |
| 1971 | asyncResp->res.jsonValue["@odata.type"] = |
| 1972 | "#LogServiceCollection.LogServiceCollection"; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1973 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 1974 | "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1975 | asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; |
| 1976 | asyncResp->res.jsonValue["Description"] = |
| 1977 | "Collection of LogServices for this Manager"; |
| 1978 | nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; |
| 1979 | logServiceArray = nlohmann::json::array(); |
| 1980 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1981 | if constexpr (BMCWEB_REDFISH_BMC_JOURNAL) |
| 1982 | { |
| 1983 | nlohmann::json::object_t journal; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1984 | journal["@odata.id"] = |
| 1985 | boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal", |
| 1986 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1987 | logServiceArray.emplace_back(std::move(journal)); |
| 1988 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 1989 | |
| 1990 | asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); |
| 1991 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1992 | if constexpr (BMCWEB_REDFISH_DUMP_LOG) |
| 1993 | { |
| 1994 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1995 | "xyz.openbmc_project.Collection.DeleteAll"}; |
| 1996 | dbus::utility::getSubTreePaths( |
| 1997 | "/xyz/openbmc_project/dump", 0, interfaces, |
| 1998 | [asyncResp](const boost::system::error_code& ec, |
| 1999 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 2000 | subTreePaths) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2001 | if (ec) |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2002 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2003 | BMCWEB_LOG_ERROR( |
| 2004 | "handleBMCLogServicesCollectionGet respHandler got error {}", |
| 2005 | ec); |
| 2006 | // Assume that getting an error simply means there are no |
| 2007 | // dump LogServices. Return without adding any error |
| 2008 | // response. |
| 2009 | return; |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2010 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2011 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2012 | nlohmann::json& logServiceArrayLocal = |
| 2013 | asyncResp->res.jsonValue["Members"]; |
| 2014 | |
| 2015 | for (const std::string& path : subTreePaths) |
| 2016 | { |
| 2017 | if (path == "/xyz/openbmc_project/dump/bmc") |
| 2018 | { |
| 2019 | nlohmann::json::object_t member; |
| 2020 | member["@odata.id"] = boost::urls::format( |
| 2021 | "/redfish/v1/Managers/{}/LogServices/Dump", |
| 2022 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2023 | logServiceArrayLocal.emplace_back(std::move(member)); |
| 2024 | } |
| 2025 | else if (path == "/xyz/openbmc_project/dump/faultlog") |
| 2026 | { |
| 2027 | nlohmann::json::object_t member; |
| 2028 | member["@odata.id"] = boost::urls::format( |
| 2029 | "/redfish/v1/Managers/{}/LogServices/FaultLog", |
| 2030 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2031 | logServiceArrayLocal.emplace_back(std::move(member)); |
| 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 2036 | logServiceArrayLocal.size(); |
| 2037 | }); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2038 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2039 | } |
| 2040 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2041 | inline void requestRoutesBMCLogServiceCollection(App& app) |
| 2042 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2043 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/") |
Gunnar Mills | ad89dcf | 2021-07-30 14:40:11 -0500 | [diff] [blame] | 2044 | .privileges(redfish::privileges::getLogServiceCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2045 | .methods(boost::beast::http::verb::get)( |
Claire Weinan | dd72e87 | 2022-08-15 14:20:06 -0700 | [diff] [blame] | 2046 | std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2047 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2048 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2049 | inline void getDumpServiceInfo( |
| 2050 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2051 | const std::string& dumpType) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2052 | { |
| 2053 | std::string dumpPath; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2054 | log_service::OverWritePolicy overWritePolicy = |
| 2055 | log_service::OverWritePolicy::Invalid; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2056 | bool collectDiagnosticDataSupported = false; |
| 2057 | |
| 2058 | if (dumpType == "BMC") |
| 2059 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2060 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump", |
| 2061 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2062 | overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2063 | collectDiagnosticDataSupported = true; |
| 2064 | } |
| 2065 | else if (dumpType == "FaultLog") |
| 2066 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2067 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog", |
| 2068 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2069 | overWritePolicy = log_service::OverWritePolicy::Unknown; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2070 | collectDiagnosticDataSupported = false; |
| 2071 | } |
| 2072 | else if (dumpType == "System") |
| 2073 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2074 | dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump", |
| 2075 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2076 | overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2077 | collectDiagnosticDataSupported = true; |
| 2078 | } |
| 2079 | else |
| 2080 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2081 | BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}", |
| 2082 | dumpType); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2083 | messages::internalError(asyncResp->res); |
| 2084 | return; |
| 2085 | } |
| 2086 | |
| 2087 | asyncResp->res.jsonValue["@odata.id"] = dumpPath; |
| 2088 | asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; |
| 2089 | asyncResp->res.jsonValue["Name"] = "Dump LogService"; |
| 2090 | asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; |
| 2091 | asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2092 | asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2093 | |
| 2094 | std::pair<std::string, std::string> redfishDateTimeOffset = |
Ed Tanous | 2b82937 | 2022-08-03 14:22:34 -0700 | [diff] [blame] | 2095 | redfish::time_utils::getDateTimeOffsetNow(); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2096 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 2097 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 2098 | redfishDateTimeOffset.second; |
| 2099 | |
| 2100 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2101 | |
| 2102 | if (collectDiagnosticDataSupported) |
| 2103 | { |
| 2104 | asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] |
| 2105 | ["target"] = |
| 2106 | dumpPath + "/Actions/LogService.CollectDiagnosticData"; |
| 2107 | } |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 2108 | |
| 2109 | constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface}; |
| 2110 | dbus::utility::getSubTreePaths( |
| 2111 | "/xyz/openbmc_project/dump", 0, interfaces, |
| 2112 | [asyncResp, dumpType, dumpPath]( |
| 2113 | const boost::system::error_code& ec, |
| 2114 | const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2115 | if (ec) |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 2116 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2117 | BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", |
| 2118 | ec); |
| 2119 | // Assume that getting an error simply means there are no dump |
| 2120 | // LogServices. Return without adding any error response. |
| 2121 | return; |
Claire 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 | std::string dbusDumpPath = getDumpPath(dumpType); |
| 2124 | for (const std::string& path : subTreePaths) |
| 2125 | { |
| 2126 | if (path == dbusDumpPath) |
| 2127 | { |
| 2128 | asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] |
| 2129 | ["target"] = |
| 2130 | dumpPath + "/Actions/LogService.ClearLog"; |
| 2131 | break; |
| 2132 | } |
| 2133 | } |
| 2134 | }); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | inline void handleLogServicesDumpServiceGet( |
| 2138 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2139 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2140 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2141 | { |
| 2142 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2143 | { |
| 2144 | return; |
| 2145 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2146 | |
| 2147 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2148 | { |
| 2149 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2150 | return; |
| 2151 | } |
| 2152 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2153 | getDumpServiceInfo(asyncResp, dumpType); |
| 2154 | } |
| 2155 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2156 | inline void handleLogServicesDumpServiceComputerSystemGet( |
| 2157 | crow::App& app, const crow::Request& req, |
| 2158 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2159 | const std::string& chassisId) |
| 2160 | { |
| 2161 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2162 | { |
| 2163 | return; |
| 2164 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2165 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2166 | { |
| 2167 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 2168 | return; |
| 2169 | } |
| 2170 | getDumpServiceInfo(asyncResp, "System"); |
| 2171 | } |
| 2172 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2173 | inline void handleLogServicesDumpEntriesCollectionGet( |
| 2174 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2175 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2176 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2177 | { |
| 2178 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2179 | { |
| 2180 | return; |
| 2181 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2182 | |
| 2183 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2184 | { |
| 2185 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2186 | return; |
| 2187 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2188 | getDumpEntryCollection(asyncResp, dumpType); |
| 2189 | } |
| 2190 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2191 | inline void handleLogServicesDumpEntriesCollectionComputerSystemGet( |
| 2192 | crow::App& app, const crow::Request& req, |
| 2193 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2194 | const std::string& chassisId) |
| 2195 | { |
| 2196 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2197 | { |
| 2198 | return; |
| 2199 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2200 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2201 | { |
| 2202 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 2203 | return; |
| 2204 | } |
| 2205 | getDumpEntryCollection(asyncResp, "System"); |
| 2206 | } |
| 2207 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2208 | inline void handleLogServicesDumpEntryGet( |
| 2209 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 2210 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2211 | const std::string& managerId, const std::string& dumpId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2212 | { |
| 2213 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2214 | { |
| 2215 | return; |
| 2216 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2217 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2218 | { |
| 2219 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2220 | return; |
| 2221 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2222 | getDumpEntryById(asyncResp, dumpId, dumpType); |
| 2223 | } |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2224 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2225 | inline void handleLogServicesDumpEntryComputerSystemGet( |
| 2226 | crow::App& app, const crow::Request& req, |
| 2227 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2228 | const std::string& chassisId, const std::string& dumpId) |
| 2229 | { |
| 2230 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2231 | { |
| 2232 | return; |
| 2233 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2234 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2235 | { |
| 2236 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 2237 | return; |
| 2238 | } |
| 2239 | getDumpEntryById(asyncResp, dumpId, "System"); |
| 2240 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2241 | |
| 2242 | inline void handleLogServicesDumpEntryDelete( |
| 2243 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 2244 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2245 | const std::string& managerId, const std::string& dumpId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2246 | { |
| 2247 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2248 | { |
| 2249 | return; |
| 2250 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2251 | |
| 2252 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2253 | { |
| 2254 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2255 | return; |
| 2256 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2257 | deleteDumpEntry(asyncResp, dumpId, dumpType); |
| 2258 | } |
| 2259 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2260 | inline void handleLogServicesDumpEntryComputerSystemDelete( |
| 2261 | crow::App& app, const crow::Request& req, |
| 2262 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2263 | const std::string& chassisId, const std::string& dumpId) |
| 2264 | { |
| 2265 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2266 | { |
| 2267 | return; |
| 2268 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2269 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2270 | { |
| 2271 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 2272 | return; |
| 2273 | } |
| 2274 | deleteDumpEntry(asyncResp, dumpId, "System"); |
| 2275 | } |
| 2276 | |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2277 | inline void handleLogServicesDumpEntryDownloadGet( |
| 2278 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 2279 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2280 | const std::string& managerId, const std::string& dumpId) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2281 | { |
| 2282 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2283 | { |
| 2284 | return; |
| 2285 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2286 | |
| 2287 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2288 | { |
| 2289 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2290 | return; |
| 2291 | } |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2292 | downloadDumpEntry(asyncResp, dumpId, dumpType); |
| 2293 | } |
| 2294 | |
| 2295 | inline void handleDBusEventLogEntryDownloadGet( |
| 2296 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 2297 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2298 | const std::string& systemName, const std::string& entryID) |
| 2299 | { |
| 2300 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2301 | { |
| 2302 | return; |
| 2303 | } |
| 2304 | if (!http_helpers::isContentTypeAllowed( |
| 2305 | req.getHeaderValue("Accept"), |
| 2306 | http_helpers::ContentType::OctetStream, true)) |
| 2307 | { |
| 2308 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 2309 | return; |
| 2310 | } |
| 2311 | downloadEventLogEntry(asyncResp, systemName, entryID, dumpType); |
| 2312 | } |
| 2313 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2314 | inline void handleLogServicesDumpCollectDiagnosticDataPost( |
| 2315 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2316 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2317 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2318 | { |
| 2319 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2320 | { |
| 2321 | return; |
| 2322 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2323 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2324 | { |
| 2325 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2326 | return; |
| 2327 | } |
| 2328 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2329 | createDump(asyncResp, req, dumpType); |
| 2330 | } |
| 2331 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2332 | inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost( |
| 2333 | crow::App& app, const crow::Request& req, |
| 2334 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2335 | const std::string& systemName) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2336 | { |
| 2337 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2338 | { |
| 2339 | return; |
| 2340 | } |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2341 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2342 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2343 | { |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2344 | // Option currently returns no systems. TBD |
| 2345 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2346 | systemName); |
| 2347 | return; |
| 2348 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2349 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2350 | { |
| 2351 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2352 | systemName); |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2353 | return; |
| 2354 | } |
| 2355 | createDump(asyncResp, req, "System"); |
| 2356 | } |
| 2357 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2358 | inline void handleLogServicesDumpClearLogPost( |
| 2359 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2360 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2361 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2362 | { |
| 2363 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2364 | { |
| 2365 | return; |
| 2366 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2367 | |
| 2368 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2369 | { |
| 2370 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2371 | return; |
| 2372 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2373 | clearDump(asyncResp, dumpType); |
| 2374 | } |
| 2375 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2376 | inline void handleLogServicesDumpClearLogComputerSystemPost( |
| 2377 | crow::App& app, const crow::Request& req, |
| 2378 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2379 | const std::string& systemName) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2380 | { |
| 2381 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2382 | { |
| 2383 | return; |
| 2384 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2385 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2386 | { |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2387 | // Option currently returns no systems. TBD |
| 2388 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2389 | systemName); |
| 2390 | return; |
| 2391 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2392 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2393 | { |
| 2394 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2395 | systemName); |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2396 | return; |
| 2397 | } |
| 2398 | clearDump(asyncResp, "System"); |
| 2399 | } |
| 2400 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2401 | inline void requestRoutesBMCDumpService(App& app) |
| 2402 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2403 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2404 | .privileges(redfish::privileges::getLogService) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2405 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2406 | handleLogServicesDumpServiceGet, std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | inline void requestRoutesBMCDumpEntryCollection(App& app) |
| 2410 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2411 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2412 | .privileges(redfish::privileges::getLogEntryCollection) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2413 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2414 | handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | inline void requestRoutesBMCDumpEntry(App& app) |
| 2418 | { |
| 2419 | BMCWEB_ROUTE(app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2420 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2421 | .privileges(redfish::privileges::getLogEntry) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2422 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2423 | handleLogServicesDumpEntryGet, std::ref(app), "BMC")); |
| 2424 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 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::deleteLogEntry) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2428 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
| 2429 | handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2432 | inline void requestRoutesBMCDumpEntryDownload(App& app) |
| 2433 | { |
| 2434 | BMCWEB_ROUTE( |
| 2435 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2436 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/") |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2437 | .privileges(redfish::privileges::getLogEntry) |
| 2438 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2439 | handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC")); |
| 2440 | } |
| 2441 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2442 | inline void requestRoutesBMCDumpCreate(App& app) |
| 2443 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2444 | BMCWEB_ROUTE( |
| 2445 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2446 | "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2447 | .privileges(redfish::privileges::postLogService) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2448 | .methods(boost::beast::http::verb::post)( |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2449 | std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, |
| 2450 | std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | inline void requestRoutesBMCDumpClear(App& app) |
| 2454 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2455 | BMCWEB_ROUTE( |
| 2456 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2457 | "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2458 | .privileges(redfish::privileges::postLogService) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2459 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 2460 | handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); |
| 2461 | } |
| 2462 | |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2463 | inline void requestRoutesDBusEventLogEntryDownload(App& app) |
| 2464 | { |
| 2465 | BMCWEB_ROUTE( |
| 2466 | app, |
Ravi Teja | 9e9d99d | 2023-11-08 05:33:59 -0600 | [diff] [blame] | 2467 | "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/") |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2468 | .privileges(redfish::privileges::getLogEntry) |
| 2469 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2470 | handleDBusEventLogEntryDownloadGet, std::ref(app), "System")); |
| 2471 | } |
| 2472 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2473 | inline void requestRoutesFaultLogDumpService(App& app) |
| 2474 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2475 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2476 | .privileges(redfish::privileges::getLogService) |
| 2477 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2478 | handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); |
| 2479 | } |
| 2480 | |
| 2481 | inline void requestRoutesFaultLogDumpEntryCollection(App& app) |
| 2482 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2483 | BMCWEB_ROUTE(app, |
| 2484 | "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2485 | .privileges(redfish::privileges::getLogEntryCollection) |
| 2486 | .methods(boost::beast::http::verb::get)( |
| 2487 | std::bind_front(handleLogServicesDumpEntriesCollectionGet, |
| 2488 | std::ref(app), "FaultLog")); |
| 2489 | } |
| 2490 | |
| 2491 | inline void requestRoutesFaultLogDumpEntry(App& app) |
| 2492 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2493 | BMCWEB_ROUTE( |
| 2494 | app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2495 | .privileges(redfish::privileges::getLogEntry) |
| 2496 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2497 | handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); |
| 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::deleteLogEntry) |
| 2502 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
| 2503 | handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); |
| 2504 | } |
| 2505 | |
| 2506 | inline void requestRoutesFaultLogDumpClear(App& app) |
| 2507 | { |
| 2508 | BMCWEB_ROUTE( |
| 2509 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2510 | "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2511 | .privileges(redfish::privileges::postLogService) |
| 2512 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 2513 | handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | inline void requestRoutesSystemDumpService(App& app) |
| 2517 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2518 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2519 | .privileges(redfish::privileges::getLogService) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2520 | .methods(boost::beast::http::verb::get)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2521 | handleLogServicesDumpServiceComputerSystemGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | inline void requestRoutesSystemDumpEntryCollection(App& app) |
| 2525 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2526 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2527 | .privileges(redfish::privileges::getLogEntryCollection) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2528 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2529 | handleLogServicesDumpEntriesCollectionComputerSystemGet, |
| 2530 | std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | inline void requestRoutesSystemDumpEntry(App& app) |
| 2534 | { |
| 2535 | BMCWEB_ROUTE(app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2536 | "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2537 | .privileges(redfish::privileges::getLogEntry) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2538 | .methods(boost::beast::http::verb::get)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2539 | handleLogServicesDumpEntryComputerSystemGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 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::deleteLogEntry) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2544 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2545 | handleLogServicesDumpEntryComputerSystemDelete, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | inline void requestRoutesSystemDumpCreate(App& app) |
| 2549 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2550 | BMCWEB_ROUTE( |
| 2551 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2552 | "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2553 | .privileges(redfish::privileges::postLogService) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2554 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 2555 | handleLogServicesDumpCollectDiagnosticDataComputerSystemPost, |
| 2556 | std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | inline void requestRoutesSystemDumpClear(App& app) |
| 2560 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2561 | BMCWEB_ROUTE( |
| 2562 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2563 | "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2564 | .privileges(redfish::privileges::postLogService) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2565 | .methods(boost::beast::http::verb::post)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2566 | handleLogServicesDumpClearLogComputerSystemPost, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | inline void requestRoutesCrashdumpService(App& app) |
| 2570 | { |
| 2571 | // Note: Deviated from redfish privilege registry for GET & HEAD |
| 2572 | // method for security reasons. |
| 2573 | /** |
| 2574 | * Functions triggers appropriate requests on DBus |
| 2575 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2576 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2577 | // This is incorrect, should be: |
| 2578 | //.privileges(redfish::privileges::getLogService) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 2579 | .privileges({{"ConfigureManager"}}) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2580 | .methods( |
| 2581 | boost::beast::http::verb:: |
| 2582 | get)([&app](const crow::Request& req, |
| 2583 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2584 | const std::string& systemName) { |
| 2585 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2586 | { |
| 2587 | return; |
| 2588 | } |
| 2589 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2590 | { |
| 2591 | // Option currently returns no systems. TBD |
| 2592 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2593 | systemName); |
| 2594 | return; |
| 2595 | } |
| 2596 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2597 | { |
| 2598 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2599 | systemName); |
| 2600 | return; |
| 2601 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2602 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2603 | // Copy over the static data to include the entries added by |
| 2604 | // SubRoute |
| 2605 | asyncResp->res.jsonValue["@odata.id"] = |
| 2606 | std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", |
| 2607 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2608 | asyncResp->res.jsonValue["@odata.type"] = |
| 2609 | "#LogService.v1_2_0.LogService"; |
| 2610 | asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; |
| 2611 | asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; |
| 2612 | asyncResp->res.jsonValue["Id"] = "Crashdump"; |
| 2613 | asyncResp->res.jsonValue["OverWritePolicy"] = |
| 2614 | log_service::OverWritePolicy::WrapsWhenFull; |
| 2615 | asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 2616 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2617 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| 2618 | redfish::time_utils::getDateTimeOffsetNow(); |
| 2619 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 2620 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 2621 | redfishDateTimeOffset.second; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 2622 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2623 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format( |
| 2624 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", |
| 2625 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2626 | asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] |
| 2627 | ["target"] = std::format( |
| 2628 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog", |
| 2629 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2630 | asyncResp->res |
| 2631 | .jsonValue["Actions"]["#LogService.CollectDiagnosticData"] |
| 2632 | ["target"] = std::format( |
| 2633 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData", |
| 2634 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2635 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | void inline requestRoutesCrashdumpClear(App& app) |
| 2639 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2640 | BMCWEB_ROUTE( |
| 2641 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2642 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2643 | // This is incorrect, should be: |
| 2644 | //.privileges(redfish::privileges::postLogService) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 2645 | .privileges({{"ConfigureComponents"}}) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2646 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2647 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2648 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2649 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2650 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2651 | { |
| 2652 | return; |
| 2653 | } |
| 2654 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2655 | { |
| 2656 | // Option currently returns no systems. TBD |
| 2657 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2658 | systemName); |
| 2659 | return; |
| 2660 | } |
| 2661 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2662 | { |
| 2663 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2664 | systemName); |
| 2665 | return; |
| 2666 | } |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 2667 | dbus::utility::async_method_call( |
| 2668 | asyncResp, |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2669 | [asyncResp](const boost::system::error_code& ec, |
| 2670 | const std::string&) { |
| 2671 | if (ec) |
| 2672 | { |
| 2673 | messages::internalError(asyncResp->res); |
| 2674 | return; |
| 2675 | } |
| 2676 | messages::success(asyncResp->res); |
| 2677 | }, |
| 2678 | crashdumpObject, crashdumpPath, deleteAllInterface, |
| 2679 | "DeleteAll"); |
| 2680 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2681 | } |
Jason M. Bills | 5b61b5e | 2019-10-16 10:59:02 -0700 | [diff] [blame] | 2682 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2683 | inline void logCrashdumpEntry( |
| 2684 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2685 | const std::string& logID, nlohmann::json& logEntryJson) |
Jason M. Bills | e855dd2 | 2019-10-08 11:37:48 -0700 | [diff] [blame] | 2686 | { |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 2687 | auto getStoredLogCallback = |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 2688 | [asyncResp, logID, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 2689 | &logEntryJson](const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 2690 | const dbus::utility::DBusPropertiesMap& params) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2691 | if (ec) |
| 2692 | { |
| 2693 | BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message()); |
| 2694 | if (ec.value() == |
| 2695 | boost::system::linux_error::bad_request_descriptor) |
| 2696 | { |
| 2697 | messages::resourceNotFound(asyncResp->res, "LogEntry", |
| 2698 | logID); |
| 2699 | } |
| 2700 | else |
| 2701 | { |
| 2702 | messages::internalError(asyncResp->res); |
| 2703 | } |
| 2704 | return; |
| 2705 | } |
| 2706 | |
| 2707 | std::string timestamp{}; |
| 2708 | std::string filename{}; |
| 2709 | std::string logfile{}; |
| 2710 | parseCrashdumpParameters(params, filename, timestamp, logfile); |
| 2711 | |
| 2712 | if (filename.empty() || timestamp.empty()) |
Jason M. Bills | 1ddcf01 | 2019-11-26 14:59:21 -0800 | [diff] [blame] | 2713 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2714 | messages::resourceNotFound(asyncResp->res, "LogEntry", logID); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2715 | return; |
| 2716 | } |
| 2717 | |
| 2718 | std::string crashdumpURI = |
| 2719 | std::format( |
| 2720 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/", |
| 2721 | BMCWEB_REDFISH_SYSTEM_URI_NAME) + |
| 2722 | logID + "/" + filename; |
| 2723 | nlohmann::json::object_t logEntry; |
| 2724 | logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
| 2725 | logEntry["@odata.id"] = boost::urls::format( |
| 2726 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}", |
| 2727 | BMCWEB_REDFISH_SYSTEM_URI_NAME, logID); |
| 2728 | logEntry["Name"] = "CPU Crashdump"; |
| 2729 | logEntry["Id"] = logID; |
| 2730 | logEntry["EntryType"] = log_entry::LogEntryType::Oem; |
| 2731 | logEntry["AdditionalDataURI"] = std::move(crashdumpURI); |
| 2732 | logEntry["DiagnosticDataType"] = "OEM"; |
| 2733 | logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; |
| 2734 | logEntry["Created"] = std::move(timestamp); |
| 2735 | |
| 2736 | // If logEntryJson references an array of LogEntry resources |
| 2737 | // ('Members' list), then push this as a new entry, otherwise set it |
| 2738 | // directly |
| 2739 | if (logEntryJson.is_array()) |
| 2740 | { |
| 2741 | logEntryJson.push_back(logEntry); |
| 2742 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 2743 | logEntryJson.size(); |
Jason M. Bills | 2b20ef6 | 2022-01-06 15:48:07 -0800 | [diff] [blame] | 2744 | } |
| 2745 | else |
| 2746 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2747 | logEntryJson.update(logEntry); |
Jason M. Bills | 2b20ef6 | 2022-01-06 15:48:07 -0800 | [diff] [blame] | 2748 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2749 | }; |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2750 | dbus::utility::getAllProperties( |
| 2751 | crashdumpObject, crashdumpPath + std::string("/") + logID, |
| 2752 | crashdumpInterface, std::move(getStoredLogCallback)); |
Jason M. Bills | e855dd2 | 2019-10-08 11:37:48 -0700 | [diff] [blame] | 2753 | } |
| 2754 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2755 | inline void requestRoutesCrashdumpEntryCollection(App& app) |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2756 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2757 | // Note: Deviated from redfish privilege registry for GET & HEAD |
| 2758 | // method for security reasons. |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2759 | /** |
| 2760 | * Functions triggers appropriate requests on DBus |
| 2761 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2762 | BMCWEB_ROUTE(app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2763 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2764 | // This is incorrect, should be. |
| 2765 | //.privileges(redfish::privileges::postLogEntryCollection) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 2766 | .privileges({{"ConfigureComponents"}}) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2767 | .methods( |
| 2768 | boost::beast::http::verb:: |
| 2769 | get)([&app](const crow::Request& req, |
| 2770 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2771 | const std::string& systemName) { |
| 2772 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2773 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2774 | return; |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2775 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2776 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2777 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2778 | // Option currently returns no systems. TBD |
| 2779 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2780 | systemName); |
| 2781 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2782 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2783 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2784 | { |
| 2785 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2786 | systemName); |
| 2787 | return; |
| 2788 | } |
| 2789 | |
| 2790 | constexpr std::array<std::string_view, 1> interfaces = { |
| 2791 | crashdumpInterface}; |
| 2792 | dbus::utility::getSubTreePaths( |
| 2793 | "/", 0, interfaces, |
| 2794 | [asyncResp](const boost::system::error_code& ec, |
| 2795 | const std::vector<std::string>& resp) { |
| 2796 | if (ec) |
| 2797 | { |
| 2798 | if (ec.value() != |
| 2799 | boost::system::errc::no_such_file_or_directory) |
| 2800 | { |
| 2801 | BMCWEB_LOG_DEBUG("failed to get entries ec: {}", |
| 2802 | ec.message()); |
| 2803 | messages::internalError(asyncResp->res); |
| 2804 | return; |
| 2805 | } |
| 2806 | } |
| 2807 | asyncResp->res.jsonValue["@odata.type"] = |
| 2808 | "#LogEntryCollection.LogEntryCollection"; |
| 2809 | asyncResp->res.jsonValue["@odata.id"] = std::format( |
| 2810 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", |
| 2811 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2812 | asyncResp->res.jsonValue["Name"] = |
| 2813 | "Open BMC Crashdump Entries"; |
| 2814 | asyncResp->res.jsonValue["Description"] = |
| 2815 | "Collection of Crashdump Entries"; |
| 2816 | asyncResp->res.jsonValue["Members"] = |
| 2817 | nlohmann::json::array(); |
| 2818 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
| 2819 | |
| 2820 | for (const std::string& path : resp) |
| 2821 | { |
| 2822 | const sdbusplus::message::object_path objPath(path); |
| 2823 | // Get the log ID |
| 2824 | std::string logID = objPath.filename(); |
| 2825 | if (logID.empty()) |
| 2826 | { |
| 2827 | continue; |
| 2828 | } |
| 2829 | // Add the log entry to the array |
| 2830 | logCrashdumpEntry(asyncResp, logID, |
| 2831 | asyncResp->res.jsonValue["Members"]); |
| 2832 | } |
| 2833 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2834 | }); |
| 2835 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2836 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2837 | inline void requestRoutesCrashdumpEntry(App& app) |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2838 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2839 | // Note: Deviated from redfish privilege registry for GET & HEAD |
| 2840 | // method for security reasons. |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2841 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2842 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2843 | app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2844 | // this is incorrect, should be |
| 2845 | // .privileges(redfish::privileges::getLogEntry) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 2846 | .privileges({{"ConfigureComponents"}}) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2847 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2848 | [&app](const crow::Request& req, |
| 2849 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2850 | const std::string& systemName, const std::string& param) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2851 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2852 | { |
| 2853 | return; |
| 2854 | } |
| 2855 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2856 | { |
| 2857 | // Option currently returns no systems. TBD |
| 2858 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2859 | systemName); |
| 2860 | return; |
| 2861 | } |
| 2862 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2863 | { |
| 2864 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2865 | systemName); |
| 2866 | return; |
| 2867 | } |
| 2868 | const std::string& logID = param; |
| 2869 | logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); |
| 2870 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2871 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2872 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2873 | inline void requestRoutesCrashdumpFile(App& app) |
| 2874 | { |
| 2875 | // Note: Deviated from redfish privilege registry for GET & HEAD |
| 2876 | // method for security reasons. |
| 2877 | BMCWEB_ROUTE( |
| 2878 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2879 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2880 | .privileges(redfish::privileges::getLogEntry) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2881 | .methods(boost::beast::http::verb::get)( |
Nan Zhou | a4ce114 | 2022-08-02 18:45:25 +0000 | [diff] [blame] | 2882 | [](const crow::Request& req, |
| 2883 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2884 | const std::string& systemName, const std::string& logID, |
| 2885 | const std::string& fileName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2886 | // Do not call getRedfishRoute here since the crashdump file is |
| 2887 | // not a Redfish resource. |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2888 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2889 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2890 | { |
| 2891 | // Option currently returns no systems. TBD |
| 2892 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2893 | systemName); |
| 2894 | return; |
| 2895 | } |
| 2896 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2897 | { |
| 2898 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2899 | systemName); |
| 2900 | return; |
| 2901 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2902 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2903 | auto getStoredLogCallback = |
| 2904 | [asyncResp, logID, fileName, |
| 2905 | url(boost::urls::url(req.url()))]( |
| 2906 | const boost::system::error_code& ec, |
| 2907 | const std::vector<std::pair< |
| 2908 | std::string, dbus::utility::DbusVariantType>>& |
| 2909 | resp) { |
| 2910 | if (ec) |
| 2911 | { |
| 2912 | BMCWEB_LOG_DEBUG("failed to get log ec: {}", |
| 2913 | ec.message()); |
| 2914 | messages::internalError(asyncResp->res); |
| 2915 | return; |
| 2916 | } |
Jason M. Bills | 8e6c099 | 2021-03-11 16:26:53 -0800 | [diff] [blame] | 2917 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2918 | std::string dbusFilename{}; |
| 2919 | std::string dbusTimestamp{}; |
| 2920 | std::string dbusFilepath{}; |
Jason M. Bills | 8e6c099 | 2021-03-11 16:26:53 -0800 | [diff] [blame] | 2921 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2922 | parseCrashdumpParameters(resp, dbusFilename, |
| 2923 | dbusTimestamp, dbusFilepath); |
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 | if (dbusFilename.empty() || dbusTimestamp.empty() || |
| 2926 | dbusFilepath.empty()) |
| 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 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2933 | // Verify the file name parameter is correct |
| 2934 | if (fileName != dbusFilename) |
| 2935 | { |
| 2936 | messages::resourceNotFound(asyncResp->res, |
| 2937 | "LogEntry", logID); |
| 2938 | return; |
| 2939 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2940 | |
Myung Bae | d51c61b | 2024-09-13 10:35:34 -0500 | [diff] [blame] | 2941 | if (asyncResp->res.openFile(dbusFilepath) != |
| 2942 | crow::OpenCode::Success) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2943 | { |
| 2944 | messages::resourceNotFound(asyncResp->res, |
| 2945 | "LogEntry", logID); |
| 2946 | return; |
| 2947 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2948 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2949 | // Configure this to be a file download when accessed |
| 2950 | // from a browser |
| 2951 | asyncResp->res.addHeader( |
| 2952 | boost::beast::http::field::content_disposition, |
| 2953 | "attachment"); |
| 2954 | }; |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2955 | dbus::utility::getAllProperties( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2956 | *crow::connections::systemBus, crashdumpObject, |
| 2957 | crashdumpPath + std::string("/") + logID, |
| 2958 | crashdumpInterface, std::move(getStoredLogCallback)); |
| 2959 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2960 | } |
| 2961 | |
Jason M. Bills | c5a4c82 | 2022-01-06 15:51:23 -0800 | [diff] [blame] | 2962 | enum class OEMDiagnosticType |
| 2963 | { |
| 2964 | onDemand, |
| 2965 | telemetry, |
| 2966 | invalid, |
| 2967 | }; |
| 2968 | |
Ed Tanous | 26ccae3 | 2023-02-16 10:28:44 -0800 | [diff] [blame] | 2969 | inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr) |
Jason M. Bills | c5a4c82 | 2022-01-06 15:51:23 -0800 | [diff] [blame] | 2970 | { |
| 2971 | if (oemDiagStr == "OnDemand") |
| 2972 | { |
| 2973 | return OEMDiagnosticType::onDemand; |
| 2974 | } |
| 2975 | if (oemDiagStr == "Telemetry") |
| 2976 | { |
| 2977 | return OEMDiagnosticType::telemetry; |
| 2978 | } |
| 2979 | |
| 2980 | return OEMDiagnosticType::invalid; |
| 2981 | } |
| 2982 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2983 | inline void requestRoutesCrashdumpCollect(App& app) |
| 2984 | { |
| 2985 | // Note: Deviated from redfish privilege registry for GET & HEAD |
| 2986 | // method for security reasons. |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2987 | BMCWEB_ROUTE( |
| 2988 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2989 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2990 | // The below is incorrect; Should be ConfigureManager |
| 2991 | //.privileges(redfish::privileges::postLogService) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 2992 | .privileges({{"ConfigureComponents"}}) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2993 | .methods(boost::beast::http::verb::post)( |
| 2994 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2995 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2996 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2997 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2998 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2999 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3000 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3001 | |
| 3002 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3003 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3004 | // Option currently returns no systems. TBD |
| 3005 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3006 | systemName); |
| 3007 | return; |
| 3008 | } |
| 3009 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3010 | { |
| 3011 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3012 | systemName); |
| 3013 | return; |
| 3014 | } |
| 3015 | |
| 3016 | std::string diagnosticDataType; |
| 3017 | std::string oemDiagnosticDataType; |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 3018 | if (!redfish::json_util::readJsonAction( // |
| 3019 | req, asyncResp->res, // |
| 3020 | "DiagnosticDataType", diagnosticDataType, // |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 3021 | "OEMDiagnosticDataType", oemDiagnosticDataType // |
| 3022 | )) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3023 | { |
| 3024 | return; |
| 3025 | } |
| 3026 | |
| 3027 | if (diagnosticDataType != "OEM") |
| 3028 | { |
| 3029 | BMCWEB_LOG_ERROR( |
| 3030 | "Only OEM DiagnosticDataType supported for Crashdump"); |
| 3031 | messages::actionParameterValueFormatError( |
| 3032 | asyncResp->res, diagnosticDataType, |
| 3033 | "DiagnosticDataType", "CollectDiagnosticData"); |
| 3034 | return; |
| 3035 | } |
| 3036 | |
| 3037 | OEMDiagnosticType oemDiagType = |
| 3038 | getOEMDiagnosticType(oemDiagnosticDataType); |
| 3039 | |
| 3040 | std::string iface; |
| 3041 | std::string method; |
| 3042 | std::string taskMatchStr; |
| 3043 | if (oemDiagType == OEMDiagnosticType::onDemand) |
| 3044 | { |
| 3045 | iface = crashdumpOnDemandInterface; |
| 3046 | method = "GenerateOnDemandLog"; |
| 3047 | taskMatchStr = |
| 3048 | "type='signal'," |
| 3049 | "interface='org.freedesktop.DBus.Properties'," |
| 3050 | "member='PropertiesChanged'," |
| 3051 | "arg0namespace='com.intel.crashdump'"; |
| 3052 | } |
| 3053 | else if (oemDiagType == OEMDiagnosticType::telemetry) |
| 3054 | { |
| 3055 | iface = crashdumpTelemetryInterface; |
| 3056 | method = "GenerateTelemetryLog"; |
| 3057 | taskMatchStr = |
| 3058 | "type='signal'," |
| 3059 | "interface='org.freedesktop.DBus.Properties'," |
| 3060 | "member='PropertiesChanged'," |
| 3061 | "arg0namespace='com.intel.crashdump'"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3062 | } |
| 3063 | else |
| 3064 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3065 | BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}", |
| 3066 | oemDiagnosticDataType); |
| 3067 | messages::actionParameterValueFormatError( |
| 3068 | asyncResp->res, oemDiagnosticDataType, |
| 3069 | "OEMDiagnosticDataType", "CollectDiagnosticData"); |
| 3070 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3071 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 3072 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3073 | auto collectCrashdumpCallback = |
| 3074 | [asyncResp, payload(task::Payload(req)), |
| 3075 | taskMatchStr](const boost::system::error_code& ec, |
| 3076 | const std::string&) mutable { |
| 3077 | if (ec) |
| 3078 | { |
| 3079 | if (ec.value() == |
| 3080 | boost::system::errc::operation_not_supported) |
| 3081 | { |
| 3082 | messages::resourceInStandby(asyncResp->res); |
| 3083 | } |
| 3084 | else if (ec.value() == boost::system::errc:: |
| 3085 | device_or_resource_busy) |
| 3086 | { |
| 3087 | messages::serviceTemporarilyUnavailable( |
| 3088 | asyncResp->res, "60"); |
| 3089 | } |
| 3090 | else |
| 3091 | { |
| 3092 | messages::internalError(asyncResp->res); |
| 3093 | } |
| 3094 | return; |
| 3095 | } |
| 3096 | std::shared_ptr<task::TaskData> task = |
| 3097 | task::TaskData::createTask( |
| 3098 | [](const boost::system::error_code& ec2, |
| 3099 | sdbusplus::message_t&, |
| 3100 | const std::shared_ptr<task::TaskData>& |
| 3101 | taskData) { |
| 3102 | if (!ec2) |
| 3103 | { |
| 3104 | taskData->messages.emplace_back( |
| 3105 | messages::taskCompletedOK( |
| 3106 | std::to_string( |
| 3107 | taskData->index))); |
| 3108 | taskData->state = "Completed"; |
| 3109 | } |
| 3110 | return task::completed; |
| 3111 | }, |
| 3112 | taskMatchStr); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3113 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3114 | task->startTimer(std::chrono::minutes(5)); |
| 3115 | task->populateResp(asyncResp->res); |
| 3116 | task->payload.emplace(std::move(payload)); |
| 3117 | }; |
| 3118 | |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 3119 | dbus::utility::async_method_call( |
| 3120 | asyncResp, std::move(collectCrashdumpCallback), |
| 3121 | crashdumpObject, crashdumpPath, iface, method); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3122 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3123 | } |
Kenny L. Ku | 6eda768 | 2020-06-19 09:48:36 -0700 | [diff] [blame] | 3124 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 3125 | inline void dBusLogServiceActionsClear( |
| 3126 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 3127 | { |
| 3128 | BMCWEB_LOG_DEBUG("Do delete all entries."); |
| 3129 | |
| 3130 | // Process response from Logging service. |
| 3131 | auto respHandler = [asyncResp](const boost::system::error_code& ec) { |
| 3132 | BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done"); |
| 3133 | if (ec) |
| 3134 | { |
| 3135 | // TODO Handle for specific error code |
| 3136 | BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec); |
| 3137 | asyncResp->res.result( |
| 3138 | boost::beast::http::status::internal_server_error); |
| 3139 | return; |
| 3140 | } |
| 3141 | |
| 3142 | asyncResp->res.result(boost::beast::http::status::no_content); |
| 3143 | }; |
| 3144 | |
| 3145 | // Make call to Logging service to request Clear Log |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 3146 | dbus::utility::async_method_call( |
| 3147 | asyncResp, respHandler, "xyz.openbmc_project.Logging", |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 3148 | "/xyz/openbmc_project/logging", |
| 3149 | "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); |
| 3150 | } |
| 3151 | |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 3152 | /** |
| 3153 | * DBusLogServiceActionsClear class supports POST method for ClearLog action. |
| 3154 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3155 | inline void requestRoutesDBusLogServiceActionsClear(App& app) |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 3156 | { |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 3157 | /** |
| 3158 | * Function handles POST method request. |
| 3159 | * The Clear Log actions does not require any parameter.The action deletes |
| 3160 | * all entries found in the Entries collection for this Log Service. |
| 3161 | */ |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 3162 | |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 3163 | BMCWEB_ROUTE( |
| 3164 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3165 | "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 3166 | .privileges(redfish::privileges::postLogService) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3167 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 3168 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3169 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3170 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3171 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3172 | { |
| 3173 | return; |
| 3174 | } |
| 3175 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3176 | { |
| 3177 | // Option currently returns no systems. TBD |
| 3178 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3179 | systemName); |
| 3180 | return; |
| 3181 | } |
| 3182 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3183 | { |
| 3184 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3185 | systemName); |
| 3186 | return; |
| 3187 | } |
| 3188 | dBusLogServiceActionsClear(asyncResp); |
| 3189 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3190 | } |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3191 | |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 3192 | } // namespace redfish |