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