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