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