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