xref: /openbmc/bmcweb/features/redfish/lib/log_services.hpp (revision b0b6152c5457de60db8ed38a4e8b31513e30edd0)
11da66f75SEd Tanous /*
21da66f75SEd Tanous // Copyright (c) 2018 Intel Corporation
31da66f75SEd Tanous //
41da66f75SEd Tanous // Licensed under the Apache License, Version 2.0 (the "License");
51da66f75SEd Tanous // you may not use this file except in compliance with the License.
61da66f75SEd Tanous // You may obtain a copy of the License at
71da66f75SEd Tanous //
81da66f75SEd Tanous //      http://www.apache.org/licenses/LICENSE-2.0
91da66f75SEd Tanous //
101da66f75SEd Tanous // Unless required by applicable law or agreed to in writing, software
111da66f75SEd Tanous // distributed under the License is distributed on an "AS IS" BASIS,
121da66f75SEd Tanous // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131da66f75SEd Tanous // See the License for the specific language governing permissions and
141da66f75SEd Tanous // limitations under the License.
151da66f75SEd Tanous */
161da66f75SEd Tanous #pragma once
171da66f75SEd Tanous 
183ccb3adbSEd Tanous #include "app.hpp"
197a1dbc48SGeorge Liu #include "dbus_utility.hpp"
203ccb3adbSEd Tanous #include "error_messages.hpp"
2168dd075aSAsmitha Karunanithi #include "generated/enums/log_entry.hpp"
22539d8c6bSEd Tanous #include "generated/enums/log_service.hpp"
23b7028ebfSSpencer Ku #include "gzfile.hpp"
24647b3cdcSGeorge Liu #include "http_utility.hpp"
25b7028ebfSSpencer Ku #include "human_sort.hpp"
263ccb3adbSEd Tanous #include "query.hpp"
274851d45dSJason M. Bills #include "registries.hpp"
284851d45dSJason M. Bills #include "registries/base_message_registry.hpp"
294851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp"
303ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
3146229577SJames Feist #include "task.hpp"
325b90429aSEd Tanous #include "task_messages.hpp"
333ccb3adbSEd Tanous #include "utils/dbus_utils.hpp"
345b90429aSEd Tanous #include "utils/json_utils.hpp"
353ccb3adbSEd Tanous #include "utils/time_utils.hpp"
361da66f75SEd Tanous 
3775e8e218SMyung Bae #include <systemd/sd-id128.h>
388e31778eSAsmitha Karunanithi #include <tinyxml2.h>
39400fd1fbSAdriana Kobylak #include <unistd.h>
40e1f26343SJason M. Bills 
4107c8c20dSEd Tanous #include <boost/beast/http/verb.hpp>
421da66f75SEd Tanous #include <boost/container/flat_map.hpp>
431ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp>
44ef4c65b7SEd Tanous #include <boost/url/format.hpp>
45d1bde9e5SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp>
46d1bde9e5SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp>
471214b7e7SGunnar Mills 
487a1dbc48SGeorge Liu #include <array>
49647b3cdcSGeorge Liu #include <charconv>
50b5f288d2SAbhilash Raju #include <cstddef>
514418c7f0SJames Feist #include <filesystem>
5218f8f608SEd Tanous #include <iterator>
5375710de2SXiaochao Ma #include <optional>
543544d2a7SEd Tanous #include <ranges>
5526702d01SEd Tanous #include <span>
5618f8f608SEd Tanous #include <string>
57cd225da8SJason M. Bills #include <string_view>
58abf2add6SEd Tanous #include <variant>
591da66f75SEd Tanous 
601da66f75SEd Tanous namespace redfish
611da66f75SEd Tanous {
621da66f75SEd Tanous 
6389492a15SPatrick Williams constexpr const char* crashdumpObject = "com.intel.crashdump";
6489492a15SPatrick Williams constexpr const char* crashdumpPath = "/com/intel/crashdump";
6589492a15SPatrick Williams constexpr const char* crashdumpInterface = "com.intel.crashdump";
6689492a15SPatrick Williams constexpr const char* deleteAllInterface =
675b61b5e8SJason M. Bills     "xyz.openbmc_project.Collection.DeleteAll";
6889492a15SPatrick Williams constexpr const char* crashdumpOnDemandInterface =
69424c4176SJason M. Bills     "com.intel.crashdump.OnDemand";
7089492a15SPatrick Williams constexpr const char* crashdumpTelemetryInterface =
716eda7685SKenny L. Ku     "com.intel.crashdump.Telemetry";
721da66f75SEd Tanous 
738e31778eSAsmitha Karunanithi enum class DumpCreationProgress
748e31778eSAsmitha Karunanithi {
758e31778eSAsmitha Karunanithi     DUMP_CREATE_SUCCESS,
768e31778eSAsmitha Karunanithi     DUMP_CREATE_FAILED,
778e31778eSAsmitha Karunanithi     DUMP_CREATE_INPROGRESS
788e31778eSAsmitha Karunanithi };
798e31778eSAsmitha Karunanithi 
80f6150403SJames Feist namespace fs = std::filesystem;
811da66f75SEd Tanous 
82cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s)
83cb92c03bSAndrew Geissler {
84d4d25793SEd Tanous     if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
85d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
86d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
87d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
88cb92c03bSAndrew Geissler     {
89cb92c03bSAndrew Geissler         return "Critical";
90cb92c03bSAndrew Geissler     }
913174e4dfSEd Tanous     if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
92d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
93d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
94cb92c03bSAndrew Geissler     {
95cb92c03bSAndrew Geissler         return "OK";
96cb92c03bSAndrew Geissler     }
973174e4dfSEd Tanous     if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
98cb92c03bSAndrew Geissler     {
99cb92c03bSAndrew Geissler         return "Warning";
100cb92c03bSAndrew Geissler     }
101cb92c03bSAndrew Geissler     return "";
102cb92c03bSAndrew Geissler }
103cb92c03bSAndrew Geissler 
1049017faf2SAbhishek Patel inline std::optional<bool> getProviderNotifyAction(const std::string& notify)
1059017faf2SAbhishek Patel {
1069017faf2SAbhishek Patel     std::optional<bool> notifyAction;
1079017faf2SAbhishek Patel     if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify")
1089017faf2SAbhishek Patel     {
1099017faf2SAbhishek Patel         notifyAction = true;
1109017faf2SAbhishek Patel     }
1119017faf2SAbhishek Patel     else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit")
1129017faf2SAbhishek Patel     {
1139017faf2SAbhishek Patel         notifyAction = false;
1149017faf2SAbhishek Patel     }
1159017faf2SAbhishek Patel 
1169017faf2SAbhishek Patel     return notifyAction;
1179017faf2SAbhishek Patel }
1189017faf2SAbhishek Patel 
11918f8f608SEd Tanous inline std::string getDumpPath(std::string_view dumpType)
12018f8f608SEd Tanous {
12118f8f608SEd Tanous     std::string dbusDumpPath = "/xyz/openbmc_project/dump/";
12218f8f608SEd Tanous     std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath),
12318f8f608SEd Tanous                            bmcweb::asciiToLower);
12418f8f608SEd Tanous 
12518f8f608SEd Tanous     return dbusDumpPath;
12618f8f608SEd Tanous }
12718f8f608SEd Tanous 
128055713e4SEd Tanous inline bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
129e85d6b16SJason M. Bills                              const bool firstEntry = true)
13095820184SJason M. Bills {
131271584abSEd Tanous     static time_t prevTs = 0;
13295820184SJason M. Bills     static int index = 0;
133e85d6b16SJason M. Bills     if (firstEntry)
134e85d6b16SJason M. Bills     {
135e85d6b16SJason M. Bills         prevTs = 0;
136e85d6b16SJason M. Bills     }
137e85d6b16SJason M. Bills 
13895820184SJason M. Bills     // Get the entry timestamp
139271584abSEd Tanous     std::time_t curTs = 0;
14095820184SJason M. Bills     std::tm timeStruct = {};
14195820184SJason M. Bills     std::istringstream entryStream(logEntry);
14295820184SJason M. Bills     if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
14395820184SJason M. Bills     {
14495820184SJason M. Bills         curTs = std::mktime(&timeStruct);
14595820184SJason M. Bills     }
14695820184SJason M. Bills     // If the timestamp isn't unique, increment the index
14795820184SJason M. Bills     if (curTs == prevTs)
14895820184SJason M. Bills     {
14995820184SJason M. Bills         index++;
15095820184SJason M. Bills     }
15195820184SJason M. Bills     else
15295820184SJason M. Bills     {
15395820184SJason M. Bills         // Otherwise, reset it
15495820184SJason M. Bills         index = 0;
15595820184SJason M. Bills     }
15695820184SJason M. Bills     // Save the timestamp
15795820184SJason M. Bills     prevTs = curTs;
15895820184SJason M. Bills 
15995820184SJason M. Bills     entryID = std::to_string(curTs);
16095820184SJason M. Bills     if (index > 0)
16195820184SJason M. Bills     {
16295820184SJason M. Bills         entryID += "_" + std::to_string(index);
16395820184SJason M. Bills     }
16495820184SJason M. Bills     return true;
16595820184SJason M. Bills }
16695820184SJason M. Bills 
16795820184SJason M. Bills static bool
16895820184SJason M. Bills     getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
16995820184SJason M. Bills {
17095820184SJason M. Bills     static const std::filesystem::path redfishLogDir = "/var/log";
17195820184SJason M. Bills     static const std::string redfishLogFilename = "redfish";
17295820184SJason M. Bills 
17395820184SJason M. Bills     // Loop through the directory looking for redfish log files
17495820184SJason M. Bills     for (const std::filesystem::directory_entry& dirEnt :
17595820184SJason M. Bills          std::filesystem::directory_iterator(redfishLogDir))
17695820184SJason M. Bills     {
17795820184SJason M. Bills         // If we find a redfish log file, save the path
17895820184SJason M. Bills         std::string filename = dirEnt.path().filename();
17911ba3979SEd Tanous         if (filename.starts_with(redfishLogFilename))
18095820184SJason M. Bills         {
18195820184SJason M. Bills             redfishLogFiles.emplace_back(redfishLogDir / filename);
18295820184SJason M. Bills         }
18395820184SJason M. Bills     }
18495820184SJason M. Bills     // As the log files rotate, they are appended with a ".#" that is higher for
18595820184SJason M. Bills     // the older logs. Since we don't expect more than 10 log files, we
18695820184SJason M. Bills     // can just sort the list to get them in order from newest to oldest
1873544d2a7SEd Tanous     std::ranges::sort(redfishLogFiles);
18895820184SJason M. Bills 
18995820184SJason M. Bills     return !redfishLogFiles.empty();
19095820184SJason M. Bills }
19195820184SJason M. Bills 
19268dd075aSAsmitha Karunanithi inline log_entry::OriginatorTypes
19368dd075aSAsmitha Karunanithi     mapDbusOriginatorTypeToRedfish(const std::string& originatorType)
19468dd075aSAsmitha Karunanithi {
19568dd075aSAsmitha Karunanithi     if (originatorType ==
19668dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client")
19768dd075aSAsmitha Karunanithi     {
19868dd075aSAsmitha Karunanithi         return log_entry::OriginatorTypes::Client;
19968dd075aSAsmitha Karunanithi     }
20068dd075aSAsmitha Karunanithi     if (originatorType ==
20168dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal")
20268dd075aSAsmitha Karunanithi     {
20368dd075aSAsmitha Karunanithi         return log_entry::OriginatorTypes::Internal;
20468dd075aSAsmitha Karunanithi     }
20568dd075aSAsmitha Karunanithi     if (originatorType ==
20668dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService")
20768dd075aSAsmitha Karunanithi     {
20868dd075aSAsmitha Karunanithi         return log_entry::OriginatorTypes::SupportingService;
20968dd075aSAsmitha Karunanithi     }
21068dd075aSAsmitha Karunanithi     return log_entry::OriginatorTypes::Invalid;
21168dd075aSAsmitha Karunanithi }
21268dd075aSAsmitha Karunanithi 
213aefe3786SClaire Weinan inline void parseDumpEntryFromDbusObject(
2142d613eb6SJiaqing Zhao     const dbus::utility::ManagedObjectType::value_type& object,
215c6fecdabSClaire Weinan     std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs,
21668dd075aSAsmitha Karunanithi     std::string& originatorId, log_entry::OriginatorTypes& originatorType,
217aefe3786SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
218aefe3786SClaire Weinan {
219aefe3786SClaire Weinan     for (const auto& interfaceMap : object.second)
220aefe3786SClaire Weinan     {
221aefe3786SClaire Weinan         if (interfaceMap.first == "xyz.openbmc_project.Common.Progress")
222aefe3786SClaire Weinan         {
223aefe3786SClaire Weinan             for (const auto& propertyMap : interfaceMap.second)
224aefe3786SClaire Weinan             {
225aefe3786SClaire Weinan                 if (propertyMap.first == "Status")
226aefe3786SClaire Weinan                 {
227aefe3786SClaire Weinan                     const auto* status =
228aefe3786SClaire Weinan                         std::get_if<std::string>(&propertyMap.second);
229aefe3786SClaire Weinan                     if (status == nullptr)
230aefe3786SClaire Weinan                     {
231aefe3786SClaire Weinan                         messages::internalError(asyncResp->res);
232aefe3786SClaire Weinan                         break;
233aefe3786SClaire Weinan                     }
234aefe3786SClaire Weinan                     dumpStatus = *status;
235aefe3786SClaire Weinan                 }
236aefe3786SClaire Weinan             }
237aefe3786SClaire Weinan         }
238aefe3786SClaire Weinan         else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
239aefe3786SClaire Weinan         {
240aefe3786SClaire Weinan             for (const auto& propertyMap : interfaceMap.second)
241aefe3786SClaire Weinan             {
242aefe3786SClaire Weinan                 if (propertyMap.first == "Size")
243aefe3786SClaire Weinan                 {
244aefe3786SClaire Weinan                     const auto* sizePtr =
245aefe3786SClaire Weinan                         std::get_if<uint64_t>(&propertyMap.second);
246aefe3786SClaire Weinan                     if (sizePtr == nullptr)
247aefe3786SClaire Weinan                     {
248aefe3786SClaire Weinan                         messages::internalError(asyncResp->res);
249aefe3786SClaire Weinan                         break;
250aefe3786SClaire Weinan                     }
251aefe3786SClaire Weinan                     size = *sizePtr;
252aefe3786SClaire Weinan                     break;
253aefe3786SClaire Weinan                 }
254aefe3786SClaire Weinan             }
255aefe3786SClaire Weinan         }
256aefe3786SClaire Weinan         else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime")
257aefe3786SClaire Weinan         {
258aefe3786SClaire Weinan             for (const auto& propertyMap : interfaceMap.second)
259aefe3786SClaire Weinan             {
260aefe3786SClaire Weinan                 if (propertyMap.first == "Elapsed")
261aefe3786SClaire Weinan                 {
262aefe3786SClaire Weinan                     const uint64_t* usecsTimeStamp =
263aefe3786SClaire Weinan                         std::get_if<uint64_t>(&propertyMap.second);
264aefe3786SClaire Weinan                     if (usecsTimeStamp == nullptr)
265aefe3786SClaire Weinan                     {
266aefe3786SClaire Weinan                         messages::internalError(asyncResp->res);
267aefe3786SClaire Weinan                         break;
268aefe3786SClaire Weinan                     }
269c6fecdabSClaire Weinan                     timestampUs = *usecsTimeStamp;
270aefe3786SClaire Weinan                     break;
271aefe3786SClaire Weinan                 }
272aefe3786SClaire Weinan             }
273aefe3786SClaire Weinan         }
27468dd075aSAsmitha Karunanithi         else if (interfaceMap.first ==
27568dd075aSAsmitha Karunanithi                  "xyz.openbmc_project.Common.OriginatedBy")
27668dd075aSAsmitha Karunanithi         {
27768dd075aSAsmitha Karunanithi             for (const auto& propertyMap : interfaceMap.second)
27868dd075aSAsmitha Karunanithi             {
27968dd075aSAsmitha Karunanithi                 if (propertyMap.first == "OriginatorId")
28068dd075aSAsmitha Karunanithi                 {
28168dd075aSAsmitha Karunanithi                     const std::string* id =
28268dd075aSAsmitha Karunanithi                         std::get_if<std::string>(&propertyMap.second);
28368dd075aSAsmitha Karunanithi                     if (id == nullptr)
28468dd075aSAsmitha Karunanithi                     {
28568dd075aSAsmitha Karunanithi                         messages::internalError(asyncResp->res);
28668dd075aSAsmitha Karunanithi                         break;
28768dd075aSAsmitha Karunanithi                     }
28868dd075aSAsmitha Karunanithi                     originatorId = *id;
28968dd075aSAsmitha Karunanithi                 }
29068dd075aSAsmitha Karunanithi 
29168dd075aSAsmitha Karunanithi                 if (propertyMap.first == "OriginatorType")
29268dd075aSAsmitha Karunanithi                 {
29368dd075aSAsmitha Karunanithi                     const std::string* type =
29468dd075aSAsmitha Karunanithi                         std::get_if<std::string>(&propertyMap.second);
29568dd075aSAsmitha Karunanithi                     if (type == nullptr)
29668dd075aSAsmitha Karunanithi                     {
29768dd075aSAsmitha Karunanithi                         messages::internalError(asyncResp->res);
29868dd075aSAsmitha Karunanithi                         break;
29968dd075aSAsmitha Karunanithi                     }
30068dd075aSAsmitha Karunanithi 
30168dd075aSAsmitha Karunanithi                     originatorType = mapDbusOriginatorTypeToRedfish(*type);
30268dd075aSAsmitha Karunanithi                     if (originatorType == log_entry::OriginatorTypes::Invalid)
30368dd075aSAsmitha Karunanithi                     {
30468dd075aSAsmitha Karunanithi                         messages::internalError(asyncResp->res);
30568dd075aSAsmitha Karunanithi                         break;
30668dd075aSAsmitha Karunanithi                     }
30768dd075aSAsmitha Karunanithi                 }
30868dd075aSAsmitha Karunanithi             }
30968dd075aSAsmitha Karunanithi         }
310aefe3786SClaire Weinan     }
311aefe3786SClaire Weinan }
312aefe3786SClaire Weinan 
31321ab404cSNan Zhou static std::string getDumpEntriesPath(const std::string& dumpType)
314fdd26906SClaire Weinan {
315fdd26906SClaire Weinan     std::string entriesPath;
316fdd26906SClaire Weinan 
317fdd26906SClaire Weinan     if (dumpType == "BMC")
318fdd26906SClaire Weinan     {
319253f11b8SEd Tanous         entriesPath =
320253f11b8SEd Tanous             std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
321253f11b8SEd Tanous                         BMCWEB_REDFISH_MANAGER_URI_NAME);
322fdd26906SClaire Weinan     }
323fdd26906SClaire Weinan     else if (dumpType == "FaultLog")
324fdd26906SClaire Weinan     {
325253f11b8SEd Tanous         entriesPath =
326253f11b8SEd Tanous             std::format("/redfish/v1/Managers/{}/LogServices/FaultLog/Entries/",
327253f11b8SEd Tanous                         BMCWEB_REDFISH_MANAGER_URI_NAME);
328fdd26906SClaire Weinan     }
329fdd26906SClaire Weinan     else if (dumpType == "System")
330fdd26906SClaire Weinan     {
331253f11b8SEd Tanous         entriesPath =
332253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
333253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
334fdd26906SClaire Weinan     }
335fdd26906SClaire Weinan     else
336fdd26906SClaire Weinan     {
33762598e31SEd Tanous         BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}",
33862598e31SEd Tanous                          dumpType);
339fdd26906SClaire Weinan     }
340fdd26906SClaire Weinan 
341fdd26906SClaire Weinan     // Returns empty string on error
342fdd26906SClaire Weinan     return entriesPath;
343fdd26906SClaire Weinan }
344fdd26906SClaire Weinan 
3458d1b46d7Szhanghch05 inline void
3468d1b46d7Szhanghch05     getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3475cb1dd27SAsmitha Karunanithi                            const std::string& dumpType)
3485cb1dd27SAsmitha Karunanithi {
349fdd26906SClaire Weinan     std::string entriesPath = getDumpEntriesPath(dumpType);
350fdd26906SClaire Weinan     if (entriesPath.empty())
3515cb1dd27SAsmitha Karunanithi     {
3525cb1dd27SAsmitha Karunanithi         messages::internalError(asyncResp->res);
3535cb1dd27SAsmitha Karunanithi         return;
3545cb1dd27SAsmitha Karunanithi     }
3555cb1dd27SAsmitha Karunanithi 
3565eb468daSGeorge Liu     sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
3575eb468daSGeorge Liu     dbus::utility::getManagedObjects(
3585eb468daSGeorge Liu         "xyz.openbmc_project.Dump.Manager", path,
359fdd26906SClaire Weinan         [asyncResp, entriesPath,
3605e7e2dc5SEd Tanous          dumpType](const boost::system::error_code& ec,
3615eb468daSGeorge Liu                    const dbus::utility::ManagedObjectType& objects) {
3625cb1dd27SAsmitha Karunanithi         if (ec)
3635cb1dd27SAsmitha Karunanithi         {
36462598e31SEd Tanous             BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
3655cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
3665cb1dd27SAsmitha Karunanithi             return;
3675cb1dd27SAsmitha Karunanithi         }
3685cb1dd27SAsmitha Karunanithi 
369fdd26906SClaire Weinan         // Remove ending slash
370fdd26906SClaire Weinan         std::string odataIdStr = entriesPath;
371fdd26906SClaire Weinan         if (!odataIdStr.empty())
372fdd26906SClaire Weinan         {
373fdd26906SClaire Weinan             odataIdStr.pop_back();
374fdd26906SClaire Weinan         }
375fdd26906SClaire Weinan 
376fdd26906SClaire Weinan         asyncResp->res.jsonValue["@odata.type"] =
377fdd26906SClaire Weinan             "#LogEntryCollection.LogEntryCollection";
378fdd26906SClaire Weinan         asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr);
379fdd26906SClaire Weinan         asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries";
38089492a15SPatrick Williams         asyncResp->res.jsonValue["Description"] = "Collection of " + dumpType +
38189492a15SPatrick Williams                                                   " Dump Entries";
382fdd26906SClaire Weinan 
3833544d2a7SEd Tanous         nlohmann::json::array_t entriesArray;
38418f8f608SEd Tanous         std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
3855cb1dd27SAsmitha Karunanithi 
3865eb468daSGeorge Liu         dbus::utility::ManagedObjectType resp(objects);
3873544d2a7SEd Tanous         std::ranges::sort(resp, [](const auto& l, const auto& r) {
388002d39b4SEd Tanous             return AlphanumLess<std::string>()(l.first.filename(),
389002d39b4SEd Tanous                                                r.first.filename());
390565dfb6fSClaire Weinan         });
391565dfb6fSClaire Weinan 
3925cb1dd27SAsmitha Karunanithi         for (auto& object : resp)
3935cb1dd27SAsmitha Karunanithi         {
394b47452b2SAsmitha Karunanithi             if (object.first.str.find(dumpEntryPath) == std::string::npos)
3955cb1dd27SAsmitha Karunanithi             {
3965cb1dd27SAsmitha Karunanithi                 continue;
3975cb1dd27SAsmitha Karunanithi             }
398c6fecdabSClaire Weinan             uint64_t timestampUs = 0;
3995cb1dd27SAsmitha Karunanithi             uint64_t size = 0;
40035440d18SAsmitha Karunanithi             std::string dumpStatus;
40168dd075aSAsmitha Karunanithi             std::string originatorId;
40268dd075aSAsmitha Karunanithi             log_entry::OriginatorTypes originatorType =
40368dd075aSAsmitha Karunanithi                 log_entry::OriginatorTypes::Internal;
404433b68b4SJason M. Bills             nlohmann::json::object_t thisEntry;
4052dfd18efSEd Tanous 
4062dfd18efSEd Tanous             std::string entryID = object.first.filename();
4072dfd18efSEd Tanous             if (entryID.empty())
4085cb1dd27SAsmitha Karunanithi             {
4095cb1dd27SAsmitha Karunanithi                 continue;
4105cb1dd27SAsmitha Karunanithi             }
4115cb1dd27SAsmitha Karunanithi 
412c6fecdabSClaire Weinan             parseDumpEntryFromDbusObject(object, dumpStatus, size, timestampUs,
41368dd075aSAsmitha Karunanithi                                          originatorId, originatorType,
414aefe3786SClaire Weinan                                          asyncResp);
4155cb1dd27SAsmitha Karunanithi 
4160fda0f12SGeorge Liu             if (dumpStatus !=
4170fda0f12SGeorge Liu                     "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
41835440d18SAsmitha Karunanithi                 !dumpStatus.empty())
41935440d18SAsmitha Karunanithi             {
42035440d18SAsmitha Karunanithi                 // Dump status is not Complete, no need to enumerate
42135440d18SAsmitha Karunanithi                 continue;
42235440d18SAsmitha Karunanithi             }
42335440d18SAsmitha Karunanithi 
42468dd075aSAsmitha Karunanithi             thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry";
425fdd26906SClaire Weinan             thisEntry["@odata.id"] = entriesPath + entryID;
4265cb1dd27SAsmitha Karunanithi             thisEntry["Id"] = entryID;
4275cb1dd27SAsmitha Karunanithi             thisEntry["EntryType"] = "Event";
4285cb1dd27SAsmitha Karunanithi             thisEntry["Name"] = dumpType + " Dump Entry";
429bbd80db8SClaire Weinan             thisEntry["Created"] =
430bbd80db8SClaire Weinan                 redfish::time_utils::getDateTimeUintUs(timestampUs);
4315cb1dd27SAsmitha Karunanithi 
43268dd075aSAsmitha Karunanithi             if (!originatorId.empty())
43368dd075aSAsmitha Karunanithi             {
43468dd075aSAsmitha Karunanithi                 thisEntry["Originator"] = originatorId;
43568dd075aSAsmitha Karunanithi                 thisEntry["OriginatorType"] = originatorType;
43668dd075aSAsmitha Karunanithi             }
43768dd075aSAsmitha Karunanithi 
4385cb1dd27SAsmitha Karunanithi             if (dumpType == "BMC")
4395cb1dd27SAsmitha Karunanithi             {
440d337bb72SAsmitha Karunanithi                 thisEntry["DiagnosticDataType"] = "Manager";
44189492a15SPatrick Williams                 thisEntry["AdditionalDataURI"] = entriesPath + entryID +
44289492a15SPatrick Williams                                                  "/attachment";
443fdd26906SClaire Weinan                 thisEntry["AdditionalDataSizeBytes"] = size;
4445cb1dd27SAsmitha Karunanithi             }
4455cb1dd27SAsmitha Karunanithi             else if (dumpType == "System")
4465cb1dd27SAsmitha Karunanithi             {
447d337bb72SAsmitha Karunanithi                 thisEntry["DiagnosticDataType"] = "OEM";
448d337bb72SAsmitha Karunanithi                 thisEntry["OEMDiagnosticDataType"] = "System";
44989492a15SPatrick Williams                 thisEntry["AdditionalDataURI"] = entriesPath + entryID +
45089492a15SPatrick Williams                                                  "/attachment";
451fdd26906SClaire Weinan                 thisEntry["AdditionalDataSizeBytes"] = size;
4525cb1dd27SAsmitha Karunanithi             }
453b2ba3072SPatrick Williams             entriesArray.emplace_back(std::move(thisEntry));
4545cb1dd27SAsmitha Karunanithi         }
455002d39b4SEd Tanous         asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
4563544d2a7SEd Tanous         asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
4575eb468daSGeorge Liu     });
4585cb1dd27SAsmitha Karunanithi }
4595cb1dd27SAsmitha Karunanithi 
4608d1b46d7Szhanghch05 inline void
461c7a6d660SClaire Weinan     getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
4628d1b46d7Szhanghch05                      const std::string& entryID, const std::string& dumpType)
4635cb1dd27SAsmitha Karunanithi {
464fdd26906SClaire Weinan     std::string entriesPath = getDumpEntriesPath(dumpType);
465fdd26906SClaire Weinan     if (entriesPath.empty())
4665cb1dd27SAsmitha Karunanithi     {
4675cb1dd27SAsmitha Karunanithi         messages::internalError(asyncResp->res);
4685cb1dd27SAsmitha Karunanithi         return;
4695cb1dd27SAsmitha Karunanithi     }
4705cb1dd27SAsmitha Karunanithi 
4715eb468daSGeorge Liu     sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
4725eb468daSGeorge Liu     dbus::utility::getManagedObjects(
4735eb468daSGeorge Liu         "xyz.openbmc_project.Dump.Manager", path,
474fdd26906SClaire Weinan         [asyncResp, entryID, dumpType,
4755e7e2dc5SEd Tanous          entriesPath](const boost::system::error_code& ec,
47602cad96eSEd Tanous                       const dbus::utility::ManagedObjectType& resp) {
4775cb1dd27SAsmitha Karunanithi         if (ec)
4785cb1dd27SAsmitha Karunanithi         {
47962598e31SEd Tanous             BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
4805cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
4815cb1dd27SAsmitha Karunanithi             return;
4825cb1dd27SAsmitha Karunanithi         }
4835cb1dd27SAsmitha Karunanithi 
484b47452b2SAsmitha Karunanithi         bool foundDumpEntry = false;
48518f8f608SEd Tanous         std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
486b47452b2SAsmitha Karunanithi 
4879eb808c1SEd Tanous         for (const auto& objectPath : resp)
4885cb1dd27SAsmitha Karunanithi         {
489b47452b2SAsmitha Karunanithi             if (objectPath.first.str != dumpEntryPath + entryID)
4905cb1dd27SAsmitha Karunanithi             {
4915cb1dd27SAsmitha Karunanithi                 continue;
4925cb1dd27SAsmitha Karunanithi             }
4935cb1dd27SAsmitha Karunanithi 
4945cb1dd27SAsmitha Karunanithi             foundDumpEntry = true;
495c6fecdabSClaire Weinan             uint64_t timestampUs = 0;
4965cb1dd27SAsmitha Karunanithi             uint64_t size = 0;
49735440d18SAsmitha Karunanithi             std::string dumpStatus;
49868dd075aSAsmitha Karunanithi             std::string originatorId;
49968dd075aSAsmitha Karunanithi             log_entry::OriginatorTypes originatorType =
50068dd075aSAsmitha Karunanithi                 log_entry::OriginatorTypes::Internal;
5015cb1dd27SAsmitha Karunanithi 
502aefe3786SClaire Weinan             parseDumpEntryFromDbusObject(objectPath, dumpStatus, size,
50368dd075aSAsmitha Karunanithi                                          timestampUs, originatorId,
50468dd075aSAsmitha Karunanithi                                          originatorType, asyncResp);
5055cb1dd27SAsmitha Karunanithi 
5060fda0f12SGeorge Liu             if (dumpStatus !=
5070fda0f12SGeorge Liu                     "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
50835440d18SAsmitha Karunanithi                 !dumpStatus.empty())
50935440d18SAsmitha Karunanithi             {
51035440d18SAsmitha Karunanithi                 // Dump status is not Complete
51135440d18SAsmitha Karunanithi                 // return not found until status is changed to Completed
512d1bde9e5SKrzysztof Grobelny                 messages::resourceNotFound(asyncResp->res, dumpType + " dump",
513d1bde9e5SKrzysztof Grobelny                                            entryID);
51435440d18SAsmitha Karunanithi                 return;
51535440d18SAsmitha Karunanithi             }
51635440d18SAsmitha Karunanithi 
5175cb1dd27SAsmitha Karunanithi             asyncResp->res.jsonValue["@odata.type"] =
51868dd075aSAsmitha Karunanithi                 "#LogEntry.v1_11_0.LogEntry";
519fdd26906SClaire Weinan             asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID;
5205cb1dd27SAsmitha Karunanithi             asyncResp->res.jsonValue["Id"] = entryID;
5215cb1dd27SAsmitha Karunanithi             asyncResp->res.jsonValue["EntryType"] = "Event";
5225cb1dd27SAsmitha Karunanithi             asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
523bbd80db8SClaire Weinan             asyncResp->res.jsonValue["Created"] =
524bbd80db8SClaire Weinan                 redfish::time_utils::getDateTimeUintUs(timestampUs);
5255cb1dd27SAsmitha Karunanithi 
52668dd075aSAsmitha Karunanithi             if (!originatorId.empty())
52768dd075aSAsmitha Karunanithi             {
52868dd075aSAsmitha Karunanithi                 asyncResp->res.jsonValue["Originator"] = originatorId;
52968dd075aSAsmitha Karunanithi                 asyncResp->res.jsonValue["OriginatorType"] = originatorType;
53068dd075aSAsmitha Karunanithi             }
53168dd075aSAsmitha Karunanithi 
5325cb1dd27SAsmitha Karunanithi             if (dumpType == "BMC")
5335cb1dd27SAsmitha Karunanithi             {
534d337bb72SAsmitha Karunanithi                 asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
535d337bb72SAsmitha Karunanithi                 asyncResp->res.jsonValue["AdditionalDataURI"] =
536fdd26906SClaire Weinan                     entriesPath + entryID + "/attachment";
537fdd26906SClaire Weinan                 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
5385cb1dd27SAsmitha Karunanithi             }
5395cb1dd27SAsmitha Karunanithi             else if (dumpType == "System")
5405cb1dd27SAsmitha Karunanithi             {
541d337bb72SAsmitha Karunanithi                 asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
542002d39b4SEd Tanous                 asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System";
543d337bb72SAsmitha Karunanithi                 asyncResp->res.jsonValue["AdditionalDataURI"] =
544fdd26906SClaire Weinan                     entriesPath + entryID + "/attachment";
545fdd26906SClaire Weinan                 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
5465cb1dd27SAsmitha Karunanithi             }
5475cb1dd27SAsmitha Karunanithi         }
548e05aec50SEd Tanous         if (!foundDumpEntry)
549b47452b2SAsmitha Karunanithi         {
55062598e31SEd Tanous             BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
551b90d14f2SMyung Bae             messages::resourceNotFound(asyncResp->res, dumpType + " dump",
552b90d14f2SMyung Bae                                        entryID);
553b47452b2SAsmitha Karunanithi             return;
554b47452b2SAsmitha Karunanithi         }
5555eb468daSGeorge Liu     });
5565cb1dd27SAsmitha Karunanithi }
5575cb1dd27SAsmitha Karunanithi 
5588d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
5599878256fSStanley Chu                             const std::string& entryID,
560b47452b2SAsmitha Karunanithi                             const std::string& dumpType)
5615cb1dd27SAsmitha Karunanithi {
5625a39f77aSPatrick Williams     auto respHandler = [asyncResp,
5635a39f77aSPatrick Williams                         entryID](const boost::system::error_code& ec) {
56462598e31SEd Tanous         BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done");
5655cb1dd27SAsmitha Karunanithi         if (ec)
5665cb1dd27SAsmitha Karunanithi         {
5673de8d8baSGeorge Liu             if (ec.value() == EBADR)
5683de8d8baSGeorge Liu             {
5693de8d8baSGeorge Liu                 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
5703de8d8baSGeorge Liu                 return;
5713de8d8baSGeorge Liu             }
57262598e31SEd Tanous             BMCWEB_LOG_ERROR(
57362598e31SEd Tanous                 "Dump (DBus) doDelete respHandler got error {} entryID={}", ec,
57462598e31SEd Tanous                 entryID);
5755cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
5765cb1dd27SAsmitha Karunanithi             return;
5775cb1dd27SAsmitha Karunanithi         }
5785cb1dd27SAsmitha Karunanithi     };
57918f8f608SEd Tanous 
5805cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
5815cb1dd27SAsmitha Karunanithi         respHandler, "xyz.openbmc_project.Dump.Manager",
58218f8f608SEd Tanous         std::format("{}/entry/{}", getDumpPath(dumpType), entryID),
5835cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Object.Delete", "Delete");
5845cb1dd27SAsmitha Karunanithi }
585b5f288d2SAbhilash Raju inline bool checkSizeLimit(int fd, crow::Response& res)
586b5f288d2SAbhilash Raju {
587b5f288d2SAbhilash Raju     long long int size = lseek(fd, 0, SEEK_END);
588b5f288d2SAbhilash Raju     if (size <= 0)
589b5f288d2SAbhilash Raju     {
590b5f288d2SAbhilash Raju         BMCWEB_LOG_ERROR("Failed to get size of file, lseek() returned {}",
591b5f288d2SAbhilash Raju                          size);
592b5f288d2SAbhilash Raju         messages::internalError(res);
593b5f288d2SAbhilash Raju         return false;
594b5f288d2SAbhilash Raju     }
5955cb1dd27SAsmitha Karunanithi 
596b5f288d2SAbhilash Raju     // Arbitrary max size of 20MB to accommodate BMC dumps
597b5f288d2SAbhilash Raju     constexpr long long int maxFileSize = 20LL * 1024LL * 1024LL;
598b5f288d2SAbhilash Raju     if (size > maxFileSize)
599b5f288d2SAbhilash Raju     {
600b5f288d2SAbhilash Raju         BMCWEB_LOG_ERROR("File size {} exceeds maximum allowed size of {}",
601b5f288d2SAbhilash Raju                          size, maxFileSize);
602b5f288d2SAbhilash Raju         messages::internalError(res);
603b5f288d2SAbhilash Raju         return false;
604b5f288d2SAbhilash Raju     }
605b5f288d2SAbhilash Raju     off_t rc = lseek(fd, 0, SEEK_SET);
606b5f288d2SAbhilash Raju     if (rc < 0)
607b5f288d2SAbhilash Raju     {
608b5f288d2SAbhilash Raju         BMCWEB_LOG_ERROR("Failed to reset file offset to 0");
609b5f288d2SAbhilash Raju         messages::internalError(res);
610b5f288d2SAbhilash Raju         return false;
611b5f288d2SAbhilash Raju     }
612b5f288d2SAbhilash Raju     return true;
613b5f288d2SAbhilash Raju }
614168d1b1aSCarson Labrado inline void
615168d1b1aSCarson Labrado     downloadEntryCallback(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
616168d1b1aSCarson Labrado                           const std::string& entryID,
617168d1b1aSCarson Labrado                           const std::string& downloadEntryType,
618168d1b1aSCarson Labrado                           const boost::system::error_code& ec,
619168d1b1aSCarson Labrado                           const sdbusplus::message::unix_fd& unixfd)
620168d1b1aSCarson Labrado {
621168d1b1aSCarson Labrado     if (ec.value() == EBADR)
622168d1b1aSCarson Labrado     {
623168d1b1aSCarson Labrado         messages::resourceNotFound(asyncResp->res, "EntryAttachment", entryID);
624168d1b1aSCarson Labrado         return;
625168d1b1aSCarson Labrado     }
626168d1b1aSCarson Labrado     if (ec)
627168d1b1aSCarson Labrado     {
628168d1b1aSCarson Labrado         BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
629168d1b1aSCarson Labrado         messages::internalError(asyncResp->res);
630168d1b1aSCarson Labrado         return;
631168d1b1aSCarson Labrado     }
632168d1b1aSCarson Labrado 
633168d1b1aSCarson Labrado     // Make sure we know how to process the retrieved entry attachment
634168d1b1aSCarson Labrado     if ((downloadEntryType != "BMC") && (downloadEntryType != "System"))
635168d1b1aSCarson Labrado     {
636168d1b1aSCarson Labrado         BMCWEB_LOG_ERROR("downloadEntryCallback() invalid entry type: {}",
637168d1b1aSCarson Labrado                          downloadEntryType);
638168d1b1aSCarson Labrado         messages::internalError(asyncResp->res);
639168d1b1aSCarson Labrado     }
640168d1b1aSCarson Labrado 
641168d1b1aSCarson Labrado     int fd = -1;
642168d1b1aSCarson Labrado     fd = dup(unixfd);
643168d1b1aSCarson Labrado     if (fd < 0)
644168d1b1aSCarson Labrado     {
645168d1b1aSCarson Labrado         BMCWEB_LOG_ERROR("Failed to open file");
646168d1b1aSCarson Labrado         messages::internalError(asyncResp->res);
647168d1b1aSCarson Labrado         return;
648168d1b1aSCarson Labrado     }
649b5f288d2SAbhilash Raju     if (!checkSizeLimit(fd, asyncResp->res))
650168d1b1aSCarson Labrado     {
651168d1b1aSCarson Labrado         close(fd);
652168d1b1aSCarson Labrado         return;
653168d1b1aSCarson Labrado     }
654168d1b1aSCarson Labrado     if (downloadEntryType == "System")
655168d1b1aSCarson Labrado     {
656b5f288d2SAbhilash Raju         if (!asyncResp->res.openFd(fd, bmcweb::EncodingType::Base64))
657b5f288d2SAbhilash Raju         {
658b5f288d2SAbhilash Raju             messages::internalError(asyncResp->res);
659b5f288d2SAbhilash Raju             close(fd);
660b5f288d2SAbhilash Raju             return;
661b5f288d2SAbhilash Raju         }
662168d1b1aSCarson Labrado         asyncResp->res.addHeader(
663168d1b1aSCarson Labrado             boost::beast::http::field::content_transfer_encoding, "Base64");
664b5f288d2SAbhilash Raju         return;
665168d1b1aSCarson Labrado     }
666b5f288d2SAbhilash Raju     if (!asyncResp->res.openFd(fd))
66727b0cf90SEd Tanous     {
668b5f288d2SAbhilash Raju         messages::internalError(asyncResp->res);
669b5f288d2SAbhilash Raju         close(fd);
670b5f288d2SAbhilash Raju         return;
67127b0cf90SEd Tanous     }
672168d1b1aSCarson Labrado     asyncResp->res.addHeader(boost::beast::http::field::content_type,
673168d1b1aSCarson Labrado                              "application/octet-stream");
674168d1b1aSCarson Labrado }
675168d1b1aSCarson Labrado 
676168d1b1aSCarson Labrado inline void
677168d1b1aSCarson Labrado     downloadDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
678168d1b1aSCarson Labrado                       const std::string& entryID, const std::string& dumpType)
679168d1b1aSCarson Labrado {
680168d1b1aSCarson Labrado     if (dumpType != "BMC")
681168d1b1aSCarson Labrado     {
682168d1b1aSCarson Labrado         BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
683168d1b1aSCarson Labrado         messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID);
684168d1b1aSCarson Labrado         return;
685168d1b1aSCarson Labrado     }
686168d1b1aSCarson Labrado 
68718f8f608SEd Tanous     std::string dumpEntryPath = std::format("{}/entry/{}",
68818f8f608SEd Tanous                                             getDumpPath(dumpType), entryID);
689168d1b1aSCarson Labrado 
690168d1b1aSCarson Labrado     auto downloadDumpEntryHandler =
691168d1b1aSCarson Labrado         [asyncResp, entryID,
692168d1b1aSCarson Labrado          dumpType](const boost::system::error_code& ec,
693168d1b1aSCarson Labrado                    const sdbusplus::message::unix_fd& unixfd) {
694168d1b1aSCarson Labrado         downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
695168d1b1aSCarson Labrado     };
696168d1b1aSCarson Labrado 
697168d1b1aSCarson Labrado     crow::connections::systemBus->async_method_call(
698168d1b1aSCarson Labrado         std::move(downloadDumpEntryHandler), "xyz.openbmc_project.Dump.Manager",
699168d1b1aSCarson Labrado         dumpEntryPath, "xyz.openbmc_project.Dump.Entry", "GetFileHandle");
700168d1b1aSCarson Labrado }
701168d1b1aSCarson Labrado 
702168d1b1aSCarson Labrado inline void
703168d1b1aSCarson Labrado     downloadEventLogEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
704168d1b1aSCarson Labrado                           const std::string& systemName,
705168d1b1aSCarson Labrado                           const std::string& entryID,
706168d1b1aSCarson Labrado                           const std::string& dumpType)
707168d1b1aSCarson Labrado {
70825b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
709168d1b1aSCarson Labrado     {
710168d1b1aSCarson Labrado         // Option currently returns no systems.  TBD
711168d1b1aSCarson Labrado         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
712168d1b1aSCarson Labrado                                    systemName);
713168d1b1aSCarson Labrado         return;
714168d1b1aSCarson Labrado     }
715253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
716168d1b1aSCarson Labrado     {
717168d1b1aSCarson Labrado         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
718168d1b1aSCarson Labrado                                    systemName);
719168d1b1aSCarson Labrado         return;
720168d1b1aSCarson Labrado     }
721168d1b1aSCarson Labrado 
722168d1b1aSCarson Labrado     std::string entryPath =
723168d1b1aSCarson Labrado         sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") /
724168d1b1aSCarson Labrado         entryID;
725168d1b1aSCarson Labrado 
726168d1b1aSCarson Labrado     auto downloadEventLogEntryHandler =
727168d1b1aSCarson Labrado         [asyncResp, entryID,
728168d1b1aSCarson Labrado          dumpType](const boost::system::error_code& ec,
729168d1b1aSCarson Labrado                    const sdbusplus::message::unix_fd& unixfd) {
730168d1b1aSCarson Labrado         downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
731168d1b1aSCarson Labrado     };
732168d1b1aSCarson Labrado 
733168d1b1aSCarson Labrado     crow::connections::systemBus->async_method_call(
734168d1b1aSCarson Labrado         std::move(downloadEventLogEntryHandler), "xyz.openbmc_project.Logging",
735168d1b1aSCarson Labrado         entryPath, "xyz.openbmc_project.Logging.Entry", "GetEntry");
736168d1b1aSCarson Labrado }
737168d1b1aSCarson Labrado 
7388e31778eSAsmitha Karunanithi inline DumpCreationProgress
7398e31778eSAsmitha Karunanithi     mapDbusStatusToDumpProgress(const std::string& status)
740a43be80fSAsmitha Karunanithi {
7418e31778eSAsmitha Karunanithi     if (status ==
7428e31778eSAsmitha Karunanithi             "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" ||
7438e31778eSAsmitha Karunanithi         status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted")
7448e31778eSAsmitha Karunanithi     {
7458e31778eSAsmitha Karunanithi         return DumpCreationProgress::DUMP_CREATE_FAILED;
7468e31778eSAsmitha Karunanithi     }
7478e31778eSAsmitha Karunanithi     if (status ==
7488e31778eSAsmitha Karunanithi         "xyz.openbmc_project.Common.Progress.OperationStatus.Completed")
7498e31778eSAsmitha Karunanithi     {
7508e31778eSAsmitha Karunanithi         return DumpCreationProgress::DUMP_CREATE_SUCCESS;
7518e31778eSAsmitha Karunanithi     }
7528e31778eSAsmitha Karunanithi     return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
7538e31778eSAsmitha Karunanithi }
7548e31778eSAsmitha Karunanithi 
7558e31778eSAsmitha Karunanithi inline DumpCreationProgress
7568e31778eSAsmitha Karunanithi     getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values)
7578e31778eSAsmitha Karunanithi {
7588e31778eSAsmitha Karunanithi     for (const auto& [key, val] : values)
7598e31778eSAsmitha Karunanithi     {
7608e31778eSAsmitha Karunanithi         if (key == "Status")
7618e31778eSAsmitha Karunanithi         {
7628e31778eSAsmitha Karunanithi             const std::string* value = std::get_if<std::string>(&val);
7638e31778eSAsmitha Karunanithi             if (value == nullptr)
7648e31778eSAsmitha Karunanithi             {
76562598e31SEd Tanous                 BMCWEB_LOG_ERROR("Status property value is null");
7668e31778eSAsmitha Karunanithi                 return DumpCreationProgress::DUMP_CREATE_FAILED;
7678e31778eSAsmitha Karunanithi             }
7688e31778eSAsmitha Karunanithi             return mapDbusStatusToDumpProgress(*value);
7698e31778eSAsmitha Karunanithi         }
7708e31778eSAsmitha Karunanithi     }
7718e31778eSAsmitha Karunanithi     return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
7728e31778eSAsmitha Karunanithi }
7738e31778eSAsmitha Karunanithi 
7748e31778eSAsmitha Karunanithi inline std::string getDumpEntryPath(const std::string& dumpPath)
7758e31778eSAsmitha Karunanithi {
7768e31778eSAsmitha Karunanithi     if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry")
7778e31778eSAsmitha Karunanithi     {
778253f11b8SEd Tanous         return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
7799f565090SEd Tanous                            BMCWEB_REDFISH_MANAGER_URI_NAME);
7808e31778eSAsmitha Karunanithi     }
7818e31778eSAsmitha Karunanithi     if (dumpPath == "/xyz/openbmc_project/dump/system/entry")
7828e31778eSAsmitha Karunanithi     {
783253f11b8SEd Tanous         return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
784253f11b8SEd Tanous                            BMCWEB_REDFISH_SYSTEM_URI_NAME);
7858e31778eSAsmitha Karunanithi     }
7868e31778eSAsmitha Karunanithi     return "";
7878e31778eSAsmitha Karunanithi }
7888e31778eSAsmitha Karunanithi 
7898e31778eSAsmitha Karunanithi inline void createDumpTaskCallback(
7908e31778eSAsmitha Karunanithi     task::Payload&& payload,
7918e31778eSAsmitha Karunanithi     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
7928e31778eSAsmitha Karunanithi     const sdbusplus::message::object_path& createdObjPath)
7938e31778eSAsmitha Karunanithi {
7948e31778eSAsmitha Karunanithi     const std::string dumpPath = createdObjPath.parent_path().str;
7958e31778eSAsmitha Karunanithi     const std::string dumpId = createdObjPath.filename();
7968e31778eSAsmitha Karunanithi 
7978e31778eSAsmitha Karunanithi     std::string dumpEntryPath = getDumpEntryPath(dumpPath);
7988e31778eSAsmitha Karunanithi 
7998e31778eSAsmitha Karunanithi     if (dumpEntryPath.empty())
8008e31778eSAsmitha Karunanithi     {
80162598e31SEd Tanous         BMCWEB_LOG_ERROR("Invalid dump type received");
8028e31778eSAsmitha Karunanithi         messages::internalError(asyncResp->res);
8038e31778eSAsmitha Karunanithi         return;
8048e31778eSAsmitha Karunanithi     }
8058e31778eSAsmitha Karunanithi 
8068e31778eSAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
8078cb2c024SEd Tanous         [asyncResp, payload = std::move(payload), createdObjPath,
8088e31778eSAsmitha Karunanithi          dumpEntryPath{std::move(dumpEntryPath)},
8095e7e2dc5SEd Tanous          dumpId](const boost::system::error_code& ec,
8108e31778eSAsmitha Karunanithi                  const std::string& introspectXml) {
8118e31778eSAsmitha Karunanithi         if (ec)
8128e31778eSAsmitha Karunanithi         {
81362598e31SEd Tanous             BMCWEB_LOG_ERROR("Introspect call failed with error: {}",
81462598e31SEd Tanous                              ec.message());
8158e31778eSAsmitha Karunanithi             messages::internalError(asyncResp->res);
8168e31778eSAsmitha Karunanithi             return;
8178e31778eSAsmitha Karunanithi         }
8188e31778eSAsmitha Karunanithi 
8198e31778eSAsmitha Karunanithi         // Check if the created dump object has implemented Progress
8208e31778eSAsmitha Karunanithi         // interface to track dump completion. If yes, fetch the "Status"
8218e31778eSAsmitha Karunanithi         // property of the interface, modify the task state accordingly.
8228e31778eSAsmitha Karunanithi         // Else, return task completed.
8238e31778eSAsmitha Karunanithi         tinyxml2::XMLDocument doc;
8248e31778eSAsmitha Karunanithi 
8258e31778eSAsmitha Karunanithi         doc.Parse(introspectXml.data(), introspectXml.size());
8268e31778eSAsmitha Karunanithi         tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
8278e31778eSAsmitha Karunanithi         if (pRoot == nullptr)
8288e31778eSAsmitha Karunanithi         {
82962598e31SEd Tanous             BMCWEB_LOG_ERROR("XML document failed to parse");
8308e31778eSAsmitha Karunanithi             messages::internalError(asyncResp->res);
8318e31778eSAsmitha Karunanithi             return;
8328e31778eSAsmitha Karunanithi         }
8338e31778eSAsmitha Karunanithi         tinyxml2::XMLElement* interfaceNode =
8348e31778eSAsmitha Karunanithi             pRoot->FirstChildElement("interface");
8358e31778eSAsmitha Karunanithi 
8368e31778eSAsmitha Karunanithi         bool isProgressIntfPresent = false;
8378e31778eSAsmitha Karunanithi         while (interfaceNode != nullptr)
8388e31778eSAsmitha Karunanithi         {
8398e31778eSAsmitha Karunanithi             const char* thisInterfaceName = interfaceNode->Attribute("name");
8408e31778eSAsmitha Karunanithi             if (thisInterfaceName != nullptr)
8418e31778eSAsmitha Karunanithi             {
8428e31778eSAsmitha Karunanithi                 if (thisInterfaceName ==
8438e31778eSAsmitha Karunanithi                     std::string_view("xyz.openbmc_project.Common.Progress"))
8448e31778eSAsmitha Karunanithi                 {
8458e31778eSAsmitha Karunanithi                     interfaceNode =
8468e31778eSAsmitha Karunanithi                         interfaceNode->NextSiblingElement("interface");
8478e31778eSAsmitha Karunanithi                     continue;
8488e31778eSAsmitha Karunanithi                 }
8498e31778eSAsmitha Karunanithi                 isProgressIntfPresent = true;
8508e31778eSAsmitha Karunanithi                 break;
8518e31778eSAsmitha Karunanithi             }
8528e31778eSAsmitha Karunanithi             interfaceNode = interfaceNode->NextSiblingElement("interface");
8538e31778eSAsmitha Karunanithi         }
8548e31778eSAsmitha Karunanithi 
855a43be80fSAsmitha Karunanithi         std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
8568e31778eSAsmitha Karunanithi             [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent](
8578b24275dSEd Tanous                 const boost::system::error_code& ec2, sdbusplus::message_t& msg,
858a43be80fSAsmitha Karunanithi                 const std::shared_ptr<task::TaskData>& taskData) {
8598b24275dSEd Tanous             if (ec2)
860cb13a392SEd Tanous             {
86162598e31SEd Tanous                 BMCWEB_LOG_ERROR("{}: Error in creating dump",
86262598e31SEd Tanous                                  createdObjPath.str);
8638e31778eSAsmitha Karunanithi                 taskData->messages.emplace_back(messages::internalError());
8646145ed6fSAsmitha Karunanithi                 taskData->state = "Cancelled";
8656145ed6fSAsmitha Karunanithi                 return task::completed;
866cb13a392SEd Tanous             }
867b9d36b47SEd Tanous 
8688e31778eSAsmitha Karunanithi             if (isProgressIntfPresent)
869a43be80fSAsmitha Karunanithi             {
8708e31778eSAsmitha Karunanithi                 dbus::utility::DBusPropertiesMap values;
8718e31778eSAsmitha Karunanithi                 std::string prop;
8728e31778eSAsmitha Karunanithi                 msg.read(prop, values);
8738e31778eSAsmitha Karunanithi 
8748e31778eSAsmitha Karunanithi                 DumpCreationProgress dumpStatus =
8758e31778eSAsmitha Karunanithi                     getDumpCompletionStatus(values);
8768e31778eSAsmitha Karunanithi                 if (dumpStatus == DumpCreationProgress::DUMP_CREATE_FAILED)
8778e31778eSAsmitha Karunanithi                 {
87862598e31SEd Tanous                     BMCWEB_LOG_ERROR("{}: Error in creating dump",
87962598e31SEd Tanous                                      createdObjPath.str);
8808e31778eSAsmitha Karunanithi                     taskData->state = "Cancelled";
8818e31778eSAsmitha Karunanithi                     return task::completed;
8828e31778eSAsmitha Karunanithi                 }
8838e31778eSAsmitha Karunanithi 
8848e31778eSAsmitha Karunanithi                 if (dumpStatus == DumpCreationProgress::DUMP_CREATE_INPROGRESS)
8858e31778eSAsmitha Karunanithi                 {
88662598e31SEd Tanous                     BMCWEB_LOG_DEBUG("{}: Dump creation task is in progress",
88762598e31SEd Tanous                                      createdObjPath.str);
8888e31778eSAsmitha Karunanithi                     return !task::completed;
8898e31778eSAsmitha Karunanithi                 }
8908e31778eSAsmitha Karunanithi             }
8918e31778eSAsmitha Karunanithi 
892a43be80fSAsmitha Karunanithi             nlohmann::json retMessage = messages::success();
893a43be80fSAsmitha Karunanithi             taskData->messages.emplace_back(retMessage);
894a43be80fSAsmitha Karunanithi 
895c51a58eeSEd Tanous             boost::urls::url url = boost::urls::format(
896253f11b8SEd Tanous                 "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}",
897253f11b8SEd Tanous                 BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId);
898c51a58eeSEd Tanous 
899c51a58eeSEd Tanous             std::string headerLoc = "Location: ";
900c51a58eeSEd Tanous             headerLoc += url.buffer();
901c51a58eeSEd Tanous 
902002d39b4SEd Tanous             taskData->payload->httpHeaders.emplace_back(std::move(headerLoc));
903a43be80fSAsmitha Karunanithi 
90462598e31SEd Tanous             BMCWEB_LOG_DEBUG("{}: Dump creation task completed",
90562598e31SEd Tanous                              createdObjPath.str);
906a43be80fSAsmitha Karunanithi             taskData->state = "Completed";
907b47452b2SAsmitha Karunanithi             return task::completed;
908a43be80fSAsmitha Karunanithi         },
9098e31778eSAsmitha Karunanithi             "type='signal',interface='org.freedesktop.DBus.Properties',"
9108e31778eSAsmitha Karunanithi             "member='PropertiesChanged',path='" +
9118e31778eSAsmitha Karunanithi                 createdObjPath.str + "'");
912a43be80fSAsmitha Karunanithi 
9138e31778eSAsmitha Karunanithi         // The task timer is set to max time limit within which the
9148e31778eSAsmitha Karunanithi         // requested dump will be collected.
9158e31778eSAsmitha Karunanithi         task->startTimer(std::chrono::minutes(6));
916a43be80fSAsmitha Karunanithi         task->populateResp(asyncResp->res);
9178e31778eSAsmitha Karunanithi         task->payload.emplace(payload);
9188e31778eSAsmitha Karunanithi     },
9198e31778eSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager", createdObjPath,
9208e31778eSAsmitha Karunanithi         "org.freedesktop.DBus.Introspectable", "Introspect");
921a43be80fSAsmitha Karunanithi }
922a43be80fSAsmitha Karunanithi 
9238d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
9248d1b46d7Szhanghch05                        const crow::Request& req, const std::string& dumpType)
925a43be80fSAsmitha Karunanithi {
926fdd26906SClaire Weinan     std::string dumpPath = getDumpEntriesPath(dumpType);
927fdd26906SClaire Weinan     if (dumpPath.empty())
928a43be80fSAsmitha Karunanithi     {
929a43be80fSAsmitha Karunanithi         messages::internalError(asyncResp->res);
930a43be80fSAsmitha Karunanithi         return;
931a43be80fSAsmitha Karunanithi     }
932a43be80fSAsmitha Karunanithi 
933a43be80fSAsmitha Karunanithi     std::optional<std::string> diagnosticDataType;
934a43be80fSAsmitha Karunanithi     std::optional<std::string> oemDiagnosticDataType;
935a43be80fSAsmitha Karunanithi 
93615ed6780SWilly Tu     if (!redfish::json_util::readJsonAction(
937a43be80fSAsmitha Karunanithi             req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
938a43be80fSAsmitha Karunanithi             "OEMDiagnosticDataType", oemDiagnosticDataType))
939a43be80fSAsmitha Karunanithi     {
940a43be80fSAsmitha Karunanithi         return;
941a43be80fSAsmitha Karunanithi     }
942a43be80fSAsmitha Karunanithi 
943a43be80fSAsmitha Karunanithi     if (dumpType == "System")
944a43be80fSAsmitha Karunanithi     {
945a43be80fSAsmitha Karunanithi         if (!oemDiagnosticDataType || !diagnosticDataType)
946a43be80fSAsmitha Karunanithi         {
94762598e31SEd Tanous             BMCWEB_LOG_ERROR(
94862598e31SEd Tanous                 "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!");
949a43be80fSAsmitha Karunanithi             messages::actionParameterMissing(
950a43be80fSAsmitha Karunanithi                 asyncResp->res, "CollectDiagnosticData",
951a43be80fSAsmitha Karunanithi                 "DiagnosticDataType & OEMDiagnosticDataType");
952a43be80fSAsmitha Karunanithi             return;
953a43be80fSAsmitha Karunanithi         }
9543174e4dfSEd Tanous         if ((*oemDiagnosticDataType != "System") ||
955a43be80fSAsmitha Karunanithi             (*diagnosticDataType != "OEM"))
956a43be80fSAsmitha Karunanithi         {
95762598e31SEd Tanous             BMCWEB_LOG_ERROR("Wrong parameter values passed");
958ace85d60SEd Tanous             messages::internalError(asyncResp->res);
959a43be80fSAsmitha Karunanithi             return;
960a43be80fSAsmitha Karunanithi         }
961253f11b8SEd Tanous         dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/",
962253f11b8SEd Tanous                                BMCWEB_REDFISH_SYSTEM_URI_NAME);
963a43be80fSAsmitha Karunanithi     }
964a43be80fSAsmitha Karunanithi     else if (dumpType == "BMC")
965a43be80fSAsmitha Karunanithi     {
966a43be80fSAsmitha Karunanithi         if (!diagnosticDataType)
967a43be80fSAsmitha Karunanithi         {
96862598e31SEd Tanous             BMCWEB_LOG_ERROR(
96962598e31SEd Tanous                 "CreateDump action parameter 'DiagnosticDataType' not found!");
970a43be80fSAsmitha Karunanithi             messages::actionParameterMissing(
971a43be80fSAsmitha Karunanithi                 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
972a43be80fSAsmitha Karunanithi             return;
973a43be80fSAsmitha Karunanithi         }
9743174e4dfSEd Tanous         if (*diagnosticDataType != "Manager")
975a43be80fSAsmitha Karunanithi         {
97662598e31SEd Tanous             BMCWEB_LOG_ERROR(
97762598e31SEd Tanous                 "Wrong parameter value passed for 'DiagnosticDataType'");
978ace85d60SEd Tanous             messages::internalError(asyncResp->res);
979a43be80fSAsmitha Karunanithi             return;
980a43be80fSAsmitha Karunanithi         }
981253f11b8SEd Tanous         dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/",
982253f11b8SEd Tanous                                BMCWEB_REDFISH_MANAGER_URI_NAME);
9835907571dSAsmitha Karunanithi     }
9845907571dSAsmitha Karunanithi     else
9855907571dSAsmitha Karunanithi     {
98662598e31SEd Tanous         BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type");
9875907571dSAsmitha Karunanithi         messages::internalError(asyncResp->res);
9885907571dSAsmitha Karunanithi         return;
989a43be80fSAsmitha Karunanithi     }
990a43be80fSAsmitha Karunanithi 
9918e31778eSAsmitha Karunanithi     std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>>
9928e31778eSAsmitha Karunanithi         createDumpParamVec;
9938e31778eSAsmitha Karunanithi 
994f574a8e1SCarson Labrado     if (req.session != nullptr)
995f574a8e1SCarson Labrado     {
99668dd075aSAsmitha Karunanithi         createDumpParamVec.emplace_back(
99768dd075aSAsmitha Karunanithi             "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId",
99868dd075aSAsmitha Karunanithi             req.session->clientIp);
99968dd075aSAsmitha Karunanithi         createDumpParamVec.emplace_back(
100068dd075aSAsmitha Karunanithi             "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType",
100168dd075aSAsmitha Karunanithi             "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client");
1002f574a8e1SCarson Labrado     }
100368dd075aSAsmitha Karunanithi 
1004a43be80fSAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
10055e7e2dc5SEd Tanous         [asyncResp, payload(task::Payload(req)),
10065e7e2dc5SEd Tanous          dumpPath](const boost::system::error_code& ec,
10075e7e2dc5SEd Tanous                    const sdbusplus::message_t& msg,
10088e31778eSAsmitha Karunanithi                    const sdbusplus::message::object_path& objPath) mutable {
1009a43be80fSAsmitha Karunanithi         if (ec)
1010a43be80fSAsmitha Karunanithi         {
101162598e31SEd Tanous             BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec);
10125907571dSAsmitha Karunanithi             const sd_bus_error* dbusError = msg.get_error();
10135907571dSAsmitha Karunanithi             if (dbusError == nullptr)
10145907571dSAsmitha Karunanithi             {
10155907571dSAsmitha Karunanithi                 messages::internalError(asyncResp->res);
10165907571dSAsmitha Karunanithi                 return;
10175907571dSAsmitha Karunanithi             }
10185907571dSAsmitha Karunanithi 
101962598e31SEd Tanous             BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}",
102062598e31SEd Tanous                              dbusError->name, dbusError->message);
10215907571dSAsmitha Karunanithi             if (std::string_view(
10225907571dSAsmitha Karunanithi                     "xyz.openbmc_project.Common.Error.NotAllowed") ==
10235907571dSAsmitha Karunanithi                 dbusError->name)
10245907571dSAsmitha Karunanithi             {
10255907571dSAsmitha Karunanithi                 messages::resourceInStandby(asyncResp->res);
10265907571dSAsmitha Karunanithi                 return;
10275907571dSAsmitha Karunanithi             }
10285907571dSAsmitha Karunanithi             if (std::string_view(
10295907571dSAsmitha Karunanithi                     "xyz.openbmc_project.Dump.Create.Error.Disabled") ==
10305907571dSAsmitha Karunanithi                 dbusError->name)
10315907571dSAsmitha Karunanithi             {
10325907571dSAsmitha Karunanithi                 messages::serviceDisabled(asyncResp->res, dumpPath);
10335907571dSAsmitha Karunanithi                 return;
10345907571dSAsmitha Karunanithi             }
10355907571dSAsmitha Karunanithi             if (std::string_view(
10365907571dSAsmitha Karunanithi                     "xyz.openbmc_project.Common.Error.Unavailable") ==
10375907571dSAsmitha Karunanithi                 dbusError->name)
10385907571dSAsmitha Karunanithi             {
10395907571dSAsmitha Karunanithi                 messages::resourceInUse(asyncResp->res);
10405907571dSAsmitha Karunanithi                 return;
10415907571dSAsmitha Karunanithi             }
10425907571dSAsmitha Karunanithi             // Other Dbus errors such as:
10435907571dSAsmitha Karunanithi             // xyz.openbmc_project.Common.Error.InvalidArgument &
10445907571dSAsmitha Karunanithi             // org.freedesktop.DBus.Error.InvalidArgs are all related to
10455907571dSAsmitha Karunanithi             // the dbus call that is made here in the bmcweb
10465907571dSAsmitha Karunanithi             // implementation and has nothing to do with the client's
10475907571dSAsmitha Karunanithi             // input in the request. Hence, returning internal error
10485907571dSAsmitha Karunanithi             // back to the client.
1049a43be80fSAsmitha Karunanithi             messages::internalError(asyncResp->res);
1050a43be80fSAsmitha Karunanithi             return;
1051a43be80fSAsmitha Karunanithi         }
105262598e31SEd Tanous         BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str);
10538e31778eSAsmitha Karunanithi         createDumpTaskCallback(std::move(payload), asyncResp, objPath);
1054a43be80fSAsmitha Karunanithi     },
105518f8f608SEd Tanous         "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
10568e31778eSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec);
1057a43be80fSAsmitha Karunanithi }
1058a43be80fSAsmitha Karunanithi 
10598d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
10608d1b46d7Szhanghch05                       const std::string& dumpType)
106180319af1SAsmitha Karunanithi {
10620d946211SClaire Weinan     crow::connections::systemBus->async_method_call(
10630d946211SClaire Weinan         [asyncResp](const boost::system::error_code& ec) {
106480319af1SAsmitha Karunanithi         if (ec)
106580319af1SAsmitha Karunanithi         {
106662598e31SEd Tanous             BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec);
106780319af1SAsmitha Karunanithi             messages::internalError(asyncResp->res);
106880319af1SAsmitha Karunanithi             return;
106980319af1SAsmitha Karunanithi         }
10700d946211SClaire Weinan     },
107118f8f608SEd Tanous         "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
10720d946211SClaire Weinan         "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
107380319af1SAsmitha Karunanithi }
107480319af1SAsmitha Karunanithi 
1075df254f2cSEd Tanous inline void
1076b9d36b47SEd Tanous     parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params,
1077b9d36b47SEd Tanous                              std::string& filename, std::string& timestamp,
1078b9d36b47SEd Tanous                              std::string& logfile)
1079043a0536SJohnathan Mantey {
1080d1bde9e5SKrzysztof Grobelny     const std::string* filenamePtr = nullptr;
1081d1bde9e5SKrzysztof Grobelny     const std::string* timestampPtr = nullptr;
1082d1bde9e5SKrzysztof Grobelny     const std::string* logfilePtr = nullptr;
1083d1bde9e5SKrzysztof Grobelny 
1084d1bde9e5SKrzysztof Grobelny     const bool success = sdbusplus::unpackPropertiesNoThrow(
1085d1bde9e5SKrzysztof Grobelny         dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr,
1086d1bde9e5SKrzysztof Grobelny         "Filename", filenamePtr, "Log", logfilePtr);
1087d1bde9e5SKrzysztof Grobelny 
1088d1bde9e5SKrzysztof Grobelny     if (!success)
1089043a0536SJohnathan Mantey     {
1090d1bde9e5SKrzysztof Grobelny         return;
1091043a0536SJohnathan Mantey     }
1092d1bde9e5SKrzysztof Grobelny 
1093d1bde9e5SKrzysztof Grobelny     if (filenamePtr != nullptr)
1094043a0536SJohnathan Mantey     {
1095d1bde9e5SKrzysztof Grobelny         filename = *filenamePtr;
1096d1bde9e5SKrzysztof Grobelny     }
1097d1bde9e5SKrzysztof Grobelny 
1098d1bde9e5SKrzysztof Grobelny     if (timestampPtr != nullptr)
1099043a0536SJohnathan Mantey     {
1100d1bde9e5SKrzysztof Grobelny         timestamp = *timestampPtr;
1101043a0536SJohnathan Mantey     }
1102d1bde9e5SKrzysztof Grobelny 
1103d1bde9e5SKrzysztof Grobelny     if (logfilePtr != nullptr)
1104043a0536SJohnathan Mantey     {
1105d1bde9e5SKrzysztof Grobelny         logfile = *logfilePtr;
1106043a0536SJohnathan Mantey     }
1107043a0536SJohnathan Mantey }
1108043a0536SJohnathan Mantey 
11097e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app)
11101da66f75SEd Tanous {
1111c4bf6374SJason M. Bills     /**
1112c4bf6374SJason M. Bills      * Functions triggers appropriate requests on DBus
1113c4bf6374SJason M. Bills      */
111422d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
1115ed398213SEd Tanous         .privileges(redfish::privileges::getLogServiceCollection)
1116002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1117002d39b4SEd Tanous             [&app](const crow::Request& req,
111822d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
111922d268cbSEd Tanous                    const std::string& systemName) {
11203ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1121c4bf6374SJason M. Bills         {
112245ca1b86SEd Tanous             return;
112345ca1b86SEd Tanous         }
112425b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
11257f3e84a1SEd Tanous         {
11267f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
11277f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
11287f3e84a1SEd Tanous                                        systemName);
11297f3e84a1SEd Tanous             return;
11307f3e84a1SEd Tanous         }
1131253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
113222d268cbSEd Tanous         {
113322d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
113422d268cbSEd Tanous                                        systemName);
113522d268cbSEd Tanous             return;
113622d268cbSEd Tanous         }
113722d268cbSEd Tanous 
11387e860f15SJohn Edward Broadbent         // Collections don't include the static data added by SubRoute
11397e860f15SJohn Edward Broadbent         // because it has a duplicate entry for members
1140c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1141c4bf6374SJason M. Bills             "#LogServiceCollection.LogServiceCollection";
1142c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1143253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices",
1144253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
114545ca1b86SEd Tanous         asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
1146c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] =
1147c4bf6374SJason M. Bills             "Collection of LogServices for this Computer System";
1148002d39b4SEd Tanous         nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1149c4bf6374SJason M. Bills         logServiceArray = nlohmann::json::array();
11501476687dSEd Tanous         nlohmann::json::object_t eventLog;
11511476687dSEd Tanous         eventLog["@odata.id"] =
1152253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1153253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
1154b2ba3072SPatrick Williams         logServiceArray.emplace_back(std::move(eventLog));
115525b54dbaSEd Tanous         if constexpr (BMCWEB_REDFISH_DUMP_LOG)
115625b54dbaSEd Tanous         {
11571476687dSEd Tanous             nlohmann::json::object_t dumpLog;
115825b54dbaSEd Tanous             dumpLog["@odata.id"] =
1159253f11b8SEd Tanous                 std::format("/redfish/v1/Systems/{}/LogServices/Dump",
1160253f11b8SEd Tanous                             BMCWEB_REDFISH_SYSTEM_URI_NAME);
1161b2ba3072SPatrick Williams             logServiceArray.emplace_back(std::move(dumpLog));
116225b54dbaSEd Tanous         }
1163c9bb6861Sraviteja-b 
11645ffd11f2SGunnar Mills         if constexpr (BMCWEB_REDFISH_CPU_LOG)
116525b54dbaSEd Tanous         {
11661476687dSEd Tanous             nlohmann::json::object_t crashdump;
11671476687dSEd Tanous             crashdump["@odata.id"] =
1168253f11b8SEd Tanous                 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
1169253f11b8SEd Tanous                             BMCWEB_REDFISH_SYSTEM_URI_NAME);
1170b2ba3072SPatrick Williams             logServiceArray.emplace_back(std::move(crashdump));
117125b54dbaSEd Tanous         }
1172b7028ebfSSpencer Ku 
117325b54dbaSEd Tanous         if constexpr (BMCWEB_REDFISH_HOST_LOGGER)
117425b54dbaSEd Tanous         {
11751476687dSEd Tanous             nlohmann::json::object_t hostlogger;
11761476687dSEd Tanous             hostlogger["@odata.id"] =
1177253f11b8SEd Tanous                 std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
1178253f11b8SEd Tanous                             BMCWEB_REDFISH_SYSTEM_URI_NAME);
1179b2ba3072SPatrick Williams             logServiceArray.emplace_back(std::move(hostlogger));
118025b54dbaSEd Tanous         }
1181c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] =
1182c4bf6374SJason M. Bills             logServiceArray.size();
1183a3316fc6SZhikuiRen 
11847a1dbc48SGeorge Liu         constexpr std::array<std::string_view, 1> interfaces = {
11857a1dbc48SGeorge Liu             "xyz.openbmc_project.State.Boot.PostCode"};
11867a1dbc48SGeorge Liu         dbus::utility::getSubTreePaths(
11877a1dbc48SGeorge Liu             "/", 0, interfaces,
11887a1dbc48SGeorge Liu             [asyncResp](const boost::system::error_code& ec,
1189b9d36b47SEd Tanous                         const dbus::utility::MapperGetSubTreePathsResponse&
1190b9d36b47SEd Tanous                             subtreePath) {
1191a3316fc6SZhikuiRen             if (ec)
1192a3316fc6SZhikuiRen             {
119362598e31SEd Tanous                 BMCWEB_LOG_ERROR("{}", ec);
1194a3316fc6SZhikuiRen                 return;
1195a3316fc6SZhikuiRen             }
1196a3316fc6SZhikuiRen 
119755f79e6fSEd Tanous             for (const auto& pathStr : subtreePath)
1198a3316fc6SZhikuiRen             {
1199a3316fc6SZhikuiRen                 if (pathStr.find("PostCode") != std::string::npos)
1200a3316fc6SZhikuiRen                 {
120123a21a1cSEd Tanous                     nlohmann::json& logServiceArrayLocal =
1202a3316fc6SZhikuiRen                         asyncResp->res.jsonValue["Members"];
1203613dabeaSEd Tanous                     nlohmann::json::object_t member;
1204253f11b8SEd Tanous                     member["@odata.id"] = std::format(
1205253f11b8SEd Tanous                         "/redfish/v1/Systems/{}/LogServices/PostCodes",
1206253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
1207613dabeaSEd Tanous 
1208b2ba3072SPatrick Williams                     logServiceArrayLocal.emplace_back(std::move(member));
1209613dabeaSEd Tanous 
121045ca1b86SEd Tanous                     asyncResp->res.jsonValue["Members@odata.count"] =
121123a21a1cSEd Tanous                         logServiceArrayLocal.size();
1212a3316fc6SZhikuiRen                     return;
1213a3316fc6SZhikuiRen                 }
1214a3316fc6SZhikuiRen             }
12157a1dbc48SGeorge Liu         });
12167e860f15SJohn Edward Broadbent     });
1217c4bf6374SJason M. Bills }
1218c4bf6374SJason M. Bills 
12197e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app)
1220c4bf6374SJason M. Bills {
122122d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/")
1222ed398213SEd Tanous         .privileges(redfish::privileges::getLogService)
1223002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1224002d39b4SEd Tanous             [&app](const crow::Request& req,
122522d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
122622d268cbSEd Tanous                    const std::string& systemName) {
12273ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
122845ca1b86SEd Tanous         {
122945ca1b86SEd Tanous             return;
123045ca1b86SEd Tanous         }
1231253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
123222d268cbSEd Tanous         {
123322d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
123422d268cbSEd Tanous                                        systemName);
123522d268cbSEd Tanous             return;
123622d268cbSEd Tanous         }
1237c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1238253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1239253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
1240c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1241b25644a1SJanet Adkins             "#LogService.v1_2_0.LogService";
1242c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Event Log Service";
1243002d39b4SEd Tanous         asyncResp->res.jsonValue["Description"] = "System Event Log Service";
1244c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Id"] = "EventLog";
1245539d8c6bSEd Tanous         asyncResp->res.jsonValue["OverWritePolicy"] =
1246539d8c6bSEd Tanous             log_service::OverWritePolicy::WrapsWhenFull;
12477c8c4058STejas Patil 
12487c8c4058STejas Patil         std::pair<std::string, std::string> redfishDateTimeOffset =
12492b82937eSEd Tanous             redfish::time_utils::getDateTimeOffsetNow();
12507c8c4058STejas Patil 
12517c8c4058STejas Patil         asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
12527c8c4058STejas Patil         asyncResp->res.jsonValue["DateTimeLocalOffset"] =
12537c8c4058STejas Patil             redfishDateTimeOffset.second;
12547c8c4058STejas Patil 
12551476687dSEd Tanous         asyncResp->res.jsonValue["Entries"]["@odata.id"] =
1256253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1257253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
125820fa6a2cSEd Tanous         asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"]
1259e7d6c8b2SGunnar Mills 
126020fa6a2cSEd Tanous             = std::format(
1261253f11b8SEd Tanous                 "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog",
126220fa6a2cSEd Tanous                 BMCWEB_REDFISH_SYSTEM_URI_NAME);
12637e860f15SJohn Edward Broadbent     });
1264489640c6SJason M. Bills }
1265489640c6SJason M. Bills 
12667e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app)
1267489640c6SJason M. Bills {
12684978b63fSJason M. Bills     BMCWEB_ROUTE(
12694978b63fSJason M. Bills         app,
127022d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
1271432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
12727e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
127345ca1b86SEd Tanous             [&app](const crow::Request& req,
127422d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
127522d268cbSEd Tanous                    const std::string& systemName) {
12763ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
127745ca1b86SEd Tanous         {
127845ca1b86SEd Tanous             return;
127945ca1b86SEd Tanous         }
1280253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
128122d268cbSEd Tanous         {
128222d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
128322d268cbSEd Tanous                                        systemName);
128422d268cbSEd Tanous             return;
128522d268cbSEd Tanous         }
1286489640c6SJason M. Bills         // Clear the EventLog by deleting the log files
1287489640c6SJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
1288489640c6SJason M. Bills         if (getRedfishLogFiles(redfishLogFiles))
1289489640c6SJason M. Bills         {
1290489640c6SJason M. Bills             for (const std::filesystem::path& file : redfishLogFiles)
1291489640c6SJason M. Bills             {
1292489640c6SJason M. Bills                 std::error_code ec;
1293489640c6SJason M. Bills                 std::filesystem::remove(file, ec);
1294489640c6SJason M. Bills             }
1295489640c6SJason M. Bills         }
1296489640c6SJason M. Bills 
1297489640c6SJason M. Bills         // Reload rsyslog so it knows to start new log files
1298489640c6SJason M. Bills         crow::connections::systemBus->async_method_call(
12995e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec) {
1300489640c6SJason M. Bills             if (ec)
1301489640c6SJason M. Bills             {
130262598e31SEd Tanous                 BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec);
1303489640c6SJason M. Bills                 messages::internalError(asyncResp->res);
1304489640c6SJason M. Bills                 return;
1305489640c6SJason M. Bills             }
1306489640c6SJason M. Bills 
1307489640c6SJason M. Bills             messages::success(asyncResp->res);
1308489640c6SJason M. Bills         },
1309489640c6SJason M. Bills             "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1310002d39b4SEd Tanous             "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1311002d39b4SEd Tanous             "replace");
13127e860f15SJohn Edward Broadbent     });
1313c4bf6374SJason M. Bills }
1314c4bf6374SJason M. Bills 
1315ac992cdeSJason M. Bills enum class LogParseError
1316ac992cdeSJason M. Bills {
1317ac992cdeSJason M. Bills     success,
1318ac992cdeSJason M. Bills     parseFailed,
1319ac992cdeSJason M. Bills     messageIdNotInRegistry,
1320ac992cdeSJason M. Bills };
1321ac992cdeSJason M. Bills 
1322ac992cdeSJason M. Bills static LogParseError
1323ac992cdeSJason M. Bills     fillEventLogEntryJson(const std::string& logEntryID,
1324b5a76932SEd Tanous                           const std::string& logEntry,
1325de703c5dSJason M. Bills                           nlohmann::json::object_t& logEntryJson)
1326c4bf6374SJason M. Bills {
132795820184SJason M. Bills     // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
1328cd225da8SJason M. Bills     // First get the Timestamp
1329f23b7296SEd Tanous     size_t space = logEntry.find_first_of(' ');
1330cd225da8SJason M. Bills     if (space == std::string::npos)
133195820184SJason M. Bills     {
1332ac992cdeSJason M. Bills         return LogParseError::parseFailed;
133395820184SJason M. Bills     }
1334cd225da8SJason M. Bills     std::string timestamp = logEntry.substr(0, space);
1335cd225da8SJason M. Bills     // Then get the log contents
1336f23b7296SEd Tanous     size_t entryStart = logEntry.find_first_not_of(' ', space);
1337cd225da8SJason M. Bills     if (entryStart == std::string::npos)
1338cd225da8SJason M. Bills     {
1339ac992cdeSJason M. Bills         return LogParseError::parseFailed;
1340cd225da8SJason M. Bills     }
1341cd225da8SJason M. Bills     std::string_view entry(logEntry);
1342cd225da8SJason M. Bills     entry.remove_prefix(entryStart);
1343cd225da8SJason M. Bills     // Use split to separate the entry into its fields
1344cd225da8SJason M. Bills     std::vector<std::string> logEntryFields;
134550ebd4afSEd Tanous     bmcweb::split(logEntryFields, entry, ',');
1346cd225da8SJason M. Bills     // We need at least a MessageId to be valid
13471e6deaf6SEd Tanous     auto logEntryIter = logEntryFields.begin();
13481e6deaf6SEd Tanous     if (logEntryIter == logEntryFields.end())
1349cd225da8SJason M. Bills     {
1350ac992cdeSJason M. Bills         return LogParseError::parseFailed;
1351cd225da8SJason M. Bills     }
13521e6deaf6SEd Tanous     std::string& messageID = *logEntryIter;
13534851d45dSJason M. Bills     // Get the Message from the MessageRegistry
1354fffb8c1fSEd Tanous     const registries::Message* message = registries::getMessage(messageID);
1355c4bf6374SJason M. Bills 
13561e6deaf6SEd Tanous     logEntryIter++;
135754417b02SSui Chen     if (message == nullptr)
1358c4bf6374SJason M. Bills     {
135962598e31SEd Tanous         BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry);
1360ac992cdeSJason M. Bills         return LogParseError::messageIdNotInRegistry;
1361c4bf6374SJason M. Bills     }
1362c4bf6374SJason M. Bills 
13631e6deaf6SEd Tanous     std::vector<std::string_view> messageArgs(logEntryIter,
13641e6deaf6SEd Tanous                                               logEntryFields.end());
1365c05bba45SEd Tanous     messageArgs.resize(message->numberOfArgs);
1366c05bba45SEd Tanous 
13671e6deaf6SEd Tanous     std::string msg = redfish::registries::fillMessageArgs(messageArgs,
13681e6deaf6SEd Tanous                                                            message->message);
13691e6deaf6SEd Tanous     if (msg.empty())
137015a86ff6SJason M. Bills     {
13711e6deaf6SEd Tanous         return LogParseError::parseFailed;
137215a86ff6SJason M. Bills     }
13734851d45dSJason M. Bills 
137495820184SJason M. Bills     // Get the Created time from the timestamp. The log timestamp is in RFC3339
137595820184SJason M. Bills     // format which matches the Redfish format except for the fractional seconds
137695820184SJason M. Bills     // between the '.' and the '+', so just remove them.
1377f23b7296SEd Tanous     std::size_t dot = timestamp.find_first_of('.');
1378f23b7296SEd Tanous     std::size_t plus = timestamp.find_first_of('+');
137995820184SJason M. Bills     if (dot != std::string::npos && plus != std::string::npos)
1380c4bf6374SJason M. Bills     {
138195820184SJason M. Bills         timestamp.erase(dot, plus - dot);
1382c4bf6374SJason M. Bills     }
1383c4bf6374SJason M. Bills 
1384c4bf6374SJason M. Bills     // Fill in the log entry with the gathered data
13859c11a172SVijay Lobo     logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1386ef4c65b7SEd Tanous     logEntryJson["@odata.id"] = boost::urls::format(
1387253f11b8SEd Tanous         "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1388253f11b8SEd Tanous         BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
138984afc48bSJason M. Bills     logEntryJson["Name"] = "System Event Log Entry";
139084afc48bSJason M. Bills     logEntryJson["Id"] = logEntryID;
139184afc48bSJason M. Bills     logEntryJson["Message"] = std::move(msg);
139284afc48bSJason M. Bills     logEntryJson["MessageId"] = std::move(messageID);
139384afc48bSJason M. Bills     logEntryJson["MessageArgs"] = messageArgs;
139484afc48bSJason M. Bills     logEntryJson["EntryType"] = "Event";
139584afc48bSJason M. Bills     logEntryJson["Severity"] = message->messageSeverity;
139684afc48bSJason M. Bills     logEntryJson["Created"] = std::move(timestamp);
1397ac992cdeSJason M. Bills     return LogParseError::success;
1398c4bf6374SJason M. Bills }
1399c4bf6374SJason M. Bills 
14007e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app)
1401c4bf6374SJason M. Bills {
140222d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
14038b6a35f0SGunnar Mills         .privileges(redfish::privileges::getLogEntryCollection)
1404002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1405002d39b4SEd Tanous             [&app](const crow::Request& req,
140622d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
140722d268cbSEd Tanous                    const std::string& systemName) {
1408c937d2bfSEd Tanous         query_param::QueryCapabilities capabilities = {
1409c937d2bfSEd Tanous             .canDelegateTop = true,
1410c937d2bfSEd Tanous             .canDelegateSkip = true,
1411c937d2bfSEd Tanous         };
1412c937d2bfSEd Tanous         query_param::Query delegatedQuery;
1413c937d2bfSEd Tanous         if (!redfish::setUpRedfishRouteWithDelegation(
14143ba00073SCarson Labrado                 app, req, asyncResp, delegatedQuery, capabilities))
1415c4bf6374SJason M. Bills         {
1416c4bf6374SJason M. Bills             return;
1417c4bf6374SJason M. Bills         }
141825b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
14197f3e84a1SEd Tanous         {
14207f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
14217f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
14227f3e84a1SEd Tanous                                        systemName);
14237f3e84a1SEd Tanous             return;
14247f3e84a1SEd Tanous         }
1425253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
142622d268cbSEd Tanous         {
142722d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
142822d268cbSEd Tanous                                        systemName);
142922d268cbSEd Tanous             return;
143022d268cbSEd Tanous         }
143122d268cbSEd Tanous 
14325143f7a5SJiaqing Zhao         size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
14333648c8beSEd Tanous         size_t skip = delegatedQuery.skip.value_or(0);
14343648c8beSEd Tanous 
14357e860f15SJohn Edward Broadbent         // Collections don't include the static data added by SubRoute
14367e860f15SJohn Edward Broadbent         // because it has a duplicate entry for members
1437c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1438c4bf6374SJason M. Bills             "#LogEntryCollection.LogEntryCollection";
1439c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1440253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1441253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
1442c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1443c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] =
1444c4bf6374SJason M. Bills             "Collection of System Event Log Entries";
1445cb92c03bSAndrew Geissler 
14464978b63fSJason M. Bills         nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1447c4bf6374SJason M. Bills         logEntryArray = nlohmann::json::array();
14487e860f15SJohn Edward Broadbent         // Go through the log files and create a unique ID for each
14497e860f15SJohn Edward Broadbent         // entry
145095820184SJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
145195820184SJason M. Bills         getRedfishLogFiles(redfishLogFiles);
1452b01bf299SEd Tanous         uint64_t entryCount = 0;
1453cd225da8SJason M. Bills         std::string logEntry;
145495820184SJason M. Bills 
14557e860f15SJohn Edward Broadbent         // Oldest logs are in the last file, so start there and loop
14567e860f15SJohn Edward Broadbent         // backwards
1457002d39b4SEd Tanous         for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1458002d39b4SEd Tanous              it++)
1459c4bf6374SJason M. Bills         {
1460cd225da8SJason M. Bills             std::ifstream logStream(*it);
146195820184SJason M. Bills             if (!logStream.is_open())
1462c4bf6374SJason M. Bills             {
1463c4bf6374SJason M. Bills                 continue;
1464c4bf6374SJason M. Bills             }
1465c4bf6374SJason M. Bills 
1466e85d6b16SJason M. Bills             // Reset the unique ID on the first entry
1467e85d6b16SJason M. Bills             bool firstEntry = true;
146895820184SJason M. Bills             while (std::getline(logStream, logEntry))
146995820184SJason M. Bills             {
1470c4bf6374SJason M. Bills                 std::string idStr;
1471e85d6b16SJason M. Bills                 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1472c4bf6374SJason M. Bills                 {
1473c4bf6374SJason M. Bills                     continue;
1474c4bf6374SJason M. Bills                 }
1475e85d6b16SJason M. Bills                 firstEntry = false;
1476e85d6b16SJason M. Bills 
1477de703c5dSJason M. Bills                 nlohmann::json::object_t bmcLogEntry;
147889492a15SPatrick Williams                 LogParseError status = fillEventLogEntryJson(idStr, logEntry,
147989492a15SPatrick Williams                                                              bmcLogEntry);
1480ac992cdeSJason M. Bills                 if (status == LogParseError::messageIdNotInRegistry)
1481ac992cdeSJason M. Bills                 {
1482ac992cdeSJason M. Bills                     continue;
1483ac992cdeSJason M. Bills                 }
1484ac992cdeSJason M. Bills                 if (status != LogParseError::success)
1485c4bf6374SJason M. Bills                 {
1486c4bf6374SJason M. Bills                     messages::internalError(asyncResp->res);
1487c4bf6374SJason M. Bills                     return;
1488c4bf6374SJason M. Bills                 }
1489de703c5dSJason M. Bills 
1490de703c5dSJason M. Bills                 entryCount++;
1491de703c5dSJason M. Bills                 // Handle paging using skip (number of entries to skip from the
1492de703c5dSJason M. Bills                 // start) and top (number of entries to display)
14933648c8beSEd Tanous                 if (entryCount <= skip || entryCount > skip + top)
1494de703c5dSJason M. Bills                 {
1495de703c5dSJason M. Bills                     continue;
1496de703c5dSJason M. Bills                 }
1497de703c5dSJason M. Bills 
1498b2ba3072SPatrick Williams                 logEntryArray.emplace_back(std::move(bmcLogEntry));
1499c4bf6374SJason M. Bills             }
150095820184SJason M. Bills         }
1501c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
15023648c8beSEd Tanous         if (skip + top < entryCount)
1503c4bf6374SJason M. Bills         {
1504253f11b8SEd Tanous             asyncResp->res
1505253f11b8SEd Tanous                 .jsonValue["Members@odata.nextLink"] = boost::urls::format(
1506253f11b8SEd Tanous                 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}",
1507253f11b8SEd Tanous                 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top));
1508c4bf6374SJason M. Bills         }
15097e860f15SJohn Edward Broadbent     });
1510897967deSJason M. Bills }
1511897967deSJason M. Bills 
15127e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app)
1513897967deSJason M. Bills {
15147e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
151522d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1516ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
15177e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
151845ca1b86SEd Tanous             [&app](const crow::Request& req,
15197e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
152022d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
15213ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
152245ca1b86SEd Tanous         {
152345ca1b86SEd Tanous             return;
152445ca1b86SEd Tanous         }
152525b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
15267f3e84a1SEd Tanous         {
15277f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
15287f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
15297f3e84a1SEd Tanous                                        systemName);
15307f3e84a1SEd Tanous             return;
15317f3e84a1SEd Tanous         }
153222d268cbSEd Tanous 
1533253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
153422d268cbSEd Tanous         {
153522d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
153622d268cbSEd Tanous                                        systemName);
153722d268cbSEd Tanous             return;
153822d268cbSEd Tanous         }
153922d268cbSEd Tanous 
15407e860f15SJohn Edward Broadbent         const std::string& targetID = param;
15418d1b46d7Szhanghch05 
15427e860f15SJohn Edward Broadbent         // Go through the log files and check the unique ID for each
15437e860f15SJohn Edward Broadbent         // entry to find the target entry
1544897967deSJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
1545897967deSJason M. Bills         getRedfishLogFiles(redfishLogFiles);
1546897967deSJason M. Bills         std::string logEntry;
1547897967deSJason M. Bills 
15487e860f15SJohn Edward Broadbent         // Oldest logs are in the last file, so start there and loop
15497e860f15SJohn Edward Broadbent         // backwards
1550002d39b4SEd Tanous         for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1551002d39b4SEd Tanous              it++)
1552897967deSJason M. Bills         {
1553897967deSJason M. Bills             std::ifstream logStream(*it);
1554897967deSJason M. Bills             if (!logStream.is_open())
1555897967deSJason M. Bills             {
1556897967deSJason M. Bills                 continue;
1557897967deSJason M. Bills             }
1558897967deSJason M. Bills 
1559897967deSJason M. Bills             // Reset the unique ID on the first entry
1560897967deSJason M. Bills             bool firstEntry = true;
1561897967deSJason M. Bills             while (std::getline(logStream, logEntry))
1562897967deSJason M. Bills             {
1563897967deSJason M. Bills                 std::string idStr;
1564897967deSJason M. Bills                 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1565897967deSJason M. Bills                 {
1566897967deSJason M. Bills                     continue;
1567897967deSJason M. Bills                 }
1568897967deSJason M. Bills                 firstEntry = false;
1569897967deSJason M. Bills 
1570897967deSJason M. Bills                 if (idStr == targetID)
1571897967deSJason M. Bills                 {
1572de703c5dSJason M. Bills                     nlohmann::json::object_t bmcLogEntry;
1573ac992cdeSJason M. Bills                     LogParseError status =
1574ac992cdeSJason M. Bills                         fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
1575ac992cdeSJason M. Bills                     if (status != LogParseError::success)
1576897967deSJason M. Bills                     {
1577897967deSJason M. Bills                         messages::internalError(asyncResp->res);
1578897967deSJason M. Bills                         return;
1579897967deSJason M. Bills                     }
1580d405bb51SJason M. Bills                     asyncResp->res.jsonValue.update(bmcLogEntry);
1581897967deSJason M. Bills                     return;
1582897967deSJason M. Bills                 }
1583897967deSJason M. Bills             }
1584897967deSJason M. Bills         }
1585897967deSJason M. Bills         // Requested ID was not found
15869db4ba25SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "LogEntry", targetID);
15877e860f15SJohn Edward Broadbent     });
158808a4e4b5SAnthony Wilson }
158908a4e4b5SAnthony Wilson 
15907e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app)
159108a4e4b5SAnthony Wilson {
159222d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
1593ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntryCollection)
1594002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1595002d39b4SEd Tanous             [&app](const crow::Request& req,
159622d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
159722d268cbSEd Tanous                    const std::string& systemName) {
15983ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
159945ca1b86SEd Tanous         {
160045ca1b86SEd Tanous             return;
160145ca1b86SEd Tanous         }
160225b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
16037f3e84a1SEd Tanous         {
16047f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
16057f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
16067f3e84a1SEd Tanous                                        systemName);
16077f3e84a1SEd Tanous             return;
16087f3e84a1SEd Tanous         }
1609253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
161022d268cbSEd Tanous         {
161122d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
161222d268cbSEd Tanous                                        systemName);
161322d268cbSEd Tanous             return;
161422d268cbSEd Tanous         }
161522d268cbSEd Tanous 
16167e860f15SJohn Edward Broadbent         // Collections don't include the static data added by SubRoute
16177e860f15SJohn Edward Broadbent         // because it has a duplicate entry for members
161808a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["@odata.type"] =
161908a4e4b5SAnthony Wilson             "#LogEntryCollection.LogEntryCollection";
162008a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["@odata.id"] =
1621253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1622253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
162308a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
162408a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["Description"] =
162508a4e4b5SAnthony Wilson             "Collection of System Event Log Entries";
162608a4e4b5SAnthony Wilson 
1627cb92c03bSAndrew Geissler         // DBus implementation of EventLog/Entries
1628cb92c03bSAndrew Geissler         // Make call to Logging Service to find all log entry objects
16295eb468daSGeorge Liu         sdbusplus::message::object_path path("/xyz/openbmc_project/logging");
16305eb468daSGeorge Liu         dbus::utility::getManagedObjects(
16315eb468daSGeorge Liu             "xyz.openbmc_project.Logging", path,
16325e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec,
1633914e2d5dSEd Tanous                         const dbus::utility::ManagedObjectType& resp) {
1634cb92c03bSAndrew Geissler             if (ec)
1635cb92c03bSAndrew Geissler             {
1636cb92c03bSAndrew Geissler                 // TODO Handle for specific error code
163762598e31SEd Tanous                 BMCWEB_LOG_ERROR(
163862598e31SEd Tanous                     "getLogEntriesIfaceData resp_handler got error {}", ec);
1639cb92c03bSAndrew Geissler                 messages::internalError(asyncResp->res);
1640cb92c03bSAndrew Geissler                 return;
1641cb92c03bSAndrew Geissler             }
16423544d2a7SEd Tanous             nlohmann::json::array_t entriesArray;
16439eb808c1SEd Tanous             for (const auto& objectPath : resp)
1644cb92c03bSAndrew Geissler             {
1645914e2d5dSEd Tanous                 const uint32_t* id = nullptr;
1646c419c759SEd Tanous                 const uint64_t* timestamp = nullptr;
1647c419c759SEd Tanous                 const uint64_t* updateTimestamp = nullptr;
1648914e2d5dSEd Tanous                 const std::string* severity = nullptr;
1649914e2d5dSEd Tanous                 const std::string* message = nullptr;
1650914e2d5dSEd Tanous                 const std::string* filePath = nullptr;
16519c11a172SVijay Lobo                 const std::string* resolution = nullptr;
165275710de2SXiaochao Ma                 bool resolved = false;
16539017faf2SAbhishek Patel                 const std::string* notify = nullptr;
16549017faf2SAbhishek Patel 
16559eb808c1SEd Tanous                 for (const auto& interfaceMap : objectPath.second)
1656f86bb901SAdriana Kobylak                 {
1657f86bb901SAdriana Kobylak                     if (interfaceMap.first ==
1658f86bb901SAdriana Kobylak                         "xyz.openbmc_project.Logging.Entry")
1659f86bb901SAdriana Kobylak                     {
1660002d39b4SEd Tanous                         for (const auto& propertyMap : interfaceMap.second)
1661cb92c03bSAndrew Geissler                         {
1662cb92c03bSAndrew Geissler                             if (propertyMap.first == "Id")
1663cb92c03bSAndrew Geissler                             {
1664002d39b4SEd Tanous                                 id = std::get_if<uint32_t>(&propertyMap.second);
1665cb92c03bSAndrew Geissler                             }
1666cb92c03bSAndrew Geissler                             else if (propertyMap.first == "Timestamp")
1667cb92c03bSAndrew Geissler                             {
1668002d39b4SEd Tanous                                 timestamp =
1669002d39b4SEd Tanous                                     std::get_if<uint64_t>(&propertyMap.second);
16707e860f15SJohn Edward Broadbent                             }
1671002d39b4SEd Tanous                             else if (propertyMap.first == "UpdateTimestamp")
16727e860f15SJohn Edward Broadbent                             {
1673002d39b4SEd Tanous                                 updateTimestamp =
1674002d39b4SEd Tanous                                     std::get_if<uint64_t>(&propertyMap.second);
16757e860f15SJohn Edward Broadbent                             }
16767e860f15SJohn Edward Broadbent                             else if (propertyMap.first == "Severity")
16777e860f15SJohn Edward Broadbent                             {
16787e860f15SJohn Edward Broadbent                                 severity = std::get_if<std::string>(
16797e860f15SJohn Edward Broadbent                                     &propertyMap.second);
16807e860f15SJohn Edward Broadbent                             }
16819c11a172SVijay Lobo                             else if (propertyMap.first == "Resolution")
16829c11a172SVijay Lobo                             {
16839c11a172SVijay Lobo                                 resolution = std::get_if<std::string>(
16849c11a172SVijay Lobo                                     &propertyMap.second);
16859c11a172SVijay Lobo                             }
16867e860f15SJohn Edward Broadbent                             else if (propertyMap.first == "Message")
16877e860f15SJohn Edward Broadbent                             {
16887e860f15SJohn Edward Broadbent                                 message = std::get_if<std::string>(
16897e860f15SJohn Edward Broadbent                                     &propertyMap.second);
16907e860f15SJohn Edward Broadbent                             }
16917e860f15SJohn Edward Broadbent                             else if (propertyMap.first == "Resolved")
16927e860f15SJohn Edward Broadbent                             {
1693914e2d5dSEd Tanous                                 const bool* resolveptr =
1694002d39b4SEd Tanous                                     std::get_if<bool>(&propertyMap.second);
16957e860f15SJohn Edward Broadbent                                 if (resolveptr == nullptr)
16967e860f15SJohn Edward Broadbent                                 {
1697002d39b4SEd Tanous                                     messages::internalError(asyncResp->res);
16987e860f15SJohn Edward Broadbent                                     return;
16997e860f15SJohn Edward Broadbent                                 }
17007e860f15SJohn Edward Broadbent                                 resolved = *resolveptr;
17017e860f15SJohn Edward Broadbent                             }
17029017faf2SAbhishek Patel                             else if (propertyMap.first ==
17039017faf2SAbhishek Patel                                      "ServiceProviderNotify")
17049017faf2SAbhishek Patel                             {
17059017faf2SAbhishek Patel                                 notify = std::get_if<std::string>(
17069017faf2SAbhishek Patel                                     &propertyMap.second);
17079017faf2SAbhishek Patel                                 if (notify == nullptr)
17089017faf2SAbhishek Patel                                 {
17099017faf2SAbhishek Patel                                     messages::internalError(asyncResp->res);
17109017faf2SAbhishek Patel                                     return;
17119017faf2SAbhishek Patel                                 }
17129017faf2SAbhishek Patel                             }
17137e860f15SJohn Edward Broadbent                         }
17147e860f15SJohn Edward Broadbent                         if (id == nullptr || message == nullptr ||
17157e860f15SJohn Edward Broadbent                             severity == nullptr)
17167e860f15SJohn Edward Broadbent                         {
17177e860f15SJohn Edward Broadbent                             messages::internalError(asyncResp->res);
17187e860f15SJohn Edward Broadbent                             return;
17197e860f15SJohn Edward Broadbent                         }
17207e860f15SJohn Edward Broadbent                     }
17217e860f15SJohn Edward Broadbent                     else if (interfaceMap.first ==
17227e860f15SJohn Edward Broadbent                              "xyz.openbmc_project.Common.FilePath")
17237e860f15SJohn Edward Broadbent                     {
1724002d39b4SEd Tanous                         for (const auto& propertyMap : interfaceMap.second)
17257e860f15SJohn Edward Broadbent                         {
17267e860f15SJohn Edward Broadbent                             if (propertyMap.first == "Path")
17277e860f15SJohn Edward Broadbent                             {
17287e860f15SJohn Edward Broadbent                                 filePath = std::get_if<std::string>(
17297e860f15SJohn Edward Broadbent                                     &propertyMap.second);
17307e860f15SJohn Edward Broadbent                             }
17317e860f15SJohn Edward Broadbent                         }
17327e860f15SJohn Edward Broadbent                     }
17337e860f15SJohn Edward Broadbent                 }
17347e860f15SJohn Edward Broadbent                 // Object path without the
17357e860f15SJohn Edward Broadbent                 // xyz.openbmc_project.Logging.Entry interface, ignore
17367e860f15SJohn Edward Broadbent                 // and continue.
17377e860f15SJohn Edward Broadbent                 if (id == nullptr || message == nullptr ||
1738c419c759SEd Tanous                     severity == nullptr || timestamp == nullptr ||
1739c419c759SEd Tanous                     updateTimestamp == nullptr)
17407e860f15SJohn Edward Broadbent                 {
17417e860f15SJohn Edward Broadbent                     continue;
17427e860f15SJohn Edward Broadbent                 }
17433544d2a7SEd Tanous                 nlohmann::json& thisEntry = entriesArray.emplace_back();
17449c11a172SVijay Lobo                 thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1745ef4c65b7SEd Tanous                 thisEntry["@odata.id"] = boost::urls::format(
1746253f11b8SEd Tanous                     "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1747253f11b8SEd Tanous                     BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(*id));
17487e860f15SJohn Edward Broadbent                 thisEntry["Name"] = "System Event Log Entry";
17497e860f15SJohn Edward Broadbent                 thisEntry["Id"] = std::to_string(*id);
17507e860f15SJohn Edward Broadbent                 thisEntry["Message"] = *message;
17517e860f15SJohn Edward Broadbent                 thisEntry["Resolved"] = resolved;
17529c11a172SVijay Lobo                 if ((resolution != nullptr) && (!(*resolution).empty()))
17539c11a172SVijay Lobo                 {
17549c11a172SVijay Lobo                     thisEntry["Resolution"] = *resolution;
17559c11a172SVijay Lobo                 }
1756*b0b6152cSEd Tanous                 if (notify != nullptr)
1757*b0b6152cSEd Tanous                 {
17589017faf2SAbhishek Patel                     std::optional<bool> notifyAction =
17599017faf2SAbhishek Patel                         getProviderNotifyAction(*notify);
17609017faf2SAbhishek Patel                     if (notifyAction)
17619017faf2SAbhishek Patel                     {
17629017faf2SAbhishek Patel                         thisEntry["ServiceProviderNotified"] = *notifyAction;
17639017faf2SAbhishek Patel                     }
1764*b0b6152cSEd Tanous                 }
17657e860f15SJohn Edward Broadbent                 thisEntry["EntryType"] = "Event";
17667e860f15SJohn Edward Broadbent                 thisEntry["Severity"] =
17677e860f15SJohn Edward Broadbent                     translateSeverityDbusToRedfish(*severity);
17687e860f15SJohn Edward Broadbent                 thisEntry["Created"] =
17692b82937eSEd Tanous                     redfish::time_utils::getDateTimeUintMs(*timestamp);
17707e860f15SJohn Edward Broadbent                 thisEntry["Modified"] =
17712b82937eSEd Tanous                     redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
17727e860f15SJohn Edward Broadbent                 if (filePath != nullptr)
17737e860f15SJohn Edward Broadbent                 {
17747e860f15SJohn Edward Broadbent                     thisEntry["AdditionalDataURI"] =
1775253f11b8SEd Tanous                         std::format(
1776253f11b8SEd Tanous                             "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/",
1777253f11b8SEd Tanous                             BMCWEB_REDFISH_SYSTEM_URI_NAME) +
17787e860f15SJohn Edward Broadbent                         std::to_string(*id) + "/attachment";
17797e860f15SJohn Edward Broadbent                 }
17807e860f15SJohn Edward Broadbent             }
17813544d2a7SEd Tanous             std::ranges::sort(entriesArray, [](const nlohmann::json& left,
17823544d2a7SEd Tanous                                                const nlohmann::json& right) {
17837e860f15SJohn Edward Broadbent                 return (left["Id"] <= right["Id"]);
17847e860f15SJohn Edward Broadbent             });
17857e860f15SJohn Edward Broadbent             asyncResp->res.jsonValue["Members@odata.count"] =
17867e860f15SJohn Edward Broadbent                 entriesArray.size();
17873544d2a7SEd Tanous             asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
17885eb468daSGeorge Liu         });
17897e860f15SJohn Edward Broadbent     });
17907e860f15SJohn Edward Broadbent }
17917e860f15SJohn Edward Broadbent 
17927e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app)
17937e860f15SJohn Edward Broadbent {
17947e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
179522d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1796ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
1797002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1798002d39b4SEd Tanous             [&app](const crow::Request& req,
17997e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
180022d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
18013ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
18027e860f15SJohn Edward Broadbent         {
180345ca1b86SEd Tanous             return;
180445ca1b86SEd Tanous         }
180525b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
18067f3e84a1SEd Tanous         {
18077f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
18087f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
18097f3e84a1SEd Tanous                                        systemName);
18107f3e84a1SEd Tanous             return;
18117f3e84a1SEd Tanous         }
1812253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
181322d268cbSEd Tanous         {
181422d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
181522d268cbSEd Tanous                                        systemName);
181622d268cbSEd Tanous             return;
181722d268cbSEd Tanous         }
181822d268cbSEd Tanous 
18197e860f15SJohn Edward Broadbent         std::string entryID = param;
18207e860f15SJohn Edward Broadbent         dbus::utility::escapePathForDbus(entryID);
18217e860f15SJohn Edward Broadbent 
18227e860f15SJohn Edward Broadbent         // DBus implementation of EventLog/Entries
18237e860f15SJohn Edward Broadbent         // Make call to Logging Service to find all log entry objects
1824d1bde9e5SKrzysztof Grobelny         sdbusplus::asio::getAllProperties(
1825d1bde9e5SKrzysztof Grobelny             *crow::connections::systemBus, "xyz.openbmc_project.Logging",
1826d1bde9e5SKrzysztof Grobelny             "/xyz/openbmc_project/logging/entry/" + entryID, "",
18275e7e2dc5SEd Tanous             [asyncResp, entryID](const boost::system::error_code& ec,
1828b9d36b47SEd Tanous                                  const dbus::utility::DBusPropertiesMap& resp) {
18297e860f15SJohn Edward Broadbent             if (ec.value() == EBADR)
18307e860f15SJohn Edward Broadbent             {
1831d1bde9e5SKrzysztof Grobelny                 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1832d1bde9e5SKrzysztof Grobelny                                            entryID);
18337e860f15SJohn Edward Broadbent                 return;
18347e860f15SJohn Edward Broadbent             }
18357e860f15SJohn Edward Broadbent             if (ec)
18367e860f15SJohn Edward Broadbent             {
183762598e31SEd Tanous                 BMCWEB_LOG_ERROR(
183862598e31SEd Tanous                     "EventLogEntry (DBus) resp_handler got error {}", ec);
18397e860f15SJohn Edward Broadbent                 messages::internalError(asyncResp->res);
18407e860f15SJohn Edward Broadbent                 return;
18417e860f15SJohn Edward Broadbent             }
1842914e2d5dSEd Tanous             const uint32_t* id = nullptr;
1843c419c759SEd Tanous             const uint64_t* timestamp = nullptr;
1844c419c759SEd Tanous             const uint64_t* updateTimestamp = nullptr;
1845914e2d5dSEd Tanous             const std::string* severity = nullptr;
1846914e2d5dSEd Tanous             const std::string* message = nullptr;
1847914e2d5dSEd Tanous             const std::string* filePath = nullptr;
18489c11a172SVijay Lobo             const std::string* resolution = nullptr;
18497e860f15SJohn Edward Broadbent             bool resolved = false;
18509017faf2SAbhishek Patel             const std::string* notify = nullptr;
18517e860f15SJohn Edward Broadbent 
1852d1bde9e5SKrzysztof Grobelny             const bool success = sdbusplus::unpackPropertiesNoThrow(
1853d1bde9e5SKrzysztof Grobelny                 dbus_utils::UnpackErrorPrinter(), resp, "Id", id, "Timestamp",
1854d1bde9e5SKrzysztof Grobelny                 timestamp, "UpdateTimestamp", updateTimestamp, "Severity",
18559c11a172SVijay Lobo                 severity, "Message", message, "Resolved", resolved,
18569017faf2SAbhishek Patel                 "Resolution", resolution, "Path", filePath,
18579017faf2SAbhishek Patel                 "ServiceProviderNotify", notify);
1858d1bde9e5SKrzysztof Grobelny 
1859d1bde9e5SKrzysztof Grobelny             if (!success)
186075710de2SXiaochao Ma             {
186175710de2SXiaochao Ma                 messages::internalError(asyncResp->res);
186275710de2SXiaochao Ma                 return;
186375710de2SXiaochao Ma             }
1864d1bde9e5SKrzysztof Grobelny 
1865002d39b4SEd Tanous             if (id == nullptr || message == nullptr || severity == nullptr ||
18669017faf2SAbhishek Patel                 timestamp == nullptr || updateTimestamp == nullptr ||
18679017faf2SAbhishek Patel                 notify == nullptr)
1868f86bb901SAdriana Kobylak             {
1869ae34c8e8SAdriana Kobylak                 messages::internalError(asyncResp->res);
1870271584abSEd Tanous                 return;
1871271584abSEd Tanous             }
18729017faf2SAbhishek Patel 
1873f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["@odata.type"] =
18749c11a172SVijay Lobo                 "#LogEntry.v1_9_0.LogEntry";
1875ef4c65b7SEd Tanous             asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1876253f11b8SEd Tanous                 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1877253f11b8SEd Tanous                 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(*id));
187845ca1b86SEd Tanous             asyncResp->res.jsonValue["Name"] = "System Event Log Entry";
1879f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Id"] = std::to_string(*id);
1880f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Message"] = *message;
1881f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Resolved"] = resolved;
18829017faf2SAbhishek Patel             std::optional<bool> notifyAction = getProviderNotifyAction(*notify);
18839017faf2SAbhishek Patel             if (notifyAction)
18849017faf2SAbhishek Patel             {
18859017faf2SAbhishek Patel                 asyncResp->res.jsonValue["ServiceProviderNotified"] =
18869017faf2SAbhishek Patel                     *notifyAction;
18879017faf2SAbhishek Patel             }
18889c11a172SVijay Lobo             if ((resolution != nullptr) && (!(*resolution).empty()))
18899c11a172SVijay Lobo             {
18909c11a172SVijay Lobo                 asyncResp->res.jsonValue["Resolution"] = *resolution;
18919c11a172SVijay Lobo             }
1892f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["EntryType"] = "Event";
1893f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Severity"] =
1894f86bb901SAdriana Kobylak                 translateSeverityDbusToRedfish(*severity);
1895f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Created"] =
18962b82937eSEd Tanous                 redfish::time_utils::getDateTimeUintMs(*timestamp);
1897f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Modified"] =
18982b82937eSEd Tanous                 redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
1899f86bb901SAdriana Kobylak             if (filePath != nullptr)
1900f86bb901SAdriana Kobylak             {
1901f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["AdditionalDataURI"] =
1902253f11b8SEd Tanous                     std::format(
1903253f11b8SEd Tanous                         "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/",
1904253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME) +
1905e7dbd530SPotin Lai                     std::to_string(*id) + "/attachment";
1906f86bb901SAdriana Kobylak             }
1907d1bde9e5SKrzysztof Grobelny         });
19087e860f15SJohn Edward Broadbent     });
1909336e96c6SChicago Duan 
19107e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
191122d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1912ed398213SEd Tanous         .privileges(redfish::privileges::patchLogEntry)
19137e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::patch)(
191445ca1b86SEd Tanous             [&app](const crow::Request& req,
19157e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
191622d268cbSEd Tanous                    const std::string& systemName, const std::string& entryId) {
19173ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
191845ca1b86SEd Tanous         {
191945ca1b86SEd Tanous             return;
192045ca1b86SEd Tanous         }
192125b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
19227f3e84a1SEd Tanous         {
19237f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
19247f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
19257f3e84a1SEd Tanous                                        systemName);
19267f3e84a1SEd Tanous             return;
19277f3e84a1SEd Tanous         }
1928253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
192922d268cbSEd Tanous         {
193022d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
193122d268cbSEd Tanous                                        systemName);
193222d268cbSEd Tanous             return;
193322d268cbSEd Tanous         }
193475710de2SXiaochao Ma         std::optional<bool> resolved;
193575710de2SXiaochao Ma 
193615ed6780SWilly Tu         if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved",
19377e860f15SJohn Edward Broadbent                                       resolved))
193875710de2SXiaochao Ma         {
193975710de2SXiaochao Ma             return;
194075710de2SXiaochao Ma         }
194162598e31SEd Tanous         BMCWEB_LOG_DEBUG("Set Resolved");
194275710de2SXiaochao Ma 
1943e93abac6SGinu George         setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging",
19449ae226faSGeorge Liu                         "/xyz/openbmc_project/logging/entry/" + entryId,
19453eb66652SAsmitha Karunanithi                         "xyz.openbmc_project.Logging.Entry", "Resolved",
1946e93abac6SGinu George                         *resolved);
19477e860f15SJohn Edward Broadbent     });
194875710de2SXiaochao Ma 
19497e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
195022d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1951ed398213SEd Tanous         .privileges(redfish::privileges::deleteLogEntry)
1952ed398213SEd Tanous 
1953002d39b4SEd Tanous         .methods(boost::beast::http::verb::delete_)(
1954002d39b4SEd Tanous             [&app](const crow::Request& req,
1955002d39b4SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
195622d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
19573ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1958336e96c6SChicago Duan         {
195945ca1b86SEd Tanous             return;
196045ca1b86SEd Tanous         }
196125b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
19627f3e84a1SEd Tanous         {
19637f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
19647f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
19657f3e84a1SEd Tanous                                        systemName);
19667f3e84a1SEd Tanous             return;
19677f3e84a1SEd Tanous         }
1968253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
196922d268cbSEd Tanous         {
197022d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
197122d268cbSEd Tanous                                        systemName);
197222d268cbSEd Tanous             return;
197322d268cbSEd Tanous         }
197462598e31SEd Tanous         BMCWEB_LOG_DEBUG("Do delete single event entries.");
1975336e96c6SChicago Duan 
19767e860f15SJohn Edward Broadbent         std::string entryID = param;
1977336e96c6SChicago Duan 
1978336e96c6SChicago Duan         dbus::utility::escapePathForDbus(entryID);
1979336e96c6SChicago Duan 
1980336e96c6SChicago Duan         // Process response from Logging service.
19815a39f77aSPatrick Williams         auto respHandler = [asyncResp,
19825a39f77aSPatrick Williams                             entryID](const boost::system::error_code& ec) {
198362598e31SEd Tanous             BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done");
1984336e96c6SChicago Duan             if (ec)
1985336e96c6SChicago Duan             {
19863de8d8baSGeorge Liu                 if (ec.value() == EBADR)
19873de8d8baSGeorge Liu                 {
198845ca1b86SEd Tanous                     messages::resourceNotFound(asyncResp->res, "LogEntry",
198945ca1b86SEd Tanous                                                entryID);
19903de8d8baSGeorge Liu                     return;
19913de8d8baSGeorge Liu                 }
1992336e96c6SChicago Duan                 // TODO Handle for specific error code
199362598e31SEd Tanous                 BMCWEB_LOG_ERROR(
199462598e31SEd Tanous                     "EventLogEntry (DBus) doDelete respHandler got error {}",
199562598e31SEd Tanous                     ec);
1996336e96c6SChicago Duan                 asyncResp->res.result(
1997336e96c6SChicago Duan                     boost::beast::http::status::internal_server_error);
1998336e96c6SChicago Duan                 return;
1999336e96c6SChicago Duan             }
2000336e96c6SChicago Duan 
2001336e96c6SChicago Duan             asyncResp->res.result(boost::beast::http::status::ok);
2002336e96c6SChicago Duan         };
2003336e96c6SChicago Duan 
2004336e96c6SChicago Duan         // Make call to Logging service to request Delete Log
2005336e96c6SChicago Duan         crow::connections::systemBus->async_method_call(
2006336e96c6SChicago Duan             respHandler, "xyz.openbmc_project.Logging",
2007336e96c6SChicago Duan             "/xyz/openbmc_project/logging/entry/" + entryID,
2008336e96c6SChicago Duan             "xyz.openbmc_project.Object.Delete", "Delete");
20097e860f15SJohn Edward Broadbent     });
2010400fd1fbSAdriana Kobylak }
2011400fd1fbSAdriana Kobylak 
2012b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console";
2013b7028ebfSSpencer Ku 
2014b7028ebfSSpencer Ku inline bool
2015b7028ebfSSpencer Ku     getHostLoggerFiles(const std::string& hostLoggerFilePath,
2016b7028ebfSSpencer Ku                        std::vector<std::filesystem::path>& hostLoggerFiles)
2017b7028ebfSSpencer Ku {
2018b7028ebfSSpencer Ku     std::error_code ec;
2019b7028ebfSSpencer Ku     std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec);
2020b7028ebfSSpencer Ku     if (ec)
2021b7028ebfSSpencer Ku     {
2022bf2ddedeSCarson Labrado         BMCWEB_LOG_WARNING("{}", ec.message());
2023b7028ebfSSpencer Ku         return false;
2024b7028ebfSSpencer Ku     }
2025b7028ebfSSpencer Ku     for (const std::filesystem::directory_entry& it : logPath)
2026b7028ebfSSpencer Ku     {
2027b7028ebfSSpencer Ku         std::string filename = it.path().filename();
2028b7028ebfSSpencer Ku         // Prefix of each log files is "log". Find the file and save the
2029b7028ebfSSpencer Ku         // path
203011ba3979SEd Tanous         if (filename.starts_with("log"))
2031b7028ebfSSpencer Ku         {
2032b7028ebfSSpencer Ku             hostLoggerFiles.emplace_back(it.path());
2033b7028ebfSSpencer Ku         }
2034b7028ebfSSpencer Ku     }
2035b7028ebfSSpencer Ku     // As the log files rotate, they are appended with a ".#" that is higher for
2036b7028ebfSSpencer Ku     // the older logs. Since we start from oldest logs, sort the name in
2037b7028ebfSSpencer Ku     // descending order.
2038b7028ebfSSpencer Ku     std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(),
2039b7028ebfSSpencer Ku               AlphanumLess<std::string>());
2040b7028ebfSSpencer Ku 
2041b7028ebfSSpencer Ku     return true;
2042b7028ebfSSpencer Ku }
2043b7028ebfSSpencer Ku 
204402cad96eSEd Tanous inline bool getHostLoggerEntries(
204502cad96eSEd Tanous     const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip,
204602cad96eSEd Tanous     uint64_t top, std::vector<std::string>& logEntries, size_t& logCount)
2047b7028ebfSSpencer Ku {
2048b7028ebfSSpencer Ku     GzFileReader logFile;
2049b7028ebfSSpencer Ku 
2050b7028ebfSSpencer Ku     // Go though all log files and expose host logs.
2051b7028ebfSSpencer Ku     for (const std::filesystem::path& it : hostLoggerFiles)
2052b7028ebfSSpencer Ku     {
2053b7028ebfSSpencer Ku         if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount))
2054b7028ebfSSpencer Ku         {
205562598e31SEd Tanous             BMCWEB_LOG_ERROR("fail to expose host logs");
2056b7028ebfSSpencer Ku             return false;
2057b7028ebfSSpencer Ku         }
2058b7028ebfSSpencer Ku     }
2059b7028ebfSSpencer Ku     // Get lastMessage from constructor by getter
2060b7028ebfSSpencer Ku     std::string lastMessage = logFile.getLastMessage();
2061b7028ebfSSpencer Ku     if (!lastMessage.empty())
2062b7028ebfSSpencer Ku     {
2063b7028ebfSSpencer Ku         logCount++;
2064b7028ebfSSpencer Ku         if (logCount > skip && logCount <= (skip + top))
2065b7028ebfSSpencer Ku         {
2066b7028ebfSSpencer Ku             logEntries.push_back(lastMessage);
2067b7028ebfSSpencer Ku         }
2068b7028ebfSSpencer Ku     }
2069b7028ebfSSpencer Ku     return true;
2070b7028ebfSSpencer Ku }
2071b7028ebfSSpencer Ku 
20726f056f24SEd Tanous inline void fillHostLoggerEntryJson(std::string_view logEntryID,
20736f056f24SEd Tanous                                     std::string_view msg,
20746d6574c9SJason M. Bills                                     nlohmann::json::object_t& logEntryJson)
2075b7028ebfSSpencer Ku {
2076b7028ebfSSpencer Ku     // Fill in the log entry with the gathered data.
20779c11a172SVijay Lobo     logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
2078ef4c65b7SEd Tanous     logEntryJson["@odata.id"] = boost::urls::format(
2079253f11b8SEd Tanous         "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries/{}",
2080253f11b8SEd Tanous         BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
20816d6574c9SJason M. Bills     logEntryJson["Name"] = "Host Logger Entry";
20826d6574c9SJason M. Bills     logEntryJson["Id"] = logEntryID;
20836d6574c9SJason M. Bills     logEntryJson["Message"] = msg;
2084539d8c6bSEd Tanous     logEntryJson["EntryType"] = log_entry::LogEntryType::Oem;
2085539d8c6bSEd Tanous     logEntryJson["Severity"] = log_entry::EventSeverity::OK;
20866d6574c9SJason M. Bills     logEntryJson["OemRecordFormat"] = "Host Logger Entry";
2087b7028ebfSSpencer Ku }
2088b7028ebfSSpencer Ku 
2089b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app)
2090b7028ebfSSpencer Ku {
209122d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/")
2092b7028ebfSSpencer Ku         .privileges(redfish::privileges::getLogService)
20931476687dSEd Tanous         .methods(boost::beast::http::verb::get)(
20941476687dSEd Tanous             [&app](const crow::Request& req,
209522d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
209622d268cbSEd Tanous                    const std::string& systemName) {
20973ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
209845ca1b86SEd Tanous         {
209945ca1b86SEd Tanous             return;
210045ca1b86SEd Tanous         }
210125b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
21027f3e84a1SEd Tanous         {
21037f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
21047f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
21057f3e84a1SEd Tanous                                        systemName);
21067f3e84a1SEd Tanous             return;
21077f3e84a1SEd Tanous         }
2108253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
210922d268cbSEd Tanous         {
211022d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
211122d268cbSEd Tanous                                        systemName);
211222d268cbSEd Tanous             return;
211322d268cbSEd Tanous         }
2114b7028ebfSSpencer Ku         asyncResp->res.jsonValue["@odata.id"] =
2115253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
2116253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
2117b7028ebfSSpencer Ku         asyncResp->res.jsonValue["@odata.type"] =
2118b25644a1SJanet Adkins             "#LogService.v1_2_0.LogService";
2119b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Name"] = "Host Logger Service";
2120b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Description"] = "Host Logger Service";
2121b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Id"] = "HostLogger";
21221476687dSEd Tanous         asyncResp->res.jsonValue["Entries"]["@odata.id"] =
2123253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
2124253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
2125b7028ebfSSpencer Ku     });
2126b7028ebfSSpencer Ku }
2127b7028ebfSSpencer Ku 
2128b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app)
2129b7028ebfSSpencer Ku {
2130b7028ebfSSpencer Ku     BMCWEB_ROUTE(app,
213122d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/")
2132b7028ebfSSpencer Ku         .privileges(redfish::privileges::getLogEntry)
2133002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
2134002d39b4SEd Tanous             [&app](const crow::Request& req,
213522d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
213622d268cbSEd Tanous                    const std::string& systemName) {
2137c937d2bfSEd Tanous         query_param::QueryCapabilities capabilities = {
2138c937d2bfSEd Tanous             .canDelegateTop = true,
2139c937d2bfSEd Tanous             .canDelegateSkip = true,
2140c937d2bfSEd Tanous         };
2141c937d2bfSEd Tanous         query_param::Query delegatedQuery;
2142c937d2bfSEd Tanous         if (!redfish::setUpRedfishRouteWithDelegation(
21433ba00073SCarson Labrado                 app, req, asyncResp, delegatedQuery, capabilities))
2144b7028ebfSSpencer Ku         {
2145b7028ebfSSpencer Ku             return;
2146b7028ebfSSpencer Ku         }
214725b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
21487f3e84a1SEd Tanous         {
21497f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
21507f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
21517f3e84a1SEd Tanous                                        systemName);
21527f3e84a1SEd Tanous             return;
21537f3e84a1SEd Tanous         }
2154253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
215522d268cbSEd Tanous         {
215622d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
215722d268cbSEd Tanous                                        systemName);
215822d268cbSEd Tanous             return;
215922d268cbSEd Tanous         }
2160b7028ebfSSpencer Ku         asyncResp->res.jsonValue["@odata.id"] =
2161253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
2162253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
2163b7028ebfSSpencer Ku         asyncResp->res.jsonValue["@odata.type"] =
2164b7028ebfSSpencer Ku             "#LogEntryCollection.LogEntryCollection";
2165b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Name"] = "HostLogger Entries";
2166b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Description"] =
2167b7028ebfSSpencer Ku             "Collection of HostLogger Entries";
21680fda0f12SGeorge Liu         nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
2169b7028ebfSSpencer Ku         logEntryArray = nlohmann::json::array();
2170b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Members@odata.count"] = 0;
2171b7028ebfSSpencer Ku 
2172b7028ebfSSpencer Ku         std::vector<std::filesystem::path> hostLoggerFiles;
2173b7028ebfSSpencer Ku         if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
2174b7028ebfSSpencer Ku         {
2175bf2ddedeSCarson Labrado             BMCWEB_LOG_DEBUG("Failed to get host log file path");
2176b7028ebfSSpencer Ku             return;
2177b7028ebfSSpencer Ku         }
21783648c8beSEd Tanous         // If we weren't provided top and skip limits, use the defaults.
21793648c8beSEd Tanous         size_t skip = delegatedQuery.skip.value_or(0);
21805143f7a5SJiaqing Zhao         size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
2181b7028ebfSSpencer Ku         size_t logCount = 0;
2182b7028ebfSSpencer Ku         // This vector only store the entries we want to expose that
2183b7028ebfSSpencer Ku         // control by skip and top.
2184b7028ebfSSpencer Ku         std::vector<std::string> logEntries;
21853648c8beSEd Tanous         if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries,
21863648c8beSEd Tanous                                   logCount))
2187b7028ebfSSpencer Ku         {
2188b7028ebfSSpencer Ku             messages::internalError(asyncResp->res);
2189b7028ebfSSpencer Ku             return;
2190b7028ebfSSpencer Ku         }
2191b7028ebfSSpencer Ku         // If vector is empty, that means skip value larger than total
2192b7028ebfSSpencer Ku         // log count
219326f6976fSEd Tanous         if (logEntries.empty())
2194b7028ebfSSpencer Ku         {
2195b7028ebfSSpencer Ku             asyncResp->res.jsonValue["Members@odata.count"] = logCount;
2196b7028ebfSSpencer Ku             return;
2197b7028ebfSSpencer Ku         }
219826f6976fSEd Tanous         if (!logEntries.empty())
2199b7028ebfSSpencer Ku         {
2200b7028ebfSSpencer Ku             for (size_t i = 0; i < logEntries.size(); i++)
2201b7028ebfSSpencer Ku             {
22026d6574c9SJason M. Bills                 nlohmann::json::object_t hostLogEntry;
22033648c8beSEd Tanous                 fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i],
22043648c8beSEd Tanous                                         hostLogEntry);
2205b2ba3072SPatrick Williams                 logEntryArray.emplace_back(std::move(hostLogEntry));
2206b7028ebfSSpencer Ku             }
2207b7028ebfSSpencer Ku 
2208b7028ebfSSpencer Ku             asyncResp->res.jsonValue["Members@odata.count"] = logCount;
22093648c8beSEd Tanous             if (skip + top < logCount)
2210b7028ebfSSpencer Ku             {
2211b7028ebfSSpencer Ku                 asyncResp->res.jsonValue["Members@odata.nextLink"] =
2212253f11b8SEd Tanous                     std::format(
2213253f11b8SEd Tanous                         "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries?$skip=",
2214253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME) +
22153648c8beSEd Tanous                     std::to_string(skip + top);
2216b7028ebfSSpencer Ku             }
2217b7028ebfSSpencer Ku         }
2218b7028ebfSSpencer Ku     });
2219b7028ebfSSpencer Ku }
2220b7028ebfSSpencer Ku 
2221b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app)
2222b7028ebfSSpencer Ku {
2223b7028ebfSSpencer Ku     BMCWEB_ROUTE(
222422d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/")
2225b7028ebfSSpencer Ku         .privileges(redfish::privileges::getLogEntry)
2226b7028ebfSSpencer Ku         .methods(boost::beast::http::verb::get)(
222745ca1b86SEd Tanous             [&app](const crow::Request& req,
2228b7028ebfSSpencer Ku                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
222922d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
22303ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
223145ca1b86SEd Tanous         {
223245ca1b86SEd Tanous             return;
223345ca1b86SEd Tanous         }
223425b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
22357f3e84a1SEd Tanous         {
22367f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
22377f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
22387f3e84a1SEd Tanous                                        systemName);
22397f3e84a1SEd Tanous             return;
22407f3e84a1SEd Tanous         }
2241253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
224222d268cbSEd Tanous         {
224322d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
224422d268cbSEd Tanous                                        systemName);
224522d268cbSEd Tanous             return;
224622d268cbSEd Tanous         }
22476f056f24SEd Tanous         std::string_view targetID = param;
2248b7028ebfSSpencer Ku 
2249b7028ebfSSpencer Ku         uint64_t idInt = 0;
2250ca45aa3cSEd Tanous 
22516f056f24SEd Tanous         auto [ptr, ec] = std::from_chars(targetID.begin(), targetID.end(),
225284396af9SPatrick Williams                                          idInt);
22536f056f24SEd Tanous         if (ec != std::errc{} || ptr != targetID.end())
2254b7028ebfSSpencer Ku         {
22559db4ba25SJiaqing Zhao             messages::resourceNotFound(asyncResp->res, "LogEntry", param);
2256b7028ebfSSpencer Ku             return;
2257b7028ebfSSpencer Ku         }
2258b7028ebfSSpencer Ku 
2259b7028ebfSSpencer Ku         std::vector<std::filesystem::path> hostLoggerFiles;
2260b7028ebfSSpencer Ku         if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
2261b7028ebfSSpencer Ku         {
2262bf2ddedeSCarson Labrado             BMCWEB_LOG_DEBUG("Failed to get host log file path");
2263b7028ebfSSpencer Ku             return;
2264b7028ebfSSpencer Ku         }
2265b7028ebfSSpencer Ku 
2266b7028ebfSSpencer Ku         size_t logCount = 0;
22673648c8beSEd Tanous         size_t top = 1;
2268b7028ebfSSpencer Ku         std::vector<std::string> logEntries;
2269b7028ebfSSpencer Ku         // We can get specific entry by skip and top. For example, if we
2270b7028ebfSSpencer Ku         // want to get nth entry, we can set skip = n-1 and top = 1 to
2271b7028ebfSSpencer Ku         // get that entry
2272002d39b4SEd Tanous         if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries,
2273002d39b4SEd Tanous                                   logCount))
2274b7028ebfSSpencer Ku         {
2275b7028ebfSSpencer Ku             messages::internalError(asyncResp->res);
2276b7028ebfSSpencer Ku             return;
2277b7028ebfSSpencer Ku         }
2278b7028ebfSSpencer Ku 
2279b7028ebfSSpencer Ku         if (!logEntries.empty())
2280b7028ebfSSpencer Ku         {
22816d6574c9SJason M. Bills             nlohmann::json::object_t hostLogEntry;
22826d6574c9SJason M. Bills             fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry);
22836d6574c9SJason M. Bills             asyncResp->res.jsonValue.update(hostLogEntry);
2284b7028ebfSSpencer Ku             return;
2285b7028ebfSSpencer Ku         }
2286b7028ebfSSpencer Ku 
2287b7028ebfSSpencer Ku         // Requested ID was not found
22889db4ba25SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "LogEntry", param);
2289b7028ebfSSpencer Ku     });
2290b7028ebfSSpencer Ku }
2291b7028ebfSSpencer Ku 
2292dd72e87bSClaire Weinan inline void handleBMCLogServicesCollectionGet(
2293fdd26906SClaire Weinan     crow::App& app, const crow::Request& req,
2294253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2295253f11b8SEd Tanous     const std::string& managerId)
22961da66f75SEd Tanous {
22973ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
229845ca1b86SEd Tanous     {
229945ca1b86SEd Tanous         return;
230045ca1b86SEd Tanous     }
2301253f11b8SEd Tanous 
2302253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2303253f11b8SEd Tanous     {
2304253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2305253f11b8SEd Tanous         return;
2306253f11b8SEd Tanous     }
2307253f11b8SEd Tanous 
23087e860f15SJohn Edward Broadbent     // Collections don't include the static data added by SubRoute
23097e860f15SJohn Edward Broadbent     // because it has a duplicate entry for members
2310e1f26343SJason M. Bills     asyncResp->res.jsonValue["@odata.type"] =
23111da66f75SEd Tanous         "#LogServiceCollection.LogServiceCollection";
2312253f11b8SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2313253f11b8SEd Tanous         "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME);
2314002d39b4SEd Tanous     asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
2315e1f26343SJason M. Bills     asyncResp->res.jsonValue["Description"] =
23161da66f75SEd Tanous         "Collection of LogServices for this Manager";
2317002d39b4SEd Tanous     nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
2318c4bf6374SJason M. Bills     logServiceArray = nlohmann::json::array();
2319fdd26906SClaire Weinan 
232025b54dbaSEd Tanous     if constexpr (BMCWEB_REDFISH_BMC_JOURNAL)
232125b54dbaSEd Tanous     {
2322613dabeaSEd Tanous         nlohmann::json::object_t journal;
2323253f11b8SEd Tanous         journal["@odata.id"] =
2324253f11b8SEd Tanous             boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal",
2325253f11b8SEd Tanous                                 BMCWEB_REDFISH_MANAGER_URI_NAME);
2326b2ba3072SPatrick Williams         logServiceArray.emplace_back(std::move(journal));
232725b54dbaSEd Tanous     }
2328fdd26906SClaire Weinan 
2329fdd26906SClaire Weinan     asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
2330fdd26906SClaire Weinan 
233125b54dbaSEd Tanous     if constexpr (BMCWEB_REDFISH_DUMP_LOG)
233225b54dbaSEd Tanous     {
233315912159SGeorge Liu         constexpr std::array<std::string_view, 1> interfaces = {
23347a1dbc48SGeorge Liu             "xyz.openbmc_project.Collection.DeleteAll"};
23357a1dbc48SGeorge Liu         dbus::utility::getSubTreePaths(
23367a1dbc48SGeorge Liu             "/xyz/openbmc_project/dump", 0, interfaces,
233725b54dbaSEd Tanous             [asyncResp](const boost::system::error_code& ec,
233825b54dbaSEd Tanous                         const dbus::utility::MapperGetSubTreePathsResponse&
233925b54dbaSEd Tanous                             subTreePaths) {
2340fdd26906SClaire Weinan             if (ec)
2341fdd26906SClaire Weinan             {
234262598e31SEd Tanous                 BMCWEB_LOG_ERROR(
234362598e31SEd Tanous                     "handleBMCLogServicesCollectionGet respHandler got error {}",
234462598e31SEd Tanous                     ec);
2345fdd26906SClaire Weinan                 // Assume that getting an error simply means there are no dump
2346fdd26906SClaire Weinan                 // LogServices. Return without adding any error response.
2347fdd26906SClaire Weinan                 return;
2348fdd26906SClaire Weinan             }
2349fdd26906SClaire Weinan 
2350fdd26906SClaire Weinan             nlohmann::json& logServiceArrayLocal =
2351fdd26906SClaire Weinan                 asyncResp->res.jsonValue["Members"];
2352fdd26906SClaire Weinan 
2353fdd26906SClaire Weinan             for (const std::string& path : subTreePaths)
2354fdd26906SClaire Weinan             {
2355fdd26906SClaire Weinan                 if (path == "/xyz/openbmc_project/dump/bmc")
2356fdd26906SClaire Weinan                 {
2357613dabeaSEd Tanous                     nlohmann::json::object_t member;
2358253f11b8SEd Tanous                     member["@odata.id"] = boost::urls::format(
2359253f11b8SEd Tanous                         "/redfish/v1/Managers/{}/LogServices/Dump",
2360253f11b8SEd Tanous                         BMCWEB_REDFISH_MANAGER_URI_NAME);
2361b2ba3072SPatrick Williams                     logServiceArrayLocal.emplace_back(std::move(member));
2362fdd26906SClaire Weinan                 }
2363fdd26906SClaire Weinan                 else if (path == "/xyz/openbmc_project/dump/faultlog")
2364fdd26906SClaire Weinan                 {
2365613dabeaSEd Tanous                     nlohmann::json::object_t member;
2366253f11b8SEd Tanous                     member["@odata.id"] = boost::urls::format(
2367253f11b8SEd Tanous                         "/redfish/v1/Managers/{}/LogServices/FaultLog",
2368253f11b8SEd Tanous                         BMCWEB_REDFISH_MANAGER_URI_NAME);
2369b2ba3072SPatrick Williams                     logServiceArrayLocal.emplace_back(std::move(member));
2370fdd26906SClaire Weinan                 }
2371fdd26906SClaire Weinan             }
2372fdd26906SClaire Weinan 
2373e1f26343SJason M. Bills             asyncResp->res.jsonValue["Members@odata.count"] =
2374fdd26906SClaire Weinan                 logServiceArrayLocal.size();
23757a1dbc48SGeorge Liu         });
237625b54dbaSEd Tanous     }
2377fdd26906SClaire Weinan }
2378fdd26906SClaire Weinan 
2379fdd26906SClaire Weinan inline void requestRoutesBMCLogServiceCollection(App& app)
2380fdd26906SClaire Weinan {
2381253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/")
2382fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogServiceCollection)
2383fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(
2384dd72e87bSClaire Weinan             std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app)));
2385e1f26343SJason M. Bills }
2386e1f26343SJason M. Bills 
2387fdd26906SClaire Weinan inline void
2388fdd26906SClaire Weinan     getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2389fdd26906SClaire Weinan                        const std::string& dumpType)
2390c9bb6861Sraviteja-b {
2391fdd26906SClaire Weinan     std::string dumpPath;
2392539d8c6bSEd Tanous     log_service::OverWritePolicy overWritePolicy =
2393539d8c6bSEd Tanous         log_service::OverWritePolicy::Invalid;
2394fdd26906SClaire Weinan     bool collectDiagnosticDataSupported = false;
2395fdd26906SClaire Weinan 
2396fdd26906SClaire Weinan     if (dumpType == "BMC")
239745ca1b86SEd Tanous     {
2398253f11b8SEd Tanous         dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump",
2399253f11b8SEd Tanous                                BMCWEB_REDFISH_MANAGER_URI_NAME);
2400539d8c6bSEd Tanous         overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
2401fdd26906SClaire Weinan         collectDiagnosticDataSupported = true;
2402fdd26906SClaire Weinan     }
2403fdd26906SClaire Weinan     else if (dumpType == "FaultLog")
2404fdd26906SClaire Weinan     {
2405253f11b8SEd Tanous         dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog",
2406253f11b8SEd Tanous                                BMCWEB_REDFISH_MANAGER_URI_NAME);
2407539d8c6bSEd Tanous         overWritePolicy = log_service::OverWritePolicy::Unknown;
2408fdd26906SClaire Weinan         collectDiagnosticDataSupported = false;
2409fdd26906SClaire Weinan     }
2410fdd26906SClaire Weinan     else if (dumpType == "System")
2411fdd26906SClaire Weinan     {
2412253f11b8SEd Tanous         dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump",
2413253f11b8SEd Tanous                                BMCWEB_REDFISH_SYSTEM_URI_NAME);
2414539d8c6bSEd Tanous         overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
2415fdd26906SClaire Weinan         collectDiagnosticDataSupported = true;
2416fdd26906SClaire Weinan     }
2417fdd26906SClaire Weinan     else
2418fdd26906SClaire Weinan     {
241962598e31SEd Tanous         BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}",
242062598e31SEd Tanous                          dumpType);
2421fdd26906SClaire Weinan         messages::internalError(asyncResp->res);
242245ca1b86SEd Tanous         return;
242345ca1b86SEd Tanous     }
2424fdd26906SClaire Weinan 
2425fdd26906SClaire Weinan     asyncResp->res.jsonValue["@odata.id"] = dumpPath;
2426fdd26906SClaire Weinan     asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService";
2427c9bb6861Sraviteja-b     asyncResp->res.jsonValue["Name"] = "Dump LogService";
2428fdd26906SClaire Weinan     asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService";
2429fdd26906SClaire Weinan     asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename();
2430539d8c6bSEd Tanous     asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy;
24317c8c4058STejas Patil 
24327c8c4058STejas Patil     std::pair<std::string, std::string> redfishDateTimeOffset =
24332b82937eSEd Tanous         redfish::time_utils::getDateTimeOffsetNow();
24340fda0f12SGeorge Liu     asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
24357c8c4058STejas Patil     asyncResp->res.jsonValue["DateTimeLocalOffset"] =
24367c8c4058STejas Patil         redfishDateTimeOffset.second;
24377c8c4058STejas Patil 
2438fdd26906SClaire Weinan     asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries";
2439fdd26906SClaire Weinan 
2440fdd26906SClaire Weinan     if (collectDiagnosticDataSupported)
2441fdd26906SClaire Weinan     {
2442002d39b4SEd Tanous         asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
24431476687dSEd Tanous                                 ["target"] =
2444fdd26906SClaire Weinan             dumpPath + "/Actions/LogService.CollectDiagnosticData";
2445fdd26906SClaire Weinan     }
24460d946211SClaire Weinan 
24470d946211SClaire Weinan     constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface};
24480d946211SClaire Weinan     dbus::utility::getSubTreePaths(
24490d946211SClaire Weinan         "/xyz/openbmc_project/dump", 0, interfaces,
24500d946211SClaire Weinan         [asyncResp, dumpType, dumpPath](
24510d946211SClaire Weinan             const boost::system::error_code& ec,
24520d946211SClaire Weinan             const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
24530d946211SClaire Weinan         if (ec)
24540d946211SClaire Weinan         {
245562598e31SEd Tanous             BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", ec);
24560d946211SClaire Weinan             // Assume that getting an error simply means there are no dump
24570d946211SClaire Weinan             // LogServices. Return without adding any error response.
24580d946211SClaire Weinan             return;
24590d946211SClaire Weinan         }
246018f8f608SEd Tanous         std::string dbusDumpPath = getDumpPath(dumpType);
24610d946211SClaire Weinan         for (const std::string& path : subTreePaths)
24620d946211SClaire Weinan         {
24630d946211SClaire Weinan             if (path == dbusDumpPath)
24640d946211SClaire Weinan             {
24650d946211SClaire Weinan                 asyncResp->res
24660d946211SClaire Weinan                     .jsonValue["Actions"]["#LogService.ClearLog"]["target"] =
24670d946211SClaire Weinan                     dumpPath + "/Actions/LogService.ClearLog";
24680d946211SClaire Weinan                 break;
24690d946211SClaire Weinan             }
24700d946211SClaire Weinan         }
24710d946211SClaire Weinan     });
2472c9bb6861Sraviteja-b }
2473c9bb6861Sraviteja-b 
2474fdd26906SClaire Weinan inline void handleLogServicesDumpServiceGet(
2475fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2476253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2477253f11b8SEd Tanous     const std::string& managerId)
24787e860f15SJohn Edward Broadbent {
24793ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
248045ca1b86SEd Tanous     {
248145ca1b86SEd Tanous         return;
248245ca1b86SEd Tanous     }
2483253f11b8SEd Tanous 
2484253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2485253f11b8SEd Tanous     {
2486253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2487253f11b8SEd Tanous         return;
2488253f11b8SEd Tanous     }
2489253f11b8SEd Tanous 
2490fdd26906SClaire Weinan     getDumpServiceInfo(asyncResp, dumpType);
2491fdd26906SClaire Weinan }
2492c9bb6861Sraviteja-b 
249322d268cbSEd Tanous inline void handleLogServicesDumpServiceComputerSystemGet(
249422d268cbSEd Tanous     crow::App& app, const crow::Request& req,
249522d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
249622d268cbSEd Tanous     const std::string& chassisId)
249722d268cbSEd Tanous {
249822d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
249922d268cbSEd Tanous     {
250022d268cbSEd Tanous         return;
250122d268cbSEd Tanous     }
2502253f11b8SEd Tanous     if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
250322d268cbSEd Tanous     {
250422d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
250522d268cbSEd Tanous         return;
250622d268cbSEd Tanous     }
250722d268cbSEd Tanous     getDumpServiceInfo(asyncResp, "System");
250822d268cbSEd Tanous }
250922d268cbSEd Tanous 
2510fdd26906SClaire Weinan inline void handleLogServicesDumpEntriesCollectionGet(
2511fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2512253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2513253f11b8SEd Tanous     const std::string& managerId)
2514fdd26906SClaire Weinan {
2515fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2516fdd26906SClaire Weinan     {
2517fdd26906SClaire Weinan         return;
2518fdd26906SClaire Weinan     }
2519253f11b8SEd Tanous 
2520253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2521253f11b8SEd Tanous     {
2522253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2523253f11b8SEd Tanous         return;
2524253f11b8SEd Tanous     }
2525fdd26906SClaire Weinan     getDumpEntryCollection(asyncResp, dumpType);
2526fdd26906SClaire Weinan }
2527fdd26906SClaire Weinan 
252822d268cbSEd Tanous inline void handleLogServicesDumpEntriesCollectionComputerSystemGet(
252922d268cbSEd Tanous     crow::App& app, const crow::Request& req,
253022d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
253122d268cbSEd Tanous     const std::string& chassisId)
253222d268cbSEd Tanous {
253322d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
253422d268cbSEd Tanous     {
253522d268cbSEd Tanous         return;
253622d268cbSEd Tanous     }
2537253f11b8SEd Tanous     if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
253822d268cbSEd Tanous     {
253922d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
254022d268cbSEd Tanous         return;
254122d268cbSEd Tanous     }
254222d268cbSEd Tanous     getDumpEntryCollection(asyncResp, "System");
254322d268cbSEd Tanous }
254422d268cbSEd Tanous 
2545fdd26906SClaire Weinan inline void handleLogServicesDumpEntryGet(
2546fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2547fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2548253f11b8SEd Tanous     const std::string& managerId, const std::string& dumpId)
2549fdd26906SClaire Weinan {
2550fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2551fdd26906SClaire Weinan     {
2552fdd26906SClaire Weinan         return;
2553fdd26906SClaire Weinan     }
2554253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2555253f11b8SEd Tanous     {
2556253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2557253f11b8SEd Tanous         return;
2558253f11b8SEd Tanous     }
2559fdd26906SClaire Weinan     getDumpEntryById(asyncResp, dumpId, dumpType);
2560fdd26906SClaire Weinan }
2561168d1b1aSCarson Labrado 
256222d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemGet(
256322d268cbSEd Tanous     crow::App& app, const crow::Request& req,
256422d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
256522d268cbSEd Tanous     const std::string& chassisId, const std::string& dumpId)
256622d268cbSEd Tanous {
256722d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
256822d268cbSEd Tanous     {
256922d268cbSEd Tanous         return;
257022d268cbSEd Tanous     }
2571253f11b8SEd Tanous     if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
257222d268cbSEd Tanous     {
257322d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
257422d268cbSEd Tanous         return;
257522d268cbSEd Tanous     }
257622d268cbSEd Tanous     getDumpEntryById(asyncResp, dumpId, "System");
257722d268cbSEd Tanous }
2578fdd26906SClaire Weinan 
2579fdd26906SClaire Weinan inline void handleLogServicesDumpEntryDelete(
2580fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2581fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2582253f11b8SEd Tanous     const std::string& managerId, const std::string& dumpId)
2583fdd26906SClaire Weinan {
2584fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2585fdd26906SClaire Weinan     {
2586fdd26906SClaire Weinan         return;
2587fdd26906SClaire Weinan     }
2588253f11b8SEd Tanous 
2589253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2590253f11b8SEd Tanous     {
2591253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2592253f11b8SEd Tanous         return;
2593253f11b8SEd Tanous     }
2594fdd26906SClaire Weinan     deleteDumpEntry(asyncResp, dumpId, dumpType);
2595fdd26906SClaire Weinan }
2596fdd26906SClaire Weinan 
259722d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemDelete(
259822d268cbSEd Tanous     crow::App& app, const crow::Request& req,
259922d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
260022d268cbSEd Tanous     const std::string& chassisId, const std::string& dumpId)
260122d268cbSEd Tanous {
260222d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
260322d268cbSEd Tanous     {
260422d268cbSEd Tanous         return;
260522d268cbSEd Tanous     }
2606253f11b8SEd Tanous     if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
260722d268cbSEd Tanous     {
260822d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
260922d268cbSEd Tanous         return;
261022d268cbSEd Tanous     }
261122d268cbSEd Tanous     deleteDumpEntry(asyncResp, dumpId, "System");
261222d268cbSEd Tanous }
261322d268cbSEd Tanous 
2614168d1b1aSCarson Labrado inline void handleLogServicesDumpEntryDownloadGet(
2615168d1b1aSCarson Labrado     crow::App& app, const std::string& dumpType, const crow::Request& req,
2616168d1b1aSCarson Labrado     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2617253f11b8SEd Tanous     const std::string& managerId, const std::string& dumpId)
2618168d1b1aSCarson Labrado {
2619168d1b1aSCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2620168d1b1aSCarson Labrado     {
2621168d1b1aSCarson Labrado         return;
2622168d1b1aSCarson Labrado     }
2623253f11b8SEd Tanous 
2624253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2625253f11b8SEd Tanous     {
2626253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2627253f11b8SEd Tanous         return;
2628253f11b8SEd Tanous     }
2629168d1b1aSCarson Labrado     downloadDumpEntry(asyncResp, dumpId, dumpType);
2630168d1b1aSCarson Labrado }
2631168d1b1aSCarson Labrado 
2632168d1b1aSCarson Labrado inline void handleDBusEventLogEntryDownloadGet(
2633168d1b1aSCarson Labrado     crow::App& app, const std::string& dumpType, const crow::Request& req,
2634168d1b1aSCarson Labrado     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2635168d1b1aSCarson Labrado     const std::string& systemName, const std::string& entryID)
2636168d1b1aSCarson Labrado {
2637168d1b1aSCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2638168d1b1aSCarson Labrado     {
2639168d1b1aSCarson Labrado         return;
2640168d1b1aSCarson Labrado     }
2641168d1b1aSCarson Labrado     if (!http_helpers::isContentTypeAllowed(
2642168d1b1aSCarson Labrado             req.getHeaderValue("Accept"),
2643168d1b1aSCarson Labrado             http_helpers::ContentType::OctetStream, true))
2644168d1b1aSCarson Labrado     {
2645168d1b1aSCarson Labrado         asyncResp->res.result(boost::beast::http::status::bad_request);
2646168d1b1aSCarson Labrado         return;
2647168d1b1aSCarson Labrado     }
2648168d1b1aSCarson Labrado     downloadEventLogEntry(asyncResp, systemName, entryID, dumpType);
2649168d1b1aSCarson Labrado }
2650168d1b1aSCarson Labrado 
2651fdd26906SClaire Weinan inline void handleLogServicesDumpCollectDiagnosticDataPost(
2652fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2653253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2654253f11b8SEd Tanous     const std::string& managerId)
2655fdd26906SClaire Weinan {
2656fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2657fdd26906SClaire Weinan     {
2658fdd26906SClaire Weinan         return;
2659fdd26906SClaire Weinan     }
2660253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2661253f11b8SEd Tanous     {
2662253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2663253f11b8SEd Tanous         return;
2664253f11b8SEd Tanous     }
2665253f11b8SEd Tanous 
2666fdd26906SClaire Weinan     createDump(asyncResp, req, dumpType);
2667fdd26906SClaire Weinan }
2668fdd26906SClaire Weinan 
266922d268cbSEd Tanous inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost(
267022d268cbSEd Tanous     crow::App& app, const crow::Request& req,
267122d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
26727f3e84a1SEd Tanous     const std::string& systemName)
267322d268cbSEd Tanous {
267422d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
267522d268cbSEd Tanous     {
267622d268cbSEd Tanous         return;
267722d268cbSEd Tanous     }
26787f3e84a1SEd Tanous 
267925b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
268022d268cbSEd Tanous     {
26817f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
26827f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
26837f3e84a1SEd Tanous                                    systemName);
26847f3e84a1SEd Tanous         return;
26857f3e84a1SEd Tanous     }
2686253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
26877f3e84a1SEd Tanous     {
26887f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
26897f3e84a1SEd Tanous                                    systemName);
269022d268cbSEd Tanous         return;
269122d268cbSEd Tanous     }
269222d268cbSEd Tanous     createDump(asyncResp, req, "System");
269322d268cbSEd Tanous }
269422d268cbSEd Tanous 
2695fdd26906SClaire Weinan inline void handleLogServicesDumpClearLogPost(
2696fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2697253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2698253f11b8SEd Tanous     const std::string& managerId)
2699fdd26906SClaire Weinan {
2700fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2701fdd26906SClaire Weinan     {
2702fdd26906SClaire Weinan         return;
2703fdd26906SClaire Weinan     }
2704253f11b8SEd Tanous 
2705253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2706253f11b8SEd Tanous     {
2707253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2708253f11b8SEd Tanous         return;
2709253f11b8SEd Tanous     }
2710fdd26906SClaire Weinan     clearDump(asyncResp, dumpType);
2711fdd26906SClaire Weinan }
2712fdd26906SClaire Weinan 
271322d268cbSEd Tanous inline void handleLogServicesDumpClearLogComputerSystemPost(
271422d268cbSEd Tanous     crow::App& app, const crow::Request& req,
271522d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
27167f3e84a1SEd Tanous     const std::string& systemName)
271722d268cbSEd Tanous {
271822d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
271922d268cbSEd Tanous     {
272022d268cbSEd Tanous         return;
272122d268cbSEd Tanous     }
272225b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
272322d268cbSEd Tanous     {
27247f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
27257f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
27267f3e84a1SEd Tanous                                    systemName);
27277f3e84a1SEd Tanous         return;
27287f3e84a1SEd Tanous     }
2729253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
27307f3e84a1SEd Tanous     {
27317f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
27327f3e84a1SEd Tanous                                    systemName);
273322d268cbSEd Tanous         return;
273422d268cbSEd Tanous     }
273522d268cbSEd Tanous     clearDump(asyncResp, "System");
273622d268cbSEd Tanous }
273722d268cbSEd Tanous 
2738fdd26906SClaire Weinan inline void requestRoutesBMCDumpService(App& app)
2739fdd26906SClaire Weinan {
2740253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/")
2741fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogService)
2742fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2743fdd26906SClaire Weinan             handleLogServicesDumpServiceGet, std::ref(app), "BMC"));
2744fdd26906SClaire Weinan }
2745fdd26906SClaire Weinan 
2746fdd26906SClaire Weinan inline void requestRoutesBMCDumpEntryCollection(App& app)
2747fdd26906SClaire Weinan {
2748253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/")
2749fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogEntryCollection)
2750fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2751fdd26906SClaire Weinan             handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC"));
2752c9bb6861Sraviteja-b }
2753c9bb6861Sraviteja-b 
27547e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app)
2755c9bb6861Sraviteja-b {
27567e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
2757253f11b8SEd Tanous                  "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
2758ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
2759fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2760fdd26906SClaire Weinan             handleLogServicesDumpEntryGet, std::ref(app), "BMC"));
2761fdd26906SClaire Weinan 
27627e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
2763253f11b8SEd Tanous                  "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
2764ed398213SEd Tanous         .privileges(redfish::privileges::deleteLogEntry)
2765fdd26906SClaire Weinan         .methods(boost::beast::http::verb::delete_)(std::bind_front(
2766fdd26906SClaire Weinan             handleLogServicesDumpEntryDelete, std::ref(app), "BMC"));
2767c9bb6861Sraviteja-b }
2768c9bb6861Sraviteja-b 
2769168d1b1aSCarson Labrado inline void requestRoutesBMCDumpEntryDownload(App& app)
2770168d1b1aSCarson Labrado {
2771168d1b1aSCarson Labrado     BMCWEB_ROUTE(
2772168d1b1aSCarson Labrado         app,
2773253f11b8SEd Tanous         "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/")
2774168d1b1aSCarson Labrado         .privileges(redfish::privileges::getLogEntry)
2775168d1b1aSCarson Labrado         .methods(boost::beast::http::verb::get)(std::bind_front(
2776168d1b1aSCarson Labrado             handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC"));
2777168d1b1aSCarson Labrado }
2778168d1b1aSCarson Labrado 
27797e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app)
2780c9bb6861Sraviteja-b {
27810fda0f12SGeorge Liu     BMCWEB_ROUTE(
27820fda0f12SGeorge Liu         app,
2783253f11b8SEd Tanous         "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
2784ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
27857e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
2786fdd26906SClaire Weinan             std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost,
2787fdd26906SClaire Weinan                             std::ref(app), "BMC"));
2788a43be80fSAsmitha Karunanithi }
2789a43be80fSAsmitha Karunanithi 
27907e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app)
279180319af1SAsmitha Karunanithi {
27920fda0f12SGeorge Liu     BMCWEB_ROUTE(
27930fda0f12SGeorge Liu         app,
2794253f11b8SEd Tanous         "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
2795ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
2796fdd26906SClaire Weinan         .methods(boost::beast::http::verb::post)(std::bind_front(
2797fdd26906SClaire Weinan             handleLogServicesDumpClearLogPost, std::ref(app), "BMC"));
279845ca1b86SEd Tanous }
2799fdd26906SClaire Weinan 
2800168d1b1aSCarson Labrado inline void requestRoutesDBusEventLogEntryDownload(App& app)
2801168d1b1aSCarson Labrado {
2802168d1b1aSCarson Labrado     BMCWEB_ROUTE(
2803168d1b1aSCarson Labrado         app,
28049e9d99daSRavi Teja         "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/")
2805168d1b1aSCarson Labrado         .privileges(redfish::privileges::getLogEntry)
2806168d1b1aSCarson Labrado         .methods(boost::beast::http::verb::get)(std::bind_front(
2807168d1b1aSCarson Labrado             handleDBusEventLogEntryDownloadGet, std::ref(app), "System"));
2808168d1b1aSCarson Labrado }
2809168d1b1aSCarson Labrado 
2810fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpService(App& app)
2811fdd26906SClaire Weinan {
2812253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/")
2813fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogService)
2814fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2815fdd26906SClaire Weinan             handleLogServicesDumpServiceGet, std::ref(app), "FaultLog"));
2816fdd26906SClaire Weinan }
2817fdd26906SClaire Weinan 
2818fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntryCollection(App& app)
2819fdd26906SClaire Weinan {
2820253f11b8SEd Tanous     BMCWEB_ROUTE(app,
2821253f11b8SEd Tanous                  "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/")
2822fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogEntryCollection)
2823fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(
2824fdd26906SClaire Weinan             std::bind_front(handleLogServicesDumpEntriesCollectionGet,
2825fdd26906SClaire Weinan                             std::ref(app), "FaultLog"));
2826fdd26906SClaire Weinan }
2827fdd26906SClaire Weinan 
2828fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntry(App& app)
2829fdd26906SClaire Weinan {
2830253f11b8SEd Tanous     BMCWEB_ROUTE(
2831253f11b8SEd Tanous         app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
2832fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogEntry)
2833fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2834fdd26906SClaire Weinan             handleLogServicesDumpEntryGet, std::ref(app), "FaultLog"));
2835fdd26906SClaire Weinan 
2836253f11b8SEd Tanous     BMCWEB_ROUTE(
2837253f11b8SEd Tanous         app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
2838fdd26906SClaire Weinan         .privileges(redfish::privileges::deleteLogEntry)
2839fdd26906SClaire Weinan         .methods(boost::beast::http::verb::delete_)(std::bind_front(
2840fdd26906SClaire Weinan             handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog"));
2841fdd26906SClaire Weinan }
2842fdd26906SClaire Weinan 
2843fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpClear(App& app)
2844fdd26906SClaire Weinan {
2845fdd26906SClaire Weinan     BMCWEB_ROUTE(
2846fdd26906SClaire Weinan         app,
2847253f11b8SEd Tanous         "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/")
2848fdd26906SClaire Weinan         .privileges(redfish::privileges::postLogService)
2849fdd26906SClaire Weinan         .methods(boost::beast::http::verb::post)(std::bind_front(
2850fdd26906SClaire Weinan             handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog"));
28515cb1dd27SAsmitha Karunanithi }
28525cb1dd27SAsmitha Karunanithi 
28537e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app)
28545cb1dd27SAsmitha Karunanithi {
285522d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/")
2856ed398213SEd Tanous         .privileges(redfish::privileges::getLogService)
28576ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
285822d268cbSEd Tanous             handleLogServicesDumpServiceComputerSystemGet, std::ref(app)));
28595cb1dd27SAsmitha Karunanithi }
28605cb1dd27SAsmitha Karunanithi 
28617e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app)
28627e860f15SJohn Edward Broadbent {
286322d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/")
2864ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntryCollection)
286522d268cbSEd Tanous         .methods(boost::beast::http::verb::get)(std::bind_front(
286622d268cbSEd Tanous             handleLogServicesDumpEntriesCollectionComputerSystemGet,
286722d268cbSEd Tanous             std::ref(app)));
28685cb1dd27SAsmitha Karunanithi }
28695cb1dd27SAsmitha Karunanithi 
28707e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app)
28715cb1dd27SAsmitha Karunanithi {
28727e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
287322d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
2874ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
28756ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
287622d268cbSEd Tanous             handleLogServicesDumpEntryComputerSystemGet, std::ref(app)));
28778d1b46d7Szhanghch05 
28787e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
287922d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
2880ed398213SEd Tanous         .privileges(redfish::privileges::deleteLogEntry)
28816ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::delete_)(std::bind_front(
288222d268cbSEd Tanous             handleLogServicesDumpEntryComputerSystemDelete, std::ref(app)));
28835cb1dd27SAsmitha Karunanithi }
2884c9bb6861Sraviteja-b 
28857e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app)
2886c9bb6861Sraviteja-b {
28870fda0f12SGeorge Liu     BMCWEB_ROUTE(
28880fda0f12SGeorge Liu         app,
288922d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
2890ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
289122d268cbSEd Tanous         .methods(boost::beast::http::verb::post)(std::bind_front(
289222d268cbSEd Tanous             handleLogServicesDumpCollectDiagnosticDataComputerSystemPost,
289322d268cbSEd Tanous             std::ref(app)));
2894a43be80fSAsmitha Karunanithi }
2895a43be80fSAsmitha Karunanithi 
28967e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app)
2897a43be80fSAsmitha Karunanithi {
28980fda0f12SGeorge Liu     BMCWEB_ROUTE(
28990fda0f12SGeorge Liu         app,
290022d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
2901ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
29026ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::post)(std::bind_front(
290322d268cbSEd Tanous             handleLogServicesDumpClearLogComputerSystemPost, std::ref(app)));
2904013487e5Sraviteja-b }
2905013487e5Sraviteja-b 
29067e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app)
29071da66f75SEd Tanous {
29083946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
29093946028dSAppaRao Puli     // method for security reasons.
29101da66f75SEd Tanous     /**
29111da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
29121da66f75SEd Tanous      */
291322d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/")
2914ed398213SEd Tanous         // This is incorrect, should be:
2915ed398213SEd Tanous         //.privileges(redfish::privileges::getLogService)
2916432a890cSEd Tanous         .privileges({{"ConfigureManager"}})
2917002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
2918002d39b4SEd Tanous             [&app](const crow::Request& req,
291922d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
292022d268cbSEd Tanous                    const std::string& systemName) {
29213ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
292245ca1b86SEd Tanous         {
292345ca1b86SEd Tanous             return;
292445ca1b86SEd Tanous         }
292525b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
29267f3e84a1SEd Tanous         {
29277f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
29287f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
29297f3e84a1SEd Tanous                                        systemName);
29307f3e84a1SEd Tanous             return;
29317f3e84a1SEd Tanous         }
2932253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
293322d268cbSEd Tanous         {
293422d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
293522d268cbSEd Tanous                                        systemName);
293622d268cbSEd Tanous             return;
293722d268cbSEd Tanous         }
293822d268cbSEd Tanous 
29397e860f15SJohn Edward Broadbent         // Copy over the static data to include the entries added by
29407e860f15SJohn Edward Broadbent         // SubRoute
29410f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
2942253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
2943253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
2944e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
29458e6c099aSJason M. Bills             "#LogService.v1_2_0.LogService";
29464f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
29474f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
294815b89725SV-Sanjana         asyncResp->res.jsonValue["Id"] = "Crashdump";
2949539d8c6bSEd Tanous         asyncResp->res.jsonValue["OverWritePolicy"] =
2950539d8c6bSEd Tanous             log_service::OverWritePolicy::WrapsWhenFull;
2951e1f26343SJason M. Bills         asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
29527c8c4058STejas Patil 
29537c8c4058STejas Patil         std::pair<std::string, std::string> redfishDateTimeOffset =
29542b82937eSEd Tanous             redfish::time_utils::getDateTimeOffsetNow();
29557c8c4058STejas Patil         asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
29567c8c4058STejas Patil         asyncResp->res.jsonValue["DateTimeLocalOffset"] =
29577c8c4058STejas Patil             redfishDateTimeOffset.second;
29587c8c4058STejas Patil 
29591476687dSEd Tanous         asyncResp->res.jsonValue["Entries"]["@odata.id"] =
2960253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2961253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
2962253f11b8SEd Tanous         asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2963253f11b8SEd Tanous                                 ["target"] = std::format(
2964253f11b8SEd Tanous             "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog",
2965253f11b8SEd Tanous             BMCWEB_REDFISH_SYSTEM_URI_NAME);
2966002d39b4SEd Tanous         asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2967253f11b8SEd Tanous                                 ["target"] = std::format(
2968253f11b8SEd Tanous             "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData",
2969253f11b8SEd Tanous             BMCWEB_REDFISH_SYSTEM_URI_NAME);
29707e860f15SJohn Edward Broadbent     });
29711da66f75SEd Tanous }
29721da66f75SEd Tanous 
29737e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app)
29745b61b5e8SJason M. Bills {
29750fda0f12SGeorge Liu     BMCWEB_ROUTE(
29760fda0f12SGeorge Liu         app,
297722d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/")
2978ed398213SEd Tanous         // This is incorrect, should be:
2979ed398213SEd Tanous         //.privileges(redfish::privileges::postLogService)
2980432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
29817e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
298245ca1b86SEd Tanous             [&app](const crow::Request& req,
298322d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
298422d268cbSEd Tanous                    const std::string& systemName) {
29853ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
298645ca1b86SEd Tanous         {
298745ca1b86SEd Tanous             return;
298845ca1b86SEd Tanous         }
298925b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
29907f3e84a1SEd Tanous         {
29917f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
29927f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
29937f3e84a1SEd Tanous                                        systemName);
29947f3e84a1SEd Tanous             return;
29957f3e84a1SEd Tanous         }
2996253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
299722d268cbSEd Tanous         {
299822d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
299922d268cbSEd Tanous                                        systemName);
300022d268cbSEd Tanous             return;
300122d268cbSEd Tanous         }
30025b61b5e8SJason M. Bills         crow::connections::systemBus->async_method_call(
30035e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec,
3004cb13a392SEd Tanous                         const std::string&) {
30055b61b5e8SJason M. Bills             if (ec)
30065b61b5e8SJason M. Bills             {
30075b61b5e8SJason M. Bills                 messages::internalError(asyncResp->res);
30085b61b5e8SJason M. Bills                 return;
30095b61b5e8SJason M. Bills             }
30105b61b5e8SJason M. Bills             messages::success(asyncResp->res);
30115b61b5e8SJason M. Bills         },
3012002d39b4SEd Tanous             crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
30137e860f15SJohn Edward Broadbent     });
30145b61b5e8SJason M. Bills }
30155b61b5e8SJason M. Bills 
30168d1b46d7Szhanghch05 static void
30178d1b46d7Szhanghch05     logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
30188d1b46d7Szhanghch05                       const std::string& logID, nlohmann::json& logEntryJson)
3019e855dd28SJason M. Bills {
3020043a0536SJohnathan Mantey     auto getStoredLogCallback =
3021b9d36b47SEd Tanous         [asyncResp, logID,
30225e7e2dc5SEd Tanous          &logEntryJson](const boost::system::error_code& ec,
3023b9d36b47SEd Tanous                         const dbus::utility::DBusPropertiesMap& params) {
3024e855dd28SJason M. Bills         if (ec)
3025e855dd28SJason M. Bills         {
302662598e31SEd Tanous             BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
30271ddcf01aSJason M. Bills             if (ec.value() ==
30281ddcf01aSJason M. Bills                 boost::system::linux_error::bad_request_descriptor)
30291ddcf01aSJason M. Bills             {
3030002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
30311ddcf01aSJason M. Bills             }
30321ddcf01aSJason M. Bills             else
30331ddcf01aSJason M. Bills             {
3034e855dd28SJason M. Bills                 messages::internalError(asyncResp->res);
30351ddcf01aSJason M. Bills             }
3036e855dd28SJason M. Bills             return;
3037e855dd28SJason M. Bills         }
3038043a0536SJohnathan Mantey 
3039043a0536SJohnathan Mantey         std::string timestamp{};
3040043a0536SJohnathan Mantey         std::string filename{};
3041043a0536SJohnathan Mantey         std::string logfile{};
30422c70f800SEd Tanous         parseCrashdumpParameters(params, filename, timestamp, logfile);
3043043a0536SJohnathan Mantey 
3044043a0536SJohnathan Mantey         if (filename.empty() || timestamp.empty())
3045e855dd28SJason M. Bills         {
30469db4ba25SJiaqing Zhao             messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
3047e855dd28SJason M. Bills             return;
3048e855dd28SJason M. Bills         }
3049e855dd28SJason M. Bills 
3050043a0536SJohnathan Mantey         std::string crashdumpURI =
3051253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/",
3052253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME) +
3053043a0536SJohnathan Mantey             logID + "/" + filename;
305484afc48bSJason M. Bills         nlohmann::json::object_t logEntry;
30559c11a172SVijay Lobo         logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
3056ef4c65b7SEd Tanous         logEntry["@odata.id"] = boost::urls::format(
3057253f11b8SEd Tanous             "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}",
3058253f11b8SEd Tanous             BMCWEB_REDFISH_SYSTEM_URI_NAME, logID);
305984afc48bSJason M. Bills         logEntry["Name"] = "CPU Crashdump";
306084afc48bSJason M. Bills         logEntry["Id"] = logID;
3061539d8c6bSEd Tanous         logEntry["EntryType"] = log_entry::LogEntryType::Oem;
306284afc48bSJason M. Bills         logEntry["AdditionalDataURI"] = std::move(crashdumpURI);
306384afc48bSJason M. Bills         logEntry["DiagnosticDataType"] = "OEM";
306484afc48bSJason M. Bills         logEntry["OEMDiagnosticDataType"] = "PECICrashdump";
306584afc48bSJason M. Bills         logEntry["Created"] = std::move(timestamp);
30662b20ef6eSJason M. Bills 
30672b20ef6eSJason M. Bills         // If logEntryJson references an array of LogEntry resources
30682b20ef6eSJason M. Bills         // ('Members' list), then push this as a new entry, otherwise set it
30692b20ef6eSJason M. Bills         // directly
30702b20ef6eSJason M. Bills         if (logEntryJson.is_array())
30712b20ef6eSJason M. Bills         {
30722b20ef6eSJason M. Bills             logEntryJson.push_back(logEntry);
30732b20ef6eSJason M. Bills             asyncResp->res.jsonValue["Members@odata.count"] =
30742b20ef6eSJason M. Bills                 logEntryJson.size();
30752b20ef6eSJason M. Bills         }
30762b20ef6eSJason M. Bills         else
30772b20ef6eSJason M. Bills         {
3078d405bb51SJason M. Bills             logEntryJson.update(logEntry);
30792b20ef6eSJason M. Bills         }
3080e855dd28SJason M. Bills     };
3081d1bde9e5SKrzysztof Grobelny     sdbusplus::asio::getAllProperties(
3082d1bde9e5SKrzysztof Grobelny         *crow::connections::systemBus, crashdumpObject,
3083d1bde9e5SKrzysztof Grobelny         crashdumpPath + std::string("/") + logID, crashdumpInterface,
3084d1bde9e5SKrzysztof Grobelny         std::move(getStoredLogCallback));
3085e855dd28SJason M. Bills }
3086e855dd28SJason M. Bills 
30877e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app)
30881da66f75SEd Tanous {
30893946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
30903946028dSAppaRao Puli     // method for security reasons.
30911da66f75SEd Tanous     /**
30921da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
30931da66f75SEd Tanous      */
30947e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
309522d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/")
3096ed398213SEd Tanous         // This is incorrect, should be.
3097ed398213SEd Tanous         //.privileges(redfish::privileges::postLogEntryCollection)
3098432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
3099002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
3100002d39b4SEd Tanous             [&app](const crow::Request& req,
310122d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
310222d268cbSEd Tanous                    const std::string& systemName) {
31033ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
310445ca1b86SEd Tanous         {
310545ca1b86SEd Tanous             return;
310645ca1b86SEd Tanous         }
310725b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
31087f3e84a1SEd Tanous         {
31097f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
31107f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
31117f3e84a1SEd Tanous                                        systemName);
31127f3e84a1SEd Tanous             return;
31137f3e84a1SEd Tanous         }
3114253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
311522d268cbSEd Tanous         {
311622d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
311722d268cbSEd Tanous                                        systemName);
311822d268cbSEd Tanous             return;
311922d268cbSEd Tanous         }
312022d268cbSEd Tanous 
31217a1dbc48SGeorge Liu         constexpr std::array<std::string_view, 1> interfaces = {
31227a1dbc48SGeorge Liu             crashdumpInterface};
31237a1dbc48SGeorge Liu         dbus::utility::getSubTreePaths(
31247a1dbc48SGeorge Liu             "/", 0, interfaces,
31257a1dbc48SGeorge Liu             [asyncResp](const boost::system::error_code& ec,
31262b20ef6eSJason M. Bills                         const std::vector<std::string>& resp) {
31271da66f75SEd Tanous             if (ec)
31281da66f75SEd Tanous             {
31291da66f75SEd Tanous                 if (ec.value() !=
31301da66f75SEd Tanous                     boost::system::errc::no_such_file_or_directory)
31311da66f75SEd Tanous                 {
313262598e31SEd Tanous                     BMCWEB_LOG_DEBUG("failed to get entries ec: {}",
313362598e31SEd Tanous                                      ec.message());
3134f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
31351da66f75SEd Tanous                     return;
31361da66f75SEd Tanous                 }
31371da66f75SEd Tanous             }
3138e1f26343SJason M. Bills             asyncResp->res.jsonValue["@odata.type"] =
31391da66f75SEd Tanous                 "#LogEntryCollection.LogEntryCollection";
3140253f11b8SEd Tanous             asyncResp->res.jsonValue["@odata.id"] = std::format(
3141253f11b8SEd Tanous                 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
3142253f11b8SEd Tanous                 BMCWEB_REDFISH_SYSTEM_URI_NAME);
3143002d39b4SEd Tanous             asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
3144e1f26343SJason M. Bills             asyncResp->res.jsonValue["Description"] =
3145424c4176SJason M. Bills                 "Collection of Crashdump Entries";
3146002d39b4SEd Tanous             asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3147a2dd60a6SBrandon Kim             asyncResp->res.jsonValue["Members@odata.count"] = 0;
31482b20ef6eSJason M. Bills 
31492b20ef6eSJason M. Bills             for (const std::string& path : resp)
31501da66f75SEd Tanous             {
31512b20ef6eSJason M. Bills                 const sdbusplus::message::object_path objPath(path);
3152e855dd28SJason M. Bills                 // Get the log ID
31532b20ef6eSJason M. Bills                 std::string logID = objPath.filename();
31542b20ef6eSJason M. Bills                 if (logID.empty())
31551da66f75SEd Tanous                 {
3156e855dd28SJason M. Bills                     continue;
31571da66f75SEd Tanous                 }
3158e855dd28SJason M. Bills                 // Add the log entry to the array
31592b20ef6eSJason M. Bills                 logCrashdumpEntry(asyncResp, logID,
31602b20ef6eSJason M. Bills                                   asyncResp->res.jsonValue["Members"]);
31611da66f75SEd Tanous             }
31627a1dbc48SGeorge Liu         });
31637e860f15SJohn Edward Broadbent     });
31641da66f75SEd Tanous }
31651da66f75SEd Tanous 
31667e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app)
31671da66f75SEd Tanous {
31683946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
31693946028dSAppaRao Puli     // method for security reasons.
31701da66f75SEd Tanous 
31717e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
317222d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/")
3173ed398213SEd Tanous         // this is incorrect, should be
3174ed398213SEd Tanous         // .privileges(redfish::privileges::getLogEntry)
3175432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
31767e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
317745ca1b86SEd Tanous             [&app](const crow::Request& req,
31787e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
317922d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
31803ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
318145ca1b86SEd Tanous         {
318245ca1b86SEd Tanous             return;
318345ca1b86SEd Tanous         }
318425b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
31857f3e84a1SEd Tanous         {
31867f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
31877f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
31887f3e84a1SEd Tanous                                        systemName);
31897f3e84a1SEd Tanous             return;
31907f3e84a1SEd Tanous         }
3191253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
319222d268cbSEd Tanous         {
319322d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
319422d268cbSEd Tanous                                        systemName);
319522d268cbSEd Tanous             return;
319622d268cbSEd Tanous         }
31977e860f15SJohn Edward Broadbent         const std::string& logID = param;
3198e855dd28SJason M. Bills         logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
31997e860f15SJohn Edward Broadbent     });
3200e855dd28SJason M. Bills }
3201e855dd28SJason M. Bills 
32027e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app)
3203e855dd28SJason M. Bills {
32043946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
32053946028dSAppaRao Puli     // method for security reasons.
32067e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
32077e860f15SJohn Edward Broadbent         app,
320822d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/")
3209ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
32107e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
3211a4ce114aSNan Zhou             [](const crow::Request& req,
32127e860f15SJohn Edward Broadbent                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
321322d268cbSEd Tanous                const std::string& systemName, const std::string& logID,
321422d268cbSEd Tanous                const std::string& fileName) {
32152a9beeedSShounak Mitra         // Do not call getRedfishRoute here since the crashdump file is not a
32162a9beeedSShounak Mitra         // Redfish resource.
321722d268cbSEd Tanous 
321825b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
32197f3e84a1SEd Tanous         {
32207f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
32217f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
32227f3e84a1SEd Tanous                                        systemName);
32237f3e84a1SEd Tanous             return;
32247f3e84a1SEd Tanous         }
3225253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
322622d268cbSEd Tanous         {
322722d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
322822d268cbSEd Tanous                                        systemName);
322922d268cbSEd Tanous             return;
323022d268cbSEd Tanous         }
323122d268cbSEd Tanous 
3232043a0536SJohnathan Mantey         auto getStoredLogCallback =
323339662a3bSEd Tanous             [asyncResp, logID, fileName, url(boost::urls::url(req.url()))](
32345e7e2dc5SEd Tanous                 const boost::system::error_code& ec,
3235002d39b4SEd Tanous                 const std::vector<
3236002d39b4SEd Tanous                     std::pair<std::string, dbus::utility::DbusVariantType>>&
32377e860f15SJohn Edward Broadbent                     resp) {
32381da66f75SEd Tanous             if (ec)
32391da66f75SEd Tanous             {
324062598e31SEd Tanous                 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
3241f12894f8SJason M. Bills                 messages::internalError(asyncResp->res);
32421da66f75SEd Tanous                 return;
32431da66f75SEd Tanous             }
3244e855dd28SJason M. Bills 
3245043a0536SJohnathan Mantey             std::string dbusFilename{};
3246043a0536SJohnathan Mantey             std::string dbusTimestamp{};
3247043a0536SJohnathan Mantey             std::string dbusFilepath{};
3248043a0536SJohnathan Mantey 
3249002d39b4SEd Tanous             parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
3250002d39b4SEd Tanous                                      dbusFilepath);
3251043a0536SJohnathan Mantey 
3252043a0536SJohnathan Mantey             if (dbusFilename.empty() || dbusTimestamp.empty() ||
3253043a0536SJohnathan Mantey                 dbusFilepath.empty())
32541da66f75SEd Tanous             {
32559db4ba25SJiaqing Zhao                 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
32561da66f75SEd Tanous                 return;
32571da66f75SEd Tanous             }
3258e855dd28SJason M. Bills 
3259043a0536SJohnathan Mantey             // Verify the file name parameter is correct
3260043a0536SJohnathan Mantey             if (fileName != dbusFilename)
3261043a0536SJohnathan Mantey             {
32629db4ba25SJiaqing Zhao                 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
3263043a0536SJohnathan Mantey                 return;
3264043a0536SJohnathan Mantey             }
3265043a0536SJohnathan Mantey 
326627b0cf90SEd Tanous             if (!asyncResp->res.openFile(dbusFilepath))
3267043a0536SJohnathan Mantey             {
32689db4ba25SJiaqing Zhao                 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
3269043a0536SJohnathan Mantey                 return;
3270043a0536SJohnathan Mantey             }
3271043a0536SJohnathan Mantey 
32727e860f15SJohn Edward Broadbent             // Configure this to be a file download when accessed
32737e860f15SJohn Edward Broadbent             // from a browser
3274d9f6c621SEd Tanous             asyncResp->res.addHeader(
3275d9f6c621SEd Tanous                 boost::beast::http::field::content_disposition, "attachment");
32761da66f75SEd Tanous         };
3277d1bde9e5SKrzysztof Grobelny         sdbusplus::asio::getAllProperties(
3278d1bde9e5SKrzysztof Grobelny             *crow::connections::systemBus, crashdumpObject,
3279d1bde9e5SKrzysztof Grobelny             crashdumpPath + std::string("/") + logID, crashdumpInterface,
3280d1bde9e5SKrzysztof Grobelny             std::move(getStoredLogCallback));
32817e860f15SJohn Edward Broadbent     });
32821da66f75SEd Tanous }
32831da66f75SEd Tanous 
3284c5a4c82aSJason M. Bills enum class OEMDiagnosticType
3285c5a4c82aSJason M. Bills {
3286c5a4c82aSJason M. Bills     onDemand,
3287c5a4c82aSJason M. Bills     telemetry,
3288c5a4c82aSJason M. Bills     invalid,
3289c5a4c82aSJason M. Bills };
3290c5a4c82aSJason M. Bills 
329126ccae32SEd Tanous inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr)
3292c5a4c82aSJason M. Bills {
3293c5a4c82aSJason M. Bills     if (oemDiagStr == "OnDemand")
3294c5a4c82aSJason M. Bills     {
3295c5a4c82aSJason M. Bills         return OEMDiagnosticType::onDemand;
3296c5a4c82aSJason M. Bills     }
3297c5a4c82aSJason M. Bills     if (oemDiagStr == "Telemetry")
3298c5a4c82aSJason M. Bills     {
3299c5a4c82aSJason M. Bills         return OEMDiagnosticType::telemetry;
3300c5a4c82aSJason M. Bills     }
3301c5a4c82aSJason M. Bills 
3302c5a4c82aSJason M. Bills     return OEMDiagnosticType::invalid;
3303c5a4c82aSJason M. Bills }
3304c5a4c82aSJason M. Bills 
33057e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app)
33061da66f75SEd Tanous {
33073946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
33083946028dSAppaRao Puli     // method for security reasons.
33090fda0f12SGeorge Liu     BMCWEB_ROUTE(
33100fda0f12SGeorge Liu         app,
331122d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/")
3312ed398213SEd Tanous         // The below is incorrect;  Should be ConfigureManager
3313ed398213SEd Tanous         //.privileges(redfish::privileges::postLogService)
3314432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
3315002d39b4SEd Tanous         .methods(boost::beast::http::verb::post)(
3316002d39b4SEd Tanous             [&app](const crow::Request& req,
331722d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
331822d268cbSEd Tanous                    const std::string& systemName) {
33193ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
332045ca1b86SEd Tanous         {
332145ca1b86SEd Tanous             return;
332245ca1b86SEd Tanous         }
332322d268cbSEd Tanous 
332425b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
33257f3e84a1SEd Tanous         {
33267f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
33277f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
33287f3e84a1SEd Tanous                                        systemName);
33297f3e84a1SEd Tanous             return;
33307f3e84a1SEd Tanous         }
3331253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
333222d268cbSEd Tanous         {
333322d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
333422d268cbSEd Tanous                                        systemName);
333522d268cbSEd Tanous             return;
333622d268cbSEd Tanous         }
333722d268cbSEd Tanous 
33388e6c099aSJason M. Bills         std::string diagnosticDataType;
33398e6c099aSJason M. Bills         std::string oemDiagnosticDataType;
334015ed6780SWilly Tu         if (!redfish::json_util::readJsonAction(
3341002d39b4SEd Tanous                 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
3342002d39b4SEd Tanous                 "OEMDiagnosticDataType", oemDiagnosticDataType))
33438e6c099aSJason M. Bills         {
33448e6c099aSJason M. Bills             return;
33458e6c099aSJason M. Bills         }
33468e6c099aSJason M. Bills 
33478e6c099aSJason M. Bills         if (diagnosticDataType != "OEM")
33488e6c099aSJason M. Bills         {
334962598e31SEd Tanous             BMCWEB_LOG_ERROR(
335062598e31SEd Tanous                 "Only OEM DiagnosticDataType supported for Crashdump");
33518e6c099aSJason M. Bills             messages::actionParameterValueFormatError(
33528e6c099aSJason M. Bills                 asyncResp->res, diagnosticDataType, "DiagnosticDataType",
33538e6c099aSJason M. Bills                 "CollectDiagnosticData");
33548e6c099aSJason M. Bills             return;
33558e6c099aSJason M. Bills         }
33568e6c099aSJason M. Bills 
3357c5a4c82aSJason M. Bills         OEMDiagnosticType oemDiagType =
3358c5a4c82aSJason M. Bills             getOEMDiagnosticType(oemDiagnosticDataType);
3359c5a4c82aSJason M. Bills 
3360c5a4c82aSJason M. Bills         std::string iface;
3361c5a4c82aSJason M. Bills         std::string method;
3362c5a4c82aSJason M. Bills         std::string taskMatchStr;
3363c5a4c82aSJason M. Bills         if (oemDiagType == OEMDiagnosticType::onDemand)
3364c5a4c82aSJason M. Bills         {
3365c5a4c82aSJason M. Bills             iface = crashdumpOnDemandInterface;
3366c5a4c82aSJason M. Bills             method = "GenerateOnDemandLog";
3367c5a4c82aSJason M. Bills             taskMatchStr = "type='signal',"
3368c5a4c82aSJason M. Bills                            "interface='org.freedesktop.DBus.Properties',"
3369c5a4c82aSJason M. Bills                            "member='PropertiesChanged',"
3370c5a4c82aSJason M. Bills                            "arg0namespace='com.intel.crashdump'";
3371c5a4c82aSJason M. Bills         }
3372c5a4c82aSJason M. Bills         else if (oemDiagType == OEMDiagnosticType::telemetry)
3373c5a4c82aSJason M. Bills         {
3374c5a4c82aSJason M. Bills             iface = crashdumpTelemetryInterface;
3375c5a4c82aSJason M. Bills             method = "GenerateTelemetryLog";
3376c5a4c82aSJason M. Bills             taskMatchStr = "type='signal',"
3377c5a4c82aSJason M. Bills                            "interface='org.freedesktop.DBus.Properties',"
3378c5a4c82aSJason M. Bills                            "member='PropertiesChanged',"
3379c5a4c82aSJason M. Bills                            "arg0namespace='com.intel.crashdump'";
3380c5a4c82aSJason M. Bills         }
3381c5a4c82aSJason M. Bills         else
3382c5a4c82aSJason M. Bills         {
338362598e31SEd Tanous             BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}",
338462598e31SEd Tanous                              oemDiagnosticDataType);
3385c5a4c82aSJason M. Bills             messages::actionParameterValueFormatError(
3386002d39b4SEd Tanous                 asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType",
3387002d39b4SEd Tanous                 "CollectDiagnosticData");
3388c5a4c82aSJason M. Bills             return;
3389c5a4c82aSJason M. Bills         }
3390c5a4c82aSJason M. Bills 
3391c5a4c82aSJason M. Bills         auto collectCrashdumpCallback =
3392c5a4c82aSJason M. Bills             [asyncResp, payload(task::Payload(req)),
33935e7e2dc5SEd Tanous              taskMatchStr](const boost::system::error_code& ec,
339498be3e39SEd Tanous                            const std::string&) mutable {
33951da66f75SEd Tanous             if (ec)
33961da66f75SEd Tanous             {
3397002d39b4SEd Tanous                 if (ec.value() == boost::system::errc::operation_not_supported)
33981da66f75SEd Tanous                 {
3399f12894f8SJason M. Bills                     messages::resourceInStandby(asyncResp->res);
34001da66f75SEd Tanous                 }
34014363d3b2SJason M. Bills                 else if (ec.value() ==
34024363d3b2SJason M. Bills                          boost::system::errc::device_or_resource_busy)
34034363d3b2SJason M. Bills                 {
3404002d39b4SEd Tanous                     messages::serviceTemporarilyUnavailable(asyncResp->res,
3405002d39b4SEd Tanous                                                             "60");
34064363d3b2SJason M. Bills                 }
34071da66f75SEd Tanous                 else
34081da66f75SEd Tanous                 {
3409f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
34101da66f75SEd Tanous                 }
34111da66f75SEd Tanous                 return;
34121da66f75SEd Tanous             }
3413002d39b4SEd Tanous             std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
34148b24275dSEd Tanous                 [](const boost::system::error_code& ec2, sdbusplus::message_t&,
3415002d39b4SEd Tanous                    const std::shared_ptr<task::TaskData>& taskData) {
34168b24275dSEd Tanous                 if (!ec2)
341766afe4faSJames Feist                 {
3418002d39b4SEd Tanous                     taskData->messages.emplace_back(messages::taskCompletedOK(
3419e5d5006bSJames Feist                         std::to_string(taskData->index)));
3420831d6b09SJames Feist                     taskData->state = "Completed";
342166afe4faSJames Feist                 }
342232898ceaSJames Feist                 return task::completed;
342366afe4faSJames Feist             },
3424c5a4c82aSJason M. Bills                 taskMatchStr);
3425c5a4c82aSJason M. Bills 
342646229577SJames Feist             task->startTimer(std::chrono::minutes(5));
342746229577SJames Feist             task->populateResp(asyncResp->res);
342898be3e39SEd Tanous             task->payload.emplace(std::move(payload));
34291da66f75SEd Tanous         };
34308e6c099aSJason M. Bills 
34311da66f75SEd Tanous         crow::connections::systemBus->async_method_call(
3432002d39b4SEd Tanous             std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath,
3433002d39b4SEd Tanous             iface, method);
34347e860f15SJohn Edward Broadbent     });
34356eda7685SKenny L. Ku }
34366eda7685SKenny L. Ku 
3437cb92c03bSAndrew Geissler /**
3438cb92c03bSAndrew Geissler  * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3439cb92c03bSAndrew Geissler  */
34407e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app)
3441cb92c03bSAndrew Geissler {
3442cb92c03bSAndrew Geissler     /**
3443cb92c03bSAndrew Geissler      * Function handles POST method request.
3444cb92c03bSAndrew Geissler      * The Clear Log actions does not require any parameter.The action deletes
3445cb92c03bSAndrew Geissler      * all entries found in the Entries collection for this Log Service.
3446cb92c03bSAndrew Geissler      */
34477e860f15SJohn Edward Broadbent 
34480fda0f12SGeorge Liu     BMCWEB_ROUTE(
34490fda0f12SGeorge Liu         app,
345022d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
3451ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
34527e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
345345ca1b86SEd Tanous             [&app](const crow::Request& req,
345422d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
345522d268cbSEd Tanous                    const std::string& systemName) {
34563ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
345745ca1b86SEd Tanous         {
345845ca1b86SEd Tanous             return;
345945ca1b86SEd Tanous         }
346025b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
34617f3e84a1SEd Tanous         {
34627f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
34637f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
34647f3e84a1SEd Tanous                                        systemName);
34657f3e84a1SEd Tanous             return;
34667f3e84a1SEd Tanous         }
3467253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
346822d268cbSEd Tanous         {
346922d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
347022d268cbSEd Tanous                                        systemName);
347122d268cbSEd Tanous             return;
347222d268cbSEd Tanous         }
347362598e31SEd Tanous         BMCWEB_LOG_DEBUG("Do delete all entries.");
3474cb92c03bSAndrew Geissler 
3475cb92c03bSAndrew Geissler         // Process response from Logging service.
34765e7e2dc5SEd Tanous         auto respHandler = [asyncResp](const boost::system::error_code& ec) {
347762598e31SEd Tanous             BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done");
3478cb92c03bSAndrew Geissler             if (ec)
3479cb92c03bSAndrew Geissler             {
3480cb92c03bSAndrew Geissler                 // TODO Handle for specific error code
348162598e31SEd Tanous                 BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec);
3482cb92c03bSAndrew Geissler                 asyncResp->res.result(
3483cb92c03bSAndrew Geissler                     boost::beast::http::status::internal_server_error);
3484cb92c03bSAndrew Geissler                 return;
3485cb92c03bSAndrew Geissler             }
3486cb92c03bSAndrew Geissler 
3487002d39b4SEd Tanous             asyncResp->res.result(boost::beast::http::status::no_content);
3488cb92c03bSAndrew Geissler         };
3489cb92c03bSAndrew Geissler 
3490cb92c03bSAndrew Geissler         // Make call to Logging service to request Clear Log
3491cb92c03bSAndrew Geissler         crow::connections::systemBus->async_method_call(
34922c70f800SEd Tanous             respHandler, "xyz.openbmc_project.Logging",
3493cb92c03bSAndrew Geissler             "/xyz/openbmc_project/logging",
3494cb92c03bSAndrew Geissler             "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
34957e860f15SJohn Edward Broadbent     });
3496cb92c03bSAndrew Geissler }
3497a3316fc6SZhikuiRen 
3498a3316fc6SZhikuiRen /****************************************************
3499a3316fc6SZhikuiRen  * Redfish PostCode interfaces
3500a3316fc6SZhikuiRen  * using DBUS interface: getPostCodesTS
3501a3316fc6SZhikuiRen  ******************************************************/
35027e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app)
3503a3316fc6SZhikuiRen {
350422d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/")
3505ed398213SEd Tanous         .privileges(redfish::privileges::getLogService)
3506002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
3507002d39b4SEd Tanous             [&app](const crow::Request& req,
350822d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
350922d268cbSEd Tanous                    const std::string& systemName) {
35103ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
351145ca1b86SEd Tanous         {
351245ca1b86SEd Tanous             return;
351345ca1b86SEd Tanous         }
351425b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
35157f3e84a1SEd Tanous         {
35167f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
35177f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
35187f3e84a1SEd Tanous                                        systemName);
35197f3e84a1SEd Tanous             return;
35207f3e84a1SEd Tanous         }
3521253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
352222d268cbSEd Tanous         {
352322d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
352422d268cbSEd Tanous                                        systemName);
352522d268cbSEd Tanous             return;
352622d268cbSEd Tanous         }
35271476687dSEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
3528253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/PostCodes",
3529253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
35301476687dSEd Tanous         asyncResp->res.jsonValue["@odata.type"] =
3531b25644a1SJanet Adkins             "#LogService.v1_2_0.LogService";
35321476687dSEd Tanous         asyncResp->res.jsonValue["Name"] = "POST Code Log Service";
35331476687dSEd Tanous         asyncResp->res.jsonValue["Description"] = "POST Code Log Service";
3534ed34a4adSEd Tanous         asyncResp->res.jsonValue["Id"] = "PostCodes";
3535539d8c6bSEd Tanous         asyncResp->res.jsonValue["OverWritePolicy"] =
3536539d8c6bSEd Tanous             log_service::OverWritePolicy::WrapsWhenFull;
35371476687dSEd Tanous         asyncResp->res.jsonValue["Entries"]["@odata.id"] =
3538253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries",
3539253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
35407c8c4058STejas Patil 
35417c8c4058STejas Patil         std::pair<std::string, std::string> redfishDateTimeOffset =
35422b82937eSEd Tanous             redfish::time_utils::getDateTimeOffsetNow();
35430fda0f12SGeorge Liu         asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
35447c8c4058STejas Patil         asyncResp->res.jsonValue["DateTimeLocalOffset"] =
35457c8c4058STejas Patil             redfishDateTimeOffset.second;
35467c8c4058STejas Patil 
354720fa6a2cSEd Tanous         asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
354820fa6a2cSEd Tanous                                 ["target"] = std::format(
3549253f11b8SEd Tanous             "/redfish/v1/Systems/{}/LogServices/PostCodes/Actions/LogService.ClearLog",
355020fa6a2cSEd Tanous             BMCWEB_REDFISH_SYSTEM_URI_NAME);
35517e860f15SJohn Edward Broadbent     });
3552a3316fc6SZhikuiRen }
3553a3316fc6SZhikuiRen 
35547e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app)
3555a3316fc6SZhikuiRen {
35560fda0f12SGeorge Liu     BMCWEB_ROUTE(
35570fda0f12SGeorge Liu         app,
355822d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/")
3559ed398213SEd Tanous         // The following privilege is incorrect;  It should be ConfigureManager
3560ed398213SEd Tanous         //.privileges(redfish::privileges::postLogService)
3561432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
35627e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
356345ca1b86SEd Tanous             [&app](const crow::Request& req,
356422d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
356522d268cbSEd Tanous                    const std::string& systemName) {
35663ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
356745ca1b86SEd Tanous         {
356845ca1b86SEd Tanous             return;
356945ca1b86SEd Tanous         }
357025b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
35717f3e84a1SEd Tanous         {
35727f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
35737f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
35747f3e84a1SEd Tanous                                        systemName);
35757f3e84a1SEd Tanous             return;
35767f3e84a1SEd Tanous         }
3577253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
357822d268cbSEd Tanous         {
357922d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
358022d268cbSEd Tanous                                        systemName);
358122d268cbSEd Tanous             return;
358222d268cbSEd Tanous         }
358362598e31SEd Tanous         BMCWEB_LOG_DEBUG("Do delete all postcodes entries.");
3584a3316fc6SZhikuiRen 
3585a3316fc6SZhikuiRen         // Make call to post-code service to request clear all
3586a3316fc6SZhikuiRen         crow::connections::systemBus->async_method_call(
35875e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec) {
3588a3316fc6SZhikuiRen             if (ec)
3589a3316fc6SZhikuiRen             {
3590a3316fc6SZhikuiRen                 // TODO Handle for specific error code
359162598e31SEd Tanous                 BMCWEB_LOG_ERROR("doClearPostCodes resp_handler got error {}",
359262598e31SEd Tanous                                  ec);
3593002d39b4SEd Tanous                 asyncResp->res.result(
3594002d39b4SEd Tanous                     boost::beast::http::status::internal_server_error);
3595a3316fc6SZhikuiRen                 messages::internalError(asyncResp->res);
3596a3316fc6SZhikuiRen                 return;
3597a3316fc6SZhikuiRen             }
359818fc70c0STony Lee             messages::success(asyncResp->res);
3599a3316fc6SZhikuiRen         },
360015124765SJonathan Doman             "xyz.openbmc_project.State.Boot.PostCode0",
360115124765SJonathan Doman             "/xyz/openbmc_project/State/Boot/PostCode0",
3602a3316fc6SZhikuiRen             "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
36037e860f15SJohn Edward Broadbent     });
3604a3316fc6SZhikuiRen }
3605a3316fc6SZhikuiRen 
36066f284d24SJiaqing Zhao /**
36076f284d24SJiaqing Zhao  * @brief Parse post code ID and get the current value and index value
36086f284d24SJiaqing Zhao  *        eg: postCodeID=B1-2, currentValue=1, index=2
36096f284d24SJiaqing Zhao  *
36106f284d24SJiaqing Zhao  * @param[in]  postCodeID     Post Code ID
36116f284d24SJiaqing Zhao  * @param[out] currentValue   Current value
36126f284d24SJiaqing Zhao  * @param[out] index          Index value
36136f284d24SJiaqing Zhao  *
36146f284d24SJiaqing Zhao  * @return bool true if the parsing is successful, false the parsing fails
36156f284d24SJiaqing Zhao  */
36166f056f24SEd Tanous inline bool parsePostCode(std::string_view postCodeID, uint64_t& currentValue,
3617df254f2cSEd Tanous                           uint16_t& index)
36186f284d24SJiaqing Zhao {
36196f284d24SJiaqing Zhao     std::vector<std::string> split;
362050ebd4afSEd Tanous     bmcweb::split(split, postCodeID, '-');
36216f056f24SEd Tanous     if (split.size() != 2)
36226f056f24SEd Tanous     {
36236f056f24SEd Tanous         return false;
36246f056f24SEd Tanous     }
36256f056f24SEd Tanous     std::string_view postCodeNumber = split[0];
36266f056f24SEd Tanous     if (postCodeNumber.size() < 2)
36276f056f24SEd Tanous     {
36286f056f24SEd Tanous         return false;
36296f056f24SEd Tanous     }
36306f056f24SEd Tanous     if (postCodeNumber[0] != 'B')
36316f056f24SEd Tanous     {
36326f056f24SEd Tanous         return false;
36336f056f24SEd Tanous     }
36346f056f24SEd Tanous     postCodeNumber.remove_prefix(1);
36356f056f24SEd Tanous     auto [ptrIndex, ecIndex] = std::from_chars(postCodeNumber.begin(),
36366f056f24SEd Tanous                                                postCodeNumber.end(), index);
36376f056f24SEd Tanous     if (ptrIndex != postCodeNumber.end() || ecIndex != std::errc())
36386f284d24SJiaqing Zhao     {
36396f284d24SJiaqing Zhao         return false;
36406f284d24SJiaqing Zhao     }
36416f284d24SJiaqing Zhao 
36426f056f24SEd Tanous     std::string_view postCodeIndex = split[1];
36436f284d24SJiaqing Zhao 
36446f056f24SEd Tanous     auto [ptrValue, ecValue] = std::from_chars(
36456f056f24SEd Tanous         postCodeIndex.begin(), postCodeIndex.end(), currentValue);
36466f284d24SJiaqing Zhao 
36476f056f24SEd Tanous     return ptrValue == postCodeIndex.end() && ecValue == std::errc();
36486f284d24SJiaqing Zhao }
36496f284d24SJiaqing Zhao 
36506f284d24SJiaqing Zhao static bool fillPostCodeEntry(
3651ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
36526c9a279eSManojkiran Eda     const boost::container::flat_map<
36536c9a279eSManojkiran Eda         uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode,
3654a3316fc6SZhikuiRen     const uint16_t bootIndex, const uint64_t codeIndex = 0,
3655a3316fc6SZhikuiRen     const uint64_t skip = 0, const uint64_t top = 0)
3656a3316fc6SZhikuiRen {
3657a3316fc6SZhikuiRen     // Get the Message from the MessageRegistry
3658fffb8c1fSEd Tanous     const registries::Message* message =
3659fffb8c1fSEd Tanous         registries::getMessage("OpenBMC.0.2.BIOSPOSTCode");
3660dc8cfa66SEd Tanous     if (message == nullptr)
3661dc8cfa66SEd Tanous     {
3662dc8cfa66SEd Tanous         BMCWEB_LOG_ERROR("Couldn't find known message?");
3663dc8cfa66SEd Tanous         return false;
3664dc8cfa66SEd Tanous     }
3665a3316fc6SZhikuiRen     uint64_t currentCodeIndex = 0;
3666a3316fc6SZhikuiRen     uint64_t firstCodeTimeUs = 0;
36676c9a279eSManojkiran Eda     for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
36686c9a279eSManojkiran Eda              code : postcode)
3669a3316fc6SZhikuiRen     {
3670a3316fc6SZhikuiRen         currentCodeIndex++;
3671a3316fc6SZhikuiRen         std::string postcodeEntryID =
3672a3316fc6SZhikuiRen             "B" + std::to_string(bootIndex) + "-" +
3673a3316fc6SZhikuiRen             std::to_string(currentCodeIndex); // 1 based index in EntryID string
3674a3316fc6SZhikuiRen 
3675a3316fc6SZhikuiRen         uint64_t usecSinceEpoch = code.first;
3676a3316fc6SZhikuiRen         uint64_t usTimeOffset = 0;
3677a3316fc6SZhikuiRen 
3678a3316fc6SZhikuiRen         if (1 == currentCodeIndex)
3679a3316fc6SZhikuiRen         { // already incremented
3680a3316fc6SZhikuiRen             firstCodeTimeUs = code.first;
3681a3316fc6SZhikuiRen         }
3682a3316fc6SZhikuiRen         else
3683a3316fc6SZhikuiRen         {
3684a3316fc6SZhikuiRen             usTimeOffset = code.first - firstCodeTimeUs;
3685a3316fc6SZhikuiRen         }
3686a3316fc6SZhikuiRen 
3687a3316fc6SZhikuiRen         // skip if no specific codeIndex is specified and currentCodeIndex does
3688a3316fc6SZhikuiRen         // not fall between top and skip
3689a3316fc6SZhikuiRen         if ((codeIndex == 0) &&
3690a3316fc6SZhikuiRen             (currentCodeIndex <= skip || currentCodeIndex > top))
3691a3316fc6SZhikuiRen         {
3692a3316fc6SZhikuiRen             continue;
3693a3316fc6SZhikuiRen         }
3694a3316fc6SZhikuiRen 
36954e0453b1SGunnar Mills         // skip if a specific codeIndex is specified and does not match the
3696a3316fc6SZhikuiRen         // currentIndex
3697a3316fc6SZhikuiRen         if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3698a3316fc6SZhikuiRen         {
3699a3316fc6SZhikuiRen             // This is done for simplicity. 1st entry is needed to calculate
3700a3316fc6SZhikuiRen             // time offset. To improve efficiency, one can get to the entry
3701a3316fc6SZhikuiRen             // directly (possibly with flatmap's nth method)
3702a3316fc6SZhikuiRen             continue;
3703a3316fc6SZhikuiRen         }
3704a3316fc6SZhikuiRen 
3705a3316fc6SZhikuiRen         // currentCodeIndex is within top and skip or equal to specified code
3706a3316fc6SZhikuiRen         // index
3707a3316fc6SZhikuiRen 
3708a3316fc6SZhikuiRen         // Get the Created time from the timestamp
3709a3316fc6SZhikuiRen         std::string entryTimeStr;
37102a025611SKonstantin Aladyshev         entryTimeStr = redfish::time_utils::getDateTimeUintUs(usecSinceEpoch);
3711a3316fc6SZhikuiRen 
3712a3316fc6SZhikuiRen         // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3713a3316fc6SZhikuiRen         std::ostringstream hexCode;
3714a3316fc6SZhikuiRen         hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
37156c9a279eSManojkiran Eda                 << std::get<0>(code.second);
3716a3316fc6SZhikuiRen         std::ostringstream timeOffsetStr;
3717a3316fc6SZhikuiRen         // Set Fixed -Point Notation
3718a3316fc6SZhikuiRen         timeOffsetStr << std::fixed;
3719a3316fc6SZhikuiRen         // Set precision to 4 digits
3720a3316fc6SZhikuiRen         timeOffsetStr << std::setprecision(4);
3721a3316fc6SZhikuiRen         // Add double to stream
3722a3316fc6SZhikuiRen         timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3723a3316fc6SZhikuiRen 
37241e6deaf6SEd Tanous         std::string bootIndexStr = std::to_string(bootIndex);
37251e6deaf6SEd Tanous         std::string timeOffsetString = timeOffsetStr.str();
37261e6deaf6SEd Tanous         std::string hexCodeStr = hexCode.str();
3727a3316fc6SZhikuiRen 
37281e6deaf6SEd Tanous         std::array<std::string_view, 3> messageArgs = {
37291e6deaf6SEd Tanous             bootIndexStr, timeOffsetString, hexCodeStr};
37301e6deaf6SEd Tanous 
37311e6deaf6SEd Tanous         std::string msg =
37321e6deaf6SEd Tanous             redfish::registries::fillMessageArgs(messageArgs, message->message);
37331e6deaf6SEd Tanous         if (msg.empty())
3734a3316fc6SZhikuiRen         {
37351e6deaf6SEd Tanous             messages::internalError(asyncResp->res);
37361e6deaf6SEd Tanous             return false;
3737a3316fc6SZhikuiRen         }
3738a3316fc6SZhikuiRen 
3739d4342a92STim Lee         // Get Severity template from message registry
3740d4342a92STim Lee         std::string severity;
3741d4342a92STim Lee         if (message != nullptr)
3742d4342a92STim Lee         {
37435f2b84eeSEd Tanous             severity = message->messageSeverity;
3744d4342a92STim Lee         }
3745d4342a92STim Lee 
37466f284d24SJiaqing Zhao         // Format entry
37476f284d24SJiaqing Zhao         nlohmann::json::object_t bmcLogEntry;
37489c11a172SVijay Lobo         bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
3749ef4c65b7SEd Tanous         bmcLogEntry["@odata.id"] = boost::urls::format(
3750253f11b8SEd Tanous             "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/{}",
3751253f11b8SEd Tanous             BMCWEB_REDFISH_SYSTEM_URI_NAME, postcodeEntryID);
375284afc48bSJason M. Bills         bmcLogEntry["Name"] = "POST Code Log Entry";
375384afc48bSJason M. Bills         bmcLogEntry["Id"] = postcodeEntryID;
375484afc48bSJason M. Bills         bmcLogEntry["Message"] = std::move(msg);
375584afc48bSJason M. Bills         bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode";
37561e6deaf6SEd Tanous         bmcLogEntry["MessageArgs"] = messageArgs;
375784afc48bSJason M. Bills         bmcLogEntry["EntryType"] = "Event";
375884afc48bSJason M. Bills         bmcLogEntry["Severity"] = std::move(severity);
375984afc48bSJason M. Bills         bmcLogEntry["Created"] = entryTimeStr;
3760647b3cdcSGeorge Liu         if (!std::get<std::vector<uint8_t>>(code.second).empty())
3761647b3cdcSGeorge Liu         {
3762647b3cdcSGeorge Liu             bmcLogEntry["AdditionalDataURI"] =
3763253f11b8SEd Tanous                 std::format(
3764253f11b8SEd Tanous                     "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/",
3765253f11b8SEd Tanous                     BMCWEB_REDFISH_SYSTEM_URI_NAME) +
3766647b3cdcSGeorge Liu                 postcodeEntryID + "/attachment";
3767647b3cdcSGeorge Liu         }
37686f284d24SJiaqing Zhao 
37696f284d24SJiaqing Zhao         // codeIndex is only specified when querying single entry, return only
37706f284d24SJiaqing Zhao         // that entry in this case
37716f284d24SJiaqing Zhao         if (codeIndex != 0)
37726f284d24SJiaqing Zhao         {
3773ac106bf6SEd Tanous             asyncResp->res.jsonValue.update(bmcLogEntry);
37746f284d24SJiaqing Zhao             return true;
3775a3316fc6SZhikuiRen         }
37766f284d24SJiaqing Zhao 
3777ac106bf6SEd Tanous         nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
3778b2ba3072SPatrick Williams         logEntryArray.emplace_back(std::move(bmcLogEntry));
37796f284d24SJiaqing Zhao     }
37806f284d24SJiaqing Zhao 
37816f284d24SJiaqing Zhao     // Return value is always false when querying multiple entries
37826f284d24SJiaqing Zhao     return false;
3783a3316fc6SZhikuiRen }
3784a3316fc6SZhikuiRen 
3785ac106bf6SEd Tanous static void
3786ac106bf6SEd Tanous     getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
37876f284d24SJiaqing Zhao                         const std::string& entryId)
3788a3316fc6SZhikuiRen {
37896f284d24SJiaqing Zhao     uint16_t bootIndex = 0;
37906f284d24SJiaqing Zhao     uint64_t codeIndex = 0;
37916f284d24SJiaqing Zhao     if (!parsePostCode(entryId, codeIndex, bootIndex))
37926f284d24SJiaqing Zhao     {
37936f284d24SJiaqing Zhao         // Requested ID was not found
3794ac106bf6SEd Tanous         messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
37956f284d24SJiaqing Zhao         return;
37966f284d24SJiaqing Zhao     }
37976f284d24SJiaqing Zhao 
37986f284d24SJiaqing Zhao     if (bootIndex == 0 || codeIndex == 0)
37996f284d24SJiaqing Zhao     {
38006f284d24SJiaqing Zhao         // 0 is an invalid index
3801ac106bf6SEd Tanous         messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
38026f284d24SJiaqing Zhao         return;
38036f284d24SJiaqing Zhao     }
38046f284d24SJiaqing Zhao 
3805a3316fc6SZhikuiRen     crow::connections::systemBus->async_method_call(
3806ac106bf6SEd Tanous         [asyncResp, entryId, bootIndex,
38075e7e2dc5SEd Tanous          codeIndex](const boost::system::error_code& ec,
38086c9a279eSManojkiran Eda                     const boost::container::flat_map<
38096c9a279eSManojkiran Eda                         uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
38106c9a279eSManojkiran Eda                         postcode) {
3811a3316fc6SZhikuiRen         if (ec)
3812a3316fc6SZhikuiRen         {
381362598e31SEd Tanous             BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error");
3814ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
3815a3316fc6SZhikuiRen             return;
3816a3316fc6SZhikuiRen         }
3817a3316fc6SZhikuiRen 
3818a3316fc6SZhikuiRen         if (postcode.empty())
3819a3316fc6SZhikuiRen         {
3820ac106bf6SEd Tanous             messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
3821a3316fc6SZhikuiRen             return;
3822a3316fc6SZhikuiRen         }
3823a3316fc6SZhikuiRen 
3824ac106bf6SEd Tanous         if (!fillPostCodeEntry(asyncResp, postcode, bootIndex, codeIndex))
38256f284d24SJiaqing Zhao         {
3826ac106bf6SEd Tanous             messages::resourceNotFound(asyncResp->res, "LogEntry", entryId);
38276f284d24SJiaqing Zhao             return;
38286f284d24SJiaqing Zhao         }
3829a3316fc6SZhikuiRen     },
383015124765SJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode0",
383115124765SJonathan Doman         "/xyz/openbmc_project/State/Boot/PostCode0",
3832a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3833a3316fc6SZhikuiRen         bootIndex);
3834a3316fc6SZhikuiRen }
3835a3316fc6SZhikuiRen 
3836ac106bf6SEd Tanous static void
3837ac106bf6SEd Tanous     getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3838ac106bf6SEd Tanous                        const uint16_t bootIndex, const uint16_t bootCount,
3839ac106bf6SEd Tanous                        const uint64_t entryCount, size_t skip, size_t top)
3840a3316fc6SZhikuiRen {
3841a3316fc6SZhikuiRen     crow::connections::systemBus->async_method_call(
3842ac106bf6SEd Tanous         [asyncResp, bootIndex, bootCount, entryCount, skip,
38435e7e2dc5SEd Tanous          top](const boost::system::error_code& ec,
38446c9a279eSManojkiran Eda               const boost::container::flat_map<
38456c9a279eSManojkiran Eda                   uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
38466c9a279eSManojkiran Eda                   postcode) {
3847a3316fc6SZhikuiRen         if (ec)
3848a3316fc6SZhikuiRen         {
384962598e31SEd Tanous             BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error");
3850ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
3851a3316fc6SZhikuiRen             return;
3852a3316fc6SZhikuiRen         }
3853a3316fc6SZhikuiRen 
3854a3316fc6SZhikuiRen         uint64_t endCount = entryCount;
3855a3316fc6SZhikuiRen         if (!postcode.empty())
3856a3316fc6SZhikuiRen         {
3857a3316fc6SZhikuiRen             endCount = entryCount + postcode.size();
38583648c8beSEd Tanous             if (skip < endCount && (top + skip) > entryCount)
3859a3316fc6SZhikuiRen             {
386089492a15SPatrick Williams                 uint64_t thisBootSkip = std::max(static_cast<uint64_t>(skip),
386189492a15SPatrick Williams                                                  entryCount) -
38623648c8beSEd Tanous                                         entryCount;
3863a3316fc6SZhikuiRen                 uint64_t thisBootTop =
38643648c8beSEd Tanous                     std::min(static_cast<uint64_t>(top + skip), endCount) -
38653648c8beSEd Tanous                     entryCount;
3866a3316fc6SZhikuiRen 
3867ac106bf6SEd Tanous                 fillPostCodeEntry(asyncResp, postcode, bootIndex, 0,
3868ac106bf6SEd Tanous                                   thisBootSkip, thisBootTop);
3869a3316fc6SZhikuiRen             }
3870ac106bf6SEd Tanous             asyncResp->res.jsonValue["Members@odata.count"] = endCount;
3871a3316fc6SZhikuiRen         }
3872a3316fc6SZhikuiRen 
3873a3316fc6SZhikuiRen         // continue to previous bootIndex
3874a3316fc6SZhikuiRen         if (bootIndex < bootCount)
3875a3316fc6SZhikuiRen         {
3876ac106bf6SEd Tanous             getPostCodeForBoot(asyncResp, static_cast<uint16_t>(bootIndex + 1),
3877a3316fc6SZhikuiRen                                bootCount, endCount, skip, top);
3878a3316fc6SZhikuiRen         }
387981584abeSJiaqing Zhao         else if (skip + top < endCount)
3880a3316fc6SZhikuiRen         {
3881ac106bf6SEd Tanous             asyncResp->res.jsonValue["Members@odata.nextLink"] =
3882253f11b8SEd Tanous                 std::format(
3883253f11b8SEd Tanous                     "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries?$skip=",
3884253f11b8SEd Tanous                     BMCWEB_REDFISH_SYSTEM_URI_NAME) +
3885a3316fc6SZhikuiRen                 std::to_string(skip + top);
3886a3316fc6SZhikuiRen         }
3887a3316fc6SZhikuiRen     },
388815124765SJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode0",
388915124765SJonathan Doman         "/xyz/openbmc_project/State/Boot/PostCode0",
3890a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3891a3316fc6SZhikuiRen         bootIndex);
3892a3316fc6SZhikuiRen }
3893a3316fc6SZhikuiRen 
38948d1b46d7Szhanghch05 static void
3895ac106bf6SEd Tanous     getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
38963648c8beSEd Tanous                          size_t skip, size_t top)
3897a3316fc6SZhikuiRen {
3898a3316fc6SZhikuiRen     uint64_t entryCount = 0;
38991e1e598dSJonathan Doman     sdbusplus::asio::getProperty<uint16_t>(
39001e1e598dSJonathan Doman         *crow::connections::systemBus,
39011e1e598dSJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode0",
39021e1e598dSJonathan Doman         "/xyz/openbmc_project/State/Boot/PostCode0",
39031e1e598dSJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount",
3904ac106bf6SEd Tanous         [asyncResp, entryCount, skip, top](const boost::system::error_code& ec,
39051e1e598dSJonathan Doman                                            const uint16_t bootCount) {
3906a3316fc6SZhikuiRen         if (ec)
3907a3316fc6SZhikuiRen         {
390862598e31SEd Tanous             BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
3909ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
3910a3316fc6SZhikuiRen             return;
3911a3316fc6SZhikuiRen         }
3912ac106bf6SEd Tanous         getPostCodeForBoot(asyncResp, 1, bootCount, entryCount, skip, top);
39131e1e598dSJonathan Doman     });
3914a3316fc6SZhikuiRen }
3915a3316fc6SZhikuiRen 
39167e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app)
3917a3316fc6SZhikuiRen {
39187e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
391922d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/")
3920ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntryCollection)
39217e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
392245ca1b86SEd Tanous             [&app](const crow::Request& req,
392322d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
392422d268cbSEd Tanous                    const std::string& systemName) {
3925c937d2bfSEd Tanous         query_param::QueryCapabilities capabilities = {
3926c937d2bfSEd Tanous             .canDelegateTop = true,
3927c937d2bfSEd Tanous             .canDelegateSkip = true,
3928c937d2bfSEd Tanous         };
3929c937d2bfSEd Tanous         query_param::Query delegatedQuery;
3930c937d2bfSEd Tanous         if (!redfish::setUpRedfishRouteWithDelegation(
39313ba00073SCarson Labrado                 app, req, asyncResp, delegatedQuery, capabilities))
393245ca1b86SEd Tanous         {
393345ca1b86SEd Tanous             return;
393445ca1b86SEd Tanous         }
393525b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
39367f3e84a1SEd Tanous         {
39377f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
39387f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
39397f3e84a1SEd Tanous                                        systemName);
39407f3e84a1SEd Tanous             return;
39417f3e84a1SEd Tanous         }
394222d268cbSEd Tanous 
3943253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
394422d268cbSEd Tanous         {
394522d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
394622d268cbSEd Tanous                                        systemName);
394722d268cbSEd Tanous             return;
394822d268cbSEd Tanous         }
3949a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.type"] =
3950a3316fc6SZhikuiRen             "#LogEntryCollection.LogEntryCollection";
3951a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.id"] =
3952253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries",
3953253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
3954a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3955a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Description"] =
3956a3316fc6SZhikuiRen             "Collection of POST Code Log Entries";
3957a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3958a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members@odata.count"] = 0;
39593648c8beSEd Tanous         size_t skip = delegatedQuery.skip.value_or(0);
39605143f7a5SJiaqing Zhao         size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
39613648c8beSEd Tanous         getCurrentBootNumber(asyncResp, skip, top);
39627e860f15SJohn Edward Broadbent     });
3963a3316fc6SZhikuiRen }
3964a3316fc6SZhikuiRen 
3965647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app)
3966647b3cdcSGeorge Liu {
39670fda0f12SGeorge Liu     BMCWEB_ROUTE(
39680fda0f12SGeorge Liu         app,
396922d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/")
3970647b3cdcSGeorge Liu         .privileges(redfish::privileges::getLogEntry)
3971647b3cdcSGeorge Liu         .methods(boost::beast::http::verb::get)(
397245ca1b86SEd Tanous             [&app](const crow::Request& req,
3973647b3cdcSGeorge Liu                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
397422d268cbSEd Tanous                    const std::string& systemName,
3975647b3cdcSGeorge Liu                    const std::string& postCodeID) {
39763ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
397745ca1b86SEd Tanous         {
397845ca1b86SEd Tanous             return;
397945ca1b86SEd Tanous         }
398072e21377SMatt Spinler         if (!http_helpers::isContentTypeAllowed(
398199351cd8SEd Tanous                 req.getHeaderValue("Accept"),
39824a0e1a0cSEd Tanous                 http_helpers::ContentType::OctetStream, true))
3983647b3cdcSGeorge Liu         {
3984002d39b4SEd Tanous             asyncResp->res.result(boost::beast::http::status::bad_request);
3985647b3cdcSGeorge Liu             return;
3986647b3cdcSGeorge Liu         }
398725b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
39887f3e84a1SEd Tanous         {
39897f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
39907f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
39917f3e84a1SEd Tanous                                        systemName);
39927f3e84a1SEd Tanous             return;
39937f3e84a1SEd Tanous         }
3994253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
399522d268cbSEd Tanous         {
399622d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
399722d268cbSEd Tanous                                        systemName);
399822d268cbSEd Tanous             return;
399922d268cbSEd Tanous         }
4000647b3cdcSGeorge Liu 
4001647b3cdcSGeorge Liu         uint64_t currentValue = 0;
4002647b3cdcSGeorge Liu         uint16_t index = 0;
4003647b3cdcSGeorge Liu         if (!parsePostCode(postCodeID, currentValue, index))
4004647b3cdcSGeorge Liu         {
4005002d39b4SEd Tanous             messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID);
4006647b3cdcSGeorge Liu             return;
4007647b3cdcSGeorge Liu         }
4008647b3cdcSGeorge Liu 
4009647b3cdcSGeorge Liu         crow::connections::systemBus->async_method_call(
4010647b3cdcSGeorge Liu             [asyncResp, postCodeID, currentValue](
40115e7e2dc5SEd Tanous                 const boost::system::error_code& ec,
4012002d39b4SEd Tanous                 const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>&
4013002d39b4SEd Tanous                     postcodes) {
4014647b3cdcSGeorge Liu             if (ec.value() == EBADR)
4015647b3cdcSGeorge Liu             {
4016002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "LogEntry",
4017002d39b4SEd Tanous                                            postCodeID);
4018647b3cdcSGeorge Liu                 return;
4019647b3cdcSGeorge Liu             }
4020647b3cdcSGeorge Liu             if (ec)
4021647b3cdcSGeorge Liu             {
402262598e31SEd Tanous                 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
4023647b3cdcSGeorge Liu                 messages::internalError(asyncResp->res);
4024647b3cdcSGeorge Liu                 return;
4025647b3cdcSGeorge Liu             }
4026647b3cdcSGeorge Liu 
4027647b3cdcSGeorge Liu             size_t value = static_cast<size_t>(currentValue) - 1;
4028002d39b4SEd Tanous             if (value == std::string::npos || postcodes.size() < currentValue)
4029647b3cdcSGeorge Liu             {
403062598e31SEd Tanous                 BMCWEB_LOG_WARNING("Wrong currentValue value");
4031002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "LogEntry",
4032002d39b4SEd Tanous                                            postCodeID);
4033647b3cdcSGeorge Liu                 return;
4034647b3cdcSGeorge Liu             }
4035647b3cdcSGeorge Liu 
40369eb808c1SEd Tanous             const auto& [tID, c] = postcodes[value];
403746ff87baSEd Tanous             if (c.empty())
4038647b3cdcSGeorge Liu             {
403962598e31SEd Tanous                 BMCWEB_LOG_WARNING("No found post code data");
4040002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "LogEntry",
4041002d39b4SEd Tanous                                            postCodeID);
4042647b3cdcSGeorge Liu                 return;
4043647b3cdcSGeorge Liu             }
404446ff87baSEd Tanous             // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
404546ff87baSEd Tanous             const char* d = reinterpret_cast<const char*>(c.data());
404646ff87baSEd Tanous             std::string_view strData(d, c.size());
4047647b3cdcSGeorge Liu 
4048d9f6c621SEd Tanous             asyncResp->res.addHeader(boost::beast::http::field::content_type,
4049647b3cdcSGeorge Liu                                      "application/octet-stream");
4050d9f6c621SEd Tanous             asyncResp->res.addHeader(
4051d9f6c621SEd Tanous                 boost::beast::http::field::content_transfer_encoding, "Base64");
405227b0cf90SEd Tanous             asyncResp->res.write(crow::utility::base64encode(strData));
4053647b3cdcSGeorge Liu         },
4054647b3cdcSGeorge Liu             "xyz.openbmc_project.State.Boot.PostCode0",
4055647b3cdcSGeorge Liu             "/xyz/openbmc_project/State/Boot/PostCode0",
4056002d39b4SEd Tanous             "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index);
4057647b3cdcSGeorge Liu     });
4058647b3cdcSGeorge Liu }
4059647b3cdcSGeorge Liu 
40607e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app)
4061a3316fc6SZhikuiRen {
40627e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
406322d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/")
4064ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
40657e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
406645ca1b86SEd Tanous             [&app](const crow::Request& req,
40677e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
406822d268cbSEd Tanous                    const std::string& systemName, const std::string& targetID) {
40693ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
407045ca1b86SEd Tanous         {
407145ca1b86SEd Tanous             return;
407245ca1b86SEd Tanous         }
407325b54dbaSEd Tanous         if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
40747f3e84a1SEd Tanous         {
40757f3e84a1SEd Tanous             // Option currently returns no systems.  TBD
40767f3e84a1SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
40777f3e84a1SEd Tanous                                        systemName);
40787f3e84a1SEd Tanous             return;
40797f3e84a1SEd Tanous         }
4080253f11b8SEd Tanous         if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
408122d268cbSEd Tanous         {
408222d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
408322d268cbSEd Tanous                                        systemName);
408422d268cbSEd Tanous             return;
408522d268cbSEd Tanous         }
408622d268cbSEd Tanous 
40876f284d24SJiaqing Zhao         getPostCodeForEntry(asyncResp, targetID);
40887e860f15SJohn Edward Broadbent     });
4089a3316fc6SZhikuiRen }
4090a3316fc6SZhikuiRen 
40911da66f75SEd Tanous } // namespace redfish
4092