Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "app.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 19 | #include "dbus_utility.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 20 | #include "error_messages.hpp" |
Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 21 | #include "generated/enums/log_entry.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 22 | #include "generated/enums/log_service.hpp" |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 23 | #include "gzfile.hpp" |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 24 | #include "http_utility.hpp" |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 25 | #include "human_sort.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 26 | #include "query.hpp" |
Jason M. Bills | 4851d45 | 2019-03-28 11:27:48 -0700 | [diff] [blame] | 27 | #include "registries.hpp" |
| 28 | #include "registries/base_message_registry.hpp" |
| 29 | #include "registries/openbmc_message_registry.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 30 | #include "registries/privilege_registry.hpp" |
James Feist | 4622957 | 2020-02-19 15:11:58 -0800 | [diff] [blame] | 31 | #include "task.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 32 | #include "task_messages.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 33 | #include "utils/dbus_utils.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 34 | #include "utils/json_utils.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 35 | #include "utils/time_utils.hpp" |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 36 | |
Myung Bae | 75e8e21 | 2023-11-30 12:53:46 -0800 | [diff] [blame] | 37 | #include <systemd/sd-id128.h> |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 38 | #include <tinyxml2.h> |
Adriana Kobylak | 400fd1f | 2021-01-29 09:01:30 -0600 | [diff] [blame] | 39 | #include <unistd.h> |
Jason M. Bills | e1f2634 | 2018-07-18 12:12:00 -0700 | [diff] [blame] | 40 | |
Ed Tanous | 07c8c20 | 2022-07-11 10:08:08 -0700 | [diff] [blame] | 41 | #include <boost/beast/http/verb.hpp> |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 42 | #include <boost/container/flat_map.hpp> |
Jason M. Bills | 1ddcf01 | 2019-11-26 14:59:21 -0800 | [diff] [blame] | 43 | #include <boost/system/linux_error.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 44 | #include <boost/url/format.hpp> |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 45 | #include <sdbusplus/asio/property.hpp> |
| 46 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 47 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 48 | #include <array> |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 49 | #include <charconv> |
Abhilash Raju | b5f288d | 2023-11-08 22:32:44 -0600 | [diff] [blame] | 50 | #include <cstddef> |
James Feist | 4418c7f | 2019-04-15 11:09:15 -0700 | [diff] [blame] | 51 | #include <filesystem> |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 52 | #include <iterator> |
Xiaochao Ma | 75710de | 2021-01-21 17:56:02 +0800 | [diff] [blame] | 53 | #include <optional> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 54 | #include <ranges> |
Ed Tanous | 26702d0 | 2021-11-03 15:02:33 -0700 | [diff] [blame] | 55 | #include <span> |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 56 | #include <string> |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 57 | #include <string_view> |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 58 | #include <variant> |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 59 | |
| 60 | namespace redfish |
| 61 | { |
| 62 | |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 63 | constexpr const char* crashdumpObject = "com.intel.crashdump"; |
| 64 | constexpr const char* crashdumpPath = "/com/intel/crashdump"; |
| 65 | constexpr const char* crashdumpInterface = "com.intel.crashdump"; |
| 66 | constexpr const char* deleteAllInterface = |
Jason M. Bills | 5b61b5e | 2019-10-16 10:59:02 -0700 | [diff] [blame] | 67 | "xyz.openbmc_project.Collection.DeleteAll"; |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 68 | constexpr const char* crashdumpOnDemandInterface = |
Jason M. Bills | 424c417 | 2019-03-21 13:50:33 -0700 | [diff] [blame] | 69 | "com.intel.crashdump.OnDemand"; |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 70 | constexpr const char* crashdumpTelemetryInterface = |
Kenny L. Ku | 6eda768 | 2020-06-19 09:48:36 -0700 | [diff] [blame] | 71 | "com.intel.crashdump.Telemetry"; |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 72 | |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 73 | enum class DumpCreationProgress |
| 74 | { |
| 75 | DUMP_CREATE_SUCCESS, |
| 76 | DUMP_CREATE_FAILED, |
| 77 | DUMP_CREATE_INPROGRESS |
| 78 | }; |
| 79 | |
James Feist | f615040 | 2019-01-08 10:36:20 -0800 | [diff] [blame] | 80 | namespace fs = std::filesystem; |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 81 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 82 | inline std::string translateSeverityDbusToRedfish(const std::string& s) |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 83 | { |
Ed Tanous | d4d2579 | 2020-09-29 15:15:03 -0700 | [diff] [blame] | 84 | if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || |
| 85 | (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || |
| 86 | (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || |
| 87 | (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 88 | { |
| 89 | return "Critical"; |
| 90 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 91 | if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || |
| 92 | (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || |
| 93 | (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 94 | { |
| 95 | return "OK"; |
| 96 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 97 | if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 98 | { |
| 99 | return "Warning"; |
| 100 | } |
| 101 | return ""; |
| 102 | } |
| 103 | |
Abhishek Patel | 9017faf | 2021-09-14 22:48:55 -0500 | [diff] [blame] | 104 | inline std::optional<bool> getProviderNotifyAction(const std::string& notify) |
| 105 | { |
| 106 | std::optional<bool> notifyAction; |
| 107 | if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify") |
| 108 | { |
| 109 | notifyAction = true; |
| 110 | } |
| 111 | else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit") |
| 112 | { |
| 113 | notifyAction = false; |
| 114 | } |
| 115 | |
| 116 | return notifyAction; |
| 117 | } |
| 118 | |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 119 | inline std::string getDumpPath(std::string_view dumpType) |
| 120 | { |
| 121 | std::string dbusDumpPath = "/xyz/openbmc_project/dump/"; |
| 122 | std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath), |
| 123 | bmcweb::asciiToLower); |
| 124 | |
| 125 | return dbusDumpPath; |
| 126 | } |
| 127 | |
Ed Tanous | 055713e | 2024-07-17 17:19:36 -0700 | [diff] [blame] | 128 | inline bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, |
Jason M. Bills | e85d6b1 | 2019-07-29 17:01:15 -0700 | [diff] [blame] | 129 | const bool firstEntry = true) |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 130 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 131 | static time_t prevTs = 0; |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 132 | static int index = 0; |
Jason M. Bills | e85d6b1 | 2019-07-29 17:01:15 -0700 | [diff] [blame] | 133 | if (firstEntry) |
| 134 | { |
| 135 | prevTs = 0; |
| 136 | } |
| 137 | |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 138 | // Get the entry timestamp |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 139 | std::time_t curTs = 0; |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 140 | std::tm timeStruct = {}; |
| 141 | std::istringstream entryStream(logEntry); |
| 142 | if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) |
| 143 | { |
| 144 | curTs = std::mktime(&timeStruct); |
| 145 | } |
| 146 | // If the timestamp isn't unique, increment the index |
| 147 | if (curTs == prevTs) |
| 148 | { |
| 149 | index++; |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | // Otherwise, reset it |
| 154 | index = 0; |
| 155 | } |
| 156 | // Save the timestamp |
| 157 | prevTs = curTs; |
| 158 | |
| 159 | entryID = std::to_string(curTs); |
| 160 | if (index > 0) |
| 161 | { |
| 162 | entryID += "_" + std::to_string(index); |
| 163 | } |
| 164 | return true; |
| 165 | } |
| 166 | |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 167 | static bool |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 168 | getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 169 | { |
| 170 | static const std::filesystem::path redfishLogDir = "/var/log"; |
| 171 | static const std::string redfishLogFilename = "redfish"; |
| 172 | |
| 173 | // Loop through the directory looking for redfish log files |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 174 | for (const std::filesystem::directory_entry& dirEnt : |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 175 | std::filesystem::directory_iterator(redfishLogDir)) |
| 176 | { |
| 177 | // If we find a redfish log file, save the path |
| 178 | std::string filename = dirEnt.path().filename(); |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 179 | if (filename.starts_with(redfishLogFilename)) |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 180 | { |
| 181 | redfishLogFiles.emplace_back(redfishLogDir / filename); |
| 182 | } |
| 183 | } |
| 184 | // As the log files rotate, they are appended with a ".#" that is higher for |
| 185 | // the older logs. Since we don't expect more than 10 log files, we |
| 186 | // 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] | 187 | std::ranges::sort(redfishLogFiles); |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 188 | |
| 189 | return !redfishLogFiles.empty(); |
| 190 | } |
| 191 | |
Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 192 | inline log_entry::OriginatorTypes |
| 193 | mapDbusOriginatorTypeToRedfish(const std::string& originatorType) |
| 194 | { |
| 195 | if (originatorType == |
| 196 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client") |
| 197 | { |
| 198 | return log_entry::OriginatorTypes::Client; |
| 199 | } |
| 200 | if (originatorType == |
| 201 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal") |
| 202 | { |
| 203 | return log_entry::OriginatorTypes::Internal; |
| 204 | } |
| 205 | if (originatorType == |
| 206 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService") |
| 207 | { |
| 208 | return log_entry::OriginatorTypes::SupportingService; |
| 209 | } |
| 210 | return log_entry::OriginatorTypes::Invalid; |
| 211 | } |
| 212 | |
Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 213 | inline void parseDumpEntryFromDbusObject( |
Jiaqing Zhao | 2d613eb | 2022-08-15 16:03:00 +0800 | [diff] [blame] | 214 | const dbus::utility::ManagedObjectType::value_type& object, |
Claire Weinan | c6fecda | 2022-07-15 10:43:25 -0700 | [diff] [blame] | 215 | std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs, |
Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 216 | std::string& originatorId, log_entry::OriginatorTypes& originatorType, |
Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 217 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 218 | { |
| 219 | for (const auto& interfaceMap : object.second) |
| 220 | { |
| 221 | if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") |
| 222 | { |
| 223 | for (const auto& propertyMap : interfaceMap.second) |
| 224 | { |
| 225 | if (propertyMap.first == "Status") |
| 226 | { |
| 227 | const auto* status = |
| 228 | std::get_if<std::string>(&propertyMap.second); |
| 229 | if (status == nullptr) |
| 230 | { |
| 231 | messages::internalError(asyncResp->res); |
| 232 | break; |
| 233 | } |
| 234 | dumpStatus = *status; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") |
| 239 | { |
| 240 | for (const auto& propertyMap : interfaceMap.second) |
| 241 | { |
| 242 | if (propertyMap.first == "Size") |
| 243 | { |
| 244 | const auto* sizePtr = |
| 245 | std::get_if<uint64_t>(&propertyMap.second); |
| 246 | if (sizePtr == nullptr) |
| 247 | { |
| 248 | messages::internalError(asyncResp->res); |
| 249 | break; |
| 250 | } |
| 251 | size = *sizePtr; |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") |
| 257 | { |
| 258 | for (const auto& propertyMap : interfaceMap.second) |
| 259 | { |
| 260 | if (propertyMap.first == "Elapsed") |
| 261 | { |
| 262 | const uint64_t* usecsTimeStamp = |
| 263 | std::get_if<uint64_t>(&propertyMap.second); |
| 264 | if (usecsTimeStamp == nullptr) |
| 265 | { |
| 266 | messages::internalError(asyncResp->res); |
| 267 | break; |
| 268 | } |
Claire Weinan | c6fecda | 2022-07-15 10:43:25 -0700 | [diff] [blame] | 269 | timestampUs = *usecsTimeStamp; |
Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 270 | break; |
| 271 | } |
| 272 | } |
| 273 | } |
Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 274 | else if (interfaceMap.first == |
| 275 | "xyz.openbmc_project.Common.OriginatedBy") |
| 276 | { |
| 277 | for (const auto& propertyMap : interfaceMap.second) |
| 278 | { |
| 279 | if (propertyMap.first == "OriginatorId") |
| 280 | { |
| 281 | const std::string* id = |
| 282 | std::get_if<std::string>(&propertyMap.second); |
| 283 | if (id == nullptr) |
| 284 | { |
| 285 | messages::internalError(asyncResp->res); |
| 286 | break; |
| 287 | } |
| 288 | originatorId = *id; |
| 289 | } |
| 290 | |
| 291 | if (propertyMap.first == "OriginatorType") |
| 292 | { |
| 293 | const std::string* type = |
| 294 | std::get_if<std::string>(&propertyMap.second); |
| 295 | if (type == nullptr) |
| 296 | { |
| 297 | messages::internalError(asyncResp->res); |
| 298 | break; |
| 299 | } |
| 300 | |
| 301 | originatorType = mapDbusOriginatorTypeToRedfish(*type); |
| 302 | if (originatorType == log_entry::OriginatorTypes::Invalid) |
| 303 | { |
| 304 | messages::internalError(asyncResp->res); |
| 305 | break; |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | } |
Claire Weinan | aefe378 | 2022-07-15 19:17:19 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
Nan Zhou | 21ab404 | 2022-06-26 23:07:40 +0000 | [diff] [blame] | 313 | static std::string getDumpEntriesPath(const std::string& dumpType) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 314 | { |
| 315 | std::string entriesPath; |
| 316 | |
| 317 | if (dumpType == "BMC") |
| 318 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 319 | entriesPath = |
| 320 | std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/", |
| 321 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 322 | } |
| 323 | else if (dumpType == "FaultLog") |
| 324 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 325 | entriesPath = |
| 326 | std::format("/redfish/v1/Managers/{}/LogServices/FaultLog/Entries/", |
| 327 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 328 | } |
| 329 | else if (dumpType == "System") |
| 330 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 331 | entriesPath = |
| 332 | std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/", |
| 333 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 334 | } |
| 335 | else |
| 336 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 337 | BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}", |
| 338 | dumpType); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | // Returns empty string on error |
| 342 | return entriesPath; |
| 343 | } |
| 344 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 345 | inline void |
| 346 | getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 347 | const std::string& dumpType) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 348 | { |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 349 | std::string entriesPath = getDumpEntriesPath(dumpType); |
| 350 | if (entriesPath.empty()) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 351 | { |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 352 | messages::internalError(asyncResp->res); |
| 353 | return; |
| 354 | } |
| 355 | |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 356 | sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); |
| 357 | dbus::utility::getManagedObjects( |
| 358 | "xyz.openbmc_project.Dump.Manager", path, |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 359 | [asyncResp, entriesPath, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 360 | dumpType](const boost::system::error_code& ec, |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 361 | const dbus::utility::ManagedObjectType& objects) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 362 | if (ec) |
| 363 | { |
| 364 | BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec); |
| 365 | messages::internalError(asyncResp->res); |
| 366 | return; |
| 367 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 368 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 369 | // Remove ending slash |
| 370 | std::string odataIdStr = entriesPath; |
| 371 | if (!odataIdStr.empty()) |
| 372 | { |
| 373 | odataIdStr.pop_back(); |
| 374 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 375 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 376 | asyncResp->res.jsonValue["@odata.type"] = |
| 377 | "#LogEntryCollection.LogEntryCollection"; |
| 378 | asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr); |
| 379 | asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries"; |
| 380 | asyncResp->res.jsonValue["Description"] = |
| 381 | "Collection of " + dumpType + " Dump Entries"; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 382 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 383 | nlohmann::json::array_t entriesArray; |
| 384 | std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 385 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 386 | dbus::utility::ManagedObjectType resp(objects); |
| 387 | std::ranges::sort(resp, [](const auto& l, const auto& r) { |
| 388 | return AlphanumLess<std::string>()(l.first.filename(), |
| 389 | r.first.filename()); |
| 390 | }); |
| 391 | |
| 392 | for (auto& object : resp) |
| 393 | { |
| 394 | if (object.first.str.find(dumpEntryPath) == std::string::npos) |
| 395 | { |
| 396 | continue; |
| 397 | } |
| 398 | uint64_t timestampUs = 0; |
| 399 | uint64_t size = 0; |
| 400 | std::string dumpStatus; |
| 401 | std::string originatorId; |
| 402 | log_entry::OriginatorTypes originatorType = |
| 403 | log_entry::OriginatorTypes::Internal; |
| 404 | nlohmann::json::object_t thisEntry; |
| 405 | |
| 406 | std::string entryID = object.first.filename(); |
| 407 | if (entryID.empty()) |
| 408 | { |
| 409 | continue; |
| 410 | } |
| 411 | |
| 412 | parseDumpEntryFromDbusObject(object, dumpStatus, size, |
| 413 | timestampUs, originatorId, |
| 414 | originatorType, asyncResp); |
| 415 | |
| 416 | if (dumpStatus != |
| 417 | "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && |
| 418 | !dumpStatus.empty()) |
| 419 | { |
| 420 | // Dump status is not Complete, no need to enumerate |
| 421 | continue; |
| 422 | } |
| 423 | |
| 424 | thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry"; |
| 425 | thisEntry["@odata.id"] = entriesPath + entryID; |
| 426 | thisEntry["Id"] = entryID; |
| 427 | thisEntry["EntryType"] = "Event"; |
| 428 | thisEntry["Name"] = dumpType + " Dump Entry"; |
| 429 | thisEntry["Created"] = |
| 430 | redfish::time_utils::getDateTimeUintUs(timestampUs); |
| 431 | |
| 432 | if (!originatorId.empty()) |
| 433 | { |
| 434 | thisEntry["Originator"] = originatorId; |
| 435 | thisEntry["OriginatorType"] = originatorType; |
| 436 | } |
| 437 | |
| 438 | if (dumpType == "BMC") |
| 439 | { |
| 440 | thisEntry["DiagnosticDataType"] = "Manager"; |
| 441 | thisEntry["AdditionalDataURI"] = |
| 442 | entriesPath + entryID + "/attachment"; |
| 443 | thisEntry["AdditionalDataSizeBytes"] = size; |
| 444 | } |
| 445 | else if (dumpType == "System") |
| 446 | { |
| 447 | thisEntry["DiagnosticDataType"] = "OEM"; |
| 448 | thisEntry["OEMDiagnosticDataType"] = "System"; |
| 449 | thisEntry["AdditionalDataURI"] = |
| 450 | entriesPath + entryID + "/attachment"; |
| 451 | thisEntry["AdditionalDataSizeBytes"] = size; |
| 452 | } |
| 453 | entriesArray.emplace_back(std::move(thisEntry)); |
| 454 | } |
| 455 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 456 | entriesArray.size(); |
| 457 | asyncResp->res.jsonValue["Members"] = std::move(entriesArray); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 458 | }); |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 459 | } |
| 460 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 461 | inline void |
Claire Weinan | c7a6d66 | 2022-06-13 16:36:39 -0700 | [diff] [blame] | 462 | getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 463 | const std::string& entryID, const std::string& dumpType) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 464 | { |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 465 | std::string entriesPath = getDumpEntriesPath(dumpType); |
| 466 | if (entriesPath.empty()) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 467 | { |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 468 | messages::internalError(asyncResp->res); |
| 469 | return; |
| 470 | } |
| 471 | |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 472 | sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); |
| 473 | dbus::utility::getManagedObjects( |
| 474 | "xyz.openbmc_project.Dump.Manager", path, |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 475 | [asyncResp, entryID, dumpType, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 476 | entriesPath](const boost::system::error_code& ec, |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 477 | const dbus::utility::ManagedObjectType& resp) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 478 | if (ec) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 479 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 480 | BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec); |
| 481 | messages::internalError(asyncResp->res); |
| 482 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 485 | bool foundDumpEntry = false; |
| 486 | std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 487 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 488 | for (const auto& objectPath : resp) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 489 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 490 | if (objectPath.first.str != dumpEntryPath + entryID) |
| 491 | { |
| 492 | continue; |
| 493 | } |
| 494 | |
| 495 | foundDumpEntry = true; |
| 496 | uint64_t timestampUs = 0; |
| 497 | uint64_t size = 0; |
| 498 | std::string dumpStatus; |
| 499 | std::string originatorId; |
| 500 | log_entry::OriginatorTypes originatorType = |
| 501 | log_entry::OriginatorTypes::Internal; |
| 502 | |
| 503 | parseDumpEntryFromDbusObject(objectPath, dumpStatus, size, |
| 504 | timestampUs, originatorId, |
| 505 | originatorType, asyncResp); |
| 506 | |
| 507 | if (dumpStatus != |
| 508 | "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && |
| 509 | !dumpStatus.empty()) |
| 510 | { |
| 511 | // Dump status is not Complete |
| 512 | // return not found until status is changed to Completed |
| 513 | messages::resourceNotFound(asyncResp->res, |
| 514 | dumpType + " dump", entryID); |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | asyncResp->res.jsonValue["@odata.type"] = |
| 519 | "#LogEntry.v1_11_0.LogEntry"; |
| 520 | asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID; |
| 521 | asyncResp->res.jsonValue["Id"] = entryID; |
| 522 | asyncResp->res.jsonValue["EntryType"] = "Event"; |
| 523 | asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; |
| 524 | asyncResp->res.jsonValue["Created"] = |
| 525 | redfish::time_utils::getDateTimeUintUs(timestampUs); |
| 526 | |
| 527 | if (!originatorId.empty()) |
| 528 | { |
| 529 | asyncResp->res.jsonValue["Originator"] = originatorId; |
| 530 | asyncResp->res.jsonValue["OriginatorType"] = originatorType; |
| 531 | } |
| 532 | |
| 533 | if (dumpType == "BMC") |
| 534 | { |
| 535 | asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; |
| 536 | asyncResp->res.jsonValue["AdditionalDataURI"] = |
| 537 | entriesPath + entryID + "/attachment"; |
| 538 | asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; |
| 539 | } |
| 540 | else if (dumpType == "System") |
| 541 | { |
| 542 | asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; |
| 543 | asyncResp->res.jsonValue["OEMDiagnosticDataType"] = |
| 544 | "System"; |
| 545 | asyncResp->res.jsonValue["AdditionalDataURI"] = |
| 546 | entriesPath + entryID + "/attachment"; |
| 547 | asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; |
| 548 | } |
| 549 | } |
| 550 | if (!foundDumpEntry) |
| 551 | { |
| 552 | BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID); |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 553 | messages::resourceNotFound(asyncResp->res, dumpType + " dump", |
| 554 | entryID); |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 555 | return; |
| 556 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 557 | }); |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 558 | } |
| 559 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 560 | inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Stanley Chu | 9878256 | 2020-11-04 16:10:24 +0800 | [diff] [blame] | 561 | const std::string& entryID, |
Asmitha Karunanithi | b47452b | 2020-09-25 02:02:19 -0500 | [diff] [blame] | 562 | const std::string& dumpType) |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 563 | { |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 564 | auto respHandler = [asyncResp, |
| 565 | entryID](const boost::system::error_code& ec) { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 566 | BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done"); |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 567 | if (ec) |
| 568 | { |
George Liu | 3de8d8b | 2021-03-22 17:49:39 +0800 | [diff] [blame] | 569 | if (ec.value() == EBADR) |
| 570 | { |
| 571 | messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); |
| 572 | return; |
| 573 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 574 | BMCWEB_LOG_ERROR( |
| 575 | "Dump (DBus) doDelete respHandler got error {} entryID={}", ec, |
| 576 | entryID); |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 577 | messages::internalError(asyncResp->res); |
| 578 | return; |
| 579 | } |
| 580 | }; |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 581 | |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 582 | crow::connections::systemBus->async_method_call( |
| 583 | respHandler, "xyz.openbmc_project.Dump.Manager", |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 584 | std::format("{}/entry/{}", getDumpPath(dumpType), entryID), |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 585 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 586 | } |
Abhilash Raju | b5f288d | 2023-11-08 22:32:44 -0600 | [diff] [blame] | 587 | inline bool checkSizeLimit(int fd, crow::Response& res) |
| 588 | { |
| 589 | long long int size = lseek(fd, 0, SEEK_END); |
| 590 | if (size <= 0) |
| 591 | { |
| 592 | BMCWEB_LOG_ERROR("Failed to get size of file, lseek() returned {}", |
| 593 | size); |
| 594 | messages::internalError(res); |
| 595 | return false; |
| 596 | } |
Asmitha Karunanithi | 5cb1dd2 | 2020-05-07 04:35:02 -0500 | [diff] [blame] | 597 | |
Abhilash Raju | b5f288d | 2023-11-08 22:32:44 -0600 | [diff] [blame] | 598 | // Arbitrary max size of 20MB to accommodate BMC dumps |
| 599 | constexpr long long int maxFileSize = 20LL * 1024LL * 1024LL; |
| 600 | if (size > maxFileSize) |
| 601 | { |
| 602 | BMCWEB_LOG_ERROR("File size {} exceeds maximum allowed size of {}", |
| 603 | size, maxFileSize); |
| 604 | messages::internalError(res); |
| 605 | return false; |
| 606 | } |
| 607 | off_t rc = lseek(fd, 0, SEEK_SET); |
| 608 | if (rc < 0) |
| 609 | { |
| 610 | BMCWEB_LOG_ERROR("Failed to reset file offset to 0"); |
| 611 | messages::internalError(res); |
| 612 | return false; |
| 613 | } |
| 614 | return true; |
| 615 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 616 | inline void downloadEntryCallback( |
| 617 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 618 | const std::string& entryID, const std::string& downloadEntryType, |
| 619 | const boost::system::error_code& ec, |
| 620 | const sdbusplus::message::unix_fd& unixfd) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 621 | { |
| 622 | if (ec.value() == EBADR) |
| 623 | { |
| 624 | messages::resourceNotFound(asyncResp->res, "EntryAttachment", entryID); |
| 625 | return; |
| 626 | } |
| 627 | if (ec) |
| 628 | { |
| 629 | BMCWEB_LOG_ERROR("DBUS response error: {}", ec); |
| 630 | messages::internalError(asyncResp->res); |
| 631 | return; |
| 632 | } |
| 633 | |
| 634 | // Make sure we know how to process the retrieved entry attachment |
| 635 | if ((downloadEntryType != "BMC") && (downloadEntryType != "System")) |
| 636 | { |
| 637 | BMCWEB_LOG_ERROR("downloadEntryCallback() invalid entry type: {}", |
| 638 | downloadEntryType); |
| 639 | messages::internalError(asyncResp->res); |
| 640 | } |
| 641 | |
| 642 | int fd = -1; |
| 643 | fd = dup(unixfd); |
| 644 | if (fd < 0) |
| 645 | { |
| 646 | BMCWEB_LOG_ERROR("Failed to open file"); |
| 647 | messages::internalError(asyncResp->res); |
| 648 | return; |
| 649 | } |
Abhilash Raju | b5f288d | 2023-11-08 22:32:44 -0600 | [diff] [blame] | 650 | if (!checkSizeLimit(fd, asyncResp->res)) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 651 | { |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 652 | close(fd); |
| 653 | return; |
| 654 | } |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 655 | if (downloadEntryType == "System") |
| 656 | { |
Abhilash Raju | b5f288d | 2023-11-08 22:32:44 -0600 | [diff] [blame] | 657 | if (!asyncResp->res.openFd(fd, bmcweb::EncodingType::Base64)) |
| 658 | { |
| 659 | messages::internalError(asyncResp->res); |
| 660 | close(fd); |
| 661 | return; |
| 662 | } |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 663 | asyncResp->res.addHeader( |
| 664 | boost::beast::http::field::content_transfer_encoding, "Base64"); |
Abhilash Raju | b5f288d | 2023-11-08 22:32:44 -0600 | [diff] [blame] | 665 | return; |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 666 | } |
Abhilash Raju | b5f288d | 2023-11-08 22:32:44 -0600 | [diff] [blame] | 667 | if (!asyncResp->res.openFd(fd)) |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 668 | { |
Abhilash Raju | b5f288d | 2023-11-08 22:32:44 -0600 | [diff] [blame] | 669 | messages::internalError(asyncResp->res); |
| 670 | close(fd); |
| 671 | return; |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 672 | } |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 673 | asyncResp->res.addHeader(boost::beast::http::field::content_type, |
| 674 | "application/octet-stream"); |
| 675 | } |
| 676 | |
| 677 | inline void |
| 678 | downloadDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 679 | const std::string& entryID, const std::string& dumpType) |
| 680 | { |
| 681 | if (dumpType != "BMC") |
| 682 | { |
| 683 | BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID); |
| 684 | messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID); |
| 685 | return; |
| 686 | } |
| 687 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 688 | std::string dumpEntryPath = |
| 689 | std::format("{}/entry/{}", getDumpPath(dumpType), entryID); |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 690 | |
| 691 | auto downloadDumpEntryHandler = |
| 692 | [asyncResp, entryID, |
| 693 | dumpType](const boost::system::error_code& ec, |
| 694 | const sdbusplus::message::unix_fd& unixfd) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 695 | downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd); |
| 696 | }; |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 697 | |
| 698 | crow::connections::systemBus->async_method_call( |
| 699 | std::move(downloadDumpEntryHandler), "xyz.openbmc_project.Dump.Manager", |
| 700 | dumpEntryPath, "xyz.openbmc_project.Dump.Entry", "GetFileHandle"); |
| 701 | } |
| 702 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 703 | inline void downloadEventLogEntry( |
| 704 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 705 | const std::string& systemName, const std::string& entryID, |
| 706 | const std::string& dumpType) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 707 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 708 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 709 | { |
| 710 | // Option currently returns no systems. TBD |
| 711 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 712 | systemName); |
| 713 | return; |
| 714 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 715 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 716 | { |
| 717 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 718 | systemName); |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | std::string entryPath = |
| 723 | sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") / |
| 724 | entryID; |
| 725 | |
| 726 | auto downloadEventLogEntryHandler = |
| 727 | [asyncResp, entryID, |
| 728 | dumpType](const boost::system::error_code& ec, |
| 729 | const sdbusplus::message::unix_fd& unixfd) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 730 | downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd); |
| 731 | }; |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 732 | |
| 733 | crow::connections::systemBus->async_method_call( |
| 734 | std::move(downloadEventLogEntryHandler), "xyz.openbmc_project.Logging", |
| 735 | entryPath, "xyz.openbmc_project.Logging.Entry", "GetEntry"); |
| 736 | } |
| 737 | |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 738 | inline DumpCreationProgress |
| 739 | mapDbusStatusToDumpProgress(const std::string& status) |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 740 | { |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 741 | if (status == |
| 742 | "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" || |
| 743 | status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted") |
| 744 | { |
| 745 | return DumpCreationProgress::DUMP_CREATE_FAILED; |
| 746 | } |
| 747 | if (status == |
| 748 | "xyz.openbmc_project.Common.Progress.OperationStatus.Completed") |
| 749 | { |
| 750 | return DumpCreationProgress::DUMP_CREATE_SUCCESS; |
| 751 | } |
| 752 | return DumpCreationProgress::DUMP_CREATE_INPROGRESS; |
| 753 | } |
| 754 | |
| 755 | inline DumpCreationProgress |
| 756 | getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values) |
| 757 | { |
| 758 | for (const auto& [key, val] : values) |
| 759 | { |
| 760 | if (key == "Status") |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 761 | { |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 762 | const std::string* value = std::get_if<std::string>(&val); |
| 763 | if (value == nullptr) |
| 764 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 765 | BMCWEB_LOG_ERROR("Status property value is null"); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 766 | return DumpCreationProgress::DUMP_CREATE_FAILED; |
| 767 | } |
| 768 | return mapDbusStatusToDumpProgress(*value); |
| 769 | } |
| 770 | } |
| 771 | return DumpCreationProgress::DUMP_CREATE_INPROGRESS; |
| 772 | } |
| 773 | |
| 774 | inline std::string getDumpEntryPath(const std::string& dumpPath) |
| 775 | { |
| 776 | if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry") |
| 777 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 778 | return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/", |
Ed Tanous | 9f56509 | 2024-07-12 22:06:53 -0700 | [diff] [blame] | 779 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 780 | } |
| 781 | if (dumpPath == "/xyz/openbmc_project/dump/system/entry") |
| 782 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 783 | return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/", |
| 784 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 785 | } |
| 786 | return ""; |
| 787 | } |
| 788 | |
| 789 | inline void createDumpTaskCallback( |
| 790 | task::Payload&& payload, |
| 791 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 792 | const sdbusplus::message::object_path& createdObjPath) |
| 793 | { |
| 794 | const std::string dumpPath = createdObjPath.parent_path().str; |
| 795 | const std::string dumpId = createdObjPath.filename(); |
| 796 | |
| 797 | std::string dumpEntryPath = getDumpEntryPath(dumpPath); |
| 798 | |
| 799 | if (dumpEntryPath.empty()) |
| 800 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 801 | BMCWEB_LOG_ERROR("Invalid dump type received"); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 802 | messages::internalError(asyncResp->res); |
| 803 | return; |
| 804 | } |
| 805 | |
| 806 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 8cb2c02 | 2024-03-27 16:31:46 -0700 | [diff] [blame] | 807 | [asyncResp, payload = std::move(payload), createdObjPath, |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 808 | dumpEntryPath{std::move(dumpEntryPath)}, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 809 | dumpId](const boost::system::error_code& ec, |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 810 | const std::string& introspectXml) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 811 | if (ec) |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 812 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 813 | BMCWEB_LOG_ERROR("Introspect call failed with error: {}", |
| 814 | ec.message()); |
| 815 | messages::internalError(asyncResp->res); |
| 816 | return; |
| 817 | } |
| 818 | |
| 819 | // Check if the created dump object has implemented Progress |
| 820 | // interface to track dump completion. If yes, fetch the "Status" |
| 821 | // property of the interface, modify the task state accordingly. |
| 822 | // Else, return task completed. |
| 823 | tinyxml2::XMLDocument doc; |
| 824 | |
| 825 | doc.Parse(introspectXml.data(), introspectXml.size()); |
| 826 | tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node"); |
| 827 | if (pRoot == nullptr) |
| 828 | { |
| 829 | BMCWEB_LOG_ERROR("XML document failed to parse"); |
| 830 | messages::internalError(asyncResp->res); |
| 831 | return; |
| 832 | } |
| 833 | tinyxml2::XMLElement* interfaceNode = |
| 834 | pRoot->FirstChildElement("interface"); |
| 835 | |
| 836 | bool isProgressIntfPresent = false; |
| 837 | while (interfaceNode != nullptr) |
| 838 | { |
| 839 | const char* thisInterfaceName = |
| 840 | interfaceNode->Attribute("name"); |
| 841 | if (thisInterfaceName != nullptr) |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 842 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 843 | if (thisInterfaceName == |
| 844 | std::string_view("xyz.openbmc_project.Common.Progress")) |
| 845 | { |
| 846 | interfaceNode = |
| 847 | interfaceNode->NextSiblingElement("interface"); |
| 848 | continue; |
| 849 | } |
| 850 | isProgressIntfPresent = true; |
| 851 | break; |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 852 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 853 | interfaceNode = interfaceNode->NextSiblingElement("interface"); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 854 | } |
| 855 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 856 | std::shared_ptr<task::TaskData> task = task::TaskData::createTask( |
| 857 | [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent]( |
| 858 | const boost::system::error_code& ec2, |
| 859 | sdbusplus::message_t& msg, |
| 860 | const std::shared_ptr<task::TaskData>& taskData) { |
| 861 | if (ec2) |
| 862 | { |
| 863 | BMCWEB_LOG_ERROR("{}: Error in creating dump", |
| 864 | createdObjPath.str); |
| 865 | taskData->messages.emplace_back( |
| 866 | messages::internalError()); |
| 867 | taskData->state = "Cancelled"; |
| 868 | return task::completed; |
| 869 | } |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 870 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 871 | if (isProgressIntfPresent) |
| 872 | { |
| 873 | dbus::utility::DBusPropertiesMap values; |
| 874 | std::string prop; |
| 875 | msg.read(prop, values); |
| 876 | |
| 877 | DumpCreationProgress dumpStatus = |
| 878 | getDumpCompletionStatus(values); |
| 879 | if (dumpStatus == |
| 880 | DumpCreationProgress::DUMP_CREATE_FAILED) |
| 881 | { |
| 882 | BMCWEB_LOG_ERROR("{}: Error in creating dump", |
| 883 | createdObjPath.str); |
| 884 | taskData->state = "Cancelled"; |
| 885 | return task::completed; |
| 886 | } |
| 887 | |
| 888 | if (dumpStatus == |
| 889 | DumpCreationProgress::DUMP_CREATE_INPROGRESS) |
| 890 | { |
| 891 | BMCWEB_LOG_DEBUG( |
| 892 | "{}: Dump creation task is in progress", |
| 893 | createdObjPath.str); |
| 894 | return !task::completed; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | nlohmann::json retMessage = messages::success(); |
| 899 | taskData->messages.emplace_back(retMessage); |
| 900 | |
| 901 | boost::urls::url url = boost::urls::format( |
| 902 | "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}", |
| 903 | BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId); |
| 904 | |
| 905 | std::string headerLoc = "Location: "; |
| 906 | headerLoc += url.buffer(); |
| 907 | |
| 908 | taskData->payload->httpHeaders.emplace_back( |
| 909 | std::move(headerLoc)); |
| 910 | |
| 911 | BMCWEB_LOG_DEBUG("{}: Dump creation task completed", |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 912 | createdObjPath.str); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 913 | taskData->state = "Completed"; |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 914 | return task::completed; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 915 | }, |
| 916 | "type='signal',interface='org.freedesktop.DBus.Properties'," |
| 917 | "member='PropertiesChanged',path='" + |
| 918 | createdObjPath.str + "'"); |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 919 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 920 | // The task timer is set to max time limit within which the |
| 921 | // requested dump will be collected. |
| 922 | task->startTimer(std::chrono::minutes(6)); |
| 923 | task->populateResp(asyncResp->res); |
| 924 | task->payload.emplace(payload); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 925 | }, |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 926 | "xyz.openbmc_project.Dump.Manager", createdObjPath, |
| 927 | "org.freedesktop.DBus.Introspectable", "Introspect"); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 928 | } |
| 929 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 930 | inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 931 | const crow::Request& req, const std::string& dumpType) |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 932 | { |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 933 | std::string dumpPath = getDumpEntriesPath(dumpType); |
| 934 | if (dumpPath.empty()) |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 935 | { |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 936 | messages::internalError(asyncResp->res); |
| 937 | return; |
| 938 | } |
| 939 | |
| 940 | std::optional<std::string> diagnosticDataType; |
| 941 | std::optional<std::string> oemDiagnosticDataType; |
| 942 | |
Willy Tu | 15ed678 | 2021-12-14 11:03:16 -0800 | [diff] [blame] | 943 | if (!redfish::json_util::readJsonAction( |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 944 | req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, |
| 945 | "OEMDiagnosticDataType", oemDiagnosticDataType)) |
| 946 | { |
| 947 | return; |
| 948 | } |
| 949 | |
| 950 | if (dumpType == "System") |
| 951 | { |
| 952 | if (!oemDiagnosticDataType || !diagnosticDataType) |
| 953 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 954 | BMCWEB_LOG_ERROR( |
| 955 | "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 956 | messages::actionParameterMissing( |
| 957 | asyncResp->res, "CollectDiagnosticData", |
| 958 | "DiagnosticDataType & OEMDiagnosticDataType"); |
| 959 | return; |
| 960 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 961 | if ((*oemDiagnosticDataType != "System") || |
| 962 | (*diagnosticDataType != "OEM")) |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 963 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 964 | BMCWEB_LOG_ERROR("Wrong parameter values passed"); |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 965 | messages::internalError(asyncResp->res); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 966 | return; |
| 967 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 968 | dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/", |
| 969 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 970 | } |
| 971 | else if (dumpType == "BMC") |
| 972 | { |
| 973 | if (!diagnosticDataType) |
| 974 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 975 | BMCWEB_LOG_ERROR( |
| 976 | "CreateDump action parameter 'DiagnosticDataType' not found!"); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 977 | messages::actionParameterMissing( |
| 978 | asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); |
| 979 | return; |
| 980 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 981 | if (*diagnosticDataType != "Manager") |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 982 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 983 | BMCWEB_LOG_ERROR( |
| 984 | "Wrong parameter value passed for 'DiagnosticDataType'"); |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 985 | messages::internalError(asyncResp->res); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 986 | return; |
| 987 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 988 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/", |
| 989 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 990 | } |
| 991 | else |
| 992 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 993 | BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type"); |
Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 994 | messages::internalError(asyncResp->res); |
| 995 | return; |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 996 | } |
| 997 | |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 998 | std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>> |
| 999 | createDumpParamVec; |
| 1000 | |
Carson Labrado | f574a8e | 2023-03-22 02:26:00 +0000 | [diff] [blame] | 1001 | if (req.session != nullptr) |
| 1002 | { |
| 1003 | createDumpParamVec.emplace_back( |
| 1004 | "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId", |
| 1005 | req.session->clientIp); |
| 1006 | createDumpParamVec.emplace_back( |
| 1007 | "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType", |
| 1008 | "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client"); |
| 1009 | } |
Asmitha Karunanithi | 68dd075 | 2022-11-15 11:33:46 -0600 | [diff] [blame] | 1010 | |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 1011 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1012 | [asyncResp, payload(task::Payload(req)), |
| 1013 | dumpPath](const boost::system::error_code& ec, |
| 1014 | const sdbusplus::message_t& msg, |
| 1015 | const sdbusplus::message::object_path& objPath) mutable { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1016 | if (ec) |
Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 1017 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1018 | BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec); |
| 1019 | const sd_bus_error* dbusError = msg.get_error(); |
| 1020 | if (dbusError == nullptr) |
| 1021 | { |
| 1022 | messages::internalError(asyncResp->res); |
| 1023 | return; |
| 1024 | } |
| 1025 | |
| 1026 | BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}", |
| 1027 | dbusError->name, dbusError->message); |
| 1028 | if (std::string_view( |
| 1029 | "xyz.openbmc_project.Common.Error.NotAllowed") == |
| 1030 | dbusError->name) |
| 1031 | { |
| 1032 | messages::resourceInStandby(asyncResp->res); |
| 1033 | return; |
| 1034 | } |
| 1035 | if (std::string_view( |
| 1036 | "xyz.openbmc_project.Dump.Create.Error.Disabled") == |
| 1037 | dbusError->name) |
| 1038 | { |
| 1039 | messages::serviceDisabled(asyncResp->res, dumpPath); |
| 1040 | return; |
| 1041 | } |
| 1042 | if (std::string_view( |
| 1043 | "xyz.openbmc_project.Common.Error.Unavailable") == |
| 1044 | dbusError->name) |
| 1045 | { |
| 1046 | messages::resourceInUse(asyncResp->res); |
| 1047 | return; |
| 1048 | } |
| 1049 | // Other Dbus errors such as: |
| 1050 | // xyz.openbmc_project.Common.Error.InvalidArgument & |
| 1051 | // org.freedesktop.DBus.Error.InvalidArgs are all related to |
| 1052 | // the dbus call that is made here in the bmcweb |
| 1053 | // implementation and has nothing to do with the client's |
| 1054 | // input in the request. Hence, returning internal error |
| 1055 | // back to the client. |
Asmitha Karunanithi | 5907571 | 2021-10-22 01:17:41 -0500 | [diff] [blame] | 1056 | messages::internalError(asyncResp->res); |
| 1057 | return; |
| 1058 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1059 | BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str); |
| 1060 | createDumpTaskCallback(std::move(payload), asyncResp, objPath); |
| 1061 | }, |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 1062 | "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType), |
Asmitha Karunanithi | 8e31778 | 2020-12-10 03:35:05 -0600 | [diff] [blame] | 1063 | "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec); |
Asmitha Karunanithi | a43be80 | 2020-05-07 05:05:36 -0500 | [diff] [blame] | 1064 | } |
| 1065 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1066 | inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1067 | const std::string& dumpType) |
Asmitha Karunanithi | 80319af | 2020-05-07 05:30:21 -0500 | [diff] [blame] | 1068 | { |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 1069 | crow::connections::systemBus->async_method_call( |
| 1070 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1071 | if (ec) |
| 1072 | { |
| 1073 | BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec); |
| 1074 | messages::internalError(asyncResp->res); |
| 1075 | return; |
| 1076 | } |
| 1077 | }, |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 1078 | "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType), |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 1079 | "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); |
Asmitha Karunanithi | 80319af | 2020-05-07 05:30:21 -0500 | [diff] [blame] | 1080 | } |
| 1081 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1082 | inline void parseCrashdumpParameters( |
| 1083 | const dbus::utility::DBusPropertiesMap& params, std::string& filename, |
| 1084 | std::string& timestamp, std::string& logfile) |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 1085 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1086 | const std::string* filenamePtr = nullptr; |
| 1087 | const std::string* timestampPtr = nullptr; |
| 1088 | const std::string* logfilePtr = nullptr; |
| 1089 | |
| 1090 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 1091 | dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr, |
| 1092 | "Filename", filenamePtr, "Log", logfilePtr); |
| 1093 | |
| 1094 | if (!success) |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 1095 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1096 | return; |
| 1097 | } |
| 1098 | |
| 1099 | if (filenamePtr != nullptr) |
| 1100 | { |
| 1101 | filename = *filenamePtr; |
| 1102 | } |
| 1103 | |
| 1104 | if (timestampPtr != nullptr) |
| 1105 | { |
| 1106 | timestamp = *timestampPtr; |
| 1107 | } |
| 1108 | |
| 1109 | if (logfilePtr != nullptr) |
| 1110 | { |
| 1111 | logfile = *logfilePtr; |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1115 | inline void requestRoutesSystemLogServiceCollection(App& app) |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 1116 | { |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1117 | /** |
| 1118 | * Functions triggers appropriate requests on DBus |
| 1119 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1120 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1121 | .privileges(redfish::privileges::getLogServiceCollection) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1122 | .methods( |
| 1123 | boost::beast::http::verb:: |
| 1124 | get)([&app](const crow::Request& req, |
| 1125 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1126 | const std::string& systemName) { |
| 1127 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1128 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1129 | return; |
| 1130 | } |
| 1131 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1132 | { |
| 1133 | // Option currently returns no systems. TBD |
| 1134 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1135 | systemName); |
| 1136 | return; |
| 1137 | } |
| 1138 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1139 | { |
| 1140 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1141 | systemName); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1142 | return; |
| 1143 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1144 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1145 | // Collections don't include the static data added by SubRoute |
| 1146 | // because it has a duplicate entry for members |
| 1147 | asyncResp->res.jsonValue["@odata.type"] = |
| 1148 | "#LogServiceCollection.LogServiceCollection"; |
| 1149 | asyncResp->res.jsonValue["@odata.id"] = |
| 1150 | std::format("/redfish/v1/Systems/{}/LogServices", |
| 1151 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1152 | asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; |
| 1153 | asyncResp->res.jsonValue["Description"] = |
| 1154 | "Collection of LogServices for this Computer System"; |
| 1155 | nlohmann::json& logServiceArray = |
| 1156 | asyncResp->res.jsonValue["Members"]; |
| 1157 | logServiceArray = nlohmann::json::array(); |
| 1158 | nlohmann::json::object_t eventLog; |
| 1159 | eventLog["@odata.id"] = |
| 1160 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog", |
| 1161 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1162 | logServiceArray.emplace_back(std::move(eventLog)); |
| 1163 | if constexpr (BMCWEB_REDFISH_DUMP_LOG) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1164 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1165 | nlohmann::json::object_t dumpLog; |
| 1166 | dumpLog["@odata.id"] = |
| 1167 | std::format("/redfish/v1/Systems/{}/LogServices/Dump", |
| 1168 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1169 | logServiceArray.emplace_back(std::move(dumpLog)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1170 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1171 | |
| 1172 | if constexpr (BMCWEB_REDFISH_CPU_LOG) |
| 1173 | { |
| 1174 | nlohmann::json::object_t crashdump; |
| 1175 | crashdump["@odata.id"] = |
| 1176 | std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", |
| 1177 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1178 | logServiceArray.emplace_back(std::move(crashdump)); |
| 1179 | } |
| 1180 | |
| 1181 | if constexpr (BMCWEB_REDFISH_HOST_LOGGER) |
| 1182 | { |
| 1183 | nlohmann::json::object_t hostlogger; |
| 1184 | hostlogger["@odata.id"] = |
| 1185 | std::format("/redfish/v1/Systems/{}/LogServices/HostLogger", |
| 1186 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1187 | logServiceArray.emplace_back(std::move(hostlogger)); |
| 1188 | } |
| 1189 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1190 | logServiceArray.size(); |
| 1191 | |
| 1192 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1193 | "xyz.openbmc_project.State.Boot.PostCode"}; |
| 1194 | dbus::utility::getSubTreePaths( |
| 1195 | "/", 0, interfaces, |
| 1196 | [asyncResp](const boost::system::error_code& ec, |
| 1197 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 1198 | subtreePath) { |
| 1199 | if (ec) |
| 1200 | { |
| 1201 | BMCWEB_LOG_ERROR("{}", ec); |
| 1202 | return; |
| 1203 | } |
| 1204 | |
| 1205 | for (const auto& pathStr : subtreePath) |
| 1206 | { |
| 1207 | if (pathStr.find("PostCode") != std::string::npos) |
| 1208 | { |
| 1209 | nlohmann::json& logServiceArrayLocal = |
| 1210 | asyncResp->res.jsonValue["Members"]; |
| 1211 | nlohmann::json::object_t member; |
| 1212 | member["@odata.id"] = std::format( |
| 1213 | "/redfish/v1/Systems/{}/LogServices/PostCodes", |
| 1214 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1215 | |
| 1216 | logServiceArrayLocal.emplace_back( |
| 1217 | std::move(member)); |
| 1218 | |
| 1219 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1220 | logServiceArrayLocal.size(); |
| 1221 | return; |
| 1222 | } |
| 1223 | } |
| 1224 | }); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1225 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | inline void requestRoutesEventLogService(App& app) |
| 1229 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1230 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1231 | .privileges(redfish::privileges::getLogService) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1232 | .methods( |
| 1233 | boost::beast::http::verb:: |
| 1234 | get)([&app](const crow::Request& req, |
| 1235 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1236 | const std::string& systemName) { |
| 1237 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1238 | { |
| 1239 | return; |
| 1240 | } |
| 1241 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1242 | { |
| 1243 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1244 | systemName); |
| 1245 | return; |
| 1246 | } |
| 1247 | asyncResp->res.jsonValue["@odata.id"] = |
| 1248 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog", |
| 1249 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1250 | asyncResp->res.jsonValue["@odata.type"] = |
| 1251 | "#LogService.v1_2_0.LogService"; |
| 1252 | asyncResp->res.jsonValue["Name"] = "Event Log Service"; |
| 1253 | asyncResp->res.jsonValue["Description"] = |
| 1254 | "System Event Log Service"; |
| 1255 | asyncResp->res.jsonValue["Id"] = "EventLog"; |
| 1256 | asyncResp->res.jsonValue["OverWritePolicy"] = |
| 1257 | log_service::OverWritePolicy::WrapsWhenFull; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1258 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1259 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| 1260 | redfish::time_utils::getDateTimeOffsetNow(); |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1261 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1262 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 1263 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 1264 | redfishDateTimeOffset.second; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 1265 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1266 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format( |
| 1267 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries", |
Ed Tanous | 20fa6a2 | 2024-05-20 18:02:58 -0700 | [diff] [blame] | 1268 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1269 | asyncResp->res |
| 1270 | .jsonValue["Actions"]["#LogService.ClearLog"]["target"] |
| 1271 | |
| 1272 | = std::format( |
| 1273 | "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog", |
| 1274 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1275 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1278 | inline void handleSystemsLogServicesEventLogActionsClearPost( |
| 1279 | App& app, const crow::Request& req, |
| 1280 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1281 | const std::string& systemName) |
| 1282 | { |
| 1283 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1284 | { |
| 1285 | return; |
| 1286 | } |
| 1287 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1288 | { |
| 1289 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1290 | systemName); |
| 1291 | return; |
| 1292 | } |
| 1293 | |
| 1294 | // Clear the EventLog by deleting the log files |
| 1295 | std::vector<std::filesystem::path> redfishLogFiles; |
| 1296 | if (getRedfishLogFiles(redfishLogFiles)) |
| 1297 | { |
| 1298 | for (const std::filesystem::path& file : redfishLogFiles) |
| 1299 | { |
| 1300 | std::error_code ec; |
| 1301 | std::filesystem::remove(file, ec); |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | // Reload rsyslog so it knows to start new log files |
| 1306 | crow::connections::systemBus->async_method_call( |
| 1307 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1308 | if (ec) |
| 1309 | { |
| 1310 | BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec); |
| 1311 | messages::internalError(asyncResp->res); |
| 1312 | return; |
| 1313 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1314 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1315 | messages::success(asyncResp->res); |
| 1316 | }, |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1317 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 1318 | "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", |
| 1319 | "replace"); |
| 1320 | } |
| 1321 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1322 | inline void requestRoutesJournalEventLogClear(App& app) |
| 1323 | { |
Jason M. Bills | 4978b63 | 2022-02-22 14:17:43 -0800 | [diff] [blame] | 1324 | BMCWEB_ROUTE( |
| 1325 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1326 | "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 1327 | .privileges({{"ConfigureComponents"}}) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1328 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 1329 | handleSystemsLogServicesEventLogActionsClearPost, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1330 | } |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1331 | |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1332 | enum class LogParseError |
| 1333 | { |
| 1334 | success, |
| 1335 | parseFailed, |
| 1336 | messageIdNotInRegistry, |
| 1337 | }; |
| 1338 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1339 | static LogParseError fillEventLogEntryJson( |
| 1340 | const std::string& logEntryID, const std::string& logEntry, |
| 1341 | nlohmann::json::object_t& logEntryJson) |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1342 | { |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1343 | // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1344 | // First get the Timestamp |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 1345 | size_t space = logEntry.find_first_of(' '); |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1346 | if (space == std::string::npos) |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1347 | { |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1348 | return LogParseError::parseFailed; |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1349 | } |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1350 | std::string timestamp = logEntry.substr(0, space); |
| 1351 | // Then get the log contents |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 1352 | size_t entryStart = logEntry.find_first_not_of(' ', space); |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1353 | if (entryStart == std::string::npos) |
| 1354 | { |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1355 | return LogParseError::parseFailed; |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1356 | } |
| 1357 | std::string_view entry(logEntry); |
| 1358 | entry.remove_prefix(entryStart); |
| 1359 | // Use split to separate the entry into its fields |
| 1360 | std::vector<std::string> logEntryFields; |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 1361 | bmcweb::split(logEntryFields, entry, ','); |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1362 | // We need at least a MessageId to be valid |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1363 | auto logEntryIter = logEntryFields.begin(); |
| 1364 | if (logEntryIter == logEntryFields.end()) |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1365 | { |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1366 | return LogParseError::parseFailed; |
Jason M. Bills | cd225da | 2019-05-08 15:31:57 -0700 | [diff] [blame] | 1367 | } |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1368 | std::string& messageID = *logEntryIter; |
Jason M. Bills | 4851d45 | 2019-03-28 11:27:48 -0700 | [diff] [blame] | 1369 | // Get the Message from the MessageRegistry |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 1370 | const registries::Message* message = registries::getMessage(messageID); |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1371 | |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1372 | logEntryIter++; |
Sui Chen | 54417b0 | 2022-03-24 14:59:52 -0700 | [diff] [blame] | 1373 | if (message == nullptr) |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1374 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1375 | BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry); |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1376 | return LogParseError::messageIdNotInRegistry; |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1377 | } |
| 1378 | |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1379 | std::vector<std::string_view> messageArgs(logEntryIter, |
| 1380 | logEntryFields.end()); |
Ed Tanous | c05bba4 | 2023-06-28 08:33:29 -0700 | [diff] [blame] | 1381 | messageArgs.resize(message->numberOfArgs); |
| 1382 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1383 | std::string msg = |
| 1384 | redfish::registries::fillMessageArgs(messageArgs, message->message); |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1385 | if (msg.empty()) |
Jason M. Bills | 4851d45 | 2019-03-28 11:27:48 -0700 | [diff] [blame] | 1386 | { |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 1387 | return LogParseError::parseFailed; |
Jason M. Bills | 4851d45 | 2019-03-28 11:27:48 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1390 | // Get the Created time from the timestamp. The log timestamp is in RFC3339 |
| 1391 | // format which matches the Redfish format except for the fractional seconds |
| 1392 | // between the '.' and the '+', so just remove them. |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 1393 | std::size_t dot = timestamp.find_first_of('.'); |
| 1394 | std::size_t plus = timestamp.find_first_of('+'); |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1395 | if (dot != std::string::npos && plus != std::string::npos) |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1396 | { |
Jason M. Bills | 9582018 | 2019-04-22 16:25:34 -0700 | [diff] [blame] | 1397 | timestamp.erase(dot, plus - dot); |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | // Fill in the log entry with the gathered data |
Vijay Lobo | 9c11a17 | 2021-10-07 16:53:16 -0500 | [diff] [blame] | 1401 | logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 1402 | logEntryJson["@odata.id"] = boost::urls::format( |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1403 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}", |
| 1404 | BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID); |
Jason M. Bills | 84afc48 | 2022-06-24 12:38:23 -0700 | [diff] [blame] | 1405 | logEntryJson["Name"] = "System Event Log Entry"; |
| 1406 | logEntryJson["Id"] = logEntryID; |
| 1407 | logEntryJson["Message"] = std::move(msg); |
| 1408 | logEntryJson["MessageId"] = std::move(messageID); |
| 1409 | logEntryJson["MessageArgs"] = messageArgs; |
| 1410 | logEntryJson["EntryType"] = "Event"; |
| 1411 | logEntryJson["Severity"] = message->messageSeverity; |
| 1412 | logEntryJson["Created"] = std::move(timestamp); |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1413 | return LogParseError::success; |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1414 | } |
| 1415 | |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1416 | inline void fillEventLogLogEntryFromPropertyMap( |
| 1417 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1418 | const dbus::utility::DBusPropertiesMap& resp, |
| 1419 | nlohmann::json& objectToFillOut) |
| 1420 | { |
| 1421 | uint32_t id = 0; |
| 1422 | uint64_t timestamp = 0; |
| 1423 | uint64_t updateTimestamp = 0; |
| 1424 | std::string severity; |
| 1425 | std::string message; |
| 1426 | const std::string* filePath = nullptr; |
| 1427 | const std::string* resolution = nullptr; |
| 1428 | bool resolved = false; |
| 1429 | std::string notify; |
| 1430 | // clang-format off |
| 1431 | bool success = sdbusplus::unpackPropertiesNoThrow( |
| 1432 | dbus_utils::UnpackErrorPrinter(), resp, |
| 1433 | "Id", id, |
| 1434 | "Message", message, |
| 1435 | "Path", filePath, |
| 1436 | "Resolution", resolution, |
| 1437 | "Resolved", resolved, |
| 1438 | "ServiceProviderNotify", notify, |
| 1439 | "Severity", severity, |
| 1440 | "Timestamp", timestamp, |
| 1441 | "UpdateTimestamp", updateTimestamp |
| 1442 | ); |
| 1443 | // clang-format on |
| 1444 | |
| 1445 | if (!success) |
| 1446 | { |
| 1447 | messages::internalError(asyncResp->res); |
| 1448 | return; |
| 1449 | } |
| 1450 | |
| 1451 | objectToFillOut["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
| 1452 | objectToFillOut["@odata.id"] = boost::urls::format( |
| 1453 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}", |
| 1454 | BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(id)); |
| 1455 | objectToFillOut["Name"] = "System Event Log Entry"; |
| 1456 | objectToFillOut["Id"] = std::to_string(id); |
| 1457 | objectToFillOut["Message"] = message; |
| 1458 | objectToFillOut["Resolved"] = resolved; |
| 1459 | std::optional<bool> notifyAction = getProviderNotifyAction(notify); |
| 1460 | if (notifyAction) |
| 1461 | { |
| 1462 | objectToFillOut["ServiceProviderNotified"] = *notifyAction; |
| 1463 | } |
| 1464 | if ((resolution != nullptr) && !resolution->empty()) |
| 1465 | { |
| 1466 | objectToFillOut["Resolution"] = *resolution; |
| 1467 | } |
| 1468 | objectToFillOut["EntryType"] = "Event"; |
| 1469 | objectToFillOut["Severity"] = translateSeverityDbusToRedfish(severity); |
| 1470 | objectToFillOut["Created"] = |
| 1471 | redfish::time_utils::getDateTimeUintMs(timestamp); |
| 1472 | objectToFillOut["Modified"] = |
| 1473 | redfish::time_utils::getDateTimeUintMs(updateTimestamp); |
| 1474 | if (filePath != nullptr) |
| 1475 | { |
| 1476 | objectToFillOut["AdditionalDataURI"] = boost::urls::format( |
| 1477 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment", |
| 1478 | BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(id)); |
| 1479 | } |
| 1480 | } |
| 1481 | |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1482 | inline void afterLogEntriesGetManagedObjects( |
| 1483 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1484 | const boost::system::error_code& ec, |
| 1485 | const dbus::utility::ManagedObjectType& resp) |
| 1486 | { |
| 1487 | if (ec) |
| 1488 | { |
| 1489 | // TODO Handle for specific error code |
| 1490 | BMCWEB_LOG_ERROR("getLogEntriesIfaceData resp_handler got error {}", |
| 1491 | ec); |
| 1492 | messages::internalError(asyncResp->res); |
| 1493 | return; |
| 1494 | } |
| 1495 | nlohmann::json::array_t entriesArray; |
| 1496 | for (const auto& objectPath : resp) |
| 1497 | { |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1498 | dbus::utility::DBusPropertiesMap propsFlattened; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1499 | auto isEntry = |
| 1500 | std::ranges::find_if(objectPath.second, [](const auto& object) { |
| 1501 | return object.first == "xyz.openbmc_project.Logging.Entry"; |
| 1502 | }); |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1503 | if (isEntry == objectPath.second.end()) |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1504 | { |
| 1505 | continue; |
| 1506 | } |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1507 | for (const auto& interfaceMap : objectPath.second) |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1508 | { |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1509 | for (const auto& propertyMap : interfaceMap.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 | propsFlattened.emplace_back(propertyMap.first, |
| 1512 | propertyMap.second); |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1513 | } |
| 1514 | } |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1515 | fillEventLogLogEntryFromPropertyMap(asyncResp, propsFlattened, |
| 1516 | entriesArray.emplace_back()); |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1517 | } |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1518 | |
Ed Tanous | b729096 | 2024-08-07 11:09:51 -0700 | [diff] [blame] | 1519 | std::ranges::sort(entriesArray, [](const nlohmann::json& left, |
| 1520 | const nlohmann::json& right) { |
| 1521 | return (left["Id"] <= right["Id"]); |
| 1522 | }); |
| 1523 | asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size(); |
| 1524 | asyncResp->res.jsonValue["Members"] = std::move(entriesArray); |
| 1525 | } |
| 1526 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1527 | inline void handleSystemsLogServiceEventLogLogEntryCollection( |
| 1528 | App& app, const crow::Request& req, |
| 1529 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1530 | const std::string& systemName) |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1531 | { |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1532 | query_param::QueryCapabilities capabilities = { |
| 1533 | .canDelegateTop = true, |
| 1534 | .canDelegateSkip = true, |
| 1535 | }; |
| 1536 | query_param::Query delegatedQuery; |
| 1537 | if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp, |
| 1538 | delegatedQuery, capabilities)) |
| 1539 | { |
| 1540 | return; |
| 1541 | } |
| 1542 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1543 | { |
| 1544 | // Option currently returns no systems. TBD |
| 1545 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1546 | systemName); |
| 1547 | return; |
| 1548 | } |
| 1549 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1550 | { |
| 1551 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1552 | systemName); |
| 1553 | return; |
| 1554 | } |
| 1555 | |
| 1556 | size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); |
| 1557 | size_t skip = delegatedQuery.skip.value_or(0); |
| 1558 | |
| 1559 | // Collections don't include the static data added by SubRoute |
| 1560 | // because it has a duplicate entry for members |
| 1561 | asyncResp->res.jsonValue["@odata.type"] = |
| 1562 | "#LogEntryCollection.LogEntryCollection"; |
| 1563 | asyncResp->res.jsonValue["@odata.id"] = |
| 1564 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries", |
| 1565 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1566 | asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; |
| 1567 | asyncResp->res.jsonValue["Description"] = |
| 1568 | "Collection of System Event Log Entries"; |
| 1569 | |
| 1570 | nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; |
| 1571 | logEntryArray = nlohmann::json::array(); |
| 1572 | // Go through the log files and create a unique ID for each |
| 1573 | // entry |
| 1574 | std::vector<std::filesystem::path> redfishLogFiles; |
| 1575 | getRedfishLogFiles(redfishLogFiles); |
| 1576 | uint64_t entryCount = 0; |
| 1577 | std::string logEntry; |
| 1578 | |
| 1579 | // Oldest logs are in the last file, so start there and loop |
| 1580 | // backwards |
| 1581 | for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++) |
| 1582 | { |
| 1583 | std::ifstream logStream(*it); |
| 1584 | if (!logStream.is_open()) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1585 | { |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1586 | continue; |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1589 | // Reset the unique ID on the first entry |
| 1590 | bool firstEntry = true; |
| 1591 | while (std::getline(logStream, logEntry)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1592 | { |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1593 | std::string idStr; |
| 1594 | if (!getUniqueEntryID(logEntry, idStr, firstEntry)) |
| 1595 | { |
| 1596 | continue; |
| 1597 | } |
| 1598 | firstEntry = false; |
| 1599 | |
| 1600 | nlohmann::json::object_t bmcLogEntry; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1601 | LogParseError status = |
| 1602 | fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1603 | if (status == LogParseError::messageIdNotInRegistry) |
| 1604 | { |
| 1605 | continue; |
| 1606 | } |
| 1607 | if (status != LogParseError::success) |
| 1608 | { |
| 1609 | messages::internalError(asyncResp->res); |
| 1610 | return; |
| 1611 | } |
| 1612 | |
| 1613 | entryCount++; |
| 1614 | // Handle paging using skip (number of entries to skip from the |
| 1615 | // start) and top (number of entries to display) |
| 1616 | if (entryCount <= skip || entryCount > skip + top) |
Jason M. Bills | 4978b63 | 2022-02-22 14:17:43 -0800 | [diff] [blame] | 1617 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1618 | continue; |
Jason M. Bills | 4978b63 | 2022-02-22 14:17:43 -0800 | [diff] [blame] | 1619 | } |
Jason M. Bills | 897967d | 2019-07-29 17:05:30 -0700 | [diff] [blame] | 1620 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1621 | logEntryArray.emplace_back(std::move(bmcLogEntry)); |
| 1622 | } |
| 1623 | } |
| 1624 | asyncResp->res.jsonValue["Members@odata.count"] = entryCount; |
| 1625 | if (skip + top < entryCount) |
| 1626 | { |
| 1627 | asyncResp->res.jsonValue["Members@odata.nextLink"] = |
| 1628 | boost::urls::format( |
| 1629 | "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}", |
| 1630 | BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top)); |
| 1631 | } |
| 1632 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1633 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1634 | inline void requestRoutesJournalEventLogEntryCollection(App& app) |
| 1635 | { |
| 1636 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") |
| 1637 | .privileges(redfish::privileges::getLogEntryCollection) |
| 1638 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1639 | handleSystemsLogServiceEventLogLogEntryCollection, std::ref(app))); |
| 1640 | } |
| 1641 | |
| 1642 | inline void handleSystemsLogServiceEventLogEntriesGet( |
| 1643 | App& app, const crow::Request& req, |
| 1644 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1645 | const std::string& systemName, const std::string& param) |
| 1646 | { |
| 1647 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1648 | { |
| 1649 | return; |
| 1650 | } |
| 1651 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1652 | { |
| 1653 | // Option currently returns no systems. TBD |
| 1654 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1655 | systemName); |
| 1656 | return; |
| 1657 | } |
| 1658 | |
| 1659 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1660 | { |
| 1661 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1662 | systemName); |
| 1663 | return; |
| 1664 | } |
| 1665 | |
| 1666 | const std::string& targetID = param; |
| 1667 | |
| 1668 | // Go through the log files and check the unique ID for each |
| 1669 | // entry to find the target entry |
| 1670 | std::vector<std::filesystem::path> redfishLogFiles; |
| 1671 | getRedfishLogFiles(redfishLogFiles); |
| 1672 | std::string logEntry; |
| 1673 | |
| 1674 | // Oldest logs are in the last file, so start there and loop |
| 1675 | // backwards |
| 1676 | for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++) |
| 1677 | { |
| 1678 | std::ifstream logStream(*it); |
| 1679 | if (!logStream.is_open()) |
| 1680 | { |
| 1681 | continue; |
| 1682 | } |
| 1683 | |
| 1684 | // Reset the unique ID on the first entry |
| 1685 | bool firstEntry = true; |
| 1686 | while (std::getline(logStream, logEntry)) |
| 1687 | { |
| 1688 | std::string idStr; |
| 1689 | if (!getUniqueEntryID(logEntry, idStr, firstEntry)) |
| 1690 | { |
| 1691 | continue; |
| 1692 | } |
| 1693 | firstEntry = false; |
| 1694 | |
| 1695 | if (idStr == targetID) |
| 1696 | { |
Jason M. Bills | de703c5 | 2022-06-23 14:19:04 -0700 | [diff] [blame] | 1697 | nlohmann::json::object_t bmcLogEntry; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1698 | LogParseError status = |
| 1699 | fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); |
Jason M. Bills | ac992cd | 2022-06-24 13:31:46 -0700 | [diff] [blame] | 1700 | if (status != LogParseError::success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1701 | { |
| 1702 | messages::internalError(asyncResp->res); |
| 1703 | return; |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 1704 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1705 | asyncResp->res.jsonValue.update(bmcLogEntry); |
| 1706 | return; |
Jason M. Bills | 4978b63 | 2022-02-22 14:17:43 -0800 | [diff] [blame] | 1707 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1708 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1709 | } |
| 1710 | // Requested ID was not found |
| 1711 | messages::resourceNotFound(asyncResp->res, "LogEntry", targetID); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1712 | } |
Chicago Duan | 336e96c | 2019-07-15 14:22:08 +0800 | [diff] [blame] | 1713 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1714 | inline void requestRoutesJournalEventLogEntry(App& app) |
| 1715 | { |
| 1716 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1717 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1718 | .privileges(redfish::privileges::getLogEntry) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1719 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1720 | handleSystemsLogServiceEventLogEntriesGet, std::ref(app))); |
| 1721 | } |
| 1722 | |
| 1723 | inline void dBusEventLogEntryCollection( |
| 1724 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1725 | { |
| 1726 | // Collections don't include the static data added by SubRoute |
| 1727 | // because it has a duplicate entry for members |
| 1728 | asyncResp->res.jsonValue["@odata.type"] = |
| 1729 | "#LogEntryCollection.LogEntryCollection"; |
| 1730 | asyncResp->res.jsonValue["@odata.id"] = |
| 1731 | std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries", |
| 1732 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 1733 | asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; |
| 1734 | asyncResp->res.jsonValue["Description"] = |
| 1735 | "Collection of System Event Log Entries"; |
| 1736 | |
| 1737 | // DBus implementation of EventLog/Entries |
| 1738 | // Make call to Logging Service to find all log entry objects |
| 1739 | sdbusplus::message::object_path path("/xyz/openbmc_project/logging"); |
| 1740 | dbus::utility::getManagedObjects( |
| 1741 | "xyz.openbmc_project.Logging", path, |
| 1742 | [asyncResp](const boost::system::error_code& ec, |
| 1743 | const dbus::utility::ManagedObjectType& resp) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1744 | afterLogEntriesGetManagedObjects(asyncResp, ec, resp); |
| 1745 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | inline void requestRoutesDBusEventLogEntryCollection(App& app) |
| 1749 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1750 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1751 | .privileges(redfish::privileges::getLogEntryCollection) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1752 | .methods(boost::beast::http::verb::get)( |
| 1753 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1754 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1755 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1756 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1757 | { |
| 1758 | return; |
| 1759 | } |
| 1760 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1761 | { |
| 1762 | // Option currently returns no systems. TBD |
| 1763 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1764 | systemName); |
| 1765 | return; |
| 1766 | } |
| 1767 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1768 | { |
| 1769 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1770 | systemName); |
| 1771 | return; |
| 1772 | } |
| 1773 | dBusEventLogEntryCollection(asyncResp); |
| 1774 | }); |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1775 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1776 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1777 | inline void dBusEventLogEntryGet( |
| 1778 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1779 | { |
| 1780 | dbus::utility::escapePathForDbus(entryID); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1781 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1782 | // DBus implementation of EventLog/Entries |
| 1783 | // Make call to Logging Service to find all log entry objects |
| 1784 | sdbusplus::asio::getAllProperties( |
| 1785 | *crow::connections::systemBus, "xyz.openbmc_project.Logging", |
| 1786 | "/xyz/openbmc_project/logging/entry/" + entryID, "", |
| 1787 | [asyncResp, entryID](const boost::system::error_code& ec, |
| 1788 | const dbus::utility::DBusPropertiesMap& resp) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1789 | if (ec.value() == EBADR) |
| 1790 | { |
| 1791 | messages::resourceNotFound(asyncResp->res, "EventLogEntry", |
| 1792 | entryID); |
| 1793 | return; |
| 1794 | } |
| 1795 | if (ec) |
| 1796 | { |
| 1797 | BMCWEB_LOG_ERROR( |
| 1798 | "EventLogEntry (DBus) resp_handler got error {}", ec); |
| 1799 | messages::internalError(asyncResp->res); |
| 1800 | return; |
| 1801 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1802 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1803 | fillEventLogLogEntryFromPropertyMap(asyncResp, resp, |
| 1804 | asyncResp->res.jsonValue); |
| 1805 | }); |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | inline void |
| 1809 | dBusEventLogEntryPatch(const crow::Request& req, |
| 1810 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1811 | const std::string& entryId) |
| 1812 | { |
| 1813 | std::optional<bool> resolved; |
| 1814 | |
| 1815 | if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", resolved)) |
| 1816 | { |
| 1817 | return; |
| 1818 | } |
| 1819 | BMCWEB_LOG_DEBUG("Set Resolved"); |
| 1820 | |
| 1821 | setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging", |
| 1822 | "/xyz/openbmc_project/logging/entry/" + entryId, |
| 1823 | "xyz.openbmc_project.Logging.Entry", "Resolved", |
| 1824 | resolved.value_or(false)); |
| 1825 | } |
| 1826 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1827 | inline void dBusEventLogEntryDelete( |
| 1828 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID) |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1829 | { |
| 1830 | BMCWEB_LOG_DEBUG("Do delete single event entries."); |
| 1831 | |
| 1832 | dbus::utility::escapePathForDbus(entryID); |
| 1833 | |
| 1834 | // Process response from Logging service. |
| 1835 | auto respHandler = [asyncResp, |
| 1836 | entryID](const boost::system::error_code& ec) { |
| 1837 | BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done"); |
| 1838 | if (ec) |
| 1839 | { |
| 1840 | if (ec.value() == EBADR) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1841 | { |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1842 | messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1843 | return; |
| 1844 | } |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1845 | // TODO Handle for specific error code |
| 1846 | BMCWEB_LOG_ERROR( |
| 1847 | "EventLogEntry (DBus) doDelete respHandler got error {}", ec); |
| 1848 | asyncResp->res.result( |
| 1849 | boost::beast::http::status::internal_server_error); |
| 1850 | return; |
| 1851 | } |
Abhishek Patel | 9017faf | 2021-09-14 22:48:55 -0500 | [diff] [blame] | 1852 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 1853 | asyncResp->res.result(boost::beast::http::status::ok); |
| 1854 | }; |
| 1855 | |
| 1856 | // Make call to Logging service to request Delete Log |
| 1857 | crow::connections::systemBus->async_method_call( |
| 1858 | respHandler, "xyz.openbmc_project.Logging", |
| 1859 | "/xyz/openbmc_project/logging/entry/" + entryID, |
| 1860 | "xyz.openbmc_project.Object.Delete", "Delete"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1861 | } |
Xiaochao Ma | 75710de | 2021-01-21 17:56:02 +0800 | [diff] [blame] | 1862 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1863 | inline void requestRoutesDBusEventLogEntry(App& app) |
Adriana Kobylak | 400fd1f | 2021-01-29 09:01:30 -0600 | [diff] [blame] | 1864 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1865 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1866 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1867 | .privileges(redfish::privileges::getLogEntry) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1868 | .methods(boost::beast::http::verb::get)( |
| 1869 | [&app](const crow::Request& req, |
| 1870 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 898f2aa | 2024-08-07 12:18:22 -0700 | [diff] [blame] | 1871 | const std::string& systemName, const std::string& entryId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1872 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1873 | { |
| 1874 | return; |
| 1875 | } |
| 1876 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1877 | { |
| 1878 | // Option currently returns no systems. TBD |
| 1879 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1880 | systemName); |
| 1881 | return; |
| 1882 | } |
| 1883 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1884 | { |
| 1885 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1886 | systemName); |
| 1887 | return; |
| 1888 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1889 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1890 | dBusEventLogEntryGet(asyncResp, entryId); |
| 1891 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1892 | |
| 1893 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1894 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1895 | .privileges(redfish::privileges::patchLogEntry) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1896 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1897 | [&app](const crow::Request& req, |
| 1898 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1899 | const std::string& systemName, const std::string& entryId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1900 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1901 | { |
| 1902 | return; |
| 1903 | } |
| 1904 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1905 | { |
| 1906 | // Option currently returns no systems. TBD |
| 1907 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1908 | systemName); |
| 1909 | return; |
| 1910 | } |
| 1911 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1912 | { |
| 1913 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1914 | systemName); |
| 1915 | return; |
| 1916 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1917 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1918 | dBusEventLogEntryPatch(req, asyncResp, entryId); |
| 1919 | }); |
Adriana Kobylak | 400fd1f | 2021-01-29 09:01:30 -0600 | [diff] [blame] | 1920 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1921 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1922 | app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1923 | .privileges(redfish::privileges::deleteLogEntry) |
| 1924 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1925 | .methods(boost::beast::http::verb::delete_)( |
| 1926 | [&app](const crow::Request& req, |
| 1927 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1928 | const std::string& systemName, const std::string& param) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1929 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1930 | { |
| 1931 | return; |
| 1932 | } |
| 1933 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1934 | { |
| 1935 | // Option currently returns no systems. TBD |
| 1936 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1937 | systemName); |
| 1938 | return; |
| 1939 | } |
| 1940 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1941 | { |
| 1942 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1943 | systemName); |
| 1944 | return; |
| 1945 | } |
| 1946 | dBusEventLogEntryDelete(asyncResp, param); |
| 1947 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 1950 | constexpr const char* hostLoggerFolderPath = "/var/log/console"; |
| 1951 | |
| 1952 | inline bool |
| 1953 | getHostLoggerFiles(const std::string& hostLoggerFilePath, |
| 1954 | std::vector<std::filesystem::path>& hostLoggerFiles) |
| 1955 | { |
| 1956 | std::error_code ec; |
| 1957 | std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); |
| 1958 | if (ec) |
| 1959 | { |
Carson Labrado | bf2dded | 2023-08-10 00:37:06 +0000 | [diff] [blame] | 1960 | BMCWEB_LOG_WARNING("{}", ec.message()); |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 1961 | return false; |
| 1962 | } |
| 1963 | for (const std::filesystem::directory_entry& it : logPath) |
| 1964 | { |
| 1965 | std::string filename = it.path().filename(); |
| 1966 | // Prefix of each log files is "log". Find the file and save the |
| 1967 | // path |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 1968 | if (filename.starts_with("log")) |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 1969 | { |
| 1970 | hostLoggerFiles.emplace_back(it.path()); |
| 1971 | } |
| 1972 | } |
| 1973 | // As the log files rotate, they are appended with a ".#" that is higher for |
| 1974 | // the older logs. Since we start from oldest logs, sort the name in |
| 1975 | // descending order. |
| 1976 | std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), |
| 1977 | AlphanumLess<std::string>()); |
| 1978 | |
| 1979 | return true; |
| 1980 | } |
| 1981 | |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 1982 | inline bool getHostLoggerEntries( |
| 1983 | const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip, |
| 1984 | uint64_t top, std::vector<std::string>& logEntries, size_t& logCount) |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 1985 | { |
| 1986 | GzFileReader logFile; |
| 1987 | |
| 1988 | // Go though all log files and expose host logs. |
| 1989 | for (const std::filesystem::path& it : hostLoggerFiles) |
| 1990 | { |
| 1991 | if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) |
| 1992 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1993 | BMCWEB_LOG_ERROR("fail to expose host logs"); |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 1994 | return false; |
| 1995 | } |
| 1996 | } |
| 1997 | // Get lastMessage from constructor by getter |
| 1998 | std::string lastMessage = logFile.getLastMessage(); |
| 1999 | if (!lastMessage.empty()) |
| 2000 | { |
| 2001 | logCount++; |
| 2002 | if (logCount > skip && logCount <= (skip + top)) |
| 2003 | { |
| 2004 | logEntries.push_back(lastMessage); |
| 2005 | } |
| 2006 | } |
| 2007 | return true; |
| 2008 | } |
| 2009 | |
Ed Tanous | 6f056f2 | 2024-04-07 13:35:51 -0700 | [diff] [blame] | 2010 | inline void fillHostLoggerEntryJson(std::string_view logEntryID, |
| 2011 | std::string_view msg, |
Jason M. Bills | 6d6574c | 2022-06-28 12:30:16 -0700 | [diff] [blame] | 2012 | nlohmann::json::object_t& logEntryJson) |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2013 | { |
| 2014 | // Fill in the log entry with the gathered data. |
Vijay Lobo | 9c11a17 | 2021-10-07 16:53:16 -0500 | [diff] [blame] | 2015 | logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 2016 | logEntryJson["@odata.id"] = boost::urls::format( |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2017 | "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries/{}", |
| 2018 | BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID); |
Jason M. Bills | 6d6574c | 2022-06-28 12:30:16 -0700 | [diff] [blame] | 2019 | logEntryJson["Name"] = "Host Logger Entry"; |
| 2020 | logEntryJson["Id"] = logEntryID; |
| 2021 | logEntryJson["Message"] = msg; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2022 | logEntryJson["EntryType"] = log_entry::LogEntryType::Oem; |
| 2023 | logEntryJson["Severity"] = log_entry::EventSeverity::OK; |
Jason M. Bills | 6d6574c | 2022-06-28 12:30:16 -0700 | [diff] [blame] | 2024 | logEntryJson["OemRecordFormat"] = "Host Logger Entry"; |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | inline void requestRoutesSystemHostLogger(App& app) |
| 2028 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2029 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/") |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2030 | .privileges(redfish::privileges::getLogService) |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 2031 | .methods(boost::beast::http::verb::get)( |
| 2032 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2033 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2034 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2035 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2036 | { |
| 2037 | return; |
| 2038 | } |
| 2039 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2040 | { |
| 2041 | // Option currently returns no systems. TBD |
| 2042 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2043 | systemName); |
| 2044 | return; |
| 2045 | } |
| 2046 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2047 | { |
| 2048 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2049 | systemName); |
| 2050 | return; |
| 2051 | } |
| 2052 | asyncResp->res.jsonValue["@odata.id"] = |
| 2053 | std::format("/redfish/v1/Systems/{}/LogServices/HostLogger", |
| 2054 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2055 | asyncResp->res.jsonValue["@odata.type"] = |
| 2056 | "#LogService.v1_2_0.LogService"; |
| 2057 | asyncResp->res.jsonValue["Name"] = "Host Logger Service"; |
| 2058 | asyncResp->res.jsonValue["Description"] = "Host Logger Service"; |
| 2059 | asyncResp->res.jsonValue["Id"] = "HostLogger"; |
| 2060 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format( |
| 2061 | "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries", |
| 2062 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2063 | }); |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | inline void requestRoutesSystemHostLoggerCollection(App& app) |
| 2067 | { |
| 2068 | BMCWEB_ROUTE(app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2069 | "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/") |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2070 | .privileges(redfish::privileges::getLogEntry) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2071 | .methods( |
| 2072 | boost::beast::http::verb:: |
| 2073 | get)([&app](const crow::Request& req, |
| 2074 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2075 | const std::string& systemName) { |
| 2076 | query_param::QueryCapabilities capabilities = { |
| 2077 | .canDelegateTop = true, |
| 2078 | .canDelegateSkip = true, |
| 2079 | }; |
| 2080 | query_param::Query delegatedQuery; |
| 2081 | if (!redfish::setUpRedfishRouteWithDelegation( |
| 2082 | app, req, asyncResp, delegatedQuery, capabilities)) |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2083 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2084 | return; |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2085 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2086 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2087 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2088 | // Option currently returns no systems. TBD |
| 2089 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2090 | systemName); |
| 2091 | return; |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2092 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2093 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2094 | { |
| 2095 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2096 | systemName); |
| 2097 | return; |
| 2098 | } |
| 2099 | asyncResp->res.jsonValue["@odata.id"] = std::format( |
| 2100 | "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries", |
| 2101 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2102 | asyncResp->res.jsonValue["@odata.type"] = |
| 2103 | "#LogEntryCollection.LogEntryCollection"; |
| 2104 | asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; |
| 2105 | asyncResp->res.jsonValue["Description"] = |
| 2106 | "Collection of HostLogger Entries"; |
| 2107 | nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; |
| 2108 | logEntryArray = nlohmann::json::array(); |
| 2109 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
| 2110 | |
| 2111 | std::vector<std::filesystem::path> hostLoggerFiles; |
| 2112 | if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) |
| 2113 | { |
| 2114 | BMCWEB_LOG_DEBUG("Failed to get host log file path"); |
| 2115 | return; |
| 2116 | } |
| 2117 | // If we weren't provided top and skip limits, use the defaults. |
| 2118 | size_t skip = delegatedQuery.skip.value_or(0); |
| 2119 | size_t top = |
| 2120 | delegatedQuery.top.value_or(query_param::Query::maxTop); |
| 2121 | size_t logCount = 0; |
| 2122 | // This vector only store the entries we want to expose that |
| 2123 | // control by skip and top. |
| 2124 | std::vector<std::string> logEntries; |
| 2125 | if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries, |
| 2126 | logCount)) |
| 2127 | { |
| 2128 | messages::internalError(asyncResp->res); |
| 2129 | return; |
| 2130 | } |
| 2131 | // If vector is empty, that means skip value larger than total |
| 2132 | // log count |
| 2133 | if (logEntries.empty()) |
| 2134 | { |
| 2135 | asyncResp->res.jsonValue["Members@odata.count"] = logCount; |
| 2136 | return; |
| 2137 | } |
| 2138 | if (!logEntries.empty()) |
| 2139 | { |
| 2140 | for (size_t i = 0; i < logEntries.size(); i++) |
| 2141 | { |
| 2142 | nlohmann::json::object_t hostLogEntry; |
| 2143 | fillHostLoggerEntryJson(std::to_string(skip + i), |
| 2144 | logEntries[i], hostLogEntry); |
| 2145 | logEntryArray.emplace_back(std::move(hostLogEntry)); |
| 2146 | } |
| 2147 | |
| 2148 | asyncResp->res.jsonValue["Members@odata.count"] = logCount; |
| 2149 | if (skip + top < logCount) |
| 2150 | { |
| 2151 | asyncResp->res.jsonValue["Members@odata.nextLink"] = |
| 2152 | std::format( |
| 2153 | "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries?$skip=", |
| 2154 | BMCWEB_REDFISH_SYSTEM_URI_NAME) + |
| 2155 | std::to_string(skip + top); |
| 2156 | } |
| 2157 | } |
| 2158 | }); |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | inline void requestRoutesSystemHostLoggerLogEntry(App& app) |
| 2162 | { |
| 2163 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2164 | app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/") |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2165 | .privileges(redfish::privileges::getLogEntry) |
| 2166 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2167 | [&app](const crow::Request& req, |
| 2168 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2169 | const std::string& systemName, const std::string& param) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2170 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2171 | { |
| 2172 | return; |
| 2173 | } |
| 2174 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2175 | { |
| 2176 | // Option currently returns no systems. TBD |
| 2177 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2178 | systemName); |
| 2179 | return; |
| 2180 | } |
| 2181 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2182 | { |
| 2183 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2184 | systemName); |
| 2185 | return; |
| 2186 | } |
| 2187 | std::string_view targetID = param; |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2188 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2189 | uint64_t idInt = 0; |
Ed Tanous | ca45aa3 | 2022-01-07 09:28:45 -0800 | [diff] [blame] | 2190 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2191 | auto [ptr, ec] = |
| 2192 | std::from_chars(targetID.begin(), targetID.end(), idInt); |
| 2193 | if (ec != std::errc{} || ptr != targetID.end()) |
| 2194 | { |
| 2195 | messages::resourceNotFound(asyncResp->res, "LogEntry", |
| 2196 | param); |
| 2197 | return; |
| 2198 | } |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2199 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2200 | std::vector<std::filesystem::path> hostLoggerFiles; |
| 2201 | if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) |
| 2202 | { |
| 2203 | BMCWEB_LOG_DEBUG("Failed to get host log file path"); |
| 2204 | return; |
| 2205 | } |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2206 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2207 | size_t logCount = 0; |
| 2208 | size_t top = 1; |
| 2209 | std::vector<std::string> logEntries; |
| 2210 | // We can get specific entry by skip and top. For example, if we |
| 2211 | // want to get nth entry, we can set skip = n-1 and top = 1 to |
| 2212 | // get that entry |
| 2213 | if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, |
| 2214 | logEntries, logCount)) |
| 2215 | { |
| 2216 | messages::internalError(asyncResp->res); |
| 2217 | return; |
| 2218 | } |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2219 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2220 | if (!logEntries.empty()) |
| 2221 | { |
| 2222 | nlohmann::json::object_t hostLogEntry; |
| 2223 | fillHostLoggerEntryJson(targetID, logEntries[0], |
| 2224 | hostLogEntry); |
| 2225 | asyncResp->res.jsonValue.update(hostLogEntry); |
| 2226 | return; |
| 2227 | } |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2228 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2229 | // Requested ID was not found |
| 2230 | messages::resourceNotFound(asyncResp->res, "LogEntry", param); |
| 2231 | }); |
Spencer Ku | b7028eb | 2021-10-26 15:27:35 +0800 | [diff] [blame] | 2232 | } |
| 2233 | |
Claire Weinan | dd72e87 | 2022-08-15 14:20:06 -0700 | [diff] [blame] | 2234 | inline void handleBMCLogServicesCollectionGet( |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2235 | crow::App& app, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2236 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2237 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2238 | { |
| 2239 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2240 | { |
| 2241 | return; |
| 2242 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2243 | |
| 2244 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2245 | { |
| 2246 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2247 | return; |
| 2248 | } |
| 2249 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2250 | // Collections don't include the static data added by SubRoute |
| 2251 | // because it has a duplicate entry for members |
| 2252 | asyncResp->res.jsonValue["@odata.type"] = |
| 2253 | "#LogServiceCollection.LogServiceCollection"; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2254 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 2255 | "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2256 | asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; |
| 2257 | asyncResp->res.jsonValue["Description"] = |
| 2258 | "Collection of LogServices for this Manager"; |
| 2259 | nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; |
| 2260 | logServiceArray = nlohmann::json::array(); |
| 2261 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2262 | if constexpr (BMCWEB_REDFISH_BMC_JOURNAL) |
| 2263 | { |
| 2264 | nlohmann::json::object_t journal; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2265 | journal["@odata.id"] = |
| 2266 | boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal", |
| 2267 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2268 | logServiceArray.emplace_back(std::move(journal)); |
| 2269 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2270 | |
| 2271 | asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); |
| 2272 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2273 | if constexpr (BMCWEB_REDFISH_DUMP_LOG) |
| 2274 | { |
| 2275 | constexpr std::array<std::string_view, 1> interfaces = { |
| 2276 | "xyz.openbmc_project.Collection.DeleteAll"}; |
| 2277 | dbus::utility::getSubTreePaths( |
| 2278 | "/xyz/openbmc_project/dump", 0, interfaces, |
| 2279 | [asyncResp](const boost::system::error_code& ec, |
| 2280 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 2281 | subTreePaths) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2282 | if (ec) |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2283 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2284 | BMCWEB_LOG_ERROR( |
| 2285 | "handleBMCLogServicesCollectionGet respHandler got error {}", |
| 2286 | ec); |
| 2287 | // Assume that getting an error simply means there are no |
| 2288 | // dump LogServices. Return without adding any error |
| 2289 | // response. |
| 2290 | return; |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2291 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2292 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2293 | nlohmann::json& logServiceArrayLocal = |
| 2294 | asyncResp->res.jsonValue["Members"]; |
| 2295 | |
| 2296 | for (const std::string& path : subTreePaths) |
| 2297 | { |
| 2298 | if (path == "/xyz/openbmc_project/dump/bmc") |
| 2299 | { |
| 2300 | nlohmann::json::object_t member; |
| 2301 | member["@odata.id"] = boost::urls::format( |
| 2302 | "/redfish/v1/Managers/{}/LogServices/Dump", |
| 2303 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2304 | logServiceArrayLocal.emplace_back(std::move(member)); |
| 2305 | } |
| 2306 | else if (path == "/xyz/openbmc_project/dump/faultlog") |
| 2307 | { |
| 2308 | nlohmann::json::object_t member; |
| 2309 | member["@odata.id"] = boost::urls::format( |
| 2310 | "/redfish/v1/Managers/{}/LogServices/FaultLog", |
| 2311 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2312 | logServiceArrayLocal.emplace_back(std::move(member)); |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 2317 | logServiceArrayLocal.size(); |
| 2318 | }); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2319 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2320 | } |
| 2321 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2322 | inline void requestRoutesBMCLogServiceCollection(App& app) |
| 2323 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2324 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/") |
Gunnar Mills | ad89dcf | 2021-07-30 14:40:11 -0500 | [diff] [blame] | 2325 | .privileges(redfish::privileges::getLogServiceCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2326 | .methods(boost::beast::http::verb::get)( |
Claire Weinan | dd72e87 | 2022-08-15 14:20:06 -0700 | [diff] [blame] | 2327 | std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2328 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 2329 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2330 | inline void |
| 2331 | getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2332 | const std::string& dumpType) |
| 2333 | { |
| 2334 | std::string dumpPath; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2335 | log_service::OverWritePolicy overWritePolicy = |
| 2336 | log_service::OverWritePolicy::Invalid; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2337 | bool collectDiagnosticDataSupported = false; |
| 2338 | |
| 2339 | if (dumpType == "BMC") |
| 2340 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2341 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump", |
| 2342 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2343 | overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2344 | collectDiagnosticDataSupported = true; |
| 2345 | } |
| 2346 | else if (dumpType == "FaultLog") |
| 2347 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2348 | dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog", |
| 2349 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2350 | overWritePolicy = log_service::OverWritePolicy::Unknown; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2351 | collectDiagnosticDataSupported = false; |
| 2352 | } |
| 2353 | else if (dumpType == "System") |
| 2354 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2355 | dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump", |
| 2356 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2357 | overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2358 | collectDiagnosticDataSupported = true; |
| 2359 | } |
| 2360 | else |
| 2361 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2362 | BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}", |
| 2363 | dumpType); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2364 | messages::internalError(asyncResp->res); |
| 2365 | return; |
| 2366 | } |
| 2367 | |
| 2368 | asyncResp->res.jsonValue["@odata.id"] = dumpPath; |
| 2369 | asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; |
| 2370 | asyncResp->res.jsonValue["Name"] = "Dump LogService"; |
| 2371 | asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; |
| 2372 | asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2373 | asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2374 | |
| 2375 | std::pair<std::string, std::string> redfishDateTimeOffset = |
Ed Tanous | 2b82937 | 2022-08-03 14:22:34 -0700 | [diff] [blame] | 2376 | redfish::time_utils::getDateTimeOffsetNow(); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2377 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 2378 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 2379 | redfishDateTimeOffset.second; |
| 2380 | |
| 2381 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2382 | |
| 2383 | if (collectDiagnosticDataSupported) |
| 2384 | { |
| 2385 | asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] |
| 2386 | ["target"] = |
| 2387 | dumpPath + "/Actions/LogService.CollectDiagnosticData"; |
| 2388 | } |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 2389 | |
| 2390 | constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface}; |
| 2391 | dbus::utility::getSubTreePaths( |
| 2392 | "/xyz/openbmc_project/dump", 0, interfaces, |
| 2393 | [asyncResp, dumpType, dumpPath]( |
| 2394 | const boost::system::error_code& ec, |
| 2395 | const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2396 | if (ec) |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 2397 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2398 | BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", |
| 2399 | ec); |
| 2400 | // Assume that getting an error simply means there are no dump |
| 2401 | // LogServices. Return without adding any error response. |
| 2402 | return; |
Claire Weinan | 0d94621 | 2022-07-13 19:40:19 -0700 | [diff] [blame] | 2403 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2404 | std::string dbusDumpPath = getDumpPath(dumpType); |
| 2405 | for (const std::string& path : subTreePaths) |
| 2406 | { |
| 2407 | if (path == dbusDumpPath) |
| 2408 | { |
| 2409 | asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] |
| 2410 | ["target"] = |
| 2411 | dumpPath + "/Actions/LogService.ClearLog"; |
| 2412 | break; |
| 2413 | } |
| 2414 | } |
| 2415 | }); |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | inline void handleLogServicesDumpServiceGet( |
| 2419 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2420 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2421 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2422 | { |
| 2423 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2424 | { |
| 2425 | return; |
| 2426 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2427 | |
| 2428 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2429 | { |
| 2430 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2431 | return; |
| 2432 | } |
| 2433 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2434 | getDumpServiceInfo(asyncResp, dumpType); |
| 2435 | } |
| 2436 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2437 | inline void handleLogServicesDumpServiceComputerSystemGet( |
| 2438 | crow::App& app, const crow::Request& req, |
| 2439 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2440 | const std::string& chassisId) |
| 2441 | { |
| 2442 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2443 | { |
| 2444 | return; |
| 2445 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2446 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2447 | { |
| 2448 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 2449 | return; |
| 2450 | } |
| 2451 | getDumpServiceInfo(asyncResp, "System"); |
| 2452 | } |
| 2453 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2454 | inline void handleLogServicesDumpEntriesCollectionGet( |
| 2455 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2456 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2457 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2458 | { |
| 2459 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2460 | { |
| 2461 | return; |
| 2462 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2463 | |
| 2464 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2465 | { |
| 2466 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2467 | return; |
| 2468 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2469 | getDumpEntryCollection(asyncResp, dumpType); |
| 2470 | } |
| 2471 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2472 | inline void handleLogServicesDumpEntriesCollectionComputerSystemGet( |
| 2473 | crow::App& app, const crow::Request& req, |
| 2474 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2475 | const std::string& chassisId) |
| 2476 | { |
| 2477 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2478 | { |
| 2479 | return; |
| 2480 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2481 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2482 | { |
| 2483 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 2484 | return; |
| 2485 | } |
| 2486 | getDumpEntryCollection(asyncResp, "System"); |
| 2487 | } |
| 2488 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2489 | inline void handleLogServicesDumpEntryGet( |
| 2490 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 2491 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2492 | const std::string& managerId, const std::string& dumpId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2493 | { |
| 2494 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2495 | { |
| 2496 | return; |
| 2497 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2498 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2499 | { |
| 2500 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2501 | return; |
| 2502 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2503 | getDumpEntryById(asyncResp, dumpId, dumpType); |
| 2504 | } |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2505 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2506 | inline void handleLogServicesDumpEntryComputerSystemGet( |
| 2507 | crow::App& app, const crow::Request& req, |
| 2508 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2509 | const std::string& chassisId, const std::string& dumpId) |
| 2510 | { |
| 2511 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2512 | { |
| 2513 | return; |
| 2514 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2515 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2516 | { |
| 2517 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 2518 | return; |
| 2519 | } |
| 2520 | getDumpEntryById(asyncResp, dumpId, "System"); |
| 2521 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2522 | |
| 2523 | inline void handleLogServicesDumpEntryDelete( |
| 2524 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 2525 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2526 | const std::string& managerId, const std::string& dumpId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2527 | { |
| 2528 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2529 | { |
| 2530 | return; |
| 2531 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2532 | |
| 2533 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2534 | { |
| 2535 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2536 | return; |
| 2537 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2538 | deleteDumpEntry(asyncResp, dumpId, dumpType); |
| 2539 | } |
| 2540 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2541 | inline void handleLogServicesDumpEntryComputerSystemDelete( |
| 2542 | crow::App& app, const crow::Request& req, |
| 2543 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2544 | const std::string& chassisId, const std::string& dumpId) |
| 2545 | { |
| 2546 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2547 | { |
| 2548 | return; |
| 2549 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2550 | if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2551 | { |
| 2552 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); |
| 2553 | return; |
| 2554 | } |
| 2555 | deleteDumpEntry(asyncResp, dumpId, "System"); |
| 2556 | } |
| 2557 | |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2558 | inline void handleLogServicesDumpEntryDownloadGet( |
| 2559 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 2560 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2561 | const std::string& managerId, const std::string& dumpId) |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2562 | { |
| 2563 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2564 | { |
| 2565 | return; |
| 2566 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2567 | |
| 2568 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2569 | { |
| 2570 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2571 | return; |
| 2572 | } |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2573 | downloadDumpEntry(asyncResp, dumpId, dumpType); |
| 2574 | } |
| 2575 | |
| 2576 | inline void handleDBusEventLogEntryDownloadGet( |
| 2577 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
| 2578 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2579 | const std::string& systemName, const std::string& entryID) |
| 2580 | { |
| 2581 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2582 | { |
| 2583 | return; |
| 2584 | } |
| 2585 | if (!http_helpers::isContentTypeAllowed( |
| 2586 | req.getHeaderValue("Accept"), |
| 2587 | http_helpers::ContentType::OctetStream, true)) |
| 2588 | { |
| 2589 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 2590 | return; |
| 2591 | } |
| 2592 | downloadEventLogEntry(asyncResp, systemName, entryID, dumpType); |
| 2593 | } |
| 2594 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2595 | inline void handleLogServicesDumpCollectDiagnosticDataPost( |
| 2596 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2597 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2598 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2599 | { |
| 2600 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2601 | { |
| 2602 | return; |
| 2603 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2604 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2605 | { |
| 2606 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2607 | return; |
| 2608 | } |
| 2609 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2610 | createDump(asyncResp, req, dumpType); |
| 2611 | } |
| 2612 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2613 | inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost( |
| 2614 | crow::App& app, const crow::Request& req, |
| 2615 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2616 | const std::string& systemName) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2617 | { |
| 2618 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2619 | { |
| 2620 | return; |
| 2621 | } |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2622 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2623 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2624 | { |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2625 | // Option currently returns no systems. TBD |
| 2626 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2627 | systemName); |
| 2628 | return; |
| 2629 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2630 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2631 | { |
| 2632 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2633 | systemName); |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2634 | return; |
| 2635 | } |
| 2636 | createDump(asyncResp, req, "System"); |
| 2637 | } |
| 2638 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2639 | inline void handleLogServicesDumpClearLogPost( |
| 2640 | crow::App& app, const std::string& dumpType, const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2641 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2642 | const std::string& managerId) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2643 | { |
| 2644 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2645 | { |
| 2646 | return; |
| 2647 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2648 | |
| 2649 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2650 | { |
| 2651 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 2652 | return; |
| 2653 | } |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2654 | clearDump(asyncResp, dumpType); |
| 2655 | } |
| 2656 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2657 | inline void handleLogServicesDumpClearLogComputerSystemPost( |
| 2658 | crow::App& app, const crow::Request& req, |
| 2659 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2660 | const std::string& systemName) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2661 | { |
| 2662 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2663 | { |
| 2664 | return; |
| 2665 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2666 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2667 | { |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2668 | // Option currently returns no systems. TBD |
| 2669 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2670 | systemName); |
| 2671 | return; |
| 2672 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2673 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 2674 | { |
| 2675 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2676 | systemName); |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2677 | return; |
| 2678 | } |
| 2679 | clearDump(asyncResp, "System"); |
| 2680 | } |
| 2681 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2682 | inline void requestRoutesBMCDumpService(App& app) |
| 2683 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2684 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2685 | .privileges(redfish::privileges::getLogService) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2686 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2687 | handleLogServicesDumpServiceGet, std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | inline void requestRoutesBMCDumpEntryCollection(App& app) |
| 2691 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2692 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2693 | .privileges(redfish::privileges::getLogEntryCollection) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2694 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2695 | handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | inline void requestRoutesBMCDumpEntry(App& app) |
| 2699 | { |
| 2700 | BMCWEB_ROUTE(app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2701 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2702 | .privileges(redfish::privileges::getLogEntry) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2703 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2704 | handleLogServicesDumpEntryGet, std::ref(app), "BMC")); |
| 2705 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2706 | BMCWEB_ROUTE(app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2707 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2708 | .privileges(redfish::privileges::deleteLogEntry) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2709 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
| 2710 | handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2711 | } |
| 2712 | |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2713 | inline void requestRoutesBMCDumpEntryDownload(App& app) |
| 2714 | { |
| 2715 | BMCWEB_ROUTE( |
| 2716 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2717 | "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/") |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2718 | .privileges(redfish::privileges::getLogEntry) |
| 2719 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2720 | handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC")); |
| 2721 | } |
| 2722 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2723 | inline void requestRoutesBMCDumpCreate(App& app) |
| 2724 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2725 | BMCWEB_ROUTE( |
| 2726 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2727 | "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2728 | .privileges(redfish::privileges::postLogService) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2729 | .methods(boost::beast::http::verb::post)( |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2730 | std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, |
| 2731 | std::ref(app), "BMC")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | inline void requestRoutesBMCDumpClear(App& app) |
| 2735 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2736 | BMCWEB_ROUTE( |
| 2737 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2738 | "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2739 | .privileges(redfish::privileges::postLogService) |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2740 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 2741 | handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); |
| 2742 | } |
| 2743 | |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2744 | inline void requestRoutesDBusEventLogEntryDownload(App& app) |
| 2745 | { |
| 2746 | BMCWEB_ROUTE( |
| 2747 | app, |
Ravi Teja | 9e9d99d | 2023-11-08 05:33:59 -0600 | [diff] [blame] | 2748 | "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/") |
Carson Labrado | 168d1b1 | 2023-03-27 17:04:46 +0000 | [diff] [blame] | 2749 | .privileges(redfish::privileges::getLogEntry) |
| 2750 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2751 | handleDBusEventLogEntryDownloadGet, std::ref(app), "System")); |
| 2752 | } |
| 2753 | |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2754 | inline void requestRoutesFaultLogDumpService(App& app) |
| 2755 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2756 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2757 | .privileges(redfish::privileges::getLogService) |
| 2758 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2759 | handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); |
| 2760 | } |
| 2761 | |
| 2762 | inline void requestRoutesFaultLogDumpEntryCollection(App& app) |
| 2763 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2764 | BMCWEB_ROUTE(app, |
| 2765 | "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2766 | .privileges(redfish::privileges::getLogEntryCollection) |
| 2767 | .methods(boost::beast::http::verb::get)( |
| 2768 | std::bind_front(handleLogServicesDumpEntriesCollectionGet, |
| 2769 | std::ref(app), "FaultLog")); |
| 2770 | } |
| 2771 | |
| 2772 | inline void requestRoutesFaultLogDumpEntry(App& app) |
| 2773 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2774 | BMCWEB_ROUTE( |
| 2775 | app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2776 | .privileges(redfish::privileges::getLogEntry) |
| 2777 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2778 | handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); |
| 2779 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2780 | BMCWEB_ROUTE( |
| 2781 | app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2782 | .privileges(redfish::privileges::deleteLogEntry) |
| 2783 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
| 2784 | handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); |
| 2785 | } |
| 2786 | |
| 2787 | inline void requestRoutesFaultLogDumpClear(App& app) |
| 2788 | { |
| 2789 | BMCWEB_ROUTE( |
| 2790 | app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2791 | "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/") |
Claire Weinan | fdd2690 | 2022-03-01 14:18:25 -0800 | [diff] [blame] | 2792 | .privileges(redfish::privileges::postLogService) |
| 2793 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 2794 | handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | inline void requestRoutesSystemDumpService(App& app) |
| 2798 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2799 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2800 | .privileges(redfish::privileges::getLogService) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2801 | .methods(boost::beast::http::verb::get)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2802 | handleLogServicesDumpServiceComputerSystemGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | inline void requestRoutesSystemDumpEntryCollection(App& app) |
| 2806 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2807 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2808 | .privileges(redfish::privileges::getLogEntryCollection) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2809 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2810 | handleLogServicesDumpEntriesCollectionComputerSystemGet, |
| 2811 | std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | inline void requestRoutesSystemDumpEntry(App& app) |
| 2815 | { |
| 2816 | BMCWEB_ROUTE(app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2817 | "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2818 | .privileges(redfish::privileges::getLogEntry) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2819 | .methods(boost::beast::http::verb::get)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2820 | handleLogServicesDumpEntryComputerSystemGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2821 | |
| 2822 | BMCWEB_ROUTE(app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2823 | "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2824 | .privileges(redfish::privileges::deleteLogEntry) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2825 | .methods(boost::beast::http::verb::delete_)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2826 | handleLogServicesDumpEntryComputerSystemDelete, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | inline void requestRoutesSystemDumpCreate(App& app) |
| 2830 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2831 | BMCWEB_ROUTE( |
| 2832 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2833 | "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2834 | .privileges(redfish::privileges::postLogService) |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2835 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 2836 | handleLogServicesDumpCollectDiagnosticDataComputerSystemPost, |
| 2837 | std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | inline void requestRoutesSystemDumpClear(App& app) |
| 2841 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2842 | BMCWEB_ROUTE( |
| 2843 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2844 | "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2845 | .privileges(redfish::privileges::postLogService) |
Claire Weinan | 6ab9ad5 | 2022-08-12 18:20:17 -0700 | [diff] [blame] | 2846 | .methods(boost::beast::http::verb::post)(std::bind_front( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2847 | handleLogServicesDumpClearLogComputerSystemPost, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | inline void requestRoutesCrashdumpService(App& app) |
| 2851 | { |
| 2852 | // Note: Deviated from redfish privilege registry for GET & HEAD |
| 2853 | // method for security reasons. |
| 2854 | /** |
| 2855 | * Functions triggers appropriate requests on DBus |
| 2856 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2857 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2858 | // This is incorrect, should be: |
| 2859 | //.privileges(redfish::privileges::getLogService) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 2860 | .privileges({{"ConfigureManager"}}) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2861 | .methods( |
| 2862 | boost::beast::http::verb:: |
| 2863 | get)([&app](const crow::Request& req, |
| 2864 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2865 | const std::string& systemName) { |
| 2866 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2867 | { |
| 2868 | return; |
| 2869 | } |
| 2870 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2871 | { |
| 2872 | // Option currently returns no systems. TBD |
| 2873 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2874 | systemName); |
| 2875 | return; |
| 2876 | } |
| 2877 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2878 | { |
| 2879 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2880 | systemName); |
| 2881 | return; |
| 2882 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2883 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2884 | // Copy over the static data to include the entries added by |
| 2885 | // SubRoute |
| 2886 | asyncResp->res.jsonValue["@odata.id"] = |
| 2887 | std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", |
| 2888 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2889 | asyncResp->res.jsonValue["@odata.type"] = |
| 2890 | "#LogService.v1_2_0.LogService"; |
| 2891 | asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; |
| 2892 | asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; |
| 2893 | asyncResp->res.jsonValue["Id"] = "Crashdump"; |
| 2894 | asyncResp->res.jsonValue["OverWritePolicy"] = |
| 2895 | log_service::OverWritePolicy::WrapsWhenFull; |
| 2896 | asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 2897 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2898 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| 2899 | redfish::time_utils::getDateTimeOffsetNow(); |
| 2900 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 2901 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 2902 | redfishDateTimeOffset.second; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 2903 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2904 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format( |
| 2905 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", |
| 2906 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2907 | asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] |
| 2908 | ["target"] = std::format( |
| 2909 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog", |
| 2910 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2911 | asyncResp->res |
| 2912 | .jsonValue["Actions"]["#LogService.CollectDiagnosticData"] |
| 2913 | ["target"] = std::format( |
| 2914 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData", |
| 2915 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2916 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | void inline requestRoutesCrashdumpClear(App& app) |
| 2920 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2921 | BMCWEB_ROUTE( |
| 2922 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2923 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2924 | // This is incorrect, should be: |
| 2925 | //.privileges(redfish::privileges::postLogService) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 2926 | .privileges({{"ConfigureComponents"}}) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2927 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2928 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 2929 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2930 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2931 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2932 | { |
| 2933 | return; |
| 2934 | } |
| 2935 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2936 | { |
| 2937 | // Option currently returns no systems. TBD |
| 2938 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2939 | systemName); |
| 2940 | return; |
| 2941 | } |
| 2942 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 2943 | { |
| 2944 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2945 | systemName); |
| 2946 | return; |
| 2947 | } |
| 2948 | crow::connections::systemBus->async_method_call( |
| 2949 | [asyncResp](const boost::system::error_code& ec, |
| 2950 | const std::string&) { |
| 2951 | if (ec) |
| 2952 | { |
| 2953 | messages::internalError(asyncResp->res); |
| 2954 | return; |
| 2955 | } |
| 2956 | messages::success(asyncResp->res); |
| 2957 | }, |
| 2958 | crashdumpObject, crashdumpPath, deleteAllInterface, |
| 2959 | "DeleteAll"); |
| 2960 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2961 | } |
Jason M. Bills | 5b61b5e | 2019-10-16 10:59:02 -0700 | [diff] [blame] | 2962 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2963 | static void |
| 2964 | logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2965 | const std::string& logID, nlohmann::json& logEntryJson) |
Jason M. Bills | e855dd2 | 2019-10-08 11:37:48 -0700 | [diff] [blame] | 2966 | { |
Johnathan Mantey | 043a053 | 2020-03-10 17:15:28 -0700 | [diff] [blame] | 2967 | auto getStoredLogCallback = |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 2968 | [asyncResp, logID, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 2969 | &logEntryJson](const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 2970 | const dbus::utility::DBusPropertiesMap& params) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2971 | if (ec) |
| 2972 | { |
| 2973 | BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message()); |
| 2974 | if (ec.value() == |
| 2975 | boost::system::linux_error::bad_request_descriptor) |
| 2976 | { |
| 2977 | messages::resourceNotFound(asyncResp->res, "LogEntry", |
| 2978 | logID); |
| 2979 | } |
| 2980 | else |
| 2981 | { |
| 2982 | messages::internalError(asyncResp->res); |
| 2983 | } |
| 2984 | return; |
| 2985 | } |
| 2986 | |
| 2987 | std::string timestamp{}; |
| 2988 | std::string filename{}; |
| 2989 | std::string logfile{}; |
| 2990 | parseCrashdumpParameters(params, filename, timestamp, logfile); |
| 2991 | |
| 2992 | if (filename.empty() || timestamp.empty()) |
Jason M. Bills | 1ddcf01 | 2019-11-26 14:59:21 -0800 | [diff] [blame] | 2993 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2994 | messages::resourceNotFound(asyncResp->res, "LogEntry", logID); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2995 | return; |
| 2996 | } |
| 2997 | |
| 2998 | std::string crashdumpURI = |
| 2999 | std::format( |
| 3000 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/", |
| 3001 | BMCWEB_REDFISH_SYSTEM_URI_NAME) + |
| 3002 | logID + "/" + filename; |
| 3003 | nlohmann::json::object_t logEntry; |
| 3004 | logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
| 3005 | logEntry["@odata.id"] = boost::urls::format( |
| 3006 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}", |
| 3007 | BMCWEB_REDFISH_SYSTEM_URI_NAME, logID); |
| 3008 | logEntry["Name"] = "CPU Crashdump"; |
| 3009 | logEntry["Id"] = logID; |
| 3010 | logEntry["EntryType"] = log_entry::LogEntryType::Oem; |
| 3011 | logEntry["AdditionalDataURI"] = std::move(crashdumpURI); |
| 3012 | logEntry["DiagnosticDataType"] = "OEM"; |
| 3013 | logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; |
| 3014 | logEntry["Created"] = std::move(timestamp); |
| 3015 | |
| 3016 | // If logEntryJson references an array of LogEntry resources |
| 3017 | // ('Members' list), then push this as a new entry, otherwise set it |
| 3018 | // directly |
| 3019 | if (logEntryJson.is_array()) |
| 3020 | { |
| 3021 | logEntryJson.push_back(logEntry); |
| 3022 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 3023 | logEntryJson.size(); |
Jason M. Bills | 2b20ef6 | 2022-01-06 15:48:07 -0800 | [diff] [blame] | 3024 | } |
| 3025 | else |
| 3026 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3027 | logEntryJson.update(logEntry); |
Jason M. Bills | 2b20ef6 | 2022-01-06 15:48:07 -0800 | [diff] [blame] | 3028 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3029 | }; |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 3030 | sdbusplus::asio::getAllProperties( |
| 3031 | *crow::connections::systemBus, crashdumpObject, |
| 3032 | crashdumpPath + std::string("/") + logID, crashdumpInterface, |
| 3033 | std::move(getStoredLogCallback)); |
Jason M. Bills | e855dd2 | 2019-10-08 11:37:48 -0700 | [diff] [blame] | 3034 | } |
| 3035 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3036 | inline void requestRoutesCrashdumpEntryCollection(App& app) |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 3037 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3038 | // Note: Deviated from redfish privilege registry for GET & HEAD |
| 3039 | // method for security reasons. |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 3040 | /** |
| 3041 | * Functions triggers appropriate requests on DBus |
| 3042 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3043 | BMCWEB_ROUTE(app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3044 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 3045 | // This is incorrect, should be. |
| 3046 | //.privileges(redfish::privileges::postLogEntryCollection) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 3047 | .privileges({{"ConfigureComponents"}}) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3048 | .methods( |
| 3049 | boost::beast::http::verb:: |
| 3050 | get)([&app](const crow::Request& req, |
| 3051 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3052 | const std::string& systemName) { |
| 3053 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 3054 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3055 | return; |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 3056 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3057 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3058 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3059 | // Option currently returns no systems. TBD |
| 3060 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3061 | systemName); |
| 3062 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3063 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3064 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3065 | { |
| 3066 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3067 | systemName); |
| 3068 | return; |
| 3069 | } |
| 3070 | |
| 3071 | constexpr std::array<std::string_view, 1> interfaces = { |
| 3072 | crashdumpInterface}; |
| 3073 | dbus::utility::getSubTreePaths( |
| 3074 | "/", 0, interfaces, |
| 3075 | [asyncResp](const boost::system::error_code& ec, |
| 3076 | const std::vector<std::string>& resp) { |
| 3077 | if (ec) |
| 3078 | { |
| 3079 | if (ec.value() != |
| 3080 | boost::system::errc::no_such_file_or_directory) |
| 3081 | { |
| 3082 | BMCWEB_LOG_DEBUG("failed to get entries ec: {}", |
| 3083 | ec.message()); |
| 3084 | messages::internalError(asyncResp->res); |
| 3085 | return; |
| 3086 | } |
| 3087 | } |
| 3088 | asyncResp->res.jsonValue["@odata.type"] = |
| 3089 | "#LogEntryCollection.LogEntryCollection"; |
| 3090 | asyncResp->res.jsonValue["@odata.id"] = std::format( |
| 3091 | "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", |
| 3092 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 3093 | asyncResp->res.jsonValue["Name"] = |
| 3094 | "Open BMC Crashdump Entries"; |
| 3095 | asyncResp->res.jsonValue["Description"] = |
| 3096 | "Collection of Crashdump Entries"; |
| 3097 | asyncResp->res.jsonValue["Members"] = |
| 3098 | nlohmann::json::array(); |
| 3099 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
| 3100 | |
| 3101 | for (const std::string& path : resp) |
| 3102 | { |
| 3103 | const sdbusplus::message::object_path objPath(path); |
| 3104 | // Get the log ID |
| 3105 | std::string logID = objPath.filename(); |
| 3106 | if (logID.empty()) |
| 3107 | { |
| 3108 | continue; |
| 3109 | } |
| 3110 | // Add the log entry to the array |
| 3111 | logCrashdumpEntry(asyncResp, logID, |
| 3112 | asyncResp->res.jsonValue["Members"]); |
| 3113 | } |
| 3114 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3115 | }); |
| 3116 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 3117 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3118 | inline void requestRoutesCrashdumpEntry(App& app) |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 3119 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3120 | // Note: Deviated from redfish privilege registry for GET & HEAD |
| 3121 | // method for security reasons. |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 3122 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3123 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3124 | app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 3125 | // this is incorrect, should be |
| 3126 | // .privileges(redfish::privileges::getLogEntry) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 3127 | .privileges({{"ConfigureComponents"}}) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3128 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 3129 | [&app](const crow::Request& req, |
| 3130 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3131 | const std::string& systemName, const std::string& param) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3132 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3133 | { |
| 3134 | return; |
| 3135 | } |
| 3136 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3137 | { |
| 3138 | // Option currently returns no systems. TBD |
| 3139 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3140 | systemName); |
| 3141 | return; |
| 3142 | } |
| 3143 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3144 | { |
| 3145 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3146 | systemName); |
| 3147 | return; |
| 3148 | } |
| 3149 | const std::string& logID = param; |
| 3150 | logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); |
| 3151 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3152 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 3153 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3154 | inline void requestRoutesCrashdumpFile(App& app) |
| 3155 | { |
| 3156 | // Note: Deviated from redfish privilege registry for GET & HEAD |
| 3157 | // method for security reasons. |
| 3158 | BMCWEB_ROUTE( |
| 3159 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3160 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 3161 | .privileges(redfish::privileges::getLogEntry) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3162 | .methods(boost::beast::http::verb::get)( |
Nan Zhou | a4ce114 | 2022-08-02 18:45:25 +0000 | [diff] [blame] | 3163 | [](const crow::Request& req, |
| 3164 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3165 | const std::string& systemName, const std::string& logID, |
| 3166 | const std::string& fileName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3167 | // Do not call getRedfishRoute here since the crashdump file is |
| 3168 | // not a Redfish resource. |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3169 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3170 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3171 | { |
| 3172 | // Option currently returns no systems. TBD |
| 3173 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3174 | systemName); |
| 3175 | return; |
| 3176 | } |
| 3177 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3178 | { |
| 3179 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3180 | systemName); |
| 3181 | return; |
| 3182 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3183 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3184 | auto getStoredLogCallback = |
| 3185 | [asyncResp, logID, fileName, |
| 3186 | url(boost::urls::url(req.url()))]( |
| 3187 | const boost::system::error_code& ec, |
| 3188 | const std::vector<std::pair< |
| 3189 | std::string, dbus::utility::DbusVariantType>>& |
| 3190 | resp) { |
| 3191 | if (ec) |
| 3192 | { |
| 3193 | BMCWEB_LOG_DEBUG("failed to get log ec: {}", |
| 3194 | ec.message()); |
| 3195 | messages::internalError(asyncResp->res); |
| 3196 | return; |
| 3197 | } |
Jason M. Bills | 8e6c099 | 2021-03-11 16:26:53 -0800 | [diff] [blame] | 3198 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3199 | std::string dbusFilename{}; |
| 3200 | std::string dbusTimestamp{}; |
| 3201 | std::string dbusFilepath{}; |
Jason M. Bills | 8e6c099 | 2021-03-11 16:26:53 -0800 | [diff] [blame] | 3202 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3203 | parseCrashdumpParameters(resp, dbusFilename, |
| 3204 | dbusTimestamp, dbusFilepath); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3205 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3206 | if (dbusFilename.empty() || dbusTimestamp.empty() || |
| 3207 | dbusFilepath.empty()) |
| 3208 | { |
| 3209 | messages::resourceNotFound(asyncResp->res, |
| 3210 | "LogEntry", logID); |
| 3211 | return; |
| 3212 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3213 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3214 | // Verify the file name parameter is correct |
| 3215 | if (fileName != dbusFilename) |
| 3216 | { |
| 3217 | messages::resourceNotFound(asyncResp->res, |
| 3218 | "LogEntry", logID); |
| 3219 | return; |
| 3220 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3221 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3222 | if (!asyncResp->res.openFile(dbusFilepath)) |
| 3223 | { |
| 3224 | messages::resourceNotFound(asyncResp->res, |
| 3225 | "LogEntry", logID); |
| 3226 | return; |
| 3227 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3228 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3229 | // Configure this to be a file download when accessed |
| 3230 | // from a browser |
| 3231 | asyncResp->res.addHeader( |
| 3232 | boost::beast::http::field::content_disposition, |
| 3233 | "attachment"); |
| 3234 | }; |
| 3235 | sdbusplus::asio::getAllProperties( |
| 3236 | *crow::connections::systemBus, crashdumpObject, |
| 3237 | crashdumpPath + std::string("/") + logID, |
| 3238 | crashdumpInterface, std::move(getStoredLogCallback)); |
| 3239 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
Jason M. Bills | c5a4c82 | 2022-01-06 15:51:23 -0800 | [diff] [blame] | 3242 | enum class OEMDiagnosticType |
| 3243 | { |
| 3244 | onDemand, |
| 3245 | telemetry, |
| 3246 | invalid, |
| 3247 | }; |
| 3248 | |
Ed Tanous | 26ccae3 | 2023-02-16 10:28:44 -0800 | [diff] [blame] | 3249 | inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr) |
Jason M. Bills | c5a4c82 | 2022-01-06 15:51:23 -0800 | [diff] [blame] | 3250 | { |
| 3251 | if (oemDiagStr == "OnDemand") |
| 3252 | { |
| 3253 | return OEMDiagnosticType::onDemand; |
| 3254 | } |
| 3255 | if (oemDiagStr == "Telemetry") |
| 3256 | { |
| 3257 | return OEMDiagnosticType::telemetry; |
| 3258 | } |
| 3259 | |
| 3260 | return OEMDiagnosticType::invalid; |
| 3261 | } |
| 3262 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3263 | inline void requestRoutesCrashdumpCollect(App& app) |
| 3264 | { |
| 3265 | // Note: Deviated from redfish privilege registry for GET & HEAD |
| 3266 | // method for security reasons. |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 3267 | BMCWEB_ROUTE( |
| 3268 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3269 | "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 3270 | // The below is incorrect; Should be ConfigureManager |
| 3271 | //.privileges(redfish::privileges::postLogService) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 3272 | .privileges({{"ConfigureComponents"}}) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3273 | .methods(boost::beast::http::verb::post)( |
| 3274 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3275 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3276 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3277 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3278 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3279 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3280 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3281 | |
| 3282 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3283 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3284 | // Option currently returns no systems. TBD |
| 3285 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3286 | systemName); |
| 3287 | return; |
| 3288 | } |
| 3289 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3290 | { |
| 3291 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3292 | systemName); |
| 3293 | return; |
| 3294 | } |
| 3295 | |
| 3296 | std::string diagnosticDataType; |
| 3297 | std::string oemDiagnosticDataType; |
| 3298 | if (!redfish::json_util::readJsonAction( |
| 3299 | req, asyncResp->res, "DiagnosticDataType", |
| 3300 | diagnosticDataType, "OEMDiagnosticDataType", |
| 3301 | oemDiagnosticDataType)) |
| 3302 | { |
| 3303 | return; |
| 3304 | } |
| 3305 | |
| 3306 | if (diagnosticDataType != "OEM") |
| 3307 | { |
| 3308 | BMCWEB_LOG_ERROR( |
| 3309 | "Only OEM DiagnosticDataType supported for Crashdump"); |
| 3310 | messages::actionParameterValueFormatError( |
| 3311 | asyncResp->res, diagnosticDataType, |
| 3312 | "DiagnosticDataType", "CollectDiagnosticData"); |
| 3313 | return; |
| 3314 | } |
| 3315 | |
| 3316 | OEMDiagnosticType oemDiagType = |
| 3317 | getOEMDiagnosticType(oemDiagnosticDataType); |
| 3318 | |
| 3319 | std::string iface; |
| 3320 | std::string method; |
| 3321 | std::string taskMatchStr; |
| 3322 | if (oemDiagType == OEMDiagnosticType::onDemand) |
| 3323 | { |
| 3324 | iface = crashdumpOnDemandInterface; |
| 3325 | method = "GenerateOnDemandLog"; |
| 3326 | taskMatchStr = |
| 3327 | "type='signal'," |
| 3328 | "interface='org.freedesktop.DBus.Properties'," |
| 3329 | "member='PropertiesChanged'," |
| 3330 | "arg0namespace='com.intel.crashdump'"; |
| 3331 | } |
| 3332 | else if (oemDiagType == OEMDiagnosticType::telemetry) |
| 3333 | { |
| 3334 | iface = crashdumpTelemetryInterface; |
| 3335 | method = "GenerateTelemetryLog"; |
| 3336 | taskMatchStr = |
| 3337 | "type='signal'," |
| 3338 | "interface='org.freedesktop.DBus.Properties'," |
| 3339 | "member='PropertiesChanged'," |
| 3340 | "arg0namespace='com.intel.crashdump'"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3341 | } |
| 3342 | else |
| 3343 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3344 | BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}", |
| 3345 | oemDiagnosticDataType); |
| 3346 | messages::actionParameterValueFormatError( |
| 3347 | asyncResp->res, oemDiagnosticDataType, |
| 3348 | "OEMDiagnosticDataType", "CollectDiagnosticData"); |
| 3349 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3350 | } |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 3351 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3352 | auto collectCrashdumpCallback = |
| 3353 | [asyncResp, payload(task::Payload(req)), |
| 3354 | taskMatchStr](const boost::system::error_code& ec, |
| 3355 | const std::string&) mutable { |
| 3356 | if (ec) |
| 3357 | { |
| 3358 | if (ec.value() == |
| 3359 | boost::system::errc::operation_not_supported) |
| 3360 | { |
| 3361 | messages::resourceInStandby(asyncResp->res); |
| 3362 | } |
| 3363 | else if (ec.value() == boost::system::errc:: |
| 3364 | device_or_resource_busy) |
| 3365 | { |
| 3366 | messages::serviceTemporarilyUnavailable( |
| 3367 | asyncResp->res, "60"); |
| 3368 | } |
| 3369 | else |
| 3370 | { |
| 3371 | messages::internalError(asyncResp->res); |
| 3372 | } |
| 3373 | return; |
| 3374 | } |
| 3375 | std::shared_ptr<task::TaskData> task = |
| 3376 | task::TaskData::createTask( |
| 3377 | [](const boost::system::error_code& ec2, |
| 3378 | sdbusplus::message_t&, |
| 3379 | const std::shared_ptr<task::TaskData>& |
| 3380 | taskData) { |
| 3381 | if (!ec2) |
| 3382 | { |
| 3383 | taskData->messages.emplace_back( |
| 3384 | messages::taskCompletedOK( |
| 3385 | std::to_string( |
| 3386 | taskData->index))); |
| 3387 | taskData->state = "Completed"; |
| 3388 | } |
| 3389 | return task::completed; |
| 3390 | }, |
| 3391 | taskMatchStr); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3392 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3393 | task->startTimer(std::chrono::minutes(5)); |
| 3394 | task->populateResp(asyncResp->res); |
| 3395 | task->payload.emplace(std::move(payload)); |
| 3396 | }; |
| 3397 | |
| 3398 | crow::connections::systemBus->async_method_call( |
| 3399 | std::move(collectCrashdumpCallback), crashdumpObject, |
| 3400 | crashdumpPath, iface, method); |
| 3401 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3402 | } |
Kenny L. Ku | 6eda768 | 2020-06-19 09:48:36 -0700 | [diff] [blame] | 3403 | |
Alexander Hansen | 599b9af | 2024-08-06 15:11:57 +0200 | [diff] [blame] | 3404 | inline void dBusLogServiceActionsClear( |
| 3405 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 3406 | { |
| 3407 | BMCWEB_LOG_DEBUG("Do delete all entries."); |
| 3408 | |
| 3409 | // Process response from Logging service. |
| 3410 | auto respHandler = [asyncResp](const boost::system::error_code& ec) { |
| 3411 | BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done"); |
| 3412 | if (ec) |
| 3413 | { |
| 3414 | // TODO Handle for specific error code |
| 3415 | BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec); |
| 3416 | asyncResp->res.result( |
| 3417 | boost::beast::http::status::internal_server_error); |
| 3418 | return; |
| 3419 | } |
| 3420 | |
| 3421 | asyncResp->res.result(boost::beast::http::status::no_content); |
| 3422 | }; |
| 3423 | |
| 3424 | // Make call to Logging service to request Clear Log |
| 3425 | crow::connections::systemBus->async_method_call( |
| 3426 | respHandler, "xyz.openbmc_project.Logging", |
| 3427 | "/xyz/openbmc_project/logging", |
| 3428 | "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); |
| 3429 | } |
| 3430 | |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 3431 | /** |
| 3432 | * DBusLogServiceActionsClear class supports POST method for ClearLog action. |
| 3433 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3434 | inline void requestRoutesDBusLogServiceActionsClear(App& app) |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 3435 | { |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 3436 | /** |
| 3437 | * Function handles POST method request. |
| 3438 | * The Clear Log actions does not require any parameter.The action deletes |
| 3439 | * all entries found in the Entries collection for this Log Service. |
| 3440 | */ |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 3441 | |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 3442 | BMCWEB_ROUTE( |
| 3443 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3444 | "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 3445 | .privileges(redfish::privileges::postLogService) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3446 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 3447 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3448 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3449 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3450 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3451 | { |
| 3452 | return; |
| 3453 | } |
| 3454 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3455 | { |
| 3456 | // Option currently returns no systems. TBD |
| 3457 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3458 | systemName); |
| 3459 | return; |
| 3460 | } |
| 3461 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3462 | { |
| 3463 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3464 | systemName); |
| 3465 | return; |
| 3466 | } |
| 3467 | dBusLogServiceActionsClear(asyncResp); |
| 3468 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3469 | } |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3470 | |
| 3471 | /**************************************************** |
| 3472 | * Redfish PostCode interfaces |
| 3473 | * using DBUS interface: getPostCodesTS |
| 3474 | ******************************************************/ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3475 | inline void requestRoutesPostCodesLogService(App& app) |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3476 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3477 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 3478 | .privileges(redfish::privileges::getLogService) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3479 | .methods( |
| 3480 | boost::beast::http::verb:: |
| 3481 | get)([&app](const crow::Request& req, |
| 3482 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3483 | const std::string& systemName) { |
| 3484 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3485 | { |
| 3486 | return; |
| 3487 | } |
| 3488 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3489 | { |
| 3490 | // Option currently returns no systems. TBD |
| 3491 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3492 | systemName); |
| 3493 | return; |
| 3494 | } |
| 3495 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3496 | { |
| 3497 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3498 | systemName); |
| 3499 | return; |
| 3500 | } |
| 3501 | asyncResp->res.jsonValue["@odata.id"] = |
| 3502 | std::format("/redfish/v1/Systems/{}/LogServices/PostCodes", |
| 3503 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 3504 | asyncResp->res.jsonValue["@odata.type"] = |
| 3505 | "#LogService.v1_2_0.LogService"; |
| 3506 | asyncResp->res.jsonValue["Name"] = "POST Code Log Service"; |
| 3507 | asyncResp->res.jsonValue["Description"] = "POST Code Log Service"; |
| 3508 | asyncResp->res.jsonValue["Id"] = "PostCodes"; |
| 3509 | asyncResp->res.jsonValue["OverWritePolicy"] = |
| 3510 | log_service::OverWritePolicy::WrapsWhenFull; |
| 3511 | asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format( |
| 3512 | "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries", |
| 3513 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 3514 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3515 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| 3516 | redfish::time_utils::getDateTimeOffsetNow(); |
| 3517 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 3518 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 3519 | redfishDateTimeOffset.second; |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 3520 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3521 | asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] |
| 3522 | ["target"] = std::format( |
| 3523 | "/redfish/v1/Systems/{}/LogServices/PostCodes/Actions/LogService.ClearLog", |
| 3524 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 3525 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3526 | } |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3527 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3528 | inline void requestRoutesPostCodesClear(App& app) |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3529 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 3530 | BMCWEB_ROUTE( |
| 3531 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3532 | "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 3533 | // The following privilege is incorrect; It should be ConfigureManager |
| 3534 | //.privileges(redfish::privileges::postLogService) |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 3535 | .privileges({{"ConfigureComponents"}}) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3536 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 3537 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3538 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3539 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3540 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3541 | { |
| 3542 | return; |
| 3543 | } |
| 3544 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3545 | { |
| 3546 | // Option currently returns no systems. TBD |
| 3547 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3548 | systemName); |
| 3549 | return; |
| 3550 | } |
| 3551 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3552 | { |
| 3553 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3554 | systemName); |
| 3555 | return; |
| 3556 | } |
| 3557 | BMCWEB_LOG_DEBUG("Do delete all postcodes entries."); |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3558 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3559 | // Make call to post-code service to request clear all |
| 3560 | crow::connections::systemBus->async_method_call( |
| 3561 | [asyncResp](const boost::system::error_code& ec) { |
| 3562 | if (ec) |
| 3563 | { |
| 3564 | // TODO Handle for specific error code |
| 3565 | BMCWEB_LOG_ERROR( |
| 3566 | "doClearPostCodes resp_handler got error {}", |
| 3567 | ec); |
| 3568 | asyncResp->res.result(boost::beast::http::status:: |
| 3569 | internal_server_error); |
| 3570 | messages::internalError(asyncResp->res); |
| 3571 | return; |
| 3572 | } |
| 3573 | messages::success(asyncResp->res); |
| 3574 | }, |
| 3575 | "xyz.openbmc_project.State.Boot.PostCode0", |
| 3576 | "/xyz/openbmc_project/State/Boot/PostCode0", |
| 3577 | "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); |
| 3578 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3579 | } |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3580 | |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3581 | /** |
| 3582 | * @brief Parse post code ID and get the current value and index value |
| 3583 | * eg: postCodeID=B1-2, currentValue=1, index=2 |
| 3584 | * |
| 3585 | * @param[in] postCodeID Post Code ID |
| 3586 | * @param[out] currentValue Current value |
| 3587 | * @param[out] index Index value |
| 3588 | * |
| 3589 | * @return bool true if the parsing is successful, false the parsing fails |
| 3590 | */ |
Ed Tanous | 6f056f2 | 2024-04-07 13:35:51 -0700 | [diff] [blame] | 3591 | inline bool parsePostCode(std::string_view postCodeID, uint64_t& currentValue, |
Ed Tanous | df254f2 | 2024-04-01 13:25:46 -0700 | [diff] [blame] | 3592 | uint16_t& index) |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3593 | { |
| 3594 | std::vector<std::string> split; |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 3595 | bmcweb::split(split, postCodeID, '-'); |
Ed Tanous | 6f056f2 | 2024-04-07 13:35:51 -0700 | [diff] [blame] | 3596 | if (split.size() != 2) |
| 3597 | { |
| 3598 | return false; |
| 3599 | } |
| 3600 | std::string_view postCodeNumber = split[0]; |
| 3601 | if (postCodeNumber.size() < 2) |
| 3602 | { |
| 3603 | return false; |
| 3604 | } |
| 3605 | if (postCodeNumber[0] != 'B') |
| 3606 | { |
| 3607 | return false; |
| 3608 | } |
| 3609 | postCodeNumber.remove_prefix(1); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3610 | auto [ptrIndex, ecIndex] = |
| 3611 | std::from_chars(postCodeNumber.begin(), postCodeNumber.end(), index); |
Ed Tanous | 6f056f2 | 2024-04-07 13:35:51 -0700 | [diff] [blame] | 3612 | if (ptrIndex != postCodeNumber.end() || ecIndex != std::errc()) |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3613 | { |
| 3614 | return false; |
| 3615 | } |
| 3616 | |
Ed Tanous | 6f056f2 | 2024-04-07 13:35:51 -0700 | [diff] [blame] | 3617 | std::string_view postCodeIndex = split[1]; |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3618 | |
Ed Tanous | 6f056f2 | 2024-04-07 13:35:51 -0700 | [diff] [blame] | 3619 | auto [ptrValue, ecValue] = std::from_chars( |
| 3620 | postCodeIndex.begin(), postCodeIndex.end(), currentValue); |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3621 | |
Ed Tanous | 6f056f2 | 2024-04-07 13:35:51 -0700 | [diff] [blame] | 3622 | return ptrValue == postCodeIndex.end() && ecValue == std::errc(); |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | static bool fillPostCodeEntry( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 3626 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Manojkiran Eda | 6c9a279 | 2021-02-27 14:25:04 +0530 | [diff] [blame] | 3627 | const boost::container::flat_map< |
| 3628 | uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3629 | const uint16_t bootIndex, const uint64_t codeIndex = 0, |
| 3630 | const uint64_t skip = 0, const uint64_t top = 0) |
| 3631 | { |
| 3632 | // Get the Message from the MessageRegistry |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 3633 | const registries::Message* message = |
| 3634 | registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); |
Ed Tanous | dc8cfa6 | 2024-04-07 13:37:25 -0700 | [diff] [blame] | 3635 | if (message == nullptr) |
| 3636 | { |
| 3637 | BMCWEB_LOG_ERROR("Couldn't find known message?"); |
| 3638 | return false; |
| 3639 | } |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3640 | uint64_t currentCodeIndex = 0; |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3641 | uint64_t firstCodeTimeUs = 0; |
Manojkiran Eda | 6c9a279 | 2021-02-27 14:25:04 +0530 | [diff] [blame] | 3642 | for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& |
| 3643 | code : postcode) |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3644 | { |
| 3645 | currentCodeIndex++; |
| 3646 | std::string postcodeEntryID = |
| 3647 | "B" + std::to_string(bootIndex) + "-" + |
| 3648 | std::to_string(currentCodeIndex); // 1 based index in EntryID string |
| 3649 | |
| 3650 | uint64_t usecSinceEpoch = code.first; |
| 3651 | uint64_t usTimeOffset = 0; |
| 3652 | |
| 3653 | if (1 == currentCodeIndex) |
| 3654 | { // already incremented |
| 3655 | firstCodeTimeUs = code.first; |
| 3656 | } |
| 3657 | else |
| 3658 | { |
| 3659 | usTimeOffset = code.first - firstCodeTimeUs; |
| 3660 | } |
| 3661 | |
| 3662 | // skip if no specific codeIndex is specified and currentCodeIndex does |
| 3663 | // not fall between top and skip |
| 3664 | if ((codeIndex == 0) && |
| 3665 | (currentCodeIndex <= skip || currentCodeIndex > top)) |
| 3666 | { |
| 3667 | continue; |
| 3668 | } |
| 3669 | |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 3670 | // skip if a specific codeIndex is specified and does not match the |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3671 | // currentIndex |
| 3672 | if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) |
| 3673 | { |
| 3674 | // This is done for simplicity. 1st entry is needed to calculate |
| 3675 | // time offset. To improve efficiency, one can get to the entry |
| 3676 | // directly (possibly with flatmap's nth method) |
| 3677 | continue; |
| 3678 | } |
| 3679 | |
| 3680 | // currentCodeIndex is within top and skip or equal to specified code |
| 3681 | // index |
| 3682 | |
| 3683 | // Get the Created time from the timestamp |
| 3684 | std::string entryTimeStr; |
Konstantin Aladyshev | 2a02561 | 2023-02-15 11:52:58 +0300 | [diff] [blame] | 3685 | entryTimeStr = redfish::time_utils::getDateTimeUintUs(usecSinceEpoch); |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3686 | |
| 3687 | // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) |
| 3688 | std::ostringstream hexCode; |
| 3689 | hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex |
Manojkiran Eda | 6c9a279 | 2021-02-27 14:25:04 +0530 | [diff] [blame] | 3690 | << std::get<0>(code.second); |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3691 | std::ostringstream timeOffsetStr; |
| 3692 | // Set Fixed -Point Notation |
| 3693 | timeOffsetStr << std::fixed; |
| 3694 | // Set precision to 4 digits |
| 3695 | timeOffsetStr << std::setprecision(4); |
| 3696 | // Add double to stream |
| 3697 | timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3698 | |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 3699 | std::string bootIndexStr = std::to_string(bootIndex); |
| 3700 | std::string timeOffsetString = timeOffsetStr.str(); |
| 3701 | std::string hexCodeStr = hexCode.str(); |
| 3702 | |
| 3703 | std::array<std::string_view, 3> messageArgs = { |
| 3704 | bootIndexStr, timeOffsetString, hexCodeStr}; |
| 3705 | |
| 3706 | std::string msg = |
| 3707 | redfish::registries::fillMessageArgs(messageArgs, message->message); |
| 3708 | if (msg.empty()) |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3709 | { |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 3710 | messages::internalError(asyncResp->res); |
| 3711 | return false; |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3712 | } |
| 3713 | |
Tim Lee | d4342a9 | 2020-04-27 11:47:58 +0800 | [diff] [blame] | 3714 | // Get Severity template from message registry |
| 3715 | std::string severity; |
| 3716 | if (message != nullptr) |
| 3717 | { |
Ed Tanous | 5f2b84e | 2022-02-08 00:41:53 -0800 | [diff] [blame] | 3718 | severity = message->messageSeverity; |
Tim Lee | d4342a9 | 2020-04-27 11:47:58 +0800 | [diff] [blame] | 3719 | } |
| 3720 | |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3721 | // Format entry |
| 3722 | nlohmann::json::object_t bmcLogEntry; |
Vijay Lobo | 9c11a17 | 2021-10-07 16:53:16 -0500 | [diff] [blame] | 3723 | bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 3724 | bmcLogEntry["@odata.id"] = boost::urls::format( |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 3725 | "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/{}", |
| 3726 | BMCWEB_REDFISH_SYSTEM_URI_NAME, postcodeEntryID); |
Jason M. Bills | 84afc48 | 2022-06-24 12:38:23 -0700 | [diff] [blame] | 3727 | bmcLogEntry["Name"] = "POST Code Log Entry"; |
| 3728 | bmcLogEntry["Id"] = postcodeEntryID; |
| 3729 | bmcLogEntry["Message"] = std::move(msg); |
| 3730 | bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode"; |
Ed Tanous | 1e6deaf | 2022-02-17 11:32:37 -0800 | [diff] [blame] | 3731 | bmcLogEntry["MessageArgs"] = messageArgs; |
Jason M. Bills | 84afc48 | 2022-06-24 12:38:23 -0700 | [diff] [blame] | 3732 | bmcLogEntry["EntryType"] = "Event"; |
| 3733 | bmcLogEntry["Severity"] = std::move(severity); |
| 3734 | bmcLogEntry["Created"] = entryTimeStr; |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 3735 | if (!std::get<std::vector<uint8_t>>(code.second).empty()) |
| 3736 | { |
| 3737 | bmcLogEntry["AdditionalDataURI"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 3738 | std::format( |
| 3739 | "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/", |
| 3740 | BMCWEB_REDFISH_SYSTEM_URI_NAME) + |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 3741 | postcodeEntryID + "/attachment"; |
| 3742 | } |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3743 | |
| 3744 | // codeIndex is only specified when querying single entry, return only |
| 3745 | // that entry in this case |
| 3746 | if (codeIndex != 0) |
| 3747 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 3748 | asyncResp->res.jsonValue.update(bmcLogEntry); |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3749 | return true; |
| 3750 | } |
| 3751 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 3752 | nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 3753 | logEntryArray.emplace_back(std::move(bmcLogEntry)); |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3754 | } |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3755 | |
| 3756 | // Return value is always false when querying multiple entries |
| 3757 | return false; |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3758 | } |
| 3759 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 3760 | static void |
| 3761 | getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3762 | const std::string& entryId) |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3763 | { |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3764 | uint16_t bootIndex = 0; |
| 3765 | uint64_t codeIndex = 0; |
| 3766 | if (!parsePostCode(entryId, codeIndex, bootIndex)) |
| 3767 | { |
| 3768 | // Requested ID was not found |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 3769 | messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3770 | return; |
| 3771 | } |
| 3772 | |
| 3773 | if (bootIndex == 0 || codeIndex == 0) |
| 3774 | { |
| 3775 | // 0 is an invalid index |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 3776 | messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); |
Jiaqing Zhao | 6f284d2 | 2022-10-10 15:56:45 +0800 | [diff] [blame] | 3777 | return; |
| 3778 | } |
| 3779 | |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3780 | crow::connections::systemBus->async_method_call( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 3781 | [asyncResp, entryId, bootIndex, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 3782 | codeIndex](const boost::system::error_code& ec, |
Manojkiran Eda | 6c9a279 | 2021-02-27 14:25:04 +0530 | [diff] [blame] | 3783 | const boost::container::flat_map< |
| 3784 | uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& |
| 3785 | postcode) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3786 | if (ec) |
| 3787 | { |
| 3788 | BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error"); |
| 3789 | messages::internalError(asyncResp->res); |
| 3790 | return; |
| 3791 | } |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3792 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3793 | if (postcode.empty()) |
| 3794 | { |
| 3795 | messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); |
| 3796 | return; |
| 3797 | } |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3798 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3799 | if (!fillPostCodeEntry(asyncResp, postcode, bootIndex, codeIndex)) |
| 3800 | { |
| 3801 | messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); |
| 3802 | return; |
| 3803 | } |
| 3804 | }, |
Jonathan Doman | 1512476 | 2021-01-07 17:54:17 -0800 | [diff] [blame] | 3805 | "xyz.openbmc_project.State.Boot.PostCode0", |
| 3806 | "/xyz/openbmc_project/State/Boot/PostCode0", |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3807 | "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", |
| 3808 | bootIndex); |
| 3809 | } |
| 3810 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 3811 | static void |
| 3812 | getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3813 | const uint16_t bootIndex, const uint16_t bootCount, |
| 3814 | const uint64_t entryCount, size_t skip, size_t top) |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3815 | { |
| 3816 | crow::connections::systemBus->async_method_call( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 3817 | [asyncResp, bootIndex, bootCount, entryCount, skip, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 3818 | top](const boost::system::error_code& ec, |
Manojkiran Eda | 6c9a279 | 2021-02-27 14:25:04 +0530 | [diff] [blame] | 3819 | const boost::container::flat_map< |
| 3820 | uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& |
| 3821 | postcode) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3822 | if (ec) |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3823 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3824 | BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error"); |
| 3825 | messages::internalError(asyncResp->res); |
| 3826 | return; |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3827 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3828 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3829 | uint64_t endCount = entryCount; |
| 3830 | if (!postcode.empty()) |
| 3831 | { |
| 3832 | endCount = entryCount + postcode.size(); |
| 3833 | if (skip < endCount && (top + skip) > entryCount) |
| 3834 | { |
| 3835 | uint64_t thisBootSkip = |
| 3836 | std::max(static_cast<uint64_t>(skip), entryCount) - |
| 3837 | entryCount; |
| 3838 | uint64_t thisBootTop = |
| 3839 | std::min(static_cast<uint64_t>(top + skip), endCount) - |
| 3840 | entryCount; |
| 3841 | |
| 3842 | fillPostCodeEntry(asyncResp, postcode, bootIndex, 0, |
| 3843 | thisBootSkip, thisBootTop); |
| 3844 | } |
| 3845 | asyncResp->res.jsonValue["Members@odata.count"] = endCount; |
| 3846 | } |
| 3847 | |
| 3848 | // continue to previous bootIndex |
| 3849 | if (bootIndex < bootCount) |
| 3850 | { |
| 3851 | getPostCodeForBoot(asyncResp, |
| 3852 | static_cast<uint16_t>(bootIndex + 1), |
| 3853 | bootCount, endCount, skip, top); |
| 3854 | } |
| 3855 | else if (skip + top < endCount) |
| 3856 | { |
| 3857 | asyncResp->res.jsonValue["Members@odata.nextLink"] = |
| 3858 | std::format( |
| 3859 | "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries?$skip=", |
| 3860 | BMCWEB_REDFISH_SYSTEM_URI_NAME) + |
| 3861 | std::to_string(skip + top); |
| 3862 | } |
| 3863 | }, |
Jonathan Doman | 1512476 | 2021-01-07 17:54:17 -0800 | [diff] [blame] | 3864 | "xyz.openbmc_project.State.Boot.PostCode0", |
| 3865 | "/xyz/openbmc_project/State/Boot/PostCode0", |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3866 | "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", |
| 3867 | bootIndex); |
| 3868 | } |
| 3869 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 3870 | static void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 3871 | getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 3648c8b | 2022-07-25 13:39:59 -0700 | [diff] [blame] | 3872 | size_t skip, size_t top) |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3873 | { |
| 3874 | uint64_t entryCount = 0; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 3875 | sdbusplus::asio::getProperty<uint16_t>( |
| 3876 | *crow::connections::systemBus, |
| 3877 | "xyz.openbmc_project.State.Boot.PostCode0", |
| 3878 | "/xyz/openbmc_project/State/Boot/PostCode0", |
| 3879 | "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3880 | [asyncResp, entryCount, skip, |
| 3881 | top](const boost::system::error_code& ec, const uint16_t bootCount) { |
| 3882 | if (ec) |
| 3883 | { |
| 3884 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec); |
| 3885 | messages::internalError(asyncResp->res); |
| 3886 | return; |
| 3887 | } |
| 3888 | getPostCodeForBoot(asyncResp, 1, bootCount, entryCount, skip, top); |
| 3889 | }); |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3890 | } |
| 3891 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3892 | inline void requestRoutesPostCodesEntryCollection(App& app) |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3893 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3894 | BMCWEB_ROUTE(app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3895 | "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 3896 | .privileges(redfish::privileges::getLogEntryCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3897 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 3898 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3899 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3900 | const std::string& systemName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3901 | query_param::QueryCapabilities capabilities = { |
| 3902 | .canDelegateTop = true, |
| 3903 | .canDelegateSkip = true, |
| 3904 | }; |
| 3905 | query_param::Query delegatedQuery; |
| 3906 | if (!redfish::setUpRedfishRouteWithDelegation( |
| 3907 | app, req, asyncResp, delegatedQuery, capabilities)) |
| 3908 | { |
| 3909 | return; |
| 3910 | } |
| 3911 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3912 | { |
| 3913 | // Option currently returns no systems. TBD |
| 3914 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3915 | systemName); |
| 3916 | return; |
| 3917 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3918 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3919 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3920 | { |
| 3921 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3922 | systemName); |
| 3923 | return; |
| 3924 | } |
| 3925 | asyncResp->res.jsonValue["@odata.type"] = |
| 3926 | "#LogEntryCollection.LogEntryCollection"; |
| 3927 | asyncResp->res.jsonValue["@odata.id"] = std::format( |
| 3928 | "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries", |
| 3929 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 3930 | asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; |
| 3931 | asyncResp->res.jsonValue["Description"] = |
| 3932 | "Collection of POST Code Log Entries"; |
| 3933 | asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); |
| 3934 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
| 3935 | size_t skip = delegatedQuery.skip.value_or(0); |
| 3936 | size_t top = |
| 3937 | delegatedQuery.top.value_or(query_param::Query::maxTop); |
| 3938 | getCurrentBootNumber(asyncResp, skip, top); |
| 3939 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3940 | } |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 3941 | |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 3942 | inline void requestRoutesPostCodesEntryAdditionalData(App& app) |
| 3943 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 3944 | BMCWEB_ROUTE( |
| 3945 | app, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3946 | "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/") |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 3947 | .privileges(redfish::privileges::getLogEntry) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3948 | .methods( |
| 3949 | boost::beast::http::verb:: |
| 3950 | get)([&app](const crow::Request& req, |
| 3951 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3952 | const std::string& systemName, |
| 3953 | const std::string& postCodeID) { |
| 3954 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3955 | { |
| 3956 | return; |
| 3957 | } |
| 3958 | if (!http_helpers::isContentTypeAllowed( |
| 3959 | req.getHeaderValue("Accept"), |
| 3960 | http_helpers::ContentType::OctetStream, true)) |
| 3961 | { |
| 3962 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 3963 | return; |
| 3964 | } |
| 3965 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3966 | { |
| 3967 | // Option currently returns no systems. TBD |
| 3968 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3969 | systemName); |
| 3970 | return; |
| 3971 | } |
| 3972 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3973 | { |
| 3974 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3975 | systemName); |
| 3976 | return; |
| 3977 | } |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 3978 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3979 | uint64_t currentValue = 0; |
| 3980 | uint16_t index = 0; |
| 3981 | if (!parsePostCode(postCodeID, currentValue, index)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 3982 | { |
| 3983 | messages::resourceNotFound(asyncResp->res, "LogEntry", |
| 3984 | postCodeID); |
| 3985 | return; |
| 3986 | } |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 3987 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 3988 | crow::connections::systemBus->async_method_call( |
| 3989 | [asyncResp, postCodeID, currentValue]( |
| 3990 | const boost::system::error_code& ec, |
| 3991 | const std::vector<std::tuple< |
| 3992 | uint64_t, std::vector<uint8_t>>>& postcodes) { |
| 3993 | if (ec.value() == EBADR) |
| 3994 | { |
| 3995 | messages::resourceNotFound(asyncResp->res, "LogEntry", |
| 3996 | postCodeID); |
| 3997 | return; |
| 3998 | } |
| 3999 | if (ec) |
| 4000 | { |
| 4001 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec); |
| 4002 | messages::internalError(asyncResp->res); |
| 4003 | return; |
| 4004 | } |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 4005 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 4006 | size_t value = static_cast<size_t>(currentValue) - 1; |
| 4007 | if (value == std::string::npos || |
| 4008 | postcodes.size() < currentValue) |
| 4009 | { |
| 4010 | BMCWEB_LOG_WARNING("Wrong currentValue value"); |
| 4011 | messages::resourceNotFound(asyncResp->res, "LogEntry", |
| 4012 | postCodeID); |
| 4013 | return; |
| 4014 | } |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 4015 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 4016 | const auto& [tID, c] = postcodes[value]; |
| 4017 | if (c.empty()) |
| 4018 | { |
| 4019 | BMCWEB_LOG_WARNING("No found post code data"); |
| 4020 | messages::resourceNotFound(asyncResp->res, "LogEntry", |
| 4021 | postCodeID); |
| 4022 | return; |
| 4023 | } |
| 4024 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) |
| 4025 | const char* d = reinterpret_cast<const char*>(c.data()); |
| 4026 | std::string_view strData(d, c.size()); |
| 4027 | |
| 4028 | asyncResp->res.addHeader( |
| 4029 | boost::beast::http::field::content_type, |
| 4030 | "application/octet-stream"); |
| 4031 | asyncResp->res.addHeader( |
| 4032 | boost::beast::http::field::content_transfer_encoding, |
| 4033 | "Base64"); |
| 4034 | asyncResp->res.write(crow::utility::base64encode(strData)); |
| 4035 | }, |
| 4036 | "xyz.openbmc_project.State.Boot.PostCode0", |
| 4037 | "/xyz/openbmc_project/State/Boot/PostCode0", |
| 4038 | "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", |
| 4039 | index); |
| 4040 | }); |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 4041 | } |
| 4042 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 4043 | inline void requestRoutesPostCodesEntry(App& app) |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 4044 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 4045 | BMCWEB_ROUTE( |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 4046 | app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 4047 | .privileges(redfish::privileges::getLogEntry) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 4048 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 4049 | [&app](const crow::Request& req, |
| 4050 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 4051 | const std::string& systemName, const std::string& targetID) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 4052 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 4053 | { |
| 4054 | return; |
| 4055 | } |
| 4056 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 4057 | { |
| 4058 | // Option currently returns no systems. TBD |
| 4059 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 4060 | systemName); |
| 4061 | return; |
| 4062 | } |
| 4063 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 4064 | { |
| 4065 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 4066 | systemName); |
| 4067 | return; |
| 4068 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 4069 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 4070 | getPostCodeForEntry(asyncResp, targetID); |
| 4071 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 4072 | } |
ZhikuiRen | a3316fc | 2020-01-29 14:58:08 -0800 | [diff] [blame] | 4073 | |
Ed Tanous | 1da66f7 | 2018-07-27 16:13:37 -0700 | [diff] [blame] | 4074 | } // namespace redfish |