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