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