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