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