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