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