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