blob: 540a1be98e8eec32bb5acf4af3e0874db13c514f [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"
Spencer Kub7028eb2021-10-26 15:27:35 +080022#include "gzfile.hpp"
George Liu647b3cd2021-07-05 12:43:56 +080023#include "http_utility.hpp"
Spencer Kub7028eb2021-10-26 15:27:35 +080024#include "human_sort.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080025#include "query.hpp"
Jason M. Bills4851d452019-03-28 11:27:48 -070026#include "registries.hpp"
27#include "registries/base_message_registry.hpp"
28#include "registries/openbmc_message_registry.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080029#include "registries/privilege_registry.hpp"
James Feist46229572020-02-19 15:11:58 -080030#include "task.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070031#include "task_messages.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080032#include "utils/dbus_utils.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070033#include "utils/json_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080034#include "utils/time_utils.hpp"
Ed Tanous1da66f72018-07-27 16:13:37 -070035
Myung Bae75e8e212023-11-30 12:53:46 -080036#include <systemd/sd-id128.h>
Asmitha Karunanithi8e317782020-12-10 03:35:05 -060037#include <tinyxml2.h>
Adriana Kobylak400fd1f2021-01-29 09:01:30 -060038#include <unistd.h>
Jason M. Billse1f26342018-07-18 12:12:00 -070039
Ed Tanous07c8c202022-07-11 10:08:08 -070040#include <boost/beast/http/verb.hpp>
Ed Tanous1da66f72018-07-27 16:13:37 -070041#include <boost/container/flat_map.hpp>
Jason M. Bills1ddcf012019-11-26 14:59:21 -080042#include <boost/system/linux_error.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070043#include <boost/url/format.hpp>
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +020044#include <sdbusplus/asio/property.hpp>
45#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050046
George Liu7a1dbc42022-12-07 16:03:22 +080047#include <array>
George Liu647b3cd2021-07-05 12:43:56 +080048#include <charconv>
Abhilash Rajub5f288d2023-11-08 22:32:44 -060049#include <cstddef>
James Feist4418c7f2019-04-15 11:09:15 -070050#include <filesystem>
Ed Tanous18f8f602023-07-18 10:07:23 -070051#include <iterator>
Xiaochao Ma75710de2021-01-21 17:56:02 +080052#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070053#include <ranges>
Ed Tanous26702d02021-11-03 15:02:33 -070054#include <span>
Ed Tanous18f8f602023-07-18 10:07:23 -070055#include <string>
Jason M. Billscd225da2019-05-08 15:31:57 -070056#include <string_view>
Ed Tanousabf2add2019-01-22 16:40:12 -080057#include <variant>
Ed Tanous1da66f72018-07-27 16:13:37 -070058
59namespace redfish
60{
61
Patrick Williams89492a12023-05-10 07:51:34 -050062constexpr const char* crashdumpObject = "com.intel.crashdump";
63constexpr const char* crashdumpPath = "/com/intel/crashdump";
64constexpr const char* crashdumpInterface = "com.intel.crashdump";
65constexpr const char* deleteAllInterface =
Jason M. Bills5b61b5e2019-10-16 10:59:02 -070066 "xyz.openbmc_project.Collection.DeleteAll";
Patrick Williams89492a12023-05-10 07:51:34 -050067constexpr const char* crashdumpOnDemandInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070068 "com.intel.crashdump.OnDemand";
Patrick Williams89492a12023-05-10 07:51:34 -050069constexpr const char* crashdumpTelemetryInterface =
Kenny L. Ku6eda7682020-06-19 09:48:36 -070070 "com.intel.crashdump.Telemetry";
Ed Tanous1da66f72018-07-27 16:13:37 -070071
Asmitha Karunanithi8e317782020-12-10 03:35:05 -060072enum class DumpCreationProgress
73{
74 DUMP_CREATE_SUCCESS,
75 DUMP_CREATE_FAILED,
76 DUMP_CREATE_INPROGRESS
77};
78
James Feistf6150402019-01-08 10:36:20 -080079namespace fs = std::filesystem;
Ed Tanous1da66f72018-07-27 16:13:37 -070080
Gunnar Mills1214b7e2020-06-04 10:11:30 -050081inline std::string translateSeverityDbusToRedfish(const std::string& s)
Andrew Geisslercb92c032018-08-17 07:56:14 -070082{
Ed Tanousd4d25792020-09-29 15:15:03 -070083 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
84 (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
85 (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
86 (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
Andrew Geisslercb92c032018-08-17 07:56:14 -070087 {
88 return "Critical";
89 }
Ed Tanous3174e4d2020-10-07 11:41:22 -070090 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
91 (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
92 (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
Andrew Geisslercb92c032018-08-17 07:56:14 -070093 {
94 return "OK";
95 }
Ed Tanous3174e4d2020-10-07 11:41:22 -070096 if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
Andrew Geisslercb92c032018-08-17 07:56:14 -070097 {
98 return "Warning";
99 }
100 return "";
101}
102
Abhishek Patel9017faf2021-09-14 22:48:55 -0500103inline std::optional<bool> getProviderNotifyAction(const std::string& notify)
104{
105 std::optional<bool> notifyAction;
106 if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify")
107 {
108 notifyAction = true;
109 }
110 else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit")
111 {
112 notifyAction = false;
113 }
114
115 return notifyAction;
116}
117
Ed Tanous18f8f602023-07-18 10:07:23 -0700118inline std::string getDumpPath(std::string_view dumpType)
119{
120 std::string dbusDumpPath = "/xyz/openbmc_project/dump/";
121 std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath),
122 bmcweb::asciiToLower);
123
124 return dbusDumpPath;
125}
126
Ed Tanous055713e2024-07-17 17:19:36 -0700127inline bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700128 const bool firstEntry = true)
Jason M. Bills95820182019-04-22 16:25:34 -0700129{
Ed Tanous271584a2019-07-09 16:24:22 -0700130 static time_t prevTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700131 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700132 if (firstEntry)
133 {
134 prevTs = 0;
135 }
136
Jason M. Bills95820182019-04-22 16:25:34 -0700137 // Get the entry timestamp
Ed Tanous271584a2019-07-09 16:24:22 -0700138 std::time_t curTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700139 std::tm timeStruct = {};
140 std::istringstream entryStream(logEntry);
141 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
142 {
143 curTs = std::mktime(&timeStruct);
144 }
145 // If the timestamp isn't unique, increment the index
146 if (curTs == prevTs)
147 {
148 index++;
149 }
150 else
151 {
152 // Otherwise, reset it
153 index = 0;
154 }
155 // Save the timestamp
156 prevTs = curTs;
157
158 entryID = std::to_string(curTs);
159 if (index > 0)
160 {
161 entryID += "_" + std::to_string(index);
162 }
163 return true;
164}
165
Jason M. Bills95820182019-04-22 16:25:34 -0700166static bool
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500167 getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
Jason M. Bills95820182019-04-22 16:25:34 -0700168{
169 static const std::filesystem::path redfishLogDir = "/var/log";
170 static const std::string redfishLogFilename = "redfish";
171
172 // Loop through the directory looking for redfish log files
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500173 for (const std::filesystem::directory_entry& dirEnt :
Jason M. Bills95820182019-04-22 16:25:34 -0700174 std::filesystem::directory_iterator(redfishLogDir))
175 {
176 // If we find a redfish log file, save the path
177 std::string filename = dirEnt.path().filename();
Ed Tanous11ba3972022-07-11 09:50:41 -0700178 if (filename.starts_with(redfishLogFilename))
Jason M. Bills95820182019-04-22 16:25:34 -0700179 {
180 redfishLogFiles.emplace_back(redfishLogDir / filename);
181 }
182 }
183 // As the log files rotate, they are appended with a ".#" that is higher for
184 // the older logs. Since we don't expect more than 10 log files, we
185 // can just sort the list to get them in order from newest to oldest
Ed Tanous3544d2a2023-08-06 18:12:20 -0700186 std::ranges::sort(redfishLogFiles);
Jason M. Bills95820182019-04-22 16:25:34 -0700187
188 return !redfishLogFiles.empty();
189}
190
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600191inline log_entry::OriginatorTypes
192 mapDbusOriginatorTypeToRedfish(const std::string& originatorType)
193{
194 if (originatorType ==
195 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client")
196 {
197 return log_entry::OriginatorTypes::Client;
198 }
199 if (originatorType ==
200 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal")
201 {
202 return log_entry::OriginatorTypes::Internal;
203 }
204 if (originatorType ==
205 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService")
206 {
207 return log_entry::OriginatorTypes::SupportingService;
208 }
209 return log_entry::OriginatorTypes::Invalid;
210}
211
Claire Weinanaefe3782022-07-15 19:17:19 -0700212inline void parseDumpEntryFromDbusObject(
Jiaqing Zhao2d613eb2022-08-15 16:03:00 +0800213 const dbus::utility::ManagedObjectType::value_type& object,
Claire Weinanc6fecda2022-07-15 10:43:25 -0700214 std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs,
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600215 std::string& originatorId, log_entry::OriginatorTypes& originatorType,
Claire Weinanaefe3782022-07-15 19:17:19 -0700216 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
217{
218 for (const auto& interfaceMap : object.second)
219 {
220 if (interfaceMap.first == "xyz.openbmc_project.Common.Progress")
221 {
222 for (const auto& propertyMap : interfaceMap.second)
223 {
224 if (propertyMap.first == "Status")
225 {
226 const auto* status =
227 std::get_if<std::string>(&propertyMap.second);
228 if (status == nullptr)
229 {
230 messages::internalError(asyncResp->res);
231 break;
232 }
233 dumpStatus = *status;
234 }
235 }
236 }
237 else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
238 {
239 for (const auto& propertyMap : interfaceMap.second)
240 {
241 if (propertyMap.first == "Size")
242 {
243 const auto* sizePtr =
244 std::get_if<uint64_t>(&propertyMap.second);
245 if (sizePtr == nullptr)
246 {
247 messages::internalError(asyncResp->res);
248 break;
249 }
250 size = *sizePtr;
251 break;
252 }
253 }
254 }
255 else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime")
256 {
257 for (const auto& propertyMap : interfaceMap.second)
258 {
259 if (propertyMap.first == "Elapsed")
260 {
261 const uint64_t* usecsTimeStamp =
262 std::get_if<uint64_t>(&propertyMap.second);
263 if (usecsTimeStamp == nullptr)
264 {
265 messages::internalError(asyncResp->res);
266 break;
267 }
Claire Weinanc6fecda2022-07-15 10:43:25 -0700268 timestampUs = *usecsTimeStamp;
Claire Weinanaefe3782022-07-15 19:17:19 -0700269 break;
270 }
271 }
272 }
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600273 else if (interfaceMap.first ==
274 "xyz.openbmc_project.Common.OriginatedBy")
275 {
276 for (const auto& propertyMap : interfaceMap.second)
277 {
278 if (propertyMap.first == "OriginatorId")
279 {
280 const std::string* id =
281 std::get_if<std::string>(&propertyMap.second);
282 if (id == nullptr)
283 {
284 messages::internalError(asyncResp->res);
285 break;
286 }
287 originatorId = *id;
288 }
289
290 if (propertyMap.first == "OriginatorType")
291 {
292 const std::string* type =
293 std::get_if<std::string>(&propertyMap.second);
294 if (type == nullptr)
295 {
296 messages::internalError(asyncResp->res);
297 break;
298 }
299
300 originatorType = mapDbusOriginatorTypeToRedfish(*type);
301 if (originatorType == log_entry::OriginatorTypes::Invalid)
302 {
303 messages::internalError(asyncResp->res);
304 break;
305 }
306 }
307 }
308 }
Claire Weinanaefe3782022-07-15 19:17:19 -0700309 }
310}
311
Nan Zhou21ab4042022-06-26 23:07:40 +0000312static std::string getDumpEntriesPath(const std::string& dumpType)
Claire Weinanfdd26902022-03-01 14:18:25 -0800313{
314 std::string entriesPath;
315
316 if (dumpType == "BMC")
317 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700318 entriesPath =
319 std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
320 BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800321 }
322 else if (dumpType == "FaultLog")
323 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700324 entriesPath =
325 std::format("/redfish/v1/Managers/{}/LogServices/FaultLog/Entries/",
326 BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800327 }
328 else if (dumpType == "System")
329 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700330 entriesPath =
331 std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
332 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -0800333 }
334 else
335 {
Ed Tanous62598e32023-07-17 17:06:25 -0700336 BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}",
337 dumpType);
Claire Weinanfdd26902022-03-01 14:18:25 -0800338 }
339
340 // Returns empty string on error
341 return entriesPath;
342}
343
zhanghch058d1b46d2021-04-01 11:18:24 +0800344inline void
345 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
346 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500347{
Claire Weinanfdd26902022-03-01 14:18:25 -0800348 std::string entriesPath = getDumpEntriesPath(dumpType);
349 if (entriesPath.empty())
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500350 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500351 messages::internalError(asyncResp->res);
352 return;
353 }
354
George Liu5eb468d2023-06-20 17:03:24 +0800355 sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
356 dbus::utility::getManagedObjects(
357 "xyz.openbmc_project.Dump.Manager", path,
Claire Weinanfdd26902022-03-01 14:18:25 -0800358 [asyncResp, entriesPath,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800359 dumpType](const boost::system::error_code& ec,
George Liu5eb468d2023-06-20 17:03:24 +0800360 const dbus::utility::ManagedObjectType& objects) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700361 if (ec)
362 {
Ed Tanous62598e32023-07-17 17:06:25 -0700363 BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700364 messages::internalError(asyncResp->res);
365 return;
366 }
367
Claire Weinanfdd26902022-03-01 14:18:25 -0800368 // Remove ending slash
369 std::string odataIdStr = entriesPath;
370 if (!odataIdStr.empty())
371 {
372 odataIdStr.pop_back();
373 }
374
375 asyncResp->res.jsonValue["@odata.type"] =
376 "#LogEntryCollection.LogEntryCollection";
377 asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr);
378 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries";
Patrick Williams89492a12023-05-10 07:51:34 -0500379 asyncResp->res.jsonValue["Description"] = "Collection of " + dumpType +
380 " Dump Entries";
Claire Weinanfdd26902022-03-01 14:18:25 -0800381
Ed Tanous3544d2a2023-08-06 18:12:20 -0700382 nlohmann::json::array_t entriesArray;
Ed Tanous18f8f602023-07-18 10:07:23 -0700383 std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
Ed Tanous002d39b2022-05-31 08:59:27 -0700384
George Liu5eb468d2023-06-20 17:03:24 +0800385 dbus::utility::ManagedObjectType resp(objects);
Ed Tanous3544d2a2023-08-06 18:12:20 -0700386 std::ranges::sort(resp, [](const auto& l, const auto& r) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700387 return AlphanumLess<std::string>()(l.first.filename(),
388 r.first.filename());
389 });
390
391 for (auto& object : resp)
392 {
393 if (object.first.str.find(dumpEntryPath) == std::string::npos)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500394 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700395 continue;
396 }
Claire Weinanc6fecda2022-07-15 10:43:25 -0700397 uint64_t timestampUs = 0;
Ed Tanous002d39b2022-05-31 08:59:27 -0700398 uint64_t size = 0;
399 std::string dumpStatus;
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600400 std::string originatorId;
401 log_entry::OriginatorTypes originatorType =
402 log_entry::OriginatorTypes::Internal;
Jason M. Bills433b68b2022-06-28 12:24:26 -0700403 nlohmann::json::object_t thisEntry;
Ed Tanous002d39b2022-05-31 08:59:27 -0700404
405 std::string entryID = object.first.filename();
406 if (entryID.empty())
407 {
408 continue;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500409 }
410
Claire Weinanc6fecda2022-07-15 10:43:25 -0700411 parseDumpEntryFromDbusObject(object, dumpStatus, size, timestampUs,
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600412 originatorId, originatorType,
Claire Weinanaefe3782022-07-15 19:17:19 -0700413 asyncResp);
Ed Tanous002d39b2022-05-31 08:59:27 -0700414
415 if (dumpStatus !=
416 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
417 !dumpStatus.empty())
418 {
419 // Dump status is not Complete, no need to enumerate
420 continue;
421 }
422
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600423 thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry";
Claire Weinanfdd26902022-03-01 14:18:25 -0800424 thisEntry["@odata.id"] = entriesPath + entryID;
Ed Tanous002d39b2022-05-31 08:59:27 -0700425 thisEntry["Id"] = entryID;
426 thisEntry["EntryType"] = "Event";
Ed Tanous002d39b2022-05-31 08:59:27 -0700427 thisEntry["Name"] = dumpType + " Dump Entry";
Claire Weinanbbd80db2022-10-26 16:55:52 -0700428 thisEntry["Created"] =
429 redfish::time_utils::getDateTimeUintUs(timestampUs);
Ed Tanous002d39b2022-05-31 08:59:27 -0700430
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600431 if (!originatorId.empty())
432 {
433 thisEntry["Originator"] = originatorId;
434 thisEntry["OriginatorType"] = originatorType;
435 }
436
Ed Tanous002d39b2022-05-31 08:59:27 -0700437 if (dumpType == "BMC")
438 {
439 thisEntry["DiagnosticDataType"] = "Manager";
Patrick Williams89492a12023-05-10 07:51:34 -0500440 thisEntry["AdditionalDataURI"] = entriesPath + entryID +
441 "/attachment";
Claire Weinanfdd26902022-03-01 14:18:25 -0800442 thisEntry["AdditionalDataSizeBytes"] = size;
Ed Tanous002d39b2022-05-31 08:59:27 -0700443 }
444 else if (dumpType == "System")
445 {
446 thisEntry["DiagnosticDataType"] = "OEM";
447 thisEntry["OEMDiagnosticDataType"] = "System";
Patrick Williams89492a12023-05-10 07:51:34 -0500448 thisEntry["AdditionalDataURI"] = entriesPath + entryID +
449 "/attachment";
Claire Weinanfdd26902022-03-01 14:18:25 -0800450 thisEntry["AdditionalDataSizeBytes"] = size;
Ed Tanous002d39b2022-05-31 08:59:27 -0700451 }
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500452 entriesArray.emplace_back(std::move(thisEntry));
Ed Tanous002d39b2022-05-31 08:59:27 -0700453 }
454 asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
Ed Tanous3544d2a2023-08-06 18:12:20 -0700455 asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
Patrick Williams5a39f772023-10-20 11:20:21 -0500456 });
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500457}
458
zhanghch058d1b46d2021-04-01 11:18:24 +0800459inline void
Claire Weinanc7a6d662022-06-13 16:36:39 -0700460 getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
zhanghch058d1b46d2021-04-01 11:18:24 +0800461 const std::string& entryID, const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500462{
Claire Weinanfdd26902022-03-01 14:18:25 -0800463 std::string entriesPath = getDumpEntriesPath(dumpType);
464 if (entriesPath.empty())
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500465 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500466 messages::internalError(asyncResp->res);
467 return;
468 }
469
George Liu5eb468d2023-06-20 17:03:24 +0800470 sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
471 dbus::utility::getManagedObjects(
472 "xyz.openbmc_project.Dump.Manager", path,
Claire Weinanfdd26902022-03-01 14:18:25 -0800473 [asyncResp, entryID, dumpType,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800474 entriesPath](const boost::system::error_code& ec,
Ed Tanous02cad962022-06-30 16:50:15 -0700475 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700476 if (ec)
477 {
Ed Tanous62598e32023-07-17 17:06:25 -0700478 BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700479 messages::internalError(asyncResp->res);
480 return;
481 }
482
483 bool foundDumpEntry = false;
Ed Tanous18f8f602023-07-18 10:07:23 -0700484 std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
Ed Tanous002d39b2022-05-31 08:59:27 -0700485
486 for (const auto& objectPath : resp)
487 {
488 if (objectPath.first.str != dumpEntryPath + entryID)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500489 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700490 continue;
491 }
492
493 foundDumpEntry = true;
Claire Weinanc6fecda2022-07-15 10:43:25 -0700494 uint64_t timestampUs = 0;
Ed Tanous002d39b2022-05-31 08:59:27 -0700495 uint64_t size = 0;
496 std::string dumpStatus;
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600497 std::string originatorId;
498 log_entry::OriginatorTypes originatorType =
499 log_entry::OriginatorTypes::Internal;
Ed Tanous002d39b2022-05-31 08:59:27 -0700500
Claire Weinanaefe3782022-07-15 19:17:19 -0700501 parseDumpEntryFromDbusObject(objectPath, dumpStatus, size,
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600502 timestampUs, originatorId,
503 originatorType, asyncResp);
Ed Tanous002d39b2022-05-31 08:59:27 -0700504
505 if (dumpStatus !=
506 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
507 !dumpStatus.empty())
508 {
509 // Dump status is not Complete
510 // return not found until status is changed to Completed
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200511 messages::resourceNotFound(asyncResp->res, dumpType + " dump",
512 entryID);
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500513 return;
514 }
515
Ed Tanous002d39b2022-05-31 08:59:27 -0700516 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600517 "#LogEntry.v1_11_0.LogEntry";
Claire Weinanfdd26902022-03-01 14:18:25 -0800518 asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID;
Ed Tanous002d39b2022-05-31 08:59:27 -0700519 asyncResp->res.jsonValue["Id"] = entryID;
520 asyncResp->res.jsonValue["EntryType"] = "Event";
Ed Tanous002d39b2022-05-31 08:59:27 -0700521 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
Claire Weinanbbd80db2022-10-26 16:55:52 -0700522 asyncResp->res.jsonValue["Created"] =
523 redfish::time_utils::getDateTimeUintUs(timestampUs);
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500524
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -0600525 if (!originatorId.empty())
526 {
527 asyncResp->res.jsonValue["Originator"] = originatorId;
528 asyncResp->res.jsonValue["OriginatorType"] = originatorType;
529 }
530
Ed Tanous002d39b2022-05-31 08:59:27 -0700531 if (dumpType == "BMC")
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500532 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700533 asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
534 asyncResp->res.jsonValue["AdditionalDataURI"] =
Claire Weinanfdd26902022-03-01 14:18:25 -0800535 entriesPath + entryID + "/attachment";
536 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500537 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700538 else if (dumpType == "System")
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500539 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700540 asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
541 asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System";
542 asyncResp->res.jsonValue["AdditionalDataURI"] =
Claire Weinanfdd26902022-03-01 14:18:25 -0800543 entriesPath + entryID + "/attachment";
544 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500545 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700546 }
547 if (!foundDumpEntry)
548 {
Ed Tanous62598e32023-07-17 17:06:25 -0700549 BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
Myung Baeb90d14f2023-05-31 14:40:39 -0500550 messages::resourceNotFound(asyncResp->res, dumpType + " dump",
551 entryID);
Ed Tanous002d39b2022-05-31 08:59:27 -0700552 return;
553 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500554 });
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500555}
556
zhanghch058d1b46d2021-04-01 11:18:24 +0800557inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Stanley Chu98782562020-11-04 16:10:24 +0800558 const std::string& entryID,
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500559 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500560{
Patrick Williams5a39f772023-10-20 11:20:21 -0500561 auto respHandler = [asyncResp,
562 entryID](const boost::system::error_code& ec) {
Ed Tanous62598e32023-07-17 17:06:25 -0700563 BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done");
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500564 if (ec)
565 {
George Liu3de8d8b2021-03-22 17:49:39 +0800566 if (ec.value() == EBADR)
567 {
568 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
569 return;
570 }
Ed Tanous62598e32023-07-17 17:06:25 -0700571 BMCWEB_LOG_ERROR(
572 "Dump (DBus) doDelete respHandler got error {} entryID={}", ec,
573 entryID);
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500574 messages::internalError(asyncResp->res);
575 return;
576 }
577 };
Ed Tanous18f8f602023-07-18 10:07:23 -0700578
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500579 crow::connections::systemBus->async_method_call(
580 respHandler, "xyz.openbmc_project.Dump.Manager",
Ed Tanous18f8f602023-07-18 10:07:23 -0700581 std::format("{}/entry/{}", getDumpPath(dumpType), entryID),
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500582 "xyz.openbmc_project.Object.Delete", "Delete");
583}
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600584inline bool checkSizeLimit(int fd, crow::Response& res)
585{
586 long long int size = lseek(fd, 0, SEEK_END);
587 if (size <= 0)
588 {
589 BMCWEB_LOG_ERROR("Failed to get size of file, lseek() returned {}",
590 size);
591 messages::internalError(res);
592 return false;
593 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500594
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600595 // Arbitrary max size of 20MB to accommodate BMC dumps
596 constexpr long long int maxFileSize = 20LL * 1024LL * 1024LL;
597 if (size > maxFileSize)
598 {
599 BMCWEB_LOG_ERROR("File size {} exceeds maximum allowed size of {}",
600 size, maxFileSize);
601 messages::internalError(res);
602 return false;
603 }
604 off_t rc = lseek(fd, 0, SEEK_SET);
605 if (rc < 0)
606 {
607 BMCWEB_LOG_ERROR("Failed to reset file offset to 0");
608 messages::internalError(res);
609 return false;
610 }
611 return true;
612}
Carson Labrado168d1b12023-03-27 17:04:46 +0000613inline void
614 downloadEntryCallback(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
615 const std::string& entryID,
616 const std::string& downloadEntryType,
617 const boost::system::error_code& ec,
618 const sdbusplus::message::unix_fd& unixfd)
619{
620 if (ec.value() == EBADR)
621 {
622 messages::resourceNotFound(asyncResp->res, "EntryAttachment", entryID);
623 return;
624 }
625 if (ec)
626 {
627 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
628 messages::internalError(asyncResp->res);
629 return;
630 }
631
632 // Make sure we know how to process the retrieved entry attachment
633 if ((downloadEntryType != "BMC") && (downloadEntryType != "System"))
634 {
635 BMCWEB_LOG_ERROR("downloadEntryCallback() invalid entry type: {}",
636 downloadEntryType);
637 messages::internalError(asyncResp->res);
638 }
639
640 int fd = -1;
641 fd = dup(unixfd);
642 if (fd < 0)
643 {
644 BMCWEB_LOG_ERROR("Failed to open file");
645 messages::internalError(asyncResp->res);
646 return;
647 }
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600648 if (!checkSizeLimit(fd, asyncResp->res))
Carson Labrado168d1b12023-03-27 17:04:46 +0000649 {
Carson Labrado168d1b12023-03-27 17:04:46 +0000650 close(fd);
651 return;
652 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000653 if (downloadEntryType == "System")
654 {
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600655 if (!asyncResp->res.openFd(fd, bmcweb::EncodingType::Base64))
656 {
657 messages::internalError(asyncResp->res);
658 close(fd);
659 return;
660 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000661 asyncResp->res.addHeader(
662 boost::beast::http::field::content_transfer_encoding, "Base64");
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600663 return;
Carson Labrado168d1b12023-03-27 17:04:46 +0000664 }
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600665 if (!asyncResp->res.openFd(fd))
Ed Tanous27b0cf92023-08-07 12:02:40 -0700666 {
Abhilash Rajub5f288d2023-11-08 22:32:44 -0600667 messages::internalError(asyncResp->res);
668 close(fd);
669 return;
Ed Tanous27b0cf92023-08-07 12:02:40 -0700670 }
Carson Labrado168d1b12023-03-27 17:04:46 +0000671 asyncResp->res.addHeader(boost::beast::http::field::content_type,
672 "application/octet-stream");
673}
674
675inline void
676 downloadDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
677 const std::string& entryID, const std::string& dumpType)
678{
679 if (dumpType != "BMC")
680 {
681 BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
682 messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID);
683 return;
684 }
685
Ed Tanous18f8f602023-07-18 10:07:23 -0700686 std::string dumpEntryPath = std::format("{}/entry/{}",
687 getDumpPath(dumpType), entryID);
Carson Labrado168d1b12023-03-27 17:04:46 +0000688
689 auto downloadDumpEntryHandler =
690 [asyncResp, entryID,
691 dumpType](const boost::system::error_code& ec,
692 const sdbusplus::message::unix_fd& unixfd) {
693 downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
694 };
695
696 crow::connections::systemBus->async_method_call(
697 std::move(downloadDumpEntryHandler), "xyz.openbmc_project.Dump.Manager",
698 dumpEntryPath, "xyz.openbmc_project.Dump.Entry", "GetFileHandle");
699}
700
701inline void
702 downloadEventLogEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
703 const std::string& systemName,
704 const std::string& entryID,
705 const std::string& dumpType)
706{
Ed Tanous25b54db2024-04-17 15:40:31 -0700707 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Carson Labrado168d1b12023-03-27 17:04:46 +0000708 {
709 // Option currently returns no systems. TBD
710 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
711 systemName);
712 return;
713 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700714 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Carson Labrado168d1b12023-03-27 17:04:46 +0000715 {
716 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
717 systemName);
718 return;
719 }
720
721 std::string entryPath =
722 sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") /
723 entryID;
724
725 auto downloadEventLogEntryHandler =
726 [asyncResp, entryID,
727 dumpType](const boost::system::error_code& ec,
728 const sdbusplus::message::unix_fd& unixfd) {
729 downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
730 };
731
732 crow::connections::systemBus->async_method_call(
733 std::move(downloadEventLogEntryHandler), "xyz.openbmc_project.Logging",
734 entryPath, "xyz.openbmc_project.Logging.Entry", "GetEntry");
735}
736
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600737inline DumpCreationProgress
738 mapDbusStatusToDumpProgress(const std::string& status)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500739{
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600740 if (status ==
741 "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" ||
742 status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted")
743 {
744 return DumpCreationProgress::DUMP_CREATE_FAILED;
745 }
746 if (status ==
747 "xyz.openbmc_project.Common.Progress.OperationStatus.Completed")
748 {
749 return DumpCreationProgress::DUMP_CREATE_SUCCESS;
750 }
751 return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
752}
753
754inline DumpCreationProgress
755 getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values)
756{
757 for (const auto& [key, val] : values)
758 {
759 if (key == "Status")
Ed Tanous002d39b2022-05-31 08:59:27 -0700760 {
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600761 const std::string* value = std::get_if<std::string>(&val);
762 if (value == nullptr)
763 {
Ed Tanous62598e32023-07-17 17:06:25 -0700764 BMCWEB_LOG_ERROR("Status property value is null");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600765 return DumpCreationProgress::DUMP_CREATE_FAILED;
766 }
767 return mapDbusStatusToDumpProgress(*value);
768 }
769 }
770 return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
771}
772
773inline std::string getDumpEntryPath(const std::string& dumpPath)
774{
775 if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry")
776 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700777 return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
Ed Tanous9f565092024-07-12 22:06:53 -0700778 BMCWEB_REDFISH_MANAGER_URI_NAME);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600779 }
780 if (dumpPath == "/xyz/openbmc_project/dump/system/entry")
781 {
Ed Tanous253f11b2024-05-16 09:38:31 -0700782 return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
783 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600784 }
785 return "";
786}
787
788inline void createDumpTaskCallback(
789 task::Payload&& payload,
790 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
791 const sdbusplus::message::object_path& createdObjPath)
792{
793 const std::string dumpPath = createdObjPath.parent_path().str;
794 const std::string dumpId = createdObjPath.filename();
795
796 std::string dumpEntryPath = getDumpEntryPath(dumpPath);
797
798 if (dumpEntryPath.empty())
799 {
Ed Tanous62598e32023-07-17 17:06:25 -0700800 BMCWEB_LOG_ERROR("Invalid dump type received");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600801 messages::internalError(asyncResp->res);
802 return;
803 }
804
805 crow::connections::systemBus->async_method_call(
Ed Tanous8cb2c022024-03-27 16:31:46 -0700806 [asyncResp, payload = std::move(payload), createdObjPath,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600807 dumpEntryPath{std::move(dumpEntryPath)},
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800808 dumpId](const boost::system::error_code& ec,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600809 const std::string& introspectXml) {
810 if (ec)
811 {
Ed Tanous62598e32023-07-17 17:06:25 -0700812 BMCWEB_LOG_ERROR("Introspect call failed with error: {}",
813 ec.message());
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600814 messages::internalError(asyncResp->res);
815 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700816 }
817
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600818 // Check if the created dump object has implemented Progress
819 // interface to track dump completion. If yes, fetch the "Status"
820 // property of the interface, modify the task state accordingly.
821 // Else, return task completed.
822 tinyxml2::XMLDocument doc;
Ed Tanous002d39b2022-05-31 08:59:27 -0700823
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600824 doc.Parse(introspectXml.data(), introspectXml.size());
825 tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
826 if (pRoot == nullptr)
Ed Tanous002d39b2022-05-31 08:59:27 -0700827 {
Ed Tanous62598e32023-07-17 17:06:25 -0700828 BMCWEB_LOG_ERROR("XML document failed to parse");
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600829 messages::internalError(asyncResp->res);
830 return;
831 }
832 tinyxml2::XMLElement* interfaceNode =
833 pRoot->FirstChildElement("interface");
834
835 bool isProgressIntfPresent = false;
836 while (interfaceNode != nullptr)
837 {
838 const char* thisInterfaceName = interfaceNode->Attribute("name");
839 if (thisInterfaceName != nullptr)
840 {
841 if (thisInterfaceName ==
842 std::string_view("xyz.openbmc_project.Common.Progress"))
843 {
844 interfaceNode =
845 interfaceNode->NextSiblingElement("interface");
846 continue;
847 }
848 isProgressIntfPresent = true;
849 break;
850 }
851 interfaceNode = interfaceNode->NextSiblingElement("interface");
852 }
853
854 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
855 [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent](
Ed Tanous8b242752023-06-27 17:17:13 -0700856 const boost::system::error_code& ec2, sdbusplus::message_t& msg,
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600857 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanous8b242752023-06-27 17:17:13 -0700858 if (ec2)
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600859 {
Ed Tanous62598e32023-07-17 17:06:25 -0700860 BMCWEB_LOG_ERROR("{}: Error in creating dump",
861 createdObjPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600862 taskData->messages.emplace_back(messages::internalError());
863 taskData->state = "Cancelled";
864 return task::completed;
865 }
866
867 if (isProgressIntfPresent)
868 {
869 dbus::utility::DBusPropertiesMap values;
870 std::string prop;
871 msg.read(prop, values);
872
873 DumpCreationProgress dumpStatus =
874 getDumpCompletionStatus(values);
875 if (dumpStatus == DumpCreationProgress::DUMP_CREATE_FAILED)
876 {
Ed Tanous62598e32023-07-17 17:06:25 -0700877 BMCWEB_LOG_ERROR("{}: Error in creating dump",
878 createdObjPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600879 taskData->state = "Cancelled";
880 return task::completed;
881 }
882
883 if (dumpStatus == DumpCreationProgress::DUMP_CREATE_INPROGRESS)
884 {
Ed Tanous62598e32023-07-17 17:06:25 -0700885 BMCWEB_LOG_DEBUG("{}: Dump creation task is in progress",
886 createdObjPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600887 return !task::completed;
888 }
889 }
890
Ed Tanous002d39b2022-05-31 08:59:27 -0700891 nlohmann::json retMessage = messages::success();
892 taskData->messages.emplace_back(retMessage);
893
Ed Tanousc51a58e2023-03-27 14:43:19 -0700894 boost::urls::url url = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -0700895 "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}",
896 BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId);
Ed Tanousc51a58e2023-03-27 14:43:19 -0700897
898 std::string headerLoc = "Location: ";
899 headerLoc += url.buffer();
900
Ed Tanous002d39b2022-05-31 08:59:27 -0700901 taskData->payload->httpHeaders.emplace_back(std::move(headerLoc));
902
Ed Tanous62598e32023-07-17 17:06:25 -0700903 BMCWEB_LOG_DEBUG("{}: Dump creation task completed",
904 createdObjPath.str);
Ed Tanous002d39b2022-05-31 08:59:27 -0700905 taskData->state = "Completed";
906 return task::completed;
Patrick Williams5a39f772023-10-20 11:20:21 -0500907 },
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600908 "type='signal',interface='org.freedesktop.DBus.Properties',"
909 "member='PropertiesChanged',path='" +
910 createdObjPath.str + "'");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500911
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600912 // The task timer is set to max time limit within which the
913 // requested dump will be collected.
914 task->startTimer(std::chrono::minutes(6));
915 task->populateResp(asyncResp->res);
916 task->payload.emplace(payload);
Patrick Williams5a39f772023-10-20 11:20:21 -0500917 },
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600918 "xyz.openbmc_project.Dump.Manager", createdObjPath,
919 "org.freedesktop.DBus.Introspectable", "Introspect");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500920}
921
zhanghch058d1b46d2021-04-01 11:18:24 +0800922inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
923 const crow::Request& req, const std::string& dumpType)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500924{
Claire Weinanfdd26902022-03-01 14:18:25 -0800925 std::string dumpPath = getDumpEntriesPath(dumpType);
926 if (dumpPath.empty())
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500927 {
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500928 messages::internalError(asyncResp->res);
929 return;
930 }
931
932 std::optional<std::string> diagnosticDataType;
933 std::optional<std::string> oemDiagnosticDataType;
934
Willy Tu15ed6782021-12-14 11:03:16 -0800935 if (!redfish::json_util::readJsonAction(
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500936 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
937 "OEMDiagnosticDataType", oemDiagnosticDataType))
938 {
939 return;
940 }
941
942 if (dumpType == "System")
943 {
944 if (!oemDiagnosticDataType || !diagnosticDataType)
945 {
Ed Tanous62598e32023-07-17 17:06:25 -0700946 BMCWEB_LOG_ERROR(
947 "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500948 messages::actionParameterMissing(
949 asyncResp->res, "CollectDiagnosticData",
950 "DiagnosticDataType & OEMDiagnosticDataType");
951 return;
952 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700953 if ((*oemDiagnosticDataType != "System") ||
954 (*diagnosticDataType != "OEM"))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500955 {
Ed Tanous62598e32023-07-17 17:06:25 -0700956 BMCWEB_LOG_ERROR("Wrong parameter values passed");
Ed Tanousace85d62021-10-26 12:45:59 -0700957 messages::internalError(asyncResp->res);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500958 return;
959 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700960 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/",
961 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500962 }
963 else if (dumpType == "BMC")
964 {
965 if (!diagnosticDataType)
966 {
Ed Tanous62598e32023-07-17 17:06:25 -0700967 BMCWEB_LOG_ERROR(
968 "CreateDump action parameter 'DiagnosticDataType' not found!");
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500969 messages::actionParameterMissing(
970 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
971 return;
972 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700973 if (*diagnosticDataType != "Manager")
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500974 {
Ed Tanous62598e32023-07-17 17:06:25 -0700975 BMCWEB_LOG_ERROR(
976 "Wrong parameter value passed for 'DiagnosticDataType'");
Ed Tanousace85d62021-10-26 12:45:59 -0700977 messages::internalError(asyncResp->res);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500978 return;
979 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700980 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/",
981 BMCWEB_REDFISH_MANAGER_URI_NAME);
Asmitha Karunanithi59075712021-10-22 01:17:41 -0500982 }
983 else
984 {
Ed Tanous62598e32023-07-17 17:06:25 -0700985 BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type");
Asmitha Karunanithi59075712021-10-22 01:17:41 -0500986 messages::internalError(asyncResp->res);
987 return;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500988 }
989
Asmitha Karunanithi8e317782020-12-10 03:35:05 -0600990 std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>>
991 createDumpParamVec;
992
Carson Labradof574a8e2023-03-22 02:26:00 +0000993 if (req.session != nullptr)
994 {
995 createDumpParamVec.emplace_back(
996 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId",
997 req.session->clientIp);
998 createDumpParamVec.emplace_back(
999 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType",
1000 "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client");
1001 }
Asmitha Karunanithi68dd0752022-11-15 11:33:46 -06001002
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001003 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001004 [asyncResp, payload(task::Payload(req)),
1005 dumpPath](const boost::system::error_code& ec,
1006 const sdbusplus::message_t& msg,
1007 const sdbusplus::message::object_path& objPath) mutable {
Ed Tanous002d39b2022-05-31 08:59:27 -07001008 if (ec)
1009 {
Ed Tanous62598e32023-07-17 17:06:25 -07001010 BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec);
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001011 const sd_bus_error* dbusError = msg.get_error();
1012 if (dbusError == nullptr)
1013 {
1014 messages::internalError(asyncResp->res);
1015 return;
1016 }
1017
Ed Tanous62598e32023-07-17 17:06:25 -07001018 BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}",
1019 dbusError->name, dbusError->message);
Asmitha Karunanithi59075712021-10-22 01:17:41 -05001020 if (std::string_view(
1021 "xyz.openbmc_project.Common.Error.NotAllowed") ==
1022 dbusError->name)
1023 {
1024 messages::resourceInStandby(asyncResp->res);
1025 return;
1026 }
1027 if (std::string_view(
1028 "xyz.openbmc_project.Dump.Create.Error.Disabled") ==
1029 dbusError->name)
1030 {
1031 messages::serviceDisabled(asyncResp->res, dumpPath);
1032 return;
1033 }
1034 if (std::string_view(
1035 "xyz.openbmc_project.Common.Error.Unavailable") ==
1036 dbusError->name)
1037 {
1038 messages::resourceInUse(asyncResp->res);
1039 return;
1040 }
1041 // Other Dbus errors such as:
1042 // xyz.openbmc_project.Common.Error.InvalidArgument &
1043 // org.freedesktop.DBus.Error.InvalidArgs are all related to
1044 // the dbus call that is made here in the bmcweb
1045 // implementation and has nothing to do with the client's
1046 // input in the request. Hence, returning internal error
1047 // back to the client.
Ed Tanous002d39b2022-05-31 08:59:27 -07001048 messages::internalError(asyncResp->res);
1049 return;
1050 }
Ed Tanous62598e32023-07-17 17:06:25 -07001051 BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str);
Asmitha Karunanithi8e317782020-12-10 03:35:05 -06001052 createDumpTaskCallback(std::move(payload), asyncResp, objPath);
Patrick Williams5a39f772023-10-20 11:20:21 -05001053 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001054 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Asmitha Karunanithi8e317782020-12-10 03:35:05 -06001055 "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec);
Asmitha Karunanithia43be802020-05-07 05:05:36 -05001056}
1057
zhanghch058d1b46d2021-04-01 11:18:24 +08001058inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1059 const std::string& dumpType)
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001060{
Claire Weinan0d946212022-07-13 19:40:19 -07001061 crow::connections::systemBus->async_method_call(
1062 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001063 if (ec)
1064 {
Ed Tanous62598e32023-07-17 17:06:25 -07001065 BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001066 messages::internalError(asyncResp->res);
1067 return;
1068 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001069 },
Ed Tanous18f8f602023-07-18 10:07:23 -07001070 "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
Claire Weinan0d946212022-07-13 19:40:19 -07001071 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05001072}
1073
Ed Tanousdf254f22024-04-01 13:25:46 -07001074inline void
Ed Tanousb9d36b42022-02-26 21:42:46 -08001075 parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params,
1076 std::string& filename, std::string& timestamp,
1077 std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001078{
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001079 const std::string* filenamePtr = nullptr;
1080 const std::string* timestampPtr = nullptr;
1081 const std::string* logfilePtr = nullptr;
1082
1083 const bool success = sdbusplus::unpackPropertiesNoThrow(
1084 dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr,
1085 "Filename", filenamePtr, "Log", logfilePtr);
1086
1087 if (!success)
Johnathan Mantey043a0532020-03-10 17:15:28 -07001088 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001089 return;
1090 }
1091
1092 if (filenamePtr != nullptr)
1093 {
1094 filename = *filenamePtr;
1095 }
1096
1097 if (timestampPtr != nullptr)
1098 {
1099 timestamp = *timestampPtr;
1100 }
1101
1102 if (logfilePtr != nullptr)
1103 {
1104 logfile = *logfilePtr;
Johnathan Mantey043a0532020-03-10 17:15:28 -07001105 }
1106}
1107
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001108inline void requestRoutesSystemLogServiceCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07001109{
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001110 /**
1111 * Functions triggers appropriate requests on DBus
1112 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001113 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
Ed Tanoused398212021-06-09 17:05:54 -07001114 .privileges(redfish::privileges::getLogServiceCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001115 .methods(boost::beast::http::verb::get)(
1116 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001117 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1118 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001119 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001120 {
1121 return;
1122 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001123 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001124 {
1125 // Option currently returns no systems. TBD
1126 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1127 systemName);
1128 return;
1129 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001130 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001131 {
1132 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1133 systemName);
1134 return;
1135 }
1136
Ed Tanous002d39b2022-05-31 08:59:27 -07001137 // Collections don't include the static data added by SubRoute
1138 // because it has a duplicate entry for members
1139 asyncResp->res.jsonValue["@odata.type"] =
1140 "#LogServiceCollection.LogServiceCollection";
1141 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001142 std::format("/redfish/v1/Systems/{}/LogServices",
1143 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07001144 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
1145 asyncResp->res.jsonValue["Description"] =
1146 "Collection of LogServices for this Computer System";
1147 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1148 logServiceArray = nlohmann::json::array();
1149 nlohmann::json::object_t eventLog;
1150 eventLog["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001151 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1152 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001153 logServiceArray.emplace_back(std::move(eventLog));
Ed Tanous25b54db2024-04-17 15:40:31 -07001154 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
1155 {
1156 nlohmann::json::object_t dumpLog;
1157 dumpLog["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001158 std::format("/redfish/v1/Systems/{}/LogServices/Dump",
1159 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001160 logServiceArray.emplace_back(std::move(dumpLog));
1161 }
raviteja-bc9bb6862020-02-03 11:53:32 -06001162
Gunnar Mills5ffd11f2024-05-02 08:26:12 -05001163 if constexpr (BMCWEB_REDFISH_CPU_LOG)
Ed Tanous25b54db2024-04-17 15:40:31 -07001164 {
1165 nlohmann::json::object_t crashdump;
1166 crashdump["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001167 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
1168 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001169 logServiceArray.emplace_back(std::move(crashdump));
1170 }
Spencer Kub7028eb2021-10-26 15:27:35 +08001171
Ed Tanous25b54db2024-04-17 15:40:31 -07001172 if constexpr (BMCWEB_REDFISH_HOST_LOGGER)
1173 {
1174 nlohmann::json::object_t hostlogger;
1175 hostlogger["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001176 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
1177 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07001178 logServiceArray.emplace_back(std::move(hostlogger));
1179 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001180 asyncResp->res.jsonValue["Members@odata.count"] =
1181 logServiceArray.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -08001182
George Liu7a1dbc42022-12-07 16:03:22 +08001183 constexpr std::array<std::string_view, 1> interfaces = {
1184 "xyz.openbmc_project.State.Boot.PostCode"};
1185 dbus::utility::getSubTreePaths(
1186 "/", 0, interfaces,
1187 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001188 const dbus::utility::MapperGetSubTreePathsResponse&
1189 subtreePath) {
1190 if (ec)
1191 {
Ed Tanous62598e32023-07-17 17:06:25 -07001192 BMCWEB_LOG_ERROR("{}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001193 return;
1194 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001195
Ed Tanous002d39b2022-05-31 08:59:27 -07001196 for (const auto& pathStr : subtreePath)
1197 {
1198 if (pathStr.find("PostCode") != std::string::npos)
1199 {
1200 nlohmann::json& logServiceArrayLocal =
1201 asyncResp->res.jsonValue["Members"];
Ed Tanous613dabe2022-07-09 11:17:36 -07001202 nlohmann::json::object_t member;
Ed Tanous253f11b2024-05-16 09:38:31 -07001203 member["@odata.id"] = std::format(
1204 "/redfish/v1/Systems/{}/LogServices/PostCodes",
1205 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous613dabe2022-07-09 11:17:36 -07001206
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001207 logServiceArrayLocal.emplace_back(std::move(member));
Ed Tanous613dabe2022-07-09 11:17:36 -07001208
Ed Tanous002d39b2022-05-31 08:59:27 -07001209 asyncResp->res.jsonValue["Members@odata.count"] =
1210 logServiceArrayLocal.size();
1211 return;
1212 }
1213 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001214 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001215 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001216}
1217
1218inline void requestRoutesEventLogService(App& app)
1219{
Ed Tanous22d268c2022-05-19 09:39:07 -07001220 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/")
Ed Tanoused398212021-06-09 17:05:54 -07001221 .privileges(redfish::privileges::getLogService)
Ed Tanous002d39b2022-05-31 08:59:27 -07001222 .methods(boost::beast::http::verb::get)(
1223 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001224 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1225 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001226 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001227 {
1228 return;
1229 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001230 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001231 {
1232 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1233 systemName);
1234 return;
1235 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001236 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001237 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1238 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07001239 asyncResp->res.jsonValue["@odata.type"] =
Janet Adkinsb25644a2023-08-16 11:23:45 -05001240 "#LogService.v1_2_0.LogService";
Ed Tanous002d39b2022-05-31 08:59:27 -07001241 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1242 asyncResp->res.jsonValue["Description"] = "System Event Log Service";
1243 asyncResp->res.jsonValue["Id"] = "EventLog";
1244 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
Tejas Patil7c8c4052021-06-04 17:43:14 +05301245
Ed Tanous002d39b2022-05-31 08:59:27 -07001246 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07001247 redfish::time_utils::getDateTimeOffsetNow();
Tejas Patil7c8c4052021-06-04 17:43:14 +05301248
Ed Tanous002d39b2022-05-31 08:59:27 -07001249 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
1250 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
1251 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05301252
Ed Tanous002d39b2022-05-31 08:59:27 -07001253 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001254 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1255 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous20fa6a22024-05-20 18:02:58 -07001256 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"]
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001257
Ed Tanous20fa6a22024-05-20 18:02:58 -07001258 = std::format(
1259 "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog",
1260 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05001261 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001262}
1263
1264inline void requestRoutesJournalEventLogClear(App& app)
1265{
Jason M. Bills4978b632022-02-22 14:17:43 -08001266 BMCWEB_ROUTE(
1267 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07001268 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Ed Tanous432a8902021-06-14 15:28:56 -07001269 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001270 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001271 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001272 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1273 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001274 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001275 {
1276 return;
1277 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001278 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001279 {
1280 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1281 systemName);
1282 return;
1283 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001284 // Clear the EventLog by deleting the log files
1285 std::vector<std::filesystem::path> redfishLogFiles;
1286 if (getRedfishLogFiles(redfishLogFiles))
1287 {
1288 for (const std::filesystem::path& file : redfishLogFiles)
1289 {
1290 std::error_code ec;
1291 std::filesystem::remove(file, ec);
1292 }
1293 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001294
Ed Tanous002d39b2022-05-31 08:59:27 -07001295 // Reload rsyslog so it knows to start new log files
1296 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001297 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001298 if (ec)
1299 {
Ed Tanous62598e32023-07-17 17:06:25 -07001300 BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001301 messages::internalError(asyncResp->res);
1302 return;
1303 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001304
Ed Tanous002d39b2022-05-31 08:59:27 -07001305 messages::success(asyncResp->res);
Patrick Williams5a39f772023-10-20 11:20:21 -05001306 },
Ed Tanous002d39b2022-05-31 08:59:27 -07001307 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1308 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1309 "replace");
Patrick Williams5a39f772023-10-20 11:20:21 -05001310 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001311}
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001312
Jason M. Billsac992cd2022-06-24 13:31:46 -07001313enum class LogParseError
1314{
1315 success,
1316 parseFailed,
1317 messageIdNotInRegistry,
1318};
1319
1320static LogParseError
1321 fillEventLogEntryJson(const std::string& logEntryID,
1322 const std::string& logEntry,
1323 nlohmann::json::object_t& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001324{
Jason M. Bills95820182019-04-22 16:25:34 -07001325 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001326 // First get the Timestamp
Ed Tanousf23b7292020-10-15 09:41:17 -07001327 size_t space = logEntry.find_first_of(' ');
Jason M. Billscd225da2019-05-08 15:31:57 -07001328 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001329 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001330 return LogParseError::parseFailed;
Jason M. Bills95820182019-04-22 16:25:34 -07001331 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001332 std::string timestamp = logEntry.substr(0, space);
1333 // Then get the log contents
Ed Tanousf23b7292020-10-15 09:41:17 -07001334 size_t entryStart = logEntry.find_first_not_of(' ', space);
Jason M. Billscd225da2019-05-08 15:31:57 -07001335 if (entryStart == std::string::npos)
1336 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001337 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001338 }
1339 std::string_view entry(logEntry);
1340 entry.remove_prefix(entryStart);
1341 // Use split to separate the entry into its fields
1342 std::vector<std::string> logEntryFields;
Ed Tanous50ebd4a2023-01-19 19:03:17 -08001343 bmcweb::split(logEntryFields, entry, ',');
Jason M. Billscd225da2019-05-08 15:31:57 -07001344 // We need at least a MessageId to be valid
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001345 auto logEntryIter = logEntryFields.begin();
1346 if (logEntryIter == logEntryFields.end())
Jason M. Billscd225da2019-05-08 15:31:57 -07001347 {
Jason M. Billsac992cd2022-06-24 13:31:46 -07001348 return LogParseError::parseFailed;
Jason M. Billscd225da2019-05-08 15:31:57 -07001349 }
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001350 std::string& messageID = *logEntryIter;
Jason M. Bills4851d452019-03-28 11:27:48 -07001351 // Get the Message from the MessageRegistry
Ed Tanousfffb8c12022-02-07 23:53:03 -08001352 const registries::Message* message = registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001353
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001354 logEntryIter++;
Sui Chen54417b02022-03-24 14:59:52 -07001355 if (message == nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001356 {
Ed Tanous62598e32023-07-17 17:06:25 -07001357 BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001358 return LogParseError::messageIdNotInRegistry;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001359 }
1360
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001361 std::vector<std::string_view> messageArgs(logEntryIter,
1362 logEntryFields.end());
Ed Tanousc05bba42023-06-28 08:33:29 -07001363 messageArgs.resize(message->numberOfArgs);
1364
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001365 std::string msg = redfish::registries::fillMessageArgs(messageArgs,
1366 message->message);
1367 if (msg.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001368 {
Ed Tanous1e6deaf2022-02-17 11:32:37 -08001369 return LogParseError::parseFailed;
Jason M. Bills4851d452019-03-28 11:27:48 -07001370 }
1371
Jason M. Bills95820182019-04-22 16:25:34 -07001372 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1373 // format which matches the Redfish format except for the fractional seconds
1374 // between the '.' and the '+', so just remove them.
Ed Tanousf23b7292020-10-15 09:41:17 -07001375 std::size_t dot = timestamp.find_first_of('.');
1376 std::size_t plus = timestamp.find_first_of('+');
Jason M. Bills95820182019-04-22 16:25:34 -07001377 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001378 {
Jason M. Bills95820182019-04-22 16:25:34 -07001379 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001380 }
1381
1382 // Fill in the log entry with the gathered data
Vijay Lobo9c11a172021-10-07 16:53:16 -05001383 logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001384 logEntryJson["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001385 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1386 BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
Jason M. Bills84afc482022-06-24 12:38:23 -07001387 logEntryJson["Name"] = "System Event Log Entry";
1388 logEntryJson["Id"] = logEntryID;
1389 logEntryJson["Message"] = std::move(msg);
1390 logEntryJson["MessageId"] = std::move(messageID);
1391 logEntryJson["MessageArgs"] = messageArgs;
1392 logEntryJson["EntryType"] = "Event";
1393 logEntryJson["Severity"] = message->messageSeverity;
1394 logEntryJson["Created"] = std::move(timestamp);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001395 return LogParseError::success;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001396}
1397
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001398inline void requestRoutesJournalEventLogEntryCollection(App& app)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001399{
Ed Tanous22d268c2022-05-19 09:39:07 -07001400 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
Gunnar Mills8b6a35f2021-07-30 14:52:53 -05001401 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001402 .methods(boost::beast::http::verb::get)(
1403 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001404 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1405 const std::string& systemName) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001406 query_param::QueryCapabilities capabilities = {
1407 .canDelegateTop = true,
1408 .canDelegateSkip = true,
1409 };
1410 query_param::Query delegatedQuery;
1411 if (!redfish::setUpRedfishRouteWithDelegation(
Carson Labrado3ba00072022-06-06 19:40:56 +00001412 app, req, asyncResp, delegatedQuery, capabilities))
Ed Tanous002d39b2022-05-31 08:59:27 -07001413 {
1414 return;
1415 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001416 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001417 {
1418 // Option currently returns no systems. TBD
1419 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1420 systemName);
1421 return;
1422 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001423 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001424 {
1425 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1426 systemName);
1427 return;
1428 }
1429
Jiaqing Zhao5143f7a2022-07-22 09:33:33 +08001430 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
Ed Tanous3648c8b2022-07-25 13:39:59 -07001431 size_t skip = delegatedQuery.skip.value_or(0);
1432
Ed Tanous002d39b2022-05-31 08:59:27 -07001433 // Collections don't include the static data added by SubRoute
1434 // because it has a duplicate entry for members
1435 asyncResp->res.jsonValue["@odata.type"] =
1436 "#LogEntryCollection.LogEntryCollection";
1437 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001438 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1439 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07001440 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1441 asyncResp->res.jsonValue["Description"] =
1442 "Collection of System Event Log Entries";
1443
1444 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1445 logEntryArray = nlohmann::json::array();
1446 // Go through the log files and create a unique ID for each
1447 // entry
1448 std::vector<std::filesystem::path> redfishLogFiles;
1449 getRedfishLogFiles(redfishLogFiles);
1450 uint64_t entryCount = 0;
1451 std::string logEntry;
1452
1453 // Oldest logs are in the last file, so start there and loop
1454 // backwards
1455 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1456 it++)
1457 {
1458 std::ifstream logStream(*it);
1459 if (!logStream.is_open())
Jason M. Bills4978b632022-02-22 14:17:43 -08001460 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001461 continue;
Jason M. Bills4978b632022-02-22 14:17:43 -08001462 }
Jason M. Bills897967d2019-07-29 17:05:30 -07001463
Ed Tanous002d39b2022-05-31 08:59:27 -07001464 // Reset the unique ID on the first entry
1465 bool firstEntry = true;
1466 while (std::getline(logStream, logEntry))
Jason M. Bills4978b632022-02-22 14:17:43 -08001467 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001468 std::string idStr;
1469 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
Jason M. Bills4978b632022-02-22 14:17:43 -08001470 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001471 continue;
1472 }
Jason M. Billsefde4ec2022-06-24 08:59:52 -07001473 firstEntry = false;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001474
Jason M. Billsde703c52022-06-23 14:19:04 -07001475 nlohmann::json::object_t bmcLogEntry;
Patrick Williams89492a12023-05-10 07:51:34 -05001476 LogParseError status = fillEventLogEntryJson(idStr, logEntry,
1477 bmcLogEntry);
Jason M. Billsac992cd2022-06-24 13:31:46 -07001478 if (status == LogParseError::messageIdNotInRegistry)
1479 {
1480 continue;
1481 }
1482 if (status != LogParseError::success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001483 {
1484 messages::internalError(asyncResp->res);
1485 return;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001486 }
Jason M. Billsde703c52022-06-23 14:19:04 -07001487
Jason M. Billsde703c52022-06-23 14:19:04 -07001488 entryCount++;
1489 // Handle paging using skip (number of entries to skip from the
1490 // start) and top (number of entries to display)
Ed Tanous3648c8b2022-07-25 13:39:59 -07001491 if (entryCount <= skip || entryCount > skip + top)
Jason M. Billsde703c52022-06-23 14:19:04 -07001492 {
1493 continue;
1494 }
1495
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001496 logEntryArray.emplace_back(std::move(bmcLogEntry));
Jason M. Bills4978b632022-02-22 14:17:43 -08001497 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001498 }
1499 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
Ed Tanous3648c8b2022-07-25 13:39:59 -07001500 if (skip + top < entryCount)
Ed Tanous002d39b2022-05-31 08:59:27 -07001501 {
Ed Tanous253f11b2024-05-16 09:38:31 -07001502 asyncResp->res
1503 .jsonValue["Members@odata.nextLink"] = boost::urls::format(
1504 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}",
1505 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top));
Ed Tanous002d39b2022-05-31 08:59:27 -07001506 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001507 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001508}
Chicago Duan336e96c2019-07-15 14:22:08 +08001509
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001510inline void requestRoutesJournalEventLogEntry(App& app)
1511{
1512 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001513 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001514 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001515 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001516 [&app](const crow::Request& req,
1517 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001518 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001519 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001520 {
1521 return;
1522 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001523 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001524 {
1525 // Option currently returns no systems. TBD
1526 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1527 systemName);
1528 return;
1529 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001530
Ed Tanous253f11b2024-05-16 09:38:31 -07001531 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001532 {
1533 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1534 systemName);
1535 return;
1536 }
1537
Ed Tanous002d39b2022-05-31 08:59:27 -07001538 const std::string& targetID = param;
1539
1540 // Go through the log files and check the unique ID for each
1541 // entry to find the target entry
1542 std::vector<std::filesystem::path> redfishLogFiles;
1543 getRedfishLogFiles(redfishLogFiles);
1544 std::string logEntry;
1545
1546 // Oldest logs are in the last file, so start there and loop
1547 // backwards
1548 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1549 it++)
1550 {
1551 std::ifstream logStream(*it);
1552 if (!logStream.is_open())
1553 {
1554 continue;
1555 }
1556
1557 // Reset the unique ID on the first entry
1558 bool firstEntry = true;
1559 while (std::getline(logStream, logEntry))
1560 {
1561 std::string idStr;
1562 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
Ed Tanous45ca1b82022-03-25 13:07:27 -07001563 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001564 continue;
1565 }
Jason M. Billsefde4ec2022-06-24 08:59:52 -07001566 firstEntry = false;
Ed Tanous002d39b2022-05-31 08:59:27 -07001567
1568 if (idStr == targetID)
1569 {
Jason M. Billsde703c52022-06-23 14:19:04 -07001570 nlohmann::json::object_t bmcLogEntry;
Jason M. Billsac992cd2022-06-24 13:31:46 -07001571 LogParseError status =
1572 fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
1573 if (status != LogParseError::success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001574 {
1575 messages::internalError(asyncResp->res);
1576 return;
1577 }
Jason M. Billsd405bb52022-06-24 10:52:05 -07001578 asyncResp->res.jsonValue.update(bmcLogEntry);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001579 return;
1580 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001581 }
1582 }
1583 // Requested ID was not found
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08001584 messages::resourceNotFound(asyncResp->res, "LogEntry", targetID);
Patrick Williams5a39f772023-10-20 11:20:21 -05001585 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001586}
1587
1588inline void requestRoutesDBusEventLogEntryCollection(App& app)
1589{
Ed Tanous22d268c2022-05-19 09:39:07 -07001590 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07001591 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001592 .methods(boost::beast::http::verb::get)(
1593 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001594 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1595 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001596 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001597 {
1598 return;
1599 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001600 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001601 {
1602 // Option currently returns no systems. TBD
1603 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1604 systemName);
1605 return;
1606 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001607 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001608 {
1609 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1610 systemName);
1611 return;
1612 }
1613
Ed Tanous002d39b2022-05-31 08:59:27 -07001614 // Collections don't include the static data added by SubRoute
1615 // because it has a duplicate entry for members
1616 asyncResp->res.jsonValue["@odata.type"] =
1617 "#LogEntryCollection.LogEntryCollection";
1618 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001619 std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1620 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07001621 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1622 asyncResp->res.jsonValue["Description"] =
1623 "Collection of System Event Log Entries";
1624
1625 // DBus implementation of EventLog/Entries
1626 // Make call to Logging Service to find all log entry objects
George Liu5eb468d2023-06-20 17:03:24 +08001627 sdbusplus::message::object_path path("/xyz/openbmc_project/logging");
1628 dbus::utility::getManagedObjects(
1629 "xyz.openbmc_project.Logging", path,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001630 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001631 const dbus::utility::ManagedObjectType& resp) {
1632 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001633 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001634 // TODO Handle for specific error code
Ed Tanous62598e32023-07-17 17:06:25 -07001635 BMCWEB_LOG_ERROR(
1636 "getLogEntriesIfaceData resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001637 messages::internalError(asyncResp->res);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001638 return;
1639 }
Ed Tanous3544d2a2023-08-06 18:12:20 -07001640 nlohmann::json::array_t entriesArray;
Ed Tanous002d39b2022-05-31 08:59:27 -07001641 for (const auto& objectPath : resp)
1642 {
1643 const uint32_t* id = nullptr;
1644 const uint64_t* timestamp = nullptr;
1645 const uint64_t* updateTimestamp = nullptr;
1646 const std::string* severity = nullptr;
1647 const std::string* message = nullptr;
1648 const std::string* filePath = nullptr;
Vijay Lobo9c11a172021-10-07 16:53:16 -05001649 const std::string* resolution = nullptr;
Ed Tanous002d39b2022-05-31 08:59:27 -07001650 bool resolved = false;
Abhishek Patel9017faf2021-09-14 22:48:55 -05001651 const std::string* notify = nullptr;
1652
Ed Tanous002d39b2022-05-31 08:59:27 -07001653 for (const auto& interfaceMap : objectPath.second)
1654 {
1655 if (interfaceMap.first ==
1656 "xyz.openbmc_project.Logging.Entry")
Xiaochao Ma75710de2021-01-21 17:56:02 +08001657 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001658 for (const auto& propertyMap : interfaceMap.second)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001659 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001660 if (propertyMap.first == "Id")
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001661 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001662 id = std::get_if<uint32_t>(&propertyMap.second);
1663 }
1664 else if (propertyMap.first == "Timestamp")
1665 {
1666 timestamp =
1667 std::get_if<uint64_t>(&propertyMap.second);
1668 }
1669 else if (propertyMap.first == "UpdateTimestamp")
1670 {
1671 updateTimestamp =
1672 std::get_if<uint64_t>(&propertyMap.second);
1673 }
1674 else if (propertyMap.first == "Severity")
1675 {
1676 severity = std::get_if<std::string>(
1677 &propertyMap.second);
1678 }
Vijay Lobo9c11a172021-10-07 16:53:16 -05001679 else if (propertyMap.first == "Resolution")
1680 {
1681 resolution = std::get_if<std::string>(
1682 &propertyMap.second);
1683 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001684 else if (propertyMap.first == "Message")
1685 {
1686 message = std::get_if<std::string>(
1687 &propertyMap.second);
1688 }
1689 else if (propertyMap.first == "Resolved")
1690 {
1691 const bool* resolveptr =
1692 std::get_if<bool>(&propertyMap.second);
1693 if (resolveptr == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001694 {
1695 messages::internalError(asyncResp->res);
1696 return;
1697 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001698 resolved = *resolveptr;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001699 }
Abhishek Patel9017faf2021-09-14 22:48:55 -05001700 else if (propertyMap.first ==
1701 "ServiceProviderNotify")
1702 {
1703 notify = std::get_if<std::string>(
1704 &propertyMap.second);
1705 if (notify == nullptr)
1706 {
1707 messages::internalError(asyncResp->res);
1708 return;
1709 }
1710 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001711 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001712 if (id == nullptr || message == nullptr ||
Ed Tanous002d39b2022-05-31 08:59:27 -07001713 severity == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001714 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001715 messages::internalError(asyncResp->res);
1716 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001717 }
1718 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001719 else if (interfaceMap.first ==
1720 "xyz.openbmc_project.Common.FilePath")
1721 {
1722 for (const auto& propertyMap : interfaceMap.second)
1723 {
1724 if (propertyMap.first == "Path")
1725 {
1726 filePath = std::get_if<std::string>(
1727 &propertyMap.second);
1728 }
1729 }
1730 }
1731 }
1732 // Object path without the
1733 // xyz.openbmc_project.Logging.Entry interface, ignore
1734 // and continue.
1735 if (id == nullptr || message == nullptr ||
1736 severity == nullptr || timestamp == nullptr ||
1737 updateTimestamp == nullptr)
1738 {
1739 continue;
1740 }
Ed Tanous3544d2a2023-08-06 18:12:20 -07001741 nlohmann::json& thisEntry = entriesArray.emplace_back();
Vijay Lobo9c11a172021-10-07 16:53:16 -05001742 thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001743 thisEntry["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001744 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1745 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(*id));
Ed Tanous002d39b2022-05-31 08:59:27 -07001746 thisEntry["Name"] = "System Event Log Entry";
1747 thisEntry["Id"] = std::to_string(*id);
1748 thisEntry["Message"] = *message;
1749 thisEntry["Resolved"] = resolved;
Vijay Lobo9c11a172021-10-07 16:53:16 -05001750 if ((resolution != nullptr) && (!(*resolution).empty()))
1751 {
1752 thisEntry["Resolution"] = *resolution;
1753 }
Abhishek Patel9017faf2021-09-14 22:48:55 -05001754 std::optional<bool> notifyAction =
1755 getProviderNotifyAction(*notify);
1756 if (notifyAction)
1757 {
1758 thisEntry["ServiceProviderNotified"] = *notifyAction;
1759 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001760 thisEntry["EntryType"] = "Event";
1761 thisEntry["Severity"] =
1762 translateSeverityDbusToRedfish(*severity);
1763 thisEntry["Created"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001764 redfish::time_utils::getDateTimeUintMs(*timestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07001765 thisEntry["Modified"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001766 redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07001767 if (filePath != nullptr)
1768 {
1769 thisEntry["AdditionalDataURI"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001770 std::format(
1771 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/",
1772 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous002d39b2022-05-31 08:59:27 -07001773 std::to_string(*id) + "/attachment";
1774 }
1775 }
Ed Tanous3544d2a2023-08-06 18:12:20 -07001776 std::ranges::sort(entriesArray, [](const nlohmann::json& left,
1777 const nlohmann::json& right) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001778 return (left["Id"] <= right["Id"]);
Ed Tanous3544d2a2023-08-06 18:12:20 -07001779 });
Ed Tanous002d39b2022-05-31 08:59:27 -07001780 asyncResp->res.jsonValue["Members@odata.count"] =
1781 entriesArray.size();
Ed Tanous3544d2a2023-08-06 18:12:20 -07001782 asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001783 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001784 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001785}
Xiaochao Ma75710de2021-01-21 17:56:02 +08001786
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001787inline void requestRoutesDBusEventLogEntry(App& app)
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001788{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001789 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001790 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001791 .privileges(redfish::privileges::getLogEntry)
Ed Tanous002d39b2022-05-31 08:59:27 -07001792 .methods(boost::beast::http::verb::get)(
1793 [&app](const crow::Request& req,
1794 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001795 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001796 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001797 {
1798 return;
1799 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001800 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001801 {
1802 // Option currently returns no systems. TBD
1803 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1804 systemName);
1805 return;
1806 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001807 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001808 {
1809 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1810 systemName);
1811 return;
1812 }
1813
Ed Tanous002d39b2022-05-31 08:59:27 -07001814 std::string entryID = param;
1815 dbus::utility::escapePathForDbus(entryID);
1816
1817 // DBus implementation of EventLog/Entries
1818 // Make call to Logging Service to find all log entry objects
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001819 sdbusplus::asio::getAllProperties(
1820 *crow::connections::systemBus, "xyz.openbmc_project.Logging",
1821 "/xyz/openbmc_project/logging/entry/" + entryID, "",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001822 [asyncResp, entryID](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001823 const dbus::utility::DBusPropertiesMap& resp) {
1824 if (ec.value() == EBADR)
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001825 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001826 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1827 entryID);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001828 return;
1829 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001830 if (ec)
1831 {
Ed Tanous62598e32023-07-17 17:06:25 -07001832 BMCWEB_LOG_ERROR(
1833 "EventLogEntry (DBus) resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001834 messages::internalError(asyncResp->res);
1835 return;
1836 }
1837 const uint32_t* id = nullptr;
1838 const uint64_t* timestamp = nullptr;
1839 const uint64_t* updateTimestamp = nullptr;
1840 const std::string* severity = nullptr;
1841 const std::string* message = nullptr;
1842 const std::string* filePath = nullptr;
Vijay Lobo9c11a172021-10-07 16:53:16 -05001843 const std::string* resolution = nullptr;
Ed Tanous002d39b2022-05-31 08:59:27 -07001844 bool resolved = false;
Abhishek Patel9017faf2021-09-14 22:48:55 -05001845 const std::string* notify = nullptr;
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001846
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001847 const bool success = sdbusplus::unpackPropertiesNoThrow(
1848 dbus_utils::UnpackErrorPrinter(), resp, "Id", id, "Timestamp",
1849 timestamp, "UpdateTimestamp", updateTimestamp, "Severity",
Vijay Lobo9c11a172021-10-07 16:53:16 -05001850 severity, "Message", message, "Resolved", resolved,
Abhishek Patel9017faf2021-09-14 22:48:55 -05001851 "Resolution", resolution, "Path", filePath,
1852 "ServiceProviderNotify", notify);
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001853
1854 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001855 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001856 messages::internalError(asyncResp->res);
1857 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07001858 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001859
Ed Tanous002d39b2022-05-31 08:59:27 -07001860 if (id == nullptr || message == nullptr || severity == nullptr ||
Abhishek Patel9017faf2021-09-14 22:48:55 -05001861 timestamp == nullptr || updateTimestamp == nullptr ||
1862 notify == nullptr)
Ed Tanous002d39b2022-05-31 08:59:27 -07001863 {
1864 messages::internalError(asyncResp->res);
1865 return;
1866 }
Abhishek Patel9017faf2021-09-14 22:48:55 -05001867
Ed Tanous002d39b2022-05-31 08:59:27 -07001868 asyncResp->res.jsonValue["@odata.type"] =
Vijay Lobo9c11a172021-10-07 16:53:16 -05001869 "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001870 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001871 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1872 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(*id));
Ed Tanous002d39b2022-05-31 08:59:27 -07001873 asyncResp->res.jsonValue["Name"] = "System Event Log Entry";
1874 asyncResp->res.jsonValue["Id"] = std::to_string(*id);
1875 asyncResp->res.jsonValue["Message"] = *message;
1876 asyncResp->res.jsonValue["Resolved"] = resolved;
Abhishek Patel9017faf2021-09-14 22:48:55 -05001877 std::optional<bool> notifyAction = getProviderNotifyAction(*notify);
1878 if (notifyAction)
1879 {
1880 asyncResp->res.jsonValue["ServiceProviderNotified"] =
1881 *notifyAction;
1882 }
Vijay Lobo9c11a172021-10-07 16:53:16 -05001883 if ((resolution != nullptr) && (!(*resolution).empty()))
1884 {
1885 asyncResp->res.jsonValue["Resolution"] = *resolution;
1886 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001887 asyncResp->res.jsonValue["EntryType"] = "Event";
1888 asyncResp->res.jsonValue["Severity"] =
1889 translateSeverityDbusToRedfish(*severity);
1890 asyncResp->res.jsonValue["Created"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001891 redfish::time_utils::getDateTimeUintMs(*timestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07001892 asyncResp->res.jsonValue["Modified"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001893 redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07001894 if (filePath != nullptr)
1895 {
1896 asyncResp->res.jsonValue["AdditionalDataURI"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001897 std::format(
1898 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/",
1899 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous002d39b2022-05-31 08:59:27 -07001900 std::to_string(*id) + "/attachment";
1901 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07001902 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001903 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001904
1905 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001906 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001907 .privileges(redfish::privileges::patchLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001908 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001909 [&app](const crow::Request& req,
1910 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001911 const std::string& systemName, const std::string& entryId) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001912 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001913 {
1914 return;
1915 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001916 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001917 {
1918 // Option currently returns no systems. TBD
1919 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1920 systemName);
1921 return;
1922 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001923 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001924 {
1925 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1926 systemName);
1927 return;
1928 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001929 std::optional<bool> resolved;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001930
Ed Tanous002d39b2022-05-31 08:59:27 -07001931 if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved",
1932 resolved))
1933 {
1934 return;
1935 }
Ed Tanous62598e32023-07-17 17:06:25 -07001936 BMCWEB_LOG_DEBUG("Set Resolved");
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001937
Ginu Georgee93abac2024-06-14 17:35:27 +05301938 setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging",
Asmitha Karunanithi3eb66652024-04-02 16:34:36 +00001939 "/xyz/openbmc_project/logging/entry/" + entryId,
1940 "xyz.openbmc_project.Logging.Entry", "Resolved",
Ginu Georgee93abac2024-06-14 17:35:27 +05301941 *resolved);
Patrick Williams5a39f772023-10-20 11:20:21 -05001942 });
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001943
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001944 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07001945 app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001946 .privileges(redfish::privileges::deleteLogEntry)
1947
Ed Tanous002d39b2022-05-31 08:59:27 -07001948 .methods(boost::beast::http::verb::delete_)(
1949 [&app](const crow::Request& req,
1950 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001951 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001952 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001953 {
1954 return;
1955 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001956 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001957 {
1958 // Option currently returns no systems. TBD
1959 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1960 systemName);
1961 return;
1962 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001963 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001964 {
1965 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1966 systemName);
1967 return;
1968 }
Ed Tanous62598e32023-07-17 17:06:25 -07001969 BMCWEB_LOG_DEBUG("Do delete single event entries.");
Ed Tanous002d39b2022-05-31 08:59:27 -07001970
1971 std::string entryID = param;
1972
1973 dbus::utility::escapePathForDbus(entryID);
1974
1975 // Process response from Logging service.
Patrick Williams5a39f772023-10-20 11:20:21 -05001976 auto respHandler = [asyncResp,
1977 entryID](const boost::system::error_code& ec) {
Ed Tanous62598e32023-07-17 17:06:25 -07001978 BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done");
Ed Tanous002d39b2022-05-31 08:59:27 -07001979 if (ec)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001980 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001981 if (ec.value() == EBADR)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001982 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001983 messages::resourceNotFound(asyncResp->res, "LogEntry",
1984 entryID);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001985 return;
1986 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001987 // TODO Handle for specific error code
Ed Tanous62598e32023-07-17 17:06:25 -07001988 BMCWEB_LOG_ERROR(
1989 "EventLogEntry (DBus) doDelete respHandler got error {}",
1990 ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001991 asyncResp->res.result(
1992 boost::beast::http::status::internal_server_error);
1993 return;
1994 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001995
Ed Tanous002d39b2022-05-31 08:59:27 -07001996 asyncResp->res.result(boost::beast::http::status::ok);
1997 };
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001998
Ed Tanous002d39b2022-05-31 08:59:27 -07001999 // Make call to Logging service to request Delete Log
2000 crow::connections::systemBus->async_method_call(
2001 respHandler, "xyz.openbmc_project.Logging",
2002 "/xyz/openbmc_project/logging/entry/" + entryID,
2003 "xyz.openbmc_project.Object.Delete", "Delete");
Patrick Williams5a39f772023-10-20 11:20:21 -05002004 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002005}
2006
Spencer Kub7028eb2021-10-26 15:27:35 +08002007constexpr const char* hostLoggerFolderPath = "/var/log/console";
2008
2009inline bool
2010 getHostLoggerFiles(const std::string& hostLoggerFilePath,
2011 std::vector<std::filesystem::path>& hostLoggerFiles)
2012{
2013 std::error_code ec;
2014 std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec);
2015 if (ec)
2016 {
Carson Labradobf2dded2023-08-10 00:37:06 +00002017 BMCWEB_LOG_WARNING("{}", ec.message());
Spencer Kub7028eb2021-10-26 15:27:35 +08002018 return false;
2019 }
2020 for (const std::filesystem::directory_entry& it : logPath)
2021 {
2022 std::string filename = it.path().filename();
2023 // Prefix of each log files is "log". Find the file and save the
2024 // path
Ed Tanous11ba3972022-07-11 09:50:41 -07002025 if (filename.starts_with("log"))
Spencer Kub7028eb2021-10-26 15:27:35 +08002026 {
2027 hostLoggerFiles.emplace_back(it.path());
2028 }
2029 }
2030 // As the log files rotate, they are appended with a ".#" that is higher for
2031 // the older logs. Since we start from oldest logs, sort the name in
2032 // descending order.
2033 std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(),
2034 AlphanumLess<std::string>());
2035
2036 return true;
2037}
2038
Ed Tanous02cad962022-06-30 16:50:15 -07002039inline bool getHostLoggerEntries(
2040 const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip,
2041 uint64_t top, std::vector<std::string>& logEntries, size_t& logCount)
Spencer Kub7028eb2021-10-26 15:27:35 +08002042{
2043 GzFileReader logFile;
2044
2045 // Go though all log files and expose host logs.
2046 for (const std::filesystem::path& it : hostLoggerFiles)
2047 {
2048 if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount))
2049 {
Ed Tanous62598e32023-07-17 17:06:25 -07002050 BMCWEB_LOG_ERROR("fail to expose host logs");
Spencer Kub7028eb2021-10-26 15:27:35 +08002051 return false;
2052 }
2053 }
2054 // Get lastMessage from constructor by getter
2055 std::string lastMessage = logFile.getLastMessage();
2056 if (!lastMessage.empty())
2057 {
2058 logCount++;
2059 if (logCount > skip && logCount <= (skip + top))
2060 {
2061 logEntries.push_back(lastMessage);
2062 }
2063 }
2064 return true;
2065}
2066
Ed Tanous6f056f22024-04-07 13:35:51 -07002067inline void fillHostLoggerEntryJson(std::string_view logEntryID,
2068 std::string_view msg,
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002069 nlohmann::json::object_t& logEntryJson)
Spencer Kub7028eb2021-10-26 15:27:35 +08002070{
2071 // Fill in the log entry with the gathered data.
Vijay Lobo9c11a172021-10-07 16:53:16 -05002072 logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07002073 logEntryJson["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07002074 "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries/{}",
2075 BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002076 logEntryJson["Name"] = "Host Logger Entry";
2077 logEntryJson["Id"] = logEntryID;
2078 logEntryJson["Message"] = msg;
2079 logEntryJson["EntryType"] = "Oem";
2080 logEntryJson["Severity"] = "OK";
2081 logEntryJson["OemRecordFormat"] = "Host Logger Entry";
Spencer Kub7028eb2021-10-26 15:27:35 +08002082}
2083
2084inline void requestRoutesSystemHostLogger(App& app)
2085{
Ed Tanous22d268c2022-05-19 09:39:07 -07002086 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/")
Spencer Kub7028eb2021-10-26 15:27:35 +08002087 .privileges(redfish::privileges::getLogService)
Ed Tanous14766872022-03-15 10:44:42 -07002088 .methods(boost::beast::http::verb::get)(
2089 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002090 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2091 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002092 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002093 {
2094 return;
2095 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002096 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002097 {
2098 // Option currently returns no systems. TBD
2099 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2100 systemName);
2101 return;
2102 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002103 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002104 {
2105 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2106 systemName);
2107 return;
2108 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002109 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002110 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
2111 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002112 asyncResp->res.jsonValue["@odata.type"] =
Janet Adkinsb25644a2023-08-16 11:23:45 -05002113 "#LogService.v1_2_0.LogService";
Ed Tanous002d39b2022-05-31 08:59:27 -07002114 asyncResp->res.jsonValue["Name"] = "Host Logger Service";
2115 asyncResp->res.jsonValue["Description"] = "Host Logger Service";
2116 asyncResp->res.jsonValue["Id"] = "HostLogger";
2117 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002118 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
2119 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05002120 });
Spencer Kub7028eb2021-10-26 15:27:35 +08002121}
2122
2123inline void requestRoutesSystemHostLoggerCollection(App& app)
2124{
2125 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002126 "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/")
Spencer Kub7028eb2021-10-26 15:27:35 +08002127 .privileges(redfish::privileges::getLogEntry)
Ed Tanous002d39b2022-05-31 08:59:27 -07002128 .methods(boost::beast::http::verb::get)(
2129 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002130 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2131 const std::string& systemName) {
Ed Tanous002d39b2022-05-31 08:59:27 -07002132 query_param::QueryCapabilities capabilities = {
2133 .canDelegateTop = true,
2134 .canDelegateSkip = true,
2135 };
2136 query_param::Query delegatedQuery;
2137 if (!redfish::setUpRedfishRouteWithDelegation(
Carson Labrado3ba00072022-06-06 19:40:56 +00002138 app, req, asyncResp, delegatedQuery, capabilities))
Ed Tanous002d39b2022-05-31 08:59:27 -07002139 {
2140 return;
2141 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002142 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002143 {
2144 // Option currently returns no systems. TBD
2145 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2146 systemName);
2147 return;
2148 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002149 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002150 {
2151 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2152 systemName);
2153 return;
2154 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002155 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002156 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
2157 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002158 asyncResp->res.jsonValue["@odata.type"] =
2159 "#LogEntryCollection.LogEntryCollection";
2160 asyncResp->res.jsonValue["Name"] = "HostLogger Entries";
2161 asyncResp->res.jsonValue["Description"] =
2162 "Collection of HostLogger Entries";
2163 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
2164 logEntryArray = nlohmann::json::array();
2165 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Spencer Kub7028eb2021-10-26 15:27:35 +08002166
Ed Tanous002d39b2022-05-31 08:59:27 -07002167 std::vector<std::filesystem::path> hostLoggerFiles;
2168 if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
2169 {
Carson Labradobf2dded2023-08-10 00:37:06 +00002170 BMCWEB_LOG_DEBUG("Failed to get host log file path");
Ed Tanous002d39b2022-05-31 08:59:27 -07002171 return;
2172 }
Ed Tanous3648c8b2022-07-25 13:39:59 -07002173 // If we weren't provided top and skip limits, use the defaults.
2174 size_t skip = delegatedQuery.skip.value_or(0);
Jiaqing Zhao5143f7a2022-07-22 09:33:33 +08002175 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
Ed Tanous002d39b2022-05-31 08:59:27 -07002176 size_t logCount = 0;
2177 // This vector only store the entries we want to expose that
2178 // control by skip and top.
2179 std::vector<std::string> logEntries;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002180 if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries,
2181 logCount))
Ed Tanous002d39b2022-05-31 08:59:27 -07002182 {
2183 messages::internalError(asyncResp->res);
2184 return;
2185 }
2186 // If vector is empty, that means skip value larger than total
2187 // log count
2188 if (logEntries.empty())
2189 {
2190 asyncResp->res.jsonValue["Members@odata.count"] = logCount;
2191 return;
2192 }
2193 if (!logEntries.empty())
2194 {
2195 for (size_t i = 0; i < logEntries.size(); i++)
George Liu0fda0f12021-11-16 10:06:17 +08002196 {
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002197 nlohmann::json::object_t hostLogEntry;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002198 fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i],
2199 hostLogEntry);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002200 logEntryArray.emplace_back(std::move(hostLogEntry));
George Liu0fda0f12021-11-16 10:06:17 +08002201 }
2202
Ed Tanous002d39b2022-05-31 08:59:27 -07002203 asyncResp->res.jsonValue["Members@odata.count"] = logCount;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002204 if (skip + top < logCount)
George Liu0fda0f12021-11-16 10:06:17 +08002205 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002206 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002207 std::format(
2208 "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries?$skip=",
2209 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous3648c8b2022-07-25 13:39:59 -07002210 std::to_string(skip + top);
George Liu0fda0f12021-11-16 10:06:17 +08002211 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002212 }
Patrick Williams5a39f772023-10-20 11:20:21 -05002213 });
Spencer Kub7028eb2021-10-26 15:27:35 +08002214}
2215
2216inline void requestRoutesSystemHostLoggerLogEntry(App& app)
2217{
2218 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07002219 app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/")
Spencer Kub7028eb2021-10-26 15:27:35 +08002220 .privileges(redfish::privileges::getLogEntry)
2221 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002222 [&app](const crow::Request& req,
2223 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07002224 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002225 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002226 {
2227 return;
2228 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002229 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002230 {
2231 // Option currently returns no systems. TBD
2232 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2233 systemName);
2234 return;
2235 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002236 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002237 {
2238 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2239 systemName);
2240 return;
2241 }
Ed Tanous6f056f22024-04-07 13:35:51 -07002242 std::string_view targetID = param;
Spencer Kub7028eb2021-10-26 15:27:35 +08002243
Ed Tanous002d39b2022-05-31 08:59:27 -07002244 uint64_t idInt = 0;
Ed Tanousca45aa32022-01-07 09:28:45 -08002245
Ed Tanous6f056f22024-04-07 13:35:51 -07002246 auto [ptr, ec] = std::from_chars(targetID.begin(), targetID.end(),
Patrick Williams84396af2023-05-11 11:47:45 -05002247 idInt);
Ed Tanous6f056f22024-04-07 13:35:51 -07002248 if (ec != std::errc{} || ptr != targetID.end())
Ed Tanous002d39b2022-05-31 08:59:27 -07002249 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08002250 messages::resourceNotFound(asyncResp->res, "LogEntry", param);
Ed Tanous002d39b2022-05-31 08:59:27 -07002251 return;
2252 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002253
Ed Tanous002d39b2022-05-31 08:59:27 -07002254 std::vector<std::filesystem::path> hostLoggerFiles;
2255 if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
2256 {
Carson Labradobf2dded2023-08-10 00:37:06 +00002257 BMCWEB_LOG_DEBUG("Failed to get host log file path");
Ed Tanous002d39b2022-05-31 08:59:27 -07002258 return;
2259 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002260
Ed Tanous002d39b2022-05-31 08:59:27 -07002261 size_t logCount = 0;
Ed Tanous3648c8b2022-07-25 13:39:59 -07002262 size_t top = 1;
Ed Tanous002d39b2022-05-31 08:59:27 -07002263 std::vector<std::string> logEntries;
2264 // We can get specific entry by skip and top. For example, if we
2265 // want to get nth entry, we can set skip = n-1 and top = 1 to
2266 // get that entry
2267 if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries,
2268 logCount))
2269 {
2270 messages::internalError(asyncResp->res);
2271 return;
2272 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002273
Ed Tanous002d39b2022-05-31 08:59:27 -07002274 if (!logEntries.empty())
2275 {
Jason M. Bills6d6574c2022-06-28 12:30:16 -07002276 nlohmann::json::object_t hostLogEntry;
2277 fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry);
2278 asyncResp->res.jsonValue.update(hostLogEntry);
Ed Tanous002d39b2022-05-31 08:59:27 -07002279 return;
2280 }
Spencer Kub7028eb2021-10-26 15:27:35 +08002281
Ed Tanous002d39b2022-05-31 08:59:27 -07002282 // Requested ID was not found
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08002283 messages::resourceNotFound(asyncResp->res, "LogEntry", param);
Patrick Williams5a39f772023-10-20 11:20:21 -05002284 });
Spencer Kub7028eb2021-10-26 15:27:35 +08002285}
2286
Claire Weinandd72e872022-08-15 14:20:06 -07002287inline void handleBMCLogServicesCollectionGet(
Claire Weinanfdd26902022-03-01 14:18:25 -08002288 crow::App& app, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002289 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2290 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002291{
2292 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2293 {
2294 return;
2295 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002296
2297 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2298 {
2299 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2300 return;
2301 }
2302
Claire Weinanfdd26902022-03-01 14:18:25 -08002303 // Collections don't include the static data added by SubRoute
2304 // because it has a duplicate entry for members
2305 asyncResp->res.jsonValue["@odata.type"] =
2306 "#LogServiceCollection.LogServiceCollection";
Ed Tanous253f11b2024-05-16 09:38:31 -07002307 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2308 "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -08002309 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
2310 asyncResp->res.jsonValue["Description"] =
2311 "Collection of LogServices for this Manager";
2312 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
2313 logServiceArray = nlohmann::json::array();
2314
Ed Tanous25b54db2024-04-17 15:40:31 -07002315 if constexpr (BMCWEB_REDFISH_BMC_JOURNAL)
2316 {
2317 nlohmann::json::object_t journal;
Ed Tanous253f11b2024-05-16 09:38:31 -07002318 journal["@odata.id"] =
2319 boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal",
2320 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07002321 logServiceArray.emplace_back(std::move(journal));
2322 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002323
2324 asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
2325
Ed Tanous25b54db2024-04-17 15:40:31 -07002326 if constexpr (BMCWEB_REDFISH_DUMP_LOG)
2327 {
2328 constexpr std::array<std::string_view, 1> interfaces = {
2329 "xyz.openbmc_project.Collection.DeleteAll"};
2330 dbus::utility::getSubTreePaths(
2331 "/xyz/openbmc_project/dump", 0, interfaces,
2332 [asyncResp](const boost::system::error_code& ec,
2333 const dbus::utility::MapperGetSubTreePathsResponse&
2334 subTreePaths) {
2335 if (ec)
Claire Weinanfdd26902022-03-01 14:18:25 -08002336 {
Ed Tanous25b54db2024-04-17 15:40:31 -07002337 BMCWEB_LOG_ERROR(
2338 "handleBMCLogServicesCollectionGet respHandler got error {}",
2339 ec);
2340 // Assume that getting an error simply means there are no dump
2341 // LogServices. Return without adding any error response.
2342 return;
Claire Weinanfdd26902022-03-01 14:18:25 -08002343 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002344
Ed Tanous25b54db2024-04-17 15:40:31 -07002345 nlohmann::json& logServiceArrayLocal =
2346 asyncResp->res.jsonValue["Members"];
2347
2348 for (const std::string& path : subTreePaths)
2349 {
2350 if (path == "/xyz/openbmc_project/dump/bmc")
2351 {
2352 nlohmann::json::object_t member;
Ed Tanous253f11b2024-05-16 09:38:31 -07002353 member["@odata.id"] = boost::urls::format(
2354 "/redfish/v1/Managers/{}/LogServices/Dump",
2355 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07002356 logServiceArrayLocal.emplace_back(std::move(member));
2357 }
2358 else if (path == "/xyz/openbmc_project/dump/faultlog")
2359 {
2360 nlohmann::json::object_t member;
Ed Tanous253f11b2024-05-16 09:38:31 -07002361 member["@odata.id"] = boost::urls::format(
2362 "/redfish/v1/Managers/{}/LogServices/FaultLog",
2363 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanous25b54db2024-04-17 15:40:31 -07002364 logServiceArrayLocal.emplace_back(std::move(member));
2365 }
2366 }
2367
2368 asyncResp->res.jsonValue["Members@odata.count"] =
2369 logServiceArrayLocal.size();
2370 });
2371 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002372}
2373
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002374inline void requestRoutesBMCLogServiceCollection(App& app)
2375{
Ed Tanous253f11b2024-05-16 09:38:31 -07002376 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/")
Gunnar Millsad89dcf2021-07-30 14:40:11 -05002377 .privileges(redfish::privileges::getLogServiceCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002378 .methods(boost::beast::http::verb::get)(
Claire Weinandd72e872022-08-15 14:20:06 -07002379 std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002380}
Ed Tanous1da66f72018-07-27 16:13:37 -07002381
Claire Weinanfdd26902022-03-01 14:18:25 -08002382inline void
2383 getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2384 const std::string& dumpType)
2385{
2386 std::string dumpPath;
2387 std::string overWritePolicy;
2388 bool collectDiagnosticDataSupported = false;
2389
2390 if (dumpType == "BMC")
2391 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002392 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump",
2393 BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -08002394 overWritePolicy = "WrapsWhenFull";
2395 collectDiagnosticDataSupported = true;
2396 }
2397 else if (dumpType == "FaultLog")
2398 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002399 dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog",
2400 BMCWEB_REDFISH_MANAGER_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -08002401 overWritePolicy = "Unknown";
2402 collectDiagnosticDataSupported = false;
2403 }
2404 else if (dumpType == "System")
2405 {
Ed Tanous253f11b2024-05-16 09:38:31 -07002406 dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump",
2407 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Claire Weinanfdd26902022-03-01 14:18:25 -08002408 overWritePolicy = "WrapsWhenFull";
2409 collectDiagnosticDataSupported = true;
2410 }
2411 else
2412 {
Ed Tanous62598e32023-07-17 17:06:25 -07002413 BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}",
2414 dumpType);
Claire Weinanfdd26902022-03-01 14:18:25 -08002415 messages::internalError(asyncResp->res);
2416 return;
2417 }
2418
2419 asyncResp->res.jsonValue["@odata.id"] = dumpPath;
2420 asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService";
2421 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2422 asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService";
2423 asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename();
2424 asyncResp->res.jsonValue["OverWritePolicy"] = std::move(overWritePolicy);
2425
2426 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002427 redfish::time_utils::getDateTimeOffsetNow();
Claire Weinanfdd26902022-03-01 14:18:25 -08002428 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2429 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2430 redfishDateTimeOffset.second;
2431
2432 asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries";
Claire Weinanfdd26902022-03-01 14:18:25 -08002433
2434 if (collectDiagnosticDataSupported)
2435 {
2436 asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2437 ["target"] =
2438 dumpPath + "/Actions/LogService.CollectDiagnosticData";
2439 }
Claire Weinan0d946212022-07-13 19:40:19 -07002440
2441 constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface};
2442 dbus::utility::getSubTreePaths(
2443 "/xyz/openbmc_project/dump", 0, interfaces,
2444 [asyncResp, dumpType, dumpPath](
2445 const boost::system::error_code& ec,
2446 const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
2447 if (ec)
2448 {
Ed Tanous62598e32023-07-17 17:06:25 -07002449 BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", ec);
Claire Weinan0d946212022-07-13 19:40:19 -07002450 // Assume that getting an error simply means there are no dump
2451 // LogServices. Return without adding any error response.
2452 return;
2453 }
Ed Tanous18f8f602023-07-18 10:07:23 -07002454 std::string dbusDumpPath = getDumpPath(dumpType);
Claire Weinan0d946212022-07-13 19:40:19 -07002455 for (const std::string& path : subTreePaths)
2456 {
2457 if (path == dbusDumpPath)
2458 {
2459 asyncResp->res
2460 .jsonValue["Actions"]["#LogService.ClearLog"]["target"] =
2461 dumpPath + "/Actions/LogService.ClearLog";
2462 break;
2463 }
2464 }
Patrick Williams5a39f772023-10-20 11:20:21 -05002465 });
Claire Weinanfdd26902022-03-01 14:18:25 -08002466}
2467
2468inline void handleLogServicesDumpServiceGet(
2469 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002470 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2471 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002472{
2473 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2474 {
2475 return;
2476 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002477
2478 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2479 {
2480 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2481 return;
2482 }
2483
Claire Weinanfdd26902022-03-01 14:18:25 -08002484 getDumpServiceInfo(asyncResp, dumpType);
2485}
2486
Ed Tanous22d268c2022-05-19 09:39:07 -07002487inline void handleLogServicesDumpServiceComputerSystemGet(
2488 crow::App& app, const crow::Request& req,
2489 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2490 const std::string& chassisId)
2491{
2492 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2493 {
2494 return;
2495 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002496 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002497 {
2498 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2499 return;
2500 }
2501 getDumpServiceInfo(asyncResp, "System");
2502}
2503
Claire Weinanfdd26902022-03-01 14:18:25 -08002504inline void handleLogServicesDumpEntriesCollectionGet(
2505 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002506 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2507 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002508{
2509 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2510 {
2511 return;
2512 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002513
2514 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2515 {
2516 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2517 return;
2518 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002519 getDumpEntryCollection(asyncResp, dumpType);
2520}
2521
Ed Tanous22d268c2022-05-19 09:39:07 -07002522inline void handleLogServicesDumpEntriesCollectionComputerSystemGet(
2523 crow::App& app, const crow::Request& req,
2524 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2525 const std::string& chassisId)
2526{
2527 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2528 {
2529 return;
2530 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002531 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002532 {
2533 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2534 return;
2535 }
2536 getDumpEntryCollection(asyncResp, "System");
2537}
2538
Claire Weinanfdd26902022-03-01 14:18:25 -08002539inline void handleLogServicesDumpEntryGet(
2540 crow::App& app, const std::string& dumpType, const crow::Request& req,
2541 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002542 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002543{
2544 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2545 {
2546 return;
2547 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002548 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2549 {
2550 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2551 return;
2552 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002553 getDumpEntryById(asyncResp, dumpId, dumpType);
2554}
Carson Labrado168d1b12023-03-27 17:04:46 +00002555
Ed Tanous22d268c2022-05-19 09:39:07 -07002556inline void handleLogServicesDumpEntryComputerSystemGet(
2557 crow::App& app, const crow::Request& req,
2558 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2559 const std::string& chassisId, const std::string& dumpId)
2560{
2561 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2562 {
2563 return;
2564 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002565 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002566 {
2567 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2568 return;
2569 }
2570 getDumpEntryById(asyncResp, dumpId, "System");
2571}
Claire Weinanfdd26902022-03-01 14:18:25 -08002572
2573inline void handleLogServicesDumpEntryDelete(
2574 crow::App& app, const std::string& dumpType, const crow::Request& req,
2575 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002576 const std::string& managerId, const std::string& dumpId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002577{
2578 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2579 {
2580 return;
2581 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002582
2583 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2584 {
2585 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2586 return;
2587 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002588 deleteDumpEntry(asyncResp, dumpId, dumpType);
2589}
2590
Ed Tanous22d268c2022-05-19 09:39:07 -07002591inline void handleLogServicesDumpEntryComputerSystemDelete(
2592 crow::App& app, const crow::Request& req,
2593 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2594 const std::string& chassisId, const std::string& dumpId)
2595{
2596 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2597 {
2598 return;
2599 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002600 if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002601 {
2602 messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
2603 return;
2604 }
2605 deleteDumpEntry(asyncResp, dumpId, "System");
2606}
2607
Carson Labrado168d1b12023-03-27 17:04:46 +00002608inline void handleLogServicesDumpEntryDownloadGet(
2609 crow::App& app, const std::string& dumpType, const crow::Request& req,
2610 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002611 const std::string& managerId, const std::string& dumpId)
Carson Labrado168d1b12023-03-27 17:04:46 +00002612{
2613 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2614 {
2615 return;
2616 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002617
2618 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2619 {
2620 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2621 return;
2622 }
Carson Labrado168d1b12023-03-27 17:04:46 +00002623 downloadDumpEntry(asyncResp, dumpId, dumpType);
2624}
2625
2626inline void handleDBusEventLogEntryDownloadGet(
2627 crow::App& app, const std::string& dumpType, const crow::Request& req,
2628 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2629 const std::string& systemName, const std::string& entryID)
2630{
2631 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2632 {
2633 return;
2634 }
2635 if (!http_helpers::isContentTypeAllowed(
2636 req.getHeaderValue("Accept"),
2637 http_helpers::ContentType::OctetStream, true))
2638 {
2639 asyncResp->res.result(boost::beast::http::status::bad_request);
2640 return;
2641 }
2642 downloadEventLogEntry(asyncResp, systemName, entryID, dumpType);
2643}
2644
Claire Weinanfdd26902022-03-01 14:18:25 -08002645inline void handleLogServicesDumpCollectDiagnosticDataPost(
2646 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002647 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2648 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002649{
2650 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2651 {
2652 return;
2653 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002654 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2655 {
2656 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2657 return;
2658 }
2659
Claire Weinanfdd26902022-03-01 14:18:25 -08002660 createDump(asyncResp, req, dumpType);
2661}
2662
Ed Tanous22d268c2022-05-19 09:39:07 -07002663inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost(
2664 crow::App& app, const crow::Request& req,
2665 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002666 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002667{
2668 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2669 {
2670 return;
2671 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002672
Ed Tanous25b54db2024-04-17 15:40:31 -07002673 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002674 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002675 // Option currently returns no systems. TBD
2676 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2677 systemName);
2678 return;
2679 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002680 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002681 {
2682 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2683 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002684 return;
2685 }
2686 createDump(asyncResp, req, "System");
2687}
2688
Claire Weinanfdd26902022-03-01 14:18:25 -08002689inline void handleLogServicesDumpClearLogPost(
2690 crow::App& app, const std::string& dumpType, const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002691 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2692 const std::string& managerId)
Claire Weinanfdd26902022-03-01 14:18:25 -08002693{
2694 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2695 {
2696 return;
2697 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002698
2699 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2700 {
2701 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2702 return;
2703 }
Claire Weinanfdd26902022-03-01 14:18:25 -08002704 clearDump(asyncResp, dumpType);
2705}
2706
Ed Tanous22d268c2022-05-19 09:39:07 -07002707inline void handleLogServicesDumpClearLogComputerSystemPost(
2708 crow::App& app, const crow::Request& req,
2709 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002710 const std::string& systemName)
Ed Tanous22d268c2022-05-19 09:39:07 -07002711{
2712 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2713 {
2714 return;
2715 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002716 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous22d268c2022-05-19 09:39:07 -07002717 {
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002718 // Option currently returns no systems. TBD
2719 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2720 systemName);
2721 return;
2722 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002723 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002724 {
2725 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2726 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07002727 return;
2728 }
2729 clearDump(asyncResp, "System");
2730}
2731
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002732inline void requestRoutesBMCDumpService(App& app)
2733{
Ed Tanous253f11b2024-05-16 09:38:31 -07002734 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002735 .privileges(redfish::privileges::getLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002736 .methods(boost::beast::http::verb::get)(std::bind_front(
2737 handleLogServicesDumpServiceGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002738}
2739
2740inline void requestRoutesBMCDumpEntryCollection(App& app)
2741{
Ed Tanous253f11b2024-05-16 09:38:31 -07002742 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002743 .privileges(redfish::privileges::getLogEntryCollection)
Claire Weinanfdd26902022-03-01 14:18:25 -08002744 .methods(boost::beast::http::verb::get)(std::bind_front(
2745 handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002746}
2747
2748inline void requestRoutesBMCDumpEntry(App& app)
2749{
2750 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002751 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002752 .privileges(redfish::privileges::getLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002753 .methods(boost::beast::http::verb::get)(std::bind_front(
2754 handleLogServicesDumpEntryGet, std::ref(app), "BMC"));
2755
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002756 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002757 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002758 .privileges(redfish::privileges::deleteLogEntry)
Claire Weinanfdd26902022-03-01 14:18:25 -08002759 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2760 handleLogServicesDumpEntryDelete, std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002761}
2762
Carson Labrado168d1b12023-03-27 17:04:46 +00002763inline void requestRoutesBMCDumpEntryDownload(App& app)
2764{
2765 BMCWEB_ROUTE(
2766 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002767 "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002768 .privileges(redfish::privileges::getLogEntry)
2769 .methods(boost::beast::http::verb::get)(std::bind_front(
2770 handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC"));
2771}
2772
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002773inline void requestRoutesBMCDumpCreate(App& app)
2774{
George Liu0fda0f12021-11-16 10:06:17 +08002775 BMCWEB_ROUTE(
2776 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002777 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002778 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002779 .methods(boost::beast::http::verb::post)(
Claire Weinanfdd26902022-03-01 14:18:25 -08002780 std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost,
2781 std::ref(app), "BMC"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002782}
2783
2784inline void requestRoutesBMCDumpClear(App& app)
2785{
George Liu0fda0f12021-11-16 10:06:17 +08002786 BMCWEB_ROUTE(
2787 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002788 "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002789 .privileges(redfish::privileges::postLogService)
Claire Weinanfdd26902022-03-01 14:18:25 -08002790 .methods(boost::beast::http::verb::post)(std::bind_front(
2791 handleLogServicesDumpClearLogPost, std::ref(app), "BMC"));
2792}
2793
Carson Labrado168d1b12023-03-27 17:04:46 +00002794inline void requestRoutesDBusEventLogEntryDownload(App& app)
2795{
2796 BMCWEB_ROUTE(
2797 app,
Ravi Teja9e9d99d2023-11-08 05:33:59 -06002798 "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/")
Carson Labrado168d1b12023-03-27 17:04:46 +00002799 .privileges(redfish::privileges::getLogEntry)
2800 .methods(boost::beast::http::verb::get)(std::bind_front(
2801 handleDBusEventLogEntryDownloadGet, std::ref(app), "System"));
2802}
2803
Claire Weinanfdd26902022-03-01 14:18:25 -08002804inline void requestRoutesFaultLogDumpService(App& app)
2805{
Ed Tanous253f11b2024-05-16 09:38:31 -07002806 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002807 .privileges(redfish::privileges::getLogService)
2808 .methods(boost::beast::http::verb::get)(std::bind_front(
2809 handleLogServicesDumpServiceGet, std::ref(app), "FaultLog"));
2810}
2811
2812inline void requestRoutesFaultLogDumpEntryCollection(App& app)
2813{
Ed Tanous253f11b2024-05-16 09:38:31 -07002814 BMCWEB_ROUTE(app,
2815 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002816 .privileges(redfish::privileges::getLogEntryCollection)
2817 .methods(boost::beast::http::verb::get)(
2818 std::bind_front(handleLogServicesDumpEntriesCollectionGet,
2819 std::ref(app), "FaultLog"));
2820}
2821
2822inline void requestRoutesFaultLogDumpEntry(App& app)
2823{
Ed Tanous253f11b2024-05-16 09:38:31 -07002824 BMCWEB_ROUTE(
2825 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002826 .privileges(redfish::privileges::getLogEntry)
2827 .methods(boost::beast::http::verb::get)(std::bind_front(
2828 handleLogServicesDumpEntryGet, std::ref(app), "FaultLog"));
2829
Ed Tanous253f11b2024-05-16 09:38:31 -07002830 BMCWEB_ROUTE(
2831 app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002832 .privileges(redfish::privileges::deleteLogEntry)
2833 .methods(boost::beast::http::verb::delete_)(std::bind_front(
2834 handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog"));
2835}
2836
2837inline void requestRoutesFaultLogDumpClear(App& app)
2838{
2839 BMCWEB_ROUTE(
2840 app,
Ed Tanous253f11b2024-05-16 09:38:31 -07002841 "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/")
Claire Weinanfdd26902022-03-01 14:18:25 -08002842 .privileges(redfish::privileges::postLogService)
2843 .methods(boost::beast::http::verb::post)(std::bind_front(
2844 handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog"));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002845}
2846
2847inline void requestRoutesSystemDumpService(App& app)
2848{
Ed Tanous22d268c2022-05-19 09:39:07 -07002849 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/")
Ed Tanoused398212021-06-09 17:05:54 -07002850 .privileges(redfish::privileges::getLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002851 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002852 handleLogServicesDumpServiceComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002853}
2854
2855inline void requestRoutesSystemDumpEntryCollection(App& app)
2856{
Ed Tanous22d268c2022-05-19 09:39:07 -07002857 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07002858 .privileges(redfish::privileges::getLogEntryCollection)
Ed Tanous22d268c2022-05-19 09:39:07 -07002859 .methods(boost::beast::http::verb::get)(std::bind_front(
2860 handleLogServicesDumpEntriesCollectionComputerSystemGet,
2861 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002862}
2863
2864inline void requestRoutesSystemDumpEntry(App& app)
2865{
2866 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002867 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002868 .privileges(redfish::privileges::getLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002869 .methods(boost::beast::http::verb::get)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002870 handleLogServicesDumpEntryComputerSystemGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002871
2872 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002873 "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002874 .privileges(redfish::privileges::deleteLogEntry)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002875 .methods(boost::beast::http::verb::delete_)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002876 handleLogServicesDumpEntryComputerSystemDelete, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002877}
2878
2879inline void requestRoutesSystemDumpCreate(App& app)
2880{
George Liu0fda0f12021-11-16 10:06:17 +08002881 BMCWEB_ROUTE(
2882 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002883 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07002884 .privileges(redfish::privileges::postLogService)
Ed Tanous22d268c2022-05-19 09:39:07 -07002885 .methods(boost::beast::http::verb::post)(std::bind_front(
2886 handleLogServicesDumpCollectDiagnosticDataComputerSystemPost,
2887 std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002888}
2889
2890inline void requestRoutesSystemDumpClear(App& app)
2891{
George Liu0fda0f12021-11-16 10:06:17 +08002892 BMCWEB_ROUTE(
2893 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002894 "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002895 .privileges(redfish::privileges::postLogService)
Claire Weinan6ab9ad52022-08-12 18:20:17 -07002896 .methods(boost::beast::http::verb::post)(std::bind_front(
Ed Tanous22d268c2022-05-19 09:39:07 -07002897 handleLogServicesDumpClearLogComputerSystemPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002898}
2899
2900inline void requestRoutesCrashdumpService(App& app)
2901{
2902 // Note: Deviated from redfish privilege registry for GET & HEAD
2903 // method for security reasons.
2904 /**
2905 * Functions triggers appropriate requests on DBus
2906 */
Ed Tanous22d268c2022-05-19 09:39:07 -07002907 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/")
Ed Tanoused398212021-06-09 17:05:54 -07002908 // This is incorrect, should be:
2909 //.privileges(redfish::privileges::getLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002910 .privileges({{"ConfigureManager"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07002911 .methods(boost::beast::http::verb::get)(
2912 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002913 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2914 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002915 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002916 {
2917 return;
2918 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002919 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002920 {
2921 // Option currently returns no systems. TBD
2922 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2923 systemName);
2924 return;
2925 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002926 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002927 {
2928 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2929 systemName);
2930 return;
2931 }
2932
Ed Tanous002d39b2022-05-31 08:59:27 -07002933 // Copy over the static data to include the entries added by
2934 // SubRoute
2935 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002936 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
2937 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002938 asyncResp->res.jsonValue["@odata.type"] =
2939 "#LogService.v1_2_0.LogService";
2940 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2941 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
V-Sanjana15b89722023-05-11 16:27:03 +05302942 asyncResp->res.jsonValue["Id"] = "Crashdump";
Ed Tanous002d39b2022-05-31 08:59:27 -07002943 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2944 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302945
Ed Tanous002d39b2022-05-31 08:59:27 -07002946 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002947 redfish::time_utils::getDateTimeOffsetNow();
Ed Tanous002d39b2022-05-31 08:59:27 -07002948 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2949 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2950 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05302951
Ed Tanous002d39b2022-05-31 08:59:27 -07002952 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07002953 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2954 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2955 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2956 ["target"] = std::format(
2957 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog",
2958 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07002959 asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
Ed Tanous253f11b2024-05-16 09:38:31 -07002960 ["target"] = std::format(
2961 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData",
2962 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05002963 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002964}
2965
2966void inline requestRoutesCrashdumpClear(App& app)
2967{
George Liu0fda0f12021-11-16 10:06:17 +08002968 BMCWEB_ROUTE(
2969 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07002970 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07002971 // This is incorrect, should be:
2972 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07002973 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002974 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002975 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07002976 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2977 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002978 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002979 {
2980 return;
2981 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002982 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08002983 {
2984 // Option currently returns no systems. TBD
2985 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2986 systemName);
2987 return;
2988 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002989 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07002990 {
2991 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2992 systemName);
2993 return;
2994 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002995 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002996 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07002997 const std::string&) {
2998 if (ec)
2999 {
3000 messages::internalError(asyncResp->res);
3001 return;
3002 }
3003 messages::success(asyncResp->res);
Patrick Williams5a39f772023-10-20 11:20:21 -05003004 },
Ed Tanous002d39b2022-05-31 08:59:27 -07003005 crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
Patrick Williams5a39f772023-10-20 11:20:21 -05003006 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003007}
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07003008
zhanghch058d1b46d2021-04-01 11:18:24 +08003009static void
3010 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3011 const std::string& logID, nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07003012{
Johnathan Mantey043a0532020-03-10 17:15:28 -07003013 auto getStoredLogCallback =
Ed Tanousb9d36b42022-02-26 21:42:46 -08003014 [asyncResp, logID,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003015 &logEntryJson](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08003016 const dbus::utility::DBusPropertiesMap& params) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003017 if (ec)
3018 {
Ed Tanous62598e32023-07-17 17:06:25 -07003019 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07003020 if (ec.value() ==
3021 boost::system::linux_error::bad_request_descriptor)
Jason M. Bills1ddcf012019-11-26 14:59:21 -08003022 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003023 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Jason M. Bills2b20ef62022-01-06 15:48:07 -08003024 }
3025 else
3026 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003027 messages::internalError(asyncResp->res);
Jason M. Bills2b20ef62022-01-06 15:48:07 -08003028 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003029 return;
3030 }
3031
3032 std::string timestamp{};
3033 std::string filename{};
3034 std::string logfile{};
3035 parseCrashdumpParameters(params, filename, timestamp, logfile);
3036
3037 if (filename.empty() || timestamp.empty())
3038 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003039 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003040 return;
3041 }
3042
3043 std::string crashdumpURI =
Ed Tanous253f11b2024-05-16 09:38:31 -07003044 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/",
3045 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous002d39b2022-05-31 08:59:27 -07003046 logID + "/" + filename;
Jason M. Bills84afc482022-06-24 12:38:23 -07003047 nlohmann::json::object_t logEntry;
Vijay Lobo9c11a172021-10-07 16:53:16 -05003048 logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07003049 logEntry["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07003050 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}",
3051 BMCWEB_REDFISH_SYSTEM_URI_NAME, logID);
Jason M. Bills84afc482022-06-24 12:38:23 -07003052 logEntry["Name"] = "CPU Crashdump";
3053 logEntry["Id"] = logID;
3054 logEntry["EntryType"] = "Oem";
3055 logEntry["AdditionalDataURI"] = std::move(crashdumpURI);
3056 logEntry["DiagnosticDataType"] = "OEM";
3057 logEntry["OEMDiagnosticDataType"] = "PECICrashdump";
3058 logEntry["Created"] = std::move(timestamp);
Ed Tanous002d39b2022-05-31 08:59:27 -07003059
3060 // If logEntryJson references an array of LogEntry resources
3061 // ('Members' list), then push this as a new entry, otherwise set it
3062 // directly
3063 if (logEntryJson.is_array())
3064 {
3065 logEntryJson.push_back(logEntry);
3066 asyncResp->res.jsonValue["Members@odata.count"] =
3067 logEntryJson.size();
3068 }
3069 else
3070 {
Jason M. Billsd405bb52022-06-24 10:52:05 -07003071 logEntryJson.update(logEntry);
Ed Tanous002d39b2022-05-31 08:59:27 -07003072 }
3073 };
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02003074 sdbusplus::asio::getAllProperties(
3075 *crow::connections::systemBus, crashdumpObject,
3076 crashdumpPath + std::string("/") + logID, crashdumpInterface,
3077 std::move(getStoredLogCallback));
Jason M. Billse855dd22019-10-08 11:37:48 -07003078}
3079
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003080inline void requestRoutesCrashdumpEntryCollection(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07003081{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003082 // Note: Deviated from redfish privilege registry for GET & HEAD
3083 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07003084 /**
3085 * Functions triggers appropriate requests on DBus
3086 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003087 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003088 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07003089 // This is incorrect, should be.
3090 //.privileges(redfish::privileges::postLogEntryCollection)
Ed Tanous432a8902021-06-14 15:28:56 -07003091 .privileges({{"ConfigureComponents"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07003092 .methods(boost::beast::http::verb::get)(
3093 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003094 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3095 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003096 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003097 {
3098 return;
3099 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003100 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003101 {
3102 // Option currently returns no systems. TBD
3103 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3104 systemName);
3105 return;
3106 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003107 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003108 {
3109 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3110 systemName);
3111 return;
3112 }
3113
George Liu7a1dbc42022-12-07 16:03:22 +08003114 constexpr std::array<std::string_view, 1> interfaces = {
3115 crashdumpInterface};
3116 dbus::utility::getSubTreePaths(
3117 "/", 0, interfaces,
3118 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003119 const std::vector<std::string>& resp) {
3120 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07003121 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003122 if (ec.value() !=
3123 boost::system::errc::no_such_file_or_directory)
3124 {
Ed Tanous62598e32023-07-17 17:06:25 -07003125 BMCWEB_LOG_DEBUG("failed to get entries ec: {}",
3126 ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07003127 messages::internalError(asyncResp->res);
3128 return;
3129 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07003130 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003131 asyncResp->res.jsonValue["@odata.type"] =
3132 "#LogEntryCollection.LogEntryCollection";
Ed Tanous253f11b2024-05-16 09:38:31 -07003133 asyncResp->res.jsonValue["@odata.id"] = std::format(
3134 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
3135 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07003136 asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
3137 asyncResp->res.jsonValue["Description"] =
3138 "Collection of Crashdump Entries";
3139 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3140 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Jason M. Bills2b20ef62022-01-06 15:48:07 -08003141
Ed Tanous002d39b2022-05-31 08:59:27 -07003142 for (const std::string& path : resp)
3143 {
3144 const sdbusplus::message::object_path objPath(path);
3145 // Get the log ID
3146 std::string logID = objPath.filename();
3147 if (logID.empty())
3148 {
3149 continue;
3150 }
3151 // Add the log entry to the array
3152 logCrashdumpEntry(asyncResp, logID,
3153 asyncResp->res.jsonValue["Members"]);
3154 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003155 });
Patrick Williams5a39f772023-10-20 11:20:21 -05003156 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003157}
Ed Tanous1da66f72018-07-27 16:13:37 -07003158
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003159inline void requestRoutesCrashdumpEntry(App& app)
Ed Tanous1da66f72018-07-27 16:13:37 -07003160{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003161 // Note: Deviated from redfish privilege registry for GET & HEAD
3162 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07003163
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003164 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07003165 app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07003166 // this is incorrect, should be
3167 // .privileges(redfish::privileges::getLogEntry)
Ed Tanous432a8902021-06-14 15:28:56 -07003168 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003169 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003170 [&app](const crow::Request& req,
3171 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07003172 const std::string& systemName, const std::string& param) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003173 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003174 {
3175 return;
3176 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003177 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003178 {
3179 // Option currently returns no systems. TBD
3180 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3181 systemName);
3182 return;
3183 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003184 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003185 {
3186 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3187 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003188 return;
3189 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003190 const std::string& logID = param;
3191 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
Patrick Williams5a39f772023-10-20 11:20:21 -05003192 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003193}
Ed Tanous1da66f72018-07-27 16:13:37 -07003194
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003195inline void requestRoutesCrashdumpFile(App& app)
3196{
3197 // Note: Deviated from redfish privilege registry for GET & HEAD
3198 // method for security reasons.
3199 BMCWEB_ROUTE(
3200 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003201 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07003202 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003203 .methods(boost::beast::http::verb::get)(
Nan Zhoua4ce1142022-08-02 18:45:25 +00003204 [](const crow::Request& req,
3205 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07003206 const std::string& systemName, const std::string& logID,
3207 const std::string& fileName) {
Shounak Mitra2a9beee2022-07-20 18:41:30 +00003208 // Do not call getRedfishRoute here since the crashdump file is not a
3209 // Redfish resource.
Ed Tanous22d268c2022-05-19 09:39:07 -07003210
Ed Tanous25b54db2024-04-17 15:40:31 -07003211 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003212 {
3213 // Option currently returns no systems. TBD
3214 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3215 systemName);
3216 return;
3217 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003218 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003219 {
3220 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3221 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003222 return;
3223 }
3224
Ed Tanous002d39b2022-05-31 08:59:27 -07003225 auto getStoredLogCallback =
Ed Tanous39662a32023-02-06 15:09:46 -08003226 [asyncResp, logID, fileName, url(boost::urls::url(req.url()))](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003227 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003228 const std::vector<
3229 std::pair<std::string, dbus::utility::DbusVariantType>>&
3230 resp) {
3231 if (ec)
3232 {
Ed Tanous62598e32023-07-17 17:06:25 -07003233 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07003234 messages::internalError(asyncResp->res);
3235 return;
3236 }
Jason M. Bills8e6c0992021-03-11 16:26:53 -08003237
Ed Tanous002d39b2022-05-31 08:59:27 -07003238 std::string dbusFilename{};
3239 std::string dbusTimestamp{};
3240 std::string dbusFilepath{};
Jason M. Bills8e6c0992021-03-11 16:26:53 -08003241
Ed Tanous002d39b2022-05-31 08:59:27 -07003242 parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
3243 dbusFilepath);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003244
Ed Tanous002d39b2022-05-31 08:59:27 -07003245 if (dbusFilename.empty() || dbusTimestamp.empty() ||
3246 dbusFilepath.empty())
3247 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003248 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003249 return;
3250 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003251
Ed Tanous002d39b2022-05-31 08:59:27 -07003252 // Verify the file name parameter is correct
3253 if (fileName != dbusFilename)
3254 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003255 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003256 return;
3257 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003258
Ed Tanous27b0cf92023-08-07 12:02:40 -07003259 if (!asyncResp->res.openFile(dbusFilepath))
Ed Tanous002d39b2022-05-31 08:59:27 -07003260 {
Jiaqing Zhao9db4ba22022-10-09 17:24:40 +08003261 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
Ed Tanous002d39b2022-05-31 08:59:27 -07003262 return;
3263 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003264
Ed Tanous002d39b2022-05-31 08:59:27 -07003265 // Configure this to be a file download when accessed
3266 // from a browser
Ed Tanousd9f6c622022-03-17 09:12:17 -07003267 asyncResp->res.addHeader(
3268 boost::beast::http::field::content_disposition, "attachment");
Ed Tanous002d39b2022-05-31 08:59:27 -07003269 };
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02003270 sdbusplus::asio::getAllProperties(
3271 *crow::connections::systemBus, crashdumpObject,
3272 crashdumpPath + std::string("/") + logID, crashdumpInterface,
3273 std::move(getStoredLogCallback));
Patrick Williams5a39f772023-10-20 11:20:21 -05003274 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003275}
3276
Jason M. Billsc5a4c822022-01-06 15:51:23 -08003277enum class OEMDiagnosticType
3278{
3279 onDemand,
3280 telemetry,
3281 invalid,
3282};
3283
Ed Tanous26ccae32023-02-16 10:28:44 -08003284inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr)
Jason M. Billsc5a4c822022-01-06 15:51:23 -08003285{
3286 if (oemDiagStr == "OnDemand")
3287 {
3288 return OEMDiagnosticType::onDemand;
3289 }
3290 if (oemDiagStr == "Telemetry")
3291 {
3292 return OEMDiagnosticType::telemetry;
3293 }
3294
3295 return OEMDiagnosticType::invalid;
3296}
3297
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003298inline void requestRoutesCrashdumpCollect(App& app)
3299{
3300 // Note: Deviated from redfish privilege registry for GET & HEAD
3301 // method for security reasons.
George Liu0fda0f12021-11-16 10:06:17 +08003302 BMCWEB_ROUTE(
3303 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003304 "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/")
Ed Tanoused398212021-06-09 17:05:54 -07003305 // The below is incorrect; Should be ConfigureManager
3306 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07003307 .privileges({{"ConfigureComponents"}})
Ed Tanous002d39b2022-05-31 08:59:27 -07003308 .methods(boost::beast::http::verb::post)(
3309 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003310 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3311 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003312 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003313 {
3314 return;
3315 }
Ed Tanous22d268c2022-05-19 09:39:07 -07003316
Ed Tanous25b54db2024-04-17 15:40:31 -07003317 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003318 {
3319 // Option currently returns no systems. TBD
3320 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3321 systemName);
3322 return;
3323 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003324 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003325 {
3326 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3327 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003328 return;
3329 }
3330
Ed Tanous002d39b2022-05-31 08:59:27 -07003331 std::string diagnosticDataType;
3332 std::string oemDiagnosticDataType;
3333 if (!redfish::json_util::readJsonAction(
3334 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
3335 "OEMDiagnosticDataType", oemDiagnosticDataType))
3336 {
3337 return;
3338 }
3339
3340 if (diagnosticDataType != "OEM")
3341 {
Ed Tanous62598e32023-07-17 17:06:25 -07003342 BMCWEB_LOG_ERROR(
3343 "Only OEM DiagnosticDataType supported for Crashdump");
Ed Tanous002d39b2022-05-31 08:59:27 -07003344 messages::actionParameterValueFormatError(
3345 asyncResp->res, diagnosticDataType, "DiagnosticDataType",
3346 "CollectDiagnosticData");
3347 return;
3348 }
3349
3350 OEMDiagnosticType oemDiagType =
3351 getOEMDiagnosticType(oemDiagnosticDataType);
3352
3353 std::string iface;
3354 std::string method;
3355 std::string taskMatchStr;
3356 if (oemDiagType == OEMDiagnosticType::onDemand)
3357 {
3358 iface = crashdumpOnDemandInterface;
3359 method = "GenerateOnDemandLog";
3360 taskMatchStr = "type='signal',"
3361 "interface='org.freedesktop.DBus.Properties',"
3362 "member='PropertiesChanged',"
3363 "arg0namespace='com.intel.crashdump'";
3364 }
3365 else if (oemDiagType == OEMDiagnosticType::telemetry)
3366 {
3367 iface = crashdumpTelemetryInterface;
3368 method = "GenerateTelemetryLog";
3369 taskMatchStr = "type='signal',"
3370 "interface='org.freedesktop.DBus.Properties',"
3371 "member='PropertiesChanged',"
3372 "arg0namespace='com.intel.crashdump'";
3373 }
3374 else
3375 {
Ed Tanous62598e32023-07-17 17:06:25 -07003376 BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}",
3377 oemDiagnosticDataType);
Ed Tanous002d39b2022-05-31 08:59:27 -07003378 messages::actionParameterValueFormatError(
3379 asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType",
3380 "CollectDiagnosticData");
3381 return;
3382 }
3383
3384 auto collectCrashdumpCallback =
3385 [asyncResp, payload(task::Payload(req)),
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003386 taskMatchStr](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07003387 const std::string&) mutable {
3388 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07003389 {
Ed Tanous002d39b2022-05-31 08:59:27 -07003390 if (ec.value() == boost::system::errc::operation_not_supported)
3391 {
3392 messages::resourceInStandby(asyncResp->res);
3393 }
3394 else if (ec.value() ==
3395 boost::system::errc::device_or_resource_busy)
3396 {
3397 messages::serviceTemporarilyUnavailable(asyncResp->res,
3398 "60");
3399 }
3400 else
3401 {
3402 messages::internalError(asyncResp->res);
3403 }
Ed Tanous45ca1b82022-03-25 13:07:27 -07003404 return;
3405 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003406 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Ed Tanous8b242752023-06-27 17:17:13 -07003407 [](const boost::system::error_code& ec2, sdbusplus::message_t&,
Ed Tanous002d39b2022-05-31 08:59:27 -07003408 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanous8b242752023-06-27 17:17:13 -07003409 if (!ec2)
Ed Tanous002d39b2022-05-31 08:59:27 -07003410 {
3411 taskData->messages.emplace_back(messages::taskCompletedOK(
3412 std::to_string(taskData->index)));
3413 taskData->state = "Completed";
3414 }
3415 return task::completed;
Patrick Williams5a39f772023-10-20 11:20:21 -05003416 },
Ed Tanous002d39b2022-05-31 08:59:27 -07003417 taskMatchStr);
Ed Tanous1da66f72018-07-27 16:13:37 -07003418
Ed Tanous002d39b2022-05-31 08:59:27 -07003419 task->startTimer(std::chrono::minutes(5));
3420 task->populateResp(asyncResp->res);
3421 task->payload.emplace(std::move(payload));
3422 };
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003423
Ed Tanous002d39b2022-05-31 08:59:27 -07003424 crow::connections::systemBus->async_method_call(
3425 std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath,
3426 iface, method);
Patrick Williams5a39f772023-10-20 11:20:21 -05003427 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003428}
Kenny L. Ku6eda7682020-06-19 09:48:36 -07003429
Andrew Geisslercb92c032018-08-17 07:56:14 -07003430/**
3431 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3432 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003433inline void requestRoutesDBusLogServiceActionsClear(App& app)
Andrew Geisslercb92c032018-08-17 07:56:14 -07003434{
Andrew Geisslercb92c032018-08-17 07:56:14 -07003435 /**
3436 * Function handles POST method request.
3437 * The Clear Log actions does not require any parameter.The action deletes
3438 * all entries found in the Entries collection for this Log Service.
3439 */
Andrew Geisslercb92c032018-08-17 07:56:14 -07003440
George Liu0fda0f12021-11-16 10:06:17 +08003441 BMCWEB_ROUTE(
3442 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003443 "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07003444 .privileges(redfish::privileges::postLogService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003445 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003446 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003447 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3448 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003449 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003450 {
3451 return;
3452 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003453 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003454 {
3455 // Option currently returns no systems. TBD
3456 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3457 systemName);
3458 return;
3459 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003460 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003461 {
3462 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3463 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003464 return;
3465 }
Ed Tanous62598e32023-07-17 17:06:25 -07003466 BMCWEB_LOG_DEBUG("Do delete all entries.");
Andrew Geisslercb92c032018-08-17 07:56:14 -07003467
Ed Tanous002d39b2022-05-31 08:59:27 -07003468 // Process response from Logging service.
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003469 auto respHandler = [asyncResp](const boost::system::error_code& ec) {
Ed Tanous62598e32023-07-17 17:06:25 -07003470 BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done");
Ed Tanous002d39b2022-05-31 08:59:27 -07003471 if (ec)
3472 {
3473 // TODO Handle for specific error code
Ed Tanous62598e32023-07-17 17:06:25 -07003474 BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07003475 asyncResp->res.result(
3476 boost::beast::http::status::internal_server_error);
3477 return;
3478 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07003479
Ed Tanous002d39b2022-05-31 08:59:27 -07003480 asyncResp->res.result(boost::beast::http::status::no_content);
3481 };
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003482
Ed Tanous002d39b2022-05-31 08:59:27 -07003483 // Make call to Logging service to request Clear Log
3484 crow::connections::systemBus->async_method_call(
3485 respHandler, "xyz.openbmc_project.Logging",
3486 "/xyz/openbmc_project/logging",
3487 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Patrick Williams5a39f772023-10-20 11:20:21 -05003488 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003489}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003490
3491/****************************************************
3492 * Redfish PostCode interfaces
3493 * using DBUS interface: getPostCodesTS
3494 ******************************************************/
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003495inline void requestRoutesPostCodesLogService(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003496{
Ed Tanous22d268c2022-05-19 09:39:07 -07003497 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/")
Ed Tanoused398212021-06-09 17:05:54 -07003498 .privileges(redfish::privileges::getLogService)
Ed Tanous002d39b2022-05-31 08:59:27 -07003499 .methods(boost::beast::http::verb::get)(
3500 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003501 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3502 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003503 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003504 {
3505 return;
3506 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003507 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003508 {
3509 // Option currently returns no systems. TBD
3510 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3511 systemName);
3512 return;
3513 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003514 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003515 {
3516 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3517 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003518 return;
3519 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003520 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003521 std::format("/redfish/v1/Systems/{}/LogServices/PostCodes",
3522 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07003523 asyncResp->res.jsonValue["@odata.type"] =
Janet Adkinsb25644a2023-08-16 11:23:45 -05003524 "#LogService.v1_2_0.LogService";
Ed Tanous002d39b2022-05-31 08:59:27 -07003525 asyncResp->res.jsonValue["Name"] = "POST Code Log Service";
3526 asyncResp->res.jsonValue["Description"] = "POST Code Log Service";
Ed Tanoused34a4a2023-02-08 15:43:27 -08003527 asyncResp->res.jsonValue["Id"] = "PostCodes";
Ed Tanous002d39b2022-05-31 08:59:27 -07003528 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
3529 asyncResp->res.jsonValue["Entries"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003530 std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries",
3531 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Tejas Patil7c8c4052021-06-04 17:43:14 +05303532
Ed Tanous002d39b2022-05-31 08:59:27 -07003533 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07003534 redfish::time_utils::getDateTimeOffsetNow();
Ed Tanous002d39b2022-05-31 08:59:27 -07003535 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
3536 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
3537 redfishDateTimeOffset.second;
Tejas Patil7c8c4052021-06-04 17:43:14 +05303538
Ed Tanous20fa6a22024-05-20 18:02:58 -07003539 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
3540 ["target"] = std::format(
3541 "/redfish/v1/Systems/{}/LogServices/PostCodes/Actions/LogService.ClearLog",
3542 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Patrick Williams5a39f772023-10-20 11:20:21 -05003543 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003544}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003545
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003546inline void requestRoutesPostCodesClear(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003547{
George Liu0fda0f12021-11-16 10:06:17 +08003548 BMCWEB_ROUTE(
3549 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003550 "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/")
Ed Tanoused398212021-06-09 17:05:54 -07003551 // The following privilege is incorrect; It should be ConfigureManager
3552 //.privileges(redfish::privileges::postLogService)
Ed Tanous432a8902021-06-14 15:28:56 -07003553 .privileges({{"ConfigureComponents"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003554 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003555 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003556 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3557 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003558 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003559 {
3560 return;
3561 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003562 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003563 {
3564 // Option currently returns no systems. TBD
3565 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3566 systemName);
3567 return;
3568 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003569 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003570 {
3571 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3572 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003573 return;
3574 }
Ed Tanous62598e32023-07-17 17:06:25 -07003575 BMCWEB_LOG_DEBUG("Do delete all postcodes entries.");
ZhikuiRena3316fc2020-01-29 14:58:08 -08003576
Ed Tanous002d39b2022-05-31 08:59:27 -07003577 // Make call to post-code service to request clear all
3578 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003579 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003580 if (ec)
3581 {
3582 // TODO Handle for specific error code
Ed Tanous62598e32023-07-17 17:06:25 -07003583 BMCWEB_LOG_ERROR("doClearPostCodes resp_handler got error {}",
3584 ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07003585 asyncResp->res.result(
3586 boost::beast::http::status::internal_server_error);
3587 messages::internalError(asyncResp->res);
3588 return;
3589 }
Tony Lee18fc70c2023-08-24 16:15:54 +08003590 messages::success(asyncResp->res);
Patrick Williams5a39f772023-10-20 11:20:21 -05003591 },
Ed Tanous002d39b2022-05-31 08:59:27 -07003592 "xyz.openbmc_project.State.Boot.PostCode0",
3593 "/xyz/openbmc_project/State/Boot/PostCode0",
3594 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
Patrick Williams5a39f772023-10-20 11:20:21 -05003595 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003596}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003597
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003598/**
3599 * @brief Parse post code ID and get the current value and index value
3600 * eg: postCodeID=B1-2, currentValue=1, index=2
3601 *
3602 * @param[in] postCodeID Post Code ID
3603 * @param[out] currentValue Current value
3604 * @param[out] index Index value
3605 *
3606 * @return bool true if the parsing is successful, false the parsing fails
3607 */
Ed Tanous6f056f22024-04-07 13:35:51 -07003608inline bool parsePostCode(std::string_view postCodeID, uint64_t& currentValue,
Ed Tanousdf254f22024-04-01 13:25:46 -07003609 uint16_t& index)
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003610{
3611 std::vector<std::string> split;
Ed Tanous50ebd4a2023-01-19 19:03:17 -08003612 bmcweb::split(split, postCodeID, '-');
Ed Tanous6f056f22024-04-07 13:35:51 -07003613 if (split.size() != 2)
3614 {
3615 return false;
3616 }
3617 std::string_view postCodeNumber = split[0];
3618 if (postCodeNumber.size() < 2)
3619 {
3620 return false;
3621 }
3622 if (postCodeNumber[0] != 'B')
3623 {
3624 return false;
3625 }
3626 postCodeNumber.remove_prefix(1);
3627 auto [ptrIndex, ecIndex] = std::from_chars(postCodeNumber.begin(),
3628 postCodeNumber.end(), index);
3629 if (ptrIndex != postCodeNumber.end() || ecIndex != std::errc())
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003630 {
3631 return false;
3632 }
3633
Ed Tanous6f056f22024-04-07 13:35:51 -07003634 std::string_view postCodeIndex = split[1];
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003635
Ed Tanous6f056f22024-04-07 13:35:51 -07003636 auto [ptrValue, ecValue] = std::from_chars(
3637 postCodeIndex.begin(), postCodeIndex.end(), currentValue);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003638
Ed Tanous6f056f22024-04-07 13:35:51 -07003639 return ptrValue == postCodeIndex.end() && ecValue == std::errc();
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003640}
3641
3642static bool fillPostCodeEntry(
Ed Tanousac106bf2023-06-07 09:24:59 -07003643 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303644 const boost::container::flat_map<
3645 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003646 const uint16_t bootIndex, const uint64_t codeIndex = 0,
3647 const uint64_t skip = 0, const uint64_t top = 0)
3648{
3649 // Get the Message from the MessageRegistry
Ed Tanousfffb8c12022-02-07 23:53:03 -08003650 const registries::Message* message =
3651 registries::getMessage("OpenBMC.0.2.BIOSPOSTCode");
Ed Tanousdc8cfa62024-04-07 13:37:25 -07003652 if (message == nullptr)
3653 {
3654 BMCWEB_LOG_ERROR("Couldn't find known message?");
3655 return false;
3656 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003657 uint64_t currentCodeIndex = 0;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003658 uint64_t firstCodeTimeUs = 0;
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303659 for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3660 code : postcode)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003661 {
3662 currentCodeIndex++;
3663 std::string postcodeEntryID =
3664 "B" + std::to_string(bootIndex) + "-" +
3665 std::to_string(currentCodeIndex); // 1 based index in EntryID string
3666
3667 uint64_t usecSinceEpoch = code.first;
3668 uint64_t usTimeOffset = 0;
3669
3670 if (1 == currentCodeIndex)
3671 { // already incremented
3672 firstCodeTimeUs = code.first;
3673 }
3674 else
3675 {
3676 usTimeOffset = code.first - firstCodeTimeUs;
3677 }
3678
3679 // skip if no specific codeIndex is specified and currentCodeIndex does
3680 // not fall between top and skip
3681 if ((codeIndex == 0) &&
3682 (currentCodeIndex <= skip || currentCodeIndex > top))
3683 {
3684 continue;
3685 }
3686
Gunnar Mills4e0453b2020-07-08 14:00:30 -05003687 // skip if a specific codeIndex is specified and does not match the
ZhikuiRena3316fc2020-01-29 14:58:08 -08003688 // currentIndex
3689 if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3690 {
3691 // This is done for simplicity. 1st entry is needed to calculate
3692 // time offset. To improve efficiency, one can get to the entry
3693 // directly (possibly with flatmap's nth method)
3694 continue;
3695 }
3696
3697 // currentCodeIndex is within top and skip or equal to specified code
3698 // index
3699
3700 // Get the Created time from the timestamp
3701 std::string entryTimeStr;
Konstantin Aladyshev2a025612023-02-15 11:52:58 +03003702 entryTimeStr = redfish::time_utils::getDateTimeUintUs(usecSinceEpoch);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003703
3704 // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3705 std::ostringstream hexCode;
3706 hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303707 << std::get<0>(code.second);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003708 std::ostringstream timeOffsetStr;
3709 // Set Fixed -Point Notation
3710 timeOffsetStr << std::fixed;
3711 // Set precision to 4 digits
3712 timeOffsetStr << std::setprecision(4);
3713 // Add double to stream
3714 timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003715
Ed Tanous1e6deaf2022-02-17 11:32:37 -08003716 std::string bootIndexStr = std::to_string(bootIndex);
3717 std::string timeOffsetString = timeOffsetStr.str();
3718 std::string hexCodeStr = hexCode.str();
3719
3720 std::array<std::string_view, 3> messageArgs = {
3721 bootIndexStr, timeOffsetString, hexCodeStr};
3722
3723 std::string msg =
3724 redfish::registries::fillMessageArgs(messageArgs, message->message);
3725 if (msg.empty())
ZhikuiRena3316fc2020-01-29 14:58:08 -08003726 {
Ed Tanous1e6deaf2022-02-17 11:32:37 -08003727 messages::internalError(asyncResp->res);
3728 return false;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003729 }
3730
Tim Leed4342a92020-04-27 11:47:58 +08003731 // Get Severity template from message registry
3732 std::string severity;
3733 if (message != nullptr)
3734 {
Ed Tanous5f2b84e2022-02-08 00:41:53 -08003735 severity = message->messageSeverity;
Tim Leed4342a92020-04-27 11:47:58 +08003736 }
3737
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003738 // Format entry
3739 nlohmann::json::object_t bmcLogEntry;
Vijay Lobo9c11a172021-10-07 16:53:16 -05003740 bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
Ed Tanousef4c65b2023-04-24 15:28:50 -07003741 bmcLogEntry["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07003742 "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/{}",
3743 BMCWEB_REDFISH_SYSTEM_URI_NAME, postcodeEntryID);
Jason M. Bills84afc482022-06-24 12:38:23 -07003744 bmcLogEntry["Name"] = "POST Code Log Entry";
3745 bmcLogEntry["Id"] = postcodeEntryID;
3746 bmcLogEntry["Message"] = std::move(msg);
3747 bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode";
Ed Tanous1e6deaf2022-02-17 11:32:37 -08003748 bmcLogEntry["MessageArgs"] = messageArgs;
Jason M. Bills84afc482022-06-24 12:38:23 -07003749 bmcLogEntry["EntryType"] = "Event";
3750 bmcLogEntry["Severity"] = std::move(severity);
3751 bmcLogEntry["Created"] = entryTimeStr;
George Liu647b3cd2021-07-05 12:43:56 +08003752 if (!std::get<std::vector<uint8_t>>(code.second).empty())
3753 {
3754 bmcLogEntry["AdditionalDataURI"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003755 std::format(
3756 "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/",
3757 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
George Liu647b3cd2021-07-05 12:43:56 +08003758 postcodeEntryID + "/attachment";
3759 }
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003760
3761 // codeIndex is only specified when querying single entry, return only
3762 // that entry in this case
3763 if (codeIndex != 0)
3764 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003765 asyncResp->res.jsonValue.update(bmcLogEntry);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003766 return true;
3767 }
3768
Ed Tanousac106bf2023-06-07 09:24:59 -07003769 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Patrick Williamsb2ba3072023-05-12 10:27:39 -05003770 logEntryArray.emplace_back(std::move(bmcLogEntry));
ZhikuiRena3316fc2020-01-29 14:58:08 -08003771 }
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003772
3773 // Return value is always false when querying multiple entries
3774 return false;
ZhikuiRena3316fc2020-01-29 14:58:08 -08003775}
3776
Ed Tanousac106bf2023-06-07 09:24:59 -07003777static void
3778 getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3779 const std::string& entryId)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003780{
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003781 uint16_t bootIndex = 0;
3782 uint64_t codeIndex = 0;
3783 if (!parsePostCode(entryId, codeIndex, bootIndex))
3784 {
3785 // Requested ID was not found
Ed Tanousac106bf2023-06-07 09:24:59 -07003786 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003787 return;
3788 }
3789
3790 if (bootIndex == 0 || codeIndex == 0)
3791 {
3792 // 0 is an invalid index
Ed Tanousac106bf2023-06-07 09:24:59 -07003793 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003794 return;
3795 }
3796
ZhikuiRena3316fc2020-01-29 14:58:08 -08003797 crow::connections::systemBus->async_method_call(
Ed Tanousac106bf2023-06-07 09:24:59 -07003798 [asyncResp, entryId, bootIndex,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003799 codeIndex](const boost::system::error_code& ec,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303800 const boost::container::flat_map<
3801 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3802 postcode) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003803 if (ec)
3804 {
Ed Tanous62598e32023-07-17 17:06:25 -07003805 BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error");
Ed Tanousac106bf2023-06-07 09:24:59 -07003806 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -07003807 return;
3808 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003809
Ed Tanous002d39b2022-05-31 08:59:27 -07003810 if (postcode.empty())
3811 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003812 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Ed Tanous002d39b2022-05-31 08:59:27 -07003813 return;
3814 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003815
Ed Tanousac106bf2023-06-07 09:24:59 -07003816 if (!fillPostCodeEntry(asyncResp, postcode, bootIndex, codeIndex))
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003817 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003818 messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08003819 return;
3820 }
Patrick Williams5a39f772023-10-20 11:20:21 -05003821 },
Jonathan Doman15124762021-01-07 17:54:17 -08003822 "xyz.openbmc_project.State.Boot.PostCode0",
3823 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003824 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3825 bootIndex);
3826}
3827
Ed Tanousac106bf2023-06-07 09:24:59 -07003828static void
3829 getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3830 const uint16_t bootIndex, const uint16_t bootCount,
3831 const uint64_t entryCount, size_t skip, size_t top)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003832{
3833 crow::connections::systemBus->async_method_call(
Ed Tanousac106bf2023-06-07 09:24:59 -07003834 [asyncResp, bootIndex, bootCount, entryCount, skip,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08003835 top](const boost::system::error_code& ec,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303836 const boost::container::flat_map<
3837 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3838 postcode) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003839 if (ec)
3840 {
Ed Tanous62598e32023-07-17 17:06:25 -07003841 BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error");
Ed Tanousac106bf2023-06-07 09:24:59 -07003842 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -07003843 return;
3844 }
ZhikuiRena3316fc2020-01-29 14:58:08 -08003845
Ed Tanous002d39b2022-05-31 08:59:27 -07003846 uint64_t endCount = entryCount;
3847 if (!postcode.empty())
3848 {
3849 endCount = entryCount + postcode.size();
Ed Tanous3648c8b2022-07-25 13:39:59 -07003850 if (skip < endCount && (top + skip) > entryCount)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003851 {
Patrick Williams89492a12023-05-10 07:51:34 -05003852 uint64_t thisBootSkip = std::max(static_cast<uint64_t>(skip),
3853 entryCount) -
3854 entryCount;
Ed Tanous002d39b2022-05-31 08:59:27 -07003855 uint64_t thisBootTop =
Ed Tanous3648c8b2022-07-25 13:39:59 -07003856 std::min(static_cast<uint64_t>(top + skip), endCount) -
3857 entryCount;
Ed Tanous002d39b2022-05-31 08:59:27 -07003858
Ed Tanousac106bf2023-06-07 09:24:59 -07003859 fillPostCodeEntry(asyncResp, postcode, bootIndex, 0,
3860 thisBootSkip, thisBootTop);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003861 }
Ed Tanousac106bf2023-06-07 09:24:59 -07003862 asyncResp->res.jsonValue["Members@odata.count"] = endCount;
Ed Tanous002d39b2022-05-31 08:59:27 -07003863 }
3864
3865 // continue to previous bootIndex
3866 if (bootIndex < bootCount)
3867 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003868 getPostCodeForBoot(asyncResp, static_cast<uint16_t>(bootIndex + 1),
Ed Tanous002d39b2022-05-31 08:59:27 -07003869 bootCount, endCount, skip, top);
3870 }
Jiaqing Zhao81584ab2022-07-28 00:33:45 +08003871 else if (skip + top < endCount)
Ed Tanous002d39b2022-05-31 08:59:27 -07003872 {
Ed Tanousac106bf2023-06-07 09:24:59 -07003873 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003874 std::format(
3875 "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries?$skip=",
3876 BMCWEB_REDFISH_SYSTEM_URI_NAME) +
Ed Tanous002d39b2022-05-31 08:59:27 -07003877 std::to_string(skip + top);
3878 }
Patrick Williams5a39f772023-10-20 11:20:21 -05003879 },
Jonathan Doman15124762021-01-07 17:54:17 -08003880 "xyz.openbmc_project.State.Boot.PostCode0",
3881 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003882 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3883 bootIndex);
3884}
3885
zhanghch058d1b46d2021-04-01 11:18:24 +08003886static void
Ed Tanousac106bf2023-06-07 09:24:59 -07003887 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous3648c8b2022-07-25 13:39:59 -07003888 size_t skip, size_t top)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003889{
3890 uint64_t entryCount = 0;
Jonathan Doman1e1e5982021-06-11 09:36:17 -07003891 sdbusplus::asio::getProperty<uint16_t>(
3892 *crow::connections::systemBus,
3893 "xyz.openbmc_project.State.Boot.PostCode0",
3894 "/xyz/openbmc_project/State/Boot/PostCode0",
3895 "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount",
Ed Tanousac106bf2023-06-07 09:24:59 -07003896 [asyncResp, entryCount, skip, top](const boost::system::error_code& ec,
3897 const uint16_t bootCount) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003898 if (ec)
3899 {
Ed Tanous62598e32023-07-17 17:06:25 -07003900 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
Ed Tanousac106bf2023-06-07 09:24:59 -07003901 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -07003902 return;
3903 }
Ed Tanousac106bf2023-06-07 09:24:59 -07003904 getPostCodeForBoot(asyncResp, 1, bootCount, entryCount, skip, top);
Patrick Williams5a39f772023-10-20 11:20:21 -05003905 });
ZhikuiRena3316fc2020-01-29 14:58:08 -08003906}
3907
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003908inline void requestRoutesPostCodesEntryCollection(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003909{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003910 BMCWEB_ROUTE(app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003911 "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/")
Ed Tanoused398212021-06-09 17:05:54 -07003912 .privileges(redfish::privileges::getLogEntryCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003913 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003914 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07003915 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3916 const std::string& systemName) {
Ed Tanous002d39b2022-05-31 08:59:27 -07003917 query_param::QueryCapabilities capabilities = {
3918 .canDelegateTop = true,
3919 .canDelegateSkip = true,
3920 };
3921 query_param::Query delegatedQuery;
3922 if (!redfish::setUpRedfishRouteWithDelegation(
Carson Labrado3ba00072022-06-06 19:40:56 +00003923 app, req, asyncResp, delegatedQuery, capabilities))
Ed Tanous002d39b2022-05-31 08:59:27 -07003924 {
3925 return;
3926 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003927 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003928 {
3929 // Option currently returns no systems. TBD
3930 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3931 systemName);
3932 return;
3933 }
Ed Tanous22d268c2022-05-19 09:39:07 -07003934
Ed Tanous253f11b2024-05-16 09:38:31 -07003935 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003936 {
3937 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3938 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003939 return;
3940 }
Ed Tanous002d39b2022-05-31 08:59:27 -07003941 asyncResp->res.jsonValue["@odata.type"] =
3942 "#LogEntryCollection.LogEntryCollection";
3943 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07003944 std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries",
3945 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Ed Tanous002d39b2022-05-31 08:59:27 -07003946 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3947 asyncResp->res.jsonValue["Description"] =
3948 "Collection of POST Code Log Entries";
3949 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3950 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Ed Tanous3648c8b2022-07-25 13:39:59 -07003951 size_t skip = delegatedQuery.skip.value_or(0);
Jiaqing Zhao5143f7a2022-07-22 09:33:33 +08003952 size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
Ed Tanous3648c8b2022-07-25 13:39:59 -07003953 getCurrentBootNumber(asyncResp, skip, top);
Patrick Williams5a39f772023-10-20 11:20:21 -05003954 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003955}
ZhikuiRena3316fc2020-01-29 14:58:08 -08003956
George Liu647b3cd2021-07-05 12:43:56 +08003957inline void requestRoutesPostCodesEntryAdditionalData(App& app)
3958{
George Liu0fda0f12021-11-16 10:06:17 +08003959 BMCWEB_ROUTE(
3960 app,
Ed Tanous22d268c2022-05-19 09:39:07 -07003961 "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/")
George Liu647b3cd2021-07-05 12:43:56 +08003962 .privileges(redfish::privileges::getLogEntry)
3963 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07003964 [&app](const crow::Request& req,
3965 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07003966 const std::string& systemName,
Ed Tanous45ca1b82022-03-25 13:07:27 -07003967 const std::string& postCodeID) {
Carson Labrado3ba00072022-06-06 19:40:56 +00003968 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07003969 {
3970 return;
3971 }
Matt Spinler72e21372023-04-19 12:53:33 -05003972 if (!http_helpers::isContentTypeAllowed(
Ed Tanous99351cd2022-08-07 16:42:51 -07003973 req.getHeaderValue("Accept"),
Ed Tanous4a0e1a02022-09-21 15:28:04 -07003974 http_helpers::ContentType::OctetStream, true))
Ed Tanous002d39b2022-05-31 08:59:27 -07003975 {
3976 asyncResp->res.result(boost::beast::http::status::bad_request);
3977 return;
3978 }
Ed Tanous25b54db2024-04-17 15:40:31 -07003979 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08003980 {
3981 // Option currently returns no systems. TBD
3982 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3983 systemName);
3984 return;
3985 }
Ed Tanous253f11b2024-05-16 09:38:31 -07003986 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07003987 {
3988 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3989 systemName);
Ed Tanous22d268c2022-05-19 09:39:07 -07003990 return;
3991 }
George Liu647b3cd2021-07-05 12:43:56 +08003992
Ed Tanous002d39b2022-05-31 08:59:27 -07003993 uint64_t currentValue = 0;
3994 uint16_t index = 0;
3995 if (!parsePostCode(postCodeID, currentValue, index))
3996 {
3997 messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID);
3998 return;
3999 }
George Liu647b3cd2021-07-05 12:43:56 +08004000
Ed Tanous002d39b2022-05-31 08:59:27 -07004001 crow::connections::systemBus->async_method_call(
4002 [asyncResp, postCodeID, currentValue](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08004003 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07004004 const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>&
4005 postcodes) {
4006 if (ec.value() == EBADR)
4007 {
4008 messages::resourceNotFound(asyncResp->res, "LogEntry",
4009 postCodeID);
4010 return;
4011 }
4012 if (ec)
4013 {
Ed Tanous62598e32023-07-17 17:06:25 -07004014 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07004015 messages::internalError(asyncResp->res);
4016 return;
4017 }
George Liu647b3cd2021-07-05 12:43:56 +08004018
Ed Tanous002d39b2022-05-31 08:59:27 -07004019 size_t value = static_cast<size_t>(currentValue) - 1;
4020 if (value == std::string::npos || postcodes.size() < currentValue)
4021 {
Ed Tanous62598e32023-07-17 17:06:25 -07004022 BMCWEB_LOG_WARNING("Wrong currentValue value");
Ed Tanous002d39b2022-05-31 08:59:27 -07004023 messages::resourceNotFound(asyncResp->res, "LogEntry",
4024 postCodeID);
4025 return;
4026 }
George Liu647b3cd2021-07-05 12:43:56 +08004027
Ed Tanous002d39b2022-05-31 08:59:27 -07004028 const auto& [tID, c] = postcodes[value];
4029 if (c.empty())
4030 {
Ed Tanous62598e32023-07-17 17:06:25 -07004031 BMCWEB_LOG_WARNING("No found post code data");
Ed Tanous002d39b2022-05-31 08:59:27 -07004032 messages::resourceNotFound(asyncResp->res, "LogEntry",
4033 postCodeID);
4034 return;
4035 }
4036 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
4037 const char* d = reinterpret_cast<const char*>(c.data());
4038 std::string_view strData(d, c.size());
George Liu647b3cd2021-07-05 12:43:56 +08004039
Ed Tanousd9f6c622022-03-17 09:12:17 -07004040 asyncResp->res.addHeader(boost::beast::http::field::content_type,
Ed Tanous002d39b2022-05-31 08:59:27 -07004041 "application/octet-stream");
Ed Tanousd9f6c622022-03-17 09:12:17 -07004042 asyncResp->res.addHeader(
4043 boost::beast::http::field::content_transfer_encoding, "Base64");
Ed Tanous27b0cf92023-08-07 12:02:40 -07004044 asyncResp->res.write(crow::utility::base64encode(strData));
Patrick Williams5a39f772023-10-20 11:20:21 -05004045 },
Ed Tanous002d39b2022-05-31 08:59:27 -07004046 "xyz.openbmc_project.State.Boot.PostCode0",
4047 "/xyz/openbmc_project/State/Boot/PostCode0",
4048 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index);
Patrick Williams5a39f772023-10-20 11:20:21 -05004049 });
George Liu647b3cd2021-07-05 12:43:56 +08004050}
4051
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004052inline void requestRoutesPostCodesEntry(App& app)
ZhikuiRena3316fc2020-01-29 14:58:08 -08004053{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004054 BMCWEB_ROUTE(
Ed Tanous22d268c2022-05-19 09:39:07 -07004055 app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07004056 .privileges(redfish::privileges::getLogEntry)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004057 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07004058 [&app](const crow::Request& req,
4059 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07004060 const std::string& systemName, const std::string& targetID) {
Carson Labrado3ba00072022-06-06 19:40:56 +00004061 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07004062 {
4063 return;
4064 }
Ed Tanous25b54db2024-04-17 15:40:31 -07004065 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08004066 {
4067 // Option currently returns no systems. TBD
4068 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
4069 systemName);
4070 return;
4071 }
Ed Tanous253f11b2024-05-16 09:38:31 -07004072 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07004073 {
4074 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
4075 systemName);
4076 return;
4077 }
4078
Jiaqing Zhao6f284d22022-10-10 15:56:45 +08004079 getPostCodeForEntry(asyncResp, targetID);
Patrick Williams5a39f772023-10-20 11:20:21 -05004080 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07004081}
ZhikuiRena3316fc2020-01-29 14:58:08 -08004082
Ed Tanous1da66f72018-07-27 16:13:37 -07004083} // namespace redfish