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