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