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