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