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