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