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