xref: /openbmc/bmcweb/features/redfish/lib/log_services.hpp (revision d78572018fc2022091ff8b8eb5a7fef2172ba3d6)
140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
340e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
41da66f75SEd Tanous #pragma once
51da66f75SEd Tanous 
6*d7857201SEd Tanous #include "bmcweb_config.h"
7*d7857201SEd Tanous 
83ccb3adbSEd Tanous #include "app.hpp"
9*d7857201SEd Tanous #include "async_resp.hpp"
10*d7857201SEd Tanous #include "dbus_singleton.hpp"
117a1dbc48SGeorge Liu #include "dbus_utility.hpp"
123ccb3adbSEd Tanous #include "error_messages.hpp"
1368dd075aSAsmitha Karunanithi #include "generated/enums/log_entry.hpp"
14539d8c6bSEd Tanous #include "generated/enums/log_service.hpp"
15*d7857201SEd Tanous #include "http_body.hpp"
16*d7857201SEd Tanous #include "http_request.hpp"
17*d7857201SEd Tanous #include "http_response.hpp"
18647b3cdcSGeorge Liu #include "http_utility.hpp"
19b7028ebfSSpencer Ku #include "human_sort.hpp"
20*d7857201SEd Tanous #include "logging.hpp"
213ccb3adbSEd Tanous #include "query.hpp"
224851d45dSJason M. Bills #include "registries.hpp"
233ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
24*d7857201SEd Tanous #include "str_utility.hpp"
2546229577SJames Feist #include "task.hpp"
265b90429aSEd Tanous #include "task_messages.hpp"
27262dcc1cSAlexander Hansen #include "utils/dbus_event_log_entry.hpp"
283ccb3adbSEd Tanous #include "utils/dbus_utils.hpp"
295b90429aSEd Tanous #include "utils/json_utils.hpp"
30*d7857201SEd Tanous #include "utils/query_param.hpp"
313ccb3adbSEd Tanous #include "utils/time_utils.hpp"
321da66f75SEd Tanous 
33*d7857201SEd Tanous #include <asm-generic/errno.h>
34*d7857201SEd Tanous #include <systemd/sd-bus.h>
358e31778eSAsmitha Karunanithi #include <tinyxml2.h>
36400fd1fbSAdriana Kobylak #include <unistd.h>
37e1f26343SJason M. Bills 
38*d7857201SEd Tanous #include <boost/beast/http/field.hpp>
39*d7857201SEd Tanous #include <boost/beast/http/status.hpp>
4007c8c20dSEd Tanous #include <boost/beast/http/verb.hpp>
411ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp>
42ef4c65b7SEd Tanous #include <boost/url/format.hpp>
43*d7857201SEd Tanous #include <boost/url/url.hpp>
44*d7857201SEd Tanous #include <sdbusplus/message.hpp>
45*d7857201SEd Tanous #include <sdbusplus/message/native_types.hpp>
46d1bde9e5SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp>
471214b7e7SGunnar Mills 
48*d7857201SEd Tanous #include <algorithm>
497a1dbc48SGeorge Liu #include <array>
50*d7857201SEd Tanous #include <chrono>
51b5f288d2SAbhilash Raju #include <cstddef>
52*d7857201SEd Tanous #include <cstdint>
53*d7857201SEd Tanous #include <cstdio>
54*d7857201SEd Tanous #include <ctime>
554418c7f0SJames Feist #include <filesystem>
56*d7857201SEd Tanous #include <format>
57*d7857201SEd Tanous #include <fstream>
58*d7857201SEd Tanous #include <functional>
59*d7857201SEd Tanous #include <iomanip>
6018f8f608SEd Tanous #include <iterator>
61*d7857201SEd Tanous #include <memory>
6275710de2SXiaochao Ma #include <optional>
633544d2a7SEd Tanous #include <ranges>
6426702d01SEd Tanous #include <span>
65*d7857201SEd Tanous #include <sstream>
6618f8f608SEd Tanous #include <string>
67cd225da8SJason M. Bills #include <string_view>
68*d7857201SEd Tanous #include <system_error>
69*d7857201SEd Tanous #include <utility>
70abf2add6SEd Tanous #include <variant>
71*d7857201SEd Tanous #include <vector>
721da66f75SEd Tanous 
731da66f75SEd Tanous namespace redfish
741da66f75SEd Tanous {
751da66f75SEd Tanous 
7689492a15SPatrick Williams constexpr const char* crashdumpObject = "com.intel.crashdump";
7789492a15SPatrick Williams constexpr const char* crashdumpPath = "/com/intel/crashdump";
7889492a15SPatrick Williams constexpr const char* crashdumpInterface = "com.intel.crashdump";
7989492a15SPatrick Williams constexpr const char* deleteAllInterface =
805b61b5e8SJason M. Bills     "xyz.openbmc_project.Collection.DeleteAll";
8189492a15SPatrick Williams constexpr const char* crashdumpOnDemandInterface =
82424c4176SJason M. Bills     "com.intel.crashdump.OnDemand";
8389492a15SPatrick Williams constexpr const char* crashdumpTelemetryInterface =
846eda7685SKenny L. Ku     "com.intel.crashdump.Telemetry";
851da66f75SEd Tanous 
868e31778eSAsmitha Karunanithi enum class DumpCreationProgress
878e31778eSAsmitha Karunanithi {
888e31778eSAsmitha Karunanithi     DUMP_CREATE_SUCCESS,
898e31778eSAsmitha Karunanithi     DUMP_CREATE_FAILED,
908e31778eSAsmitha Karunanithi     DUMP_CREATE_INPROGRESS
918e31778eSAsmitha Karunanithi };
928e31778eSAsmitha Karunanithi 
93cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s)
94cb92c03bSAndrew Geissler {
95d4d25793SEd Tanous     if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
96d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
97d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
98d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
99cb92c03bSAndrew Geissler     {
100cb92c03bSAndrew Geissler         return "Critical";
101cb92c03bSAndrew Geissler     }
1023174e4dfSEd Tanous     if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
103d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
104d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
105cb92c03bSAndrew Geissler     {
106cb92c03bSAndrew Geissler         return "OK";
107cb92c03bSAndrew Geissler     }
1083174e4dfSEd Tanous     if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
109cb92c03bSAndrew Geissler     {
110cb92c03bSAndrew Geissler         return "Warning";
111cb92c03bSAndrew Geissler     }
112cb92c03bSAndrew Geissler     return "";
113cb92c03bSAndrew Geissler }
114cb92c03bSAndrew Geissler 
1159017faf2SAbhishek Patel inline std::optional<bool> getProviderNotifyAction(const std::string& notify)
1169017faf2SAbhishek Patel {
1179017faf2SAbhishek Patel     std::optional<bool> notifyAction;
1189017faf2SAbhishek Patel     if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify")
1199017faf2SAbhishek Patel     {
1209017faf2SAbhishek Patel         notifyAction = true;
1219017faf2SAbhishek Patel     }
1229017faf2SAbhishek Patel     else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit")
1239017faf2SAbhishek Patel     {
1249017faf2SAbhishek Patel         notifyAction = false;
1259017faf2SAbhishek Patel     }
1269017faf2SAbhishek Patel 
1279017faf2SAbhishek Patel     return notifyAction;
1289017faf2SAbhishek Patel }
1299017faf2SAbhishek Patel 
13018f8f608SEd Tanous inline std::string getDumpPath(std::string_view dumpType)
13118f8f608SEd Tanous {
13218f8f608SEd Tanous     std::string dbusDumpPath = "/xyz/openbmc_project/dump/";
13318f8f608SEd Tanous     std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath),
13418f8f608SEd Tanous                            bmcweb::asciiToLower);
13518f8f608SEd Tanous 
13618f8f608SEd Tanous     return dbusDumpPath;
13718f8f608SEd Tanous }
13818f8f608SEd Tanous 
139055713e4SEd Tanous inline bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
140e85d6b16SJason M. Bills                              const bool firstEntry = true)
14195820184SJason M. Bills {
142271584abSEd Tanous     static time_t prevTs = 0;
14395820184SJason M. Bills     static int index = 0;
144e85d6b16SJason M. Bills     if (firstEntry)
145e85d6b16SJason M. Bills     {
146e85d6b16SJason M. Bills         prevTs = 0;
147e85d6b16SJason M. Bills     }
148e85d6b16SJason M. Bills 
14995820184SJason M. Bills     // Get the entry timestamp
150271584abSEd Tanous     std::time_t curTs = 0;
15195820184SJason M. Bills     std::tm timeStruct = {};
15295820184SJason M. Bills     std::istringstream entryStream(logEntry);
15395820184SJason M. Bills     if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
15495820184SJason M. Bills     {
15595820184SJason M. Bills         curTs = std::mktime(&timeStruct);
15695820184SJason M. Bills     }
15795820184SJason M. Bills     // If the timestamp isn't unique, increment the index
15895820184SJason M. Bills     if (curTs == prevTs)
15995820184SJason M. Bills     {
16095820184SJason M. Bills         index++;
16195820184SJason M. Bills     }
16295820184SJason M. Bills     else
16395820184SJason M. Bills     {
16495820184SJason M. Bills         // Otherwise, reset it
16595820184SJason M. Bills         index = 0;
16695820184SJason M. Bills     }
16795820184SJason M. Bills     // Save the timestamp
16895820184SJason M. Bills     prevTs = curTs;
16995820184SJason M. Bills 
17095820184SJason M. Bills     entryID = std::to_string(curTs);
17195820184SJason M. Bills     if (index > 0)
17295820184SJason M. Bills     {
17395820184SJason M. Bills         entryID += "_" + std::to_string(index);
17495820184SJason M. Bills     }
17595820184SJason M. Bills     return true;
17695820184SJason M. Bills }
17795820184SJason M. Bills 
1784ff0f1f4SEd Tanous inline bool
17995820184SJason M. Bills     getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
18095820184SJason M. Bills {
18195820184SJason M. Bills     static const std::filesystem::path redfishLogDir = "/var/log";
18295820184SJason M. Bills     static const std::string redfishLogFilename = "redfish";
18395820184SJason M. Bills 
18495820184SJason M. Bills     // Loop through the directory looking for redfish log files
18595820184SJason M. Bills     for (const std::filesystem::directory_entry& dirEnt :
18695820184SJason M. Bills          std::filesystem::directory_iterator(redfishLogDir))
18795820184SJason M. Bills     {
18895820184SJason M. Bills         // If we find a redfish log file, save the path
18995820184SJason M. Bills         std::string filename = dirEnt.path().filename();
19011ba3979SEd Tanous         if (filename.starts_with(redfishLogFilename))
19195820184SJason M. Bills         {
19295820184SJason M. Bills             redfishLogFiles.emplace_back(redfishLogDir / filename);
19395820184SJason M. Bills         }
19495820184SJason M. Bills     }
19595820184SJason M. Bills     // As the log files rotate, they are appended with a ".#" that is higher for
19695820184SJason M. Bills     // the older logs. Since we don't expect more than 10 log files, we
19795820184SJason M. Bills     // can just sort the list to get them in order from newest to oldest
1983544d2a7SEd Tanous     std::ranges::sort(redfishLogFiles);
19995820184SJason M. Bills 
20095820184SJason M. Bills     return !redfishLogFiles.empty();
20195820184SJason M. Bills }
20295820184SJason M. Bills 
20368dd075aSAsmitha Karunanithi inline log_entry::OriginatorTypes
20468dd075aSAsmitha Karunanithi     mapDbusOriginatorTypeToRedfish(const std::string& originatorType)
20568dd075aSAsmitha Karunanithi {
20668dd075aSAsmitha Karunanithi     if (originatorType ==
20768dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client")
20868dd075aSAsmitha Karunanithi     {
20968dd075aSAsmitha Karunanithi         return log_entry::OriginatorTypes::Client;
21068dd075aSAsmitha Karunanithi     }
21168dd075aSAsmitha Karunanithi     if (originatorType ==
21268dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal")
21368dd075aSAsmitha Karunanithi     {
21468dd075aSAsmitha Karunanithi         return log_entry::OriginatorTypes::Internal;
21568dd075aSAsmitha Karunanithi     }
21668dd075aSAsmitha Karunanithi     if (originatorType ==
21768dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService")
21868dd075aSAsmitha Karunanithi     {
21968dd075aSAsmitha Karunanithi         return log_entry::OriginatorTypes::SupportingService;
22068dd075aSAsmitha Karunanithi     }
22168dd075aSAsmitha Karunanithi     return log_entry::OriginatorTypes::Invalid;
22268dd075aSAsmitha Karunanithi }
22368dd075aSAsmitha Karunanithi 
224aefe3786SClaire Weinan inline void parseDumpEntryFromDbusObject(
2252d613eb6SJiaqing Zhao     const dbus::utility::ManagedObjectType::value_type& object,
226c6fecdabSClaire Weinan     std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs,
22768dd075aSAsmitha Karunanithi     std::string& originatorId, log_entry::OriginatorTypes& originatorType,
228aefe3786SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
229aefe3786SClaire Weinan {
230aefe3786SClaire Weinan     for (const auto& interfaceMap : object.second)
231aefe3786SClaire Weinan     {
232aefe3786SClaire Weinan         if (interfaceMap.first == "xyz.openbmc_project.Common.Progress")
233aefe3786SClaire Weinan         {
234aefe3786SClaire Weinan             for (const auto& propertyMap : interfaceMap.second)
235aefe3786SClaire Weinan             {
236aefe3786SClaire Weinan                 if (propertyMap.first == "Status")
237aefe3786SClaire Weinan                 {
238aefe3786SClaire Weinan                     const auto* status =
239aefe3786SClaire Weinan                         std::get_if<std::string>(&propertyMap.second);
240aefe3786SClaire Weinan                     if (status == nullptr)
241aefe3786SClaire Weinan                     {
242aefe3786SClaire Weinan                         messages::internalError(asyncResp->res);
243aefe3786SClaire Weinan                         break;
244aefe3786SClaire Weinan                     }
245aefe3786SClaire Weinan                     dumpStatus = *status;
246aefe3786SClaire Weinan                 }
247aefe3786SClaire Weinan             }
248aefe3786SClaire Weinan         }
249aefe3786SClaire Weinan         else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
250aefe3786SClaire Weinan         {
251aefe3786SClaire Weinan             for (const auto& propertyMap : interfaceMap.second)
252aefe3786SClaire Weinan             {
253aefe3786SClaire Weinan                 if (propertyMap.first == "Size")
254aefe3786SClaire Weinan                 {
255aefe3786SClaire Weinan                     const auto* sizePtr =
256aefe3786SClaire Weinan                         std::get_if<uint64_t>(&propertyMap.second);
257aefe3786SClaire Weinan                     if (sizePtr == nullptr)
258aefe3786SClaire Weinan                     {
259aefe3786SClaire Weinan                         messages::internalError(asyncResp->res);
260aefe3786SClaire Weinan                         break;
261aefe3786SClaire Weinan                     }
262aefe3786SClaire Weinan                     size = *sizePtr;
263aefe3786SClaire Weinan                     break;
264aefe3786SClaire Weinan                 }
265aefe3786SClaire Weinan             }
266aefe3786SClaire Weinan         }
267aefe3786SClaire Weinan         else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime")
268aefe3786SClaire Weinan         {
269aefe3786SClaire Weinan             for (const auto& propertyMap : interfaceMap.second)
270aefe3786SClaire Weinan             {
271aefe3786SClaire Weinan                 if (propertyMap.first == "Elapsed")
272aefe3786SClaire Weinan                 {
273aefe3786SClaire Weinan                     const uint64_t* usecsTimeStamp =
274aefe3786SClaire Weinan                         std::get_if<uint64_t>(&propertyMap.second);
275aefe3786SClaire Weinan                     if (usecsTimeStamp == nullptr)
276aefe3786SClaire Weinan                     {
277aefe3786SClaire Weinan                         messages::internalError(asyncResp->res);
278aefe3786SClaire Weinan                         break;
279aefe3786SClaire Weinan                     }
280c6fecdabSClaire Weinan                     timestampUs = *usecsTimeStamp;
281aefe3786SClaire Weinan                     break;
282aefe3786SClaire Weinan                 }
283aefe3786SClaire Weinan             }
284aefe3786SClaire Weinan         }
28568dd075aSAsmitha Karunanithi         else if (interfaceMap.first ==
28668dd075aSAsmitha Karunanithi                  "xyz.openbmc_project.Common.OriginatedBy")
28768dd075aSAsmitha Karunanithi         {
28868dd075aSAsmitha Karunanithi             for (const auto& propertyMap : interfaceMap.second)
28968dd075aSAsmitha Karunanithi             {
29068dd075aSAsmitha Karunanithi                 if (propertyMap.first == "OriginatorId")
29168dd075aSAsmitha Karunanithi                 {
29268dd075aSAsmitha Karunanithi                     const std::string* id =
29368dd075aSAsmitha Karunanithi                         std::get_if<std::string>(&propertyMap.second);
29468dd075aSAsmitha Karunanithi                     if (id == nullptr)
29568dd075aSAsmitha Karunanithi                     {
29668dd075aSAsmitha Karunanithi                         messages::internalError(asyncResp->res);
29768dd075aSAsmitha Karunanithi                         break;
29868dd075aSAsmitha Karunanithi                     }
29968dd075aSAsmitha Karunanithi                     originatorId = *id;
30068dd075aSAsmitha Karunanithi                 }
30168dd075aSAsmitha Karunanithi 
30268dd075aSAsmitha Karunanithi                 if (propertyMap.first == "OriginatorType")
30368dd075aSAsmitha Karunanithi                 {
30468dd075aSAsmitha Karunanithi                     const std::string* type =
30568dd075aSAsmitha Karunanithi                         std::get_if<std::string>(&propertyMap.second);
30668dd075aSAsmitha Karunanithi                     if (type == nullptr)
30768dd075aSAsmitha Karunanithi                     {
30868dd075aSAsmitha Karunanithi                         messages::internalError(asyncResp->res);
30968dd075aSAsmitha Karunanithi                         break;
31068dd075aSAsmitha Karunanithi                     }
31168dd075aSAsmitha Karunanithi 
31268dd075aSAsmitha Karunanithi                     originatorType = mapDbusOriginatorTypeToRedfish(*type);
31368dd075aSAsmitha Karunanithi                     if (originatorType == log_entry::OriginatorTypes::Invalid)
31468dd075aSAsmitha Karunanithi                     {
31568dd075aSAsmitha Karunanithi                         messages::internalError(asyncResp->res);
31668dd075aSAsmitha Karunanithi                         break;
31768dd075aSAsmitha Karunanithi                     }
31868dd075aSAsmitha Karunanithi                 }
31968dd075aSAsmitha Karunanithi             }
32068dd075aSAsmitha Karunanithi         }
321aefe3786SClaire Weinan     }
322aefe3786SClaire Weinan }
323aefe3786SClaire Weinan 
32421ab404cSNan Zhou static std::string getDumpEntriesPath(const std::string& dumpType)
325fdd26906SClaire Weinan {
326fdd26906SClaire Weinan     std::string entriesPath;
327fdd26906SClaire Weinan 
328fdd26906SClaire Weinan     if (dumpType == "BMC")
329fdd26906SClaire Weinan     {
330253f11b8SEd Tanous         entriesPath =
331253f11b8SEd Tanous             std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
332253f11b8SEd Tanous                         BMCWEB_REDFISH_MANAGER_URI_NAME);
333fdd26906SClaire Weinan     }
334fdd26906SClaire Weinan     else if (dumpType == "FaultLog")
335fdd26906SClaire Weinan     {
336253f11b8SEd Tanous         entriesPath =
337253f11b8SEd Tanous             std::format("/redfish/v1/Managers/{}/LogServices/FaultLog/Entries/",
338253f11b8SEd Tanous                         BMCWEB_REDFISH_MANAGER_URI_NAME);
339fdd26906SClaire Weinan     }
340fdd26906SClaire Weinan     else if (dumpType == "System")
341fdd26906SClaire Weinan     {
342253f11b8SEd Tanous         entriesPath =
343253f11b8SEd Tanous             std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
344253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
345fdd26906SClaire Weinan     }
346fdd26906SClaire Weinan     else
347fdd26906SClaire Weinan     {
34862598e31SEd Tanous         BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}",
34962598e31SEd Tanous                          dumpType);
350fdd26906SClaire Weinan     }
351fdd26906SClaire Weinan 
352fdd26906SClaire Weinan     // Returns empty string on error
353fdd26906SClaire Weinan     return entriesPath;
354fdd26906SClaire Weinan }
355fdd26906SClaire Weinan 
3568d1b46d7Szhanghch05 inline void
3578d1b46d7Szhanghch05     getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3585cb1dd27SAsmitha Karunanithi                            const std::string& dumpType)
3595cb1dd27SAsmitha Karunanithi {
360fdd26906SClaire Weinan     std::string entriesPath = getDumpEntriesPath(dumpType);
361fdd26906SClaire Weinan     if (entriesPath.empty())
3625cb1dd27SAsmitha Karunanithi     {
3635cb1dd27SAsmitha Karunanithi         messages::internalError(asyncResp->res);
3645cb1dd27SAsmitha Karunanithi         return;
3655cb1dd27SAsmitha Karunanithi     }
3665cb1dd27SAsmitha Karunanithi 
3675eb468daSGeorge Liu     sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
3685eb468daSGeorge Liu     dbus::utility::getManagedObjects(
3695eb468daSGeorge Liu         "xyz.openbmc_project.Dump.Manager", path,
370fdd26906SClaire Weinan         [asyncResp, entriesPath,
3715e7e2dc5SEd Tanous          dumpType](const boost::system::error_code& ec,
3725eb468daSGeorge Liu                    const dbus::utility::ManagedObjectType& objects) {
3735cb1dd27SAsmitha Karunanithi             if (ec)
3745cb1dd27SAsmitha Karunanithi             {
37562598e31SEd Tanous                 BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
3765cb1dd27SAsmitha Karunanithi                 messages::internalError(asyncResp->res);
3775cb1dd27SAsmitha Karunanithi                 return;
3785cb1dd27SAsmitha Karunanithi             }
3795cb1dd27SAsmitha Karunanithi 
380fdd26906SClaire Weinan             // Remove ending slash
381fdd26906SClaire Weinan             std::string odataIdStr = entriesPath;
382fdd26906SClaire Weinan             if (!odataIdStr.empty())
383fdd26906SClaire Weinan             {
384fdd26906SClaire Weinan                 odataIdStr.pop_back();
385fdd26906SClaire Weinan             }
386fdd26906SClaire Weinan 
387fdd26906SClaire Weinan             asyncResp->res.jsonValue["@odata.type"] =
388fdd26906SClaire Weinan                 "#LogEntryCollection.LogEntryCollection";
389fdd26906SClaire Weinan             asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr);
390fdd26906SClaire Weinan             asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries";
391bd79bce8SPatrick Williams             asyncResp->res.jsonValue["Description"] =
392bd79bce8SPatrick Williams                 "Collection of " + dumpType + " Dump Entries";
393fdd26906SClaire Weinan 
3943544d2a7SEd Tanous             nlohmann::json::array_t entriesArray;
39518f8f608SEd Tanous             std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
3965cb1dd27SAsmitha Karunanithi 
3975eb468daSGeorge Liu             dbus::utility::ManagedObjectType resp(objects);
3983544d2a7SEd Tanous             std::ranges::sort(resp, [](const auto& l, const auto& r) {
399002d39b4SEd Tanous                 return AlphanumLess<std::string>()(l.first.filename(),
400002d39b4SEd Tanous                                                    r.first.filename());
401565dfb6fSClaire Weinan             });
402565dfb6fSClaire Weinan 
4035cb1dd27SAsmitha Karunanithi             for (auto& object : resp)
4045cb1dd27SAsmitha Karunanithi             {
405b47452b2SAsmitha Karunanithi                 if (object.first.str.find(dumpEntryPath) == std::string::npos)
4065cb1dd27SAsmitha Karunanithi                 {
4075cb1dd27SAsmitha Karunanithi                     continue;
4085cb1dd27SAsmitha Karunanithi                 }
409c6fecdabSClaire Weinan                 uint64_t timestampUs = 0;
4105cb1dd27SAsmitha Karunanithi                 uint64_t size = 0;
41135440d18SAsmitha Karunanithi                 std::string dumpStatus;
41268dd075aSAsmitha Karunanithi                 std::string originatorId;
41368dd075aSAsmitha Karunanithi                 log_entry::OriginatorTypes originatorType =
41468dd075aSAsmitha Karunanithi                     log_entry::OriginatorTypes::Internal;
415433b68b4SJason M. Bills                 nlohmann::json::object_t thisEntry;
4162dfd18efSEd Tanous 
4172dfd18efSEd Tanous                 std::string entryID = object.first.filename();
4182dfd18efSEd Tanous                 if (entryID.empty())
4195cb1dd27SAsmitha Karunanithi                 {
4205cb1dd27SAsmitha Karunanithi                     continue;
4215cb1dd27SAsmitha Karunanithi                 }
4225cb1dd27SAsmitha Karunanithi 
423bd79bce8SPatrick Williams                 parseDumpEntryFromDbusObject(object, dumpStatus, size,
424bd79bce8SPatrick Williams                                              timestampUs, originatorId,
425bd79bce8SPatrick Williams                                              originatorType, asyncResp);
4265cb1dd27SAsmitha Karunanithi 
4270fda0f12SGeorge Liu                 if (dumpStatus !=
4280fda0f12SGeorge Liu                         "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
42935440d18SAsmitha Karunanithi                     !dumpStatus.empty())
43035440d18SAsmitha Karunanithi                 {
43135440d18SAsmitha Karunanithi                     // Dump status is not Complete, no need to enumerate
43235440d18SAsmitha Karunanithi                     continue;
43335440d18SAsmitha Karunanithi                 }
43435440d18SAsmitha Karunanithi 
43568dd075aSAsmitha Karunanithi                 thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry";
436fdd26906SClaire Weinan                 thisEntry["@odata.id"] = entriesPath + entryID;
4375cb1dd27SAsmitha Karunanithi                 thisEntry["Id"] = entryID;
4385cb1dd27SAsmitha Karunanithi                 thisEntry["EntryType"] = "Event";
4395cb1dd27SAsmitha Karunanithi                 thisEntry["Name"] = dumpType + " Dump Entry";
440bbd80db8SClaire Weinan                 thisEntry["Created"] =
441bbd80db8SClaire Weinan                     redfish::time_utils::getDateTimeUintUs(timestampUs);
4425cb1dd27SAsmitha Karunanithi 
44368dd075aSAsmitha Karunanithi                 if (!originatorId.empty())
44468dd075aSAsmitha Karunanithi                 {
44568dd075aSAsmitha Karunanithi                     thisEntry["Originator"] = originatorId;
44668dd075aSAsmitha Karunanithi                     thisEntry["OriginatorType"] = originatorType;
44768dd075aSAsmitha Karunanithi                 }
44868dd075aSAsmitha Karunanithi 
4495cb1dd27SAsmitha Karunanithi                 if (dumpType == "BMC")
4505cb1dd27SAsmitha Karunanithi                 {
451d337bb72SAsmitha Karunanithi                     thisEntry["DiagnosticDataType"] = "Manager";
452bd79bce8SPatrick Williams                     thisEntry["AdditionalDataURI"] =
453bd79bce8SPatrick Williams                         entriesPath + entryID + "/attachment";
454fdd26906SClaire Weinan                     thisEntry["AdditionalDataSizeBytes"] = size;
4555cb1dd27SAsmitha Karunanithi                 }
4565cb1dd27SAsmitha Karunanithi                 else if (dumpType == "System")
4575cb1dd27SAsmitha Karunanithi                 {
458d337bb72SAsmitha Karunanithi                     thisEntry["DiagnosticDataType"] = "OEM";
459d337bb72SAsmitha Karunanithi                     thisEntry["OEMDiagnosticDataType"] = "System";
460bd79bce8SPatrick Williams                     thisEntry["AdditionalDataURI"] =
461bd79bce8SPatrick Williams                         entriesPath + entryID + "/attachment";
462fdd26906SClaire Weinan                     thisEntry["AdditionalDataSizeBytes"] = size;
4635cb1dd27SAsmitha Karunanithi                 }
464b2ba3072SPatrick Williams                 entriesArray.emplace_back(std::move(thisEntry));
4655cb1dd27SAsmitha Karunanithi             }
466bd79bce8SPatrick Williams             asyncResp->res.jsonValue["Members@odata.count"] =
467bd79bce8SPatrick Williams                 entriesArray.size();
4683544d2a7SEd Tanous             asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
4695eb468daSGeorge Liu         });
4705cb1dd27SAsmitha Karunanithi }
4715cb1dd27SAsmitha Karunanithi 
4728d1b46d7Szhanghch05 inline void
473c7a6d660SClaire Weinan     getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
4748d1b46d7Szhanghch05                      const std::string& entryID, const std::string& dumpType)
4755cb1dd27SAsmitha Karunanithi {
476fdd26906SClaire Weinan     std::string entriesPath = getDumpEntriesPath(dumpType);
477fdd26906SClaire Weinan     if (entriesPath.empty())
4785cb1dd27SAsmitha Karunanithi     {
4795cb1dd27SAsmitha Karunanithi         messages::internalError(asyncResp->res);
4805cb1dd27SAsmitha Karunanithi         return;
4815cb1dd27SAsmitha Karunanithi     }
4825cb1dd27SAsmitha Karunanithi 
4835eb468daSGeorge Liu     sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
4845eb468daSGeorge Liu     dbus::utility::getManagedObjects(
4855eb468daSGeorge Liu         "xyz.openbmc_project.Dump.Manager", path,
486fdd26906SClaire Weinan         [asyncResp, entryID, dumpType,
4875e7e2dc5SEd Tanous          entriesPath](const boost::system::error_code& ec,
48802cad96eSEd Tanous                       const dbus::utility::ManagedObjectType& resp) {
4895cb1dd27SAsmitha Karunanithi             if (ec)
4905cb1dd27SAsmitha Karunanithi             {
49162598e31SEd Tanous                 BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec);
4925cb1dd27SAsmitha Karunanithi                 messages::internalError(asyncResp->res);
4935cb1dd27SAsmitha Karunanithi                 return;
4945cb1dd27SAsmitha Karunanithi             }
4955cb1dd27SAsmitha Karunanithi 
496b47452b2SAsmitha Karunanithi             bool foundDumpEntry = false;
49718f8f608SEd Tanous             std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
498b47452b2SAsmitha Karunanithi 
4999eb808c1SEd Tanous             for (const auto& objectPath : resp)
5005cb1dd27SAsmitha Karunanithi             {
501b47452b2SAsmitha Karunanithi                 if (objectPath.first.str != dumpEntryPath + entryID)
5025cb1dd27SAsmitha Karunanithi                 {
5035cb1dd27SAsmitha Karunanithi                     continue;
5045cb1dd27SAsmitha Karunanithi                 }
5055cb1dd27SAsmitha Karunanithi 
5065cb1dd27SAsmitha Karunanithi                 foundDumpEntry = true;
507c6fecdabSClaire Weinan                 uint64_t timestampUs = 0;
5085cb1dd27SAsmitha Karunanithi                 uint64_t size = 0;
50935440d18SAsmitha Karunanithi                 std::string dumpStatus;
51068dd075aSAsmitha Karunanithi                 std::string originatorId;
51168dd075aSAsmitha Karunanithi                 log_entry::OriginatorTypes originatorType =
51268dd075aSAsmitha Karunanithi                     log_entry::OriginatorTypes::Internal;
5135cb1dd27SAsmitha Karunanithi 
514aefe3786SClaire Weinan                 parseDumpEntryFromDbusObject(objectPath, dumpStatus, size,
51568dd075aSAsmitha Karunanithi                                              timestampUs, originatorId,
51668dd075aSAsmitha Karunanithi                                              originatorType, asyncResp);
5175cb1dd27SAsmitha Karunanithi 
5180fda0f12SGeorge Liu                 if (dumpStatus !=
5190fda0f12SGeorge Liu                         "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
52035440d18SAsmitha Karunanithi                     !dumpStatus.empty())
52135440d18SAsmitha Karunanithi                 {
52235440d18SAsmitha Karunanithi                     // Dump status is not Complete
52335440d18SAsmitha Karunanithi                     // return not found until status is changed to Completed
524bd79bce8SPatrick Williams                     messages::resourceNotFound(asyncResp->res,
525bd79bce8SPatrick Williams                                                dumpType + " dump", entryID);
52635440d18SAsmitha Karunanithi                     return;
52735440d18SAsmitha Karunanithi                 }
52835440d18SAsmitha Karunanithi 
5295cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["@odata.type"] =
53068dd075aSAsmitha Karunanithi                     "#LogEntry.v1_11_0.LogEntry";
531fdd26906SClaire Weinan                 asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID;
5325cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["Id"] = entryID;
5335cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["EntryType"] = "Event";
5345cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
535bbd80db8SClaire Weinan                 asyncResp->res.jsonValue["Created"] =
536bbd80db8SClaire Weinan                     redfish::time_utils::getDateTimeUintUs(timestampUs);
5375cb1dd27SAsmitha Karunanithi 
53868dd075aSAsmitha Karunanithi                 if (!originatorId.empty())
53968dd075aSAsmitha Karunanithi                 {
54068dd075aSAsmitha Karunanithi                     asyncResp->res.jsonValue["Originator"] = originatorId;
54168dd075aSAsmitha Karunanithi                     asyncResp->res.jsonValue["OriginatorType"] = originatorType;
54268dd075aSAsmitha Karunanithi                 }
54368dd075aSAsmitha Karunanithi 
5445cb1dd27SAsmitha Karunanithi                 if (dumpType == "BMC")
5455cb1dd27SAsmitha Karunanithi                 {
546d337bb72SAsmitha Karunanithi                     asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
547d337bb72SAsmitha Karunanithi                     asyncResp->res.jsonValue["AdditionalDataURI"] =
548fdd26906SClaire Weinan                         entriesPath + entryID + "/attachment";
549fdd26906SClaire Weinan                     asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
5505cb1dd27SAsmitha Karunanithi                 }
5515cb1dd27SAsmitha Karunanithi                 else if (dumpType == "System")
5525cb1dd27SAsmitha Karunanithi                 {
553d337bb72SAsmitha Karunanithi                     asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
554bd79bce8SPatrick Williams                     asyncResp->res.jsonValue["OEMDiagnosticDataType"] =
555bd79bce8SPatrick Williams                         "System";
556d337bb72SAsmitha Karunanithi                     asyncResp->res.jsonValue["AdditionalDataURI"] =
557fdd26906SClaire Weinan                         entriesPath + entryID + "/attachment";
558fdd26906SClaire Weinan                     asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
5595cb1dd27SAsmitha Karunanithi                 }
5605cb1dd27SAsmitha Karunanithi             }
561e05aec50SEd Tanous             if (!foundDumpEntry)
562b47452b2SAsmitha Karunanithi             {
56362598e31SEd Tanous                 BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
564b90d14f2SMyung Bae                 messages::resourceNotFound(asyncResp->res, dumpType + " dump",
565b90d14f2SMyung Bae                                            entryID);
566b47452b2SAsmitha Karunanithi                 return;
567b47452b2SAsmitha Karunanithi             }
5685eb468daSGeorge Liu         });
5695cb1dd27SAsmitha Karunanithi }
5705cb1dd27SAsmitha Karunanithi 
5718d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
5729878256fSStanley Chu                             const std::string& entryID,
573b47452b2SAsmitha Karunanithi                             const std::string& dumpType)
5745cb1dd27SAsmitha Karunanithi {
5755a39f77aSPatrick Williams     auto respHandler = [asyncResp,
5765a39f77aSPatrick Williams                         entryID](const boost::system::error_code& ec) {
57762598e31SEd Tanous         BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done");
5785cb1dd27SAsmitha Karunanithi         if (ec)
5795cb1dd27SAsmitha Karunanithi         {
5803de8d8baSGeorge Liu             if (ec.value() == EBADR)
5813de8d8baSGeorge Liu             {
5823de8d8baSGeorge Liu                 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
5833de8d8baSGeorge Liu                 return;
5843de8d8baSGeorge Liu             }
58562598e31SEd Tanous             BMCWEB_LOG_ERROR(
58662598e31SEd Tanous                 "Dump (DBus) doDelete respHandler got error {} entryID={}", ec,
58762598e31SEd Tanous                 entryID);
5885cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
5895cb1dd27SAsmitha Karunanithi             return;
5905cb1dd27SAsmitha Karunanithi         }
5915cb1dd27SAsmitha Karunanithi     };
59218f8f608SEd Tanous 
5935cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
5945cb1dd27SAsmitha Karunanithi         respHandler, "xyz.openbmc_project.Dump.Manager",
59518f8f608SEd Tanous         std::format("{}/entry/{}", getDumpPath(dumpType), entryID),
5965cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Object.Delete", "Delete");
5975cb1dd27SAsmitha Karunanithi }
598b5f288d2SAbhilash Raju inline bool checkSizeLimit(int fd, crow::Response& res)
599b5f288d2SAbhilash Raju {
600b5f288d2SAbhilash Raju     long long int size = lseek(fd, 0, SEEK_END);
601b5f288d2SAbhilash Raju     if (size <= 0)
602b5f288d2SAbhilash Raju     {
603b5f288d2SAbhilash Raju         BMCWEB_LOG_ERROR("Failed to get size of file, lseek() returned {}",
604b5f288d2SAbhilash Raju                          size);
605b5f288d2SAbhilash Raju         messages::internalError(res);
606b5f288d2SAbhilash Raju         return false;
607b5f288d2SAbhilash Raju     }
6085cb1dd27SAsmitha Karunanithi 
609b5f288d2SAbhilash Raju     // Arbitrary max size of 20MB to accommodate BMC dumps
610b5f288d2SAbhilash Raju     constexpr long long int maxFileSize = 20LL * 1024LL * 1024LL;
611b5f288d2SAbhilash Raju     if (size > maxFileSize)
612b5f288d2SAbhilash Raju     {
613b5f288d2SAbhilash Raju         BMCWEB_LOG_ERROR("File size {} exceeds maximum allowed size of {}",
614b5f288d2SAbhilash Raju                          size, maxFileSize);
615b5f288d2SAbhilash Raju         messages::internalError(res);
616b5f288d2SAbhilash Raju         return false;
617b5f288d2SAbhilash Raju     }
618b5f288d2SAbhilash Raju     off_t rc = lseek(fd, 0, SEEK_SET);
619b5f288d2SAbhilash Raju     if (rc < 0)
620b5f288d2SAbhilash Raju     {
621b5f288d2SAbhilash Raju         BMCWEB_LOG_ERROR("Failed to reset file offset to 0");
622b5f288d2SAbhilash Raju         messages::internalError(res);
623b5f288d2SAbhilash Raju         return false;
624b5f288d2SAbhilash Raju     }
625b5f288d2SAbhilash Raju     return true;
626b5f288d2SAbhilash Raju }
627bd79bce8SPatrick Williams inline void downloadEntryCallback(
628bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
629bd79bce8SPatrick Williams     const std::string& entryID, const std::string& downloadEntryType,
630168d1b1aSCarson Labrado     const boost::system::error_code& ec,
631168d1b1aSCarson Labrado     const sdbusplus::message::unix_fd& unixfd)
632168d1b1aSCarson Labrado {
633168d1b1aSCarson Labrado     if (ec.value() == EBADR)
634168d1b1aSCarson Labrado     {
635168d1b1aSCarson Labrado         messages::resourceNotFound(asyncResp->res, "EntryAttachment", entryID);
636168d1b1aSCarson Labrado         return;
637168d1b1aSCarson Labrado     }
638168d1b1aSCarson Labrado     if (ec)
639168d1b1aSCarson Labrado     {
640168d1b1aSCarson Labrado         BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
641168d1b1aSCarson Labrado         messages::internalError(asyncResp->res);
642168d1b1aSCarson Labrado         return;
643168d1b1aSCarson Labrado     }
644168d1b1aSCarson Labrado 
645168d1b1aSCarson Labrado     // Make sure we know how to process the retrieved entry attachment
646168d1b1aSCarson Labrado     if ((downloadEntryType != "BMC") && (downloadEntryType != "System"))
647168d1b1aSCarson Labrado     {
648168d1b1aSCarson Labrado         BMCWEB_LOG_ERROR("downloadEntryCallback() invalid entry type: {}",
649168d1b1aSCarson Labrado                          downloadEntryType);
650168d1b1aSCarson Labrado         messages::internalError(asyncResp->res);
651168d1b1aSCarson Labrado     }
652168d1b1aSCarson Labrado 
653168d1b1aSCarson Labrado     int fd = -1;
654168d1b1aSCarson Labrado     fd = dup(unixfd);
655168d1b1aSCarson Labrado     if (fd < 0)
656168d1b1aSCarson Labrado     {
657168d1b1aSCarson Labrado         BMCWEB_LOG_ERROR("Failed to open file");
658168d1b1aSCarson Labrado         messages::internalError(asyncResp->res);
659168d1b1aSCarson Labrado         return;
660168d1b1aSCarson Labrado     }
661b5f288d2SAbhilash Raju     if (!checkSizeLimit(fd, asyncResp->res))
662168d1b1aSCarson Labrado     {
663168d1b1aSCarson Labrado         close(fd);
664168d1b1aSCarson Labrado         return;
665168d1b1aSCarson Labrado     }
666168d1b1aSCarson Labrado     if (downloadEntryType == "System")
667168d1b1aSCarson Labrado     {
668b5f288d2SAbhilash Raju         if (!asyncResp->res.openFd(fd, bmcweb::EncodingType::Base64))
669b5f288d2SAbhilash Raju         {
670b5f288d2SAbhilash Raju             messages::internalError(asyncResp->res);
671b5f288d2SAbhilash Raju             close(fd);
672b5f288d2SAbhilash Raju             return;
673b5f288d2SAbhilash Raju         }
674168d1b1aSCarson Labrado         asyncResp->res.addHeader(
675168d1b1aSCarson Labrado             boost::beast::http::field::content_transfer_encoding, "Base64");
676b5f288d2SAbhilash Raju         return;
677168d1b1aSCarson Labrado     }
678b5f288d2SAbhilash Raju     if (!asyncResp->res.openFd(fd))
67927b0cf90SEd Tanous     {
680b5f288d2SAbhilash Raju         messages::internalError(asyncResp->res);
681b5f288d2SAbhilash Raju         close(fd);
682b5f288d2SAbhilash Raju         return;
68327b0cf90SEd Tanous     }
684168d1b1aSCarson Labrado     asyncResp->res.addHeader(boost::beast::http::field::content_type,
685168d1b1aSCarson Labrado                              "application/octet-stream");
686168d1b1aSCarson Labrado }
687168d1b1aSCarson Labrado 
688168d1b1aSCarson Labrado inline void
689168d1b1aSCarson Labrado     downloadDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
690168d1b1aSCarson Labrado                       const std::string& entryID, const std::string& dumpType)
691168d1b1aSCarson Labrado {
692168d1b1aSCarson Labrado     if (dumpType != "BMC")
693168d1b1aSCarson Labrado     {
694168d1b1aSCarson Labrado         BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID);
695168d1b1aSCarson Labrado         messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID);
696168d1b1aSCarson Labrado         return;
697168d1b1aSCarson Labrado     }
698168d1b1aSCarson Labrado 
699bd79bce8SPatrick Williams     std::string dumpEntryPath =
700bd79bce8SPatrick Williams         std::format("{}/entry/{}", getDumpPath(dumpType), entryID);
701168d1b1aSCarson Labrado 
702168d1b1aSCarson Labrado     auto downloadDumpEntryHandler =
703168d1b1aSCarson Labrado         [asyncResp, entryID,
704168d1b1aSCarson Labrado          dumpType](const boost::system::error_code& ec,
705168d1b1aSCarson Labrado                    const sdbusplus::message::unix_fd& unixfd) {
706168d1b1aSCarson Labrado             downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
707168d1b1aSCarson Labrado         };
708168d1b1aSCarson Labrado 
709168d1b1aSCarson Labrado     crow::connections::systemBus->async_method_call(
710168d1b1aSCarson Labrado         std::move(downloadDumpEntryHandler), "xyz.openbmc_project.Dump.Manager",
711168d1b1aSCarson Labrado         dumpEntryPath, "xyz.openbmc_project.Dump.Entry", "GetFileHandle");
712168d1b1aSCarson Labrado }
713168d1b1aSCarson Labrado 
714bd79bce8SPatrick Williams inline void downloadEventLogEntry(
715bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
716bd79bce8SPatrick Williams     const std::string& systemName, const std::string& entryID,
717168d1b1aSCarson Labrado     const std::string& dumpType)
718168d1b1aSCarson Labrado {
71925b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
720168d1b1aSCarson Labrado     {
721168d1b1aSCarson Labrado         // Option currently returns no systems.  TBD
722168d1b1aSCarson Labrado         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
723168d1b1aSCarson Labrado                                    systemName);
724168d1b1aSCarson Labrado         return;
725168d1b1aSCarson Labrado     }
726253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
727168d1b1aSCarson Labrado     {
728168d1b1aSCarson Labrado         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
729168d1b1aSCarson Labrado                                    systemName);
730168d1b1aSCarson Labrado         return;
731168d1b1aSCarson Labrado     }
732168d1b1aSCarson Labrado 
733168d1b1aSCarson Labrado     std::string entryPath =
734168d1b1aSCarson Labrado         sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") /
735168d1b1aSCarson Labrado         entryID;
736168d1b1aSCarson Labrado 
737168d1b1aSCarson Labrado     auto downloadEventLogEntryHandler =
738168d1b1aSCarson Labrado         [asyncResp, entryID,
739168d1b1aSCarson Labrado          dumpType](const boost::system::error_code& ec,
740168d1b1aSCarson Labrado                    const sdbusplus::message::unix_fd& unixfd) {
741168d1b1aSCarson Labrado             downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
742168d1b1aSCarson Labrado         };
743168d1b1aSCarson Labrado 
744168d1b1aSCarson Labrado     crow::connections::systemBus->async_method_call(
745168d1b1aSCarson Labrado         std::move(downloadEventLogEntryHandler), "xyz.openbmc_project.Logging",
746168d1b1aSCarson Labrado         entryPath, "xyz.openbmc_project.Logging.Entry", "GetEntry");
747168d1b1aSCarson Labrado }
748168d1b1aSCarson Labrado 
7498e31778eSAsmitha Karunanithi inline DumpCreationProgress
7508e31778eSAsmitha Karunanithi     mapDbusStatusToDumpProgress(const std::string& status)
751a43be80fSAsmitha Karunanithi {
7528e31778eSAsmitha Karunanithi     if (status ==
7538e31778eSAsmitha Karunanithi             "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" ||
7548e31778eSAsmitha Karunanithi         status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted")
7558e31778eSAsmitha Karunanithi     {
7568e31778eSAsmitha Karunanithi         return DumpCreationProgress::DUMP_CREATE_FAILED;
7578e31778eSAsmitha Karunanithi     }
7588e31778eSAsmitha Karunanithi     if (status ==
7598e31778eSAsmitha Karunanithi         "xyz.openbmc_project.Common.Progress.OperationStatus.Completed")
7608e31778eSAsmitha Karunanithi     {
7618e31778eSAsmitha Karunanithi         return DumpCreationProgress::DUMP_CREATE_SUCCESS;
7628e31778eSAsmitha Karunanithi     }
7638e31778eSAsmitha Karunanithi     return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
7648e31778eSAsmitha Karunanithi }
7658e31778eSAsmitha Karunanithi 
7668e31778eSAsmitha Karunanithi inline DumpCreationProgress
7678e31778eSAsmitha Karunanithi     getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values)
7688e31778eSAsmitha Karunanithi {
7698e31778eSAsmitha Karunanithi     for (const auto& [key, val] : values)
7708e31778eSAsmitha Karunanithi     {
7718e31778eSAsmitha Karunanithi         if (key == "Status")
7728e31778eSAsmitha Karunanithi         {
7738e31778eSAsmitha Karunanithi             const std::string* value = std::get_if<std::string>(&val);
7748e31778eSAsmitha Karunanithi             if (value == nullptr)
7758e31778eSAsmitha Karunanithi             {
77662598e31SEd Tanous                 BMCWEB_LOG_ERROR("Status property value is null");
7778e31778eSAsmitha Karunanithi                 return DumpCreationProgress::DUMP_CREATE_FAILED;
7788e31778eSAsmitha Karunanithi             }
7798e31778eSAsmitha Karunanithi             return mapDbusStatusToDumpProgress(*value);
7808e31778eSAsmitha Karunanithi         }
7818e31778eSAsmitha Karunanithi     }
7828e31778eSAsmitha Karunanithi     return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
7838e31778eSAsmitha Karunanithi }
7848e31778eSAsmitha Karunanithi 
7858e31778eSAsmitha Karunanithi inline std::string getDumpEntryPath(const std::string& dumpPath)
7868e31778eSAsmitha Karunanithi {
7878e31778eSAsmitha Karunanithi     if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry")
7888e31778eSAsmitha Karunanithi     {
789253f11b8SEd Tanous         return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/",
7909f565090SEd Tanous                            BMCWEB_REDFISH_MANAGER_URI_NAME);
7918e31778eSAsmitha Karunanithi     }
7928e31778eSAsmitha Karunanithi     if (dumpPath == "/xyz/openbmc_project/dump/system/entry")
7938e31778eSAsmitha Karunanithi     {
794253f11b8SEd Tanous         return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/",
795253f11b8SEd Tanous                            BMCWEB_REDFISH_SYSTEM_URI_NAME);
7968e31778eSAsmitha Karunanithi     }
7978e31778eSAsmitha Karunanithi     return "";
7988e31778eSAsmitha Karunanithi }
7998e31778eSAsmitha Karunanithi 
8008e31778eSAsmitha Karunanithi inline void createDumpTaskCallback(
8018e31778eSAsmitha Karunanithi     task::Payload&& payload,
8028e31778eSAsmitha Karunanithi     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
8038e31778eSAsmitha Karunanithi     const sdbusplus::message::object_path& createdObjPath)
8048e31778eSAsmitha Karunanithi {
8058e31778eSAsmitha Karunanithi     const std::string dumpPath = createdObjPath.parent_path().str;
8068e31778eSAsmitha Karunanithi     const std::string dumpId = createdObjPath.filename();
8078e31778eSAsmitha Karunanithi 
8088e31778eSAsmitha Karunanithi     std::string dumpEntryPath = getDumpEntryPath(dumpPath);
8098e31778eSAsmitha Karunanithi 
8108e31778eSAsmitha Karunanithi     if (dumpEntryPath.empty())
8118e31778eSAsmitha Karunanithi     {
81262598e31SEd Tanous         BMCWEB_LOG_ERROR("Invalid dump type received");
8138e31778eSAsmitha Karunanithi         messages::internalError(asyncResp->res);
8148e31778eSAsmitha Karunanithi         return;
8158e31778eSAsmitha Karunanithi     }
8168e31778eSAsmitha Karunanithi 
8178e31778eSAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
8188cb2c024SEd Tanous         [asyncResp, payload = std::move(payload), createdObjPath,
8198e31778eSAsmitha Karunanithi          dumpEntryPath{std::move(dumpEntryPath)},
8205e7e2dc5SEd Tanous          dumpId](const boost::system::error_code& ec,
8218e31778eSAsmitha Karunanithi                  const std::string& introspectXml) {
8228e31778eSAsmitha Karunanithi             if (ec)
8238e31778eSAsmitha Karunanithi             {
82462598e31SEd Tanous                 BMCWEB_LOG_ERROR("Introspect call failed with error: {}",
82562598e31SEd Tanous                                  ec.message());
8268e31778eSAsmitha Karunanithi                 messages::internalError(asyncResp->res);
8278e31778eSAsmitha Karunanithi                 return;
8288e31778eSAsmitha Karunanithi             }
8298e31778eSAsmitha Karunanithi 
8308e31778eSAsmitha Karunanithi             // Check if the created dump object has implemented Progress
8318e31778eSAsmitha Karunanithi             // interface to track dump completion. If yes, fetch the "Status"
8328e31778eSAsmitha Karunanithi             // property of the interface, modify the task state accordingly.
8338e31778eSAsmitha Karunanithi             // Else, return task completed.
8348e31778eSAsmitha Karunanithi             tinyxml2::XMLDocument doc;
8358e31778eSAsmitha Karunanithi 
8368e31778eSAsmitha Karunanithi             doc.Parse(introspectXml.data(), introspectXml.size());
8378e31778eSAsmitha Karunanithi             tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
8388e31778eSAsmitha Karunanithi             if (pRoot == nullptr)
8398e31778eSAsmitha Karunanithi             {
84062598e31SEd Tanous                 BMCWEB_LOG_ERROR("XML document failed to parse");
8418e31778eSAsmitha Karunanithi                 messages::internalError(asyncResp->res);
8428e31778eSAsmitha Karunanithi                 return;
8438e31778eSAsmitha Karunanithi             }
8448e31778eSAsmitha Karunanithi             tinyxml2::XMLElement* interfaceNode =
8458e31778eSAsmitha Karunanithi                 pRoot->FirstChildElement("interface");
8468e31778eSAsmitha Karunanithi 
8478e31778eSAsmitha Karunanithi             bool isProgressIntfPresent = false;
8488e31778eSAsmitha Karunanithi             while (interfaceNode != nullptr)
8498e31778eSAsmitha Karunanithi             {
850bd79bce8SPatrick Williams                 const char* thisInterfaceName =
851bd79bce8SPatrick Williams                     interfaceNode->Attribute("name");
8528e31778eSAsmitha Karunanithi                 if (thisInterfaceName != nullptr)
8538e31778eSAsmitha Karunanithi                 {
8548e31778eSAsmitha Karunanithi                     if (thisInterfaceName ==
8558e31778eSAsmitha Karunanithi                         std::string_view("xyz.openbmc_project.Common.Progress"))
8568e31778eSAsmitha Karunanithi                     {
8578e31778eSAsmitha Karunanithi                         interfaceNode =
8588e31778eSAsmitha Karunanithi                             interfaceNode->NextSiblingElement("interface");
8598e31778eSAsmitha Karunanithi                         continue;
8608e31778eSAsmitha Karunanithi                     }
8618e31778eSAsmitha Karunanithi                     isProgressIntfPresent = true;
8628e31778eSAsmitha Karunanithi                     break;
8638e31778eSAsmitha Karunanithi                 }
8648e31778eSAsmitha Karunanithi                 interfaceNode = interfaceNode->NextSiblingElement("interface");
8658e31778eSAsmitha Karunanithi             }
8668e31778eSAsmitha Karunanithi 
867a43be80fSAsmitha Karunanithi             std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
8688e31778eSAsmitha Karunanithi                 [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent](
869bd79bce8SPatrick Williams                     const boost::system::error_code& ec2,
870bd79bce8SPatrick Williams                     sdbusplus::message_t& msg,
871a43be80fSAsmitha Karunanithi                     const std::shared_ptr<task::TaskData>& taskData) {
8728b24275dSEd Tanous                     if (ec2)
873cb13a392SEd Tanous                     {
87462598e31SEd Tanous                         BMCWEB_LOG_ERROR("{}: Error in creating dump",
87562598e31SEd Tanous                                          createdObjPath.str);
876bd79bce8SPatrick Williams                         taskData->messages.emplace_back(
877bd79bce8SPatrick Williams                             messages::internalError());
8786145ed6fSAsmitha Karunanithi                         taskData->state = "Cancelled";
8796145ed6fSAsmitha Karunanithi                         return task::completed;
880cb13a392SEd Tanous                     }
881b9d36b47SEd Tanous 
8828e31778eSAsmitha Karunanithi                     if (isProgressIntfPresent)
883a43be80fSAsmitha Karunanithi                     {
8848e31778eSAsmitha Karunanithi                         dbus::utility::DBusPropertiesMap values;
8858e31778eSAsmitha Karunanithi                         std::string prop;
8868e31778eSAsmitha Karunanithi                         msg.read(prop, values);
8878e31778eSAsmitha Karunanithi 
8888e31778eSAsmitha Karunanithi                         DumpCreationProgress dumpStatus =
8898e31778eSAsmitha Karunanithi                             getDumpCompletionStatus(values);
890bd79bce8SPatrick Williams                         if (dumpStatus ==
891bd79bce8SPatrick Williams                             DumpCreationProgress::DUMP_CREATE_FAILED)
8928e31778eSAsmitha Karunanithi                         {
89362598e31SEd Tanous                             BMCWEB_LOG_ERROR("{}: Error in creating dump",
89462598e31SEd Tanous                                              createdObjPath.str);
8958e31778eSAsmitha Karunanithi                             taskData->state = "Cancelled";
8968e31778eSAsmitha Karunanithi                             return task::completed;
8978e31778eSAsmitha Karunanithi                         }
8988e31778eSAsmitha Karunanithi 
899bd79bce8SPatrick Williams                         if (dumpStatus ==
900bd79bce8SPatrick Williams                             DumpCreationProgress::DUMP_CREATE_INPROGRESS)
9018e31778eSAsmitha Karunanithi                         {
902bd79bce8SPatrick Williams                             BMCWEB_LOG_DEBUG(
903bd79bce8SPatrick Williams                                 "{}: Dump creation task is in progress",
90462598e31SEd Tanous                                 createdObjPath.str);
9058e31778eSAsmitha Karunanithi                             return !task::completed;
9068e31778eSAsmitha Karunanithi                         }
9078e31778eSAsmitha Karunanithi                     }
9088e31778eSAsmitha Karunanithi 
909a43be80fSAsmitha Karunanithi                     nlohmann::json retMessage = messages::success();
910a43be80fSAsmitha Karunanithi                     taskData->messages.emplace_back(retMessage);
911a43be80fSAsmitha Karunanithi 
912c51a58eeSEd Tanous                     boost::urls::url url = boost::urls::format(
913253f11b8SEd Tanous                         "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}",
914253f11b8SEd Tanous                         BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId);
915c51a58eeSEd Tanous 
916c51a58eeSEd Tanous                     std::string headerLoc = "Location: ";
917c51a58eeSEd Tanous                     headerLoc += url.buffer();
918c51a58eeSEd Tanous 
919bd79bce8SPatrick Williams                     taskData->payload->httpHeaders.emplace_back(
920bd79bce8SPatrick Williams                         std::move(headerLoc));
921a43be80fSAsmitha Karunanithi 
92262598e31SEd Tanous                     BMCWEB_LOG_DEBUG("{}: Dump creation task completed",
92362598e31SEd Tanous                                      createdObjPath.str);
924a43be80fSAsmitha Karunanithi                     taskData->state = "Completed";
925b47452b2SAsmitha Karunanithi                     return task::completed;
926a43be80fSAsmitha Karunanithi                 },
9278e31778eSAsmitha Karunanithi                 "type='signal',interface='org.freedesktop.DBus.Properties',"
9288e31778eSAsmitha Karunanithi                 "member='PropertiesChanged',path='" +
9298e31778eSAsmitha Karunanithi                     createdObjPath.str + "'");
930a43be80fSAsmitha Karunanithi 
9318e31778eSAsmitha Karunanithi             // The task timer is set to max time limit within which the
9328e31778eSAsmitha Karunanithi             // requested dump will be collected.
9338e31778eSAsmitha Karunanithi             task->startTimer(std::chrono::minutes(6));
934a43be80fSAsmitha Karunanithi             task->populateResp(asyncResp->res);
9358e31778eSAsmitha Karunanithi             task->payload.emplace(payload);
9368e31778eSAsmitha Karunanithi         },
9378e31778eSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager", createdObjPath,
9388e31778eSAsmitha Karunanithi         "org.freedesktop.DBus.Introspectable", "Introspect");
939a43be80fSAsmitha Karunanithi }
940a43be80fSAsmitha Karunanithi 
9418d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
9428d1b46d7Szhanghch05                        const crow::Request& req, const std::string& dumpType)
943a43be80fSAsmitha Karunanithi {
944fdd26906SClaire Weinan     std::string dumpPath = getDumpEntriesPath(dumpType);
945fdd26906SClaire Weinan     if (dumpPath.empty())
946a43be80fSAsmitha Karunanithi     {
947a43be80fSAsmitha Karunanithi         messages::internalError(asyncResp->res);
948a43be80fSAsmitha Karunanithi         return;
949a43be80fSAsmitha Karunanithi     }
950a43be80fSAsmitha Karunanithi 
951a43be80fSAsmitha Karunanithi     std::optional<std::string> diagnosticDataType;
952a43be80fSAsmitha Karunanithi     std::optional<std::string> oemDiagnosticDataType;
953a43be80fSAsmitha Karunanithi 
954afc474aeSMyung Bae     if (!redfish::json_util::readJsonAction( //
955afc474aeSMyung Bae             req, asyncResp->res, //
956afc474aeSMyung Bae             "DiagnosticDataType", diagnosticDataType, //
957afc474aeSMyung Bae             "OEMDiagnosticDataType", oemDiagnosticDataType //
958afc474aeSMyung Bae             ))
959a43be80fSAsmitha Karunanithi     {
960a43be80fSAsmitha Karunanithi         return;
961a43be80fSAsmitha Karunanithi     }
962a43be80fSAsmitha Karunanithi 
963a43be80fSAsmitha Karunanithi     if (dumpType == "System")
964a43be80fSAsmitha Karunanithi     {
965a43be80fSAsmitha Karunanithi         if (!oemDiagnosticDataType || !diagnosticDataType)
966a43be80fSAsmitha Karunanithi         {
96762598e31SEd Tanous             BMCWEB_LOG_ERROR(
96862598e31SEd Tanous                 "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!");
969a43be80fSAsmitha Karunanithi             messages::actionParameterMissing(
970a43be80fSAsmitha Karunanithi                 asyncResp->res, "CollectDiagnosticData",
971a43be80fSAsmitha Karunanithi                 "DiagnosticDataType & OEMDiagnosticDataType");
972a43be80fSAsmitha Karunanithi             return;
973a43be80fSAsmitha Karunanithi         }
9743174e4dfSEd Tanous         if ((*oemDiagnosticDataType != "System") ||
975a43be80fSAsmitha Karunanithi             (*diagnosticDataType != "OEM"))
976a43be80fSAsmitha Karunanithi         {
97762598e31SEd Tanous             BMCWEB_LOG_ERROR("Wrong parameter values passed");
978ace85d60SEd Tanous             messages::internalError(asyncResp->res);
979a43be80fSAsmitha Karunanithi             return;
980a43be80fSAsmitha Karunanithi         }
981253f11b8SEd Tanous         dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/",
982253f11b8SEd Tanous                                BMCWEB_REDFISH_SYSTEM_URI_NAME);
983a43be80fSAsmitha Karunanithi     }
984a43be80fSAsmitha Karunanithi     else if (dumpType == "BMC")
985a43be80fSAsmitha Karunanithi     {
986a43be80fSAsmitha Karunanithi         if (!diagnosticDataType)
987a43be80fSAsmitha Karunanithi         {
98862598e31SEd Tanous             BMCWEB_LOG_ERROR(
98962598e31SEd Tanous                 "CreateDump action parameter 'DiagnosticDataType' not found!");
990a43be80fSAsmitha Karunanithi             messages::actionParameterMissing(
991a43be80fSAsmitha Karunanithi                 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
992a43be80fSAsmitha Karunanithi             return;
993a43be80fSAsmitha Karunanithi         }
9943174e4dfSEd Tanous         if (*diagnosticDataType != "Manager")
995a43be80fSAsmitha Karunanithi         {
99662598e31SEd Tanous             BMCWEB_LOG_ERROR(
99762598e31SEd Tanous                 "Wrong parameter value passed for 'DiagnosticDataType'");
998ace85d60SEd Tanous             messages::internalError(asyncResp->res);
999a43be80fSAsmitha Karunanithi             return;
1000a43be80fSAsmitha Karunanithi         }
1001253f11b8SEd Tanous         dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/",
1002253f11b8SEd Tanous                                BMCWEB_REDFISH_MANAGER_URI_NAME);
10035907571dSAsmitha Karunanithi     }
10045907571dSAsmitha Karunanithi     else
10055907571dSAsmitha Karunanithi     {
100662598e31SEd Tanous         BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type");
10075907571dSAsmitha Karunanithi         messages::internalError(asyncResp->res);
10085907571dSAsmitha Karunanithi         return;
1009a43be80fSAsmitha Karunanithi     }
1010a43be80fSAsmitha Karunanithi 
10118e31778eSAsmitha Karunanithi     std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>>
10128e31778eSAsmitha Karunanithi         createDumpParamVec;
10138e31778eSAsmitha Karunanithi 
1014f574a8e1SCarson Labrado     if (req.session != nullptr)
1015f574a8e1SCarson Labrado     {
101668dd075aSAsmitha Karunanithi         createDumpParamVec.emplace_back(
101768dd075aSAsmitha Karunanithi             "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId",
101868dd075aSAsmitha Karunanithi             req.session->clientIp);
101968dd075aSAsmitha Karunanithi         createDumpParamVec.emplace_back(
102068dd075aSAsmitha Karunanithi             "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType",
102168dd075aSAsmitha Karunanithi             "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client");
1022f574a8e1SCarson Labrado     }
102368dd075aSAsmitha Karunanithi 
1024a43be80fSAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
10255e7e2dc5SEd Tanous         [asyncResp, payload(task::Payload(req)),
10265e7e2dc5SEd Tanous          dumpPath](const boost::system::error_code& ec,
10275e7e2dc5SEd Tanous                    const sdbusplus::message_t& msg,
10288e31778eSAsmitha Karunanithi                    const sdbusplus::message::object_path& objPath) mutable {
1029a43be80fSAsmitha Karunanithi             if (ec)
1030a43be80fSAsmitha Karunanithi             {
103162598e31SEd Tanous                 BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec);
10325907571dSAsmitha Karunanithi                 const sd_bus_error* dbusError = msg.get_error();
10335907571dSAsmitha Karunanithi                 if (dbusError == nullptr)
10345907571dSAsmitha Karunanithi                 {
10355907571dSAsmitha Karunanithi                     messages::internalError(asyncResp->res);
10365907571dSAsmitha Karunanithi                     return;
10375907571dSAsmitha Karunanithi                 }
10385907571dSAsmitha Karunanithi 
103962598e31SEd Tanous                 BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}",
104062598e31SEd Tanous                                  dbusError->name, dbusError->message);
10415907571dSAsmitha Karunanithi                 if (std::string_view(
10425907571dSAsmitha Karunanithi                         "xyz.openbmc_project.Common.Error.NotAllowed") ==
10435907571dSAsmitha Karunanithi                     dbusError->name)
10445907571dSAsmitha Karunanithi                 {
10455907571dSAsmitha Karunanithi                     messages::resourceInStandby(asyncResp->res);
10465907571dSAsmitha Karunanithi                     return;
10475907571dSAsmitha Karunanithi                 }
10485907571dSAsmitha Karunanithi                 if (std::string_view(
10495907571dSAsmitha Karunanithi                         "xyz.openbmc_project.Dump.Create.Error.Disabled") ==
10505907571dSAsmitha Karunanithi                     dbusError->name)
10515907571dSAsmitha Karunanithi                 {
10525907571dSAsmitha Karunanithi                     messages::serviceDisabled(asyncResp->res, dumpPath);
10535907571dSAsmitha Karunanithi                     return;
10545907571dSAsmitha Karunanithi                 }
10555907571dSAsmitha Karunanithi                 if (std::string_view(
10565907571dSAsmitha Karunanithi                         "xyz.openbmc_project.Common.Error.Unavailable") ==
10575907571dSAsmitha Karunanithi                     dbusError->name)
10585907571dSAsmitha Karunanithi                 {
10595907571dSAsmitha Karunanithi                     messages::resourceInUse(asyncResp->res);
10605907571dSAsmitha Karunanithi                     return;
10615907571dSAsmitha Karunanithi                 }
10625907571dSAsmitha Karunanithi                 // Other Dbus errors such as:
10635907571dSAsmitha Karunanithi                 // xyz.openbmc_project.Common.Error.InvalidArgument &
10645907571dSAsmitha Karunanithi                 // org.freedesktop.DBus.Error.InvalidArgs are all related to
10655907571dSAsmitha Karunanithi                 // the dbus call that is made here in the bmcweb
10665907571dSAsmitha Karunanithi                 // implementation and has nothing to do with the client's
10675907571dSAsmitha Karunanithi                 // input in the request. Hence, returning internal error
10685907571dSAsmitha Karunanithi                 // back to the client.
1069a43be80fSAsmitha Karunanithi                 messages::internalError(asyncResp->res);
1070a43be80fSAsmitha Karunanithi                 return;
1071a43be80fSAsmitha Karunanithi             }
107262598e31SEd Tanous             BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str);
10738e31778eSAsmitha Karunanithi             createDumpTaskCallback(std::move(payload), asyncResp, objPath);
1074a43be80fSAsmitha Karunanithi         },
107518f8f608SEd Tanous         "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
10768e31778eSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec);
1077a43be80fSAsmitha Karunanithi }
1078a43be80fSAsmitha Karunanithi 
10798d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
10808d1b46d7Szhanghch05                       const std::string& dumpType)
108180319af1SAsmitha Karunanithi {
10820d946211SClaire Weinan     crow::connections::systemBus->async_method_call(
10830d946211SClaire Weinan         [asyncResp](const boost::system::error_code& ec) {
108480319af1SAsmitha Karunanithi             if (ec)
108580319af1SAsmitha Karunanithi             {
108662598e31SEd Tanous                 BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec);
108780319af1SAsmitha Karunanithi                 messages::internalError(asyncResp->res);
108880319af1SAsmitha Karunanithi                 return;
108980319af1SAsmitha Karunanithi             }
10900d946211SClaire Weinan         },
109118f8f608SEd Tanous         "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
10920d946211SClaire Weinan         "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
109380319af1SAsmitha Karunanithi }
109480319af1SAsmitha Karunanithi 
1095bd79bce8SPatrick Williams inline void parseCrashdumpParameters(
1096bd79bce8SPatrick Williams     const dbus::utility::DBusPropertiesMap& params, std::string& filename,
1097bd79bce8SPatrick Williams     std::string& timestamp, std::string& logfile)
1098043a0536SJohnathan Mantey {
1099d1bde9e5SKrzysztof Grobelny     const std::string* filenamePtr = nullptr;
1100d1bde9e5SKrzysztof Grobelny     const std::string* timestampPtr = nullptr;
1101d1bde9e5SKrzysztof Grobelny     const std::string* logfilePtr = nullptr;
1102d1bde9e5SKrzysztof Grobelny 
1103d1bde9e5SKrzysztof Grobelny     const bool success = sdbusplus::unpackPropertiesNoThrow(
1104d1bde9e5SKrzysztof Grobelny         dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr,
1105d1bde9e5SKrzysztof Grobelny         "Filename", filenamePtr, "Log", logfilePtr);
1106d1bde9e5SKrzysztof Grobelny 
1107d1bde9e5SKrzysztof Grobelny     if (!success)
1108043a0536SJohnathan Mantey     {
1109d1bde9e5SKrzysztof Grobelny         return;
1110043a0536SJohnathan Mantey     }
1111d1bde9e5SKrzysztof Grobelny 
1112d1bde9e5SKrzysztof Grobelny     if (filenamePtr != nullptr)
1113043a0536SJohnathan Mantey     {
1114d1bde9e5SKrzysztof Grobelny         filename = *filenamePtr;
1115d1bde9e5SKrzysztof Grobelny     }
1116d1bde9e5SKrzysztof Grobelny 
1117d1bde9e5SKrzysztof Grobelny     if (timestampPtr != nullptr)
1118043a0536SJohnathan Mantey     {
1119d1bde9e5SKrzysztof Grobelny         timestamp = *timestampPtr;
1120043a0536SJohnathan Mantey     }
1121d1bde9e5SKrzysztof Grobelny 
1122d1bde9e5SKrzysztof Grobelny     if (logfilePtr != nullptr)
1123043a0536SJohnathan Mantey     {
1124d1bde9e5SKrzysztof Grobelny         logfile = *logfilePtr;
1125043a0536SJohnathan Mantey     }
1126043a0536SJohnathan Mantey }
1127043a0536SJohnathan Mantey 
11287e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app)
11291da66f75SEd Tanous {
1130c4bf6374SJason M. Bills     /**
1131c4bf6374SJason M. Bills      * Functions triggers appropriate requests on DBus
1132c4bf6374SJason M. Bills      */
113322d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
1134ed398213SEd Tanous         .privileges(redfish::privileges::getLogServiceCollection)
1135bd79bce8SPatrick Williams         .methods(
1136bd79bce8SPatrick Williams             boost::beast::http::verb::
1137bd79bce8SPatrick Williams                 get)([&app](const crow::Request& req,
113822d268cbSEd Tanous                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
113922d268cbSEd Tanous                             const std::string& systemName) {
11403ba00073SCarson Labrado             if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1141c4bf6374SJason M. Bills             {
114245ca1b86SEd Tanous                 return;
114345ca1b86SEd Tanous             }
114425b54dbaSEd Tanous             if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
11457f3e84a1SEd Tanous             {
11467f3e84a1SEd Tanous                 // Option currently returns no systems.  TBD
11477f3e84a1SEd Tanous                 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
11487f3e84a1SEd Tanous                                            systemName);
11497f3e84a1SEd Tanous                 return;
11507f3e84a1SEd Tanous             }
1151253f11b8SEd Tanous             if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
115222d268cbSEd Tanous             {
115322d268cbSEd Tanous                 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
115422d268cbSEd Tanous                                            systemName);
115522d268cbSEd Tanous                 return;
115622d268cbSEd Tanous             }
115722d268cbSEd Tanous 
11587e860f15SJohn Edward Broadbent             // Collections don't include the static data added by SubRoute
11597e860f15SJohn Edward Broadbent             // because it has a duplicate entry for members
1160c4bf6374SJason M. Bills             asyncResp->res.jsonValue["@odata.type"] =
1161c4bf6374SJason M. Bills                 "#LogServiceCollection.LogServiceCollection";
1162c4bf6374SJason M. Bills             asyncResp->res.jsonValue["@odata.id"] =
1163253f11b8SEd Tanous                 std::format("/redfish/v1/Systems/{}/LogServices",
1164253f11b8SEd Tanous                             BMCWEB_REDFISH_SYSTEM_URI_NAME);
116545ca1b86SEd Tanous             asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
1166c4bf6374SJason M. Bills             asyncResp->res.jsonValue["Description"] =
1167c4bf6374SJason M. Bills                 "Collection of LogServices for this Computer System";
1168bd79bce8SPatrick Williams             nlohmann::json& logServiceArray =
1169bd79bce8SPatrick Williams                 asyncResp->res.jsonValue["Members"];
1170c4bf6374SJason M. Bills             logServiceArray = nlohmann::json::array();
11711476687dSEd Tanous             nlohmann::json::object_t eventLog;
11721476687dSEd Tanous             eventLog["@odata.id"] =
1173253f11b8SEd Tanous                 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1174253f11b8SEd Tanous                             BMCWEB_REDFISH_SYSTEM_URI_NAME);
1175b2ba3072SPatrick Williams             logServiceArray.emplace_back(std::move(eventLog));
117625b54dbaSEd Tanous             if constexpr (BMCWEB_REDFISH_DUMP_LOG)
117725b54dbaSEd Tanous             {
11781476687dSEd Tanous                 nlohmann::json::object_t dumpLog;
117925b54dbaSEd Tanous                 dumpLog["@odata.id"] =
1180253f11b8SEd Tanous                     std::format("/redfish/v1/Systems/{}/LogServices/Dump",
1181253f11b8SEd Tanous                                 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1182b2ba3072SPatrick Williams                 logServiceArray.emplace_back(std::move(dumpLog));
118325b54dbaSEd Tanous             }
1184c9bb6861Sraviteja-b 
11855ffd11f2SGunnar Mills             if constexpr (BMCWEB_REDFISH_CPU_LOG)
118625b54dbaSEd Tanous             {
11871476687dSEd Tanous                 nlohmann::json::object_t crashdump;
11881476687dSEd Tanous                 crashdump["@odata.id"] =
1189253f11b8SEd Tanous                     std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
1190253f11b8SEd Tanous                                 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1191b2ba3072SPatrick Williams                 logServiceArray.emplace_back(std::move(crashdump));
119225b54dbaSEd Tanous             }
1193b7028ebfSSpencer Ku 
119425b54dbaSEd Tanous             if constexpr (BMCWEB_REDFISH_HOST_LOGGER)
119525b54dbaSEd Tanous             {
11961476687dSEd Tanous                 nlohmann::json::object_t hostlogger;
11971476687dSEd Tanous                 hostlogger["@odata.id"] =
1198253f11b8SEd Tanous                     std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
1199253f11b8SEd Tanous                                 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1200b2ba3072SPatrick Williams                 logServiceArray.emplace_back(std::move(hostlogger));
120125b54dbaSEd Tanous             }
1202c4bf6374SJason M. Bills             asyncResp->res.jsonValue["Members@odata.count"] =
1203c4bf6374SJason M. Bills                 logServiceArray.size();
1204a3316fc6SZhikuiRen 
12057a1dbc48SGeorge Liu             constexpr std::array<std::string_view, 1> interfaces = {
12067a1dbc48SGeorge Liu                 "xyz.openbmc_project.State.Boot.PostCode"};
12077a1dbc48SGeorge Liu             dbus::utility::getSubTreePaths(
12087a1dbc48SGeorge Liu                 "/", 0, interfaces,
12097a1dbc48SGeorge Liu                 [asyncResp](const boost::system::error_code& ec,
1210b9d36b47SEd Tanous                             const dbus::utility::MapperGetSubTreePathsResponse&
1211b9d36b47SEd Tanous                                 subtreePath) {
1212a3316fc6SZhikuiRen                     if (ec)
1213a3316fc6SZhikuiRen                     {
121462598e31SEd Tanous                         BMCWEB_LOG_ERROR("{}", ec);
1215a3316fc6SZhikuiRen                         return;
1216a3316fc6SZhikuiRen                     }
1217a3316fc6SZhikuiRen 
121855f79e6fSEd Tanous                     for (const auto& pathStr : subtreePath)
1219a3316fc6SZhikuiRen                     {
1220a3316fc6SZhikuiRen                         if (pathStr.find("PostCode") != std::string::npos)
1221a3316fc6SZhikuiRen                         {
122223a21a1cSEd Tanous                             nlohmann::json& logServiceArrayLocal =
1223a3316fc6SZhikuiRen                                 asyncResp->res.jsonValue["Members"];
1224613dabeaSEd Tanous                             nlohmann::json::object_t member;
1225253f11b8SEd Tanous                             member["@odata.id"] = std::format(
1226253f11b8SEd Tanous                                 "/redfish/v1/Systems/{}/LogServices/PostCodes",
1227253f11b8SEd Tanous                                 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1228613dabeaSEd Tanous 
1229bd79bce8SPatrick Williams                             logServiceArrayLocal.emplace_back(
1230bd79bce8SPatrick Williams                                 std::move(member));
1231613dabeaSEd Tanous 
123245ca1b86SEd Tanous                             asyncResp->res.jsonValue["Members@odata.count"] =
123323a21a1cSEd Tanous                                 logServiceArrayLocal.size();
1234a3316fc6SZhikuiRen                             return;
1235a3316fc6SZhikuiRen                         }
1236a3316fc6SZhikuiRen                     }
12377a1dbc48SGeorge Liu                 });
12387e860f15SJohn Edward Broadbent         });
1239c4bf6374SJason M. Bills }
1240c4bf6374SJason M. Bills 
12417e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app)
1242c4bf6374SJason M. Bills {
124322d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/")
1244ed398213SEd Tanous         .privileges(redfish::privileges::getLogService)
1245bd79bce8SPatrick Williams         .methods(
1246bd79bce8SPatrick Williams             boost::beast::http::verb::
1247bd79bce8SPatrick Williams                 get)([&app](const crow::Request& req,
124822d268cbSEd Tanous                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
124922d268cbSEd Tanous                             const std::string& systemName) {
12503ba00073SCarson Labrado             if (!redfish::setUpRedfishRoute(app, req, asyncResp))
125145ca1b86SEd Tanous             {
125245ca1b86SEd Tanous                 return;
125345ca1b86SEd Tanous             }
1254253f11b8SEd Tanous             if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
125522d268cbSEd Tanous             {
125622d268cbSEd Tanous                 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
125722d268cbSEd Tanous                                            systemName);
125822d268cbSEd Tanous                 return;
125922d268cbSEd Tanous             }
1260c4bf6374SJason M. Bills             asyncResp->res.jsonValue["@odata.id"] =
1261253f11b8SEd Tanous                 std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
1262253f11b8SEd Tanous                             BMCWEB_REDFISH_SYSTEM_URI_NAME);
1263c4bf6374SJason M. Bills             asyncResp->res.jsonValue["@odata.type"] =
1264b25644a1SJanet Adkins                 "#LogService.v1_2_0.LogService";
1265c4bf6374SJason M. Bills             asyncResp->res.jsonValue["Name"] = "Event Log Service";
1266bd79bce8SPatrick Williams             asyncResp->res.jsonValue["Description"] =
1267bd79bce8SPatrick Williams                 "System Event Log Service";
1268c4bf6374SJason M. Bills             asyncResp->res.jsonValue["Id"] = "EventLog";
1269539d8c6bSEd Tanous             asyncResp->res.jsonValue["OverWritePolicy"] =
1270539d8c6bSEd Tanous                 log_service::OverWritePolicy::WrapsWhenFull;
12717c8c4058STejas Patil 
12727c8c4058STejas Patil             std::pair<std::string, std::string> redfishDateTimeOffset =
12732b82937eSEd Tanous                 redfish::time_utils::getDateTimeOffsetNow();
12747c8c4058STejas Patil 
12757c8c4058STejas Patil             asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
12767c8c4058STejas Patil             asyncResp->res.jsonValue["DateTimeLocalOffset"] =
12777c8c4058STejas Patil                 redfishDateTimeOffset.second;
12787c8c4058STejas Patil 
1279bd79bce8SPatrick Williams             asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format(
1280bd79bce8SPatrick Williams                 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1281253f11b8SEd Tanous                 BMCWEB_REDFISH_SYSTEM_URI_NAME);
1282bd79bce8SPatrick Williams             asyncResp->res
1283bd79bce8SPatrick Williams                 .jsonValue["Actions"]["#LogService.ClearLog"]["target"]
1284e7d6c8b2SGunnar Mills 
128520fa6a2cSEd Tanous                 = std::format(
1286253f11b8SEd Tanous                     "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog",
128720fa6a2cSEd Tanous                     BMCWEB_REDFISH_SYSTEM_URI_NAME);
12887e860f15SJohn Edward Broadbent         });
1289489640c6SJason M. Bills }
1290489640c6SJason M. Bills 
1291599b9af3SAlexander Hansen inline void handleSystemsLogServicesEventLogActionsClearPost(
1292599b9af3SAlexander Hansen     App& app, const crow::Request& req,
129322d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1294599b9af3SAlexander Hansen     const std::string& systemName)
1295599b9af3SAlexander Hansen {
12963ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
129745ca1b86SEd Tanous     {
129845ca1b86SEd Tanous         return;
129945ca1b86SEd Tanous     }
1300253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
130122d268cbSEd Tanous     {
130222d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
130322d268cbSEd Tanous                                    systemName);
130422d268cbSEd Tanous         return;
130522d268cbSEd Tanous     }
1306599b9af3SAlexander Hansen 
1307489640c6SJason M. Bills     // Clear the EventLog by deleting the log files
1308489640c6SJason M. Bills     std::vector<std::filesystem::path> redfishLogFiles;
1309489640c6SJason M. Bills     if (getRedfishLogFiles(redfishLogFiles))
1310489640c6SJason M. Bills     {
1311489640c6SJason M. Bills         for (const std::filesystem::path& file : redfishLogFiles)
1312489640c6SJason M. Bills         {
1313489640c6SJason M. Bills             std::error_code ec;
1314489640c6SJason M. Bills             std::filesystem::remove(file, ec);
1315489640c6SJason M. Bills         }
1316489640c6SJason M. Bills     }
1317489640c6SJason M. Bills 
1318489640c6SJason M. Bills     // Reload rsyslog so it knows to start new log files
1319489640c6SJason M. Bills     crow::connections::systemBus->async_method_call(
13205e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
1321489640c6SJason M. Bills             if (ec)
1322489640c6SJason M. Bills             {
132362598e31SEd Tanous                 BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec);
1324489640c6SJason M. Bills                 messages::internalError(asyncResp->res);
1325489640c6SJason M. Bills                 return;
1326489640c6SJason M. Bills             }
1327489640c6SJason M. Bills 
1328489640c6SJason M. Bills             messages::success(asyncResp->res);
1329489640c6SJason M. Bills         },
1330489640c6SJason M. Bills         "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1331002d39b4SEd Tanous         "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1332002d39b4SEd Tanous         "replace");
1333599b9af3SAlexander Hansen }
1334599b9af3SAlexander Hansen 
1335599b9af3SAlexander Hansen inline void requestRoutesJournalEventLogClear(App& app)
1336599b9af3SAlexander Hansen {
1337599b9af3SAlexander Hansen     BMCWEB_ROUTE(
1338599b9af3SAlexander Hansen         app,
1339599b9af3SAlexander Hansen         "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
1340599b9af3SAlexander Hansen         .privileges({{"ConfigureComponents"}})
1341599b9af3SAlexander Hansen         .methods(boost::beast::http::verb::post)(std::bind_front(
1342599b9af3SAlexander Hansen             handleSystemsLogServicesEventLogActionsClearPost, std::ref(app)));
1343c4bf6374SJason M. Bills }
1344c4bf6374SJason M. Bills 
1345ac992cdeSJason M. Bills enum class LogParseError
1346ac992cdeSJason M. Bills {
1347ac992cdeSJason M. Bills     success,
1348ac992cdeSJason M. Bills     parseFailed,
1349ac992cdeSJason M. Bills     messageIdNotInRegistry,
1350ac992cdeSJason M. Bills };
1351ac992cdeSJason M. Bills 
1352bd79bce8SPatrick Williams static LogParseError fillEventLogEntryJson(
1353bd79bce8SPatrick Williams     const std::string& logEntryID, const std::string& logEntry,
1354de703c5dSJason M. Bills     nlohmann::json::object_t& logEntryJson)
1355c4bf6374SJason M. Bills {
135695820184SJason M. Bills     // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
1357cd225da8SJason M. Bills     // First get the Timestamp
1358f23b7296SEd Tanous     size_t space = logEntry.find_first_of(' ');
1359cd225da8SJason M. Bills     if (space == std::string::npos)
136095820184SJason M. Bills     {
1361ac992cdeSJason M. Bills         return LogParseError::parseFailed;
136295820184SJason M. Bills     }
1363cd225da8SJason M. Bills     std::string timestamp = logEntry.substr(0, space);
1364cd225da8SJason M. Bills     // Then get the log contents
1365f23b7296SEd Tanous     size_t entryStart = logEntry.find_first_not_of(' ', space);
1366cd225da8SJason M. Bills     if (entryStart == std::string::npos)
1367cd225da8SJason M. Bills     {
1368ac992cdeSJason M. Bills         return LogParseError::parseFailed;
1369cd225da8SJason M. Bills     }
1370cd225da8SJason M. Bills     std::string_view entry(logEntry);
1371cd225da8SJason M. Bills     entry.remove_prefix(entryStart);
1372cd225da8SJason M. Bills     // Use split to separate the entry into its fields
1373cd225da8SJason M. Bills     std::vector<std::string> logEntryFields;
137450ebd4afSEd Tanous     bmcweb::split(logEntryFields, entry, ',');
1375cd225da8SJason M. Bills     // We need at least a MessageId to be valid
13761e6deaf6SEd Tanous     auto logEntryIter = logEntryFields.begin();
13771e6deaf6SEd Tanous     if (logEntryIter == logEntryFields.end())
1378cd225da8SJason M. Bills     {
1379ac992cdeSJason M. Bills         return LogParseError::parseFailed;
1380cd225da8SJason M. Bills     }
13811e6deaf6SEd Tanous     std::string& messageID = *logEntryIter;
13824851d45dSJason M. Bills     // Get the Message from the MessageRegistry
1383fffb8c1fSEd Tanous     const registries::Message* message = registries::getMessage(messageID);
1384c4bf6374SJason M. Bills 
13851e6deaf6SEd Tanous     logEntryIter++;
138654417b02SSui Chen     if (message == nullptr)
1387c4bf6374SJason M. Bills     {
138862598e31SEd Tanous         BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry);
1389ac992cdeSJason M. Bills         return LogParseError::messageIdNotInRegistry;
1390c4bf6374SJason M. Bills     }
1391c4bf6374SJason M. Bills 
13921e6deaf6SEd Tanous     std::vector<std::string_view> messageArgs(logEntryIter,
13931e6deaf6SEd Tanous                                               logEntryFields.end());
1394c05bba45SEd Tanous     messageArgs.resize(message->numberOfArgs);
1395c05bba45SEd Tanous 
1396bd79bce8SPatrick Williams     std::string msg =
1397bd79bce8SPatrick Williams         redfish::registries::fillMessageArgs(messageArgs, message->message);
13981e6deaf6SEd Tanous     if (msg.empty())
139915a86ff6SJason M. Bills     {
14001e6deaf6SEd Tanous         return LogParseError::parseFailed;
140115a86ff6SJason M. Bills     }
14024851d45dSJason M. Bills 
140395820184SJason M. Bills     // Get the Created time from the timestamp. The log timestamp is in RFC3339
140495820184SJason M. Bills     // format which matches the Redfish format except for the fractional seconds
140595820184SJason M. Bills     // between the '.' and the '+', so just remove them.
1406f23b7296SEd Tanous     std::size_t dot = timestamp.find_first_of('.');
1407f23b7296SEd Tanous     std::size_t plus = timestamp.find_first_of('+');
140895820184SJason M. Bills     if (dot != std::string::npos && plus != std::string::npos)
1409c4bf6374SJason M. Bills     {
141095820184SJason M. Bills         timestamp.erase(dot, plus - dot);
1411c4bf6374SJason M. Bills     }
1412c4bf6374SJason M. Bills 
1413c4bf6374SJason M. Bills     // Fill in the log entry with the gathered data
14149c11a172SVijay Lobo     logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1415ef4c65b7SEd Tanous     logEntryJson["@odata.id"] = boost::urls::format(
1416253f11b8SEd Tanous         "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1417253f11b8SEd Tanous         BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID);
141884afc48bSJason M. Bills     logEntryJson["Name"] = "System Event Log Entry";
141984afc48bSJason M. Bills     logEntryJson["Id"] = logEntryID;
142084afc48bSJason M. Bills     logEntryJson["Message"] = std::move(msg);
142184afc48bSJason M. Bills     logEntryJson["MessageId"] = std::move(messageID);
142284afc48bSJason M. Bills     logEntryJson["MessageArgs"] = messageArgs;
142384afc48bSJason M. Bills     logEntryJson["EntryType"] = "Event";
142484afc48bSJason M. Bills     logEntryJson["Severity"] = message->messageSeverity;
142584afc48bSJason M. Bills     logEntryJson["Created"] = std::move(timestamp);
1426ac992cdeSJason M. Bills     return LogParseError::success;
1427c4bf6374SJason M. Bills }
1428c4bf6374SJason M. Bills 
1429898f2aa2SEd Tanous inline void fillEventLogLogEntryFromPropertyMap(
1430898f2aa2SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1431898f2aa2SEd Tanous     const dbus::utility::DBusPropertiesMap& resp,
1432898f2aa2SEd Tanous     nlohmann::json& objectToFillOut)
1433898f2aa2SEd Tanous {
1434262dcc1cSAlexander Hansen     std::optional<DbusEventLogEntry> optEntry =
1435262dcc1cSAlexander Hansen         fillDbusEventLogEntryFromPropertyMap(resp);
1436898f2aa2SEd Tanous 
1437262dcc1cSAlexander Hansen     if (!optEntry.has_value())
1438898f2aa2SEd Tanous     {
1439898f2aa2SEd Tanous         messages::internalError(asyncResp->res);
1440898f2aa2SEd Tanous         return;
1441898f2aa2SEd Tanous     }
1442262dcc1cSAlexander Hansen     DbusEventLogEntry entry = optEntry.value();
1443898f2aa2SEd Tanous 
1444898f2aa2SEd Tanous     objectToFillOut["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1445898f2aa2SEd Tanous     objectToFillOut["@odata.id"] = boost::urls::format(
1446898f2aa2SEd Tanous         "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
1447262dcc1cSAlexander Hansen         BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
1448898f2aa2SEd Tanous     objectToFillOut["Name"] = "System Event Log Entry";
1449262dcc1cSAlexander Hansen     objectToFillOut["Id"] = std::to_string(entry.Id);
1450262dcc1cSAlexander Hansen     objectToFillOut["Message"] = entry.Message;
1451262dcc1cSAlexander Hansen     objectToFillOut["Resolved"] = entry.Resolved;
1452262dcc1cSAlexander Hansen     std::optional<bool> notifyAction =
1453262dcc1cSAlexander Hansen         getProviderNotifyAction(entry.ServiceProviderNotify);
1454898f2aa2SEd Tanous     if (notifyAction)
1455898f2aa2SEd Tanous     {
1456898f2aa2SEd Tanous         objectToFillOut["ServiceProviderNotified"] = *notifyAction;
1457898f2aa2SEd Tanous     }
1458262dcc1cSAlexander Hansen     if ((entry.Resolution != nullptr) && !entry.Resolution->empty())
1459898f2aa2SEd Tanous     {
1460262dcc1cSAlexander Hansen         objectToFillOut["Resolution"] = *entry.Resolution;
1461898f2aa2SEd Tanous     }
1462898f2aa2SEd Tanous     objectToFillOut["EntryType"] = "Event";
1463262dcc1cSAlexander Hansen     objectToFillOut["Severity"] =
1464262dcc1cSAlexander Hansen         translateSeverityDbusToRedfish(entry.Severity);
1465898f2aa2SEd Tanous     objectToFillOut["Created"] =
1466262dcc1cSAlexander Hansen         redfish::time_utils::getDateTimeUintMs(entry.Timestamp);
1467898f2aa2SEd Tanous     objectToFillOut["Modified"] =
1468262dcc1cSAlexander Hansen         redfish::time_utils::getDateTimeUintMs(entry.UpdateTimestamp);
1469262dcc1cSAlexander Hansen     if (entry.Path != nullptr)
1470898f2aa2SEd Tanous     {
1471898f2aa2SEd Tanous         objectToFillOut["AdditionalDataURI"] = boost::urls::format(
1472898f2aa2SEd Tanous             "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment",
1473262dcc1cSAlexander Hansen             BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
1474898f2aa2SEd Tanous     }
1475898f2aa2SEd Tanous }
1476898f2aa2SEd Tanous 
1477b729096dSEd Tanous inline void afterLogEntriesGetManagedObjects(
1478b729096dSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1479b729096dSEd Tanous     const boost::system::error_code& ec,
1480b729096dSEd Tanous     const dbus::utility::ManagedObjectType& resp)
1481b729096dSEd Tanous {
1482b729096dSEd Tanous     if (ec)
1483b729096dSEd Tanous     {
1484b729096dSEd Tanous         // TODO Handle for specific error code
1485b729096dSEd Tanous         BMCWEB_LOG_ERROR("getLogEntriesIfaceData resp_handler got error {}",
1486b729096dSEd Tanous                          ec);
1487b729096dSEd Tanous         messages::internalError(asyncResp->res);
1488b729096dSEd Tanous         return;
1489b729096dSEd Tanous     }
1490b729096dSEd Tanous     nlohmann::json::array_t entriesArray;
1491b729096dSEd Tanous     for (const auto& objectPath : resp)
1492b729096dSEd Tanous     {
1493898f2aa2SEd Tanous         dbus::utility::DBusPropertiesMap propsFlattened;
1494bd79bce8SPatrick Williams         auto isEntry =
1495bd79bce8SPatrick Williams             std::ranges::find_if(objectPath.second, [](const auto& object) {
1496898f2aa2SEd Tanous                 return object.first == "xyz.openbmc_project.Logging.Entry";
1497898f2aa2SEd Tanous             });
1498898f2aa2SEd Tanous         if (isEntry == objectPath.second.end())
1499b729096dSEd Tanous         {
1500b729096dSEd Tanous             continue;
1501b729096dSEd Tanous         }
1502898f2aa2SEd Tanous         for (const auto& interfaceMap : objectPath.second)
1503b729096dSEd Tanous         {
1504898f2aa2SEd Tanous             for (const auto& propertyMap : interfaceMap.second)
1505b729096dSEd Tanous             {
1506898f2aa2SEd Tanous                 propsFlattened.emplace_back(propertyMap.first,
1507898f2aa2SEd Tanous                                             propertyMap.second);
1508b729096dSEd Tanous             }
1509b729096dSEd Tanous         }
1510898f2aa2SEd Tanous         fillEventLogLogEntryFromPropertyMap(asyncResp, propsFlattened,
1511898f2aa2SEd Tanous                                             entriesArray.emplace_back());
1512b729096dSEd Tanous     }
1513898f2aa2SEd Tanous 
1514b729096dSEd Tanous     std::ranges::sort(entriesArray, [](const nlohmann::json& left,
1515b729096dSEd Tanous                                        const nlohmann::json& right) {
1516b729096dSEd Tanous         return (left["Id"] <= right["Id"]);
1517b729096dSEd Tanous     });
1518b729096dSEd Tanous     asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
1519b729096dSEd Tanous     asyncResp->res.jsonValue["Members"] = std::move(entriesArray);
1520b729096dSEd Tanous }
1521b729096dSEd Tanous 
1522599b9af3SAlexander Hansen inline void handleSystemsLogServiceEventLogLogEntryCollection(
1523599b9af3SAlexander Hansen     App& app, const crow::Request& req,
152422d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1525599b9af3SAlexander Hansen     const std::string& systemName)
1526599b9af3SAlexander Hansen {
1527c937d2bfSEd Tanous     query_param::QueryCapabilities capabilities = {
1528c937d2bfSEd Tanous         .canDelegateTop = true,
1529c937d2bfSEd Tanous         .canDelegateSkip = true,
1530c937d2bfSEd Tanous     };
1531c937d2bfSEd Tanous     query_param::Query delegatedQuery;
1532599b9af3SAlexander Hansen     if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp,
1533599b9af3SAlexander Hansen                                                   delegatedQuery, capabilities))
1534c4bf6374SJason M. Bills     {
1535c4bf6374SJason M. Bills         return;
1536c4bf6374SJason M. Bills     }
153725b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
15387f3e84a1SEd Tanous     {
15397f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
15407f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
15417f3e84a1SEd Tanous                                    systemName);
15427f3e84a1SEd Tanous         return;
15437f3e84a1SEd Tanous     }
1544253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
154522d268cbSEd Tanous     {
154622d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
154722d268cbSEd Tanous                                    systemName);
154822d268cbSEd Tanous         return;
154922d268cbSEd Tanous     }
155022d268cbSEd Tanous 
15515143f7a5SJiaqing Zhao     size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
15523648c8beSEd Tanous     size_t skip = delegatedQuery.skip.value_or(0);
15533648c8beSEd Tanous 
15547e860f15SJohn Edward Broadbent     // Collections don't include the static data added by SubRoute
15557e860f15SJohn Edward Broadbent     // because it has a duplicate entry for members
1556c4bf6374SJason M. Bills     asyncResp->res.jsonValue["@odata.type"] =
1557c4bf6374SJason M. Bills         "#LogEntryCollection.LogEntryCollection";
1558c4bf6374SJason M. Bills     asyncResp->res.jsonValue["@odata.id"] =
1559253f11b8SEd Tanous         std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1560253f11b8SEd Tanous                     BMCWEB_REDFISH_SYSTEM_URI_NAME);
1561c4bf6374SJason M. Bills     asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1562c4bf6374SJason M. Bills     asyncResp->res.jsonValue["Description"] =
1563c4bf6374SJason M. Bills         "Collection of System Event Log Entries";
1564cb92c03bSAndrew Geissler 
15654978b63fSJason M. Bills     nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1566c4bf6374SJason M. Bills     logEntryArray = nlohmann::json::array();
15677e860f15SJohn Edward Broadbent     // Go through the log files and create a unique ID for each
15687e860f15SJohn Edward Broadbent     // entry
156995820184SJason M. Bills     std::vector<std::filesystem::path> redfishLogFiles;
157095820184SJason M. Bills     getRedfishLogFiles(redfishLogFiles);
1571b01bf299SEd Tanous     uint64_t entryCount = 0;
1572cd225da8SJason M. Bills     std::string logEntry;
157395820184SJason M. Bills 
15747e860f15SJohn Edward Broadbent     // Oldest logs are in the last file, so start there and loop
15757e860f15SJohn Edward Broadbent     // backwards
1576599b9af3SAlexander Hansen     for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++)
1577c4bf6374SJason M. Bills     {
1578cd225da8SJason M. Bills         std::ifstream logStream(*it);
157995820184SJason M. Bills         if (!logStream.is_open())
1580c4bf6374SJason M. Bills         {
1581c4bf6374SJason M. Bills             continue;
1582c4bf6374SJason M. Bills         }
1583c4bf6374SJason M. Bills 
1584e85d6b16SJason M. Bills         // Reset the unique ID on the first entry
1585e85d6b16SJason M. Bills         bool firstEntry = true;
158695820184SJason M. Bills         while (std::getline(logStream, logEntry))
158795820184SJason M. Bills         {
1588c4bf6374SJason M. Bills             std::string idStr;
1589e85d6b16SJason M. Bills             if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1590c4bf6374SJason M. Bills             {
1591c4bf6374SJason M. Bills                 continue;
1592c4bf6374SJason M. Bills             }
1593e85d6b16SJason M. Bills             firstEntry = false;
1594e85d6b16SJason M. Bills 
1595de703c5dSJason M. Bills             nlohmann::json::object_t bmcLogEntry;
1596bd79bce8SPatrick Williams             LogParseError status =
1597bd79bce8SPatrick Williams                 fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
1598ac992cdeSJason M. Bills             if (status == LogParseError::messageIdNotInRegistry)
1599ac992cdeSJason M. Bills             {
1600ac992cdeSJason M. Bills                 continue;
1601ac992cdeSJason M. Bills             }
1602ac992cdeSJason M. Bills             if (status != LogParseError::success)
1603c4bf6374SJason M. Bills             {
1604c4bf6374SJason M. Bills                 messages::internalError(asyncResp->res);
1605c4bf6374SJason M. Bills                 return;
1606c4bf6374SJason M. Bills             }
1607de703c5dSJason M. Bills 
1608de703c5dSJason M. Bills             entryCount++;
1609de703c5dSJason M. Bills             // Handle paging using skip (number of entries to skip from the
1610de703c5dSJason M. Bills             // start) and top (number of entries to display)
16113648c8beSEd Tanous             if (entryCount <= skip || entryCount > skip + top)
1612de703c5dSJason M. Bills             {
1613de703c5dSJason M. Bills                 continue;
1614de703c5dSJason M. Bills             }
1615de703c5dSJason M. Bills 
1616b2ba3072SPatrick Williams             logEntryArray.emplace_back(std::move(bmcLogEntry));
1617c4bf6374SJason M. Bills         }
161895820184SJason M. Bills     }
1619c4bf6374SJason M. Bills     asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
16203648c8beSEd Tanous     if (skip + top < entryCount)
1621c4bf6374SJason M. Bills     {
1622599b9af3SAlexander Hansen         asyncResp->res.jsonValue["Members@odata.nextLink"] =
1623599b9af3SAlexander Hansen             boost::urls::format(
1624253f11b8SEd Tanous                 "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}",
1625253f11b8SEd Tanous                 BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top));
1626c4bf6374SJason M. Bills     }
1627897967deSJason M. Bills }
1628897967deSJason M. Bills 
1629599b9af3SAlexander Hansen inline void requestRoutesJournalEventLogEntryCollection(App& app)
1630897967deSJason M. Bills {
1631599b9af3SAlexander Hansen     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
1632599b9af3SAlexander Hansen         .privileges(redfish::privileges::getLogEntryCollection)
1633599b9af3SAlexander Hansen         .methods(boost::beast::http::verb::get)(std::bind_front(
1634599b9af3SAlexander Hansen             handleSystemsLogServiceEventLogLogEntryCollection, std::ref(app)));
1635599b9af3SAlexander Hansen }
1636599b9af3SAlexander Hansen 
1637599b9af3SAlexander Hansen inline void handleSystemsLogServiceEventLogEntriesGet(
1638599b9af3SAlexander Hansen     App& app, const crow::Request& req,
16397e860f15SJohn Edward Broadbent     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1640599b9af3SAlexander Hansen     const std::string& systemName, const std::string& param)
1641599b9af3SAlexander Hansen {
16423ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
164345ca1b86SEd Tanous     {
164445ca1b86SEd Tanous         return;
164545ca1b86SEd Tanous     }
164625b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
16477f3e84a1SEd Tanous     {
16487f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
16497f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
16507f3e84a1SEd Tanous                                    systemName);
16517f3e84a1SEd Tanous         return;
16527f3e84a1SEd Tanous     }
165322d268cbSEd Tanous 
1654253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
165522d268cbSEd Tanous     {
165622d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
165722d268cbSEd Tanous                                    systemName);
165822d268cbSEd Tanous         return;
165922d268cbSEd Tanous     }
166022d268cbSEd Tanous 
16617e860f15SJohn Edward Broadbent     const std::string& targetID = param;
16628d1b46d7Szhanghch05 
16637e860f15SJohn Edward Broadbent     // Go through the log files and check the unique ID for each
16647e860f15SJohn Edward Broadbent     // entry to find the target entry
1665897967deSJason M. Bills     std::vector<std::filesystem::path> redfishLogFiles;
1666897967deSJason M. Bills     getRedfishLogFiles(redfishLogFiles);
1667897967deSJason M. Bills     std::string logEntry;
1668897967deSJason M. Bills 
16697e860f15SJohn Edward Broadbent     // Oldest logs are in the last file, so start there and loop
16707e860f15SJohn Edward Broadbent     // backwards
1671599b9af3SAlexander Hansen     for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++)
1672897967deSJason M. Bills     {
1673897967deSJason M. Bills         std::ifstream logStream(*it);
1674897967deSJason M. Bills         if (!logStream.is_open())
1675897967deSJason M. Bills         {
1676897967deSJason M. Bills             continue;
1677897967deSJason M. Bills         }
1678897967deSJason M. Bills 
1679897967deSJason M. Bills         // Reset the unique ID on the first entry
1680897967deSJason M. Bills         bool firstEntry = true;
1681897967deSJason M. Bills         while (std::getline(logStream, logEntry))
1682897967deSJason M. Bills         {
1683897967deSJason M. Bills             std::string idStr;
1684897967deSJason M. Bills             if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1685897967deSJason M. Bills             {
1686897967deSJason M. Bills                 continue;
1687897967deSJason M. Bills             }
1688897967deSJason M. Bills             firstEntry = false;
1689897967deSJason M. Bills 
1690897967deSJason M. Bills             if (idStr == targetID)
1691897967deSJason M. Bills             {
1692de703c5dSJason M. Bills                 nlohmann::json::object_t bmcLogEntry;
1693bd79bce8SPatrick Williams                 LogParseError status =
1694bd79bce8SPatrick Williams                     fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
1695ac992cdeSJason M. Bills                 if (status != LogParseError::success)
1696897967deSJason M. Bills                 {
1697897967deSJason M. Bills                     messages::internalError(asyncResp->res);
1698897967deSJason M. Bills                     return;
1699897967deSJason M. Bills                 }
1700d405bb51SJason M. Bills                 asyncResp->res.jsonValue.update(bmcLogEntry);
1701897967deSJason M. Bills                 return;
1702897967deSJason M. Bills             }
1703897967deSJason M. Bills         }
1704897967deSJason M. Bills     }
1705897967deSJason M. Bills     // Requested ID was not found
17069db4ba25SJiaqing Zhao     messages::resourceNotFound(asyncResp->res, "LogEntry", targetID);
1707599b9af3SAlexander Hansen }
1708599b9af3SAlexander Hansen 
1709599b9af3SAlexander Hansen inline void requestRoutesJournalEventLogEntry(App& app)
1710599b9af3SAlexander Hansen {
1711599b9af3SAlexander Hansen     BMCWEB_ROUTE(
1712599b9af3SAlexander Hansen         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1713599b9af3SAlexander Hansen         .privileges(redfish::privileges::getLogEntry)
1714599b9af3SAlexander Hansen         .methods(boost::beast::http::verb::get)(std::bind_front(
1715599b9af3SAlexander Hansen             handleSystemsLogServiceEventLogEntriesGet, std::ref(app)));
1716599b9af3SAlexander Hansen }
1717599b9af3SAlexander Hansen 
1718599b9af3SAlexander Hansen inline void dBusEventLogEntryCollection(
1719599b9af3SAlexander Hansen     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1720599b9af3SAlexander Hansen {
1721599b9af3SAlexander Hansen     // Collections don't include the static data added by SubRoute
1722599b9af3SAlexander Hansen     // because it has a duplicate entry for members
1723599b9af3SAlexander Hansen     asyncResp->res.jsonValue["@odata.type"] =
1724599b9af3SAlexander Hansen         "#LogEntryCollection.LogEntryCollection";
1725599b9af3SAlexander Hansen     asyncResp->res.jsonValue["@odata.id"] =
1726599b9af3SAlexander Hansen         std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
1727599b9af3SAlexander Hansen                     BMCWEB_REDFISH_SYSTEM_URI_NAME);
1728599b9af3SAlexander Hansen     asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1729599b9af3SAlexander Hansen     asyncResp->res.jsonValue["Description"] =
1730599b9af3SAlexander Hansen         "Collection of System Event Log Entries";
1731599b9af3SAlexander Hansen 
1732599b9af3SAlexander Hansen     // DBus implementation of EventLog/Entries
1733599b9af3SAlexander Hansen     // Make call to Logging Service to find all log entry objects
1734599b9af3SAlexander Hansen     sdbusplus::message::object_path path("/xyz/openbmc_project/logging");
1735599b9af3SAlexander Hansen     dbus::utility::getManagedObjects(
1736599b9af3SAlexander Hansen         "xyz.openbmc_project.Logging", path,
1737599b9af3SAlexander Hansen         [asyncResp](const boost::system::error_code& ec,
1738599b9af3SAlexander Hansen                     const dbus::utility::ManagedObjectType& resp) {
1739b729096dSEd Tanous             afterLogEntriesGetManagedObjects(asyncResp, ec, resp);
17407e860f15SJohn Edward Broadbent         });
174108a4e4b5SAnthony Wilson }
174208a4e4b5SAnthony Wilson 
17437e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app)
174408a4e4b5SAnthony Wilson {
174522d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
1746ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntryCollection)
1747002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1748002d39b4SEd Tanous             [&app](const crow::Request& req,
174922d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
175022d268cbSEd Tanous                    const std::string& systemName) {
17513ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
175245ca1b86SEd Tanous                 {
175345ca1b86SEd Tanous                     return;
175445ca1b86SEd Tanous                 }
175525b54dbaSEd Tanous                 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
17567f3e84a1SEd Tanous                 {
17577f3e84a1SEd Tanous                     // Option currently returns no systems.  TBD
17587f3e84a1SEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
17597f3e84a1SEd Tanous                                                systemName);
17607f3e84a1SEd Tanous                     return;
17617f3e84a1SEd Tanous                 }
1762253f11b8SEd Tanous                 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
176322d268cbSEd Tanous                 {
176422d268cbSEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
176522d268cbSEd Tanous                                                systemName);
176622d268cbSEd Tanous                     return;
176722d268cbSEd Tanous                 }
1768599b9af3SAlexander Hansen                 dBusEventLogEntryCollection(asyncResp);
1769599b9af3SAlexander Hansen             });
1770599b9af3SAlexander Hansen }
177122d268cbSEd Tanous 
1772bd79bce8SPatrick Williams inline void dBusEventLogEntryGet(
1773bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID)
1774599b9af3SAlexander Hansen {
1775599b9af3SAlexander Hansen     dbus::utility::escapePathForDbus(entryID);
177608a4e4b5SAnthony Wilson 
1777cb92c03bSAndrew Geissler     // DBus implementation of EventLog/Entries
1778cb92c03bSAndrew Geissler     // Make call to Logging Service to find all log entry objects
1779deae6a78SEd Tanous     dbus::utility::getAllProperties(
1780deae6a78SEd Tanous         "xyz.openbmc_project.Logging",
1781599b9af3SAlexander Hansen         "/xyz/openbmc_project/logging/entry/" + entryID, "",
1782599b9af3SAlexander Hansen         [asyncResp, entryID](const boost::system::error_code& ec,
1783599b9af3SAlexander Hansen                              const dbus::utility::DBusPropertiesMap& resp) {
1784599b9af3SAlexander Hansen             if (ec.value() == EBADR)
1785599b9af3SAlexander Hansen             {
1786599b9af3SAlexander Hansen                 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1787599b9af3SAlexander Hansen                                            entryID);
1788599b9af3SAlexander Hansen                 return;
1789599b9af3SAlexander Hansen             }
1790cb92c03bSAndrew Geissler             if (ec)
1791cb92c03bSAndrew Geissler             {
1792bd79bce8SPatrick Williams                 BMCWEB_LOG_ERROR(
1793bd79bce8SPatrick Williams                     "EventLogEntry (DBus) resp_handler got error {}", ec);
1794cb92c03bSAndrew Geissler                 messages::internalError(asyncResp->res);
1795cb92c03bSAndrew Geissler                 return;
1796cb92c03bSAndrew Geissler             }
17979017faf2SAbhishek Patel 
1798898f2aa2SEd Tanous             fillEventLogLogEntryFromPropertyMap(asyncResp, resp,
1799898f2aa2SEd Tanous                                                 asyncResp->res.jsonValue);
1800599b9af3SAlexander Hansen         });
18017e860f15SJohn Edward Broadbent }
1802599b9af3SAlexander Hansen 
1803599b9af3SAlexander Hansen inline void
1804599b9af3SAlexander Hansen     dBusEventLogEntryPatch(const crow::Request& req,
1805599b9af3SAlexander Hansen                            const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1806599b9af3SAlexander Hansen                            const std::string& entryId)
1807599b9af3SAlexander Hansen {
1808599b9af3SAlexander Hansen     std::optional<bool> resolved;
1809599b9af3SAlexander Hansen 
1810599b9af3SAlexander Hansen     if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", resolved))
1811599b9af3SAlexander Hansen     {
1812599b9af3SAlexander Hansen         return;
1813599b9af3SAlexander Hansen     }
1814599b9af3SAlexander Hansen     BMCWEB_LOG_DEBUG("Set Resolved");
1815599b9af3SAlexander Hansen 
1816599b9af3SAlexander Hansen     setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging",
1817599b9af3SAlexander Hansen                     "/xyz/openbmc_project/logging/entry/" + entryId,
1818599b9af3SAlexander Hansen                     "xyz.openbmc_project.Logging.Entry", "Resolved",
1819599b9af3SAlexander Hansen                     resolved.value_or(false));
1820599b9af3SAlexander Hansen }
1821599b9af3SAlexander Hansen 
1822bd79bce8SPatrick Williams inline void dBusEventLogEntryDelete(
1823bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string entryID)
1824599b9af3SAlexander Hansen {
1825599b9af3SAlexander Hansen     BMCWEB_LOG_DEBUG("Do delete single event entries.");
1826599b9af3SAlexander Hansen 
1827599b9af3SAlexander Hansen     dbus::utility::escapePathForDbus(entryID);
1828599b9af3SAlexander Hansen 
1829599b9af3SAlexander Hansen     // Process response from Logging service.
1830599b9af3SAlexander Hansen     auto respHandler = [asyncResp,
1831599b9af3SAlexander Hansen                         entryID](const boost::system::error_code& ec) {
1832599b9af3SAlexander Hansen         BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done");
1833599b9af3SAlexander Hansen         if (ec)
1834599b9af3SAlexander Hansen         {
1835599b9af3SAlexander Hansen             if (ec.value() == EBADR)
1836599b9af3SAlexander Hansen             {
1837599b9af3SAlexander Hansen                 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
1838599b9af3SAlexander Hansen                 return;
1839599b9af3SAlexander Hansen             }
1840599b9af3SAlexander Hansen             // TODO Handle for specific error code
1841599b9af3SAlexander Hansen             BMCWEB_LOG_ERROR(
1842599b9af3SAlexander Hansen                 "EventLogEntry (DBus) doDelete respHandler got error {}", ec);
1843599b9af3SAlexander Hansen             asyncResp->res.result(
1844599b9af3SAlexander Hansen                 boost::beast::http::status::internal_server_error);
1845599b9af3SAlexander Hansen             return;
1846599b9af3SAlexander Hansen         }
1847599b9af3SAlexander Hansen 
1848599b9af3SAlexander Hansen         asyncResp->res.result(boost::beast::http::status::ok);
1849599b9af3SAlexander Hansen     };
1850599b9af3SAlexander Hansen 
1851599b9af3SAlexander Hansen     // Make call to Logging service to request Delete Log
1852599b9af3SAlexander Hansen     crow::connections::systemBus->async_method_call(
1853599b9af3SAlexander Hansen         respHandler, "xyz.openbmc_project.Logging",
1854599b9af3SAlexander Hansen         "/xyz/openbmc_project/logging/entry/" + entryID,
1855599b9af3SAlexander Hansen         "xyz.openbmc_project.Object.Delete", "Delete");
18567e860f15SJohn Edward Broadbent }
18577e860f15SJohn Edward Broadbent 
18587e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app)
18597e860f15SJohn Edward Broadbent {
18607e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
186122d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1862ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
1863002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1864002d39b4SEd Tanous             [&app](const crow::Request& req,
18657e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1866898f2aa2SEd Tanous                    const std::string& systemName, const std::string& entryId) {
18673ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
18687e860f15SJohn Edward Broadbent                 {
186945ca1b86SEd Tanous                     return;
187045ca1b86SEd Tanous                 }
187125b54dbaSEd Tanous                 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
18727f3e84a1SEd Tanous                 {
18737f3e84a1SEd Tanous                     // Option currently returns no systems.  TBD
18747f3e84a1SEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
18757f3e84a1SEd Tanous                                                systemName);
18767f3e84a1SEd Tanous                     return;
18777f3e84a1SEd Tanous                 }
1878253f11b8SEd Tanous                 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
187922d268cbSEd Tanous                 {
188022d268cbSEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
188122d268cbSEd Tanous                                                systemName);
188222d268cbSEd Tanous                     return;
188322d268cbSEd Tanous                 }
188422d268cbSEd Tanous 
1885898f2aa2SEd Tanous                 dBusEventLogEntryGet(asyncResp, entryId);
18867e860f15SJohn Edward Broadbent             });
1887336e96c6SChicago Duan 
18887e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
188922d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1890ed398213SEd Tanous         .privileges(redfish::privileges::patchLogEntry)
18917e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::patch)(
189245ca1b86SEd Tanous             [&app](const crow::Request& req,
18937e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
189422d268cbSEd Tanous                    const std::string& systemName, const std::string& entryId) {
18953ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
189645ca1b86SEd Tanous                 {
189745ca1b86SEd Tanous                     return;
189845ca1b86SEd Tanous                 }
189925b54dbaSEd Tanous                 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
19007f3e84a1SEd Tanous                 {
19017f3e84a1SEd Tanous                     // Option currently returns no systems.  TBD
19027f3e84a1SEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
19037f3e84a1SEd Tanous                                                systemName);
19047f3e84a1SEd Tanous                     return;
19057f3e84a1SEd Tanous                 }
1906253f11b8SEd Tanous                 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
190722d268cbSEd Tanous                 {
190822d268cbSEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
190922d268cbSEd Tanous                                                systemName);
191022d268cbSEd Tanous                     return;
191122d268cbSEd Tanous                 }
191275710de2SXiaochao Ma 
1913599b9af3SAlexander Hansen                 dBusEventLogEntryPatch(req, asyncResp, entryId);
19147e860f15SJohn Edward Broadbent             });
191575710de2SXiaochao Ma 
19167e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
191722d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1918ed398213SEd Tanous         .privileges(redfish::privileges::deleteLogEntry)
1919ed398213SEd Tanous 
1920002d39b4SEd Tanous         .methods(boost::beast::http::verb::delete_)(
1921002d39b4SEd Tanous             [&app](const crow::Request& req,
1922002d39b4SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
192322d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
19243ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1925336e96c6SChicago Duan                 {
192645ca1b86SEd Tanous                     return;
192745ca1b86SEd Tanous                 }
192825b54dbaSEd Tanous                 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
19297f3e84a1SEd Tanous                 {
19307f3e84a1SEd Tanous                     // Option currently returns no systems.  TBD
19317f3e84a1SEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
19327f3e84a1SEd Tanous                                                systemName);
19337f3e84a1SEd Tanous                     return;
19347f3e84a1SEd Tanous                 }
1935253f11b8SEd Tanous                 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
193622d268cbSEd Tanous                 {
193722d268cbSEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
193822d268cbSEd Tanous                                                systemName);
193922d268cbSEd Tanous                     return;
194022d268cbSEd Tanous                 }
1941599b9af3SAlexander Hansen                 dBusEventLogEntryDelete(asyncResp, param);
19427e860f15SJohn Edward Broadbent             });
1943400fd1fbSAdriana Kobylak }
1944400fd1fbSAdriana Kobylak 
1945dd72e87bSClaire Weinan inline void handleBMCLogServicesCollectionGet(
1946fdd26906SClaire Weinan     crow::App& app, const crow::Request& req,
1947253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1948253f11b8SEd Tanous     const std::string& managerId)
19491da66f75SEd Tanous {
19503ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
195145ca1b86SEd Tanous     {
195245ca1b86SEd Tanous         return;
195345ca1b86SEd Tanous     }
1954253f11b8SEd Tanous 
1955253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
1956253f11b8SEd Tanous     {
1957253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
1958253f11b8SEd Tanous         return;
1959253f11b8SEd Tanous     }
1960253f11b8SEd Tanous 
19617e860f15SJohn Edward Broadbent     // Collections don't include the static data added by SubRoute
19627e860f15SJohn Edward Broadbent     // because it has a duplicate entry for members
1963e1f26343SJason M. Bills     asyncResp->res.jsonValue["@odata.type"] =
19641da66f75SEd Tanous         "#LogServiceCollection.LogServiceCollection";
1965253f11b8SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1966253f11b8SEd Tanous         "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME);
1967002d39b4SEd Tanous     asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1968e1f26343SJason M. Bills     asyncResp->res.jsonValue["Description"] =
19691da66f75SEd Tanous         "Collection of LogServices for this Manager";
1970002d39b4SEd Tanous     nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1971c4bf6374SJason M. Bills     logServiceArray = nlohmann::json::array();
1972fdd26906SClaire Weinan 
197325b54dbaSEd Tanous     if constexpr (BMCWEB_REDFISH_BMC_JOURNAL)
197425b54dbaSEd Tanous     {
1975613dabeaSEd Tanous         nlohmann::json::object_t journal;
1976253f11b8SEd Tanous         journal["@odata.id"] =
1977253f11b8SEd Tanous             boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal",
1978253f11b8SEd Tanous                                 BMCWEB_REDFISH_MANAGER_URI_NAME);
1979b2ba3072SPatrick Williams         logServiceArray.emplace_back(std::move(journal));
198025b54dbaSEd Tanous     }
1981fdd26906SClaire Weinan 
1982fdd26906SClaire Weinan     asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
1983fdd26906SClaire Weinan 
198425b54dbaSEd Tanous     if constexpr (BMCWEB_REDFISH_DUMP_LOG)
198525b54dbaSEd Tanous     {
198615912159SGeorge Liu         constexpr std::array<std::string_view, 1> interfaces = {
19877a1dbc48SGeorge Liu             "xyz.openbmc_project.Collection.DeleteAll"};
19887a1dbc48SGeorge Liu         dbus::utility::getSubTreePaths(
19897a1dbc48SGeorge Liu             "/xyz/openbmc_project/dump", 0, interfaces,
199025b54dbaSEd Tanous             [asyncResp](const boost::system::error_code& ec,
199125b54dbaSEd Tanous                         const dbus::utility::MapperGetSubTreePathsResponse&
199225b54dbaSEd Tanous                             subTreePaths) {
1993fdd26906SClaire Weinan                 if (ec)
1994fdd26906SClaire Weinan                 {
199562598e31SEd Tanous                     BMCWEB_LOG_ERROR(
199662598e31SEd Tanous                         "handleBMCLogServicesCollectionGet respHandler got error {}",
199762598e31SEd Tanous                         ec);
1998bd79bce8SPatrick Williams                     // Assume that getting an error simply means there are no
1999bd79bce8SPatrick Williams                     // dump LogServices. Return without adding any error
2000bd79bce8SPatrick Williams                     // response.
2001fdd26906SClaire Weinan                     return;
2002fdd26906SClaire Weinan                 }
2003fdd26906SClaire Weinan 
2004fdd26906SClaire Weinan                 nlohmann::json& logServiceArrayLocal =
2005fdd26906SClaire Weinan                     asyncResp->res.jsonValue["Members"];
2006fdd26906SClaire Weinan 
2007fdd26906SClaire Weinan                 for (const std::string& path : subTreePaths)
2008fdd26906SClaire Weinan                 {
2009fdd26906SClaire Weinan                     if (path == "/xyz/openbmc_project/dump/bmc")
2010fdd26906SClaire Weinan                     {
2011613dabeaSEd Tanous                         nlohmann::json::object_t member;
2012253f11b8SEd Tanous                         member["@odata.id"] = boost::urls::format(
2013253f11b8SEd Tanous                             "/redfish/v1/Managers/{}/LogServices/Dump",
2014253f11b8SEd Tanous                             BMCWEB_REDFISH_MANAGER_URI_NAME);
2015b2ba3072SPatrick Williams                         logServiceArrayLocal.emplace_back(std::move(member));
2016fdd26906SClaire Weinan                     }
2017fdd26906SClaire Weinan                     else if (path == "/xyz/openbmc_project/dump/faultlog")
2018fdd26906SClaire Weinan                     {
2019613dabeaSEd Tanous                         nlohmann::json::object_t member;
2020253f11b8SEd Tanous                         member["@odata.id"] = boost::urls::format(
2021253f11b8SEd Tanous                             "/redfish/v1/Managers/{}/LogServices/FaultLog",
2022253f11b8SEd Tanous                             BMCWEB_REDFISH_MANAGER_URI_NAME);
2023b2ba3072SPatrick Williams                         logServiceArrayLocal.emplace_back(std::move(member));
2024fdd26906SClaire Weinan                     }
2025fdd26906SClaire Weinan                 }
2026fdd26906SClaire Weinan 
2027e1f26343SJason M. Bills                 asyncResp->res.jsonValue["Members@odata.count"] =
2028fdd26906SClaire Weinan                     logServiceArrayLocal.size();
20297a1dbc48SGeorge Liu             });
203025b54dbaSEd Tanous     }
2031fdd26906SClaire Weinan }
2032fdd26906SClaire Weinan 
2033fdd26906SClaire Weinan inline void requestRoutesBMCLogServiceCollection(App& app)
2034fdd26906SClaire Weinan {
2035253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/")
2036fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogServiceCollection)
2037fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(
2038dd72e87bSClaire Weinan             std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app)));
2039e1f26343SJason M. Bills }
2040e1f26343SJason M. Bills 
2041fdd26906SClaire Weinan inline void
2042fdd26906SClaire Weinan     getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2043fdd26906SClaire Weinan                        const std::string& dumpType)
2044c9bb6861Sraviteja-b {
2045fdd26906SClaire Weinan     std::string dumpPath;
2046539d8c6bSEd Tanous     log_service::OverWritePolicy overWritePolicy =
2047539d8c6bSEd Tanous         log_service::OverWritePolicy::Invalid;
2048fdd26906SClaire Weinan     bool collectDiagnosticDataSupported = false;
2049fdd26906SClaire Weinan 
2050fdd26906SClaire Weinan     if (dumpType == "BMC")
205145ca1b86SEd Tanous     {
2052253f11b8SEd Tanous         dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump",
2053253f11b8SEd Tanous                                BMCWEB_REDFISH_MANAGER_URI_NAME);
2054539d8c6bSEd Tanous         overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
2055fdd26906SClaire Weinan         collectDiagnosticDataSupported = true;
2056fdd26906SClaire Weinan     }
2057fdd26906SClaire Weinan     else if (dumpType == "FaultLog")
2058fdd26906SClaire Weinan     {
2059253f11b8SEd Tanous         dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog",
2060253f11b8SEd Tanous                                BMCWEB_REDFISH_MANAGER_URI_NAME);
2061539d8c6bSEd Tanous         overWritePolicy = log_service::OverWritePolicy::Unknown;
2062fdd26906SClaire Weinan         collectDiagnosticDataSupported = false;
2063fdd26906SClaire Weinan     }
2064fdd26906SClaire Weinan     else if (dumpType == "System")
2065fdd26906SClaire Weinan     {
2066253f11b8SEd Tanous         dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump",
2067253f11b8SEd Tanous                                BMCWEB_REDFISH_SYSTEM_URI_NAME);
2068539d8c6bSEd Tanous         overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull;
2069fdd26906SClaire Weinan         collectDiagnosticDataSupported = true;
2070fdd26906SClaire Weinan     }
2071fdd26906SClaire Weinan     else
2072fdd26906SClaire Weinan     {
207362598e31SEd Tanous         BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}",
207462598e31SEd Tanous                          dumpType);
2075fdd26906SClaire Weinan         messages::internalError(asyncResp->res);
207645ca1b86SEd Tanous         return;
207745ca1b86SEd Tanous     }
2078fdd26906SClaire Weinan 
2079fdd26906SClaire Weinan     asyncResp->res.jsonValue["@odata.id"] = dumpPath;
2080fdd26906SClaire Weinan     asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService";
2081c9bb6861Sraviteja-b     asyncResp->res.jsonValue["Name"] = "Dump LogService";
2082fdd26906SClaire Weinan     asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService";
2083fdd26906SClaire Weinan     asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename();
2084539d8c6bSEd Tanous     asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy;
20857c8c4058STejas Patil 
20867c8c4058STejas Patil     std::pair<std::string, std::string> redfishDateTimeOffset =
20872b82937eSEd Tanous         redfish::time_utils::getDateTimeOffsetNow();
20880fda0f12SGeorge Liu     asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
20897c8c4058STejas Patil     asyncResp->res.jsonValue["DateTimeLocalOffset"] =
20907c8c4058STejas Patil         redfishDateTimeOffset.second;
20917c8c4058STejas Patil 
2092fdd26906SClaire Weinan     asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries";
2093fdd26906SClaire Weinan 
2094fdd26906SClaire Weinan     if (collectDiagnosticDataSupported)
2095fdd26906SClaire Weinan     {
2096002d39b4SEd Tanous         asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
20971476687dSEd Tanous                                 ["target"] =
2098fdd26906SClaire Weinan             dumpPath + "/Actions/LogService.CollectDiagnosticData";
2099fdd26906SClaire Weinan     }
21000d946211SClaire Weinan 
21010d946211SClaire Weinan     constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface};
21020d946211SClaire Weinan     dbus::utility::getSubTreePaths(
21030d946211SClaire Weinan         "/xyz/openbmc_project/dump", 0, interfaces,
21040d946211SClaire Weinan         [asyncResp, dumpType, dumpPath](
21050d946211SClaire Weinan             const boost::system::error_code& ec,
21060d946211SClaire Weinan             const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
21070d946211SClaire Weinan             if (ec)
21080d946211SClaire Weinan             {
2109bd79bce8SPatrick Williams                 BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}",
2110bd79bce8SPatrick Williams                                  ec);
21110d946211SClaire Weinan                 // Assume that getting an error simply means there are no dump
21120d946211SClaire Weinan                 // LogServices. Return without adding any error response.
21130d946211SClaire Weinan                 return;
21140d946211SClaire Weinan             }
211518f8f608SEd Tanous             std::string dbusDumpPath = getDumpPath(dumpType);
21160d946211SClaire Weinan             for (const std::string& path : subTreePaths)
21170d946211SClaire Weinan             {
21180d946211SClaire Weinan                 if (path == dbusDumpPath)
21190d946211SClaire Weinan                 {
2120bd79bce8SPatrick Williams                     asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2121bd79bce8SPatrick Williams                                             ["target"] =
21220d946211SClaire Weinan                         dumpPath + "/Actions/LogService.ClearLog";
21230d946211SClaire Weinan                     break;
21240d946211SClaire Weinan                 }
21250d946211SClaire Weinan             }
21260d946211SClaire Weinan         });
2127c9bb6861Sraviteja-b }
2128c9bb6861Sraviteja-b 
2129fdd26906SClaire Weinan inline void handleLogServicesDumpServiceGet(
2130fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2131253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2132253f11b8SEd Tanous     const std::string& managerId)
21337e860f15SJohn Edward Broadbent {
21343ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
213545ca1b86SEd Tanous     {
213645ca1b86SEd Tanous         return;
213745ca1b86SEd Tanous     }
2138253f11b8SEd Tanous 
2139253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2140253f11b8SEd Tanous     {
2141253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2142253f11b8SEd Tanous         return;
2143253f11b8SEd Tanous     }
2144253f11b8SEd Tanous 
2145fdd26906SClaire Weinan     getDumpServiceInfo(asyncResp, dumpType);
2146fdd26906SClaire Weinan }
2147c9bb6861Sraviteja-b 
214822d268cbSEd Tanous inline void handleLogServicesDumpServiceComputerSystemGet(
214922d268cbSEd Tanous     crow::App& app, const crow::Request& req,
215022d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
215122d268cbSEd Tanous     const std::string& chassisId)
215222d268cbSEd Tanous {
215322d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
215422d268cbSEd Tanous     {
215522d268cbSEd Tanous         return;
215622d268cbSEd Tanous     }
2157253f11b8SEd Tanous     if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
215822d268cbSEd Tanous     {
215922d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
216022d268cbSEd Tanous         return;
216122d268cbSEd Tanous     }
216222d268cbSEd Tanous     getDumpServiceInfo(asyncResp, "System");
216322d268cbSEd Tanous }
216422d268cbSEd Tanous 
2165fdd26906SClaire Weinan inline void handleLogServicesDumpEntriesCollectionGet(
2166fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2167253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2168253f11b8SEd Tanous     const std::string& managerId)
2169fdd26906SClaire Weinan {
2170fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2171fdd26906SClaire Weinan     {
2172fdd26906SClaire Weinan         return;
2173fdd26906SClaire Weinan     }
2174253f11b8SEd Tanous 
2175253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2176253f11b8SEd Tanous     {
2177253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2178253f11b8SEd Tanous         return;
2179253f11b8SEd Tanous     }
2180fdd26906SClaire Weinan     getDumpEntryCollection(asyncResp, dumpType);
2181fdd26906SClaire Weinan }
2182fdd26906SClaire Weinan 
218322d268cbSEd Tanous inline void handleLogServicesDumpEntriesCollectionComputerSystemGet(
218422d268cbSEd Tanous     crow::App& app, const crow::Request& req,
218522d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
218622d268cbSEd Tanous     const std::string& chassisId)
218722d268cbSEd Tanous {
218822d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
218922d268cbSEd Tanous     {
219022d268cbSEd Tanous         return;
219122d268cbSEd Tanous     }
2192253f11b8SEd Tanous     if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
219322d268cbSEd Tanous     {
219422d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
219522d268cbSEd Tanous         return;
219622d268cbSEd Tanous     }
219722d268cbSEd Tanous     getDumpEntryCollection(asyncResp, "System");
219822d268cbSEd Tanous }
219922d268cbSEd Tanous 
2200fdd26906SClaire Weinan inline void handleLogServicesDumpEntryGet(
2201fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2202fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2203253f11b8SEd Tanous     const std::string& managerId, const std::string& dumpId)
2204fdd26906SClaire Weinan {
2205fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2206fdd26906SClaire Weinan     {
2207fdd26906SClaire Weinan         return;
2208fdd26906SClaire Weinan     }
2209253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2210253f11b8SEd Tanous     {
2211253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2212253f11b8SEd Tanous         return;
2213253f11b8SEd Tanous     }
2214fdd26906SClaire Weinan     getDumpEntryById(asyncResp, dumpId, dumpType);
2215fdd26906SClaire Weinan }
2216168d1b1aSCarson Labrado 
221722d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemGet(
221822d268cbSEd Tanous     crow::App& app, const crow::Request& req,
221922d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
222022d268cbSEd Tanous     const std::string& chassisId, const std::string& dumpId)
222122d268cbSEd Tanous {
222222d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
222322d268cbSEd Tanous     {
222422d268cbSEd Tanous         return;
222522d268cbSEd Tanous     }
2226253f11b8SEd Tanous     if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
222722d268cbSEd Tanous     {
222822d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
222922d268cbSEd Tanous         return;
223022d268cbSEd Tanous     }
223122d268cbSEd Tanous     getDumpEntryById(asyncResp, dumpId, "System");
223222d268cbSEd Tanous }
2233fdd26906SClaire Weinan 
2234fdd26906SClaire Weinan inline void handleLogServicesDumpEntryDelete(
2235fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2236fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2237253f11b8SEd Tanous     const std::string& managerId, const std::string& dumpId)
2238fdd26906SClaire Weinan {
2239fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2240fdd26906SClaire Weinan     {
2241fdd26906SClaire Weinan         return;
2242fdd26906SClaire Weinan     }
2243253f11b8SEd Tanous 
2244253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2245253f11b8SEd Tanous     {
2246253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2247253f11b8SEd Tanous         return;
2248253f11b8SEd Tanous     }
2249fdd26906SClaire Weinan     deleteDumpEntry(asyncResp, dumpId, dumpType);
2250fdd26906SClaire Weinan }
2251fdd26906SClaire Weinan 
225222d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemDelete(
225322d268cbSEd Tanous     crow::App& app, const crow::Request& req,
225422d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
225522d268cbSEd Tanous     const std::string& chassisId, const std::string& dumpId)
225622d268cbSEd Tanous {
225722d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
225822d268cbSEd Tanous     {
225922d268cbSEd Tanous         return;
226022d268cbSEd Tanous     }
2261253f11b8SEd Tanous     if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME)
226222d268cbSEd Tanous     {
226322d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
226422d268cbSEd Tanous         return;
226522d268cbSEd Tanous     }
226622d268cbSEd Tanous     deleteDumpEntry(asyncResp, dumpId, "System");
226722d268cbSEd Tanous }
226822d268cbSEd Tanous 
2269168d1b1aSCarson Labrado inline void handleLogServicesDumpEntryDownloadGet(
2270168d1b1aSCarson Labrado     crow::App& app, const std::string& dumpType, const crow::Request& req,
2271168d1b1aSCarson Labrado     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2272253f11b8SEd Tanous     const std::string& managerId, const std::string& dumpId)
2273168d1b1aSCarson Labrado {
2274168d1b1aSCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2275168d1b1aSCarson Labrado     {
2276168d1b1aSCarson Labrado         return;
2277168d1b1aSCarson Labrado     }
2278253f11b8SEd Tanous 
2279253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2280253f11b8SEd Tanous     {
2281253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2282253f11b8SEd Tanous         return;
2283253f11b8SEd Tanous     }
2284168d1b1aSCarson Labrado     downloadDumpEntry(asyncResp, dumpId, dumpType);
2285168d1b1aSCarson Labrado }
2286168d1b1aSCarson Labrado 
2287168d1b1aSCarson Labrado inline void handleDBusEventLogEntryDownloadGet(
2288168d1b1aSCarson Labrado     crow::App& app, const std::string& dumpType, const crow::Request& req,
2289168d1b1aSCarson Labrado     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2290168d1b1aSCarson Labrado     const std::string& systemName, const std::string& entryID)
2291168d1b1aSCarson Labrado {
2292168d1b1aSCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2293168d1b1aSCarson Labrado     {
2294168d1b1aSCarson Labrado         return;
2295168d1b1aSCarson Labrado     }
2296168d1b1aSCarson Labrado     if (!http_helpers::isContentTypeAllowed(
2297168d1b1aSCarson Labrado             req.getHeaderValue("Accept"),
2298168d1b1aSCarson Labrado             http_helpers::ContentType::OctetStream, true))
2299168d1b1aSCarson Labrado     {
2300168d1b1aSCarson Labrado         asyncResp->res.result(boost::beast::http::status::bad_request);
2301168d1b1aSCarson Labrado         return;
2302168d1b1aSCarson Labrado     }
2303168d1b1aSCarson Labrado     downloadEventLogEntry(asyncResp, systemName, entryID, dumpType);
2304168d1b1aSCarson Labrado }
2305168d1b1aSCarson Labrado 
2306fdd26906SClaire Weinan inline void handleLogServicesDumpCollectDiagnosticDataPost(
2307fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2308253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2309253f11b8SEd Tanous     const std::string& managerId)
2310fdd26906SClaire Weinan {
2311fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2312fdd26906SClaire Weinan     {
2313fdd26906SClaire Weinan         return;
2314fdd26906SClaire Weinan     }
2315253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2316253f11b8SEd Tanous     {
2317253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2318253f11b8SEd Tanous         return;
2319253f11b8SEd Tanous     }
2320253f11b8SEd Tanous 
2321fdd26906SClaire Weinan     createDump(asyncResp, req, dumpType);
2322fdd26906SClaire Weinan }
2323fdd26906SClaire Weinan 
232422d268cbSEd Tanous inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost(
232522d268cbSEd Tanous     crow::App& app, const crow::Request& req,
232622d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
23277f3e84a1SEd Tanous     const std::string& systemName)
232822d268cbSEd Tanous {
232922d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
233022d268cbSEd Tanous     {
233122d268cbSEd Tanous         return;
233222d268cbSEd Tanous     }
23337f3e84a1SEd Tanous 
233425b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
233522d268cbSEd Tanous     {
23367f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
23377f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
23387f3e84a1SEd Tanous                                    systemName);
23397f3e84a1SEd Tanous         return;
23407f3e84a1SEd Tanous     }
2341253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
23427f3e84a1SEd Tanous     {
23437f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
23447f3e84a1SEd Tanous                                    systemName);
234522d268cbSEd Tanous         return;
234622d268cbSEd Tanous     }
234722d268cbSEd Tanous     createDump(asyncResp, req, "System");
234822d268cbSEd Tanous }
234922d268cbSEd Tanous 
2350fdd26906SClaire Weinan inline void handleLogServicesDumpClearLogPost(
2351fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2352253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2353253f11b8SEd Tanous     const std::string& managerId)
2354fdd26906SClaire Weinan {
2355fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2356fdd26906SClaire Weinan     {
2357fdd26906SClaire Weinan         return;
2358fdd26906SClaire Weinan     }
2359253f11b8SEd Tanous 
2360253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2361253f11b8SEd Tanous     {
2362253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
2363253f11b8SEd Tanous         return;
2364253f11b8SEd Tanous     }
2365fdd26906SClaire Weinan     clearDump(asyncResp, dumpType);
2366fdd26906SClaire Weinan }
2367fdd26906SClaire Weinan 
236822d268cbSEd Tanous inline void handleLogServicesDumpClearLogComputerSystemPost(
236922d268cbSEd Tanous     crow::App& app, const crow::Request& req,
237022d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
23717f3e84a1SEd Tanous     const std::string& systemName)
237222d268cbSEd Tanous {
237322d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
237422d268cbSEd Tanous     {
237522d268cbSEd Tanous         return;
237622d268cbSEd Tanous     }
237725b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
237822d268cbSEd Tanous     {
23797f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
23807f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
23817f3e84a1SEd Tanous                                    systemName);
23827f3e84a1SEd Tanous         return;
23837f3e84a1SEd Tanous     }
2384253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
23857f3e84a1SEd Tanous     {
23867f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
23877f3e84a1SEd Tanous                                    systemName);
238822d268cbSEd Tanous         return;
238922d268cbSEd Tanous     }
239022d268cbSEd Tanous     clearDump(asyncResp, "System");
239122d268cbSEd Tanous }
239222d268cbSEd Tanous 
2393fdd26906SClaire Weinan inline void requestRoutesBMCDumpService(App& app)
2394fdd26906SClaire Weinan {
2395253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/")
2396fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogService)
2397fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2398fdd26906SClaire Weinan             handleLogServicesDumpServiceGet, std::ref(app), "BMC"));
2399fdd26906SClaire Weinan }
2400fdd26906SClaire Weinan 
2401fdd26906SClaire Weinan inline void requestRoutesBMCDumpEntryCollection(App& app)
2402fdd26906SClaire Weinan {
2403253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/")
2404fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogEntryCollection)
2405fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2406fdd26906SClaire Weinan             handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC"));
2407c9bb6861Sraviteja-b }
2408c9bb6861Sraviteja-b 
24097e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app)
2410c9bb6861Sraviteja-b {
24117e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
2412253f11b8SEd Tanous                  "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
2413ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
2414fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2415fdd26906SClaire Weinan             handleLogServicesDumpEntryGet, std::ref(app), "BMC"));
2416fdd26906SClaire Weinan 
24177e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
2418253f11b8SEd Tanous                  "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/")
2419ed398213SEd Tanous         .privileges(redfish::privileges::deleteLogEntry)
2420fdd26906SClaire Weinan         .methods(boost::beast::http::verb::delete_)(std::bind_front(
2421fdd26906SClaire Weinan             handleLogServicesDumpEntryDelete, std::ref(app), "BMC"));
2422c9bb6861Sraviteja-b }
2423c9bb6861Sraviteja-b 
2424168d1b1aSCarson Labrado inline void requestRoutesBMCDumpEntryDownload(App& app)
2425168d1b1aSCarson Labrado {
2426168d1b1aSCarson Labrado     BMCWEB_ROUTE(
2427168d1b1aSCarson Labrado         app,
2428253f11b8SEd Tanous         "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/")
2429168d1b1aSCarson Labrado         .privileges(redfish::privileges::getLogEntry)
2430168d1b1aSCarson Labrado         .methods(boost::beast::http::verb::get)(std::bind_front(
2431168d1b1aSCarson Labrado             handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC"));
2432168d1b1aSCarson Labrado }
2433168d1b1aSCarson Labrado 
24347e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app)
2435c9bb6861Sraviteja-b {
24360fda0f12SGeorge Liu     BMCWEB_ROUTE(
24370fda0f12SGeorge Liu         app,
2438253f11b8SEd Tanous         "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
2439ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
24407e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
2441fdd26906SClaire Weinan             std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost,
2442fdd26906SClaire Weinan                             std::ref(app), "BMC"));
2443a43be80fSAsmitha Karunanithi }
2444a43be80fSAsmitha Karunanithi 
24457e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app)
244680319af1SAsmitha Karunanithi {
24470fda0f12SGeorge Liu     BMCWEB_ROUTE(
24480fda0f12SGeorge Liu         app,
2449253f11b8SEd Tanous         "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
2450ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
2451fdd26906SClaire Weinan         .methods(boost::beast::http::verb::post)(std::bind_front(
2452fdd26906SClaire Weinan             handleLogServicesDumpClearLogPost, std::ref(app), "BMC"));
245345ca1b86SEd Tanous }
2454fdd26906SClaire Weinan 
2455168d1b1aSCarson Labrado inline void requestRoutesDBusEventLogEntryDownload(App& app)
2456168d1b1aSCarson Labrado {
2457168d1b1aSCarson Labrado     BMCWEB_ROUTE(
2458168d1b1aSCarson Labrado         app,
24599e9d99daSRavi Teja         "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/")
2460168d1b1aSCarson Labrado         .privileges(redfish::privileges::getLogEntry)
2461168d1b1aSCarson Labrado         .methods(boost::beast::http::verb::get)(std::bind_front(
2462168d1b1aSCarson Labrado             handleDBusEventLogEntryDownloadGet, std::ref(app), "System"));
2463168d1b1aSCarson Labrado }
2464168d1b1aSCarson Labrado 
2465fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpService(App& app)
2466fdd26906SClaire Weinan {
2467253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/")
2468fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogService)
2469fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2470fdd26906SClaire Weinan             handleLogServicesDumpServiceGet, std::ref(app), "FaultLog"));
2471fdd26906SClaire Weinan }
2472fdd26906SClaire Weinan 
2473fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntryCollection(App& app)
2474fdd26906SClaire Weinan {
2475253f11b8SEd Tanous     BMCWEB_ROUTE(app,
2476253f11b8SEd Tanous                  "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/")
2477fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogEntryCollection)
2478fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(
2479fdd26906SClaire Weinan             std::bind_front(handleLogServicesDumpEntriesCollectionGet,
2480fdd26906SClaire Weinan                             std::ref(app), "FaultLog"));
2481fdd26906SClaire Weinan }
2482fdd26906SClaire Weinan 
2483fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntry(App& app)
2484fdd26906SClaire Weinan {
2485253f11b8SEd Tanous     BMCWEB_ROUTE(
2486253f11b8SEd Tanous         app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
2487fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogEntry)
2488fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2489fdd26906SClaire Weinan             handleLogServicesDumpEntryGet, std::ref(app), "FaultLog"));
2490fdd26906SClaire Weinan 
2491253f11b8SEd Tanous     BMCWEB_ROUTE(
2492253f11b8SEd Tanous         app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/")
2493fdd26906SClaire Weinan         .privileges(redfish::privileges::deleteLogEntry)
2494fdd26906SClaire Weinan         .methods(boost::beast::http::verb::delete_)(std::bind_front(
2495fdd26906SClaire Weinan             handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog"));
2496fdd26906SClaire Weinan }
2497fdd26906SClaire Weinan 
2498fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpClear(App& app)
2499fdd26906SClaire Weinan {
2500fdd26906SClaire Weinan     BMCWEB_ROUTE(
2501fdd26906SClaire Weinan         app,
2502253f11b8SEd Tanous         "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/")
2503fdd26906SClaire Weinan         .privileges(redfish::privileges::postLogService)
2504fdd26906SClaire Weinan         .methods(boost::beast::http::verb::post)(std::bind_front(
2505fdd26906SClaire Weinan             handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog"));
25065cb1dd27SAsmitha Karunanithi }
25075cb1dd27SAsmitha Karunanithi 
25087e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app)
25095cb1dd27SAsmitha Karunanithi {
251022d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/")
2511ed398213SEd Tanous         .privileges(redfish::privileges::getLogService)
25126ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
251322d268cbSEd Tanous             handleLogServicesDumpServiceComputerSystemGet, std::ref(app)));
25145cb1dd27SAsmitha Karunanithi }
25155cb1dd27SAsmitha Karunanithi 
25167e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app)
25177e860f15SJohn Edward Broadbent {
251822d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/")
2519ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntryCollection)
252022d268cbSEd Tanous         .methods(boost::beast::http::verb::get)(std::bind_front(
252122d268cbSEd Tanous             handleLogServicesDumpEntriesCollectionComputerSystemGet,
252222d268cbSEd Tanous             std::ref(app)));
25235cb1dd27SAsmitha Karunanithi }
25245cb1dd27SAsmitha Karunanithi 
25257e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app)
25265cb1dd27SAsmitha Karunanithi {
25277e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
252822d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
2529ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
25306ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
253122d268cbSEd Tanous             handleLogServicesDumpEntryComputerSystemGet, std::ref(app)));
25328d1b46d7Szhanghch05 
25337e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
253422d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
2535ed398213SEd Tanous         .privileges(redfish::privileges::deleteLogEntry)
25366ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::delete_)(std::bind_front(
253722d268cbSEd Tanous             handleLogServicesDumpEntryComputerSystemDelete, std::ref(app)));
25385cb1dd27SAsmitha Karunanithi }
2539c9bb6861Sraviteja-b 
25407e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app)
2541c9bb6861Sraviteja-b {
25420fda0f12SGeorge Liu     BMCWEB_ROUTE(
25430fda0f12SGeorge Liu         app,
254422d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
2545ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
254622d268cbSEd Tanous         .methods(boost::beast::http::verb::post)(std::bind_front(
254722d268cbSEd Tanous             handleLogServicesDumpCollectDiagnosticDataComputerSystemPost,
254822d268cbSEd Tanous             std::ref(app)));
2549a43be80fSAsmitha Karunanithi }
2550a43be80fSAsmitha Karunanithi 
25517e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app)
2552a43be80fSAsmitha Karunanithi {
25530fda0f12SGeorge Liu     BMCWEB_ROUTE(
25540fda0f12SGeorge Liu         app,
255522d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
2556ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
25576ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::post)(std::bind_front(
255822d268cbSEd Tanous             handleLogServicesDumpClearLogComputerSystemPost, std::ref(app)));
2559013487e5Sraviteja-b }
2560013487e5Sraviteja-b 
25617e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app)
25621da66f75SEd Tanous {
25633946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
25643946028dSAppaRao Puli     // method for security reasons.
25651da66f75SEd Tanous     /**
25661da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
25671da66f75SEd Tanous      */
256822d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/")
2569ed398213SEd Tanous         // This is incorrect, should be:
2570ed398213SEd Tanous         //.privileges(redfish::privileges::getLogService)
2571432a890cSEd Tanous         .privileges({{"ConfigureManager"}})
2572bd79bce8SPatrick Williams         .methods(
2573bd79bce8SPatrick Williams             boost::beast::http::verb::
2574bd79bce8SPatrick Williams                 get)([&app](const crow::Request& req,
257522d268cbSEd Tanous                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
257622d268cbSEd Tanous                             const std::string& systemName) {
25773ba00073SCarson Labrado             if (!redfish::setUpRedfishRoute(app, req, asyncResp))
257845ca1b86SEd Tanous             {
257945ca1b86SEd Tanous                 return;
258045ca1b86SEd Tanous             }
258125b54dbaSEd Tanous             if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
25827f3e84a1SEd Tanous             {
25837f3e84a1SEd Tanous                 // Option currently returns no systems.  TBD
25847f3e84a1SEd Tanous                 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
25857f3e84a1SEd Tanous                                            systemName);
25867f3e84a1SEd Tanous                 return;
25877f3e84a1SEd Tanous             }
2588253f11b8SEd Tanous             if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
258922d268cbSEd Tanous             {
259022d268cbSEd Tanous                 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
259122d268cbSEd Tanous                                            systemName);
259222d268cbSEd Tanous                 return;
259322d268cbSEd Tanous             }
259422d268cbSEd Tanous 
25957e860f15SJohn Edward Broadbent             // Copy over the static data to include the entries added by
25967e860f15SJohn Edward Broadbent             // SubRoute
25970f74e643SEd Tanous             asyncResp->res.jsonValue["@odata.id"] =
2598253f11b8SEd Tanous                 std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
2599253f11b8SEd Tanous                             BMCWEB_REDFISH_SYSTEM_URI_NAME);
2600e1f26343SJason M. Bills             asyncResp->res.jsonValue["@odata.type"] =
26018e6c099aSJason M. Bills                 "#LogService.v1_2_0.LogService";
26024f50ae4bSGunnar Mills             asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
26034f50ae4bSGunnar Mills             asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
260415b89725SV-Sanjana             asyncResp->res.jsonValue["Id"] = "Crashdump";
2605539d8c6bSEd Tanous             asyncResp->res.jsonValue["OverWritePolicy"] =
2606539d8c6bSEd Tanous                 log_service::OverWritePolicy::WrapsWhenFull;
2607e1f26343SJason M. Bills             asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
26087c8c4058STejas Patil 
26097c8c4058STejas Patil             std::pair<std::string, std::string> redfishDateTimeOffset =
26102b82937eSEd Tanous                 redfish::time_utils::getDateTimeOffsetNow();
26117c8c4058STejas Patil             asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
26127c8c4058STejas Patil             asyncResp->res.jsonValue["DateTimeLocalOffset"] =
26137c8c4058STejas Patil                 redfishDateTimeOffset.second;
26147c8c4058STejas Patil 
2615bd79bce8SPatrick Williams             asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format(
2616bd79bce8SPatrick Williams                 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2617253f11b8SEd Tanous                 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2618253f11b8SEd Tanous             asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
2619253f11b8SEd Tanous                                     ["target"] = std::format(
2620253f11b8SEd Tanous                 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog",
2621253f11b8SEd Tanous                 BMCWEB_REDFISH_SYSTEM_URI_NAME);
2622bd79bce8SPatrick Williams             asyncResp->res
2623bd79bce8SPatrick Williams                 .jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
2624253f11b8SEd Tanous                           ["target"] = std::format(
2625253f11b8SEd Tanous                 "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData",
2626253f11b8SEd Tanous                 BMCWEB_REDFISH_SYSTEM_URI_NAME);
26277e860f15SJohn Edward Broadbent         });
26281da66f75SEd Tanous }
26291da66f75SEd Tanous 
26307e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app)
26315b61b5e8SJason M. Bills {
26320fda0f12SGeorge Liu     BMCWEB_ROUTE(
26330fda0f12SGeorge Liu         app,
263422d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/")
2635ed398213SEd Tanous         // This is incorrect, should be:
2636ed398213SEd Tanous         //.privileges(redfish::privileges::postLogService)
2637432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
26387e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
263945ca1b86SEd Tanous             [&app](const crow::Request& req,
264022d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
264122d268cbSEd Tanous                    const std::string& systemName) {
26423ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
264345ca1b86SEd Tanous                 {
264445ca1b86SEd Tanous                     return;
264545ca1b86SEd Tanous                 }
264625b54dbaSEd Tanous                 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
26477f3e84a1SEd Tanous                 {
26487f3e84a1SEd Tanous                     // Option currently returns no systems.  TBD
26497f3e84a1SEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
26507f3e84a1SEd Tanous                                                systemName);
26517f3e84a1SEd Tanous                     return;
26527f3e84a1SEd Tanous                 }
2653253f11b8SEd Tanous                 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
265422d268cbSEd Tanous                 {
265522d268cbSEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
265622d268cbSEd Tanous                                                systemName);
265722d268cbSEd Tanous                     return;
265822d268cbSEd Tanous                 }
26595b61b5e8SJason M. Bills                 crow::connections::systemBus->async_method_call(
26605e7e2dc5SEd Tanous                     [asyncResp](const boost::system::error_code& ec,
2661cb13a392SEd Tanous                                 const std::string&) {
26625b61b5e8SJason M. Bills                         if (ec)
26635b61b5e8SJason M. Bills                         {
26645b61b5e8SJason M. Bills                             messages::internalError(asyncResp->res);
26655b61b5e8SJason M. Bills                             return;
26665b61b5e8SJason M. Bills                         }
26675b61b5e8SJason M. Bills                         messages::success(asyncResp->res);
26685b61b5e8SJason M. Bills                     },
2669bd79bce8SPatrick Williams                     crashdumpObject, crashdumpPath, deleteAllInterface,
2670bd79bce8SPatrick Williams                     "DeleteAll");
26717e860f15SJohn Edward Broadbent             });
26725b61b5e8SJason M. Bills }
26735b61b5e8SJason M. Bills 
26744ff0f1f4SEd Tanous inline void
26758d1b46d7Szhanghch05     logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
26768d1b46d7Szhanghch05                       const std::string& logID, nlohmann::json& logEntryJson)
2677e855dd28SJason M. Bills {
2678043a0536SJohnathan Mantey     auto getStoredLogCallback =
2679b9d36b47SEd Tanous         [asyncResp, logID,
26805e7e2dc5SEd Tanous          &logEntryJson](const boost::system::error_code& ec,
2681b9d36b47SEd Tanous                         const dbus::utility::DBusPropertiesMap& params) {
2682e855dd28SJason M. Bills             if (ec)
2683e855dd28SJason M. Bills             {
268462598e31SEd Tanous                 BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message());
26851ddcf01aSJason M. Bills                 if (ec.value() ==
26861ddcf01aSJason M. Bills                     boost::system::linux_error::bad_request_descriptor)
26871ddcf01aSJason M. Bills                 {
2688bd79bce8SPatrick Williams                     messages::resourceNotFound(asyncResp->res, "LogEntry",
2689bd79bce8SPatrick Williams                                                logID);
26901ddcf01aSJason M. Bills                 }
26911ddcf01aSJason M. Bills                 else
26921ddcf01aSJason M. Bills                 {
2693e855dd28SJason M. Bills                     messages::internalError(asyncResp->res);
26941ddcf01aSJason M. Bills                 }
2695e855dd28SJason M. Bills                 return;
2696e855dd28SJason M. Bills             }
2697043a0536SJohnathan Mantey 
2698043a0536SJohnathan Mantey             std::string timestamp{};
2699043a0536SJohnathan Mantey             std::string filename{};
2700043a0536SJohnathan Mantey             std::string logfile{};
27012c70f800SEd Tanous             parseCrashdumpParameters(params, filename, timestamp, logfile);
2702043a0536SJohnathan Mantey 
2703043a0536SJohnathan Mantey             if (filename.empty() || timestamp.empty())
2704e855dd28SJason M. Bills             {
27059db4ba25SJiaqing Zhao                 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
2706e855dd28SJason M. Bills                 return;
2707e855dd28SJason M. Bills             }
2708e855dd28SJason M. Bills 
2709043a0536SJohnathan Mantey             std::string crashdumpURI =
2710bd79bce8SPatrick Williams                 std::format(
2711bd79bce8SPatrick Williams                     "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/",
2712253f11b8SEd Tanous                     BMCWEB_REDFISH_SYSTEM_URI_NAME) +
2713043a0536SJohnathan Mantey                 logID + "/" + filename;
271484afc48bSJason M. Bills             nlohmann::json::object_t logEntry;
27159c11a172SVijay Lobo             logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
2716ef4c65b7SEd Tanous             logEntry["@odata.id"] = boost::urls::format(
2717253f11b8SEd Tanous                 "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}",
2718253f11b8SEd Tanous                 BMCWEB_REDFISH_SYSTEM_URI_NAME, logID);
271984afc48bSJason M. Bills             logEntry["Name"] = "CPU Crashdump";
272084afc48bSJason M. Bills             logEntry["Id"] = logID;
2721539d8c6bSEd Tanous             logEntry["EntryType"] = log_entry::LogEntryType::Oem;
272284afc48bSJason M. Bills             logEntry["AdditionalDataURI"] = std::move(crashdumpURI);
272384afc48bSJason M. Bills             logEntry["DiagnosticDataType"] = "OEM";
272484afc48bSJason M. Bills             logEntry["OEMDiagnosticDataType"] = "PECICrashdump";
272584afc48bSJason M. Bills             logEntry["Created"] = std::move(timestamp);
27262b20ef6eSJason M. Bills 
27272b20ef6eSJason M. Bills             // If logEntryJson references an array of LogEntry resources
27282b20ef6eSJason M. Bills             // ('Members' list), then push this as a new entry, otherwise set it
27292b20ef6eSJason M. Bills             // directly
27302b20ef6eSJason M. Bills             if (logEntryJson.is_array())
27312b20ef6eSJason M. Bills             {
27322b20ef6eSJason M. Bills                 logEntryJson.push_back(logEntry);
27332b20ef6eSJason M. Bills                 asyncResp->res.jsonValue["Members@odata.count"] =
27342b20ef6eSJason M. Bills                     logEntryJson.size();
27352b20ef6eSJason M. Bills             }
27362b20ef6eSJason M. Bills             else
27372b20ef6eSJason M. Bills             {
2738d405bb51SJason M. Bills                 logEntryJson.update(logEntry);
27392b20ef6eSJason M. Bills             }
2740e855dd28SJason M. Bills         };
2741deae6a78SEd Tanous     dbus::utility::getAllProperties(
2742deae6a78SEd Tanous         crashdumpObject, crashdumpPath + std::string("/") + logID,
2743deae6a78SEd Tanous         crashdumpInterface, std::move(getStoredLogCallback));
2744e855dd28SJason M. Bills }
2745e855dd28SJason M. Bills 
27467e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app)
27471da66f75SEd Tanous {
27483946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
27493946028dSAppaRao Puli     // method for security reasons.
27501da66f75SEd Tanous     /**
27511da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
27521da66f75SEd Tanous      */
27537e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
275422d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/")
2755ed398213SEd Tanous         // This is incorrect, should be.
2756ed398213SEd Tanous         //.privileges(redfish::privileges::postLogEntryCollection)
2757432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
2758bd79bce8SPatrick Williams         .methods(
2759bd79bce8SPatrick Williams             boost::beast::http::verb::
2760bd79bce8SPatrick Williams                 get)([&app](const crow::Request& req,
276122d268cbSEd Tanous                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
276222d268cbSEd Tanous                             const std::string& systemName) {
27633ba00073SCarson Labrado             if (!redfish::setUpRedfishRoute(app, req, asyncResp))
276445ca1b86SEd Tanous             {
276545ca1b86SEd Tanous                 return;
276645ca1b86SEd Tanous             }
276725b54dbaSEd Tanous             if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
27687f3e84a1SEd Tanous             {
27697f3e84a1SEd Tanous                 // Option currently returns no systems.  TBD
27707f3e84a1SEd Tanous                 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
27717f3e84a1SEd Tanous                                            systemName);
27727f3e84a1SEd Tanous                 return;
27737f3e84a1SEd Tanous             }
2774253f11b8SEd Tanous             if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
277522d268cbSEd Tanous             {
277622d268cbSEd Tanous                 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
277722d268cbSEd Tanous                                            systemName);
277822d268cbSEd Tanous                 return;
277922d268cbSEd Tanous             }
278022d268cbSEd Tanous 
27817a1dbc48SGeorge Liu             constexpr std::array<std::string_view, 1> interfaces = {
27827a1dbc48SGeorge Liu                 crashdumpInterface};
27837a1dbc48SGeorge Liu             dbus::utility::getSubTreePaths(
27847a1dbc48SGeorge Liu                 "/", 0, interfaces,
27857a1dbc48SGeorge Liu                 [asyncResp](const boost::system::error_code& ec,
27862b20ef6eSJason M. Bills                             const std::vector<std::string>& resp) {
27871da66f75SEd Tanous                     if (ec)
27881da66f75SEd Tanous                     {
27891da66f75SEd Tanous                         if (ec.value() !=
27901da66f75SEd Tanous                             boost::system::errc::no_such_file_or_directory)
27911da66f75SEd Tanous                         {
279262598e31SEd Tanous                             BMCWEB_LOG_DEBUG("failed to get entries ec: {}",
279362598e31SEd Tanous                                              ec.message());
2794f12894f8SJason M. Bills                             messages::internalError(asyncResp->res);
27951da66f75SEd Tanous                             return;
27961da66f75SEd Tanous                         }
27971da66f75SEd Tanous                     }
2798e1f26343SJason M. Bills                     asyncResp->res.jsonValue["@odata.type"] =
27991da66f75SEd Tanous                         "#LogEntryCollection.LogEntryCollection";
2800253f11b8SEd Tanous                     asyncResp->res.jsonValue["@odata.id"] = std::format(
2801253f11b8SEd Tanous                         "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries",
2802253f11b8SEd Tanous                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
2803bd79bce8SPatrick Williams                     asyncResp->res.jsonValue["Name"] =
2804bd79bce8SPatrick Williams                         "Open BMC Crashdump Entries";
2805e1f26343SJason M. Bills                     asyncResp->res.jsonValue["Description"] =
2806424c4176SJason M. Bills                         "Collection of Crashdump Entries";
2807bd79bce8SPatrick Williams                     asyncResp->res.jsonValue["Members"] =
2808bd79bce8SPatrick Williams                         nlohmann::json::array();
2809a2dd60a6SBrandon Kim                     asyncResp->res.jsonValue["Members@odata.count"] = 0;
28102b20ef6eSJason M. Bills 
28112b20ef6eSJason M. Bills                     for (const std::string& path : resp)
28121da66f75SEd Tanous                     {
28132b20ef6eSJason M. Bills                         const sdbusplus::message::object_path objPath(path);
2814e855dd28SJason M. Bills                         // Get the log ID
28152b20ef6eSJason M. Bills                         std::string logID = objPath.filename();
28162b20ef6eSJason M. Bills                         if (logID.empty())
28171da66f75SEd Tanous                         {
2818e855dd28SJason M. Bills                             continue;
28191da66f75SEd Tanous                         }
2820e855dd28SJason M. Bills                         // Add the log entry to the array
28212b20ef6eSJason M. Bills                         logCrashdumpEntry(asyncResp, logID,
28222b20ef6eSJason M. Bills                                           asyncResp->res.jsonValue["Members"]);
28231da66f75SEd Tanous                     }
28247a1dbc48SGeorge Liu                 });
28257e860f15SJohn Edward Broadbent         });
28261da66f75SEd Tanous }
28271da66f75SEd Tanous 
28287e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app)
28291da66f75SEd Tanous {
28303946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
28313946028dSAppaRao Puli     // method for security reasons.
28321da66f75SEd Tanous 
28337e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
283422d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/")
2835ed398213SEd Tanous         // this is incorrect, should be
2836ed398213SEd Tanous         // .privileges(redfish::privileges::getLogEntry)
2837432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
28387e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
283945ca1b86SEd Tanous             [&app](const crow::Request& req,
28407e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
284122d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
28423ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
284345ca1b86SEd Tanous                 {
284445ca1b86SEd Tanous                     return;
284545ca1b86SEd Tanous                 }
284625b54dbaSEd Tanous                 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
28477f3e84a1SEd Tanous                 {
28487f3e84a1SEd Tanous                     // Option currently returns no systems.  TBD
28497f3e84a1SEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
28507f3e84a1SEd Tanous                                                systemName);
28517f3e84a1SEd Tanous                     return;
28527f3e84a1SEd Tanous                 }
2853253f11b8SEd Tanous                 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
285422d268cbSEd Tanous                 {
285522d268cbSEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
285622d268cbSEd Tanous                                                systemName);
285722d268cbSEd Tanous                     return;
285822d268cbSEd Tanous                 }
28597e860f15SJohn Edward Broadbent                 const std::string& logID = param;
2860e855dd28SJason M. Bills                 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
28617e860f15SJohn Edward Broadbent             });
2862e855dd28SJason M. Bills }
2863e855dd28SJason M. Bills 
28647e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app)
2865e855dd28SJason M. Bills {
28663946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
28673946028dSAppaRao Puli     // method for security reasons.
28687e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
28697e860f15SJohn Edward Broadbent         app,
287022d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/")
2871ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
28727e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
2873a4ce114aSNan Zhou             [](const crow::Request& req,
28747e860f15SJohn Edward Broadbent                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
287522d268cbSEd Tanous                const std::string& systemName, const std::string& logID,
287622d268cbSEd Tanous                const std::string& fileName) {
2877bd79bce8SPatrick Williams                 // Do not call getRedfishRoute here since the crashdump file is
2878bd79bce8SPatrick Williams                 // not a Redfish resource.
287922d268cbSEd Tanous 
288025b54dbaSEd Tanous                 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
28817f3e84a1SEd Tanous                 {
28827f3e84a1SEd Tanous                     // Option currently returns no systems.  TBD
28837f3e84a1SEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
28847f3e84a1SEd Tanous                                                systemName);
28857f3e84a1SEd Tanous                     return;
28867f3e84a1SEd Tanous                 }
2887253f11b8SEd Tanous                 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
288822d268cbSEd Tanous                 {
288922d268cbSEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
289022d268cbSEd Tanous                                                systemName);
289122d268cbSEd Tanous                     return;
289222d268cbSEd Tanous                 }
289322d268cbSEd Tanous 
2894043a0536SJohnathan Mantey                 auto getStoredLogCallback =
2895bd79bce8SPatrick Williams                     [asyncResp, logID, fileName,
2896bd79bce8SPatrick Williams                      url(boost::urls::url(req.url()))](
28975e7e2dc5SEd Tanous                         const boost::system::error_code& ec,
2898bd79bce8SPatrick Williams                         const std::vector<std::pair<
2899bd79bce8SPatrick Williams                             std::string, dbus::utility::DbusVariantType>>&
29007e860f15SJohn Edward Broadbent                             resp) {
29011da66f75SEd Tanous                         if (ec)
29021da66f75SEd Tanous                         {
2903bd79bce8SPatrick Williams                             BMCWEB_LOG_DEBUG("failed to get log ec: {}",
2904bd79bce8SPatrick Williams                                              ec.message());
2905f12894f8SJason M. Bills                             messages::internalError(asyncResp->res);
29061da66f75SEd Tanous                             return;
29071da66f75SEd Tanous                         }
2908e855dd28SJason M. Bills 
2909043a0536SJohnathan Mantey                         std::string dbusFilename{};
2910043a0536SJohnathan Mantey                         std::string dbusTimestamp{};
2911043a0536SJohnathan Mantey                         std::string dbusFilepath{};
2912043a0536SJohnathan Mantey 
2913bd79bce8SPatrick Williams                         parseCrashdumpParameters(resp, dbusFilename,
2914bd79bce8SPatrick Williams                                                  dbusTimestamp, dbusFilepath);
2915043a0536SJohnathan Mantey 
2916043a0536SJohnathan Mantey                         if (dbusFilename.empty() || dbusTimestamp.empty() ||
2917043a0536SJohnathan Mantey                             dbusFilepath.empty())
29181da66f75SEd Tanous                         {
2919bd79bce8SPatrick Williams                             messages::resourceNotFound(asyncResp->res,
2920bd79bce8SPatrick Williams                                                        "LogEntry", logID);
29211da66f75SEd Tanous                             return;
29221da66f75SEd Tanous                         }
2923e855dd28SJason M. Bills 
2924043a0536SJohnathan Mantey                         // Verify the file name parameter is correct
2925043a0536SJohnathan Mantey                         if (fileName != dbusFilename)
2926043a0536SJohnathan Mantey                         {
2927bd79bce8SPatrick Williams                             messages::resourceNotFound(asyncResp->res,
2928bd79bce8SPatrick Williams                                                        "LogEntry", logID);
2929043a0536SJohnathan Mantey                             return;
2930043a0536SJohnathan Mantey                         }
2931043a0536SJohnathan Mantey 
2932d51c61b4SMyung Bae                         if (asyncResp->res.openFile(dbusFilepath) !=
2933d51c61b4SMyung Bae                             crow::OpenCode::Success)
2934043a0536SJohnathan Mantey                         {
2935bd79bce8SPatrick Williams                             messages::resourceNotFound(asyncResp->res,
2936bd79bce8SPatrick Williams                                                        "LogEntry", logID);
2937043a0536SJohnathan Mantey                             return;
2938043a0536SJohnathan Mantey                         }
2939043a0536SJohnathan Mantey 
29407e860f15SJohn Edward Broadbent                         // Configure this to be a file download when accessed
29417e860f15SJohn Edward Broadbent                         // from a browser
2942d9f6c621SEd Tanous                         asyncResp->res.addHeader(
2943bd79bce8SPatrick Williams                             boost::beast::http::field::content_disposition,
2944bd79bce8SPatrick Williams                             "attachment");
29451da66f75SEd Tanous                     };
2946deae6a78SEd Tanous                 dbus::utility::getAllProperties(
2947d1bde9e5SKrzysztof Grobelny                     *crow::connections::systemBus, crashdumpObject,
2948bd79bce8SPatrick Williams                     crashdumpPath + std::string("/") + logID,
2949bd79bce8SPatrick Williams                     crashdumpInterface, std::move(getStoredLogCallback));
29507e860f15SJohn Edward Broadbent             });
29511da66f75SEd Tanous }
29521da66f75SEd Tanous 
2953c5a4c82aSJason M. Bills enum class OEMDiagnosticType
2954c5a4c82aSJason M. Bills {
2955c5a4c82aSJason M. Bills     onDemand,
2956c5a4c82aSJason M. Bills     telemetry,
2957c5a4c82aSJason M. Bills     invalid,
2958c5a4c82aSJason M. Bills };
2959c5a4c82aSJason M. Bills 
296026ccae32SEd Tanous inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr)
2961c5a4c82aSJason M. Bills {
2962c5a4c82aSJason M. Bills     if (oemDiagStr == "OnDemand")
2963c5a4c82aSJason M. Bills     {
2964c5a4c82aSJason M. Bills         return OEMDiagnosticType::onDemand;
2965c5a4c82aSJason M. Bills     }
2966c5a4c82aSJason M. Bills     if (oemDiagStr == "Telemetry")
2967c5a4c82aSJason M. Bills     {
2968c5a4c82aSJason M. Bills         return OEMDiagnosticType::telemetry;
2969c5a4c82aSJason M. Bills     }
2970c5a4c82aSJason M. Bills 
2971c5a4c82aSJason M. Bills     return OEMDiagnosticType::invalid;
2972c5a4c82aSJason M. Bills }
2973c5a4c82aSJason M. Bills 
29747e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app)
29751da66f75SEd Tanous {
29763946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
29773946028dSAppaRao Puli     // method for security reasons.
29780fda0f12SGeorge Liu     BMCWEB_ROUTE(
29790fda0f12SGeorge Liu         app,
298022d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/")
2981ed398213SEd Tanous         // The below is incorrect;  Should be ConfigureManager
2982ed398213SEd Tanous         //.privileges(redfish::privileges::postLogService)
2983432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
2984002d39b4SEd Tanous         .methods(boost::beast::http::verb::post)(
2985002d39b4SEd Tanous             [&app](const crow::Request& req,
298622d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
298722d268cbSEd Tanous                    const std::string& systemName) {
29883ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
298945ca1b86SEd Tanous                 {
299045ca1b86SEd Tanous                     return;
299145ca1b86SEd Tanous                 }
299222d268cbSEd Tanous 
299325b54dbaSEd Tanous                 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
29947f3e84a1SEd Tanous                 {
29957f3e84a1SEd Tanous                     // Option currently returns no systems.  TBD
29967f3e84a1SEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
29977f3e84a1SEd Tanous                                                systemName);
29987f3e84a1SEd Tanous                     return;
29997f3e84a1SEd Tanous                 }
3000253f11b8SEd Tanous                 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
300122d268cbSEd Tanous                 {
300222d268cbSEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
300322d268cbSEd Tanous                                                systemName);
300422d268cbSEd Tanous                     return;
300522d268cbSEd Tanous                 }
300622d268cbSEd Tanous 
30078e6c099aSJason M. Bills                 std::string diagnosticDataType;
30088e6c099aSJason M. Bills                 std::string oemDiagnosticDataType;
3009afc474aeSMyung Bae                 if (!redfish::json_util::readJsonAction( //
3010afc474aeSMyung Bae                         req, asyncResp->res, //
3011afc474aeSMyung Bae                         "DiagnosticDataType", diagnosticDataType, //
3012afc474aeSMyung Bae                         "OEMDiagnosticDataType", oemDiagnosticDataType //
3013afc474aeSMyung Bae                         ))
30148e6c099aSJason M. Bills                 {
30158e6c099aSJason M. Bills                     return;
30168e6c099aSJason M. Bills                 }
30178e6c099aSJason M. Bills 
30188e6c099aSJason M. Bills                 if (diagnosticDataType != "OEM")
30198e6c099aSJason M. Bills                 {
302062598e31SEd Tanous                     BMCWEB_LOG_ERROR(
302162598e31SEd Tanous                         "Only OEM DiagnosticDataType supported for Crashdump");
30228e6c099aSJason M. Bills                     messages::actionParameterValueFormatError(
3023bd79bce8SPatrick Williams                         asyncResp->res, diagnosticDataType,
3024bd79bce8SPatrick Williams                         "DiagnosticDataType", "CollectDiagnosticData");
30258e6c099aSJason M. Bills                     return;
30268e6c099aSJason M. Bills                 }
30278e6c099aSJason M. Bills 
3028c5a4c82aSJason M. Bills                 OEMDiagnosticType oemDiagType =
3029c5a4c82aSJason M. Bills                     getOEMDiagnosticType(oemDiagnosticDataType);
3030c5a4c82aSJason M. Bills 
3031c5a4c82aSJason M. Bills                 std::string iface;
3032c5a4c82aSJason M. Bills                 std::string method;
3033c5a4c82aSJason M. Bills                 std::string taskMatchStr;
3034c5a4c82aSJason M. Bills                 if (oemDiagType == OEMDiagnosticType::onDemand)
3035c5a4c82aSJason M. Bills                 {
3036c5a4c82aSJason M. Bills                     iface = crashdumpOnDemandInterface;
3037c5a4c82aSJason M. Bills                     method = "GenerateOnDemandLog";
3038bd79bce8SPatrick Williams                     taskMatchStr =
3039bd79bce8SPatrick Williams                         "type='signal',"
3040c5a4c82aSJason M. Bills                         "interface='org.freedesktop.DBus.Properties',"
3041c5a4c82aSJason M. Bills                         "member='PropertiesChanged',"
3042c5a4c82aSJason M. Bills                         "arg0namespace='com.intel.crashdump'";
3043c5a4c82aSJason M. Bills                 }
3044c5a4c82aSJason M. Bills                 else if (oemDiagType == OEMDiagnosticType::telemetry)
3045c5a4c82aSJason M. Bills                 {
3046c5a4c82aSJason M. Bills                     iface = crashdumpTelemetryInterface;
3047c5a4c82aSJason M. Bills                     method = "GenerateTelemetryLog";
3048bd79bce8SPatrick Williams                     taskMatchStr =
3049bd79bce8SPatrick Williams                         "type='signal',"
3050c5a4c82aSJason M. Bills                         "interface='org.freedesktop.DBus.Properties',"
3051c5a4c82aSJason M. Bills                         "member='PropertiesChanged',"
3052c5a4c82aSJason M. Bills                         "arg0namespace='com.intel.crashdump'";
3053c5a4c82aSJason M. Bills                 }
3054c5a4c82aSJason M. Bills                 else
3055c5a4c82aSJason M. Bills                 {
305662598e31SEd Tanous                     BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}",
305762598e31SEd Tanous                                      oemDiagnosticDataType);
3058c5a4c82aSJason M. Bills                     messages::actionParameterValueFormatError(
3059bd79bce8SPatrick Williams                         asyncResp->res, oemDiagnosticDataType,
3060bd79bce8SPatrick Williams                         "OEMDiagnosticDataType", "CollectDiagnosticData");
3061c5a4c82aSJason M. Bills                     return;
3062c5a4c82aSJason M. Bills                 }
3063c5a4c82aSJason M. Bills 
3064c5a4c82aSJason M. Bills                 auto collectCrashdumpCallback =
3065c5a4c82aSJason M. Bills                     [asyncResp, payload(task::Payload(req)),
30665e7e2dc5SEd Tanous                      taskMatchStr](const boost::system::error_code& ec,
306798be3e39SEd Tanous                                    const std::string&) mutable {
30681da66f75SEd Tanous                         if (ec)
30691da66f75SEd Tanous                         {
3070bd79bce8SPatrick Williams                             if (ec.value() ==
3071bd79bce8SPatrick Williams                                 boost::system::errc::operation_not_supported)
30721da66f75SEd Tanous                             {
3073f12894f8SJason M. Bills                                 messages::resourceInStandby(asyncResp->res);
30741da66f75SEd Tanous                             }
3075bd79bce8SPatrick Williams                             else if (ec.value() == boost::system::errc::
3076bd79bce8SPatrick Williams                                                        device_or_resource_busy)
30774363d3b2SJason M. Bills                             {
3078bd79bce8SPatrick Williams                                 messages::serviceTemporarilyUnavailable(
3079bd79bce8SPatrick Williams                                     asyncResp->res, "60");
30804363d3b2SJason M. Bills                             }
30811da66f75SEd Tanous                             else
30821da66f75SEd Tanous                             {
3083f12894f8SJason M. Bills                                 messages::internalError(asyncResp->res);
30841da66f75SEd Tanous                             }
30851da66f75SEd Tanous                             return;
30861da66f75SEd Tanous                         }
3087bd79bce8SPatrick Williams                         std::shared_ptr<task::TaskData> task =
3088bd79bce8SPatrick Williams                             task::TaskData::createTask(
3089bd79bce8SPatrick Williams                                 [](const boost::system::error_code& ec2,
3090bd79bce8SPatrick Williams                                    sdbusplus::message_t&,
3091bd79bce8SPatrick Williams                                    const std::shared_ptr<task::TaskData>&
3092bd79bce8SPatrick Williams                                        taskData) {
30938b24275dSEd Tanous                                     if (!ec2)
309466afe4faSJames Feist                                     {
3095bd79bce8SPatrick Williams                                         taskData->messages.emplace_back(
3096bd79bce8SPatrick Williams                                             messages::taskCompletedOK(
3097bd79bce8SPatrick Williams                                                 std::to_string(
3098bd79bce8SPatrick Williams                                                     taskData->index)));
3099831d6b09SJames Feist                                         taskData->state = "Completed";
310066afe4faSJames Feist                                     }
310132898ceaSJames Feist                                     return task::completed;
310266afe4faSJames Feist                                 },
3103c5a4c82aSJason M. Bills                                 taskMatchStr);
3104c5a4c82aSJason M. Bills 
310546229577SJames Feist                         task->startTimer(std::chrono::minutes(5));
310646229577SJames Feist                         task->populateResp(asyncResp->res);
310798be3e39SEd Tanous                         task->payload.emplace(std::move(payload));
31081da66f75SEd Tanous                     };
31098e6c099aSJason M. Bills 
31101da66f75SEd Tanous                 crow::connections::systemBus->async_method_call(
3111bd79bce8SPatrick Williams                     std::move(collectCrashdumpCallback), crashdumpObject,
3112bd79bce8SPatrick Williams                     crashdumpPath, iface, method);
31137e860f15SJohn Edward Broadbent             });
31146eda7685SKenny L. Ku }
31156eda7685SKenny L. Ku 
3116599b9af3SAlexander Hansen inline void dBusLogServiceActionsClear(
3117599b9af3SAlexander Hansen     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
3118599b9af3SAlexander Hansen {
3119599b9af3SAlexander Hansen     BMCWEB_LOG_DEBUG("Do delete all entries.");
3120599b9af3SAlexander Hansen 
3121599b9af3SAlexander Hansen     // Process response from Logging service.
3122599b9af3SAlexander Hansen     auto respHandler = [asyncResp](const boost::system::error_code& ec) {
3123599b9af3SAlexander Hansen         BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done");
3124599b9af3SAlexander Hansen         if (ec)
3125599b9af3SAlexander Hansen         {
3126599b9af3SAlexander Hansen             // TODO Handle for specific error code
3127599b9af3SAlexander Hansen             BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec);
3128599b9af3SAlexander Hansen             asyncResp->res.result(
3129599b9af3SAlexander Hansen                 boost::beast::http::status::internal_server_error);
3130599b9af3SAlexander Hansen             return;
3131599b9af3SAlexander Hansen         }
3132599b9af3SAlexander Hansen 
3133599b9af3SAlexander Hansen         asyncResp->res.result(boost::beast::http::status::no_content);
3134599b9af3SAlexander Hansen     };
3135599b9af3SAlexander Hansen 
3136599b9af3SAlexander Hansen     // Make call to Logging service to request Clear Log
3137599b9af3SAlexander Hansen     crow::connections::systemBus->async_method_call(
3138599b9af3SAlexander Hansen         respHandler, "xyz.openbmc_project.Logging",
3139599b9af3SAlexander Hansen         "/xyz/openbmc_project/logging",
3140599b9af3SAlexander Hansen         "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3141599b9af3SAlexander Hansen }
3142599b9af3SAlexander Hansen 
3143cb92c03bSAndrew Geissler /**
3144cb92c03bSAndrew Geissler  * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3145cb92c03bSAndrew Geissler  */
31467e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app)
3147cb92c03bSAndrew Geissler {
3148cb92c03bSAndrew Geissler     /**
3149cb92c03bSAndrew Geissler      * Function handles POST method request.
3150cb92c03bSAndrew Geissler      * The Clear Log actions does not require any parameter.The action deletes
3151cb92c03bSAndrew Geissler      * all entries found in the Entries collection for this Log Service.
3152cb92c03bSAndrew Geissler      */
31537e860f15SJohn Edward Broadbent 
31540fda0f12SGeorge Liu     BMCWEB_ROUTE(
31550fda0f12SGeorge Liu         app,
315622d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
3157ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
31587e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
315945ca1b86SEd Tanous             [&app](const crow::Request& req,
316022d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
316122d268cbSEd Tanous                    const std::string& systemName) {
31623ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
316345ca1b86SEd Tanous                 {
316445ca1b86SEd Tanous                     return;
316545ca1b86SEd Tanous                 }
316625b54dbaSEd Tanous                 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
31677f3e84a1SEd Tanous                 {
31687f3e84a1SEd Tanous                     // Option currently returns no systems.  TBD
31697f3e84a1SEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
31707f3e84a1SEd Tanous                                                systemName);
31717f3e84a1SEd Tanous                     return;
31727f3e84a1SEd Tanous                 }
3173253f11b8SEd Tanous                 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
317422d268cbSEd Tanous                 {
317522d268cbSEd Tanous                     messages::resourceNotFound(asyncResp->res, "ComputerSystem",
317622d268cbSEd Tanous                                                systemName);
317722d268cbSEd Tanous                     return;
317822d268cbSEd Tanous                 }
3179599b9af3SAlexander Hansen                 dBusLogServiceActionsClear(asyncResp);
31807e860f15SJohn Edward Broadbent             });
3181cb92c03bSAndrew Geissler }
3182a3316fc6SZhikuiRen 
31831da66f75SEd Tanous } // namespace redfish
3184