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