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