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