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