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