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