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