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