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