blob: 7f27515bd7feb42fcaac909bb5da43d0249bbd17 [file] [log] [blame]
Ed Tanous1da66f72018-07-27 16:13:37 -07001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "app.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080019#include "dbus_utility.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080020#include "error_messages.hpp"
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -060021#include "generated/enums/log_entry.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070022#include "generated/enums/log_service.hpp"
Spencer Kub7028eb2021-10-26 15:27:35 +080023#include "gzfile.hpp"
George Liu647b3cd2021-07-05 12:43:56 +080024#include "http_utility.hpp"
Spencer Kub7028eb2021-10-26 15:27:35 +080025#include "human_sort.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080026#include "query.hpp"
Jason M. Bills4851d452019-03-28 11:27:48 -070027#include "registries.hpp"
28#include "registries/base_message_registry.hpp"
29#include "registries/openbmc_message_registry.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080030#include "registries/privilege_registry.hpp"
James Feist46229572020-02-19 15:11:58 -080031#include "task.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070032#include "task_messages.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080033#include "utils/dbus_utils.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070034#include "utils/json_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080035#include "utils/time_utils.hpp"
Ed Tanous1da66f72018-07-27 16:13:37 -070036
Myung Bae75e8e212023-11-30 12:53:46 -080037#include <systemd/sd-id128.h>
Asmitha Karunanithi8e317782020-12-10 03:35:05 -060038#include <tinyxml2.h>
Adriana Kobylak400fd1f2021-01-29 09:01:30 -060039#include <unistd.h>
Jason M. Billse1f26342018-07-18 12:12:00 -070040
Ed Tanous07c8c202022-07-11 10:08:08 -070041#include <boost/beast/http/verb.hpp>
Ed Tanous1da66f72018-07-27 16:13:37 -070042#include <boost/container/flat_map.hpp>
Jason M. Bills1ddcf012019-11-26 14:59:21 -080043#include <boost/system/linux_error.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070044#include <boost/url/format.hpp>
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +020045#include <sdbusplus/asio/property.hpp>
46#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050047
George Liu7a1dbc42022-12-07 16:03:22 +080048#include <array>
George Liu647b3cd2021-07-05 12:43:56 +080049#include <charconv>
Abhilash Rajub5f288d2023-11-08 22:32:44 -060050#include <cstddef>
James Feist4418c7f2019-04-15 11:09:15 -070051#include <filesystem>
Ed Tanous18f8f602023-07-18 10:07:23 -070052#include <iterator>
Xiaochao Ma75710de2021-01-21 17:56:02 +080053#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070054#include <ranges>
Ed Tanous26702d02021-11-03 15:02:33 -070055#include <span>
Ed Tanous18f8f602023-07-18 10:07:23 -070056#include <string>
Jason M. Billscd225da2019-05-08 15:31:57 -070057#include <string_view>
Ed Tanousabf2add2019-01-22 16:40:12 -080058#include <variant>
Ed Tanous1da66f72018-07-27 16:13:37 -070059
60namespace redfish
61{
62
Patrick Williams89492a12023-05-10 07:51:34 -050063constexpr const char* crashdumpObject = "com.intel.crashdump";
64constexpr const char* crashdumpPath = "/com/intel/crashdump";
65constexpr const char* crashdumpInterface = "com.intel.crashdump";
66constexpr const char* deleteAllInterface =
Jason M. Bills5b61b5e2019-10-16 10:59:02 -070067 "xyz.openbmc_project.Collection.DeleteAll";
Patrick Williams89492a12023-05-10 07:51:34 -050068constexpr const char* crashdumpOnDemandInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070069 "com.intel.crashdump.OnDemand";
Patrick Williams89492a12023-05-10 07:51:34 -050070constexpr const char* crashdumpTelemetryInterface =
Kenny L. Ku6eda7682020-06-19 09:48:36 -070071 "com.intel.crashdump.Telemetry";
Ed Tanous1da66f72018-07-27 16:13:37 -070072
Asmitha Karunanithi8e317782020-12-10 03:35:05 -060073enum class DumpCreationProgress
74{
75 DUMP_CREATE_SUCCESS,
76 DUMP_CREATE_FAILED,
77 DUMP_CREATE_INPROGRESS
78};
79
James Feistf6150402019-01-08 10:36:20 -080080namespace fs = std::filesystem;
Ed Tanous1da66f72018-07-27 16:13:37 -070081
Gunnar Mills1214b7e2020-06-04 10:11:30 -050082inline std::string translateSeverityDbusToRedfish(const std::string& s)
Andrew Geisslercb92c032018-08-17 07:56:14 -070083{
Ed Tanousd4d25792020-09-29 15:15:03 -070084 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
85 (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
86 (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
87 (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
Andrew Geisslercb92c032018-08-17 07:56:14 -070088 {
89 return "Critical";
90 }
Ed Tanous3174e4d2020-10-07 11:41:22 -070091 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
92 (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
93 (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
Andrew Geisslercb92c032018-08-17 07:56:14 -070094 {
95 return "OK";
96 }
Ed Tanous3174e4d2020-10-07 11:41:22 -070097 if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
Andrew Geisslercb92c032018-08-17 07:56:14 -070098 {
99 return "Warning";
100 }
101 return "";
102}
103
Abhishek Patel9017faf2021-09-14 22:48:55 -0500104inline std::optional<bool> getProviderNotifyAction(const std::string& notify)
105{
106 std::optional<bool> notifyAction;
107 if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify")
108 {
109 notifyAction = true;
110 }
111 else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit")
112 {
113 notifyAction = false;
114 }
115
116 return notifyAction;
117}
118
Ed Tanous18f8f602023-07-18 10:07:23 -0700119inline std::string getDumpPath(std::string_view dumpType)
120{
121 std::string dbusDumpPath = "/xyz/openbmc_project/dump/";
122 std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath),
123 bmcweb::asciiToLower);
124
125 return dbusDumpPath;
126}
127
Ed Tanous055713e2024-07-17 17:19:36 -0700128inline bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700129 const bool firstEntry = true)
Jason M. Bills95820182019-04-22 16:25:34 -0700130{
Ed Tanous271584a2019-07-09 16:24:22 -0700131 static time_t prevTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700132 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700133 if (firstEntry)
134 {
135 prevTs = 0;
136 }
137
Jason M. Bills95820182019-04-22 16:25:34 -0700138 // Get the entry timestamp
Ed Tanous271584a2019-07-09 16:24:22 -0700139 std::time_t curTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700140 std::tm timeStruct = {};
141 std::istringstream entryStream(logEntry);
142 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
143 {
144 curTs = std::mktime(&timeStruct);
145 }
146 // If the timestamp isn't unique, increment the index
147 if (curTs == prevTs)
148 {
149 index++;
150 }
151 else
152 {
153 // Otherwise, reset it
154 index = 0;
155 }
156 // Save the timestamp
157 prevTs = curTs;
158
159 entryID = std::to_string(curTs);
160 if (index > 0)
161 {
162 entryID += "_" + std::to_string(index);
163 }
164 return true;
165}
166
Jason M. Bills95820182019-04-22 16:25:34 -0700167static bool
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500168 getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
Jason M. Bills95820182019-04-22 16:25:34 -0700169{
170 static const std::filesystem::path redfishLogDir = "/var/log";
171 static const std::string redfishLogFilename = "redfish";
172
173 // Loop through the directory looking for redfish log files
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500174 for (const std::filesystem::directory_entry& dirEnt :
Jason M. Bills95820182019-04-22 16:25:34 -0700175 std::filesystem::directory_iterator(redfishLogDir))
176 {
177 // If we find a redfish log file, save the path
178 std::string filename = dirEnt.path().filename();
Ed Tanous11ba3972022-07-11 09:50:41 -0700179 if (filename.starts_with(redfishLogFilename))
Jason M. Bills95820182019-04-22 16:25:34 -0700180 {
181 redfishLogFiles.emplace_back(redfishLogDir / filename);
182 }
183 }
184 // As the log files rotate, they are appended with a ".#" that is higher for
185 // the older logs. Since we don't expect more than 10 log files, we
186 // can just sort the list to get them in order from newest to oldest
Ed Tanous3544d2a2023-08-06 18:12:20 -0700187 std::ranges::sort(redfishLogFiles);
Jason M. Bills95820182019-04-22 16:25:34 -0700188
189 return !redfishLogFiles.empty();
190}
191
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600192inline log_entry::OriginatorTypes
193 mapDbusOriginatorTypeToRedfish(const std::string& originatorType)
194{
195 if (originatorType ==
196 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client")
197 {
198 return log_entry::OriginatorTypes::Client;
199 }
200 if (originatorType ==
201 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal")
202 {
203 return log_entry::OriginatorTypes::Internal;
204 }
205 if (originatorType ==
206 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService")
207 {
208 return log_entry::OriginatorTypes::SupportingService;
209 }
210 return log_entry::OriginatorTypes::Invalid;
211}
212
Claire Weinanaefe3782022-07-15 19:17:19 -0700213inline void parseDumpEntryFromDbusObject(
Jiaqing Zhao2d613eb2022-08-15 16:03:00 +0800214 const dbus::utility::ManagedObjectType::value_type& object,
Claire Weinanc6fecda2022-07-15 10:43:25 -0700215 std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs,
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600216 std::string& originatorId, log_entry::OriginatorTypes& originatorType,
Claire Weinanaefe3782022-07-15 19:17:19 -0700217 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
218{
219 for (const auto& interfaceMap : object.second)
220 {
221 if (interfaceMap.first == "xyz.openbmc_project.Common.Progress")
222 {
223 for (const auto& propertyMap : interfaceMap.second)
224 {
225 if (propertyMap.first == "Status")
226 {
227 const auto* status =
228 std::get_if<std::string>(&propertyMap.second);
229 if (status == nullptr)
230 {
231 messages::internalError(asyncResp->res);
232 break;
233 }
234 dumpStatus = *status;
235 }
236 }
237 }
238 else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
239 {
240 for (const auto& propertyMap : interfaceMap.second)
241 {
242 if (propertyMap.first == "Size")
243 {
244 const auto* sizePtr =
245 std::get_if<uint64_t>(&propertyMap.second);
246 if (sizePtr == nullptr)
247 {
248 messages::internalError(asyncResp->res);
249 break;
250 }
251 size = *sizePtr;
252 break;
253 }
254 }
255 }
256 else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime")
257 {
258 for (const auto& propertyMap : interfaceMap.second)
259 {
260 if (propertyMap.first == "Elapsed")
261 {
262 const uint64_t* usecsTimeStamp =
263 std::get_if<uint64_t>(&propertyMap.second);
264 if (usecsTimeStamp == nullptr)
265 {
266 messages::internalError(asyncResp->res);
267 break;
268 }
Claire Weinanc6fecda2022-07-15 10:43:25 -0700269 timestampUs = *usecsTimeStamp;
Claire Weinanaefe3782022-07-15 19:17:19 -0700270 break;
271 }
272 }
273 }
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600274 else if (interfaceMap.first ==
275 "xyz.openbmc_project.Common.OriginatedBy")
276 {
277 for (const auto& propertyMap : interfaceMap.second)
278 {
279 if (propertyMap.first == "OriginatorId")
280 {
281 const std::string* id =
282 std::get_if<std::string>(&propertyMap.second);
283 if (id == nullptr)
284 {
285 messages::internalError(asyncResp->res);
286 break;
287 }
288 originatorId = *id;
289 }
290
291 if (propertyMap.first == "OriginatorType")
292 {
293 const std::string* type =
294 std::get_if<std::string>(&propertyMap.second);
295 if (type == nullptr)
296 {
297 messages::internalError(asyncResp->res);
298 break;
299 }
300
301 originatorType = mapDbusOriginatorTypeToRedfish(*type);
302 if (originatorType == log_entry::OriginatorTypes::Invalid)
303 {
304 messages::internalError(asyncResp->res);
305 break;
306 }
307 }
308 }
309 }
Claire Weinanaefe3782022-07-15 19:17:19 -0700310 }
311}
312
Nan Zhou21ab4042022-06-26 23:07:40 +0000313static std::string getDumpEntriesPath(const std::string& dumpType)
Claire Weinanfdd26902022-03-01 14:18:25 -0800314{
315 std::string entriesPath;
316
317 if (dumpType == "BMC")
318 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700319 entriesPath =
320 std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
321 BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800322 }
323 else if (dumpType == "FaultLog")
324 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700325 entriesPath =
326 std::format("/redfish/v1/Managers/{}/LogServices/FaultLog/Entries/",
327 BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800328 }
329 else if (dumpType == "System")
330 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700331 entriesPath =
332 std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
333 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800334 }
335 else
336 {
Ed Tanous62598e32023-07-17 17:06:25 -0700337 BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}",
338 dumpType);
Claire Weinanfdd26902022-03-01 14:18:25 -0800339 }
340
341 // Returns empty string on error
342 return entriesPath;
343}
344
zhanghch058d1b46d2021-04-01 11:18:24 +0800345inline void
346 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
347 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500348{
Claire Weinanfdd26902022-03-01 14:18:25 -0800349 std::string entriesPath = getDumpEntriesPath(dumpType);
350 if (entriesPath.empty())
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500351 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500352 messages::internalError(asyncResp->res);
353 return;
354 }
355
George Liu5eb468d2023-06-20 17:03:24 +0800356 sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
357 dbus::utility::getManagedObjects(
358 "xyz.openbmc_project.Dump.Manager", path,
Claire Weinanfdd26902022-03-01 14:18:25 -0800359 [asyncResp, entriesPath,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800360 dumpType](const boost::system::error_code& ec,
George Liu5eb468d2023-06-20 17:03:24 +0800361 const dbus::utility::ManagedObjectType& objects) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700362 if (ec)
363 {
Ed Tanous62598e32023-07-17 17:06:25 -0700364 BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700365 messages::internalError(asyncResp->res);
366 return;
367 }
368
Claire Weinanfdd26902022-03-01 14:18:25 -0800369 // Remove ending slash
370 std::string odataIdStr = entriesPath;
371 if (!odataIdStr.empty())
372 {
373 odataIdStr.pop_back();
374 }
375
376 asyncResp->res.jsonValue["@odata.type"] =
377 "#LogEntryCollection.LogEntryCollection";
378 asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr);
379 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries";
Patrick Williams89492a12023-05-10 07:51:34 -0500380 asyncResp->res.jsonValue["Description"] = "Collection of " + dumpType +
381 " Dump Entries";
Claire Weinanfdd26902022-03-01 14:18:25 -0800382
Ed Tanous3544d2a2023-08-06 18:12:20 -0700383 nlohmann::json::array_t entriesArray;
Ed Tanous18f8f602023-07-18 10:07:23 -0700384 std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
Ed Tanous002d39b2022-05-31 08:59:27 -0700385
George Liu5eb468d2023-06-20 17:03:24 +0800386 dbus::utility::ManagedObjectType resp(objects);
Ed Tanous3544d2a2023-08-06 18:12:20 -0700387 std::ranges::sort(resp, [](const auto& l, const auto& r) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700388 return AlphanumLess<std::string>()(l.first.filename(),
389 r.first.filename());
390 });
391
392 for (auto& object : resp)
393 {
394 if (object.first.str.find(dumpEntryPath) == std::string::npos)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500395 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700396 continue;
397 }
Claire Weinanc6fecda2022-07-15 10:43:25 -0700398 uint64_t timestampUs = 0;
Ed Tanous002d39b2022-05-31 08:59:27 -0700399 uint64_t size = 0;
400 std::string dumpStatus;
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600401 std::string originatorId;
402 log_entry::OriginatorTypes originatorType =
403 log_entry::OriginatorTypes::Internal;
Jason M. Bills433b68b2022-06-28 12:24:26 -0700404 nlohmann::json::object_t thisEntry;
Ed Tanous002d39b2022-05-31 08:59:27 -0700405
406 std::string entryID = object.first.filename();
407 if (entryID.empty())
408 {
409 continue;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500410 }
411
Claire Weinanc6fecda2022-07-15 10:43:25 -0700412 parseDumpEntryFromDbusObject(object, dumpStatus, size, timestampUs,
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600413 originatorId, originatorType,
Claire Weinanaefe3782022-07-15 19:17:19 -0700414 asyncResp);
Ed Tanous002d39b2022-05-31 08:59:27 -0700415
416 if (dumpStatus !=
417 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
418 !dumpStatus.empty())
419 {
420 // Dump status is not Complete, no need to enumerate
421 continue;
422 }
423
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600424 thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry";
Claire Weinanfdd26902022-03-01 14:18:25 -0800425 thisEntry["@odata.id"] = entriesPath + entryID;
Ed Tanous002d39b2022-05-31 08:59:27 -0700426 thisEntry["Id"] = entryID;
427 thisEntry["EntryType"] = "Event";
Ed Tanous002d39b2022-05-31 08:59:27 -0700428 thisEntry["Name"] = dumpType + " Dump Entry";
Claire Weinanbbd80db2022-10-26 16:55:52 -0700429 thisEntry["Created"] =
430 redfish::time_utils::getDateTimeUintUs(timestampUs);
Ed Tanous002d39b2022-05-31 08:59:27 -0700431
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600432 if (!originatorId.empty())
433 {
434 thisEntry["Originator"] = originatorId;
435 thisEntry["OriginatorType"] = originatorType;
436 }
437
Ed Tanous002d39b2022-05-31 08:59:27 -0700438 if (dumpType == "BMC")
439 {
440 thisEntry["DiagnosticDataType"] = "Manager";
Patrick Williams89492a12023-05-10 07:51:34 -0500441 thisEntry["AdditionalDataURI"] = entriesPath + entryID +
442 "/attachment";
Claire Weinanfdd26902022-03-01 14:18:25 -0800443 thisEntry["AdditionalDataSizeBytes"] = size;
Ed Tanous002d39b2022-05-31 08:59:27 -0700444 }
445 else if (dumpType == "System")
446 {
447 thisEntry["DiagnosticDataType"] = "OEM";
448 thisEntry["OEMDiagnosticDataType"] = "System";
Patrick Williams89492a12023-05-10 07:51:34 -0500449 thisEntry["AdditionalDataURI"] = entriesPath + entryID +
450 "/attachment";
Claire Weinanfdd26902022-03-01 14:18:25 -0800451 thisEntry["AdditionalDataSizeBytes"] = size;
Ed Tanous002d39b2022-05-31 08:59:27 -0700452 }
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500453 entriesArray.emplace_back(std::move(thisEntry));
Ed Tanous002d39b2022-05-31 08:59:27 -0700454 }
455 asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
Ed Tanous3544d2a2023-08-06 18:12:20 -0700456 asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
Patrick Williams5a39f772023-10-20 11:20:21 -0500457 });
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500458}
459
zhanghch058d1b46d2021-04-01 11:18:24 +0800460inline void
Claire Weinanc7a6d662022-06-13 16:36:39 -0700461 getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
zhanghch058d1b46d2021-04-01 11:18:24 +0800462 const std::string& entryID, const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500463{
Claire Weinanfdd26902022-03-01 14:18:25 -0800464 std::string entriesPath = getDumpEntriesPath(dumpType);
465 if (entriesPath.empty())
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500466 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500467 messages::internalError(asyncResp->res);
468 return;
469 }
470
George Liu5eb468d2023-06-20 17:03:24 +0800471 sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
472 dbus::utility::getManagedObjects(
473 "xyz.openbmc_project.Dump.Manager", path,
Claire Weinanfdd26902022-03-01 14:18:25 -0800474 [asyncResp, entryID, dumpType,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800475 entriesPath](const boost::system::error_code& ec,
Ed Tanous02cad962022-06-30 16:50:15 -0700476 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700477 if (ec)
478 {
Ed Tanous62598e32023-07-17 17:06:25 -0700479 BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700480 messages::internalError(asyncResp->res);
481 return;
482 }
483
484 bool foundDumpEntry = false;
Ed Tanous18f8f602023-07-18 10:07:23 -0700485 std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
Ed Tanous002d39b2022-05-31 08:59:27 -0700486
487 for (const auto& objectPath : resp)
488 {
489 if (objectPath.first.str != dumpEntryPath + entryID)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500490 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700491 continue;
492 }
493
494 foundDumpEntry = true;
Claire Weinanc6fecda2022-07-15 10:43:25 -0700495 uint64_t timestampUs = 0;
Ed Tanous002d39b2022-05-31 08:59:27 -0700496 uint64_t size = 0;
497 std::string dumpStatus;
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600498 std::string originatorId;
499 log_entry::OriginatorTypes originatorType =
500 log_entry::OriginatorTypes::Internal;
Ed Tanous002d39b2022-05-31 08:59:27 -0700501
Claire Weinanaefe3782022-07-15 19:17:19 -0700502 parseDumpEntryFromDbusObject(objectPath, dumpStatus, size,
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600503 timestampUs, originatorId,
504 originatorType, asyncResp);
Ed Tanous002d39b2022-05-31 08:59:27 -0700505
506 if (dumpStatus !=
507 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
508 !dumpStatus.empty())
509 {
510 // Dump status is not Complete
511 // return not found until status is changed to Completed
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200512 messages::resourceNotFound(asyncResp->res, dumpType + " dump",
513 entryID);
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500514 return;
515 }
516
Ed Tanous002d39b2022-05-31 08:59:27 -0700517 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600518 "#LogEntry.v1_11_0.LogEntry";
Claire Weinanfdd26902022-03-01 14:18:25 -0800519 asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID;
Ed Tanous002d39b2022-05-31 08:59:27 -0700520 asyncResp->res.jsonValue["Id"] = entryID;
521 asyncResp->res.jsonValue["EntryType"] = "Event";
Ed Tanous002d39b2022-05-31 08:59:27 -0700522 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
Claire Weinanbbd80db2022-10-26 16:55:52 -0700523 asyncResp->res.jsonValue["Created"] =
524 redfish::time_utils::getDateTimeUintUs(timestampUs);
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500525
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600526 if (!originatorId.empty())
527 {
528 asyncResp->res.jsonValue["Originator"] = originatorId;
529 asyncResp->res.jsonValue["OriginatorType"] = originatorType;
530 }
531
Ed Tanous002d39b2022-05-31 08:59:27 -0700532 if (dumpType == "BMC")
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500533 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700534 asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
535 asyncResp->res.jsonValue["AdditionalDataURI"] =
Claire Weinanfdd26902022-03-01 14:18:25 -0800536 entriesPath + entryID + "/attachment";
537 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500538 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700539 else if (dumpType == "System")
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500540 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700541 asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
542 asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System";
543 asyncResp->res.jsonValue["AdditionalDataURI"] =
Claire Weinanfdd26902022-03-01 14:18:25 -0800544 entriesPath + entryID + "/attachment";
545 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500546 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700547 }
548 if (!foundDumpEntry)
549 {
Ed Tanous62598e32023-07-17 17:06:25 -0700550 BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
Myung Baeb90d14f2023-05-31 14:40:39 -0500551 messages::resourceNotFound(asyncResp->res, dumpType + " dump",
552 entryID);
Ed Tanous002d39b2022-05-31 08:59:27 -0700553 return;
554 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500555 });
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500556}
557
zhanghch058d1b46d2021-04-01 11:18:24 +0800558inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Stanley Chu98782562020-11-04 16:10:24 +0800559 const std::string& entryID,
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500560 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500561{
Patrick Williams5a39f772023-10-20 11:20:21 -0500562 auto respHandler = [asyncResp,
563 entryID](const boost::system::error_code& ec) {
Ed Tanous62598e32023-07-17 17:06:25 -0700564 BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done");
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500565 if (ec)
566 {
George Liu3de8d8b2021-03-22 17:49:39 +0800567 if (ec.value() == EBADR)
568 {
569 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
570 return;
571 }
Ed Tanous62598e32023-07-17 17:06:25 -0700572 BMCWEB_LOG_ERROR(
573 "Dump (DBus) doDelete respHandler got error {} entryID={}", ec,
574 entryID);
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500575 messages::internalError(asyncResp->res);
576 return;
577 }
578 };
Ed Tanous18f8f602023-07-18 10:07:23 -0700579
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500580 crow::connections::systemBus->async_method_call(
581 respHandler, "xyz.openbmc_project.Dump.Manager",
Ed Tanous18f8f602023-07-18 10:07:23 -0700582 std::format("{}/entry/{}", getDumpPath(dumpType), entryID),
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500583 "xyz.openbmc_project.Object.Delete", "Delete");
584}
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600585inline bool checkSizeLimit(int fd, crow::Response& res)
586{
587 long long int size = lseek(fd, 0, SEEK_END);
588 if (size <= 0)
589 {
590 BMCWEB_LOG_ERROR("Failed to get size of file, lseek() returned {}",
591 size);
592 messages::internalError(res);
593 return false;
594 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500595
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600596 // Arbitrary max size of 20MB to accommodate BMC dumps
597 constexpr long long int maxFileSize = 20LL * 1024LL * 1024LL;
598 if (size > maxFileSize)
599 {
600 BMCWEB_LOG_ERROR("File size {} exceeds maximum allowed size of {}",
601 size, maxFileSize);
602 messages::internalError(res);
603 return false;
604 }
605 off_t rc = lseek(fd, 0, SEEK_SET);
606 if (rc < 0)
607 {
608 BMCWEB_LOG_ERROR("Failed to reset file offset to 0");
609 messages::internalError(res);
610 return false;
611 }
612 return true;
613}
Carson Labrado168d1b12023-03-27 17:04:46 +0000614inline void
615 downloadEntryCallback(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
616 const std::string& entryID,
617 const std::string& downloadEntryType,
618 const boost::system::error_code& ec,
619 const sdbusplus::message::unix_fd& unixfd)
620{
621 if (ec.value() == EBADR)
622 {
623 messages::resourceNotFound(asyncResp->res, "EntryAttachment", entryID);
624 return;
625 }
626 if (ec)
627 {
628 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
629 messages::internalError(asyncResp->res);
630 return;
631 }
632
633 // Make sure we know how to process the retrieved entry attachment
634 if ((downloadEntryType != "BMC") && (downloadEntryType != "System"))
635 {
636 BMCWEB_LOG_ERROR("downloadEntryCallback() invalid entry type: {}",
637 downloadEntryType);
638 messages::internalError(asyncResp->res);
639 }
640
641 int fd = -1;
642 fd = dup(unixfd);
643 if (fd < 0)
644 {
645 BMCWEB_LOG_ERROR("Failed to open file");
646 messages::internalError(asyncResp->res);
647 return;
648 }
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600649 if (!checkSizeLimit(fd, asyncResp->res))
Carson Labrado168d1b12023-03-27 17:04:46 +0000650 {
Carson Labrado168d1b12023-03-27 17:04:46 +0000651 close(fd);
652 return;
653 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000654 if (downloadEntryType == "System")
655 {
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600656 if (!asyncResp->res.openFd(fd, bmcweb::EncodingType::Base64))
657 {
658 messages::internalError(asyncResp->res);
659 close(fd);
660 return;
661 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000662 asyncResp->res.addHeader(
663 boost::beast::http::field::content_transfer_encoding, "Base64");
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600664 return;
Carson Labrado168d1b12023-03-27 17:04:46 +0000665 }
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600666 if (!asyncResp->res.openFd(fd))
Ed Tanous27b0cf92023-08-07 12:02:40 -0700667 {
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600668 messages::internalError(asyncResp->res);
669 close(fd);
670 return;
Ed Tanous27b0cf92023-08-07 12:02:40 -0700671 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000672 asyncResp->res.addHeader(boost::beast::http::field::content_type,
673 "application/octet-stream");
674}
675
676inline void
677 downloadDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
678 const std::string& entryID, const std::string& dumpType)
679{
680 if (dumpType != "BMC")
681 {
682 BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
683 messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID);
684 return;
685 }
686
Ed Tanous18f8f602023-07-18 10:07:23 -0700687 std::string dumpEntryPath = std::format("{}/entry/{}",
688 getDumpPath(dumpType), entryID);
Carson Labrado168d1b12023-03-27 17:04:46 +0000689
690 auto downloadDumpEntryHandler =
691 [asyncResp, entryID,
692 dumpType](const boost::system::error_code& ec,
693 const sdbusplus::message::unix_fd& unixfd) {
694 downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
695 };
696
697 crow::connections::systemBus->async_method_call(
698 std::move(downloadDumpEntryHandler), "xyz.openbmc_project.Dump.Manager",
699 dumpEntryPath, "xyz.openbmc_project.Dump.Entry", "GetFileHandle");
700}
701
702inline void
703 downloadEventLogEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
704 const std::string& systemName,
705 const std::string& entryID,
706 const std::string& dumpType)
707{
Ed Tanous25b54db2024-04-17 15:40:31 -0700708 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Carson Labrado168d1b12023-03-27 17:04:46 +0000709 {
710 // Option currently returns no systems. TBD
711 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
712 systemName);
713 return;
714 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700715 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Carson Labrado168d1b12023-03-27 17:04:46 +0000716 {
717 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
718 systemName);
719 return;
720 }
721
722 std::string entryPath =
723 sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") /
724 entryID;
725
726 auto downloadEventLogEntryHandler =
727 [asyncResp, entryID,
728 dumpType](const boost::system::error_code& ec,
729 const sdbusplus::message::unix_fd& unixfd) {
730 downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
731 };
732
733 crow::connections::systemBus->async_method_call(
734 std::move(downloadEventLogEntryHandler), "xyz.openbmc_project.Logging",
735 entryPath, "xyz.openbmc_project.Logging.Entry", "GetEntry");
736}
737
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600738inline DumpCreationProgress
739 mapDbusStatusToDumpProgress(const std::string& status)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500740{
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600741 if (status ==
742 "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" ||
743 status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted")
744 {
745 return DumpCreationProgress::DUMP_CREATE_FAILED;
746 }
747 if (status ==
748 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed")
749 {
750 return DumpCreationProgress::DUMP_CREATE_SUCCESS;
751 }
752 return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
753}
754
755inline DumpCreationProgress
756 getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values)
757{
758 for (const auto& [key, val] : values)
759 {
760 if (key == "Status")
Ed Tanous002d39b2022-05-31 08:59:27 -0700761 {
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600762 const std::string* value = std::get_if<std::string>(&val);
763 if (value == nullptr)
764 {
Ed Tanous62598e32023-07-17 17:06:25 -0700765 BMCWEB_LOG_ERROR("Status property value is null");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600766 return DumpCreationProgress::DUMP_CREATE_FAILED;
767 }
768 return mapDbusStatusToDumpProgress(*value);
769 }
770 }
771 return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
772}
773
774inline std::string getDumpEntryPath(const std::string& dumpPath)
775{
776 if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry")
777 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700778 return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
Ed Tanous9f565092024-07-12 22:06:53 -0700779 BMCWEB_REDFISH_MANAGER_URI_NAME);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600780 }
781 if (dumpPath == "/xyz/openbmc_project/dump/system/entry")
782 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700783 return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
784 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600785 }
786 return "";
787}
788
789inline void createDumpTaskCallback(
790 task::Payload&& payload,
791 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
792 const sdbusplus::message::object_path& createdObjPath)
793{
794 const std::string dumpPath = createdObjPath.parent_path().str;
795 const std::string dumpId = createdObjPath.filename();
796
797 std::string dumpEntryPath = getDumpEntryPath(dumpPath);
798
799 if (dumpEntryPath.empty())
800 {
Ed Tanous62598e32023-07-17 17:06:25 -0700801 BMCWEB_LOG_ERROR("Invalid dump type received");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600802 messages::internalError(asyncResp->res);
803 return;
804 }
805
806 crow::connections::systemBus->async_method_call(
Ed Tanous8cb2c022024-03-27 16:31:46 -0700807 [asyncResp, payload = std::move(payload), createdObjPath,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600808 dumpEntryPath{std::move(dumpEntryPath)},
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800809 dumpId](const boost::system::error_code& ec,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600810 const std::string& introspectXml) {
811 if (ec)
812 {
Ed Tanous62598e32023-07-17 17:06:25 -0700813 BMCWEB_LOG_ERROR("Introspect call failed with error: {}",
814 ec.message());
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600815 messages::internalError(asyncResp->res);
816 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700817 }
818
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600819 // Check if the created dump object has implemented Progress
820 // interface to track dump completion. If yes, fetch the "Status"
821 // property of the interface, modify the task state accordingly.
822 // Else, return task completed.
823 tinyxml2::XMLDocument doc;
Ed Tanous002d39b2022-05-31 08:59:27 -0700824
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600825 doc.Parse(introspectXml.data(), introspectXml.size());
826 tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
827 if (pRoot == nullptr)
Ed Tanous002d39b2022-05-31 08:59:27 -0700828 {
Ed Tanous62598e32023-07-17 17:06:25 -0700829 BMCWEB_LOG_ERROR("XML document failed to parse");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600830 messages::internalError(asyncResp->res);
831 return;
832 }
833 tinyxml2::XMLElement* interfaceNode =
834 pRoot->FirstChildElement("interface");
835
836 bool isProgressIntfPresent = false;
837 while (interfaceNode != nullptr)
838 {
839 const char* thisInterfaceName = interfaceNode->Attribute("name");
840 if (thisInterfaceName != nullptr)
841 {
842 if (thisInterfaceName ==
843 std::string_view("xyz.openbmc_project.Common.Progress"))
844 {
845 interfaceNode =
846 interfaceNode->NextSiblingElement("interface");
847 continue;
848 }
849 isProgressIntfPresent = true;
850 break;
851 }
852 interfaceNode = interfaceNode->NextSiblingElement("interface");
853 }
854
855 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
856 [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent](
Ed Tanous8b242752023-06-27 17:17:13 -0700857 const boost::system::error_code& ec2, sdbusplus::message_t& msg,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600858 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanous8b242752023-06-27 17:17:13 -0700859 if (ec2)
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600860 {
Ed Tanous62598e32023-07-17 17:06:25 -0700861 BMCWEB_LOG_ERROR("{}: Error in creating dump",
862 createdObjPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600863 taskData->messages.emplace_back(messages::internalError());
864 taskData->state = "Cancelled";
865 return task::completed;
866 }
867
868 if (isProgressIntfPresent)
869 {
870 dbus::utility::DBusPropertiesMap values;
871 std::string prop;
872 msg.read(prop, values);
873
874 DumpCreationProgress dumpStatus =
875 getDumpCompletionStatus(values);
876 if (dumpStatus == DumpCreationProgress::DUMP_CREATE_FAILED)
877 {
Ed Tanous62598e32023-07-17 17:06:25 -0700878 BMCWEB_LOG_ERROR("{}: Error in creating dump",
879 createdObjPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600880 taskData->state = "Cancelled";
881 return task::completed;
882 }
883
884 if (dumpStatus == DumpCreationProgress::DUMP_CREATE_INPROGRESS)
885 {
Ed Tanous62598e32023-07-17 17:06:25 -0700886 BMCWEB_LOG_DEBUG("{}: Dump creation task is in progress",
887 createdObjPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600888 return !task::completed;
889 }
890 }
891
Ed Tanous002d39b2022-05-31 08:59:27 -0700892 nlohmann::json retMessage = messages::success();
893 taskData->messages.emplace_back(retMessage);
894
Ed Tanousc51a58e2023-03-27 14:43:19 -0700895 boost::urls::url url = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -0700896 "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}",
897 BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId);
Ed Tanousc51a58e2023-03-27 14:43:19 -0700898
899 std::string headerLoc = "Location: ";
900 headerLoc += url.buffer();
901
Ed Tanous002d39b2022-05-31 08:59:27 -0700902 taskData->payload->httpHeaders.emplace_back(std::move(headerLoc));
903
Ed Tanous62598e32023-07-17 17:06:25 -0700904 BMCWEB_LOG_DEBUG("{}: Dump creation task completed",
905 createdObjPath.str);
Ed Tanous002d39b2022-05-31 08:59:27 -0700906 taskData->state = "Completed";
907 return task::completed;
Patrick Williams5a39f772023-10-20 11:20:21 -0500908 },
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600909 "type='signal',interface='org.freedesktop.DBus.Properties',"
910 "member='PropertiesChanged',path='" +
911 createdObjPath.str + "'");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500912
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600913 // The task timer is set to max time limit within which the
914 // requested dump will be collected.
915 task->startTimer(std::chrono::minutes(6));
916 task->populateResp(asyncResp->res);
917 task->payload.emplace(payload);
Patrick Williams5a39f772023-10-20 11:20:21 -0500918 },
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600919 "xyz.openbmc_project.Dump.Manager", createdObjPath,
920 "org.freedesktop.DBus.Introspectable", "Introspect");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500921}
922
zhanghch058d1b46d2021-04-01 11:18:24 +0800923inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
924 const crow::Request& req, const std::string& dumpType)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500925{
Claire Weinanfdd26902022-03-01 14:18:25 -0800926 std::string dumpPath = getDumpEntriesPath(dumpType);
927 if (dumpPath.empty())
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500928 {
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500929 messages::internalError(asyncResp->res);
930 return;
931 }
932
933 std::optional<std::string> diagnosticDataType;
934 std::optional<std::string> oemDiagnosticDataType;
935
Willy Tu15ed6782021-12-14 11:03:16 -0800936 if (!redfish::json_util::readJsonAction(
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500937 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
938 "OEMDiagnosticDataType", oemDiagnosticDataType))
939 {
940 return;
941 }
942
943 if (dumpType == "System")
944 {
945 if (!oemDiagnosticDataType || !diagnosticDataType)
946 {
Ed Tanous62598e32023-07-17 17:06:25 -0700947 BMCWEB_LOG_ERROR(
948 "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500949 messages::actionParameterMissing(
950 asyncResp->res, "CollectDiagnosticData",
951 "DiagnosticDataType & OEMDiagnosticDataType");
952 return;
953 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700954 if ((*oemDiagnosticDataType != "System") ||
955 (*diagnosticDataType != "OEM"))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500956 {
Ed Tanous62598e32023-07-17 17:06:25 -0700957 BMCWEB_LOG_ERROR("Wrong parameter values passed");
Ed Tanousace85d62021-10-26 12:45:59 -0700958 messages::internalError(asyncResp->res);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500959 return;
960 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700961 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/",
962 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500963 }
964 else if (dumpType == "BMC")
965 {
966 if (!diagnosticDataType)
967 {
Ed Tanous62598e32023-07-17 17:06:25 -0700968 BMCWEB_LOG_ERROR(
969 "CreateDump action parameter 'DiagnosticDataType' not found!");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500970 messages::actionParameterMissing(
971 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
972 return;
973 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700974 if (*diagnosticDataType != "Manager")
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500975 {
Ed Tanous62598e32023-07-17 17:06:25 -0700976 BMCWEB_LOG_ERROR(
977 "Wrong parameter value passed for 'DiagnosticDataType'");
Ed Tanousace85d62021-10-26 12:45:59 -0700978 messages::internalError(asyncResp->res);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500979 return;
980 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700981 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/",
982 BMCWEB_REDFISH_MANAGER_URI_NAME);
Asmitha Karunanithi59075712021-10-22 01:17:41 -0500983 }
984 else
985 {
Ed Tanous62598e32023-07-17 17:06:25 -0700986 BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type");
Asmitha Karunanithi59075712021-10-22 01:17:41 -0500987 messages::internalError(asyncResp->res);
988 return;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500989 }
990
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600991 std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>>
992 createDumpParamVec;
993
Carson Labradof574a8e2023-03-22 02:26:00 +0000994 if (req.session != nullptr)
995 {
996 createDumpParamVec.emplace_back(
997 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId",
998 req.session->clientIp);
999 createDumpParamVec.emplace_back(
1000 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType",
1001 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client");
1002 }
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -06001003
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001004 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001005 [asyncResp, payload(task::Payload(req)),
1006 dumpPath](const boost::system::error_code& ec,
1007 const sdbusplus::message_t& msg,
1008 const sdbusplus::message::object_path& objPath) mutable {
Ed Tanous002d39b2022-05-31 08:59:27 -07001009 if (ec)
1010 {
Ed Tanous62598e32023-07-17 17:06:25 -07001011 BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec);
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001012 const sd_bus_error* dbusError = msg.get_error();
1013 if (dbusError == nullptr)
1014 {
1015 messages::internalError(asyncResp->res);
1016 return;
1017 }
1018
Ed Tanous62598e32023-07-17 17:06:25 -07001019 BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}",
1020 dbusError->name, dbusError->message);
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001021 if (std::string_view(
1022 "xyz.openbmc_project.Common.Error.NotAllowed") ==
1023 dbusError->name)
1024 {
1025 messages::resourceInStandby(asyncResp->res);
1026 return;
1027 }
1028 if (std::string_view(
1029 "xyz.openbmc_project.Dump.Create.Error.Disabled") ==
1030 dbusError->name)
1031 {
1032 messages::serviceDisabled(asyncResp->res, dumpPath);
1033 return;
1034 }
1035 if (std::string_view(
1036 "xyz.openbmc_project.Common.Error.Unavailable") ==
1037 dbusError->name)
1038 {
1039 messages::resourceInUse(asyncResp->res);
1040 return;
1041 }
1042 // Other Dbus errors such as:
1043 // xyz.openbmc_project.Common.Error.InvalidArgument &
1044 // org.freedesktop.DBus.Error.InvalidArgs are all related to
1045 // the dbus call that is made here in the bmcweb
1046 // implementation and has nothing to do with the client's
1047 // input in the request. Hence, returning internal error
1048 // back to the client.
Ed Tanous002d39b2022-05-31 08:59:27 -07001049 messages::internalError(asyncResp->res);
1050 return;
1051 }
Ed Tanous62598e32023-07-17 17:06:25 -07001052 BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -06001053 createDumpTaskCallback(std::move(payload), asyncResp, objPath);
Patrick Williams5a39f772023-10-20 11:20:21 -05001054 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001055 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Asmitha Karunanithi8e317782020-12-10 03:35:05 -06001056 "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec);
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001057}
1058
zhanghch058d1b46d2021-04-01 11:18:24 +08001059inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1060 const std::string& dumpType)
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001061{
Claire Weinan0d946212022-07-13 19:40:19 -07001062 crow::connections::systemBus->async_method_call(
1063 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001064 if (ec)
1065 {
Ed Tanous62598e32023-07-17 17:06:25 -07001066 BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001067 messages::internalError(asyncResp->res);
1068 return;
1069 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001070 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001071 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Claire Weinan0d946212022-07-13 19:40:19 -07001072 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001073}
1074
Ed Tanousdf254f22024-04-01 13:25:46 -07001075inline void
Ed Tanousb9d36b42022-02-26 21:42:46 -08001076 parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params,
1077 std::string& filename, std::string& timestamp,
1078 std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001079{
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001080 const std::string* filenamePtr = nullptr;
1081 const std::string* timestampPtr = nullptr;
1082 const std::string* logfilePtr = nullptr;
1083
1084 const bool success = sdbusplus::unpackPropertiesNoThrow(
1085 dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr,
1086 "Filename", filenamePtr, "Log", logfilePtr);
1087
1088 if (!success)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001089 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001090 return;
1091 }
1092
1093 if (filenamePtr != nullptr)
1094 {
1095 filename = *filenamePtr;
1096 }
1097
1098 if (timestampPtr != nullptr)
1099 {
1100 timestamp = *timestampPtr;
1101 }
1102
1103 if (logfilePtr != nullptr)
1104 {
1105 logfile = *logfilePtr;
Johnathan Mantey043a0532020-03-10 17:15:28 -07001106 }
1107}
1108
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001109inline void requestRoutesSystemLogServiceCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07001110{
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001111 /**
1112 * Functions triggers appropriate requests on DBus
1113 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001114 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
Ed Tanoused398212021-06-09 17:05:54 -07001115 .privileges(redfish::privileges::getLogServiceCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001116 .methods(boost::beast::http::verb::get)(
1117 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001118 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1119 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001120 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001121 {
1122 return;
1123 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001124 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001125 {
1126 // Option currently returns no systems. TBD
1127 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1128 systemName);
1129 return;
1130 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001131 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001132 {
1133 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1134 systemName);
1135 return;
1136 }
1137
Ed Tanous002d39b2022-05-31 08:59:27 -07001138 // Collections don't include the static data added by SubRoute
1139 // because it has a duplicate entry for members
1140 asyncResp->res.jsonValue["@odata.type"] =
1141 "#LogServiceCollection.LogServiceCollection";
1142 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001143 std::format("/redfish/v1/Systems/{}/LogServices",
1144 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07001145 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
1146 asyncResp->res.jsonValue["Description"] =
1147 "Collection of LogServices for this Computer System";
1148 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1149 logServiceArray = nlohmann::json::array();
1150 nlohmann::json::object_t eventLog;
1151 eventLog["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001152 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1153 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001154 logServiceArray.emplace_back(std::move(eventLog));
Ed Tanous25b54db2024-04-17 15:40:31 -07001155 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
1156 {
1157 nlohmann::json::object_t dumpLog;
1158 dumpLog["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001159 std::format("/redfish/v1/Systems/{}/LogServices/Dump",
1160 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001161 logServiceArray.emplace_back(std::move(dumpLog));
1162 }
raviteja-bc9bb6862020-02-03 11:53:32 -06001163
Gunnar Mills5ffd11f2024-05-02 08:26:12 -05001164 if constexpr (BMCWEB_REDFISH_CPU_LOG)
Ed Tanous25b54db2024-04-17 15:40:31 -07001165 {
1166 nlohmann::json::object_t crashdump;
1167 crashdump["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001168 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
1169 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001170 logServiceArray.emplace_back(std::move(crashdump));
1171 }
Spencer Kub7028eb2021-10-26 15:27:35 +08001172
Ed Tanous25b54db2024-04-17 15:40:31 -07001173 if constexpr (BMCWEB_REDFISH_HOST_LOGGER)
1174 {
1175 nlohmann::json::object_t hostlogger;
1176 hostlogger["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001177 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
1178 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001179 logServiceArray.emplace_back(std::move(hostlogger));
1180 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001181 asyncResp->res.jsonValue["Members@odata.count"] =
1182 logServiceArray.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -08001183
George Liu7a1dbc42022-12-07 16:03:22 +08001184 constexpr std::array<std::string_view, 1> interfaces = {
1185 "xyz.openbmc_project.State.Boot.PostCode"};
1186 dbus::utility::getSubTreePaths(
1187 "/", 0, interfaces,
1188 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001189 const dbus::utility::MapperGetSubTreePathsResponse&
1190 subtreePath) {
1191 if (ec)
1192 {
Ed Tanous62598e32023-07-17 17:06:25 -07001193 BMCWEB_LOG_ERROR("{}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001194 return;
1195 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001196
Ed Tanous002d39b2022-05-31 08:59:27 -07001197 for (const auto& pathStr : subtreePath)
1198 {
1199 if (pathStr.find("PostCode") != std::string::npos)
1200 {
1201 nlohmann::json& logServiceArrayLocal =
1202 asyncResp->res.jsonValue["Members"];
Ed Tanous613dabe2022-07-09 11:17:36 -07001203 nlohmann::json::object_t member;
Ed Tanous253f11b2024-05-16 09:38:31 -07001204 member["@odata.id"] = std::format(
1205 "/redfish/v1/Systems/{}/LogServices/PostCodes",
1206 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous613dabe2022-07-09 11:17:36 -07001207
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001208 logServiceArrayLocal.emplace_back(std::move(member));
Ed Tanous613dabe2022-07-09 11:17:36 -07001209
Ed Tanous002d39b2022-05-31 08:59:27 -07001210 asyncResp->res.jsonValue["Members@odata.count"] =
1211 logServiceArrayLocal.size();
1212 return;
1213 }
1214 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001215 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001216 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001217}
1218
1219inline void requestRoutesEventLogService(App& app)
1220{
Ed Tanous22d268c2022-05-19 09:39:07 -07001221 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/")
Ed Tanoused398212021-06-09 17:05:54 -07001222 .privileges(redfish::privileges::getLogService)
Ed Tanous002d39b2022-05-31 08:59:27 -07001223 .methods(boost::beast::http::verb::get)(
1224 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001225 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1226 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001227 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001228 {
1229 return;
1230 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001231 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001232 {
1233 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1234 systemName);
1235 return;
1236 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001237 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001238 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1239 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07001240 asyncResp->res.jsonValue["@odata.type"] =
Janet Adkinsb25644a2023-08-16 11:23:45 -05001241 "#LogService.v1_2_0.LogService";
Ed Tanous002d39b2022-05-31 08:59:27 -07001242 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1243 asyncResp->res.jsonValue["Description"] = "System Event Log Service";
1244 asyncResp->res.jsonValue["Id"] = "EventLog";
Ed Tanous539d8c62024-06-19 14:38:27 -07001245 asyncResp->res.jsonValue["OverWritePolicy"] =
1246 log_service::OverWritePolicy::WrapsWhenFull;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301247
Ed Tanous002d39b2022-05-31 08:59:27 -07001248 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07001249 redfish::time_utils::getDateTimeOffsetNow();
Tejas Patil7c8c4052021-06-04 17:43:14 +05301250
Ed Tanous002d39b2022-05-31 08:59:27 -07001251 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
1252 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
1253 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301254
Ed Tanous002d39b2022-05-31 08:59:27 -07001255 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001256 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1257 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous20fa6a22024-05-20 18:02:58 -07001258 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"]
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001259
Ed Tanous20fa6a22024-05-20 18:02:58 -07001260 = std::format(
1261 "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog",
1262 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05001263 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001264}
1265
1266inline void requestRoutesJournalEventLogClear(App& app)
1267{
Jason M. Bills4978b632022-02-22 14:17:43 -08001268 BMCWEB_ROUTE(
1269 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07001270 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Ed Tanous432a8902021-06-14 15:28:56 -07001271 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001272 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001273 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001274 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1275 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001276 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001277 {
1278 return;
1279 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001280 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001281 {
1282 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1283 systemName);
1284 return;
1285 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001286 // Clear the EventLog by deleting the log files
1287 std::vector<std::filesystem::path> redfishLogFiles;
1288 if (getRedfishLogFiles(redfishLogFiles))
1289 {
1290 for (const std::filesystem::path& file : redfishLogFiles)
1291 {
1292 std::error_code ec;
1293 std::filesystem::remove(file, ec);
1294 }
1295 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001296
Ed Tanous002d39b2022-05-31 08:59:27 -07001297 // Reload rsyslog so it knows to start new log files
1298 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001299 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001300 if (ec)
1301 {
Ed Tanous62598e32023-07-17 17:06:25 -07001302 BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001303 messages::internalError(asyncResp->res);
1304 return;
1305 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001306
Ed Tanous002d39b2022-05-31 08:59:27 -07001307 messages::success(asyncResp->res);
Patrick Williams5a39f772023-10-20 11:20:21 -05001308 },
Ed Tanous002d39b2022-05-31 08:59:27 -07001309 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1310 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1311 "replace");
Patrick Williams5a39f772023-10-20 11:20:21 -05001312 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001313}
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001314
Jason M. Billsac992cd2022-06-24 13:31:46 -07001315enum class LogParseError
1316{
1317 success,
1318 parseFailed,
1319 messageIdNotInRegistry,
1320};
1321
1322static LogParseError
1323 fillEventLogEntryJson(const std::string& logEntryID,
1324 const std::string& logEntry,
1325 nlohmann::json::object_t& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001326{
Jason M. Bills95820182019-04-22 16:25:34 -07001327 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001328 // First get the Timestamp
Ed Tanousf23b7292020-10-15 09:41:17 -07001329 size_t space = logEntry.find_first_of(' ');
Jason M. Billscd225da2019-05-08 15:31:57 -07001330 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001331 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001332 return LogParseError::parseFailed;
Jason M. Bills95820182019-04-22 16:25:34 -07001333 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001334 std::string timestamp = logEntry.substr(0, space);
1335 // Then get the log contents
Ed Tanousf23b7292020-10-15 09:41:17 -07001336 size_t entryStart = logEntry.find_first_not_of(' ', space);
Jason M. Billscd225da2019-05-08 15:31:57 -07001337 if (entryStart == std::string::npos)
1338 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001339 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001340 }
1341 std::string_view entry(logEntry);
1342 entry.remove_prefix(entryStart);
1343 // Use split to separate the entry into its fields
1344 std::vector<std::string> logEntryFields;
Ed Tanous50ebd4a2023-01-19 19:03:17 -08001345 bmcweb::split(logEntryFields, entry, ',');
Jason M. Billscd225da2019-05-08 15:31:57 -07001346 // We need at least a MessageId to be valid
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001347 auto logEntryIter = logEntryFields.begin();
1348 if (logEntryIter == logEntryFields.end())
Jason M. Billscd225da2019-05-08 15:31:57 -07001349 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001350 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001351 }
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001352 std::string& messageID = *logEntryIter;
Jason M. Bills4851d452019-03-28 11:27:48 -07001353 // Get the Message from the MessageRegistry
Ed Tanousfffb8c12022-02-07 23:53:03 -08001354 const registries::Message* message = registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001355
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001356 logEntryIter++;
Sui Chen54417b02022-03-24 14:59:52 -07001357 if (message == nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001358 {
Ed Tanous62598e32023-07-17 17:06:25 -07001359 BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001360 return LogParseError::messageIdNotInRegistry;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001361 }
1362
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001363 std::vector<std::string_view> messageArgs(logEntryIter,
1364 logEntryFields.end());
Ed Tanousc05bba42023-06-28 08:33:29 -07001365 messageArgs.resize(message->numberOfArgs);
1366
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001367 std::string msg = redfish::registries::fillMessageArgs(messageArgs,
1368 message->message);
1369 if (msg.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001370 {
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001371 return LogParseError::parseFailed;
Jason M. Bills4851d452019-03-28 11:27:48 -07001372 }
1373
Jason M. Bills95820182019-04-22 16:25:34 -07001374 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1375 // format which matches the Redfish format except for the fractional seconds
1376 // between the '.' and the '+', so just remove them.
Ed Tanousf23b7292020-10-15 09:41:17 -07001377 std::size_t dot = timestamp.find_first_of('.');
1378 std::size_t plus = timestamp.find_first_of('+');
Jason M. Bills95820182019-04-22 16:25:34 -07001379 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001380 {
Jason M. Bills95820182019-04-22 16:25:34 -07001381 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001382 }
1383
1384 // Fill in the log entry with the gathered data
Vijay Lobo9c11a172021-10-07 16:53:16 -05001385 logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001386 logEntryJson["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001387 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1388 BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
Jason M. Bills84afc482022-06-24 12:38:23 -07001389 logEntryJson["Name"] = "System Event Log Entry";
1390 logEntryJson["Id"] = logEntryID;
1391 logEntryJson["Message"] = std::move(msg);
1392 logEntryJson["MessageId"] = std::move(messageID);
1393 logEntryJson["MessageArgs"] = messageArgs;
1394 logEntryJson["EntryType"] = "Event";
1395 logEntryJson["Severity"] = message->messageSeverity;
1396 logEntryJson["Created"] = std::move(timestamp);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001397 return LogParseError::success;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001398}
1399
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001400inline void requestRoutesJournalEventLogEntryCollection(App& app)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001401{
Ed Tanous22d268c2022-05-19 09:39:07 -07001402 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
Gunnar Mills8b6a35f2021-07-30 14:52:53 -05001403 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001404 .methods(boost::beast::http::verb::get)(
1405 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001406 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1407 const std::string& systemName) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001408 query_param::QueryCapabilities capabilities = {
1409 .canDelegateTop = true,
1410 .canDelegateSkip = true,
1411 };
1412 query_param::Query delegatedQuery;
1413 if (!redfish::setUpRedfishRouteWithDelegation(
Carson Labrado3ba00072022-06-06 19:40:56 +00001414 app, req, asyncResp, delegatedQuery, capabilities))
Ed Tanous002d39b2022-05-31 08:59:27 -07001415 {
1416 return;
1417 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001418 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001419 {
1420 // Option currently returns no systems. TBD
1421 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1422 systemName);
1423 return;
1424 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001425 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001426 {
1427 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1428 systemName);
1429 return;
1430 }
1431
Jiaqing Zhao5143f7a2022-07-22 09:33:33 +08001432 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
Ed Tanous3648c8b2022-07-25 13:39:59 -07001433 size_t skip = delegatedQuery.skip.value_or(0);
1434
Ed Tanous002d39b2022-05-31 08:59:27 -07001435 // Collections don't include the static data added by SubRoute
1436 // because it has a duplicate entry for members
1437 asyncResp->res.jsonValue["@odata.type"] =
1438 "#LogEntryCollection.LogEntryCollection";
1439 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001440 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1441 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07001442 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1443 asyncResp->res.jsonValue["Description"] =
1444 "Collection of System Event Log Entries";
1445
1446 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1447 logEntryArray = nlohmann::json::array();
1448 // Go through the log files and create a unique ID for each
1449 // entry
1450 std::vector<std::filesystem::path> redfishLogFiles;
1451 getRedfishLogFiles(redfishLogFiles);
1452 uint64_t entryCount = 0;
1453 std::string logEntry;
1454
1455 // Oldest logs are in the last file, so start there and loop
1456 // backwards
1457 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1458 it++)
1459 {
1460 std::ifstream logStream(*it);
1461 if (!logStream.is_open())
Jason M. Bills4978b632022-02-22 14:17:43 -08001462 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001463 continue;
Jason M. Bills4978b632022-02-22 14:17:43 -08001464 }
Jason M. Bills897967d2019-07-29 17:05:30 -07001465
Ed Tanous002d39b2022-05-31 08:59:27 -07001466 // Reset the unique ID on the first entry
1467 bool firstEntry = true;
1468 while (std::getline(logStream, logEntry))
Jason M. Bills4978b632022-02-22 14:17:43 -08001469 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001470 std::string idStr;
1471 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
Jason M. Bills4978b632022-02-22 14:17:43 -08001472 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001473 continue;
1474 }
Jason M. Billsefde4ec2022-06-24 08:59:52 -07001475 firstEntry = false;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001476
Jason M. Billsde703c52022-06-23 14:19:04 -07001477 nlohmann::json::object_t bmcLogEntry;
Patrick Williams89492a12023-05-10 07:51:34 -05001478 LogParseError status = fillEventLogEntryJson(idStr, logEntry,
1479 bmcLogEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001480 if (status == LogParseError::messageIdNotInRegistry)
1481 {
1482 continue;
1483 }
1484 if (status != LogParseError::success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001485 {
1486 messages::internalError(asyncResp->res);
1487 return;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001488 }
Jason M. Billsde703c52022-06-23 14:19:04 -07001489
Jason M. Billsde703c52022-06-23 14:19:04 -07001490 entryCount++;
1491 // Handle paging using skip (number of entries to skip from the
1492 // start) and top (number of entries to display)
Ed Tanous3648c8b2022-07-25 13:39:59 -07001493 if (entryCount <= skip || entryCount > skip + top)
Jason M. Billsde703c52022-06-23 14:19:04 -07001494 {
1495 continue;
1496 }
1497
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001498 logEntryArray.emplace_back(std::move(bmcLogEntry));
Jason M. Bills4978b632022-02-22 14:17:43 -08001499 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001500 }
1501 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
Ed Tanous3648c8b2022-07-25 13:39:59 -07001502 if (skip + top < entryCount)
Ed Tanous002d39b2022-05-31 08:59:27 -07001503 {
Ed Tanous253f11b2024-05-16 09:38:31 -07001504 asyncResp->res
1505 .jsonValue["Members@odata.nextLink"] = boost::urls::format(
1506 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}",
1507 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top));
Ed Tanous002d39b2022-05-31 08:59:27 -07001508 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001509 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001510}
Chicago Duan336e96c2019-07-15 14:22:08 +08001511
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001512inline void requestRoutesJournalEventLogEntry(App& app)
1513{
1514 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001515 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001516 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001517 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001518 [&app](const crow::Request& req,
1519 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001520 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001521 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001522 {
1523 return;
1524 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001525 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001526 {
1527 // Option currently returns no systems. TBD
1528 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1529 systemName);
1530 return;
1531 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001532
Ed Tanous253f11b2024-05-16 09:38:31 -07001533 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001534 {
1535 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1536 systemName);
1537 return;
1538 }
1539
Ed Tanous002d39b2022-05-31 08:59:27 -07001540 const std::string& targetID = param;
1541
1542 // Go through the log files and check the unique ID for each
1543 // entry to find the target entry
1544 std::vector<std::filesystem::path> redfishLogFiles;
1545 getRedfishLogFiles(redfishLogFiles);
1546 std::string logEntry;
1547
1548 // Oldest logs are in the last file, so start there and loop
1549 // backwards
1550 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1551 it++)
1552 {
1553 std::ifstream logStream(*it);
1554 if (!logStream.is_open())
1555 {
1556 continue;
1557 }
1558
1559 // Reset the unique ID on the first entry
1560 bool firstEntry = true;
1561 while (std::getline(logStream, logEntry))
1562 {
1563 std::string idStr;
1564 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
Ed Tanous45ca1b82022-03-25 13:07:27 -07001565 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001566 continue;
1567 }
Jason M. Billsefde4ec2022-06-24 08:59:52 -07001568 firstEntry = false;
Ed Tanous002d39b2022-05-31 08:59:27 -07001569
1570 if (idStr == targetID)
1571 {
Jason M. Billsde703c52022-06-23 14:19:04 -07001572 nlohmann::json::object_t bmcLogEntry;
Jason M. Billsac992cd2022-06-24 13:31:46 -07001573 LogParseError status =
1574 fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
1575 if (status != LogParseError::success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001576 {
1577 messages::internalError(asyncResp->res);
1578 return;
1579 }
Jason M. Billsd405bb52022-06-24 10:52:05 -07001580 asyncResp->res.jsonValue.update(bmcLogEntry);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001581 return;
1582 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001583 }
1584 }
1585 // Requested ID was not found
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08001586 messages::resourceNotFound(asyncResp->res, "LogEntry", targetID);
Patrick Williams5a39f772023-10-20 11:20:21 -05001587 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001588}
1589
1590inline void requestRoutesDBusEventLogEntryCollection(App& app)
1591{
Ed Tanous22d268c2022-05-19 09:39:07 -07001592 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07001593 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001594 .methods(boost::beast::http::verb::get)(
1595 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001596 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1597 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001598 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001599 {
1600 return;
1601 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001602 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001603 {
1604 // Option currently returns no systems. TBD
1605 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1606 systemName);
1607 return;
1608 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001609 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001610 {
1611 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1612 systemName);
1613 return;
1614 }
1615
Ed Tanous002d39b2022-05-31 08:59:27 -07001616 // Collections don't include the static data added by SubRoute
1617 // because it has a duplicate entry for members
1618 asyncResp->res.jsonValue["@odata.type"] =
1619 "#LogEntryCollection.LogEntryCollection";
1620 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001621 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1622 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07001623 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1624 asyncResp->res.jsonValue["Description"] =
1625 "Collection of System Event Log Entries";
1626
1627 // DBus implementation of EventLog/Entries
1628 // Make call to Logging Service to find all log entry objects
George Liu5eb468d2023-06-20 17:03:24 +08001629 sdbusplus::message::object_path path("/xyz/openbmc_project/logging");
1630 dbus::utility::getManagedObjects(
1631 "xyz.openbmc_project.Logging", path,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001632 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001633 const dbus::utility::ManagedObjectType& resp) {
1634 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001635 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001636 // TODO Handle for specific error code
Ed Tanous62598e32023-07-17 17:06:25 -07001637 BMCWEB_LOG_ERROR(
1638 "getLogEntriesIfaceData resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001639 messages::internalError(asyncResp->res);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001640 return;
1641 }
Ed Tanous3544d2a2023-08-06 18:12:20 -07001642 nlohmann::json::array_t entriesArray;
Ed Tanous002d39b2022-05-31 08:59:27 -07001643 for (const auto& objectPath : resp)
1644 {
1645 const uint32_t* id = nullptr;
1646 const uint64_t* timestamp = nullptr;
1647 const uint64_t* updateTimestamp = nullptr;
1648 const std::string* severity = nullptr;
1649 const std::string* message = nullptr;
1650 const std::string* filePath = nullptr;
Vijay Lobo9c11a172021-10-07 16:53:16 -05001651 const std::string* resolution = nullptr;
Ed Tanous002d39b2022-05-31 08:59:27 -07001652 bool resolved = false;
Abhishek Patel9017faf2021-09-14 22:48:55 -05001653 const std::string* notify = nullptr;
1654
Ed Tanous002d39b2022-05-31 08:59:27 -07001655 for (const auto& interfaceMap : objectPath.second)
1656 {
1657 if (interfaceMap.first ==
1658 "xyz.openbmc_project.Logging.Entry")
Xiaochao Ma75710de2021-01-21 17:56:02 +08001659 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001660 for (const auto& propertyMap : interfaceMap.second)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001661 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001662 if (propertyMap.first == "Id")
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001663 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001664 id = std::get_if<uint32_t>(&propertyMap.second);
1665 }
1666 else if (propertyMap.first == "Timestamp")
1667 {
1668 timestamp =
1669 std::get_if<uint64_t>(&propertyMap.second);
1670 }
1671 else if (propertyMap.first == "UpdateTimestamp")
1672 {
1673 updateTimestamp =
1674 std::get_if<uint64_t>(&propertyMap.second);
1675 }
1676 else if (propertyMap.first == "Severity")
1677 {
1678 severity = std::get_if<std::string>(
1679 &propertyMap.second);
1680 }
Vijay Lobo9c11a172021-10-07 16:53:16 -05001681 else if (propertyMap.first == "Resolution")
1682 {
1683 resolution = std::get_if<std::string>(
1684 &propertyMap.second);
1685 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001686 else if (propertyMap.first == "Message")
1687 {
1688 message = std::get_if<std::string>(
1689 &propertyMap.second);
1690 }
1691 else if (propertyMap.first == "Resolved")
1692 {
1693 const bool* resolveptr =
1694 std::get_if<bool>(&propertyMap.second);
1695 if (resolveptr == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001696 {
1697 messages::internalError(asyncResp->res);
1698 return;
1699 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001700 resolved = *resolveptr;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001701 }
Abhishek Patel9017faf2021-09-14 22:48:55 -05001702 else if (propertyMap.first ==
1703 "ServiceProviderNotify")
1704 {
1705 notify = std::get_if<std::string>(
1706 &propertyMap.second);
1707 if (notify == nullptr)
1708 {
1709 messages::internalError(asyncResp->res);
1710 return;
1711 }
1712 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001713 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001714 if (id == nullptr || message == nullptr ||
Ed Tanous002d39b2022-05-31 08:59:27 -07001715 severity == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001716 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001717 messages::internalError(asyncResp->res);
1718 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001719 }
1720 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001721 else if (interfaceMap.first ==
1722 "xyz.openbmc_project.Common.FilePath")
1723 {
1724 for (const auto& propertyMap : interfaceMap.second)
1725 {
1726 if (propertyMap.first == "Path")
1727 {
1728 filePath = std::get_if<std::string>(
1729 &propertyMap.second);
1730 }
1731 }
1732 }
1733 }
1734 // Object path without the
1735 // xyz.openbmc_project.Logging.Entry interface, ignore
1736 // and continue.
1737 if (id == nullptr || message == nullptr ||
1738 severity == nullptr || timestamp == nullptr ||
1739 updateTimestamp == nullptr)
1740 {
1741 continue;
1742 }
Ed Tanous3544d2a2023-08-06 18:12:20 -07001743 nlohmann::json& thisEntry = entriesArray.emplace_back();
Vijay Lobo9c11a172021-10-07 16:53:16 -05001744 thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001745 thisEntry["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001746 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1747 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(*id));
Ed Tanous002d39b2022-05-31 08:59:27 -07001748 thisEntry["Name"] = "System Event Log Entry";
1749 thisEntry["Id"] = std::to_string(*id);
1750 thisEntry["Message"] = *message;
1751 thisEntry["Resolved"] = resolved;
Vijay Lobo9c11a172021-10-07 16:53:16 -05001752 if ((resolution != nullptr) && (!(*resolution).empty()))
1753 {
1754 thisEntry["Resolution"] = *resolution;
1755 }
Abhishek Patel9017faf2021-09-14 22:48:55 -05001756 std::optional<bool> notifyAction =
1757 getProviderNotifyAction(*notify);
1758 if (notifyAction)
1759 {
1760 thisEntry["ServiceProviderNotified"] = *notifyAction;
1761 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001762 thisEntry["EntryType"] = "Event";
1763 thisEntry["Severity"] =
1764 translateSeverityDbusToRedfish(*severity);
1765 thisEntry["Created"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001766 redfish::time_utils::getDateTimeUintMs(*timestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07001767 thisEntry["Modified"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001768 redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07001769 if (filePath != nullptr)
1770 {
1771 thisEntry["AdditionalDataURI"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001772 std::format(
1773 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/",
1774 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous002d39b2022-05-31 08:59:27 -07001775 std::to_string(*id) + "/attachment";
1776 }
1777 }
Ed Tanous3544d2a2023-08-06 18:12:20 -07001778 std::ranges::sort(entriesArray, [](const nlohmann::json& left,
1779 const nlohmann::json& right) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001780 return (left["Id"] <= right["Id"]);
Ed Tanous3544d2a2023-08-06 18:12:20 -07001781 });
Ed Tanous002d39b2022-05-31 08:59:27 -07001782 asyncResp->res.jsonValue["Members@odata.count"] =
1783 entriesArray.size();
Ed Tanous3544d2a2023-08-06 18:12:20 -07001784 asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001785 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001786 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001787}
Xiaochao Ma75710de2021-01-21 17:56:02 +08001788
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001789inline void requestRoutesDBusEventLogEntry(App& app)
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001790{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001791 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001792 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001793 .privileges(redfish::privileges::getLogEntry)
Ed Tanous002d39b2022-05-31 08:59:27 -07001794 .methods(boost::beast::http::verb::get)(
1795 [&app](const crow::Request& req,
1796 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001797 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001798 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001799 {
1800 return;
1801 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001802 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001803 {
1804 // Option currently returns no systems. TBD
1805 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1806 systemName);
1807 return;
1808 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001809 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001810 {
1811 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1812 systemName);
1813 return;
1814 }
1815
Ed Tanous002d39b2022-05-31 08:59:27 -07001816 std::string entryID = param;
1817 dbus::utility::escapePathForDbus(entryID);
1818
1819 // DBus implementation of EventLog/Entries
1820 // Make call to Logging Service to find all log entry objects
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001821 sdbusplus::asio::getAllProperties(
1822 *crow::connections::systemBus, "xyz.openbmc_project.Logging",
1823 "/xyz/openbmc_project/logging/entry/" + entryID, "",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001824 [asyncResp, entryID](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001825 const dbus::utility::DBusPropertiesMap& resp) {
1826 if (ec.value() == EBADR)
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001827 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001828 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1829 entryID);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001830 return;
1831 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001832 if (ec)
1833 {
Ed Tanous62598e32023-07-17 17:06:25 -07001834 BMCWEB_LOG_ERROR(
1835 "EventLogEntry (DBus) resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001836 messages::internalError(asyncResp->res);
1837 return;
1838 }
1839 const uint32_t* id = nullptr;
1840 const uint64_t* timestamp = nullptr;
1841 const uint64_t* updateTimestamp = nullptr;
1842 const std::string* severity = nullptr;
1843 const std::string* message = nullptr;
1844 const std::string* filePath = nullptr;
Vijay Lobo9c11a172021-10-07 16:53:16 -05001845 const std::string* resolution = nullptr;
Ed Tanous002d39b2022-05-31 08:59:27 -07001846 bool resolved = false;
Abhishek Patel9017faf2021-09-14 22:48:55 -05001847 const std::string* notify = nullptr;
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001848
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001849 const bool success = sdbusplus::unpackPropertiesNoThrow(
1850 dbus_utils::UnpackErrorPrinter(), resp, "Id", id, "Timestamp",
1851 timestamp, "UpdateTimestamp", updateTimestamp, "Severity",
Vijay Lobo9c11a172021-10-07 16:53:16 -05001852 severity, "Message", message, "Resolved", resolved,
Abhishek Patel9017faf2021-09-14 22:48:55 -05001853 "Resolution", resolution, "Path", filePath,
1854 "ServiceProviderNotify", notify);
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001855
1856 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001857 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001858 messages::internalError(asyncResp->res);
1859 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07001860 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001861
Ed Tanous002d39b2022-05-31 08:59:27 -07001862 if (id == nullptr || message == nullptr || severity == nullptr ||
Abhishek Patel9017faf2021-09-14 22:48:55 -05001863 timestamp == nullptr || updateTimestamp == nullptr ||
1864 notify == nullptr)
Ed Tanous002d39b2022-05-31 08:59:27 -07001865 {
1866 messages::internalError(asyncResp->res);
1867 return;
1868 }
Abhishek Patel9017faf2021-09-14 22:48:55 -05001869
Ed Tanous002d39b2022-05-31 08:59:27 -07001870 asyncResp->res.jsonValue["@odata.type"] =
Vijay Lobo9c11a172021-10-07 16:53:16 -05001871 "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001872 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001873 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1874 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(*id));
Ed Tanous002d39b2022-05-31 08:59:27 -07001875 asyncResp->res.jsonValue["Name"] = "System Event Log Entry";
1876 asyncResp->res.jsonValue["Id"] = std::to_string(*id);
1877 asyncResp->res.jsonValue["Message"] = *message;
1878 asyncResp->res.jsonValue["Resolved"] = resolved;
Abhishek Patel9017faf2021-09-14 22:48:55 -05001879 std::optional<bool> notifyAction = getProviderNotifyAction(*notify);
1880 if (notifyAction)
1881 {
1882 asyncResp->res.jsonValue["ServiceProviderNotified"] =
1883 *notifyAction;
1884 }
Vijay Lobo9c11a172021-10-07 16:53:16 -05001885 if ((resolution != nullptr) && (!(*resolution).empty()))
1886 {
1887 asyncResp->res.jsonValue["Resolution"] = *resolution;
1888 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001889 asyncResp->res.jsonValue["EntryType"] = "Event";
1890 asyncResp->res.jsonValue["Severity"] =
1891 translateSeverityDbusToRedfish(*severity);
1892 asyncResp->res.jsonValue["Created"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001893 redfish::time_utils::getDateTimeUintMs(*timestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07001894 asyncResp->res.jsonValue["Modified"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001895 redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07001896 if (filePath != nullptr)
1897 {
1898 asyncResp->res.jsonValue["AdditionalDataURI"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001899 std::format(
1900 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/",
1901 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous002d39b2022-05-31 08:59:27 -07001902 std::to_string(*id) + "/attachment";
1903 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001904 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001905 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001906
1907 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001908 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001909 .privileges(redfish::privileges::patchLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001910 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001911 [&app](const crow::Request& req,
1912 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001913 const std::string& systemName, const std::string& entryId) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001914 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001915 {
1916 return;
1917 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001918 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001919 {
1920 // Option currently returns no systems. TBD
1921 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1922 systemName);
1923 return;
1924 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001925 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001926 {
1927 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1928 systemName);
1929 return;
1930 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001931 std::optional<bool> resolved;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001932
Ed Tanous002d39b2022-05-31 08:59:27 -07001933 if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved",
1934 resolved))
1935 {
1936 return;
1937 }
Ed Tanous62598e32023-07-17 17:06:25 -07001938 BMCWEB_LOG_DEBUG("Set Resolved");
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001939
Ginu Georgee93abac2024-06-14 17:35:27 +05301940 setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging",
Asmitha Karunanithi3eb66652024-04-02 16:34:36 +00001941 "/xyz/openbmc_project/logging/entry/" + entryId,
1942 "xyz.openbmc_project.Logging.Entry", "Resolved",
Ginu Georgee93abac2024-06-14 17:35:27 +05301943 *resolved);
Patrick Williams5a39f772023-10-20 11:20:21 -05001944 });
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001945
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001946 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001947 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001948 .privileges(redfish::privileges::deleteLogEntry)
1949
Ed Tanous002d39b2022-05-31 08:59:27 -07001950 .methods(boost::beast::http::verb::delete_)(
1951 [&app](const crow::Request& req,
1952 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001953 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001954 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001955 {
1956 return;
1957 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001958 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001959 {
1960 // Option currently returns no systems. TBD
1961 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1962 systemName);
1963 return;
1964 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001965 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001966 {
1967 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1968 systemName);
1969 return;
1970 }
Ed Tanous62598e32023-07-17 17:06:25 -07001971 BMCWEB_LOG_DEBUG("Do delete single event entries.");
Ed Tanous002d39b2022-05-31 08:59:27 -07001972
1973 std::string entryID = param;
1974
1975 dbus::utility::escapePathForDbus(entryID);
1976
1977 // Process response from Logging service.
Patrick Williams5a39f772023-10-20 11:20:21 -05001978 auto respHandler = [asyncResp,
1979 entryID](const boost::system::error_code& ec) {
Ed Tanous62598e32023-07-17 17:06:25 -07001980 BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done");
Ed Tanous002d39b2022-05-31 08:59:27 -07001981 if (ec)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001982 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001983 if (ec.value() == EBADR)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001984 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001985 messages::resourceNotFound(asyncResp->res, "LogEntry",
1986 entryID);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001987 return;
1988 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001989 // TODO Handle for specific error code
Ed Tanous62598e32023-07-17 17:06:25 -07001990 BMCWEB_LOG_ERROR(
1991 "EventLogEntry (DBus) doDelete respHandler got error {}",
1992 ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001993 asyncResp->res.result(
1994 boost::beast::http::status::internal_server_error);
1995 return;
1996 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001997
Ed Tanous002d39b2022-05-31 08:59:27 -07001998 asyncResp->res.result(boost::beast::http::status::ok);
1999 };
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002000
Ed Tanous002d39b2022-05-31 08:59:27 -07002001 // Make call to Logging service to request Delete Log
2002 crow::connections::systemBus->async_method_call(
2003 respHandler, "xyz.openbmc_project.Logging",
2004 "/xyz/openbmc_project/logging/entry/" + entryID,
2005 "xyz.openbmc_project.Object.Delete", "Delete");
Patrick Williams5a39f772023-10-20 11:20:21 -05002006 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002007}
2008
Spencer Kub7028eb2021-10-26 15:27:35 +08002009constexpr const char* hostLoggerFolderPath = "/var/log/console";
2010
2011inline bool
2012 getHostLoggerFiles(const std::string& hostLoggerFilePath,
2013 std::vector<std::filesystem::path>& hostLoggerFiles)
2014{
2015 std::error_code ec;
2016 std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec);
2017 if (ec)
2018 {
Carson Labradobf2dded2023-08-10 00:37:06 +00002019 BMCWEB_LOG_WARNING("{}", ec.message());
Spencer Kub7028eb2021-10-26 15:27:35 +08002020 return false;
2021 }
2022 for (const std::filesystem::directory_entry& it : logPath)
2023 {
2024 std::string filename = it.path().filename();
2025 // Prefix of each log files is "log". Find the file and save the
2026 // path
Ed Tanous11ba3972022-07-11 09:50:41 -07002027 if (filename.starts_with("log"))
Spencer Kub7028eb2021-10-26 15:27:35 +08002028 {
2029 hostLoggerFiles.emplace_back(it.path());
2030 }
2031 }
2032 // As the log files rotate, they are appended with a ".#" that is higher for
2033 // the older logs. Since we start from oldest logs, sort the name in
2034 // descending order.
2035 std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(),
2036 AlphanumLess<std::string>());
2037
2038 return true;
2039}
2040
Ed Tanous02cad962022-06-30 16:50:15 -07002041inline bool getHostLoggerEntries(
2042 const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip,
2043 uint64_t top, std::vector<std::string>& logEntries, size_t& logCount)
Spencer Kub7028eb2021-10-26 15:27:35 +08002044{
2045 GzFileReader logFile;
2046
2047 // Go though all log files and expose host logs.
2048 for (const std::filesystem::path& it : hostLoggerFiles)
2049 {
2050 if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount))
2051 {
Ed Tanous62598e32023-07-17 17:06:25 -07002052 BMCWEB_LOG_ERROR("fail to expose host logs");
Spencer Kub7028eb2021-10-26 15:27:35 +08002053 return false;
2054 }
2055 }
2056 // Get lastMessage from constructor by getter
2057 std::string lastMessage = logFile.getLastMessage();
2058 if (!lastMessage.empty())
2059 {
2060 logCount++;
2061 if (logCount > skip && logCount <= (skip + top))
2062 {
2063 logEntries.push_back(lastMessage);
2064 }
2065 }
2066 return true;
2067}
2068
Ed Tanous6f056f22024-04-07 13:35:51 -07002069inline void fillHostLoggerEntryJson(std::string_view logEntryID,
2070 std::string_view msg,
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002071 nlohmann::json::object_t& logEntryJson)
Spencer Kub7028eb2021-10-26 15:27:35 +08002072{
2073 // Fill in the log entry with the gathered data.
Vijay Lobo9c11a172021-10-07 16:53:16 -05002074 logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07002075 logEntryJson["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07002076 "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries/{}",
2077 BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002078 logEntryJson["Name"] = "Host Logger Entry";
2079 logEntryJson["Id"] = logEntryID;
2080 logEntryJson["Message"] = msg;
Ed Tanous539d8c62024-06-19 14:38:27 -07002081 logEntryJson["EntryType"] = log_entry::LogEntryType::Oem;
2082 logEntryJson["Severity"] = log_entry::EventSeverity::OK;
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002083 logEntryJson["OemRecordFormat"] = "Host Logger Entry";
Spencer Kub7028eb2021-10-26 15:27:35 +08002084}
2085
2086inline void requestRoutesSystemHostLogger(App& app)
2087{
Ed Tanous22d268c2022-05-19 09:39:07 -07002088 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/")
Spencer Kub7028eb2021-10-26 15:27:35 +08002089 .privileges(redfish::privileges::getLogService)
Ed Tanous14766872022-03-15 10:44:42 -07002090 .methods(boost::beast::http::verb::get)(
2091 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002092 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2093 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002094 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002095 {
2096 return;
2097 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002098 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002099 {
2100 // Option currently returns no systems. TBD
2101 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2102 systemName);
2103 return;
2104 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002105 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002106 {
2107 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2108 systemName);
2109 return;
2110 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002111 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002112 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
2113 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002114 asyncResp->res.jsonValue["@odata.type"] =
Janet Adkinsb25644a2023-08-16 11:23:45 -05002115 "#LogService.v1_2_0.LogService";
Ed Tanous002d39b2022-05-31 08:59:27 -07002116 asyncResp->res.jsonValue["Name"] = "Host Logger Service";
2117 asyncResp->res.jsonValue["Description"] = "Host Logger Service";
2118 asyncResp->res.jsonValue["Id"] = "HostLogger";
2119 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002120 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
2121 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05002122 });
Spencer Kub7028eb2021-10-26 15:27:35 +08002123}
2124
2125inline void requestRoutesSystemHostLoggerCollection(App& app)
2126{
2127 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002128 "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/")
Spencer Kub7028eb2021-10-26 15:27:35 +08002129 .privileges(redfish::privileges::getLogEntry)
Ed Tanous002d39b2022-05-31 08:59:27 -07002130 .methods(boost::beast::http::verb::get)(
2131 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002132 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2133 const std::string& systemName) {
Ed Tanous002d39b2022-05-31 08:59:27 -07002134 query_param::QueryCapabilities capabilities = {
2135 .canDelegateTop = true,
2136 .canDelegateSkip = true,
2137 };
2138 query_param::Query delegatedQuery;
2139 if (!redfish::setUpRedfishRouteWithDelegation(
Carson Labrado3ba00072022-06-06 19:40:56 +00002140 app, req, asyncResp, delegatedQuery, capabilities))
Ed Tanous002d39b2022-05-31 08:59:27 -07002141 {
2142 return;
2143 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002144 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002145 {
2146 // Option currently returns no systems. TBD
2147 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2148 systemName);
2149 return;
2150 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002151 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002152 {
2153 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2154 systemName);
2155 return;
2156 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002157 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002158 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
2159 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002160 asyncResp->res.jsonValue["@odata.type"] =
2161 "#LogEntryCollection.LogEntryCollection";
2162 asyncResp->res.jsonValue["Name"] = "HostLogger Entries";
2163 asyncResp->res.jsonValue["Description"] =
2164 "Collection of HostLogger Entries";
2165 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
2166 logEntryArray = nlohmann::json::array();
2167 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Spencer Kub7028eb2021-10-26 15:27:35 +08002168
Ed Tanous002d39b2022-05-31 08:59:27 -07002169 std::vector<std::filesystem::path> hostLoggerFiles;
2170 if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
2171 {
Carson Labradobf2dded2023-08-10 00:37:06 +00002172 BMCWEB_LOG_DEBUG("Failed to get host log file path");
Ed Tanous002d39b2022-05-31 08:59:27 -07002173 return;
2174 }
Ed Tanous3648c8b2022-07-25 13:39:59 -07002175 // If we weren't provided top and skip limits, use the defaults.
2176 size_t skip = delegatedQuery.skip.value_or(0);
Jiaqing Zhao5143f7a2022-07-22 09:33:33 +08002177 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
Ed Tanous002d39b2022-05-31 08:59:27 -07002178 size_t logCount = 0;
2179 // This vector only store the entries we want to expose that
2180 // control by skip and top.
2181 std::vector<std::string> logEntries;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002182 if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries,
2183 logCount))
Ed Tanous002d39b2022-05-31 08:59:27 -07002184 {
2185 messages::internalError(asyncResp->res);
2186 return;
2187 }
2188 // If vector is empty, that means skip value larger than total
2189 // log count
2190 if (logEntries.empty())
2191 {
2192 asyncResp->res.jsonValue["Members@odata.count"] = logCount;
2193 return;
2194 }
2195 if (!logEntries.empty())
2196 {
2197 for (size_t i = 0; i < logEntries.size(); i++)
George Liu0fda0f12021-11-16 10:06:17 +08002198 {
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002199 nlohmann::json::object_t hostLogEntry;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002200 fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i],
2201 hostLogEntry);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002202 logEntryArray.emplace_back(std::move(hostLogEntry));
George Liu0fda0f12021-11-16 10:06:17 +08002203 }
2204
Ed Tanous002d39b2022-05-31 08:59:27 -07002205 asyncResp->res.jsonValue["Members@odata.count"] = logCount;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002206 if (skip + top < logCount)
George Liu0fda0f12021-11-16 10:06:17 +08002207 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002208 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002209 std::format(
2210 "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries?$skip=",
2211 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous3648c8b2022-07-25 13:39:59 -07002212 std::to_string(skip + top);
George Liu0fda0f12021-11-16 10:06:17 +08002213 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002214 }
Patrick Williams5a39f772023-10-20 11:20:21 -05002215 });
Spencer Kub7028eb2021-10-26 15:27:35 +08002216}
2217
2218inline void requestRoutesSystemHostLoggerLogEntry(App& app)
2219{
2220 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07002221 app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/")
Spencer Kub7028eb2021-10-26 15:27:35 +08002222 .privileges(redfish::privileges::getLogEntry)
2223 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002224 [&app](const crow::Request& req,
2225 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07002226 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002227 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002228 {
2229 return;
2230 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002231 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002232 {
2233 // Option currently returns no systems. TBD
2234 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2235 systemName);
2236 return;
2237 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002238 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002239 {
2240 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2241 systemName);
2242 return;
2243 }
Ed Tanous6f056f22024-04-07 13:35:51 -07002244 std::string_view targetID = param;
Spencer Kub7028eb2021-10-26 15:27:35 +08002245
Ed Tanous002d39b2022-05-31 08:59:27 -07002246 uint64_t idInt = 0;
Ed Tanousca45aa32022-01-07 09:28:45 -08002247
Ed Tanous6f056f22024-04-07 13:35:51 -07002248 auto [ptr, ec] = std::from_chars(targetID.begin(), targetID.end(),
Patrick Williams84396af2023-05-11 11:47:45 -05002249 idInt);
Ed Tanous6f056f22024-04-07 13:35:51 -07002250 if (ec != std::errc{} || ptr != targetID.end())
Ed Tanous002d39b2022-05-31 08:59:27 -07002251 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08002252 messages::resourceNotFound(asyncResp->res, "LogEntry", param);
Ed Tanous002d39b2022-05-31 08:59:27 -07002253 return;
2254 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002255
Ed Tanous002d39b2022-05-31 08:59:27 -07002256 std::vector<std::filesystem::path> hostLoggerFiles;
2257 if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
2258 {
Carson Labradobf2dded2023-08-10 00:37:06 +00002259 BMCWEB_LOG_DEBUG("Failed to get host log file path");
Ed Tanous002d39b2022-05-31 08:59:27 -07002260 return;
2261 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002262
Ed Tanous002d39b2022-05-31 08:59:27 -07002263 size_t logCount = 0;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002264 size_t top = 1;
Ed Tanous002d39b2022-05-31 08:59:27 -07002265 std::vector<std::string> logEntries;
2266 // We can get specific entry by skip and top. For example, if we
2267 // want to get nth entry, we can set skip = n-1 and top = 1 to
2268 // get that entry
2269 if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries,
2270 logCount))
2271 {
2272 messages::internalError(asyncResp->res);
2273 return;
2274 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002275
Ed Tanous002d39b2022-05-31 08:59:27 -07002276 if (!logEntries.empty())
2277 {
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002278 nlohmann::json::object_t hostLogEntry;
2279 fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry);
2280 asyncResp->res.jsonValue.update(hostLogEntry);
Ed Tanous002d39b2022-05-31 08:59:27 -07002281 return;
2282 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002283
Ed Tanous002d39b2022-05-31 08:59:27 -07002284 // Requested ID was not found
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08002285 messages::resourceNotFound(asyncResp->res, "LogEntry", param);
Patrick Williams5a39f772023-10-20 11:20:21 -05002286 });
Spencer Kub7028eb2021-10-26 15:27:35 +08002287}
2288
Claire Weinandd72e872022-08-15 14:20:06 -07002289inline void handleBMCLogServicesCollectionGet(
Claire Weinanfdd26902022-03-01 14:18:25 -08002290 crow::App& app, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002291 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2292 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002293{
2294 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2295 {
2296 return;
2297 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002298
2299 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2300 {
2301 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2302 return;
2303 }
2304
Claire Weinanfdd26902022-03-01 14:18:25 -08002305 // Collections don't include the static data added by SubRoute
2306 // because it has a duplicate entry for members
2307 asyncResp->res.jsonValue["@odata.type"] =
2308 "#LogServiceCollection.LogServiceCollection";
Ed Tanous253f11b2024-05-16 09:38:31 -07002309 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2310 "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -08002311 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
2312 asyncResp->res.jsonValue["Description"] =
2313 "Collection of LogServices for this Manager";
2314 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
2315 logServiceArray = nlohmann::json::array();
2316
Ed Tanous25b54db2024-04-17 15:40:31 -07002317 if constexpr (BMCWEB_REDFISH_BMC_JOURNAL)
2318 {
2319 nlohmann::json::object_t journal;
Ed Tanous253f11b2024-05-16 09:38:31 -07002320 journal["@odata.id"] =
2321 boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal",
2322 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07002323 logServiceArray.emplace_back(std::move(journal));
2324 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002325
2326 asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
2327
Ed Tanous25b54db2024-04-17 15:40:31 -07002328 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
2329 {
2330 constexpr std::array<std::string_view, 1> interfaces = {
2331 "xyz.openbmc_project.Collection.DeleteAll"};
2332 dbus::utility::getSubTreePaths(
2333 "/xyz/openbmc_project/dump", 0, interfaces,
2334 [asyncResp](const boost::system::error_code& ec,
2335 const dbus::utility::MapperGetSubTreePathsResponse&
2336 subTreePaths) {
2337 if (ec)
Claire Weinanfdd26902022-03-01 14:18:25 -08002338 {
Ed Tanous25b54db2024-04-17 15:40:31 -07002339 BMCWEB_LOG_ERROR(
2340 "handleBMCLogServicesCollectionGet respHandler got error {}",
2341 ec);
2342 // Assume that getting an error simply means there are no dump
2343 // LogServices. Return without adding any error response.
2344 return;
Claire Weinanfdd26902022-03-01 14:18:25 -08002345 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002346
Ed Tanous25b54db2024-04-17 15:40:31 -07002347 nlohmann::json& logServiceArrayLocal =
2348 asyncResp->res.jsonValue["Members"];
2349
2350 for (const std::string& path : subTreePaths)
2351 {
2352 if (path == "/xyz/openbmc_project/dump/bmc")
2353 {
2354 nlohmann::json::object_t member;
Ed Tanous253f11b2024-05-16 09:38:31 -07002355 member["@odata.id"] = boost::urls::format(
2356 "/redfish/v1/Managers/{}/LogServices/Dump",
2357 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07002358 logServiceArrayLocal.emplace_back(std::move(member));
2359 }
2360 else if (path == "/xyz/openbmc_project/dump/faultlog")
2361 {
2362 nlohmann::json::object_t member;
Ed Tanous253f11b2024-05-16 09:38:31 -07002363 member["@odata.id"] = boost::urls::format(
2364 "/redfish/v1/Managers/{}/LogServices/FaultLog",
2365 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07002366 logServiceArrayLocal.emplace_back(std::move(member));
2367 }
2368 }
2369
2370 asyncResp->res.jsonValue["Members@odata.count"] =
2371 logServiceArrayLocal.size();
2372 });
2373 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002374}
2375
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002376inline void requestRoutesBMCLogServiceCollection(App& app)
2377{
Ed Tanous253f11b2024-05-16 09:38:31 -07002378 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/")
Gunnar Millsad89dcf2021-07-30 14:40:11 -05002379 .privileges(redfish::privileges::getLogServiceCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002380 .methods(boost::beast::http::verb::get)(
Claire Weinandd72e872022-08-15 14:20:06 -07002381 std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002382}
Ed Tanous1da66f72018-07-27 16:13:37 -07002383
Claire Weinanfdd26902022-03-01 14:18:25 -08002384inline void
2385 getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2386 const std::string& dumpType)
2387{
2388 std::string dumpPath;
Ed Tanous539d8c62024-06-19 14:38:27 -07002389 log_service::OverWritePolicy overWritePolicy =
2390 log_service::OverWritePolicy::Invalid;
Claire Weinanfdd26902022-03-01 14:18:25 -08002391 bool collectDiagnosticDataSupported = false;
2392
2393 if (dumpType == "BMC")
2394 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002395 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump",
2396 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002397 overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
Claire Weinanfdd26902022-03-01 14:18:25 -08002398 collectDiagnosticDataSupported = true;
2399 }
2400 else if (dumpType == "FaultLog")
2401 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002402 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog",
2403 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002404 overWritePolicy = log_service::OverWritePolicy::Unknown;
Claire Weinanfdd26902022-03-01 14:18:25 -08002405 collectDiagnosticDataSupported = false;
2406 }
2407 else if (dumpType == "System")
2408 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002409 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump",
2410 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous539d8c62024-06-19 14:38:27 -07002411 overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
Claire Weinanfdd26902022-03-01 14:18:25 -08002412 collectDiagnosticDataSupported = true;
2413 }
2414 else
2415 {
Ed Tanous62598e32023-07-17 17:06:25 -07002416 BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}",
2417 dumpType);
Claire Weinanfdd26902022-03-01 14:18:25 -08002418 messages::internalError(asyncResp->res);
2419 return;
2420 }
2421
2422 asyncResp->res.jsonValue["@odata.id"] = dumpPath;
2423 asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService";
2424 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2425 asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService";
2426 asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename();
Ed Tanous539d8c62024-06-19 14:38:27 -07002427 asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy;
Claire Weinanfdd26902022-03-01 14:18:25 -08002428
2429 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002430 redfish::time_utils::getDateTimeOffsetNow();
Claire Weinanfdd26902022-03-01 14:18:25 -08002431 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2432 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2433 redfishDateTimeOffset.second;
2434
2435 asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries";
Claire Weinanfdd26902022-03-01 14:18:25 -08002436
2437 if (collectDiagnosticDataSupported)
2438 {
2439 asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2440 ["target"] =
2441 dumpPath + "/Actions/LogService.CollectDiagnosticData";
2442 }
Claire Weinan0d946212022-07-13 19:40:19 -07002443
2444 constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface};
2445 dbus::utility::getSubTreePaths(
2446 "/xyz/openbmc_project/dump", 0, interfaces,
2447 [asyncResp, dumpType, dumpPath](
2448 const boost::system::error_code& ec,
2449 const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
2450 if (ec)
2451 {
Ed Tanous62598e32023-07-17 17:06:25 -07002452 BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", ec);
Claire Weinan0d946212022-07-13 19:40:19 -07002453 // Assume that getting an error simply means there are no dump
2454 // LogServices. Return without adding any error response.
2455 return;
2456 }
Ed Tanous18f8f602023-07-18 10:07:23 -07002457 std::string dbusDumpPath = getDumpPath(dumpType);
Claire Weinan0d946212022-07-13 19:40:19 -07002458 for (const std::string& path : subTreePaths)
2459 {
2460 if (path == dbusDumpPath)
2461 {
2462 asyncResp->res
2463 .jsonValue["Actions"]["#LogService.ClearLog"]["target"] =
2464 dumpPath + "/Actions/LogService.ClearLog";
2465 break;
2466 }
2467 }
Patrick Williams5a39f772023-10-20 11:20:21 -05002468 });
Claire Weinanfdd26902022-03-01 14:18:25 -08002469}
2470
2471inline void handleLogServicesDumpServiceGet(
2472 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002473 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2474 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002475{
2476 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2477 {
2478 return;
2479 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002480
2481 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2482 {
2483 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2484 return;
2485 }
2486
Claire Weinanfdd26902022-03-01 14:18:25 -08002487 getDumpServiceInfo(asyncResp, dumpType);
2488}
2489
Ed Tanous22d268c2022-05-19 09:39:07 -07002490inline void handleLogServicesDumpServiceComputerSystemGet(
2491 crow::App& app, const crow::Request& req,
2492 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2493 const std::string& chassisId)
2494{
2495 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2496 {
2497 return;
2498 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002499 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002500 {
2501 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2502 return;
2503 }
2504 getDumpServiceInfo(asyncResp, "System");
2505}
2506
Claire Weinanfdd26902022-03-01 14:18:25 -08002507inline void handleLogServicesDumpEntriesCollectionGet(
2508 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002509 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2510 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002511{
2512 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2513 {
2514 return;
2515 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002516
2517 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2518 {
2519 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2520 return;
2521 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002522 getDumpEntryCollection(asyncResp, dumpType);
2523}
2524
Ed Tanous22d268c2022-05-19 09:39:07 -07002525inline void handleLogServicesDumpEntriesCollectionComputerSystemGet(
2526 crow::App& app, const crow::Request& req,
2527 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2528 const std::string& chassisId)
2529{
2530 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2531 {
2532 return;
2533 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002534 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002535 {
2536 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2537 return;
2538 }
2539 getDumpEntryCollection(asyncResp, "System");
2540}
2541
Claire Weinanfdd26902022-03-01 14:18:25 -08002542inline void handleLogServicesDumpEntryGet(
2543 crow::App& app, const std::string& dumpType, const crow::Request& req,
2544 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002545 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002546{
2547 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2548 {
2549 return;
2550 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002551 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2552 {
2553 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2554 return;
2555 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002556 getDumpEntryById(asyncResp, dumpId, dumpType);
2557}
Carson Labrado168d1b12023-03-27 17:04:46 +00002558
Ed Tanous22d268c2022-05-19 09:39:07 -07002559inline void handleLogServicesDumpEntryComputerSystemGet(
2560 crow::App& app, const crow::Request& req,
2561 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2562 const std::string& chassisId, const std::string& dumpId)
2563{
2564 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2565 {
2566 return;
2567 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002568 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002569 {
2570 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2571 return;
2572 }
2573 getDumpEntryById(asyncResp, dumpId, "System");
2574}
Claire Weinanfdd26902022-03-01 14:18:25 -08002575
2576inline void handleLogServicesDumpEntryDelete(
2577 crow::App& app, const std::string& dumpType, const crow::Request& req,
2578 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002579 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002580{
2581 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2582 {
2583 return;
2584 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002585
2586 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2587 {
2588 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2589 return;
2590 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002591 deleteDumpEntry(asyncResp, dumpId, dumpType);
2592}
2593
Ed Tanous22d268c2022-05-19 09:39:07 -07002594inline void handleLogServicesDumpEntryComputerSystemDelete(
2595 crow::App& app, const crow::Request& req,
2596 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2597 const std::string& chassisId, const std::string& dumpId)
2598{
2599 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2600 {
2601 return;
2602 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002603 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002604 {
2605 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2606 return;
2607 }
2608 deleteDumpEntry(asyncResp, dumpId, "System");
2609}
2610
Carson Labrado168d1b12023-03-27 17:04:46 +00002611inline void handleLogServicesDumpEntryDownloadGet(
2612 crow::App& app, const std::string& dumpType, const crow::Request& req,
2613 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002614 const std::string& managerId, const std::string& dumpId)
Carson Labrado168d1b12023-03-27 17:04:46 +00002615{
2616 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2617 {
2618 return;
2619 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002620
2621 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2622 {
2623 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2624 return;
2625 }
Carson Labrado168d1b12023-03-27 17:04:46 +00002626 downloadDumpEntry(asyncResp, dumpId, dumpType);
2627}
2628
2629inline void handleDBusEventLogEntryDownloadGet(
2630 crow::App& app, const std::string& dumpType, const crow::Request& req,
2631 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2632 const std::string& systemName, const std::string& entryID)
2633{
2634 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2635 {
2636 return;
2637 }
2638 if (!http_helpers::isContentTypeAllowed(
2639 req.getHeaderValue("Accept"),
2640 http_helpers::ContentType::OctetStream, true))
2641 {
2642 asyncResp->res.result(boost::beast::http::status::bad_request);
2643 return;
2644 }
2645 downloadEventLogEntry(asyncResp, systemName, entryID, dumpType);
2646}
2647
Claire Weinanfdd26902022-03-01 14:18:25 -08002648inline void handleLogServicesDumpCollectDiagnosticDataPost(
2649 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002650 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2651 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002652{
2653 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2654 {
2655 return;
2656 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002657 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2658 {
2659 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2660 return;
2661 }
2662
Claire Weinanfdd26902022-03-01 14:18:25 -08002663 createDump(asyncResp, req, dumpType);
2664}
2665
Ed Tanous22d268c2022-05-19 09:39:07 -07002666inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost(
2667 crow::App& app, const crow::Request& req,
2668 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002669 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002670{
2671 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2672 {
2673 return;
2674 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002675
Ed Tanous25b54db2024-04-17 15:40:31 -07002676 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002677 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002678 // Option currently returns no systems. TBD
2679 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2680 systemName);
2681 return;
2682 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002683 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002684 {
2685 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2686 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002687 return;
2688 }
2689 createDump(asyncResp, req, "System");
2690}
2691
Claire Weinanfdd26902022-03-01 14:18:25 -08002692inline void handleLogServicesDumpClearLogPost(
2693 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002694 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2695 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002696{
2697 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2698 {
2699 return;
2700 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002701
2702 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2703 {
2704 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2705 return;
2706 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002707 clearDump(asyncResp, dumpType);
2708}
2709
Ed Tanous22d268c2022-05-19 09:39:07 -07002710inline void handleLogServicesDumpClearLogComputerSystemPost(
2711 crow::App& app, const crow::Request& req,
2712 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002713 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002714{
2715 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2716 {
2717 return;
2718 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002719 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002720 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002721 // Option currently returns no systems. TBD
2722 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2723 systemName);
2724 return;
2725 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002726 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002727 {
2728 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2729 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002730 return;
2731 }
2732 clearDump(asyncResp, "System");
2733}
2734
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002735inline void requestRoutesBMCDumpService(App& app)
2736{
Ed Tanous253f11b2024-05-16 09:38:31 -07002737 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002738 .privileges(redfish::privileges::getLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002739 .methods(boost::beast::http::verb::get)(std::bind_front(
2740 handleLogServicesDumpServiceGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002741}
2742
2743inline void requestRoutesBMCDumpEntryCollection(App& app)
2744{
Ed Tanous253f11b2024-05-16 09:38:31 -07002745 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002746 .privileges(redfish::privileges::getLogEntryCollection)
Claire Weinanfdd26902022-03-01 14:18:25 -08002747 .methods(boost::beast::http::verb::get)(std::bind_front(
2748 handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002749}
2750
2751inline void requestRoutesBMCDumpEntry(App& app)
2752{
2753 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002754 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002755 .privileges(redfish::privileges::getLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002756 .methods(boost::beast::http::verb::get)(std::bind_front(
2757 handleLogServicesDumpEntryGet, std::ref(app), "BMC"));
2758
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002759 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002760 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002761 .privileges(redfish::privileges::deleteLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002762 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2763 handleLogServicesDumpEntryDelete, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002764}
2765
Carson Labrado168d1b12023-03-27 17:04:46 +00002766inline void requestRoutesBMCDumpEntryDownload(App& app)
2767{
2768 BMCWEB_ROUTE(
2769 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002770 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002771 .privileges(redfish::privileges::getLogEntry)
2772 .methods(boost::beast::http::verb::get)(std::bind_front(
2773 handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC"));
2774}
2775
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002776inline void requestRoutesBMCDumpCreate(App& app)
2777{
George Liu0fda0f12021-11-16 10:06:17 +08002778 BMCWEB_ROUTE(
2779 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002780 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002781 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002782 .methods(boost::beast::http::verb::post)(
Claire Weinanfdd26902022-03-01 14:18:25 -08002783 std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost,
2784 std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002785}
2786
2787inline void requestRoutesBMCDumpClear(App& app)
2788{
George Liu0fda0f12021-11-16 10:06:17 +08002789 BMCWEB_ROUTE(
2790 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002791 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002792 .privileges(redfish::privileges::postLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002793 .methods(boost::beast::http::verb::post)(std::bind_front(
2794 handleLogServicesDumpClearLogPost, std::ref(app), "BMC"));
2795}
2796
Carson Labrado168d1b12023-03-27 17:04:46 +00002797inline void requestRoutesDBusEventLogEntryDownload(App& app)
2798{
2799 BMCWEB_ROUTE(
2800 app,
Ravi Teja9e9d99d2023-11-08 05:33:59 -06002801 "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002802 .privileges(redfish::privileges::getLogEntry)
2803 .methods(boost::beast::http::verb::get)(std::bind_front(
2804 handleDBusEventLogEntryDownloadGet, std::ref(app), "System"));
2805}
2806
Claire Weinanfdd26902022-03-01 14:18:25 -08002807inline void requestRoutesFaultLogDumpService(App& app)
2808{
Ed Tanous253f11b2024-05-16 09:38:31 -07002809 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002810 .privileges(redfish::privileges::getLogService)
2811 .methods(boost::beast::http::verb::get)(std::bind_front(
2812 handleLogServicesDumpServiceGet, std::ref(app), "FaultLog"));
2813}
2814
2815inline void requestRoutesFaultLogDumpEntryCollection(App& app)
2816{
Ed Tanous253f11b2024-05-16 09:38:31 -07002817 BMCWEB_ROUTE(app,
2818 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002819 .privileges(redfish::privileges::getLogEntryCollection)
2820 .methods(boost::beast::http::verb::get)(
2821 std::bind_front(handleLogServicesDumpEntriesCollectionGet,
2822 std::ref(app), "FaultLog"));
2823}
2824
2825inline void requestRoutesFaultLogDumpEntry(App& app)
2826{
Ed Tanous253f11b2024-05-16 09:38:31 -07002827 BMCWEB_ROUTE(
2828 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002829 .privileges(redfish::privileges::getLogEntry)
2830 .methods(boost::beast::http::verb::get)(std::bind_front(
2831 handleLogServicesDumpEntryGet, std::ref(app), "FaultLog"));
2832
Ed Tanous253f11b2024-05-16 09:38:31 -07002833 BMCWEB_ROUTE(
2834 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002835 .privileges(redfish::privileges::deleteLogEntry)
2836 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2837 handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog"));
2838}
2839
2840inline void requestRoutesFaultLogDumpClear(App& app)
2841{
2842 BMCWEB_ROUTE(
2843 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002844 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002845 .privileges(redfish::privileges::postLogService)
2846 .methods(boost::beast::http::verb::post)(std::bind_front(
2847 handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002848}
2849
2850inline void requestRoutesSystemDumpService(App& app)
2851{
Ed Tanous22d268c2022-05-19 09:39:07 -07002852 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002853 .privileges(redfish::privileges::getLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002854 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002855 handleLogServicesDumpServiceComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002856}
2857
2858inline void requestRoutesSystemDumpEntryCollection(App& app)
2859{
Ed Tanous22d268c2022-05-19 09:39:07 -07002860 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002861 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous22d268c2022-05-19 09:39:07 -07002862 .methods(boost::beast::http::verb::get)(std::bind_front(
2863 handleLogServicesDumpEntriesCollectionComputerSystemGet,
2864 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002865}
2866
2867inline void requestRoutesSystemDumpEntry(App& app)
2868{
2869 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002870 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002871 .privileges(redfish::privileges::getLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002872 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002873 handleLogServicesDumpEntryComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002874
2875 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002876 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002877 .privileges(redfish::privileges::deleteLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002878 .methods(boost::beast::http::verb::delete_)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002879 handleLogServicesDumpEntryComputerSystemDelete, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002880}
2881
2882inline void requestRoutesSystemDumpCreate(App& app)
2883{
George Liu0fda0f12021-11-16 10:06:17 +08002884 BMCWEB_ROUTE(
2885 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002886 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002887 .privileges(redfish::privileges::postLogService)
Ed Tanous22d268c2022-05-19 09:39:07 -07002888 .methods(boost::beast::http::verb::post)(std::bind_front(
2889 handleLogServicesDumpCollectDiagnosticDataComputerSystemPost,
2890 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002891}
2892
2893inline void requestRoutesSystemDumpClear(App& app)
2894{
George Liu0fda0f12021-11-16 10:06:17 +08002895 BMCWEB_ROUTE(
2896 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002897 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002898 .privileges(redfish::privileges::postLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002899 .methods(boost::beast::http::verb::post)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002900 handleLogServicesDumpClearLogComputerSystemPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002901}
2902
2903inline void requestRoutesCrashdumpService(App& app)
2904{
2905 // Note: Deviated from redfish privilege registry for GET & HEAD
2906 // method for security reasons.
2907 /**
2908 * Functions triggers appropriate requests on DBus
2909 */
Ed Tanous22d268c2022-05-19 09:39:07 -07002910 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/")
Ed Tanoused398212021-06-09 17:05:54 -07002911 // This is incorrect, should be:
2912 //.privileges(redfish::privileges::getLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002913 .privileges({{"ConfigureManager"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07002914 .methods(boost::beast::http::verb::get)(
2915 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002916 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2917 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002918 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002919 {
2920 return;
2921 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002922 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002923 {
2924 // Option currently returns no systems. TBD
2925 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2926 systemName);
2927 return;
2928 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002929 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002930 {
2931 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2932 systemName);
2933 return;
2934 }
2935
Ed Tanous002d39b2022-05-31 08:59:27 -07002936 // Copy over the static data to include the entries added by
2937 // SubRoute
2938 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002939 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
2940 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002941 asyncResp->res.jsonValue["@odata.type"] =
2942 "#LogService.v1_2_0.LogService";
2943 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2944 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
V-Sanjana15b89722023-05-11 16:27:03 +05302945 asyncResp->res.jsonValue["Id"] = "Crashdump";
Ed Tanous539d8c62024-06-19 14:38:27 -07002946 asyncResp->res.jsonValue["OverWritePolicy"] =
2947 log_service::OverWritePolicy::WrapsWhenFull;
Ed Tanous002d39b2022-05-31 08:59:27 -07002948 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302949
Ed Tanous002d39b2022-05-31 08:59:27 -07002950 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002951 redfish::time_utils::getDateTimeOffsetNow();
Ed Tanous002d39b2022-05-31 08:59:27 -07002952 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2953 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2954 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302955
Ed Tanous002d39b2022-05-31 08:59:27 -07002956 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002957 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2958 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2959 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2960 ["target"] = std::format(
2961 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog",
2962 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002963 asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
Ed Tanous253f11b2024-05-16 09:38:31 -07002964 ["target"] = std::format(
2965 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData",
2966 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05002967 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002968}
2969
2970void inline requestRoutesCrashdumpClear(App& app)
2971{
George Liu0fda0f12021-11-16 10:06:17 +08002972 BMCWEB_ROUTE(
2973 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002974 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002975 // This is incorrect, should be:
2976 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002977 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002978 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002979 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002980 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2981 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002982 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002983 {
2984 return;
2985 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002986 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002987 {
2988 // Option currently returns no systems. TBD
2989 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2990 systemName);
2991 return;
2992 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002993 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002994 {
2995 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2996 systemName);
2997 return;
2998 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002999 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003000 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003001 const std::string&) {
3002 if (ec)
3003 {
3004 messages::internalError(asyncResp->res);
3005 return;
3006 }
3007 messages::success(asyncResp->res);
Patrick Williams5a39f772023-10-20 11:20:21 -05003008 },
Ed Tanous002d39b2022-05-31 08:59:27 -07003009 crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
Patrick Williams5a39f772023-10-20 11:20:21 -05003010 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003011}
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07003012
zhanghch058d1b46d2021-04-01 11:18:24 +08003013static void
3014 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3015 const std::string& logID, nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07003016{
Johnathan Mantey043a0532020-03-10 17:15:28 -07003017 auto getStoredLogCallback =
Ed Tanousb9d36b42022-02-26 21:42:46 -08003018 [asyncResp, logID,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003019 &logEntryJson](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08003020 const dbus::utility::DBusPropertiesMap& params) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003021 if (ec)
3022 {
Ed Tanous62598e32023-07-17 17:06:25 -07003023 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07003024 if (ec.value() ==
3025 boost::system::linux_error::bad_request_descriptor)
Jason M. Bills1ddcf012019-11-26 14:59:21 -08003026 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003027 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Jason M. Bills2b20ef62022-01-06 15:48:07 -08003028 }
3029 else
3030 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003031 messages::internalError(asyncResp->res);
Jason M. Bills2b20ef62022-01-06 15:48:07 -08003032 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003033 return;
3034 }
3035
3036 std::string timestamp{};
3037 std::string filename{};
3038 std::string logfile{};
3039 parseCrashdumpParameters(params, filename, timestamp, logfile);
3040
3041 if (filename.empty() || timestamp.empty())
3042 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003043 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003044 return;
3045 }
3046
3047 std::string crashdumpURI =
Ed Tanous253f11b2024-05-16 09:38:31 -07003048 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/",
3049 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous002d39b2022-05-31 08:59:27 -07003050 logID + "/" + filename;
Jason M. Bills84afc482022-06-24 12:38:23 -07003051 nlohmann::json::object_t logEntry;
Vijay Lobo9c11a172021-10-07 16:53:16 -05003052 logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07003053 logEntry["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07003054 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}",
3055 BMCWEB_REDFISH_SYSTEM_URI_NAME, logID);
Jason M. Bills84afc482022-06-24 12:38:23 -07003056 logEntry["Name"] = "CPU Crashdump";
3057 logEntry["Id"] = logID;
Ed Tanous539d8c62024-06-19 14:38:27 -07003058 logEntry["EntryType"] = log_entry::LogEntryType::Oem;
Jason M. Bills84afc482022-06-24 12:38:23 -07003059 logEntry["AdditionalDataURI"] = std::move(crashdumpURI);
3060 logEntry["DiagnosticDataType"] = "OEM";
3061 logEntry["OEMDiagnosticDataType"] = "PECICrashdump";
3062 logEntry["Created"] = std::move(timestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07003063
3064 // If logEntryJson references an array of LogEntry resources
3065 // ('Members' list), then push this as a new entry, otherwise set it
3066 // directly
3067 if (logEntryJson.is_array())
3068 {
3069 logEntryJson.push_back(logEntry);
3070 asyncResp->res.jsonValue["Members@odata.count"] =
3071 logEntryJson.size();
3072 }
3073 else
3074 {
Jason M. Billsd405bb52022-06-24 10:52:05 -07003075 logEntryJson.update(logEntry);
Ed Tanous002d39b2022-05-31 08:59:27 -07003076 }
3077 };
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02003078 sdbusplus::asio::getAllProperties(
3079 *crow::connections::systemBus, crashdumpObject,
3080 crashdumpPath + std::string("/") + logID, crashdumpInterface,
3081 std::move(getStoredLogCallback));
Jason M. Billse855dd22019-10-08 11:37:48 -07003082}
3083
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003084inline void requestRoutesCrashdumpEntryCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07003085{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003086 // Note: Deviated from redfish privilege registry for GET & HEAD
3087 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07003088 /**
3089 * Functions triggers appropriate requests on DBus
3090 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003091 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003092 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07003093 // This is incorrect, should be.
3094 //.privileges(redfish::privileges::postLogEntryCollection)
Ed Tanous432a8902021-06-14 15:28:56 -07003095 .privileges({{"ConfigureComponents"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07003096 .methods(boost::beast::http::verb::get)(
3097 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003098 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3099 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003100 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003101 {
3102 return;
3103 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003104 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003105 {
3106 // Option currently returns no systems. TBD
3107 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3108 systemName);
3109 return;
3110 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003111 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003112 {
3113 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3114 systemName);
3115 return;
3116 }
3117
George Liu7a1dbc42022-12-07 16:03:22 +08003118 constexpr std::array<std::string_view, 1> interfaces = {
3119 crashdumpInterface};
3120 dbus::utility::getSubTreePaths(
3121 "/", 0, interfaces,
3122 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003123 const std::vector<std::string>& resp) {
3124 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07003125 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003126 if (ec.value() !=
3127 boost::system::errc::no_such_file_or_directory)
3128 {
Ed Tanous62598e32023-07-17 17:06:25 -07003129 BMCWEB_LOG_DEBUG("failed to get entries ec: {}",
3130 ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07003131 messages::internalError(asyncResp->res);
3132 return;
3133 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07003134 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003135 asyncResp->res.jsonValue["@odata.type"] =
3136 "#LogEntryCollection.LogEntryCollection";
Ed Tanous253f11b2024-05-16 09:38:31 -07003137 asyncResp->res.jsonValue["@odata.id"] = std::format(
3138 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
3139 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07003140 asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
3141 asyncResp->res.jsonValue["Description"] =
3142 "Collection of Crashdump Entries";
3143 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3144 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Jason M. Bills2b20ef62022-01-06 15:48:07 -08003145
Ed Tanous002d39b2022-05-31 08:59:27 -07003146 for (const std::string& path : resp)
3147 {
3148 const sdbusplus::message::object_path objPath(path);
3149 // Get the log ID
3150 std::string logID = objPath.filename();
3151 if (logID.empty())
3152 {
3153 continue;
3154 }
3155 // Add the log entry to the array
3156 logCrashdumpEntry(asyncResp, logID,
3157 asyncResp->res.jsonValue["Members"]);
3158 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003159 });
Patrick Williams5a39f772023-10-20 11:20:21 -05003160 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003161}
Ed Tanous1da66f72018-07-27 16:13:37 -07003162
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003163inline void requestRoutesCrashdumpEntry(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07003164{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003165 // Note: Deviated from redfish privilege registry for GET & HEAD
3166 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07003167
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003168 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07003169 app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07003170 // this is incorrect, should be
3171 // .privileges(redfish::privileges::getLogEntry)
Ed Tanous432a8902021-06-14 15:28:56 -07003172 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003173 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003174 [&app](const crow::Request& req,
3175 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07003176 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003177 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003178 {
3179 return;
3180 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003181 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003182 {
3183 // Option currently returns no systems. TBD
3184 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3185 systemName);
3186 return;
3187 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003188 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003189 {
3190 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3191 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003192 return;
3193 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003194 const std::string& logID = param;
3195 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
Patrick Williams5a39f772023-10-20 11:20:21 -05003196 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003197}
Ed Tanous1da66f72018-07-27 16:13:37 -07003198
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003199inline void requestRoutesCrashdumpFile(App& app)
3200{
3201 // Note: Deviated from redfish privilege registry for GET & HEAD
3202 // method for security reasons.
3203 BMCWEB_ROUTE(
3204 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003205 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07003206 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003207 .methods(boost::beast::http::verb::get)(
Nan Zhoua4ce1142022-08-02 18:45:25 +00003208 [](const crow::Request& req,
3209 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07003210 const std::string& systemName, const std::string& logID,
3211 const std::string& fileName) {
Shounak Mitra2a9beee2022-07-20 18:41:30 +00003212 // Do not call getRedfishRoute here since the crashdump file is not a
3213 // Redfish resource.
Ed Tanous22d268c2022-05-19 09:39:07 -07003214
Ed Tanous25b54db2024-04-17 15:40:31 -07003215 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003216 {
3217 // Option currently returns no systems. TBD
3218 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3219 systemName);
3220 return;
3221 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003222 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003223 {
3224 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3225 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003226 return;
3227 }
3228
Ed Tanous002d39b2022-05-31 08:59:27 -07003229 auto getStoredLogCallback =
Ed Tanous39662a32023-02-06 15:09:46 -08003230 [asyncResp, logID, fileName, url(boost::urls::url(req.url()))](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003231 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003232 const std::vector<
3233 std::pair<std::string, dbus::utility::DbusVariantType>>&
3234 resp) {
3235 if (ec)
3236 {
Ed Tanous62598e32023-07-17 17:06:25 -07003237 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07003238 messages::internalError(asyncResp->res);
3239 return;
3240 }
Jason M. Bills8e6c0992021-03-11 16:26:53 -08003241
Ed Tanous002d39b2022-05-31 08:59:27 -07003242 std::string dbusFilename{};
3243 std::string dbusTimestamp{};
3244 std::string dbusFilepath{};
Jason M. Bills8e6c0992021-03-11 16:26:53 -08003245
Ed Tanous002d39b2022-05-31 08:59:27 -07003246 parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
3247 dbusFilepath);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003248
Ed Tanous002d39b2022-05-31 08:59:27 -07003249 if (dbusFilename.empty() || dbusTimestamp.empty() ||
3250 dbusFilepath.empty())
3251 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003252 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003253 return;
3254 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003255
Ed Tanous002d39b2022-05-31 08:59:27 -07003256 // Verify the file name parameter is correct
3257 if (fileName != dbusFilename)
3258 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003259 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003260 return;
3261 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003262
Ed Tanous27b0cf92023-08-07 12:02:40 -07003263 if (!asyncResp->res.openFile(dbusFilepath))
Ed Tanous002d39b2022-05-31 08:59:27 -07003264 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003265 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003266 return;
3267 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003268
Ed Tanous002d39b2022-05-31 08:59:27 -07003269 // Configure this to be a file download when accessed
3270 // from a browser
Ed Tanousd9f6c622022-03-17 09:12:17 -07003271 asyncResp->res.addHeader(
3272 boost::beast::http::field::content_disposition, "attachment");
Ed Tanous002d39b2022-05-31 08:59:27 -07003273 };
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02003274 sdbusplus::asio::getAllProperties(
3275 *crow::connections::systemBus, crashdumpObject,
3276 crashdumpPath + std::string("/") + logID, crashdumpInterface,
3277 std::move(getStoredLogCallback));
Patrick Williams5a39f772023-10-20 11:20:21 -05003278 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003279}
3280
Jason M. Billsc5a4c822022-01-06 15:51:23 -08003281enum class OEMDiagnosticType
3282{
3283 onDemand,
3284 telemetry,
3285 invalid,
3286};
3287
Ed Tanous26ccae32023-02-16 10:28:44 -08003288inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr)
Jason M. Billsc5a4c822022-01-06 15:51:23 -08003289{
3290 if (oemDiagStr == "OnDemand")
3291 {
3292 return OEMDiagnosticType::onDemand;
3293 }
3294 if (oemDiagStr == "Telemetry")
3295 {
3296 return OEMDiagnosticType::telemetry;
3297 }
3298
3299 return OEMDiagnosticType::invalid;
3300}
3301
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003302inline void requestRoutesCrashdumpCollect(App& app)
3303{
3304 // Note: Deviated from redfish privilege registry for GET & HEAD
3305 // method for security reasons.
George Liu0fda0f12021-11-16 10:06:17 +08003306 BMCWEB_ROUTE(
3307 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003308 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07003309 // The below is incorrect; Should be ConfigureManager
3310 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07003311 .privileges({{"ConfigureComponents"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07003312 .methods(boost::beast::http::verb::post)(
3313 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003314 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3315 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003316 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003317 {
3318 return;
3319 }
Ed Tanous22d268c2022-05-19 09:39:07 -07003320
Ed Tanous25b54db2024-04-17 15:40:31 -07003321 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003322 {
3323 // Option currently returns no systems. TBD
3324 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3325 systemName);
3326 return;
3327 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003328 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003329 {
3330 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3331 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003332 return;
3333 }
3334
Ed Tanous002d39b2022-05-31 08:59:27 -07003335 std::string diagnosticDataType;
3336 std::string oemDiagnosticDataType;
3337 if (!redfish::json_util::readJsonAction(
3338 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
3339 "OEMDiagnosticDataType", oemDiagnosticDataType))
3340 {
3341 return;
3342 }
3343
3344 if (diagnosticDataType != "OEM")
3345 {
Ed Tanous62598e32023-07-17 17:06:25 -07003346 BMCWEB_LOG_ERROR(
3347 "Only OEM DiagnosticDataType supported for Crashdump");
Ed Tanous002d39b2022-05-31 08:59:27 -07003348 messages::actionParameterValueFormatError(
3349 asyncResp->res, diagnosticDataType, "DiagnosticDataType",
3350 "CollectDiagnosticData");
3351 return;
3352 }
3353
3354 OEMDiagnosticType oemDiagType =
3355 getOEMDiagnosticType(oemDiagnosticDataType);
3356
3357 std::string iface;
3358 std::string method;
3359 std::string taskMatchStr;
3360 if (oemDiagType == OEMDiagnosticType::onDemand)
3361 {
3362 iface = crashdumpOnDemandInterface;
3363 method = "GenerateOnDemandLog";
3364 taskMatchStr = "type='signal',"
3365 "interface='org.freedesktop.DBus.Properties',"
3366 "member='PropertiesChanged',"
3367 "arg0namespace='com.intel.crashdump'";
3368 }
3369 else if (oemDiagType == OEMDiagnosticType::telemetry)
3370 {
3371 iface = crashdumpTelemetryInterface;
3372 method = "GenerateTelemetryLog";
3373 taskMatchStr = "type='signal',"
3374 "interface='org.freedesktop.DBus.Properties',"
3375 "member='PropertiesChanged',"
3376 "arg0namespace='com.intel.crashdump'";
3377 }
3378 else
3379 {
Ed Tanous62598e32023-07-17 17:06:25 -07003380 BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}",
3381 oemDiagnosticDataType);
Ed Tanous002d39b2022-05-31 08:59:27 -07003382 messages::actionParameterValueFormatError(
3383 asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType",
3384 "CollectDiagnosticData");
3385 return;
3386 }
3387
3388 auto collectCrashdumpCallback =
3389 [asyncResp, payload(task::Payload(req)),
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003390 taskMatchStr](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003391 const std::string&) mutable {
3392 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07003393 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003394 if (ec.value() == boost::system::errc::operation_not_supported)
3395 {
3396 messages::resourceInStandby(asyncResp->res);
3397 }
3398 else if (ec.value() ==
3399 boost::system::errc::device_or_resource_busy)
3400 {
3401 messages::serviceTemporarilyUnavailable(asyncResp->res,
3402 "60");
3403 }
3404 else
3405 {
3406 messages::internalError(asyncResp->res);
3407 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07003408 return;
3409 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003410 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Ed Tanous8b242752023-06-27 17:17:13 -07003411 [](const boost::system::error_code& ec2, sdbusplus::message_t&,
Ed Tanous002d39b2022-05-31 08:59:27 -07003412 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanous8b242752023-06-27 17:17:13 -07003413 if (!ec2)
Ed Tanous002d39b2022-05-31 08:59:27 -07003414 {
3415 taskData->messages.emplace_back(messages::taskCompletedOK(
3416 std::to_string(taskData->index)));
3417 taskData->state = "Completed";
3418 }
3419 return task::completed;
Patrick Williams5a39f772023-10-20 11:20:21 -05003420 },
Ed Tanous002d39b2022-05-31 08:59:27 -07003421 taskMatchStr);
Ed Tanous1da66f72018-07-27 16:13:37 -07003422
Ed Tanous002d39b2022-05-31 08:59:27 -07003423 task->startTimer(std::chrono::minutes(5));
3424 task->populateResp(asyncResp->res);
3425 task->payload.emplace(std::move(payload));
3426 };
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003427
Ed Tanous002d39b2022-05-31 08:59:27 -07003428 crow::connections::systemBus->async_method_call(
3429 std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath,
3430 iface, method);
Patrick Williams5a39f772023-10-20 11:20:21 -05003431 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003432}
Kenny L. Ku6eda7682020-06-19 09:48:36 -07003433
Andrew Geisslercb92c032018-08-17 07:56:14 -07003434/**
3435 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3436 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003437inline void requestRoutesDBusLogServiceActionsClear(App& app)
Andrew Geisslercb92c032018-08-17 07:56:14 -07003438{
Andrew Geisslercb92c032018-08-17 07:56:14 -07003439 /**
3440 * Function handles POST method request.
3441 * The Clear Log actions does not require any parameter.The action deletes
3442 * all entries found in the Entries collection for this Log Service.
3443 */
Andrew Geisslercb92c032018-08-17 07:56:14 -07003444
George Liu0fda0f12021-11-16 10:06:17 +08003445 BMCWEB_ROUTE(
3446 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003447 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07003448 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003449 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003450 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003451 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3452 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003453 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003454 {
3455 return;
3456 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003457 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003458 {
3459 // Option currently returns no systems. TBD
3460 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3461 systemName);
3462 return;
3463 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003464 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003465 {
3466 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3467 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003468 return;
3469 }
Ed Tanous62598e32023-07-17 17:06:25 -07003470 BMCWEB_LOG_DEBUG("Do delete all entries.");
Andrew Geisslercb92c032018-08-17 07:56:14 -07003471
Ed Tanous002d39b2022-05-31 08:59:27 -07003472 // Process response from Logging service.
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003473 auto respHandler = [asyncResp](const boost::system::error_code& ec) {
Ed Tanous62598e32023-07-17 17:06:25 -07003474 BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done");
Ed Tanous002d39b2022-05-31 08:59:27 -07003475 if (ec)
3476 {
3477 // TODO Handle for specific error code
Ed Tanous62598e32023-07-17 17:06:25 -07003478 BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07003479 asyncResp->res.result(
3480 boost::beast::http::status::internal_server_error);
3481 return;
3482 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07003483
Ed Tanous002d39b2022-05-31 08:59:27 -07003484 asyncResp->res.result(boost::beast::http::status::no_content);
3485 };
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003486
Ed Tanous002d39b2022-05-31 08:59:27 -07003487 // Make call to Logging service to request Clear Log
3488 crow::connections::systemBus->async_method_call(
3489 respHandler, "xyz.openbmc_project.Logging",
3490 "/xyz/openbmc_project/logging",
3491 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Patrick Williams5a39f772023-10-20 11:20:21 -05003492 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003493}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003494
3495/****************************************************
3496 * Redfish PostCode interfaces
3497 * using DBUS interface: getPostCodesTS
3498 ******************************************************/
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003499inline void requestRoutesPostCodesLogService(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003500{
Ed Tanous22d268c2022-05-19 09:39:07 -07003501 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/")
Ed Tanoused398212021-06-09 17:05:54 -07003502 .privileges(redfish::privileges::getLogService)
Ed Tanous002d39b2022-05-31 08:59:27 -07003503 .methods(boost::beast::http::verb::get)(
3504 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003505 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3506 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003507 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003508 {
3509 return;
3510 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003511 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003512 {
3513 // Option currently returns no systems. TBD
3514 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3515 systemName);
3516 return;
3517 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003518 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003519 {
3520 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3521 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003522 return;
3523 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003524 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003525 std::format("/redfish/v1/Systems/{}/LogServices/PostCodes",
3526 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07003527 asyncResp->res.jsonValue["@odata.type"] =
Janet Adkinsb25644a2023-08-16 11:23:45 -05003528 "#LogService.v1_2_0.LogService";
Ed Tanous002d39b2022-05-31 08:59:27 -07003529 asyncResp->res.jsonValue["Name"] = "POST Code Log Service";
3530 asyncResp->res.jsonValue["Description"] = "POST Code Log Service";
Ed Tanoused34a4a2023-02-08 15:43:27 -08003531 asyncResp->res.jsonValue["Id"] = "PostCodes";
Ed Tanous539d8c62024-06-19 14:38:27 -07003532 asyncResp->res.jsonValue["OverWritePolicy"] =
3533 log_service::OverWritePolicy::WrapsWhenFull;
Ed Tanous002d39b2022-05-31 08:59:27 -07003534 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003535 std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries",
3536 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Tejas Patil7c8c4052021-06-04 17:43:14 +05303537
Ed Tanous002d39b2022-05-31 08:59:27 -07003538 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07003539 redfish::time_utils::getDateTimeOffsetNow();
Ed Tanous002d39b2022-05-31 08:59:27 -07003540 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
3541 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
3542 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05303543
Ed Tanous20fa6a22024-05-20 18:02:58 -07003544 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
3545 ["target"] = std::format(
3546 "/redfish/v1/Systems/{}/LogServices/PostCodes/Actions/LogService.ClearLog",
3547 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05003548 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003549}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003550
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003551inline void requestRoutesPostCodesClear(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003552{
George Liu0fda0f12021-11-16 10:06:17 +08003553 BMCWEB_ROUTE(
3554 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003555 "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07003556 // The following privilege is incorrect; It should be ConfigureManager
3557 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07003558 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003559 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003560 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003561 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3562 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003563 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003564 {
3565 return;
3566 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003567 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003568 {
3569 // Option currently returns no systems. TBD
3570 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3571 systemName);
3572 return;
3573 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003574 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003575 {
3576 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3577 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003578 return;
3579 }
Ed Tanous62598e32023-07-17 17:06:25 -07003580 BMCWEB_LOG_DEBUG("Do delete all postcodes entries.");
ZhikuiRena3316fc2020-01-29 14:58:08 -08003581
Ed Tanous002d39b2022-05-31 08:59:27 -07003582 // Make call to post-code service to request clear all
3583 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003584 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003585 if (ec)
3586 {
3587 // TODO Handle for specific error code
Ed Tanous62598e32023-07-17 17:06:25 -07003588 BMCWEB_LOG_ERROR("doClearPostCodes resp_handler got error {}",
3589 ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07003590 asyncResp->res.result(
3591 boost::beast::http::status::internal_server_error);
3592 messages::internalError(asyncResp->res);
3593 return;
3594 }
Tony Lee18fc70c2023-08-24 16:15:54 +08003595 messages::success(asyncResp->res);
Patrick Williams5a39f772023-10-20 11:20:21 -05003596 },
Ed Tanous002d39b2022-05-31 08:59:27 -07003597 "xyz.openbmc_project.State.Boot.PostCode0",
3598 "/xyz/openbmc_project/State/Boot/PostCode0",
3599 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Patrick Williams5a39f772023-10-20 11:20:21 -05003600 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003601}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003602
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003603/**
3604 * @brief Parse post code ID and get the current value and index value
3605 * eg: postCodeID=B1-2, currentValue=1, index=2
3606 *
3607 * @param[in] postCodeID Post Code ID
3608 * @param[out] currentValue Current value
3609 * @param[out] index Index value
3610 *
3611 * @return bool true if the parsing is successful, false the parsing fails
3612 */
Ed Tanous6f056f22024-04-07 13:35:51 -07003613inline bool parsePostCode(std::string_view postCodeID, uint64_t& currentValue,
Ed Tanousdf254f22024-04-01 13:25:46 -07003614 uint16_t& index)
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003615{
3616 std::vector<std::string> split;
Ed Tanous50ebd4a2023-01-19 19:03:17 -08003617 bmcweb::split(split, postCodeID, '-');
Ed Tanous6f056f22024-04-07 13:35:51 -07003618 if (split.size() != 2)
3619 {
3620 return false;
3621 }
3622 std::string_view postCodeNumber = split[0];
3623 if (postCodeNumber.size() < 2)
3624 {
3625 return false;
3626 }
3627 if (postCodeNumber[0] != 'B')
3628 {
3629 return false;
3630 }
3631 postCodeNumber.remove_prefix(1);
3632 auto [ptrIndex, ecIndex] = std::from_chars(postCodeNumber.begin(),
3633 postCodeNumber.end(), index);
3634 if (ptrIndex != postCodeNumber.end() || ecIndex != std::errc())
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003635 {
3636 return false;
3637 }
3638
Ed Tanous6f056f22024-04-07 13:35:51 -07003639 std::string_view postCodeIndex = split[1];
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003640
Ed Tanous6f056f22024-04-07 13:35:51 -07003641 auto [ptrValue, ecValue] = std::from_chars(
3642 postCodeIndex.begin(), postCodeIndex.end(), currentValue);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003643
Ed Tanous6f056f22024-04-07 13:35:51 -07003644 return ptrValue == postCodeIndex.end() && ecValue == std::errc();
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003645}
3646
3647static bool fillPostCodeEntry(
Ed Tanousac106bf2023-06-07 09:24:59 -07003648 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303649 const boost::container::flat_map<
3650 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003651 const uint16_t bootIndex, const uint64_t codeIndex = 0,
3652 const uint64_t skip = 0, const uint64_t top = 0)
3653{
3654 // Get the Message from the MessageRegistry
Ed Tanousfffb8c12022-02-07 23:53:03 -08003655 const registries::Message* message =
3656 registries::getMessage("OpenBMC.0.2.BIOSPOSTCode");
Ed Tanousdc8cfa62024-04-07 13:37:25 -07003657 if (message == nullptr)
3658 {
3659 BMCWEB_LOG_ERROR("Couldn't find known message?");
3660 return false;
3661 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003662 uint64_t currentCodeIndex = 0;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003663 uint64_t firstCodeTimeUs = 0;
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303664 for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3665 code : postcode)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003666 {
3667 currentCodeIndex++;
3668 std::string postcodeEntryID =
3669 "B" + std::to_string(bootIndex) + "-" +
3670 std::to_string(currentCodeIndex); // 1 based index in EntryID string
3671
3672 uint64_t usecSinceEpoch = code.first;
3673 uint64_t usTimeOffset = 0;
3674
3675 if (1 == currentCodeIndex)
3676 { // already incremented
3677 firstCodeTimeUs = code.first;
3678 }
3679 else
3680 {
3681 usTimeOffset = code.first - firstCodeTimeUs;
3682 }
3683
3684 // skip if no specific codeIndex is specified and currentCodeIndex does
3685 // not fall between top and skip
3686 if ((codeIndex == 0) &&
3687 (currentCodeIndex <= skip || currentCodeIndex > top))
3688 {
3689 continue;
3690 }
3691
Gunnar Mills4e0453b2020-07-08 14:00:30 -05003692 // skip if a specific codeIndex is specified and does not match the
ZhikuiRena3316fc2020-01-29 14:58:08 -08003693 // currentIndex
3694 if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3695 {
3696 // This is done for simplicity. 1st entry is needed to calculate
3697 // time offset. To improve efficiency, one can get to the entry
3698 // directly (possibly with flatmap's nth method)
3699 continue;
3700 }
3701
3702 // currentCodeIndex is within top and skip or equal to specified code
3703 // index
3704
3705 // Get the Created time from the timestamp
3706 std::string entryTimeStr;
Konstantin Aladyshev2a025612023-02-15 11:52:58 +03003707 entryTimeStr = redfish::time_utils::getDateTimeUintUs(usecSinceEpoch);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003708
3709 // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3710 std::ostringstream hexCode;
3711 hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303712 << std::get<0>(code.second);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003713 std::ostringstream timeOffsetStr;
3714 // Set Fixed -Point Notation
3715 timeOffsetStr << std::fixed;
3716 // Set precision to 4 digits
3717 timeOffsetStr << std::setprecision(4);
3718 // Add double to stream
3719 timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003720
Ed Tanous1e6deaf2022-02-17 11:32:37 -08003721 std::string bootIndexStr = std::to_string(bootIndex);
3722 std::string timeOffsetString = timeOffsetStr.str();
3723 std::string hexCodeStr = hexCode.str();
3724
3725 std::array<std::string_view, 3> messageArgs = {
3726 bootIndexStr, timeOffsetString, hexCodeStr};
3727
3728 std::string msg =
3729 redfish::registries::fillMessageArgs(messageArgs, message->message);
3730 if (msg.empty())
ZhikuiRena3316fc2020-01-29 14:58:08 -08003731 {
Ed Tanous1e6deaf2022-02-17 11:32:37 -08003732 messages::internalError(asyncResp->res);
3733 return false;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003734 }
3735
Tim Leed4342a92020-04-27 11:47:58 +08003736 // Get Severity template from message registry
3737 std::string severity;
3738 if (message != nullptr)
3739 {
Ed Tanous5f2b84e2022-02-08 00:41:53 -08003740 severity = message->messageSeverity;
Tim Leed4342a92020-04-27 11:47:58 +08003741 }
3742
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003743 // Format entry
3744 nlohmann::json::object_t bmcLogEntry;
Vijay Lobo9c11a172021-10-07 16:53:16 -05003745 bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07003746 bmcLogEntry["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07003747 "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/{}",
3748 BMCWEB_REDFISH_SYSTEM_URI_NAME, postcodeEntryID);
Jason M. Bills84afc482022-06-24 12:38:23 -07003749 bmcLogEntry["Name"] = "POST Code Log Entry";
3750 bmcLogEntry["Id"] = postcodeEntryID;
3751 bmcLogEntry["Message"] = std::move(msg);
3752 bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode";
Ed Tanous1e6deaf2022-02-17 11:32:37 -08003753 bmcLogEntry["MessageArgs"] = messageArgs;
Jason M. Bills84afc482022-06-24 12:38:23 -07003754 bmcLogEntry["EntryType"] = "Event";
3755 bmcLogEntry["Severity"] = std::move(severity);
3756 bmcLogEntry["Created"] = entryTimeStr;
George Liu647b3cd2021-07-05 12:43:56 +08003757 if (!std::get<std::vector<uint8_t>>(code.second).empty())
3758 {
3759 bmcLogEntry["AdditionalDataURI"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003760 std::format(
3761 "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/",
3762 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
George Liu647b3cd2021-07-05 12:43:56 +08003763 postcodeEntryID + "/attachment";
3764 }
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003765
3766 // codeIndex is only specified when querying single entry, return only
3767 // that entry in this case
3768 if (codeIndex != 0)
3769 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003770 asyncResp->res.jsonValue.update(bmcLogEntry);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003771 return true;
3772 }
3773
Ed Tanousac106bf2023-06-07 09:24:59 -07003774 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Patrick Williamsb2ba3072023-05-12 10:27:39 -05003775 logEntryArray.emplace_back(std::move(bmcLogEntry));
ZhikuiRena3316fc2020-01-29 14:58:08 -08003776 }
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003777
3778 // Return value is always false when querying multiple entries
3779 return false;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003780}
3781
Ed Tanousac106bf2023-06-07 09:24:59 -07003782static void
3783 getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3784 const std::string& entryId)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003785{
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003786 uint16_t bootIndex = 0;
3787 uint64_t codeIndex = 0;
3788 if (!parsePostCode(entryId, codeIndex, bootIndex))
3789 {
3790 // Requested ID was not found
Ed Tanousac106bf2023-06-07 09:24:59 -07003791 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003792 return;
3793 }
3794
3795 if (bootIndex == 0 || codeIndex == 0)
3796 {
3797 // 0 is an invalid index
Ed Tanousac106bf2023-06-07 09:24:59 -07003798 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003799 return;
3800 }
3801
ZhikuiRena3316fc2020-01-29 14:58:08 -08003802 crow::connections::systemBus->async_method_call(
Ed Tanousac106bf2023-06-07 09:24:59 -07003803 [asyncResp, entryId, bootIndex,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003804 codeIndex](const boost::system::error_code& ec,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303805 const boost::container::flat_map<
3806 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3807 postcode) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003808 if (ec)
3809 {
Ed Tanous62598e32023-07-17 17:06:25 -07003810 BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error");
Ed Tanousac106bf2023-06-07 09:24:59 -07003811 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -07003812 return;
3813 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003814
Ed Tanous002d39b2022-05-31 08:59:27 -07003815 if (postcode.empty())
3816 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003817 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Ed Tanous002d39b2022-05-31 08:59:27 -07003818 return;
3819 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003820
Ed Tanousac106bf2023-06-07 09:24:59 -07003821 if (!fillPostCodeEntry(asyncResp, postcode, bootIndex, codeIndex))
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003822 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003823 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003824 return;
3825 }
Patrick Williams5a39f772023-10-20 11:20:21 -05003826 },
Jonathan Doman15124762021-01-07 17:54:17 -08003827 "xyz.openbmc_project.State.Boot.PostCode0",
3828 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003829 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3830 bootIndex);
3831}
3832
Ed Tanousac106bf2023-06-07 09:24:59 -07003833static void
3834 getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3835 const uint16_t bootIndex, const uint16_t bootCount,
3836 const uint64_t entryCount, size_t skip, size_t top)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003837{
3838 crow::connections::systemBus->async_method_call(
Ed Tanousac106bf2023-06-07 09:24:59 -07003839 [asyncResp, bootIndex, bootCount, entryCount, skip,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003840 top](const boost::system::error_code& ec,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303841 const boost::container::flat_map<
3842 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3843 postcode) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003844 if (ec)
3845 {
Ed Tanous62598e32023-07-17 17:06:25 -07003846 BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error");
Ed Tanousac106bf2023-06-07 09:24:59 -07003847 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -07003848 return;
3849 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003850
Ed Tanous002d39b2022-05-31 08:59:27 -07003851 uint64_t endCount = entryCount;
3852 if (!postcode.empty())
3853 {
3854 endCount = entryCount + postcode.size();
Ed Tanous3648c8b2022-07-25 13:39:59 -07003855 if (skip < endCount && (top + skip) > entryCount)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003856 {
Patrick Williams89492a12023-05-10 07:51:34 -05003857 uint64_t thisBootSkip = std::max(static_cast<uint64_t>(skip),
3858 entryCount) -
3859 entryCount;
Ed Tanous002d39b2022-05-31 08:59:27 -07003860 uint64_t thisBootTop =
Ed Tanous3648c8b2022-07-25 13:39:59 -07003861 std::min(static_cast<uint64_t>(top + skip), endCount) -
3862 entryCount;
Ed Tanous002d39b2022-05-31 08:59:27 -07003863
Ed Tanousac106bf2023-06-07 09:24:59 -07003864 fillPostCodeEntry(asyncResp, postcode, bootIndex, 0,
3865 thisBootSkip, thisBootTop);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003866 }
Ed Tanousac106bf2023-06-07 09:24:59 -07003867 asyncResp->res.jsonValue["Members@odata.count"] = endCount;
Ed Tanous002d39b2022-05-31 08:59:27 -07003868 }
3869
3870 // continue to previous bootIndex
3871 if (bootIndex < bootCount)
3872 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003873 getPostCodeForBoot(asyncResp, static_cast<uint16_t>(bootIndex + 1),
Ed Tanous002d39b2022-05-31 08:59:27 -07003874 bootCount, endCount, skip, top);
3875 }
Jiaqing Zhao81584ab2022-07-28 00:33:45 +08003876 else if (skip + top < endCount)
Ed Tanous002d39b2022-05-31 08:59:27 -07003877 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003878 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003879 std::format(
3880 "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries?$skip=",
3881 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous002d39b2022-05-31 08:59:27 -07003882 std::to_string(skip + top);
3883 }
Patrick Williams5a39f772023-10-20 11:20:21 -05003884 },
Jonathan Doman15124762021-01-07 17:54:17 -08003885 "xyz.openbmc_project.State.Boot.PostCode0",
3886 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003887 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3888 bootIndex);
3889}
3890
zhanghch058d1b46d2021-04-01 11:18:24 +08003891static void
Ed Tanousac106bf2023-06-07 09:24:59 -07003892 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous3648c8b2022-07-25 13:39:59 -07003893 size_t skip, size_t top)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003894{
3895 uint64_t entryCount = 0;
Jonathan Doman1e1e5982021-06-11 09:36:17 -07003896 sdbusplus::asio::getProperty<uint16_t>(
3897 *crow::connections::systemBus,
3898 "xyz.openbmc_project.State.Boot.PostCode0",
3899 "/xyz/openbmc_project/State/Boot/PostCode0",
3900 "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount",
Ed Tanousac106bf2023-06-07 09:24:59 -07003901 [asyncResp, entryCount, skip, top](const boost::system::error_code& ec,
3902 const uint16_t bootCount) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003903 if (ec)
3904 {
Ed Tanous62598e32023-07-17 17:06:25 -07003905 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
Ed Tanousac106bf2023-06-07 09:24:59 -07003906 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -07003907 return;
3908 }
Ed Tanousac106bf2023-06-07 09:24:59 -07003909 getPostCodeForBoot(asyncResp, 1, bootCount, entryCount, skip, top);
Patrick Williams5a39f772023-10-20 11:20:21 -05003910 });
ZhikuiRena3316fc2020-01-29 14:58:08 -08003911}
3912
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003913inline void requestRoutesPostCodesEntryCollection(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003914{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003915 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003916 "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07003917 .privileges(redfish::privileges::getLogEntryCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003918 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003919 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003920 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3921 const std::string& systemName) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003922 query_param::QueryCapabilities capabilities = {
3923 .canDelegateTop = true,
3924 .canDelegateSkip = true,
3925 };
3926 query_param::Query delegatedQuery;
3927 if (!redfish::setUpRedfishRouteWithDelegation(
Carson Labrado3ba00072022-06-06 19:40:56 +00003928 app, req, asyncResp, delegatedQuery, capabilities))
Ed Tanous002d39b2022-05-31 08:59:27 -07003929 {
3930 return;
3931 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003932 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003933 {
3934 // Option currently returns no systems. TBD
3935 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3936 systemName);
3937 return;
3938 }
Ed Tanous22d268c2022-05-19 09:39:07 -07003939
Ed Tanous253f11b2024-05-16 09:38:31 -07003940 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003941 {
3942 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3943 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003944 return;
3945 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003946 asyncResp->res.jsonValue["@odata.type"] =
3947 "#LogEntryCollection.LogEntryCollection";
3948 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003949 std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries",
3950 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07003951 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3952 asyncResp->res.jsonValue["Description"] =
3953 "Collection of POST Code Log Entries";
3954 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3955 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Ed Tanous3648c8b2022-07-25 13:39:59 -07003956 size_t skip = delegatedQuery.skip.value_or(0);
Jiaqing Zhao5143f7a2022-07-22 09:33:33 +08003957 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
Ed Tanous3648c8b2022-07-25 13:39:59 -07003958 getCurrentBootNumber(asyncResp, skip, top);
Patrick Williams5a39f772023-10-20 11:20:21 -05003959 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003960}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003961
George Liu647b3cd2021-07-05 12:43:56 +08003962inline void requestRoutesPostCodesEntryAdditionalData(App& app)
3963{
George Liu0fda0f12021-11-16 10:06:17 +08003964 BMCWEB_ROUTE(
3965 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003966 "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/")
George Liu647b3cd2021-07-05 12:43:56 +08003967 .privileges(redfish::privileges::getLogEntry)
3968 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003969 [&app](const crow::Request& req,
3970 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07003971 const std::string& systemName,
Ed Tanous45ca1b82022-03-25 13:07:27 -07003972 const std::string& postCodeID) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003973 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003974 {
3975 return;
3976 }
Matt Spinler72e21372023-04-19 12:53:33 -05003977 if (!http_helpers::isContentTypeAllowed(
Ed Tanous99351cd2022-08-07 16:42:51 -07003978 req.getHeaderValue("Accept"),
Ed Tanous4a0e1a02022-09-21 15:28:04 -07003979 http_helpers::ContentType::OctetStream, true))
Ed Tanous002d39b2022-05-31 08:59:27 -07003980 {
3981 asyncResp->res.result(boost::beast::http::status::bad_request);
3982 return;
3983 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003984 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003985 {
3986 // Option currently returns no systems. TBD
3987 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3988 systemName);
3989 return;
3990 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003991 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003992 {
3993 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3994 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003995 return;
3996 }
George Liu647b3cd2021-07-05 12:43:56 +08003997
Ed Tanous002d39b2022-05-31 08:59:27 -07003998 uint64_t currentValue = 0;
3999 uint16_t index = 0;
4000 if (!parsePostCode(postCodeID, currentValue, index))
4001 {
4002 messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID);
4003 return;
4004 }
George Liu647b3cd2021-07-05 12:43:56 +08004005
Ed Tanous002d39b2022-05-31 08:59:27 -07004006 crow::connections::systemBus->async_method_call(
4007 [asyncResp, postCodeID, currentValue](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08004008 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07004009 const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>&
4010 postcodes) {
4011 if (ec.value() == EBADR)
4012 {
4013 messages::resourceNotFound(asyncResp->res, "LogEntry",
4014 postCodeID);
4015 return;
4016 }
4017 if (ec)
4018 {
Ed Tanous62598e32023-07-17 17:06:25 -07004019 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07004020 messages::internalError(asyncResp->res);
4021 return;
4022 }
George Liu647b3cd2021-07-05 12:43:56 +08004023
Ed Tanous002d39b2022-05-31 08:59:27 -07004024 size_t value = static_cast<size_t>(currentValue) - 1;
4025 if (value == std::string::npos || postcodes.size() < currentValue)
4026 {
Ed Tanous62598e32023-07-17 17:06:25 -07004027 BMCWEB_LOG_WARNING("Wrong currentValue value");
Ed Tanous002d39b2022-05-31 08:59:27 -07004028 messages::resourceNotFound(asyncResp->res, "LogEntry",
4029 postCodeID);
4030 return;
4031 }
George Liu647b3cd2021-07-05 12:43:56 +08004032
Ed Tanous002d39b2022-05-31 08:59:27 -07004033 const auto& [tID, c] = postcodes[value];
4034 if (c.empty())
4035 {
Ed Tanous62598e32023-07-17 17:06:25 -07004036 BMCWEB_LOG_WARNING("No found post code data");
Ed Tanous002d39b2022-05-31 08:59:27 -07004037 messages::resourceNotFound(asyncResp->res, "LogEntry",
4038 postCodeID);
4039 return;
4040 }
4041 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
4042 const char* d = reinterpret_cast<const char*>(c.data());
4043 std::string_view strData(d, c.size());
George Liu647b3cd2021-07-05 12:43:56 +08004044
Ed Tanousd9f6c622022-03-17 09:12:17 -07004045 asyncResp->res.addHeader(boost::beast::http::field::content_type,
Ed Tanous002d39b2022-05-31 08:59:27 -07004046 "application/octet-stream");
Ed Tanousd9f6c622022-03-17 09:12:17 -07004047 asyncResp->res.addHeader(
4048 boost::beast::http::field::content_transfer_encoding, "Base64");
Ed Tanous27b0cf92023-08-07 12:02:40 -07004049 asyncResp->res.write(crow::utility::base64encode(strData));
Patrick Williams5a39f772023-10-20 11:20:21 -05004050 },
Ed Tanous002d39b2022-05-31 08:59:27 -07004051 "xyz.openbmc_project.State.Boot.PostCode0",
4052 "/xyz/openbmc_project/State/Boot/PostCode0",
4053 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index);
Patrick Williams5a39f772023-10-20 11:20:21 -05004054 });
George Liu647b3cd2021-07-05 12:43:56 +08004055}
4056
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004057inline void requestRoutesPostCodesEntry(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08004058{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004059 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07004060 app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07004061 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004062 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07004063 [&app](const crow::Request& req,
4064 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07004065 const std::string& systemName, const std::string& targetID) {
Carson Labrado3ba00072022-06-06 19:40:56 +00004066 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07004067 {
4068 return;
4069 }
Ed Tanous25b54db2024-04-17 15:40:31 -07004070 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08004071 {
4072 // Option currently returns no systems. TBD
4073 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
4074 systemName);
4075 return;
4076 }
Ed Tanous253f11b2024-05-16 09:38:31 -07004077 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07004078 {
4079 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
4080 systemName);
4081 return;
4082 }
4083
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08004084 getPostCodeForEntry(asyncResp, targetID);
Patrick Williams5a39f772023-10-20 11:20:21 -05004085 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004086}
ZhikuiRena3316fc2020-01-29 14:58:08 -08004087
Ed Tanous1da66f72018-07-27 16:13:37 -07004088} // namespace redfish