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