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