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