xref: /openbmc/bmcweb/features/redfish/lib/log_services.hpp (revision a7405d5fe77fa9e324c22cb29ea08029fc023f4e)
11da66f75SEd Tanous /*
21da66f75SEd Tanous // Copyright (c) 2018 Intel Corporation
31da66f75SEd Tanous //
41da66f75SEd Tanous // Licensed under the Apache License, Version 2.0 (the "License");
51da66f75SEd Tanous // you may not use this file except in compliance with the License.
61da66f75SEd Tanous // You may obtain a copy of the License at
71da66f75SEd Tanous //
81da66f75SEd Tanous //      http://www.apache.org/licenses/LICENSE-2.0
91da66f75SEd Tanous //
101da66f75SEd Tanous // Unless required by applicable law or agreed to in writing, software
111da66f75SEd Tanous // distributed under the License is distributed on an "AS IS" BASIS,
121da66f75SEd Tanous // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131da66f75SEd Tanous // See the License for the specific language governing permissions and
141da66f75SEd Tanous // limitations under the License.
151da66f75SEd Tanous */
161da66f75SEd Tanous #pragma once
171da66f75SEd Tanous 
183ccb3adbSEd Tanous #include "app.hpp"
197a1dbc48SGeorge Liu #include "dbus_utility.hpp"
203ccb3adbSEd Tanous #include "error_messages.hpp"
2168dd075aSAsmitha Karunanithi #include "generated/enums/log_entry.hpp"
22b7028ebfSSpencer Ku #include "gzfile.hpp"
23647b3cdcSGeorge Liu #include "http_utility.hpp"
24b7028ebfSSpencer Ku #include "human_sort.hpp"
253ccb3adbSEd Tanous #include "query.hpp"
264851d45dSJason M. Bills #include "registries.hpp"
274851d45dSJason M. Bills #include "registries/base_message_registry.hpp"
284851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp"
293ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
3046229577SJames Feist #include "task.hpp"
313ccb3adbSEd Tanous #include "utils/dbus_utils.hpp"
323ccb3adbSEd Tanous #include "utils/time_utils.hpp"
331da66f75SEd Tanous 
34e1f26343SJason M. Bills #include <systemd/sd-journal.h>
358e31778eSAsmitha Karunanithi #include <tinyxml2.h>
36400fd1fbSAdriana Kobylak #include <unistd.h>
37e1f26343SJason M. Bills 
389896eaedSEd Tanous #include <boost/algorithm/string/case_conv.hpp>
3911ba3979SEd Tanous #include <boost/algorithm/string/classification.hpp>
40400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp>
414851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp>
4207c8c20dSEd Tanous #include <boost/beast/http/verb.hpp>
431da66f75SEd Tanous #include <boost/container/flat_map.hpp>
441ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp>
45d1bde9e5SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp>
46d1bde9e5SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp>
471214b7e7SGunnar Mills 
487a1dbc48SGeorge Liu #include <array>
49647b3cdcSGeorge Liu #include <charconv>
504418c7f0SJames Feist #include <filesystem>
5175710de2SXiaochao Ma #include <optional>
5226702d01SEd Tanous #include <span>
53cd225da8SJason M. Bills #include <string_view>
54abf2add6SEd Tanous #include <variant>
551da66f75SEd Tanous 
561da66f75SEd Tanous namespace redfish
571da66f75SEd Tanous {
581da66f75SEd Tanous 
595b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump";
605b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump";
615b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump";
625b61b5e8SJason M. Bills constexpr char const* deleteAllInterface =
635b61b5e8SJason M. Bills     "xyz.openbmc_project.Collection.DeleteAll";
645b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface =
65424c4176SJason M. Bills     "com.intel.crashdump.OnDemand";
666eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface =
676eda7685SKenny L. Ku     "com.intel.crashdump.Telemetry";
681da66f75SEd Tanous 
698e31778eSAsmitha Karunanithi enum class DumpCreationProgress
708e31778eSAsmitha Karunanithi {
718e31778eSAsmitha Karunanithi     DUMP_CREATE_SUCCESS,
728e31778eSAsmitha Karunanithi     DUMP_CREATE_FAILED,
738e31778eSAsmitha Karunanithi     DUMP_CREATE_INPROGRESS
748e31778eSAsmitha Karunanithi };
758e31778eSAsmitha Karunanithi 
76f6150403SJames Feist namespace fs = std::filesystem;
771da66f75SEd Tanous 
78cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s)
79cb92c03bSAndrew Geissler {
80d4d25793SEd Tanous     if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
81d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
82d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
83d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
84cb92c03bSAndrew Geissler     {
85cb92c03bSAndrew Geissler         return "Critical";
86cb92c03bSAndrew Geissler     }
873174e4dfSEd Tanous     if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
88d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
89d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
90cb92c03bSAndrew Geissler     {
91cb92c03bSAndrew Geissler         return "OK";
92cb92c03bSAndrew Geissler     }
933174e4dfSEd Tanous     if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
94cb92c03bSAndrew Geissler     {
95cb92c03bSAndrew Geissler         return "Warning";
96cb92c03bSAndrew Geissler     }
97cb92c03bSAndrew Geissler     return "";
98cb92c03bSAndrew Geissler }
99cb92c03bSAndrew Geissler 
1009017faf2SAbhishek Patel inline std::optional<bool> getProviderNotifyAction(const std::string& notify)
1019017faf2SAbhishek Patel {
1029017faf2SAbhishek Patel     std::optional<bool> notifyAction;
1039017faf2SAbhishek Patel     if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify")
1049017faf2SAbhishek Patel     {
1059017faf2SAbhishek Patel         notifyAction = true;
1069017faf2SAbhishek Patel     }
1079017faf2SAbhishek Patel     else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit")
1089017faf2SAbhishek Patel     {
1099017faf2SAbhishek Patel         notifyAction = false;
1109017faf2SAbhishek Patel     }
1119017faf2SAbhishek Patel 
1129017faf2SAbhishek Patel     return notifyAction;
1139017faf2SAbhishek Patel }
1149017faf2SAbhishek Patel 
1157e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal,
11626ccae32SEd Tanous                                      std::string_view field,
11739e77504SEd Tanous                                      std::string_view& contents)
11816428a1aSJason M. Bills {
11916428a1aSJason M. Bills     const char* data = nullptr;
12016428a1aSJason M. Bills     size_t length = 0;
12116428a1aSJason M. Bills     int ret = 0;
12216428a1aSJason M. Bills     // Get the metadata from the requested field of the journal entry
12346ff87baSEd Tanous     // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
12446ff87baSEd Tanous     const void** dataVoid = reinterpret_cast<const void**>(&data);
12546ff87baSEd Tanous 
12646ff87baSEd Tanous     ret = sd_journal_get_data(journal, field.data(), dataVoid, &length);
12716428a1aSJason M. Bills     if (ret < 0)
12816428a1aSJason M. Bills     {
12916428a1aSJason M. Bills         return ret;
13016428a1aSJason M. Bills     }
13139e77504SEd Tanous     contents = std::string_view(data, length);
13216428a1aSJason M. Bills     // Only use the content after the "=" character.
13381ce609eSEd Tanous     contents.remove_prefix(std::min(contents.find('=') + 1, contents.size()));
13416428a1aSJason M. Bills     return ret;
13516428a1aSJason M. Bills }
13616428a1aSJason M. Bills 
1377e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal,
13826ccae32SEd Tanous                                      std::string_view field, const int& base,
13926ccae32SEd Tanous                                      long int& contents)
14016428a1aSJason M. Bills {
14116428a1aSJason M. Bills     int ret = 0;
14239e77504SEd Tanous     std::string_view metadata;
14316428a1aSJason M. Bills     // Get the metadata from the requested field of the journal entry
14416428a1aSJason M. Bills     ret = getJournalMetadata(journal, field, metadata);
14516428a1aSJason M. Bills     if (ret < 0)
14616428a1aSJason M. Bills     {
14716428a1aSJason M. Bills         return ret;
14816428a1aSJason M. Bills     }
149b01bf299SEd Tanous     contents = strtol(metadata.data(), nullptr, base);
15016428a1aSJason M. Bills     return ret;
15116428a1aSJason M. Bills }
15216428a1aSJason M. Bills 
1537e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal,
1547e860f15SJohn Edward Broadbent                                      std::string& entryTimestamp)
155a3316fc6SZhikuiRen {
156a3316fc6SZhikuiRen     int ret = 0;
157a3316fc6SZhikuiRen     uint64_t timestamp = 0;
158a3316fc6SZhikuiRen     ret = sd_journal_get_realtime_usec(journal, &timestamp);
159a3316fc6SZhikuiRen     if (ret < 0)
160a3316fc6SZhikuiRen     {
161a3316fc6SZhikuiRen         BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
162a3316fc6SZhikuiRen                          << strerror(-ret);
163a3316fc6SZhikuiRen         return false;
164a3316fc6SZhikuiRen     }
165e645c5e6SKonstantin Aladyshev     entryTimestamp = redfish::time_utils::getDateTimeUintUs(timestamp);
1669c620e21SAsmitha Karunanithi     return true;
167a3316fc6SZhikuiRen }
16850b8a43aSEd Tanous 
1697e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID,
170e85d6b16SJason M. Bills                                     const bool firstEntry = true)
17116428a1aSJason M. Bills {
17216428a1aSJason M. Bills     int ret = 0;
17316428a1aSJason M. Bills     static uint64_t prevTs = 0;
17416428a1aSJason M. Bills     static int index = 0;
175e85d6b16SJason M. Bills     if (firstEntry)
176e85d6b16SJason M. Bills     {
177e85d6b16SJason M. Bills         prevTs = 0;
178e85d6b16SJason M. Bills     }
179e85d6b16SJason M. Bills 
18016428a1aSJason M. Bills     // Get the entry timestamp
18116428a1aSJason M. Bills     uint64_t curTs = 0;
18216428a1aSJason M. Bills     ret = sd_journal_get_realtime_usec(journal, &curTs);
18316428a1aSJason M. Bills     if (ret < 0)
18416428a1aSJason M. Bills     {
18516428a1aSJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
18616428a1aSJason M. Bills                          << strerror(-ret);
18716428a1aSJason M. Bills         return false;
18816428a1aSJason M. Bills     }
18916428a1aSJason M. Bills     // If the timestamp isn't unique, increment the index
19016428a1aSJason M. Bills     if (curTs == prevTs)
19116428a1aSJason M. Bills     {
19216428a1aSJason M. Bills         index++;
19316428a1aSJason M. Bills     }
19416428a1aSJason M. Bills     else
19516428a1aSJason M. Bills     {
19616428a1aSJason M. Bills         // Otherwise, reset it
19716428a1aSJason M. Bills         index = 0;
19816428a1aSJason M. Bills     }
19916428a1aSJason M. Bills     // Save the timestamp
20016428a1aSJason M. Bills     prevTs = curTs;
20116428a1aSJason M. Bills 
20216428a1aSJason M. Bills     entryID = std::to_string(curTs);
20316428a1aSJason M. Bills     if (index > 0)
20416428a1aSJason M. Bills     {
20516428a1aSJason M. Bills         entryID += "_" + std::to_string(index);
20616428a1aSJason M. Bills     }
20716428a1aSJason M. Bills     return true;
20816428a1aSJason M. Bills }
20916428a1aSJason M. Bills 
210e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
211e85d6b16SJason M. Bills                              const bool firstEntry = true)
21295820184SJason M. Bills {
213271584abSEd Tanous     static time_t prevTs = 0;
21495820184SJason M. Bills     static int index = 0;
215e85d6b16SJason M. Bills     if (firstEntry)
216e85d6b16SJason M. Bills     {
217e85d6b16SJason M. Bills         prevTs = 0;
218e85d6b16SJason M. Bills     }
219e85d6b16SJason M. Bills 
22095820184SJason M. Bills     // Get the entry timestamp
221271584abSEd Tanous     std::time_t curTs = 0;
22295820184SJason M. Bills     std::tm timeStruct = {};
22395820184SJason M. Bills     std::istringstream entryStream(logEntry);
22495820184SJason M. Bills     if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
22595820184SJason M. Bills     {
22695820184SJason M. Bills         curTs = std::mktime(&timeStruct);
22795820184SJason M. Bills     }
22895820184SJason M. Bills     // If the timestamp isn't unique, increment the index
22995820184SJason M. Bills     if (curTs == prevTs)
23095820184SJason M. Bills     {
23195820184SJason M. Bills         index++;
23295820184SJason M. Bills     }
23395820184SJason M. Bills     else
23495820184SJason M. Bills     {
23595820184SJason M. Bills         // Otherwise, reset it
23695820184SJason M. Bills         index = 0;
23795820184SJason M. Bills     }
23895820184SJason M. Bills     // Save the timestamp
23995820184SJason M. Bills     prevTs = curTs;
24095820184SJason M. Bills 
24195820184SJason M. Bills     entryID = std::to_string(curTs);
24295820184SJason M. Bills     if (index > 0)
24395820184SJason M. Bills     {
24495820184SJason M. Bills         entryID += "_" + std::to_string(index);
24595820184SJason M. Bills     }
24695820184SJason M. Bills     return true;
24795820184SJason M. Bills }
24895820184SJason M. Bills 
2497e860f15SJohn Edward Broadbent inline static bool
2508d1b46d7Szhanghch05     getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2518d1b46d7Szhanghch05                        const std::string& entryID, uint64_t& timestamp,
2528d1b46d7Szhanghch05                        uint64_t& index)
25316428a1aSJason M. Bills {
25416428a1aSJason M. Bills     if (entryID.empty())
25516428a1aSJason M. Bills     {
25616428a1aSJason M. Bills         return false;
25716428a1aSJason M. Bills     }
25816428a1aSJason M. Bills     // Convert the unique ID back to a timestamp to find the entry
25939e77504SEd Tanous     std::string_view tsStr(entryID);
26016428a1aSJason M. Bills 
26181ce609eSEd Tanous     auto underscorePos = tsStr.find('_');
26271d5d8dbSEd Tanous     if (underscorePos != std::string_view::npos)
26316428a1aSJason M. Bills     {
26416428a1aSJason M. Bills         // Timestamp has an index
26516428a1aSJason M. Bills         tsStr.remove_suffix(tsStr.size() - underscorePos);
26639e77504SEd Tanous         std::string_view indexStr(entryID);
26716428a1aSJason M. Bills         indexStr.remove_prefix(underscorePos + 1);
268c0bd5e4bSEd Tanous         auto [ptr, ec] = std::from_chars(
269c0bd5e4bSEd Tanous             indexStr.data(), indexStr.data() + indexStr.size(), index);
270c0bd5e4bSEd Tanous         if (ec != std::errc())
27116428a1aSJason M. Bills         {
2729db4ba25SJiaqing Zhao             messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
27316428a1aSJason M. Bills             return false;
27416428a1aSJason M. Bills         }
27516428a1aSJason M. Bills     }
27616428a1aSJason M. Bills     // Timestamp has no index
277c0bd5e4bSEd Tanous     auto [ptr, ec] =
278c0bd5e4bSEd Tanous         std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp);
279c0bd5e4bSEd Tanous     if (ec != std::errc())
28016428a1aSJason M. Bills     {
2819db4ba25SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
28216428a1aSJason M. Bills         return false;
28316428a1aSJason M. Bills     }
28416428a1aSJason M. Bills     return true;
28516428a1aSJason M. Bills }
28616428a1aSJason M. Bills 
28795820184SJason M. Bills static bool
28895820184SJason M. Bills     getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
28995820184SJason M. Bills {
29095820184SJason M. Bills     static const std::filesystem::path redfishLogDir = "/var/log";
29195820184SJason M. Bills     static const std::string redfishLogFilename = "redfish";
29295820184SJason M. Bills 
29395820184SJason M. Bills     // Loop through the directory looking for redfish log files
29495820184SJason M. Bills     for (const std::filesystem::directory_entry& dirEnt :
29595820184SJason M. Bills          std::filesystem::directory_iterator(redfishLogDir))
29695820184SJason M. Bills     {
29795820184SJason M. Bills         // If we find a redfish log file, save the path
29895820184SJason M. Bills         std::string filename = dirEnt.path().filename();
29911ba3979SEd Tanous         if (filename.starts_with(redfishLogFilename))
30095820184SJason M. Bills         {
30195820184SJason M. Bills             redfishLogFiles.emplace_back(redfishLogDir / filename);
30295820184SJason M. Bills         }
30395820184SJason M. Bills     }
30495820184SJason M. Bills     // As the log files rotate, they are appended with a ".#" that is higher for
30595820184SJason M. Bills     // the older logs. Since we don't expect more than 10 log files, we
30695820184SJason M. Bills     // can just sort the list to get them in order from newest to oldest
30795820184SJason M. Bills     std::sort(redfishLogFiles.begin(), redfishLogFiles.end());
30895820184SJason M. Bills 
30995820184SJason M. Bills     return !redfishLogFiles.empty();
31095820184SJason M. Bills }
31195820184SJason M. Bills 
31268dd075aSAsmitha Karunanithi inline log_entry::OriginatorTypes
31368dd075aSAsmitha Karunanithi     mapDbusOriginatorTypeToRedfish(const std::string& originatorType)
31468dd075aSAsmitha Karunanithi {
31568dd075aSAsmitha Karunanithi     if (originatorType ==
31668dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client")
31768dd075aSAsmitha Karunanithi     {
31868dd075aSAsmitha Karunanithi         return log_entry::OriginatorTypes::Client;
31968dd075aSAsmitha Karunanithi     }
32068dd075aSAsmitha Karunanithi     if (originatorType ==
32168dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal")
32268dd075aSAsmitha Karunanithi     {
32368dd075aSAsmitha Karunanithi         return log_entry::OriginatorTypes::Internal;
32468dd075aSAsmitha Karunanithi     }
32568dd075aSAsmitha Karunanithi     if (originatorType ==
32668dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService")
32768dd075aSAsmitha Karunanithi     {
32868dd075aSAsmitha Karunanithi         return log_entry::OriginatorTypes::SupportingService;
32968dd075aSAsmitha Karunanithi     }
33068dd075aSAsmitha Karunanithi     return log_entry::OriginatorTypes::Invalid;
33168dd075aSAsmitha Karunanithi }
33268dd075aSAsmitha Karunanithi 
333aefe3786SClaire Weinan inline void parseDumpEntryFromDbusObject(
3342d613eb6SJiaqing Zhao     const dbus::utility::ManagedObjectType::value_type& object,
335c6fecdabSClaire Weinan     std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs,
33668dd075aSAsmitha Karunanithi     std::string& originatorId, log_entry::OriginatorTypes& originatorType,
337aefe3786SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
338aefe3786SClaire Weinan {
339aefe3786SClaire Weinan     for (const auto& interfaceMap : object.second)
340aefe3786SClaire Weinan     {
341aefe3786SClaire Weinan         if (interfaceMap.first == "xyz.openbmc_project.Common.Progress")
342aefe3786SClaire Weinan         {
343aefe3786SClaire Weinan             for (const auto& propertyMap : interfaceMap.second)
344aefe3786SClaire Weinan             {
345aefe3786SClaire Weinan                 if (propertyMap.first == "Status")
346aefe3786SClaire Weinan                 {
347aefe3786SClaire Weinan                     const auto* status =
348aefe3786SClaire Weinan                         std::get_if<std::string>(&propertyMap.second);
349aefe3786SClaire Weinan                     if (status == nullptr)
350aefe3786SClaire Weinan                     {
351aefe3786SClaire Weinan                         messages::internalError(asyncResp->res);
352aefe3786SClaire Weinan                         break;
353aefe3786SClaire Weinan                     }
354aefe3786SClaire Weinan                     dumpStatus = *status;
355aefe3786SClaire Weinan                 }
356aefe3786SClaire Weinan             }
357aefe3786SClaire Weinan         }
358aefe3786SClaire Weinan         else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
359aefe3786SClaire Weinan         {
360aefe3786SClaire Weinan             for (const auto& propertyMap : interfaceMap.second)
361aefe3786SClaire Weinan             {
362aefe3786SClaire Weinan                 if (propertyMap.first == "Size")
363aefe3786SClaire Weinan                 {
364aefe3786SClaire Weinan                     const auto* sizePtr =
365aefe3786SClaire Weinan                         std::get_if<uint64_t>(&propertyMap.second);
366aefe3786SClaire Weinan                     if (sizePtr == nullptr)
367aefe3786SClaire Weinan                     {
368aefe3786SClaire Weinan                         messages::internalError(asyncResp->res);
369aefe3786SClaire Weinan                         break;
370aefe3786SClaire Weinan                     }
371aefe3786SClaire Weinan                     size = *sizePtr;
372aefe3786SClaire Weinan                     break;
373aefe3786SClaire Weinan                 }
374aefe3786SClaire Weinan             }
375aefe3786SClaire Weinan         }
376aefe3786SClaire Weinan         else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime")
377aefe3786SClaire Weinan         {
378aefe3786SClaire Weinan             for (const auto& propertyMap : interfaceMap.second)
379aefe3786SClaire Weinan             {
380aefe3786SClaire Weinan                 if (propertyMap.first == "Elapsed")
381aefe3786SClaire Weinan                 {
382aefe3786SClaire Weinan                     const uint64_t* usecsTimeStamp =
383aefe3786SClaire Weinan                         std::get_if<uint64_t>(&propertyMap.second);
384aefe3786SClaire Weinan                     if (usecsTimeStamp == nullptr)
385aefe3786SClaire Weinan                     {
386aefe3786SClaire Weinan                         messages::internalError(asyncResp->res);
387aefe3786SClaire Weinan                         break;
388aefe3786SClaire Weinan                     }
389c6fecdabSClaire Weinan                     timestampUs = *usecsTimeStamp;
390aefe3786SClaire Weinan                     break;
391aefe3786SClaire Weinan                 }
392aefe3786SClaire Weinan             }
393aefe3786SClaire Weinan         }
39468dd075aSAsmitha Karunanithi         else if (interfaceMap.first ==
39568dd075aSAsmitha Karunanithi                  "xyz.openbmc_project.Common.OriginatedBy")
39668dd075aSAsmitha Karunanithi         {
39768dd075aSAsmitha Karunanithi             for (const auto& propertyMap : interfaceMap.second)
39868dd075aSAsmitha Karunanithi             {
39968dd075aSAsmitha Karunanithi                 if (propertyMap.first == "OriginatorId")
40068dd075aSAsmitha Karunanithi                 {
40168dd075aSAsmitha Karunanithi                     const std::string* id =
40268dd075aSAsmitha Karunanithi                         std::get_if<std::string>(&propertyMap.second);
40368dd075aSAsmitha Karunanithi                     if (id == nullptr)
40468dd075aSAsmitha Karunanithi                     {
40568dd075aSAsmitha Karunanithi                         messages::internalError(asyncResp->res);
40668dd075aSAsmitha Karunanithi                         break;
40768dd075aSAsmitha Karunanithi                     }
40868dd075aSAsmitha Karunanithi                     originatorId = *id;
40968dd075aSAsmitha Karunanithi                 }
41068dd075aSAsmitha Karunanithi 
41168dd075aSAsmitha Karunanithi                 if (propertyMap.first == "OriginatorType")
41268dd075aSAsmitha Karunanithi                 {
41368dd075aSAsmitha Karunanithi                     const std::string* type =
41468dd075aSAsmitha Karunanithi                         std::get_if<std::string>(&propertyMap.second);
41568dd075aSAsmitha Karunanithi                     if (type == nullptr)
41668dd075aSAsmitha Karunanithi                     {
41768dd075aSAsmitha Karunanithi                         messages::internalError(asyncResp->res);
41868dd075aSAsmitha Karunanithi                         break;
41968dd075aSAsmitha Karunanithi                     }
42068dd075aSAsmitha Karunanithi 
42168dd075aSAsmitha Karunanithi                     originatorType = mapDbusOriginatorTypeToRedfish(*type);
42268dd075aSAsmitha Karunanithi                     if (originatorType == log_entry::OriginatorTypes::Invalid)
42368dd075aSAsmitha Karunanithi                     {
42468dd075aSAsmitha Karunanithi                         messages::internalError(asyncResp->res);
42568dd075aSAsmitha Karunanithi                         break;
42668dd075aSAsmitha Karunanithi                     }
42768dd075aSAsmitha Karunanithi                 }
42868dd075aSAsmitha Karunanithi             }
42968dd075aSAsmitha Karunanithi         }
430aefe3786SClaire Weinan     }
431aefe3786SClaire Weinan }
432aefe3786SClaire Weinan 
43321ab404cSNan Zhou static std::string getDumpEntriesPath(const std::string& dumpType)
434fdd26906SClaire Weinan {
435fdd26906SClaire Weinan     std::string entriesPath;
436fdd26906SClaire Weinan 
437fdd26906SClaire Weinan     if (dumpType == "BMC")
438fdd26906SClaire Weinan     {
439fdd26906SClaire Weinan         entriesPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
440fdd26906SClaire Weinan     }
441fdd26906SClaire Weinan     else if (dumpType == "FaultLog")
442fdd26906SClaire Weinan     {
443fdd26906SClaire Weinan         entriesPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/";
444fdd26906SClaire Weinan     }
445fdd26906SClaire Weinan     else if (dumpType == "System")
446fdd26906SClaire Weinan     {
447fdd26906SClaire Weinan         entriesPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
448fdd26906SClaire Weinan     }
449fdd26906SClaire Weinan     else
450fdd26906SClaire Weinan     {
451fdd26906SClaire Weinan         BMCWEB_LOG_ERROR << "getDumpEntriesPath() invalid dump type: "
452fdd26906SClaire Weinan                          << dumpType;
453fdd26906SClaire Weinan     }
454fdd26906SClaire Weinan 
455fdd26906SClaire Weinan     // Returns empty string on error
456fdd26906SClaire Weinan     return entriesPath;
457fdd26906SClaire Weinan }
458fdd26906SClaire Weinan 
4598d1b46d7Szhanghch05 inline void
4608d1b46d7Szhanghch05     getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
4615cb1dd27SAsmitha Karunanithi                            const std::string& dumpType)
4625cb1dd27SAsmitha Karunanithi {
463fdd26906SClaire Weinan     std::string entriesPath = getDumpEntriesPath(dumpType);
464fdd26906SClaire Weinan     if (entriesPath.empty())
4655cb1dd27SAsmitha Karunanithi     {
4665cb1dd27SAsmitha Karunanithi         messages::internalError(asyncResp->res);
4675cb1dd27SAsmitha Karunanithi         return;
4685cb1dd27SAsmitha Karunanithi     }
4695cb1dd27SAsmitha Karunanithi 
4705cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
471fdd26906SClaire Weinan         [asyncResp, entriesPath,
4725e7e2dc5SEd Tanous          dumpType](const boost::system::error_code& ec,
473711ac7a9SEd Tanous                    dbus::utility::ManagedObjectType& resp) {
4745cb1dd27SAsmitha Karunanithi         if (ec)
4755cb1dd27SAsmitha Karunanithi         {
4765cb1dd27SAsmitha Karunanithi             BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
4775cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
4785cb1dd27SAsmitha Karunanithi             return;
4795cb1dd27SAsmitha Karunanithi         }
4805cb1dd27SAsmitha Karunanithi 
481fdd26906SClaire Weinan         // Remove ending slash
482fdd26906SClaire Weinan         std::string odataIdStr = entriesPath;
483fdd26906SClaire Weinan         if (!odataIdStr.empty())
484fdd26906SClaire Weinan         {
485fdd26906SClaire Weinan             odataIdStr.pop_back();
486fdd26906SClaire Weinan         }
487fdd26906SClaire Weinan 
488fdd26906SClaire Weinan         asyncResp->res.jsonValue["@odata.type"] =
489fdd26906SClaire Weinan             "#LogEntryCollection.LogEntryCollection";
490fdd26906SClaire Weinan         asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr);
491fdd26906SClaire Weinan         asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries";
492fdd26906SClaire Weinan         asyncResp->res.jsonValue["Description"] =
493fdd26906SClaire Weinan             "Collection of " + dumpType + " Dump Entries";
494fdd26906SClaire Weinan 
4955cb1dd27SAsmitha Karunanithi         nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
4965cb1dd27SAsmitha Karunanithi         entriesArray = nlohmann::json::array();
497b47452b2SAsmitha Karunanithi         std::string dumpEntryPath =
498b47452b2SAsmitha Karunanithi             "/xyz/openbmc_project/dump/" +
499002d39b4SEd Tanous             std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/";
5005cb1dd27SAsmitha Karunanithi 
501002d39b4SEd Tanous         std::sort(resp.begin(), resp.end(), [](const auto& l, const auto& r) {
502002d39b4SEd Tanous             return AlphanumLess<std::string>()(l.first.filename(),
503002d39b4SEd Tanous                                                r.first.filename());
504565dfb6fSClaire Weinan         });
505565dfb6fSClaire Weinan 
5065cb1dd27SAsmitha Karunanithi         for (auto& object : resp)
5075cb1dd27SAsmitha Karunanithi         {
508b47452b2SAsmitha Karunanithi             if (object.first.str.find(dumpEntryPath) == std::string::npos)
5095cb1dd27SAsmitha Karunanithi             {
5105cb1dd27SAsmitha Karunanithi                 continue;
5115cb1dd27SAsmitha Karunanithi             }
512c6fecdabSClaire Weinan             uint64_t timestampUs = 0;
5135cb1dd27SAsmitha Karunanithi             uint64_t size = 0;
51435440d18SAsmitha Karunanithi             std::string dumpStatus;
51568dd075aSAsmitha Karunanithi             std::string originatorId;
51668dd075aSAsmitha Karunanithi             log_entry::OriginatorTypes originatorType =
51768dd075aSAsmitha Karunanithi                 log_entry::OriginatorTypes::Internal;
518433b68b4SJason M. Bills             nlohmann::json::object_t thisEntry;
5192dfd18efSEd Tanous 
5202dfd18efSEd Tanous             std::string entryID = object.first.filename();
5212dfd18efSEd Tanous             if (entryID.empty())
5225cb1dd27SAsmitha Karunanithi             {
5235cb1dd27SAsmitha Karunanithi                 continue;
5245cb1dd27SAsmitha Karunanithi             }
5255cb1dd27SAsmitha Karunanithi 
526c6fecdabSClaire Weinan             parseDumpEntryFromDbusObject(object, dumpStatus, size, timestampUs,
52768dd075aSAsmitha Karunanithi                                          originatorId, originatorType,
528aefe3786SClaire Weinan                                          asyncResp);
5295cb1dd27SAsmitha Karunanithi 
5300fda0f12SGeorge Liu             if (dumpStatus !=
5310fda0f12SGeorge Liu                     "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
53235440d18SAsmitha Karunanithi                 !dumpStatus.empty())
53335440d18SAsmitha Karunanithi             {
53435440d18SAsmitha Karunanithi                 // Dump status is not Complete, no need to enumerate
53535440d18SAsmitha Karunanithi                 continue;
53635440d18SAsmitha Karunanithi             }
53735440d18SAsmitha Karunanithi 
53868dd075aSAsmitha Karunanithi             thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry";
539fdd26906SClaire Weinan             thisEntry["@odata.id"] = entriesPath + entryID;
5405cb1dd27SAsmitha Karunanithi             thisEntry["Id"] = entryID;
5415cb1dd27SAsmitha Karunanithi             thisEntry["EntryType"] = "Event";
5425cb1dd27SAsmitha Karunanithi             thisEntry["Name"] = dumpType + " Dump Entry";
543bbd80db8SClaire Weinan             thisEntry["Created"] =
544bbd80db8SClaire Weinan                 redfish::time_utils::getDateTimeUintUs(timestampUs);
5455cb1dd27SAsmitha Karunanithi 
54668dd075aSAsmitha Karunanithi             if (!originatorId.empty())
54768dd075aSAsmitha Karunanithi             {
54868dd075aSAsmitha Karunanithi                 thisEntry["Originator"] = originatorId;
54968dd075aSAsmitha Karunanithi                 thisEntry["OriginatorType"] = originatorType;
55068dd075aSAsmitha Karunanithi             }
55168dd075aSAsmitha Karunanithi 
5525cb1dd27SAsmitha Karunanithi             if (dumpType == "BMC")
5535cb1dd27SAsmitha Karunanithi             {
554d337bb72SAsmitha Karunanithi                 thisEntry["DiagnosticDataType"] = "Manager";
555d337bb72SAsmitha Karunanithi                 thisEntry["AdditionalDataURI"] =
556fdd26906SClaire Weinan                     entriesPath + entryID + "/attachment";
557fdd26906SClaire Weinan                 thisEntry["AdditionalDataSizeBytes"] = size;
5585cb1dd27SAsmitha Karunanithi             }
5595cb1dd27SAsmitha Karunanithi             else if (dumpType == "System")
5605cb1dd27SAsmitha Karunanithi             {
561d337bb72SAsmitha Karunanithi                 thisEntry["DiagnosticDataType"] = "OEM";
562d337bb72SAsmitha Karunanithi                 thisEntry["OEMDiagnosticDataType"] = "System";
563d337bb72SAsmitha Karunanithi                 thisEntry["AdditionalDataURI"] =
564fdd26906SClaire Weinan                     entriesPath + entryID + "/attachment";
565fdd26906SClaire Weinan                 thisEntry["AdditionalDataSizeBytes"] = size;
5665cb1dd27SAsmitha Karunanithi             }
56735440d18SAsmitha Karunanithi             entriesArray.push_back(std::move(thisEntry));
5685cb1dd27SAsmitha Karunanithi         }
569002d39b4SEd Tanous         asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
5705cb1dd27SAsmitha Karunanithi         },
5715cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
5725cb1dd27SAsmitha Karunanithi         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
5735cb1dd27SAsmitha Karunanithi }
5745cb1dd27SAsmitha Karunanithi 
5758d1b46d7Szhanghch05 inline void
576c7a6d660SClaire Weinan     getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
5778d1b46d7Szhanghch05                      const std::string& entryID, const std::string& dumpType)
5785cb1dd27SAsmitha Karunanithi {
579fdd26906SClaire Weinan     std::string entriesPath = getDumpEntriesPath(dumpType);
580fdd26906SClaire Weinan     if (entriesPath.empty())
5815cb1dd27SAsmitha Karunanithi     {
5825cb1dd27SAsmitha Karunanithi         messages::internalError(asyncResp->res);
5835cb1dd27SAsmitha Karunanithi         return;
5845cb1dd27SAsmitha Karunanithi     }
5855cb1dd27SAsmitha Karunanithi 
5865cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
587fdd26906SClaire Weinan         [asyncResp, entryID, dumpType,
5885e7e2dc5SEd Tanous          entriesPath](const boost::system::error_code& ec,
58902cad96eSEd Tanous                       const dbus::utility::ManagedObjectType& resp) {
5905cb1dd27SAsmitha Karunanithi         if (ec)
5915cb1dd27SAsmitha Karunanithi         {
5925cb1dd27SAsmitha Karunanithi             BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
5935cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
5945cb1dd27SAsmitha Karunanithi             return;
5955cb1dd27SAsmitha Karunanithi         }
5965cb1dd27SAsmitha Karunanithi 
597b47452b2SAsmitha Karunanithi         bool foundDumpEntry = false;
598b47452b2SAsmitha Karunanithi         std::string dumpEntryPath =
599b47452b2SAsmitha Karunanithi             "/xyz/openbmc_project/dump/" +
600002d39b4SEd Tanous             std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/";
601b47452b2SAsmitha Karunanithi 
6029eb808c1SEd Tanous         for (const auto& objectPath : resp)
6035cb1dd27SAsmitha Karunanithi         {
604b47452b2SAsmitha Karunanithi             if (objectPath.first.str != dumpEntryPath + entryID)
6055cb1dd27SAsmitha Karunanithi             {
6065cb1dd27SAsmitha Karunanithi                 continue;
6075cb1dd27SAsmitha Karunanithi             }
6085cb1dd27SAsmitha Karunanithi 
6095cb1dd27SAsmitha Karunanithi             foundDumpEntry = true;
610c6fecdabSClaire Weinan             uint64_t timestampUs = 0;
6115cb1dd27SAsmitha Karunanithi             uint64_t size = 0;
61235440d18SAsmitha Karunanithi             std::string dumpStatus;
61368dd075aSAsmitha Karunanithi             std::string originatorId;
61468dd075aSAsmitha Karunanithi             log_entry::OriginatorTypes originatorType =
61568dd075aSAsmitha Karunanithi                 log_entry::OriginatorTypes::Internal;
6165cb1dd27SAsmitha Karunanithi 
617aefe3786SClaire Weinan             parseDumpEntryFromDbusObject(objectPath, dumpStatus, size,
61868dd075aSAsmitha Karunanithi                                          timestampUs, originatorId,
61968dd075aSAsmitha Karunanithi                                          originatorType, asyncResp);
6205cb1dd27SAsmitha Karunanithi 
6210fda0f12SGeorge Liu             if (dumpStatus !=
6220fda0f12SGeorge Liu                     "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
62335440d18SAsmitha Karunanithi                 !dumpStatus.empty())
62435440d18SAsmitha Karunanithi             {
62535440d18SAsmitha Karunanithi                 // Dump status is not Complete
62635440d18SAsmitha Karunanithi                 // return not found until status is changed to Completed
627d1bde9e5SKrzysztof Grobelny                 messages::resourceNotFound(asyncResp->res, dumpType + " dump",
628d1bde9e5SKrzysztof Grobelny                                            entryID);
62935440d18SAsmitha Karunanithi                 return;
63035440d18SAsmitha Karunanithi             }
63135440d18SAsmitha Karunanithi 
6325cb1dd27SAsmitha Karunanithi             asyncResp->res.jsonValue["@odata.type"] =
63368dd075aSAsmitha Karunanithi                 "#LogEntry.v1_11_0.LogEntry";
634fdd26906SClaire Weinan             asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID;
6355cb1dd27SAsmitha Karunanithi             asyncResp->res.jsonValue["Id"] = entryID;
6365cb1dd27SAsmitha Karunanithi             asyncResp->res.jsonValue["EntryType"] = "Event";
6375cb1dd27SAsmitha Karunanithi             asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
638bbd80db8SClaire Weinan             asyncResp->res.jsonValue["Created"] =
639bbd80db8SClaire Weinan                 redfish::time_utils::getDateTimeUintUs(timestampUs);
6405cb1dd27SAsmitha Karunanithi 
64168dd075aSAsmitha Karunanithi             if (!originatorId.empty())
64268dd075aSAsmitha Karunanithi             {
64368dd075aSAsmitha Karunanithi                 asyncResp->res.jsonValue["Originator"] = originatorId;
64468dd075aSAsmitha Karunanithi                 asyncResp->res.jsonValue["OriginatorType"] = originatorType;
64568dd075aSAsmitha Karunanithi             }
64668dd075aSAsmitha Karunanithi 
6475cb1dd27SAsmitha Karunanithi             if (dumpType == "BMC")
6485cb1dd27SAsmitha Karunanithi             {
649d337bb72SAsmitha Karunanithi                 asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
650d337bb72SAsmitha Karunanithi                 asyncResp->res.jsonValue["AdditionalDataURI"] =
651fdd26906SClaire Weinan                     entriesPath + entryID + "/attachment";
652fdd26906SClaire Weinan                 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
6535cb1dd27SAsmitha Karunanithi             }
6545cb1dd27SAsmitha Karunanithi             else if (dumpType == "System")
6555cb1dd27SAsmitha Karunanithi             {
656d337bb72SAsmitha Karunanithi                 asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
657002d39b4SEd Tanous                 asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System";
658d337bb72SAsmitha Karunanithi                 asyncResp->res.jsonValue["AdditionalDataURI"] =
659fdd26906SClaire Weinan                     entriesPath + entryID + "/attachment";
660fdd26906SClaire Weinan                 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
6615cb1dd27SAsmitha Karunanithi             }
6625cb1dd27SAsmitha Karunanithi         }
663e05aec50SEd Tanous         if (!foundDumpEntry)
664b47452b2SAsmitha Karunanithi         {
665b47452b2SAsmitha Karunanithi             BMCWEB_LOG_ERROR << "Can't find Dump Entry";
666b47452b2SAsmitha Karunanithi             messages::internalError(asyncResp->res);
667b47452b2SAsmitha Karunanithi             return;
668b47452b2SAsmitha Karunanithi         }
6695cb1dd27SAsmitha Karunanithi         },
6705cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
6715cb1dd27SAsmitha Karunanithi         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
6725cb1dd27SAsmitha Karunanithi }
6735cb1dd27SAsmitha Karunanithi 
6748d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
6759878256fSStanley Chu                             const std::string& entryID,
676b47452b2SAsmitha Karunanithi                             const std::string& dumpType)
6775cb1dd27SAsmitha Karunanithi {
678002d39b4SEd Tanous     auto respHandler =
6795e7e2dc5SEd Tanous         [asyncResp, entryID](const boost::system::error_code& ec) {
6805cb1dd27SAsmitha Karunanithi         BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done";
6815cb1dd27SAsmitha Karunanithi         if (ec)
6825cb1dd27SAsmitha Karunanithi         {
6833de8d8baSGeorge Liu             if (ec.value() == EBADR)
6843de8d8baSGeorge Liu             {
6853de8d8baSGeorge Liu                 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
6863de8d8baSGeorge Liu                 return;
6873de8d8baSGeorge Liu             }
6885cb1dd27SAsmitha Karunanithi             BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error "
689fdd26906SClaire Weinan                              << ec << " entryID=" << entryID;
6905cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
6915cb1dd27SAsmitha Karunanithi             return;
6925cb1dd27SAsmitha Karunanithi         }
6935cb1dd27SAsmitha Karunanithi     };
6945cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
6955cb1dd27SAsmitha Karunanithi         respHandler, "xyz.openbmc_project.Dump.Manager",
696b47452b2SAsmitha Karunanithi         "/xyz/openbmc_project/dump/" +
697b47452b2SAsmitha Karunanithi             std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" +
698b47452b2SAsmitha Karunanithi             entryID,
6995cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Object.Delete", "Delete");
7005cb1dd27SAsmitha Karunanithi }
7015cb1dd27SAsmitha Karunanithi 
7028e31778eSAsmitha Karunanithi inline DumpCreationProgress
7038e31778eSAsmitha Karunanithi     mapDbusStatusToDumpProgress(const std::string& status)
704a43be80fSAsmitha Karunanithi {
7058e31778eSAsmitha Karunanithi     if (status ==
7068e31778eSAsmitha Karunanithi             "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" ||
7078e31778eSAsmitha Karunanithi         status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted")
7088e31778eSAsmitha Karunanithi     {
7098e31778eSAsmitha Karunanithi         return DumpCreationProgress::DUMP_CREATE_FAILED;
7108e31778eSAsmitha Karunanithi     }
7118e31778eSAsmitha Karunanithi     if (status ==
7128e31778eSAsmitha Karunanithi         "xyz.openbmc_project.Common.Progress.OperationStatus.Completed")
7138e31778eSAsmitha Karunanithi     {
7148e31778eSAsmitha Karunanithi         return DumpCreationProgress::DUMP_CREATE_SUCCESS;
7158e31778eSAsmitha Karunanithi     }
7168e31778eSAsmitha Karunanithi     return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
7178e31778eSAsmitha Karunanithi }
7188e31778eSAsmitha Karunanithi 
7198e31778eSAsmitha Karunanithi inline DumpCreationProgress
7208e31778eSAsmitha Karunanithi     getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values)
7218e31778eSAsmitha Karunanithi {
7228e31778eSAsmitha Karunanithi     for (const auto& [key, val] : values)
7238e31778eSAsmitha Karunanithi     {
7248e31778eSAsmitha Karunanithi         if (key == "Status")
7258e31778eSAsmitha Karunanithi         {
7268e31778eSAsmitha Karunanithi             const std::string* value = std::get_if<std::string>(&val);
7278e31778eSAsmitha Karunanithi             if (value == nullptr)
7288e31778eSAsmitha Karunanithi             {
7298e31778eSAsmitha Karunanithi                 BMCWEB_LOG_ERROR << "Status property value is null";
7308e31778eSAsmitha Karunanithi                 return DumpCreationProgress::DUMP_CREATE_FAILED;
7318e31778eSAsmitha Karunanithi             }
7328e31778eSAsmitha Karunanithi             return mapDbusStatusToDumpProgress(*value);
7338e31778eSAsmitha Karunanithi         }
7348e31778eSAsmitha Karunanithi     }
7358e31778eSAsmitha Karunanithi     return DumpCreationProgress::DUMP_CREATE_INPROGRESS;
7368e31778eSAsmitha Karunanithi }
7378e31778eSAsmitha Karunanithi 
7388e31778eSAsmitha Karunanithi inline std::string getDumpEntryPath(const std::string& dumpPath)
7398e31778eSAsmitha Karunanithi {
7408e31778eSAsmitha Karunanithi     if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry")
7418e31778eSAsmitha Karunanithi     {
7428e31778eSAsmitha Karunanithi         return "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
7438e31778eSAsmitha Karunanithi     }
7448e31778eSAsmitha Karunanithi     if (dumpPath == "/xyz/openbmc_project/dump/system/entry")
7458e31778eSAsmitha Karunanithi     {
7468e31778eSAsmitha Karunanithi         return "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
7478e31778eSAsmitha Karunanithi     }
7488e31778eSAsmitha Karunanithi     return "";
7498e31778eSAsmitha Karunanithi }
7508e31778eSAsmitha Karunanithi 
7518e31778eSAsmitha Karunanithi inline void createDumpTaskCallback(
7528e31778eSAsmitha Karunanithi     task::Payload&& payload,
7538e31778eSAsmitha Karunanithi     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
7548e31778eSAsmitha Karunanithi     const sdbusplus::message::object_path& createdObjPath)
7558e31778eSAsmitha Karunanithi {
7568e31778eSAsmitha Karunanithi     const std::string dumpPath = createdObjPath.parent_path().str;
7578e31778eSAsmitha Karunanithi     const std::string dumpId = createdObjPath.filename();
7588e31778eSAsmitha Karunanithi 
7598e31778eSAsmitha Karunanithi     std::string dumpEntryPath = getDumpEntryPath(dumpPath);
7608e31778eSAsmitha Karunanithi 
7618e31778eSAsmitha Karunanithi     if (dumpEntryPath.empty())
7628e31778eSAsmitha Karunanithi     {
7638e31778eSAsmitha Karunanithi         BMCWEB_LOG_ERROR << "Invalid dump type received";
7648e31778eSAsmitha Karunanithi         messages::internalError(asyncResp->res);
7658e31778eSAsmitha Karunanithi         return;
7668e31778eSAsmitha Karunanithi     }
7678e31778eSAsmitha Karunanithi 
7688e31778eSAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
7698e31778eSAsmitha Karunanithi         [asyncResp, payload, createdObjPath,
7708e31778eSAsmitha Karunanithi          dumpEntryPath{std::move(dumpEntryPath)},
7715e7e2dc5SEd Tanous          dumpId](const boost::system::error_code& ec,
7728e31778eSAsmitha Karunanithi                  const std::string& introspectXml) {
7738e31778eSAsmitha Karunanithi         if (ec)
7748e31778eSAsmitha Karunanithi         {
7758e31778eSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "Introspect call failed with error: "
7768e31778eSAsmitha Karunanithi                              << ec.message();
7778e31778eSAsmitha Karunanithi             messages::internalError(asyncResp->res);
7788e31778eSAsmitha Karunanithi             return;
7798e31778eSAsmitha Karunanithi         }
7808e31778eSAsmitha Karunanithi 
7818e31778eSAsmitha Karunanithi         // Check if the created dump object has implemented Progress
7828e31778eSAsmitha Karunanithi         // interface to track dump completion. If yes, fetch the "Status"
7838e31778eSAsmitha Karunanithi         // property of the interface, modify the task state accordingly.
7848e31778eSAsmitha Karunanithi         // Else, return task completed.
7858e31778eSAsmitha Karunanithi         tinyxml2::XMLDocument doc;
7868e31778eSAsmitha Karunanithi 
7878e31778eSAsmitha Karunanithi         doc.Parse(introspectXml.data(), introspectXml.size());
7888e31778eSAsmitha Karunanithi         tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
7898e31778eSAsmitha Karunanithi         if (pRoot == nullptr)
7908e31778eSAsmitha Karunanithi         {
7918e31778eSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "XML document failed to parse";
7928e31778eSAsmitha Karunanithi             messages::internalError(asyncResp->res);
7938e31778eSAsmitha Karunanithi             return;
7948e31778eSAsmitha Karunanithi         }
7958e31778eSAsmitha Karunanithi         tinyxml2::XMLElement* interfaceNode =
7968e31778eSAsmitha Karunanithi             pRoot->FirstChildElement("interface");
7978e31778eSAsmitha Karunanithi 
7988e31778eSAsmitha Karunanithi         bool isProgressIntfPresent = false;
7998e31778eSAsmitha Karunanithi         while (interfaceNode != nullptr)
8008e31778eSAsmitha Karunanithi         {
8018e31778eSAsmitha Karunanithi             const char* thisInterfaceName = interfaceNode->Attribute("name");
8028e31778eSAsmitha Karunanithi             if (thisInterfaceName != nullptr)
8038e31778eSAsmitha Karunanithi             {
8048e31778eSAsmitha Karunanithi                 if (thisInterfaceName ==
8058e31778eSAsmitha Karunanithi                     std::string_view("xyz.openbmc_project.Common.Progress"))
8068e31778eSAsmitha Karunanithi                 {
8078e31778eSAsmitha Karunanithi                     interfaceNode =
8088e31778eSAsmitha Karunanithi                         interfaceNode->NextSiblingElement("interface");
8098e31778eSAsmitha Karunanithi                     continue;
8108e31778eSAsmitha Karunanithi                 }
8118e31778eSAsmitha Karunanithi                 isProgressIntfPresent = true;
8128e31778eSAsmitha Karunanithi                 break;
8138e31778eSAsmitha Karunanithi             }
8148e31778eSAsmitha Karunanithi             interfaceNode = interfaceNode->NextSiblingElement("interface");
8158e31778eSAsmitha Karunanithi         }
8168e31778eSAsmitha Karunanithi 
817a43be80fSAsmitha Karunanithi         std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
8188e31778eSAsmitha Karunanithi             [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent](
8195e7e2dc5SEd Tanous                 const boost::system::error_code& err, sdbusplus::message_t& msg,
820a43be80fSAsmitha Karunanithi                 const std::shared_ptr<task::TaskData>& taskData) {
821cb13a392SEd Tanous             if (err)
822cb13a392SEd Tanous             {
8238e31778eSAsmitha Karunanithi                 BMCWEB_LOG_ERROR << createdObjPath.str
8248e31778eSAsmitha Karunanithi                                  << ": Error in creating dump";
8258e31778eSAsmitha Karunanithi                 taskData->messages.emplace_back(messages::internalError());
8266145ed6fSAsmitha Karunanithi                 taskData->state = "Cancelled";
8276145ed6fSAsmitha Karunanithi                 return task::completed;
828cb13a392SEd Tanous             }
829b9d36b47SEd Tanous 
8308e31778eSAsmitha Karunanithi             if (isProgressIntfPresent)
831a43be80fSAsmitha Karunanithi             {
8328e31778eSAsmitha Karunanithi                 dbus::utility::DBusPropertiesMap values;
8338e31778eSAsmitha Karunanithi                 std::string prop;
8348e31778eSAsmitha Karunanithi                 msg.read(prop, values);
8358e31778eSAsmitha Karunanithi 
8368e31778eSAsmitha Karunanithi                 DumpCreationProgress dumpStatus =
8378e31778eSAsmitha Karunanithi                     getDumpCompletionStatus(values);
8388e31778eSAsmitha Karunanithi                 if (dumpStatus == DumpCreationProgress::DUMP_CREATE_FAILED)
8398e31778eSAsmitha Karunanithi                 {
8408e31778eSAsmitha Karunanithi                     BMCWEB_LOG_ERROR << createdObjPath.str
8418e31778eSAsmitha Karunanithi                                      << ": Error in creating dump";
8428e31778eSAsmitha Karunanithi                     taskData->state = "Cancelled";
8438e31778eSAsmitha Karunanithi                     return task::completed;
8448e31778eSAsmitha Karunanithi                 }
8458e31778eSAsmitha Karunanithi 
8468e31778eSAsmitha Karunanithi                 if (dumpStatus == DumpCreationProgress::DUMP_CREATE_INPROGRESS)
8478e31778eSAsmitha Karunanithi                 {
8488e31778eSAsmitha Karunanithi                     BMCWEB_LOG_DEBUG << createdObjPath.str
8498e31778eSAsmitha Karunanithi                                      << ": Dump creation task is in progress";
8508e31778eSAsmitha Karunanithi                     return !task::completed;
8518e31778eSAsmitha Karunanithi                 }
8528e31778eSAsmitha Karunanithi             }
8538e31778eSAsmitha Karunanithi 
854a43be80fSAsmitha Karunanithi             nlohmann::json retMessage = messages::success();
855a43be80fSAsmitha Karunanithi             taskData->messages.emplace_back(retMessage);
856a43be80fSAsmitha Karunanithi 
857a43be80fSAsmitha Karunanithi             std::string headerLoc =
8588e31778eSAsmitha Karunanithi                 "Location: " + dumpEntryPath + http_helpers::urlEncode(dumpId);
859002d39b4SEd Tanous             taskData->payload->httpHeaders.emplace_back(std::move(headerLoc));
860a43be80fSAsmitha Karunanithi 
8618e31778eSAsmitha Karunanithi             BMCWEB_LOG_DEBUG << createdObjPath.str
8628e31778eSAsmitha Karunanithi                              << ": Dump creation task completed";
863a43be80fSAsmitha Karunanithi             taskData->state = "Completed";
864b47452b2SAsmitha Karunanithi             return task::completed;
865a43be80fSAsmitha Karunanithi             },
8668e31778eSAsmitha Karunanithi             "type='signal',interface='org.freedesktop.DBus.Properties',"
8678e31778eSAsmitha Karunanithi             "member='PropertiesChanged',path='" +
8688e31778eSAsmitha Karunanithi                 createdObjPath.str + "'");
869a43be80fSAsmitha Karunanithi 
8708e31778eSAsmitha Karunanithi         // The task timer is set to max time limit within which the
8718e31778eSAsmitha Karunanithi         // requested dump will be collected.
8728e31778eSAsmitha Karunanithi         task->startTimer(std::chrono::minutes(6));
873a43be80fSAsmitha Karunanithi         task->populateResp(asyncResp->res);
8748e31778eSAsmitha Karunanithi         task->payload.emplace(payload);
8758e31778eSAsmitha Karunanithi         },
8768e31778eSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager", createdObjPath,
8778e31778eSAsmitha Karunanithi         "org.freedesktop.DBus.Introspectable", "Introspect");
878a43be80fSAsmitha Karunanithi }
879a43be80fSAsmitha Karunanithi 
8808d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
8818d1b46d7Szhanghch05                        const crow::Request& req, const std::string& dumpType)
882a43be80fSAsmitha Karunanithi {
883fdd26906SClaire Weinan     std::string dumpPath = getDumpEntriesPath(dumpType);
884fdd26906SClaire Weinan     if (dumpPath.empty())
885a43be80fSAsmitha Karunanithi     {
886a43be80fSAsmitha Karunanithi         messages::internalError(asyncResp->res);
887a43be80fSAsmitha Karunanithi         return;
888a43be80fSAsmitha Karunanithi     }
889a43be80fSAsmitha Karunanithi 
890a43be80fSAsmitha Karunanithi     std::optional<std::string> diagnosticDataType;
891a43be80fSAsmitha Karunanithi     std::optional<std::string> oemDiagnosticDataType;
892a43be80fSAsmitha Karunanithi 
89315ed6780SWilly Tu     if (!redfish::json_util::readJsonAction(
894a43be80fSAsmitha Karunanithi             req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
895a43be80fSAsmitha Karunanithi             "OEMDiagnosticDataType", oemDiagnosticDataType))
896a43be80fSAsmitha Karunanithi     {
897a43be80fSAsmitha Karunanithi         return;
898a43be80fSAsmitha Karunanithi     }
899a43be80fSAsmitha Karunanithi 
900a43be80fSAsmitha Karunanithi     if (dumpType == "System")
901a43be80fSAsmitha Karunanithi     {
902a43be80fSAsmitha Karunanithi         if (!oemDiagnosticDataType || !diagnosticDataType)
903a43be80fSAsmitha Karunanithi         {
9044978b63fSJason M. Bills             BMCWEB_LOG_ERROR
9054978b63fSJason M. Bills                 << "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!";
906a43be80fSAsmitha Karunanithi             messages::actionParameterMissing(
907a43be80fSAsmitha Karunanithi                 asyncResp->res, "CollectDiagnosticData",
908a43be80fSAsmitha Karunanithi                 "DiagnosticDataType & OEMDiagnosticDataType");
909a43be80fSAsmitha Karunanithi             return;
910a43be80fSAsmitha Karunanithi         }
9113174e4dfSEd Tanous         if ((*oemDiagnosticDataType != "System") ||
912a43be80fSAsmitha Karunanithi             (*diagnosticDataType != "OEM"))
913a43be80fSAsmitha Karunanithi         {
914a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "Wrong parameter values passed";
915ace85d60SEd Tanous             messages::internalError(asyncResp->res);
916a43be80fSAsmitha Karunanithi             return;
917a43be80fSAsmitha Karunanithi         }
9185907571dSAsmitha Karunanithi         dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/";
919a43be80fSAsmitha Karunanithi     }
920a43be80fSAsmitha Karunanithi     else if (dumpType == "BMC")
921a43be80fSAsmitha Karunanithi     {
922a43be80fSAsmitha Karunanithi         if (!diagnosticDataType)
923a43be80fSAsmitha Karunanithi         {
9240fda0f12SGeorge Liu             BMCWEB_LOG_ERROR
9250fda0f12SGeorge Liu                 << "CreateDump action parameter 'DiagnosticDataType' not found!";
926a43be80fSAsmitha Karunanithi             messages::actionParameterMissing(
927a43be80fSAsmitha Karunanithi                 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
928a43be80fSAsmitha Karunanithi             return;
929a43be80fSAsmitha Karunanithi         }
9303174e4dfSEd Tanous         if (*diagnosticDataType != "Manager")
931a43be80fSAsmitha Karunanithi         {
932a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR
933a43be80fSAsmitha Karunanithi                 << "Wrong parameter value passed for 'DiagnosticDataType'";
934ace85d60SEd Tanous             messages::internalError(asyncResp->res);
935a43be80fSAsmitha Karunanithi             return;
936a43be80fSAsmitha Karunanithi         }
9375907571dSAsmitha Karunanithi         dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/";
9385907571dSAsmitha Karunanithi     }
9395907571dSAsmitha Karunanithi     else
9405907571dSAsmitha Karunanithi     {
9415907571dSAsmitha Karunanithi         BMCWEB_LOG_ERROR << "CreateDump failed. Unknown dump type";
9425907571dSAsmitha Karunanithi         messages::internalError(asyncResp->res);
9435907571dSAsmitha Karunanithi         return;
944a43be80fSAsmitha Karunanithi     }
945a43be80fSAsmitha Karunanithi 
9468e31778eSAsmitha Karunanithi     std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>>
9478e31778eSAsmitha Karunanithi         createDumpParamVec;
9488e31778eSAsmitha Karunanithi 
94968dd075aSAsmitha Karunanithi     createDumpParamVec.emplace_back(
95068dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId",
95168dd075aSAsmitha Karunanithi         req.session->clientIp);
95268dd075aSAsmitha Karunanithi     createDumpParamVec.emplace_back(
95368dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType",
95468dd075aSAsmitha Karunanithi         "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client");
95568dd075aSAsmitha Karunanithi 
956a43be80fSAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
9575e7e2dc5SEd Tanous         [asyncResp, payload(task::Payload(req)),
9585e7e2dc5SEd Tanous          dumpPath](const boost::system::error_code& ec,
9595e7e2dc5SEd Tanous                    const sdbusplus::message_t& msg,
9608e31778eSAsmitha Karunanithi                    const sdbusplus::message::object_path& objPath) mutable {
961a43be80fSAsmitha Karunanithi         if (ec)
962a43be80fSAsmitha Karunanithi         {
963a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
9645907571dSAsmitha Karunanithi             const sd_bus_error* dbusError = msg.get_error();
9655907571dSAsmitha Karunanithi             if (dbusError == nullptr)
9665907571dSAsmitha Karunanithi             {
9675907571dSAsmitha Karunanithi                 messages::internalError(asyncResp->res);
9685907571dSAsmitha Karunanithi                 return;
9695907571dSAsmitha Karunanithi             }
9705907571dSAsmitha Karunanithi 
9715907571dSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "CreateDump DBus error: " << dbusError->name
9725907571dSAsmitha Karunanithi                              << " and error msg: " << dbusError->message;
9735907571dSAsmitha Karunanithi             if (std::string_view(
9745907571dSAsmitha Karunanithi                     "xyz.openbmc_project.Common.Error.NotAllowed") ==
9755907571dSAsmitha Karunanithi                 dbusError->name)
9765907571dSAsmitha Karunanithi             {
9775907571dSAsmitha Karunanithi                 messages::resourceInStandby(asyncResp->res);
9785907571dSAsmitha Karunanithi                 return;
9795907571dSAsmitha Karunanithi             }
9805907571dSAsmitha Karunanithi             if (std::string_view(
9815907571dSAsmitha Karunanithi                     "xyz.openbmc_project.Dump.Create.Error.Disabled") ==
9825907571dSAsmitha Karunanithi                 dbusError->name)
9835907571dSAsmitha Karunanithi             {
9845907571dSAsmitha Karunanithi                 messages::serviceDisabled(asyncResp->res, dumpPath);
9855907571dSAsmitha Karunanithi                 return;
9865907571dSAsmitha Karunanithi             }
9875907571dSAsmitha Karunanithi             if (std::string_view(
9885907571dSAsmitha Karunanithi                     "xyz.openbmc_project.Common.Error.Unavailable") ==
9895907571dSAsmitha Karunanithi                 dbusError->name)
9905907571dSAsmitha Karunanithi             {
9915907571dSAsmitha Karunanithi                 messages::resourceInUse(asyncResp->res);
9925907571dSAsmitha Karunanithi                 return;
9935907571dSAsmitha Karunanithi             }
9945907571dSAsmitha Karunanithi             // Other Dbus errors such as:
9955907571dSAsmitha Karunanithi             // xyz.openbmc_project.Common.Error.InvalidArgument &
9965907571dSAsmitha Karunanithi             // org.freedesktop.DBus.Error.InvalidArgs are all related to
9975907571dSAsmitha Karunanithi             // the dbus call that is made here in the bmcweb
9985907571dSAsmitha Karunanithi             // implementation and has nothing to do with the client's
9995907571dSAsmitha Karunanithi             // input in the request. Hence, returning internal error
10005907571dSAsmitha Karunanithi             // back to the client.
1001a43be80fSAsmitha Karunanithi             messages::internalError(asyncResp->res);
1002a43be80fSAsmitha Karunanithi             return;
1003a43be80fSAsmitha Karunanithi         }
10048e31778eSAsmitha Karunanithi         BMCWEB_LOG_DEBUG << "Dump Created. Path: " << objPath.str;
10058e31778eSAsmitha Karunanithi         createDumpTaskCallback(std::move(payload), asyncResp, objPath);
1006a43be80fSAsmitha Karunanithi         },
1007b47452b2SAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager",
1008b47452b2SAsmitha Karunanithi         "/xyz/openbmc_project/dump/" +
1009b47452b2SAsmitha Karunanithi             std::string(boost::algorithm::to_lower_copy(dumpType)),
10108e31778eSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec);
1011a43be80fSAsmitha Karunanithi }
1012a43be80fSAsmitha Karunanithi 
10138d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
10148d1b46d7Szhanghch05                       const std::string& dumpType)
101580319af1SAsmitha Karunanithi {
1016b47452b2SAsmitha Karunanithi     std::string dumpTypeLowerCopy =
1017b47452b2SAsmitha Karunanithi         std::string(boost::algorithm::to_lower_copy(dumpType));
10188d1b46d7Szhanghch05 
10190d946211SClaire Weinan     crow::connections::systemBus->async_method_call(
10200d946211SClaire Weinan         [asyncResp](const boost::system::error_code& ec) {
102180319af1SAsmitha Karunanithi         if (ec)
102280319af1SAsmitha Karunanithi         {
10230d946211SClaire Weinan             BMCWEB_LOG_ERROR << "clearDump resp_handler got error " << ec;
102480319af1SAsmitha Karunanithi             messages::internalError(asyncResp->res);
102580319af1SAsmitha Karunanithi             return;
102680319af1SAsmitha Karunanithi         }
10270d946211SClaire Weinan         },
10280d946211SClaire Weinan         "xyz.openbmc_project.Dump.Manager",
10290d946211SClaire Weinan         "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy,
10300d946211SClaire Weinan         "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
103180319af1SAsmitha Karunanithi }
103280319af1SAsmitha Karunanithi 
1033b9d36b47SEd Tanous inline static void
1034b9d36b47SEd Tanous     parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params,
1035b9d36b47SEd Tanous                              std::string& filename, std::string& timestamp,
1036b9d36b47SEd Tanous                              std::string& logfile)
1037043a0536SJohnathan Mantey {
1038d1bde9e5SKrzysztof Grobelny     const std::string* filenamePtr = nullptr;
1039d1bde9e5SKrzysztof Grobelny     const std::string* timestampPtr = nullptr;
1040d1bde9e5SKrzysztof Grobelny     const std::string* logfilePtr = nullptr;
1041d1bde9e5SKrzysztof Grobelny 
1042d1bde9e5SKrzysztof Grobelny     const bool success = sdbusplus::unpackPropertiesNoThrow(
1043d1bde9e5SKrzysztof Grobelny         dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr,
1044d1bde9e5SKrzysztof Grobelny         "Filename", filenamePtr, "Log", logfilePtr);
1045d1bde9e5SKrzysztof Grobelny 
1046d1bde9e5SKrzysztof Grobelny     if (!success)
1047043a0536SJohnathan Mantey     {
1048d1bde9e5SKrzysztof Grobelny         return;
1049043a0536SJohnathan Mantey     }
1050d1bde9e5SKrzysztof Grobelny 
1051d1bde9e5SKrzysztof Grobelny     if (filenamePtr != nullptr)
1052043a0536SJohnathan Mantey     {
1053d1bde9e5SKrzysztof Grobelny         filename = *filenamePtr;
1054d1bde9e5SKrzysztof Grobelny     }
1055d1bde9e5SKrzysztof Grobelny 
1056d1bde9e5SKrzysztof Grobelny     if (timestampPtr != nullptr)
1057043a0536SJohnathan Mantey     {
1058d1bde9e5SKrzysztof Grobelny         timestamp = *timestampPtr;
1059043a0536SJohnathan Mantey     }
1060d1bde9e5SKrzysztof Grobelny 
1061d1bde9e5SKrzysztof Grobelny     if (logfilePtr != nullptr)
1062043a0536SJohnathan Mantey     {
1063d1bde9e5SKrzysztof Grobelny         logfile = *logfilePtr;
1064043a0536SJohnathan Mantey     }
1065043a0536SJohnathan Mantey }
1066043a0536SJohnathan Mantey 
10677e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app)
10681da66f75SEd Tanous {
1069c4bf6374SJason M. Bills     /**
1070c4bf6374SJason M. Bills      * Functions triggers appropriate requests on DBus
1071c4bf6374SJason M. Bills      */
107222d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
1073ed398213SEd Tanous         .privileges(redfish::privileges::getLogServiceCollection)
1074002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1075002d39b4SEd Tanous             [&app](const crow::Request& req,
107622d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
107722d268cbSEd Tanous                    const std::string& systemName) {
10783ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1079c4bf6374SJason M. Bills         {
108045ca1b86SEd Tanous             return;
108145ca1b86SEd Tanous         }
108222d268cbSEd Tanous         if (systemName != "system")
108322d268cbSEd Tanous         {
108422d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
108522d268cbSEd Tanous                                        systemName);
108622d268cbSEd Tanous             return;
108722d268cbSEd Tanous         }
108822d268cbSEd Tanous 
10897e860f15SJohn Edward Broadbent         // Collections don't include the static data added by SubRoute
10907e860f15SJohn Edward Broadbent         // because it has a duplicate entry for members
1091c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1092c4bf6374SJason M. Bills             "#LogServiceCollection.LogServiceCollection";
1093c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1094029573d4SEd Tanous             "/redfish/v1/Systems/system/LogServices";
109545ca1b86SEd Tanous         asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
1096c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] =
1097c4bf6374SJason M. Bills             "Collection of LogServices for this Computer System";
1098002d39b4SEd Tanous         nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1099c4bf6374SJason M. Bills         logServiceArray = nlohmann::json::array();
11001476687dSEd Tanous         nlohmann::json::object_t eventLog;
11011476687dSEd Tanous         eventLog["@odata.id"] =
11021476687dSEd Tanous             "/redfish/v1/Systems/system/LogServices/EventLog";
11031476687dSEd Tanous         logServiceArray.push_back(std::move(eventLog));
11045cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
11051476687dSEd Tanous         nlohmann::json::object_t dumpLog;
1106002d39b4SEd Tanous         dumpLog["@odata.id"] = "/redfish/v1/Systems/system/LogServices/Dump";
11071476687dSEd Tanous         logServiceArray.push_back(std::move(dumpLog));
1108c9bb6861Sraviteja-b #endif
1109c9bb6861Sraviteja-b 
1110d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
11111476687dSEd Tanous         nlohmann::json::object_t crashdump;
11121476687dSEd Tanous         crashdump["@odata.id"] =
11131476687dSEd Tanous             "/redfish/v1/Systems/system/LogServices/Crashdump";
11141476687dSEd Tanous         logServiceArray.push_back(std::move(crashdump));
1115d53dd41fSJason M. Bills #endif
1116b7028ebfSSpencer Ku 
1117b7028ebfSSpencer Ku #ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER
11181476687dSEd Tanous         nlohmann::json::object_t hostlogger;
11191476687dSEd Tanous         hostlogger["@odata.id"] =
11201476687dSEd Tanous             "/redfish/v1/Systems/system/LogServices/HostLogger";
11211476687dSEd Tanous         logServiceArray.push_back(std::move(hostlogger));
1122b7028ebfSSpencer Ku #endif
1123c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] =
1124c4bf6374SJason M. Bills             logServiceArray.size();
1125a3316fc6SZhikuiRen 
11267a1dbc48SGeorge Liu         constexpr std::array<std::string_view, 1> interfaces = {
11277a1dbc48SGeorge Liu             "xyz.openbmc_project.State.Boot.PostCode"};
11287a1dbc48SGeorge Liu         dbus::utility::getSubTreePaths(
11297a1dbc48SGeorge Liu             "/", 0, interfaces,
11307a1dbc48SGeorge Liu             [asyncResp](const boost::system::error_code& ec,
1131b9d36b47SEd Tanous                         const dbus::utility::MapperGetSubTreePathsResponse&
1132b9d36b47SEd Tanous                             subtreePath) {
1133a3316fc6SZhikuiRen             if (ec)
1134a3316fc6SZhikuiRen             {
1135a3316fc6SZhikuiRen                 BMCWEB_LOG_ERROR << ec;
1136a3316fc6SZhikuiRen                 return;
1137a3316fc6SZhikuiRen             }
1138a3316fc6SZhikuiRen 
113955f79e6fSEd Tanous             for (const auto& pathStr : subtreePath)
1140a3316fc6SZhikuiRen             {
1141a3316fc6SZhikuiRen                 if (pathStr.find("PostCode") != std::string::npos)
1142a3316fc6SZhikuiRen                 {
114323a21a1cSEd Tanous                     nlohmann::json& logServiceArrayLocal =
1144a3316fc6SZhikuiRen                         asyncResp->res.jsonValue["Members"];
1145613dabeaSEd Tanous                     nlohmann::json::object_t member;
1146613dabeaSEd Tanous                     member["@odata.id"] =
1147613dabeaSEd Tanous                         "/redfish/v1/Systems/system/LogServices/PostCodes";
1148613dabeaSEd Tanous 
1149613dabeaSEd Tanous                     logServiceArrayLocal.push_back(std::move(member));
1150613dabeaSEd Tanous 
115145ca1b86SEd Tanous                     asyncResp->res.jsonValue["Members@odata.count"] =
115223a21a1cSEd Tanous                         logServiceArrayLocal.size();
1153a3316fc6SZhikuiRen                     return;
1154a3316fc6SZhikuiRen                 }
1155a3316fc6SZhikuiRen             }
11567a1dbc48SGeorge Liu             });
11577e860f15SJohn Edward Broadbent         });
1158c4bf6374SJason M. Bills }
1159c4bf6374SJason M. Bills 
11607e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app)
1161c4bf6374SJason M. Bills {
116222d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/")
1163ed398213SEd Tanous         .privileges(redfish::privileges::getLogService)
1164002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1165002d39b4SEd Tanous             [&app](const crow::Request& req,
116622d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
116722d268cbSEd Tanous                    const std::string& systemName) {
11683ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
116945ca1b86SEd Tanous         {
117045ca1b86SEd Tanous             return;
117145ca1b86SEd Tanous         }
117222d268cbSEd Tanous         if (systemName != "system")
117322d268cbSEd Tanous         {
117422d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
117522d268cbSEd Tanous                                        systemName);
117622d268cbSEd Tanous             return;
117722d268cbSEd Tanous         }
1178c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1179029573d4SEd Tanous             "/redfish/v1/Systems/system/LogServices/EventLog";
1180c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1181c4bf6374SJason M. Bills             "#LogService.v1_1_0.LogService";
1182c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Event Log Service";
1183002d39b4SEd Tanous         asyncResp->res.jsonValue["Description"] = "System Event Log Service";
1184c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Id"] = "EventLog";
1185c4bf6374SJason M. Bills         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
11867c8c4058STejas Patil 
11877c8c4058STejas Patil         std::pair<std::string, std::string> redfishDateTimeOffset =
11882b82937eSEd Tanous             redfish::time_utils::getDateTimeOffsetNow();
11897c8c4058STejas Patil 
11907c8c4058STejas Patil         asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
11917c8c4058STejas Patil         asyncResp->res.jsonValue["DateTimeLocalOffset"] =
11927c8c4058STejas Patil             redfishDateTimeOffset.second;
11937c8c4058STejas Patil 
11941476687dSEd Tanous         asyncResp->res.jsonValue["Entries"]["@odata.id"] =
11951476687dSEd Tanous             "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
1196e7d6c8b2SGunnar Mills         asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
1197e7d6c8b2SGunnar Mills 
11980fda0f12SGeorge Liu             {"target",
11990fda0f12SGeorge Liu              "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog"}};
12007e860f15SJohn Edward Broadbent         });
1201489640c6SJason M. Bills }
1202489640c6SJason M. Bills 
12037e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app)
1204489640c6SJason M. Bills {
12054978b63fSJason M. Bills     BMCWEB_ROUTE(
12064978b63fSJason M. Bills         app,
120722d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
1208432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
12097e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
121045ca1b86SEd Tanous             [&app](const crow::Request& req,
121122d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
121222d268cbSEd Tanous                    const std::string& systemName) {
12133ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
121445ca1b86SEd Tanous         {
121545ca1b86SEd Tanous             return;
121645ca1b86SEd Tanous         }
121722d268cbSEd Tanous         if (systemName != "system")
121822d268cbSEd Tanous         {
121922d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
122022d268cbSEd Tanous                                        systemName);
122122d268cbSEd Tanous             return;
122222d268cbSEd Tanous         }
1223489640c6SJason M. Bills         // Clear the EventLog by deleting the log files
1224489640c6SJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
1225489640c6SJason M. Bills         if (getRedfishLogFiles(redfishLogFiles))
1226489640c6SJason M. Bills         {
1227489640c6SJason M. Bills             for (const std::filesystem::path& file : redfishLogFiles)
1228489640c6SJason M. Bills             {
1229489640c6SJason M. Bills                 std::error_code ec;
1230489640c6SJason M. Bills                 std::filesystem::remove(file, ec);
1231489640c6SJason M. Bills             }
1232489640c6SJason M. Bills         }
1233489640c6SJason M. Bills 
1234489640c6SJason M. Bills         // Reload rsyslog so it knows to start new log files
1235489640c6SJason M. Bills         crow::connections::systemBus->async_method_call(
12365e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec) {
1237489640c6SJason M. Bills             if (ec)
1238489640c6SJason M. Bills             {
1239002d39b4SEd Tanous                 BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec;
1240489640c6SJason M. Bills                 messages::internalError(asyncResp->res);
1241489640c6SJason M. Bills                 return;
1242489640c6SJason M. Bills             }
1243489640c6SJason M. Bills 
1244489640c6SJason M. Bills             messages::success(asyncResp->res);
1245489640c6SJason M. Bills             },
1246489640c6SJason M. Bills             "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1247002d39b4SEd Tanous             "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1248002d39b4SEd Tanous             "replace");
12497e860f15SJohn Edward Broadbent         });
1250c4bf6374SJason M. Bills }
1251c4bf6374SJason M. Bills 
1252ac992cdeSJason M. Bills enum class LogParseError
1253ac992cdeSJason M. Bills {
1254ac992cdeSJason M. Bills     success,
1255ac992cdeSJason M. Bills     parseFailed,
1256ac992cdeSJason M. Bills     messageIdNotInRegistry,
1257ac992cdeSJason M. Bills };
1258ac992cdeSJason M. Bills 
1259ac992cdeSJason M. Bills static LogParseError
1260ac992cdeSJason M. Bills     fillEventLogEntryJson(const std::string& logEntryID,
1261b5a76932SEd Tanous                           const std::string& logEntry,
1262de703c5dSJason M. Bills                           nlohmann::json::object_t& logEntryJson)
1263c4bf6374SJason M. Bills {
126495820184SJason M. Bills     // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
1265cd225da8SJason M. Bills     // First get the Timestamp
1266f23b7296SEd Tanous     size_t space = logEntry.find_first_of(' ');
1267cd225da8SJason M. Bills     if (space == std::string::npos)
126895820184SJason M. Bills     {
1269ac992cdeSJason M. Bills         return LogParseError::parseFailed;
127095820184SJason M. Bills     }
1271cd225da8SJason M. Bills     std::string timestamp = logEntry.substr(0, space);
1272cd225da8SJason M. Bills     // Then get the log contents
1273f23b7296SEd Tanous     size_t entryStart = logEntry.find_first_not_of(' ', space);
1274cd225da8SJason M. Bills     if (entryStart == std::string::npos)
1275cd225da8SJason M. Bills     {
1276ac992cdeSJason M. Bills         return LogParseError::parseFailed;
1277cd225da8SJason M. Bills     }
1278cd225da8SJason M. Bills     std::string_view entry(logEntry);
1279cd225da8SJason M. Bills     entry.remove_prefix(entryStart);
1280cd225da8SJason M. Bills     // Use split to separate the entry into its fields
1281cd225da8SJason M. Bills     std::vector<std::string> logEntryFields;
128250ebd4afSEd Tanous     bmcweb::split(logEntryFields, entry, ',');
1283cd225da8SJason M. Bills     // We need at least a MessageId to be valid
128426f6976fSEd Tanous     if (logEntryFields.empty())
1285cd225da8SJason M. Bills     {
1286ac992cdeSJason M. Bills         return LogParseError::parseFailed;
1287cd225da8SJason M. Bills     }
1288cd225da8SJason M. Bills     std::string& messageID = logEntryFields[0];
128995820184SJason M. Bills 
12904851d45dSJason M. Bills     // Get the Message from the MessageRegistry
1291fffb8c1fSEd Tanous     const registries::Message* message = registries::getMessage(messageID);
1292c4bf6374SJason M. Bills 
129354417b02SSui Chen     if (message == nullptr)
1294c4bf6374SJason M. Bills     {
129554417b02SSui Chen         BMCWEB_LOG_WARNING << "Log entry not found in registry: " << logEntry;
1296ac992cdeSJason M. Bills         return LogParseError::messageIdNotInRegistry;
1297c4bf6374SJason M. Bills     }
1298c4bf6374SJason M. Bills 
129954417b02SSui Chen     std::string msg = message->message;
130054417b02SSui Chen 
130115a86ff6SJason M. Bills     // Get the MessageArgs from the log if there are any
130226702d01SEd Tanous     std::span<std::string> messageArgs;
130315a86ff6SJason M. Bills     if (logEntryFields.size() > 1)
130415a86ff6SJason M. Bills     {
130515a86ff6SJason M. Bills         std::string& messageArgsStart = logEntryFields[1];
130615a86ff6SJason M. Bills         // If the first string is empty, assume there are no MessageArgs
130715a86ff6SJason M. Bills         std::size_t messageArgsSize = 0;
130815a86ff6SJason M. Bills         if (!messageArgsStart.empty())
130915a86ff6SJason M. Bills         {
131015a86ff6SJason M. Bills             messageArgsSize = logEntryFields.size() - 1;
131115a86ff6SJason M. Bills         }
131215a86ff6SJason M. Bills 
131323a21a1cSEd Tanous         messageArgs = {&messageArgsStart, messageArgsSize};
1314c4bf6374SJason M. Bills 
13154851d45dSJason M. Bills         // Fill the MessageArgs into the Message
131695820184SJason M. Bills         int i = 0;
131795820184SJason M. Bills         for (const std::string& messageArg : messageArgs)
13184851d45dSJason M. Bills         {
131995820184SJason M. Bills             std::string argStr = "%" + std::to_string(++i);
13204851d45dSJason M. Bills             size_t argPos = msg.find(argStr);
13214851d45dSJason M. Bills             if (argPos != std::string::npos)
13224851d45dSJason M. Bills             {
132395820184SJason M. Bills                 msg.replace(argPos, argStr.length(), messageArg);
13244851d45dSJason M. Bills             }
13254851d45dSJason M. Bills         }
132615a86ff6SJason M. Bills     }
13274851d45dSJason M. Bills 
132895820184SJason M. Bills     // Get the Created time from the timestamp. The log timestamp is in RFC3339
132995820184SJason M. Bills     // format which matches the Redfish format except for the fractional seconds
133095820184SJason M. Bills     // between the '.' and the '+', so just remove them.
1331f23b7296SEd Tanous     std::size_t dot = timestamp.find_first_of('.');
1332f23b7296SEd Tanous     std::size_t plus = timestamp.find_first_of('+');
133395820184SJason M. Bills     if (dot != std::string::npos && plus != std::string::npos)
1334c4bf6374SJason M. Bills     {
133595820184SJason M. Bills         timestamp.erase(dot, plus - dot);
1336c4bf6374SJason M. Bills     }
1337c4bf6374SJason M. Bills 
1338c4bf6374SJason M. Bills     // Fill in the log entry with the gathered data
13399c11a172SVijay Lobo     logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1340eddfc437SWilly Tu     logEntryJson["@odata.id"] = crow::utility::urlFromPieces(
1341eddfc437SWilly Tu         "redfish", "v1", "Systems", "system", "LogServices", "EventLog",
1342eddfc437SWilly Tu         "Entries", logEntryID);
134384afc48bSJason M. Bills     logEntryJson["Name"] = "System Event Log Entry";
134484afc48bSJason M. Bills     logEntryJson["Id"] = logEntryID;
134584afc48bSJason M. Bills     logEntryJson["Message"] = std::move(msg);
134684afc48bSJason M. Bills     logEntryJson["MessageId"] = std::move(messageID);
134784afc48bSJason M. Bills     logEntryJson["MessageArgs"] = messageArgs;
134884afc48bSJason M. Bills     logEntryJson["EntryType"] = "Event";
134984afc48bSJason M. Bills     logEntryJson["Severity"] = message->messageSeverity;
135084afc48bSJason M. Bills     logEntryJson["Created"] = std::move(timestamp);
1351ac992cdeSJason M. Bills     return LogParseError::success;
1352c4bf6374SJason M. Bills }
1353c4bf6374SJason M. Bills 
13547e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app)
1355c4bf6374SJason M. Bills {
135622d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
13578b6a35f0SGunnar Mills         .privileges(redfish::privileges::getLogEntryCollection)
1358002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1359002d39b4SEd Tanous             [&app](const crow::Request& req,
136022d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
136122d268cbSEd Tanous                    const std::string& systemName) {
1362c937d2bfSEd Tanous         query_param::QueryCapabilities capabilities = {
1363c937d2bfSEd Tanous             .canDelegateTop = true,
1364c937d2bfSEd Tanous             .canDelegateSkip = true,
1365c937d2bfSEd Tanous         };
1366c937d2bfSEd Tanous         query_param::Query delegatedQuery;
1367c937d2bfSEd Tanous         if (!redfish::setUpRedfishRouteWithDelegation(
13683ba00073SCarson Labrado                 app, req, asyncResp, delegatedQuery, capabilities))
1369c4bf6374SJason M. Bills         {
1370c4bf6374SJason M. Bills             return;
1371c4bf6374SJason M. Bills         }
137222d268cbSEd Tanous         if (systemName != "system")
137322d268cbSEd Tanous         {
137422d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
137522d268cbSEd Tanous                                        systemName);
137622d268cbSEd Tanous             return;
137722d268cbSEd Tanous         }
137822d268cbSEd Tanous 
13795143f7a5SJiaqing Zhao         size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
13803648c8beSEd Tanous         size_t skip = delegatedQuery.skip.value_or(0);
13813648c8beSEd Tanous 
13827e860f15SJohn Edward Broadbent         // Collections don't include the static data added by SubRoute
13837e860f15SJohn Edward Broadbent         // because it has a duplicate entry for members
1384c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1385c4bf6374SJason M. Bills             "#LogEntryCollection.LogEntryCollection";
1386c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1387029573d4SEd Tanous             "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
1388c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1389c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] =
1390c4bf6374SJason M. Bills             "Collection of System Event Log Entries";
1391cb92c03bSAndrew Geissler 
13924978b63fSJason M. Bills         nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1393c4bf6374SJason M. Bills         logEntryArray = nlohmann::json::array();
13947e860f15SJohn Edward Broadbent         // Go through the log files and create a unique ID for each
13957e860f15SJohn Edward Broadbent         // entry
139695820184SJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
139795820184SJason M. Bills         getRedfishLogFiles(redfishLogFiles);
1398b01bf299SEd Tanous         uint64_t entryCount = 0;
1399cd225da8SJason M. Bills         std::string logEntry;
140095820184SJason M. Bills 
14017e860f15SJohn Edward Broadbent         // Oldest logs are in the last file, so start there and loop
14027e860f15SJohn Edward Broadbent         // backwards
1403002d39b4SEd Tanous         for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1404002d39b4SEd Tanous              it++)
1405c4bf6374SJason M. Bills         {
1406cd225da8SJason M. Bills             std::ifstream logStream(*it);
140795820184SJason M. Bills             if (!logStream.is_open())
1408c4bf6374SJason M. Bills             {
1409c4bf6374SJason M. Bills                 continue;
1410c4bf6374SJason M. Bills             }
1411c4bf6374SJason M. Bills 
1412e85d6b16SJason M. Bills             // Reset the unique ID on the first entry
1413e85d6b16SJason M. Bills             bool firstEntry = true;
141495820184SJason M. Bills             while (std::getline(logStream, logEntry))
141595820184SJason M. Bills             {
1416c4bf6374SJason M. Bills                 std::string idStr;
1417e85d6b16SJason M. Bills                 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1418c4bf6374SJason M. Bills                 {
1419c4bf6374SJason M. Bills                     continue;
1420c4bf6374SJason M. Bills                 }
1421e85d6b16SJason M. Bills                 firstEntry = false;
1422e85d6b16SJason M. Bills 
1423de703c5dSJason M. Bills                 nlohmann::json::object_t bmcLogEntry;
1424ac992cdeSJason M. Bills                 LogParseError status =
1425ac992cdeSJason M. Bills                     fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
1426ac992cdeSJason M. Bills                 if (status == LogParseError::messageIdNotInRegistry)
1427ac992cdeSJason M. Bills                 {
1428ac992cdeSJason M. Bills                     continue;
1429ac992cdeSJason M. Bills                 }
1430ac992cdeSJason M. Bills                 if (status != LogParseError::success)
1431c4bf6374SJason M. Bills                 {
1432c4bf6374SJason M. Bills                     messages::internalError(asyncResp->res);
1433c4bf6374SJason M. Bills                     return;
1434c4bf6374SJason M. Bills                 }
1435de703c5dSJason M. Bills 
1436de703c5dSJason M. Bills                 entryCount++;
1437de703c5dSJason M. Bills                 // Handle paging using skip (number of entries to skip from the
1438de703c5dSJason M. Bills                 // start) and top (number of entries to display)
14393648c8beSEd Tanous                 if (entryCount <= skip || entryCount > skip + top)
1440de703c5dSJason M. Bills                 {
1441de703c5dSJason M. Bills                     continue;
1442de703c5dSJason M. Bills                 }
1443de703c5dSJason M. Bills 
1444de703c5dSJason M. Bills                 logEntryArray.push_back(std::move(bmcLogEntry));
1445c4bf6374SJason M. Bills             }
144695820184SJason M. Bills         }
1447c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
14483648c8beSEd Tanous         if (skip + top < entryCount)
1449c4bf6374SJason M. Bills         {
1450c4bf6374SJason M. Bills             asyncResp->res.jsonValue["Members@odata.nextLink"] =
14514978b63fSJason M. Bills                 "/redfish/v1/Systems/system/LogServices/EventLog/Entries?$skip=" +
14523648c8beSEd Tanous                 std::to_string(skip + top);
1453c4bf6374SJason M. Bills         }
14547e860f15SJohn Edward Broadbent         });
1455897967deSJason M. Bills }
1456897967deSJason M. Bills 
14577e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app)
1458897967deSJason M. Bills {
14597e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
146022d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1461ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
14627e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
146345ca1b86SEd Tanous             [&app](const crow::Request& req,
14647e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
146522d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
14663ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
146745ca1b86SEd Tanous         {
146845ca1b86SEd Tanous             return;
146945ca1b86SEd Tanous         }
147022d268cbSEd Tanous 
147122d268cbSEd Tanous         if (systemName != "system")
147222d268cbSEd Tanous         {
147322d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
147422d268cbSEd Tanous                                        systemName);
147522d268cbSEd Tanous             return;
147622d268cbSEd Tanous         }
147722d268cbSEd Tanous 
14787e860f15SJohn Edward Broadbent         const std::string& targetID = param;
14798d1b46d7Szhanghch05 
14807e860f15SJohn Edward Broadbent         // Go through the log files and check the unique ID for each
14817e860f15SJohn Edward Broadbent         // entry to find the target entry
1482897967deSJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
1483897967deSJason M. Bills         getRedfishLogFiles(redfishLogFiles);
1484897967deSJason M. Bills         std::string logEntry;
1485897967deSJason M. Bills 
14867e860f15SJohn Edward Broadbent         // Oldest logs are in the last file, so start there and loop
14877e860f15SJohn Edward Broadbent         // backwards
1488002d39b4SEd Tanous         for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1489002d39b4SEd Tanous              it++)
1490897967deSJason M. Bills         {
1491897967deSJason M. Bills             std::ifstream logStream(*it);
1492897967deSJason M. Bills             if (!logStream.is_open())
1493897967deSJason M. Bills             {
1494897967deSJason M. Bills                 continue;
1495897967deSJason M. Bills             }
1496897967deSJason M. Bills 
1497897967deSJason M. Bills             // Reset the unique ID on the first entry
1498897967deSJason M. Bills             bool firstEntry = true;
1499897967deSJason M. Bills             while (std::getline(logStream, logEntry))
1500897967deSJason M. Bills             {
1501897967deSJason M. Bills                 std::string idStr;
1502897967deSJason M. Bills                 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1503897967deSJason M. Bills                 {
1504897967deSJason M. Bills                     continue;
1505897967deSJason M. Bills                 }
1506897967deSJason M. Bills                 firstEntry = false;
1507897967deSJason M. Bills 
1508897967deSJason M. Bills                 if (idStr == targetID)
1509897967deSJason M. Bills                 {
1510de703c5dSJason M. Bills                     nlohmann::json::object_t bmcLogEntry;
1511ac992cdeSJason M. Bills                     LogParseError status =
1512ac992cdeSJason M. Bills                         fillEventLogEntryJson(idStr, logEntry, bmcLogEntry);
1513ac992cdeSJason M. Bills                     if (status != LogParseError::success)
1514897967deSJason M. Bills                     {
1515897967deSJason M. Bills                         messages::internalError(asyncResp->res);
1516897967deSJason M. Bills                         return;
1517897967deSJason M. Bills                     }
1518d405bb51SJason M. Bills                     asyncResp->res.jsonValue.update(bmcLogEntry);
1519897967deSJason M. Bills                     return;
1520897967deSJason M. Bills                 }
1521897967deSJason M. Bills             }
1522897967deSJason M. Bills         }
1523897967deSJason M. Bills         // Requested ID was not found
15249db4ba25SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "LogEntry", targetID);
15257e860f15SJohn Edward Broadbent         });
152608a4e4b5SAnthony Wilson }
152708a4e4b5SAnthony Wilson 
15287e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app)
152908a4e4b5SAnthony Wilson {
153022d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/")
1531ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntryCollection)
1532002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1533002d39b4SEd Tanous             [&app](const crow::Request& req,
153422d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
153522d268cbSEd Tanous                    const std::string& systemName) {
15363ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
153745ca1b86SEd Tanous         {
153845ca1b86SEd Tanous             return;
153945ca1b86SEd Tanous         }
154022d268cbSEd Tanous         if (systemName != "system")
154122d268cbSEd Tanous         {
154222d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
154322d268cbSEd Tanous                                        systemName);
154422d268cbSEd Tanous             return;
154522d268cbSEd Tanous         }
154622d268cbSEd Tanous 
15477e860f15SJohn Edward Broadbent         // Collections don't include the static data added by SubRoute
15487e860f15SJohn Edward Broadbent         // because it has a duplicate entry for members
154908a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["@odata.type"] =
155008a4e4b5SAnthony Wilson             "#LogEntryCollection.LogEntryCollection";
155108a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["@odata.id"] =
155208a4e4b5SAnthony Wilson             "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
155308a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
155408a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["Description"] =
155508a4e4b5SAnthony Wilson             "Collection of System Event Log Entries";
155608a4e4b5SAnthony Wilson 
1557cb92c03bSAndrew Geissler         // DBus implementation of EventLog/Entries
1558cb92c03bSAndrew Geissler         // Make call to Logging Service to find all log entry objects
1559cb92c03bSAndrew Geissler         crow::connections::systemBus->async_method_call(
15605e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec,
1561914e2d5dSEd Tanous                         const dbus::utility::ManagedObjectType& resp) {
1562cb92c03bSAndrew Geissler             if (ec)
1563cb92c03bSAndrew Geissler             {
1564cb92c03bSAndrew Geissler                 // TODO Handle for specific error code
1565cb92c03bSAndrew Geissler                 BMCWEB_LOG_ERROR
1566002d39b4SEd Tanous                     << "getLogEntriesIfaceData resp_handler got error " << ec;
1567cb92c03bSAndrew Geissler                 messages::internalError(asyncResp->res);
1568cb92c03bSAndrew Geissler                 return;
1569cb92c03bSAndrew Geissler             }
1570002d39b4SEd Tanous             nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
1571cb92c03bSAndrew Geissler             entriesArray = nlohmann::json::array();
15729eb808c1SEd Tanous             for (const auto& objectPath : resp)
1573cb92c03bSAndrew Geissler             {
1574914e2d5dSEd Tanous                 const uint32_t* id = nullptr;
1575c419c759SEd Tanous                 const uint64_t* timestamp = nullptr;
1576c419c759SEd Tanous                 const uint64_t* updateTimestamp = nullptr;
1577914e2d5dSEd Tanous                 const std::string* severity = nullptr;
1578914e2d5dSEd Tanous                 const std::string* message = nullptr;
1579914e2d5dSEd Tanous                 const std::string* filePath = nullptr;
15809c11a172SVijay Lobo                 const std::string* resolution = nullptr;
158175710de2SXiaochao Ma                 bool resolved = false;
15829017faf2SAbhishek Patel                 const std::string* notify = nullptr;
15839017faf2SAbhishek Patel 
15849eb808c1SEd Tanous                 for (const auto& interfaceMap : objectPath.second)
1585f86bb901SAdriana Kobylak                 {
1586f86bb901SAdriana Kobylak                     if (interfaceMap.first ==
1587f86bb901SAdriana Kobylak                         "xyz.openbmc_project.Logging.Entry")
1588f86bb901SAdriana Kobylak                     {
1589002d39b4SEd Tanous                         for (const auto& propertyMap : interfaceMap.second)
1590cb92c03bSAndrew Geissler                         {
1591cb92c03bSAndrew Geissler                             if (propertyMap.first == "Id")
1592cb92c03bSAndrew Geissler                             {
1593002d39b4SEd Tanous                                 id = std::get_if<uint32_t>(&propertyMap.second);
1594cb92c03bSAndrew Geissler                             }
1595cb92c03bSAndrew Geissler                             else if (propertyMap.first == "Timestamp")
1596cb92c03bSAndrew Geissler                             {
1597002d39b4SEd Tanous                                 timestamp =
1598002d39b4SEd Tanous                                     std::get_if<uint64_t>(&propertyMap.second);
15997e860f15SJohn Edward Broadbent                             }
1600002d39b4SEd Tanous                             else if (propertyMap.first == "UpdateTimestamp")
16017e860f15SJohn Edward Broadbent                             {
1602002d39b4SEd Tanous                                 updateTimestamp =
1603002d39b4SEd Tanous                                     std::get_if<uint64_t>(&propertyMap.second);
16047e860f15SJohn Edward Broadbent                             }
16057e860f15SJohn Edward Broadbent                             else if (propertyMap.first == "Severity")
16067e860f15SJohn Edward Broadbent                             {
16077e860f15SJohn Edward Broadbent                                 severity = std::get_if<std::string>(
16087e860f15SJohn Edward Broadbent                                     &propertyMap.second);
16097e860f15SJohn Edward Broadbent                             }
16109c11a172SVijay Lobo                             else if (propertyMap.first == "Resolution")
16119c11a172SVijay Lobo                             {
16129c11a172SVijay Lobo                                 resolution = std::get_if<std::string>(
16139c11a172SVijay Lobo                                     &propertyMap.second);
16149c11a172SVijay Lobo                             }
16157e860f15SJohn Edward Broadbent                             else if (propertyMap.first == "Message")
16167e860f15SJohn Edward Broadbent                             {
16177e860f15SJohn Edward Broadbent                                 message = std::get_if<std::string>(
16187e860f15SJohn Edward Broadbent                                     &propertyMap.second);
16197e860f15SJohn Edward Broadbent                             }
16207e860f15SJohn Edward Broadbent                             else if (propertyMap.first == "Resolved")
16217e860f15SJohn Edward Broadbent                             {
1622914e2d5dSEd Tanous                                 const bool* resolveptr =
1623002d39b4SEd Tanous                                     std::get_if<bool>(&propertyMap.second);
16247e860f15SJohn Edward Broadbent                                 if (resolveptr == nullptr)
16257e860f15SJohn Edward Broadbent                                 {
1626002d39b4SEd Tanous                                     messages::internalError(asyncResp->res);
16277e860f15SJohn Edward Broadbent                                     return;
16287e860f15SJohn Edward Broadbent                                 }
16297e860f15SJohn Edward Broadbent                                 resolved = *resolveptr;
16307e860f15SJohn Edward Broadbent                             }
16319017faf2SAbhishek Patel                             else if (propertyMap.first ==
16329017faf2SAbhishek Patel                                      "ServiceProviderNotify")
16339017faf2SAbhishek Patel                             {
16349017faf2SAbhishek Patel                                 notify = std::get_if<std::string>(
16359017faf2SAbhishek Patel                                     &propertyMap.second);
16369017faf2SAbhishek Patel                                 if (notify == nullptr)
16379017faf2SAbhishek Patel                                 {
16389017faf2SAbhishek Patel                                     messages::internalError(asyncResp->res);
16399017faf2SAbhishek Patel                                     return;
16409017faf2SAbhishek Patel                                 }
16419017faf2SAbhishek Patel                             }
16427e860f15SJohn Edward Broadbent                         }
16437e860f15SJohn Edward Broadbent                         if (id == nullptr || message == nullptr ||
16447e860f15SJohn Edward Broadbent                             severity == nullptr)
16457e860f15SJohn Edward Broadbent                         {
16467e860f15SJohn Edward Broadbent                             messages::internalError(asyncResp->res);
16477e860f15SJohn Edward Broadbent                             return;
16487e860f15SJohn Edward Broadbent                         }
16497e860f15SJohn Edward Broadbent                     }
16507e860f15SJohn Edward Broadbent                     else if (interfaceMap.first ==
16517e860f15SJohn Edward Broadbent                              "xyz.openbmc_project.Common.FilePath")
16527e860f15SJohn Edward Broadbent                     {
1653002d39b4SEd Tanous                         for (const auto& propertyMap : interfaceMap.second)
16547e860f15SJohn Edward Broadbent                         {
16557e860f15SJohn Edward Broadbent                             if (propertyMap.first == "Path")
16567e860f15SJohn Edward Broadbent                             {
16577e860f15SJohn Edward Broadbent                                 filePath = std::get_if<std::string>(
16587e860f15SJohn Edward Broadbent                                     &propertyMap.second);
16597e860f15SJohn Edward Broadbent                             }
16607e860f15SJohn Edward Broadbent                         }
16617e860f15SJohn Edward Broadbent                     }
16627e860f15SJohn Edward Broadbent                 }
16637e860f15SJohn Edward Broadbent                 // Object path without the
16647e860f15SJohn Edward Broadbent                 // xyz.openbmc_project.Logging.Entry interface, ignore
16657e860f15SJohn Edward Broadbent                 // and continue.
16667e860f15SJohn Edward Broadbent                 if (id == nullptr || message == nullptr ||
1667c419c759SEd Tanous                     severity == nullptr || timestamp == nullptr ||
1668c419c759SEd Tanous                     updateTimestamp == nullptr)
16697e860f15SJohn Edward Broadbent                 {
16707e860f15SJohn Edward Broadbent                     continue;
16717e860f15SJohn Edward Broadbent                 }
16727e860f15SJohn Edward Broadbent                 entriesArray.push_back({});
16737e860f15SJohn Edward Broadbent                 nlohmann::json& thisEntry = entriesArray.back();
16749c11a172SVijay Lobo                 thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
1675eddfc437SWilly Tu                 thisEntry["@odata.id"] = crow::utility::urlFromPieces(
1676eddfc437SWilly Tu                     "redfish", "v1", "Systems", "system", "LogServices",
1677eddfc437SWilly Tu                     "EventLog", "Entries", std::to_string(*id));
16787e860f15SJohn Edward Broadbent                 thisEntry["Name"] = "System Event Log Entry";
16797e860f15SJohn Edward Broadbent                 thisEntry["Id"] = std::to_string(*id);
16807e860f15SJohn Edward Broadbent                 thisEntry["Message"] = *message;
16817e860f15SJohn Edward Broadbent                 thisEntry["Resolved"] = resolved;
16829c11a172SVijay Lobo                 if ((resolution != nullptr) && (!(*resolution).empty()))
16839c11a172SVijay Lobo                 {
16849c11a172SVijay Lobo                     thisEntry["Resolution"] = *resolution;
16859c11a172SVijay Lobo                 }
16869017faf2SAbhishek Patel                 std::optional<bool> notifyAction =
16879017faf2SAbhishek Patel                     getProviderNotifyAction(*notify);
16889017faf2SAbhishek Patel                 if (notifyAction)
16899017faf2SAbhishek Patel                 {
16909017faf2SAbhishek Patel                     thisEntry["ServiceProviderNotified"] = *notifyAction;
16919017faf2SAbhishek Patel                 }
16927e860f15SJohn Edward Broadbent                 thisEntry["EntryType"] = "Event";
16937e860f15SJohn Edward Broadbent                 thisEntry["Severity"] =
16947e860f15SJohn Edward Broadbent                     translateSeverityDbusToRedfish(*severity);
16957e860f15SJohn Edward Broadbent                 thisEntry["Created"] =
16962b82937eSEd Tanous                     redfish::time_utils::getDateTimeUintMs(*timestamp);
16977e860f15SJohn Edward Broadbent                 thisEntry["Modified"] =
16982b82937eSEd Tanous                     redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
16997e860f15SJohn Edward Broadbent                 if (filePath != nullptr)
17007e860f15SJohn Edward Broadbent                 {
17017e860f15SJohn Edward Broadbent                     thisEntry["AdditionalDataURI"] =
17020fda0f12SGeorge Liu                         "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
17037e860f15SJohn Edward Broadbent                         std::to_string(*id) + "/attachment";
17047e860f15SJohn Edward Broadbent                 }
17057e860f15SJohn Edward Broadbent             }
1706002d39b4SEd Tanous             std::sort(
1707002d39b4SEd Tanous                 entriesArray.begin(), entriesArray.end(),
1708002d39b4SEd Tanous                 [](const nlohmann::json& left, const nlohmann::json& right) {
17097e860f15SJohn Edward Broadbent                 return (left["Id"] <= right["Id"]);
17107e860f15SJohn Edward Broadbent                 });
17117e860f15SJohn Edward Broadbent             asyncResp->res.jsonValue["Members@odata.count"] =
17127e860f15SJohn Edward Broadbent                 entriesArray.size();
17137e860f15SJohn Edward Broadbent             },
17147e860f15SJohn Edward Broadbent             "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
17157e860f15SJohn Edward Broadbent             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
17167e860f15SJohn Edward Broadbent         });
17177e860f15SJohn Edward Broadbent }
17187e860f15SJohn Edward Broadbent 
17197e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app)
17207e860f15SJohn Edward Broadbent {
17217e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
172222d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1723ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
1724002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1725002d39b4SEd Tanous             [&app](const crow::Request& req,
17267e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
172722d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
17283ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
17297e860f15SJohn Edward Broadbent         {
173045ca1b86SEd Tanous             return;
173145ca1b86SEd Tanous         }
173222d268cbSEd Tanous         if (systemName != "system")
173322d268cbSEd Tanous         {
173422d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
173522d268cbSEd Tanous                                        systemName);
173622d268cbSEd Tanous             return;
173722d268cbSEd Tanous         }
173822d268cbSEd Tanous 
17397e860f15SJohn Edward Broadbent         std::string entryID = param;
17407e860f15SJohn Edward Broadbent         dbus::utility::escapePathForDbus(entryID);
17417e860f15SJohn Edward Broadbent 
17427e860f15SJohn Edward Broadbent         // DBus implementation of EventLog/Entries
17437e860f15SJohn Edward Broadbent         // Make call to Logging Service to find all log entry objects
1744d1bde9e5SKrzysztof Grobelny         sdbusplus::asio::getAllProperties(
1745d1bde9e5SKrzysztof Grobelny             *crow::connections::systemBus, "xyz.openbmc_project.Logging",
1746d1bde9e5SKrzysztof Grobelny             "/xyz/openbmc_project/logging/entry/" + entryID, "",
17475e7e2dc5SEd Tanous             [asyncResp, entryID](const boost::system::error_code& ec,
1748b9d36b47SEd Tanous                                  const dbus::utility::DBusPropertiesMap& resp) {
17497e860f15SJohn Edward Broadbent             if (ec.value() == EBADR)
17507e860f15SJohn Edward Broadbent             {
1751d1bde9e5SKrzysztof Grobelny                 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1752d1bde9e5SKrzysztof Grobelny                                            entryID);
17537e860f15SJohn Edward Broadbent                 return;
17547e860f15SJohn Edward Broadbent             }
17557e860f15SJohn Edward Broadbent             if (ec)
17567e860f15SJohn Edward Broadbent             {
17570fda0f12SGeorge Liu                 BMCWEB_LOG_ERROR
1758002d39b4SEd Tanous                     << "EventLogEntry (DBus) resp_handler got error " << ec;
17597e860f15SJohn Edward Broadbent                 messages::internalError(asyncResp->res);
17607e860f15SJohn Edward Broadbent                 return;
17617e860f15SJohn Edward Broadbent             }
1762914e2d5dSEd Tanous             const uint32_t* id = nullptr;
1763c419c759SEd Tanous             const uint64_t* timestamp = nullptr;
1764c419c759SEd Tanous             const uint64_t* updateTimestamp = nullptr;
1765914e2d5dSEd Tanous             const std::string* severity = nullptr;
1766914e2d5dSEd Tanous             const std::string* message = nullptr;
1767914e2d5dSEd Tanous             const std::string* filePath = nullptr;
17689c11a172SVijay Lobo             const std::string* resolution = nullptr;
17697e860f15SJohn Edward Broadbent             bool resolved = false;
17709017faf2SAbhishek Patel             const std::string* notify = nullptr;
17717e860f15SJohn Edward Broadbent 
1772d1bde9e5SKrzysztof Grobelny             const bool success = sdbusplus::unpackPropertiesNoThrow(
1773d1bde9e5SKrzysztof Grobelny                 dbus_utils::UnpackErrorPrinter(), resp, "Id", id, "Timestamp",
1774d1bde9e5SKrzysztof Grobelny                 timestamp, "UpdateTimestamp", updateTimestamp, "Severity",
17759c11a172SVijay Lobo                 severity, "Message", message, "Resolved", resolved,
17769017faf2SAbhishek Patel                 "Resolution", resolution, "Path", filePath,
17779017faf2SAbhishek Patel                 "ServiceProviderNotify", notify);
1778d1bde9e5SKrzysztof Grobelny 
1779d1bde9e5SKrzysztof Grobelny             if (!success)
178075710de2SXiaochao Ma             {
178175710de2SXiaochao Ma                 messages::internalError(asyncResp->res);
178275710de2SXiaochao Ma                 return;
178375710de2SXiaochao Ma             }
1784d1bde9e5SKrzysztof Grobelny 
1785002d39b4SEd Tanous             if (id == nullptr || message == nullptr || severity == nullptr ||
17869017faf2SAbhishek Patel                 timestamp == nullptr || updateTimestamp == nullptr ||
17879017faf2SAbhishek Patel                 notify == nullptr)
1788f86bb901SAdriana Kobylak             {
1789ae34c8e8SAdriana Kobylak                 messages::internalError(asyncResp->res);
1790271584abSEd Tanous                 return;
1791271584abSEd Tanous             }
17929017faf2SAbhishek Patel 
1793f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["@odata.type"] =
17949c11a172SVijay Lobo                 "#LogEntry.v1_9_0.LogEntry";
1795f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["@odata.id"] =
1796eddfc437SWilly Tu                 crow::utility::urlFromPieces(
1797eddfc437SWilly Tu                     "redfish", "v1", "Systems", "system", "LogServices",
1798eddfc437SWilly Tu                     "EventLog", "Entries", std::to_string(*id));
179945ca1b86SEd Tanous             asyncResp->res.jsonValue["Name"] = "System Event Log Entry";
1800f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Id"] = std::to_string(*id);
1801f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Message"] = *message;
1802f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Resolved"] = resolved;
18039017faf2SAbhishek Patel             std::optional<bool> notifyAction = getProviderNotifyAction(*notify);
18049017faf2SAbhishek Patel             if (notifyAction)
18059017faf2SAbhishek Patel             {
18069017faf2SAbhishek Patel                 asyncResp->res.jsonValue["ServiceProviderNotified"] =
18079017faf2SAbhishek Patel                     *notifyAction;
18089017faf2SAbhishek Patel             }
18099c11a172SVijay Lobo             if ((resolution != nullptr) && (!(*resolution).empty()))
18109c11a172SVijay Lobo             {
18119c11a172SVijay Lobo                 asyncResp->res.jsonValue["Resolution"] = *resolution;
18129c11a172SVijay Lobo             }
1813f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["EntryType"] = "Event";
1814f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Severity"] =
1815f86bb901SAdriana Kobylak                 translateSeverityDbusToRedfish(*severity);
1816f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Created"] =
18172b82937eSEd Tanous                 redfish::time_utils::getDateTimeUintMs(*timestamp);
1818f86bb901SAdriana Kobylak             asyncResp->res.jsonValue["Modified"] =
18192b82937eSEd Tanous                 redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
1820f86bb901SAdriana Kobylak             if (filePath != nullptr)
1821f86bb901SAdriana Kobylak             {
1822f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["AdditionalDataURI"] =
1823e7dbd530SPotin Lai                     "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
1824e7dbd530SPotin Lai                     std::to_string(*id) + "/attachment";
1825f86bb901SAdriana Kobylak             }
1826d1bde9e5SKrzysztof Grobelny             });
18277e860f15SJohn Edward Broadbent         });
1828336e96c6SChicago Duan 
18297e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
183022d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1831ed398213SEd Tanous         .privileges(redfish::privileges::patchLogEntry)
18327e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::patch)(
183345ca1b86SEd Tanous             [&app](const crow::Request& req,
18347e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
183522d268cbSEd Tanous                    const std::string& systemName, const std::string& entryId) {
18363ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
183745ca1b86SEd Tanous         {
183845ca1b86SEd Tanous             return;
183945ca1b86SEd Tanous         }
184022d268cbSEd Tanous         if (systemName != "system")
184122d268cbSEd Tanous         {
184222d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
184322d268cbSEd Tanous                                        systemName);
184422d268cbSEd Tanous             return;
184522d268cbSEd Tanous         }
184675710de2SXiaochao Ma         std::optional<bool> resolved;
184775710de2SXiaochao Ma 
184815ed6780SWilly Tu         if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved",
18497e860f15SJohn Edward Broadbent                                       resolved))
185075710de2SXiaochao Ma         {
185175710de2SXiaochao Ma             return;
185275710de2SXiaochao Ma         }
185375710de2SXiaochao Ma         BMCWEB_LOG_DEBUG << "Set Resolved";
185475710de2SXiaochao Ma 
185575710de2SXiaochao Ma         crow::connections::systemBus->async_method_call(
18565e7e2dc5SEd Tanous             [asyncResp, entryId](const boost::system::error_code& ec) {
185775710de2SXiaochao Ma             if (ec)
185875710de2SXiaochao Ma             {
185975710de2SXiaochao Ma                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
186075710de2SXiaochao Ma                 messages::internalError(asyncResp->res);
186175710de2SXiaochao Ma                 return;
186275710de2SXiaochao Ma             }
186375710de2SXiaochao Ma             },
186475710de2SXiaochao Ma             "xyz.openbmc_project.Logging",
186575710de2SXiaochao Ma             "/xyz/openbmc_project/logging/entry/" + entryId,
186675710de2SXiaochao Ma             "org.freedesktop.DBus.Properties", "Set",
186775710de2SXiaochao Ma             "xyz.openbmc_project.Logging.Entry", "Resolved",
1868168e20c1SEd Tanous             dbus::utility::DbusVariantType(*resolved));
18697e860f15SJohn Edward Broadbent         });
187075710de2SXiaochao Ma 
18717e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
187222d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/")
1873ed398213SEd Tanous         .privileges(redfish::privileges::deleteLogEntry)
1874ed398213SEd Tanous 
1875002d39b4SEd Tanous         .methods(boost::beast::http::verb::delete_)(
1876002d39b4SEd Tanous             [&app](const crow::Request& req,
1877002d39b4SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
187822d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
18793ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1880336e96c6SChicago Duan         {
188145ca1b86SEd Tanous             return;
188245ca1b86SEd Tanous         }
188322d268cbSEd Tanous         if (systemName != "system")
188422d268cbSEd Tanous         {
188522d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
188622d268cbSEd Tanous                                        systemName);
188722d268cbSEd Tanous             return;
188822d268cbSEd Tanous         }
1889336e96c6SChicago Duan         BMCWEB_LOG_DEBUG << "Do delete single event entries.";
1890336e96c6SChicago Duan 
18917e860f15SJohn Edward Broadbent         std::string entryID = param;
1892336e96c6SChicago Duan 
1893336e96c6SChicago Duan         dbus::utility::escapePathForDbus(entryID);
1894336e96c6SChicago Duan 
1895336e96c6SChicago Duan         // Process response from Logging service.
1896002d39b4SEd Tanous         auto respHandler =
18975e7e2dc5SEd Tanous             [asyncResp, entryID](const boost::system::error_code& ec) {
1898002d39b4SEd Tanous             BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done";
1899336e96c6SChicago Duan             if (ec)
1900336e96c6SChicago Duan             {
19013de8d8baSGeorge Liu                 if (ec.value() == EBADR)
19023de8d8baSGeorge Liu                 {
190345ca1b86SEd Tanous                     messages::resourceNotFound(asyncResp->res, "LogEntry",
190445ca1b86SEd Tanous                                                entryID);
19053de8d8baSGeorge Liu                     return;
19063de8d8baSGeorge Liu                 }
1907336e96c6SChicago Duan                 // TODO Handle for specific error code
19080fda0f12SGeorge Liu                 BMCWEB_LOG_ERROR
19090fda0f12SGeorge Liu                     << "EventLogEntry (DBus) doDelete respHandler got error "
1910336e96c6SChicago Duan                     << ec;
1911336e96c6SChicago Duan                 asyncResp->res.result(
1912336e96c6SChicago Duan                     boost::beast::http::status::internal_server_error);
1913336e96c6SChicago Duan                 return;
1914336e96c6SChicago Duan             }
1915336e96c6SChicago Duan 
1916336e96c6SChicago Duan             asyncResp->res.result(boost::beast::http::status::ok);
1917336e96c6SChicago Duan         };
1918336e96c6SChicago Duan 
1919336e96c6SChicago Duan         // Make call to Logging service to request Delete Log
1920336e96c6SChicago Duan         crow::connections::systemBus->async_method_call(
1921336e96c6SChicago Duan             respHandler, "xyz.openbmc_project.Logging",
1922336e96c6SChicago Duan             "/xyz/openbmc_project/logging/entry/" + entryID,
1923336e96c6SChicago Duan             "xyz.openbmc_project.Object.Delete", "Delete");
19247e860f15SJohn Edward Broadbent         });
1925400fd1fbSAdriana Kobylak }
1926400fd1fbSAdriana Kobylak 
19277e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app)
1928400fd1fbSAdriana Kobylak {
19290fda0f12SGeorge Liu     BMCWEB_ROUTE(
19300fda0f12SGeorge Liu         app,
193122d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment")
1932ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
19337e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
193445ca1b86SEd Tanous             [&app](const crow::Request& req,
19357e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
193622d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
19373ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
19387e860f15SJohn Edward Broadbent         {
193945ca1b86SEd Tanous             return;
194045ca1b86SEd Tanous         }
194199351cd8SEd Tanous         if (http_helpers::isContentTypeAllowed(
194299351cd8SEd Tanous                 req.getHeaderValue("Accept"),
19434a0e1a0cSEd Tanous                 http_helpers::ContentType::OctetStream, true))
1944400fd1fbSAdriana Kobylak         {
1945002d39b4SEd Tanous             asyncResp->res.result(boost::beast::http::status::bad_request);
1946400fd1fbSAdriana Kobylak             return;
1947400fd1fbSAdriana Kobylak         }
194822d268cbSEd Tanous         if (systemName != "system")
194922d268cbSEd Tanous         {
195022d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
195122d268cbSEd Tanous                                        systemName);
195222d268cbSEd Tanous             return;
195322d268cbSEd Tanous         }
1954400fd1fbSAdriana Kobylak 
19557e860f15SJohn Edward Broadbent         std::string entryID = param;
1956400fd1fbSAdriana Kobylak         dbus::utility::escapePathForDbus(entryID);
1957400fd1fbSAdriana Kobylak 
1958400fd1fbSAdriana Kobylak         crow::connections::systemBus->async_method_call(
19595e7e2dc5SEd Tanous             [asyncResp, entryID](const boost::system::error_code& ec,
1960400fd1fbSAdriana Kobylak                                  const sdbusplus::message::unix_fd& unixfd) {
1961400fd1fbSAdriana Kobylak             if (ec.value() == EBADR)
1962400fd1fbSAdriana Kobylak             {
1963002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "EventLogAttachment",
1964002d39b4SEd Tanous                                            entryID);
1965400fd1fbSAdriana Kobylak                 return;
1966400fd1fbSAdriana Kobylak             }
1967400fd1fbSAdriana Kobylak             if (ec)
1968400fd1fbSAdriana Kobylak             {
1969400fd1fbSAdriana Kobylak                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1970400fd1fbSAdriana Kobylak                 messages::internalError(asyncResp->res);
1971400fd1fbSAdriana Kobylak                 return;
1972400fd1fbSAdriana Kobylak             }
1973400fd1fbSAdriana Kobylak 
1974400fd1fbSAdriana Kobylak             int fd = -1;
1975400fd1fbSAdriana Kobylak             fd = dup(unixfd);
1976400fd1fbSAdriana Kobylak             if (fd == -1)
1977400fd1fbSAdriana Kobylak             {
1978400fd1fbSAdriana Kobylak                 messages::internalError(asyncResp->res);
1979400fd1fbSAdriana Kobylak                 return;
1980400fd1fbSAdriana Kobylak             }
1981400fd1fbSAdriana Kobylak 
1982400fd1fbSAdriana Kobylak             long long int size = lseek(fd, 0, SEEK_END);
1983400fd1fbSAdriana Kobylak             if (size == -1)
1984400fd1fbSAdriana Kobylak             {
1985400fd1fbSAdriana Kobylak                 messages::internalError(asyncResp->res);
1986400fd1fbSAdriana Kobylak                 return;
1987400fd1fbSAdriana Kobylak             }
1988400fd1fbSAdriana Kobylak 
1989400fd1fbSAdriana Kobylak             // Arbitrary max size of 64kb
1990400fd1fbSAdriana Kobylak             constexpr int maxFileSize = 65536;
1991400fd1fbSAdriana Kobylak             if (size > maxFileSize)
1992400fd1fbSAdriana Kobylak             {
1993002d39b4SEd Tanous                 BMCWEB_LOG_ERROR << "File size exceeds maximum allowed size of "
1994400fd1fbSAdriana Kobylak                                  << maxFileSize;
1995400fd1fbSAdriana Kobylak                 messages::internalError(asyncResp->res);
1996400fd1fbSAdriana Kobylak                 return;
1997400fd1fbSAdriana Kobylak             }
1998400fd1fbSAdriana Kobylak             std::vector<char> data(static_cast<size_t>(size));
1999400fd1fbSAdriana Kobylak             long long int rc = lseek(fd, 0, SEEK_SET);
2000400fd1fbSAdriana Kobylak             if (rc == -1)
2001400fd1fbSAdriana Kobylak             {
2002400fd1fbSAdriana Kobylak                 messages::internalError(asyncResp->res);
2003400fd1fbSAdriana Kobylak                 return;
2004400fd1fbSAdriana Kobylak             }
2005400fd1fbSAdriana Kobylak             rc = read(fd, data.data(), data.size());
2006400fd1fbSAdriana Kobylak             if ((rc == -1) || (rc != size))
2007400fd1fbSAdriana Kobylak             {
2008400fd1fbSAdriana Kobylak                 messages::internalError(asyncResp->res);
2009400fd1fbSAdriana Kobylak                 return;
2010400fd1fbSAdriana Kobylak             }
2011400fd1fbSAdriana Kobylak             close(fd);
2012400fd1fbSAdriana Kobylak 
2013400fd1fbSAdriana Kobylak             std::string_view strData(data.data(), data.size());
2014002d39b4SEd Tanous             std::string output = crow::utility::base64encode(strData);
2015400fd1fbSAdriana Kobylak 
2016d9f6c621SEd Tanous             asyncResp->res.addHeader(boost::beast::http::field::content_type,
2017400fd1fbSAdriana Kobylak                                      "application/octet-stream");
2018d9f6c621SEd Tanous             asyncResp->res.addHeader(
2019d9f6c621SEd Tanous                 boost::beast::http::field::content_transfer_encoding, "Base64");
2020400fd1fbSAdriana Kobylak             asyncResp->res.body() = std::move(output);
2021400fd1fbSAdriana Kobylak             },
2022400fd1fbSAdriana Kobylak             "xyz.openbmc_project.Logging",
2023400fd1fbSAdriana Kobylak             "/xyz/openbmc_project/logging/entry/" + entryID,
2024400fd1fbSAdriana Kobylak             "xyz.openbmc_project.Logging.Entry", "GetEntry");
20257e860f15SJohn Edward Broadbent         });
20261da66f75SEd Tanous }
20271da66f75SEd Tanous 
2028b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console";
2029b7028ebfSSpencer Ku 
2030b7028ebfSSpencer Ku inline bool
2031b7028ebfSSpencer Ku     getHostLoggerFiles(const std::string& hostLoggerFilePath,
2032b7028ebfSSpencer Ku                        std::vector<std::filesystem::path>& hostLoggerFiles)
2033b7028ebfSSpencer Ku {
2034b7028ebfSSpencer Ku     std::error_code ec;
2035b7028ebfSSpencer Ku     std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec);
2036b7028ebfSSpencer Ku     if (ec)
2037b7028ebfSSpencer Ku     {
2038b7028ebfSSpencer Ku         BMCWEB_LOG_ERROR << ec.message();
2039b7028ebfSSpencer Ku         return false;
2040b7028ebfSSpencer Ku     }
2041b7028ebfSSpencer Ku     for (const std::filesystem::directory_entry& it : logPath)
2042b7028ebfSSpencer Ku     {
2043b7028ebfSSpencer Ku         std::string filename = it.path().filename();
2044b7028ebfSSpencer Ku         // Prefix of each log files is "log". Find the file and save the
2045b7028ebfSSpencer Ku         // path
204611ba3979SEd Tanous         if (filename.starts_with("log"))
2047b7028ebfSSpencer Ku         {
2048b7028ebfSSpencer Ku             hostLoggerFiles.emplace_back(it.path());
2049b7028ebfSSpencer Ku         }
2050b7028ebfSSpencer Ku     }
2051b7028ebfSSpencer Ku     // As the log files rotate, they are appended with a ".#" that is higher for
2052b7028ebfSSpencer Ku     // the older logs. Since we start from oldest logs, sort the name in
2053b7028ebfSSpencer Ku     // descending order.
2054b7028ebfSSpencer Ku     std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(),
2055b7028ebfSSpencer Ku               AlphanumLess<std::string>());
2056b7028ebfSSpencer Ku 
2057b7028ebfSSpencer Ku     return true;
2058b7028ebfSSpencer Ku }
2059b7028ebfSSpencer Ku 
206002cad96eSEd Tanous inline bool getHostLoggerEntries(
206102cad96eSEd Tanous     const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip,
206202cad96eSEd Tanous     uint64_t top, std::vector<std::string>& logEntries, size_t& logCount)
2063b7028ebfSSpencer Ku {
2064b7028ebfSSpencer Ku     GzFileReader logFile;
2065b7028ebfSSpencer Ku 
2066b7028ebfSSpencer Ku     // Go though all log files and expose host logs.
2067b7028ebfSSpencer Ku     for (const std::filesystem::path& it : hostLoggerFiles)
2068b7028ebfSSpencer Ku     {
2069b7028ebfSSpencer Ku         if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount))
2070b7028ebfSSpencer Ku         {
2071b7028ebfSSpencer Ku             BMCWEB_LOG_ERROR << "fail to expose host logs";
2072b7028ebfSSpencer Ku             return false;
2073b7028ebfSSpencer Ku         }
2074b7028ebfSSpencer Ku     }
2075b7028ebfSSpencer Ku     // Get lastMessage from constructor by getter
2076b7028ebfSSpencer Ku     std::string lastMessage = logFile.getLastMessage();
2077b7028ebfSSpencer Ku     if (!lastMessage.empty())
2078b7028ebfSSpencer Ku     {
2079b7028ebfSSpencer Ku         logCount++;
2080b7028ebfSSpencer Ku         if (logCount > skip && logCount <= (skip + top))
2081b7028ebfSSpencer Ku         {
2082b7028ebfSSpencer Ku             logEntries.push_back(lastMessage);
2083b7028ebfSSpencer Ku         }
2084b7028ebfSSpencer Ku     }
2085b7028ebfSSpencer Ku     return true;
2086b7028ebfSSpencer Ku }
2087b7028ebfSSpencer Ku 
2088b7028ebfSSpencer Ku inline void fillHostLoggerEntryJson(const std::string& logEntryID,
2089b7028ebfSSpencer Ku                                     const std::string& msg,
20906d6574c9SJason M. Bills                                     nlohmann::json::object_t& logEntryJson)
2091b7028ebfSSpencer Ku {
2092b7028ebfSSpencer Ku     // Fill in the log entry with the gathered data.
20939c11a172SVijay Lobo     logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
2094eddfc437SWilly Tu     logEntryJson["@odata.id"] = crow::utility::urlFromPieces(
2095eddfc437SWilly Tu         "redfish", "v1", "Systems", "system", "LogServices", "HostLogger",
2096eddfc437SWilly Tu         "Entries", logEntryID);
20976d6574c9SJason M. Bills     logEntryJson["Name"] = "Host Logger Entry";
20986d6574c9SJason M. Bills     logEntryJson["Id"] = logEntryID;
20996d6574c9SJason M. Bills     logEntryJson["Message"] = msg;
21006d6574c9SJason M. Bills     logEntryJson["EntryType"] = "Oem";
21016d6574c9SJason M. Bills     logEntryJson["Severity"] = "OK";
21026d6574c9SJason M. Bills     logEntryJson["OemRecordFormat"] = "Host Logger Entry";
2103b7028ebfSSpencer Ku }
2104b7028ebfSSpencer Ku 
2105b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app)
2106b7028ebfSSpencer Ku {
210722d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/")
2108b7028ebfSSpencer Ku         .privileges(redfish::privileges::getLogService)
21091476687dSEd Tanous         .methods(boost::beast::http::verb::get)(
21101476687dSEd Tanous             [&app](const crow::Request& req,
211122d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
211222d268cbSEd Tanous                    const std::string& systemName) {
21133ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
211445ca1b86SEd Tanous         {
211545ca1b86SEd Tanous             return;
211645ca1b86SEd Tanous         }
211722d268cbSEd Tanous         if (systemName != "system")
211822d268cbSEd Tanous         {
211922d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
212022d268cbSEd Tanous                                        systemName);
212122d268cbSEd Tanous             return;
212222d268cbSEd Tanous         }
2123b7028ebfSSpencer Ku         asyncResp->res.jsonValue["@odata.id"] =
2124b7028ebfSSpencer Ku             "/redfish/v1/Systems/system/LogServices/HostLogger";
2125b7028ebfSSpencer Ku         asyncResp->res.jsonValue["@odata.type"] =
2126b7028ebfSSpencer Ku             "#LogService.v1_1_0.LogService";
2127b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Name"] = "Host Logger Service";
2128b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Description"] = "Host Logger Service";
2129b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Id"] = "HostLogger";
21301476687dSEd Tanous         asyncResp->res.jsonValue["Entries"]["@odata.id"] =
21311476687dSEd Tanous             "/redfish/v1/Systems/system/LogServices/HostLogger/Entries";
2132b7028ebfSSpencer Ku         });
2133b7028ebfSSpencer Ku }
2134b7028ebfSSpencer Ku 
2135b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app)
2136b7028ebfSSpencer Ku {
2137b7028ebfSSpencer Ku     BMCWEB_ROUTE(app,
213822d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/")
2139b7028ebfSSpencer Ku         .privileges(redfish::privileges::getLogEntry)
2140002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
2141002d39b4SEd Tanous             [&app](const crow::Request& req,
214222d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
214322d268cbSEd Tanous                    const std::string& systemName) {
2144c937d2bfSEd Tanous         query_param::QueryCapabilities capabilities = {
2145c937d2bfSEd Tanous             .canDelegateTop = true,
2146c937d2bfSEd Tanous             .canDelegateSkip = true,
2147c937d2bfSEd Tanous         };
2148c937d2bfSEd Tanous         query_param::Query delegatedQuery;
2149c937d2bfSEd Tanous         if (!redfish::setUpRedfishRouteWithDelegation(
21503ba00073SCarson Labrado                 app, req, asyncResp, delegatedQuery, capabilities))
2151b7028ebfSSpencer Ku         {
2152b7028ebfSSpencer Ku             return;
2153b7028ebfSSpencer Ku         }
215422d268cbSEd Tanous         if (systemName != "system")
215522d268cbSEd Tanous         {
215622d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
215722d268cbSEd Tanous                                        systemName);
215822d268cbSEd Tanous             return;
215922d268cbSEd Tanous         }
2160b7028ebfSSpencer Ku         asyncResp->res.jsonValue["@odata.id"] =
2161b7028ebfSSpencer Ku             "/redfish/v1/Systems/system/LogServices/HostLogger/Entries";
2162b7028ebfSSpencer Ku         asyncResp->res.jsonValue["@odata.type"] =
2163b7028ebfSSpencer Ku             "#LogEntryCollection.LogEntryCollection";
2164b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Name"] = "HostLogger Entries";
2165b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Description"] =
2166b7028ebfSSpencer Ku             "Collection of HostLogger Entries";
21670fda0f12SGeorge Liu         nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
2168b7028ebfSSpencer Ku         logEntryArray = nlohmann::json::array();
2169b7028ebfSSpencer Ku         asyncResp->res.jsonValue["Members@odata.count"] = 0;
2170b7028ebfSSpencer Ku 
2171b7028ebfSSpencer Ku         std::vector<std::filesystem::path> hostLoggerFiles;
2172b7028ebfSSpencer Ku         if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
2173b7028ebfSSpencer Ku         {
2174b7028ebfSSpencer Ku             BMCWEB_LOG_ERROR << "fail to get host log file path";
2175b7028ebfSSpencer Ku             return;
2176b7028ebfSSpencer Ku         }
21773648c8beSEd Tanous         // If we weren't provided top and skip limits, use the defaults.
21783648c8beSEd Tanous         size_t skip = delegatedQuery.skip.value_or(0);
21795143f7a5SJiaqing Zhao         size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
2180b7028ebfSSpencer Ku         size_t logCount = 0;
2181b7028ebfSSpencer Ku         // This vector only store the entries we want to expose that
2182b7028ebfSSpencer Ku         // control by skip and top.
2183b7028ebfSSpencer Ku         std::vector<std::string> logEntries;
21843648c8beSEd Tanous         if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries,
21853648c8beSEd Tanous                                   logCount))
2186b7028ebfSSpencer Ku         {
2187b7028ebfSSpencer Ku             messages::internalError(asyncResp->res);
2188b7028ebfSSpencer Ku             return;
2189b7028ebfSSpencer Ku         }
2190b7028ebfSSpencer Ku         // If vector is empty, that means skip value larger than total
2191b7028ebfSSpencer Ku         // log count
219226f6976fSEd Tanous         if (logEntries.empty())
2193b7028ebfSSpencer Ku         {
2194b7028ebfSSpencer Ku             asyncResp->res.jsonValue["Members@odata.count"] = logCount;
2195b7028ebfSSpencer Ku             return;
2196b7028ebfSSpencer Ku         }
219726f6976fSEd Tanous         if (!logEntries.empty())
2198b7028ebfSSpencer Ku         {
2199b7028ebfSSpencer Ku             for (size_t i = 0; i < logEntries.size(); i++)
2200b7028ebfSSpencer Ku             {
22016d6574c9SJason M. Bills                 nlohmann::json::object_t hostLogEntry;
22023648c8beSEd Tanous                 fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i],
22033648c8beSEd Tanous                                         hostLogEntry);
22046d6574c9SJason M. Bills                 logEntryArray.push_back(std::move(hostLogEntry));
2205b7028ebfSSpencer Ku             }
2206b7028ebfSSpencer Ku 
2207b7028ebfSSpencer Ku             asyncResp->res.jsonValue["Members@odata.count"] = logCount;
22083648c8beSEd Tanous             if (skip + top < logCount)
2209b7028ebfSSpencer Ku             {
2210b7028ebfSSpencer Ku                 asyncResp->res.jsonValue["Members@odata.nextLink"] =
22110fda0f12SGeorge Liu                     "/redfish/v1/Systems/system/LogServices/HostLogger/Entries?$skip=" +
22123648c8beSEd Tanous                     std::to_string(skip + top);
2213b7028ebfSSpencer Ku             }
2214b7028ebfSSpencer Ku         }
2215b7028ebfSSpencer Ku         });
2216b7028ebfSSpencer Ku }
2217b7028ebfSSpencer Ku 
2218b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app)
2219b7028ebfSSpencer Ku {
2220b7028ebfSSpencer Ku     BMCWEB_ROUTE(
222122d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/")
2222b7028ebfSSpencer Ku         .privileges(redfish::privileges::getLogEntry)
2223b7028ebfSSpencer Ku         .methods(boost::beast::http::verb::get)(
222445ca1b86SEd Tanous             [&app](const crow::Request& req,
2225b7028ebfSSpencer Ku                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
222622d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
22273ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
222845ca1b86SEd Tanous         {
222945ca1b86SEd Tanous             return;
223045ca1b86SEd Tanous         }
223122d268cbSEd Tanous         if (systemName != "system")
223222d268cbSEd Tanous         {
223322d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
223422d268cbSEd Tanous                                        systemName);
223522d268cbSEd Tanous             return;
223622d268cbSEd Tanous         }
2237b7028ebfSSpencer Ku         const std::string& targetID = param;
2238b7028ebfSSpencer Ku 
2239b7028ebfSSpencer Ku         uint64_t idInt = 0;
2240ca45aa3cSEd Tanous 
2241ca45aa3cSEd Tanous         // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
2242ca45aa3cSEd Tanous         const char* end = targetID.data() + targetID.size();
2243ca45aa3cSEd Tanous 
2244ca45aa3cSEd Tanous         auto [ptr, ec] = std::from_chars(targetID.data(), end, idInt);
22459db4ba25SJiaqing Zhao         if (ec == std::errc::invalid_argument ||
22469db4ba25SJiaqing Zhao             ec == std::errc::result_out_of_range)
2247b7028ebfSSpencer Ku         {
22489db4ba25SJiaqing Zhao             messages::resourceNotFound(asyncResp->res, "LogEntry", param);
2249b7028ebfSSpencer Ku             return;
2250b7028ebfSSpencer Ku         }
2251b7028ebfSSpencer Ku 
2252b7028ebfSSpencer Ku         std::vector<std::filesystem::path> hostLoggerFiles;
2253b7028ebfSSpencer Ku         if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
2254b7028ebfSSpencer Ku         {
2255b7028ebfSSpencer Ku             BMCWEB_LOG_ERROR << "fail to get host log file path";
2256b7028ebfSSpencer Ku             return;
2257b7028ebfSSpencer Ku         }
2258b7028ebfSSpencer Ku 
2259b7028ebfSSpencer Ku         size_t logCount = 0;
22603648c8beSEd Tanous         size_t top = 1;
2261b7028ebfSSpencer Ku         std::vector<std::string> logEntries;
2262b7028ebfSSpencer Ku         // We can get specific entry by skip and top. For example, if we
2263b7028ebfSSpencer Ku         // want to get nth entry, we can set skip = n-1 and top = 1 to
2264b7028ebfSSpencer Ku         // get that entry
2265002d39b4SEd Tanous         if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries,
2266002d39b4SEd Tanous                                   logCount))
2267b7028ebfSSpencer Ku         {
2268b7028ebfSSpencer Ku             messages::internalError(asyncResp->res);
2269b7028ebfSSpencer Ku             return;
2270b7028ebfSSpencer Ku         }
2271b7028ebfSSpencer Ku 
2272b7028ebfSSpencer Ku         if (!logEntries.empty())
2273b7028ebfSSpencer Ku         {
22746d6574c9SJason M. Bills             nlohmann::json::object_t hostLogEntry;
22756d6574c9SJason M. Bills             fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry);
22766d6574c9SJason M. Bills             asyncResp->res.jsonValue.update(hostLogEntry);
2277b7028ebfSSpencer Ku             return;
2278b7028ebfSSpencer Ku         }
2279b7028ebfSSpencer Ku 
2280b7028ebfSSpencer Ku         // Requested ID was not found
22819db4ba25SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "LogEntry", param);
2282b7028ebfSSpencer Ku         });
2283b7028ebfSSpencer Ku }
2284b7028ebfSSpencer Ku 
2285dd72e87bSClaire Weinan inline void handleBMCLogServicesCollectionGet(
2286fdd26906SClaire Weinan     crow::App& app, const crow::Request& req,
2287fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
22881da66f75SEd Tanous {
22893ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
229045ca1b86SEd Tanous     {
229145ca1b86SEd Tanous         return;
229245ca1b86SEd Tanous     }
22937e860f15SJohn Edward Broadbent     // Collections don't include the static data added by SubRoute
22947e860f15SJohn Edward Broadbent     // because it has a duplicate entry for members
2295e1f26343SJason M. Bills     asyncResp->res.jsonValue["@odata.type"] =
22961da66f75SEd Tanous         "#LogServiceCollection.LogServiceCollection";
2297e1f26343SJason M. Bills     asyncResp->res.jsonValue["@odata.id"] =
2298e1f26343SJason M. Bills         "/redfish/v1/Managers/bmc/LogServices";
2299002d39b4SEd Tanous     asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
2300e1f26343SJason M. Bills     asyncResp->res.jsonValue["Description"] =
23011da66f75SEd Tanous         "Collection of LogServices for this Manager";
2302002d39b4SEd Tanous     nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
2303c4bf6374SJason M. Bills     logServiceArray = nlohmann::json::array();
2304fdd26906SClaire Weinan 
2305c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
2306613dabeaSEd Tanous     nlohmann::json::object_t journal;
2307613dabeaSEd Tanous     journal["@odata.id"] = "/redfish/v1/Managers/bmc/LogServices/Journal";
2308613dabeaSEd Tanous     logServiceArray.push_back(std::move(journal));
2309c4bf6374SJason M. Bills #endif
2310fdd26906SClaire Weinan 
2311fdd26906SClaire Weinan     asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
2312fdd26906SClaire Weinan 
2313fdd26906SClaire Weinan #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
231415912159SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
23157a1dbc48SGeorge Liu         "xyz.openbmc_project.Collection.DeleteAll"};
23167a1dbc48SGeorge Liu     dbus::utility::getSubTreePaths(
23177a1dbc48SGeorge Liu         "/xyz/openbmc_project/dump", 0, interfaces,
2318fdd26906SClaire Weinan         [asyncResp](
23197a1dbc48SGeorge Liu             const boost::system::error_code& ec,
2320fdd26906SClaire Weinan             const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
2321fdd26906SClaire Weinan         if (ec)
2322fdd26906SClaire Weinan         {
2323fdd26906SClaire Weinan             BMCWEB_LOG_ERROR
2324dd72e87bSClaire Weinan                 << "handleBMCLogServicesCollectionGet respHandler got error "
2325fdd26906SClaire Weinan                 << ec;
2326fdd26906SClaire Weinan             // Assume that getting an error simply means there are no dump
2327fdd26906SClaire Weinan             // LogServices. Return without adding any error response.
2328fdd26906SClaire Weinan             return;
2329fdd26906SClaire Weinan         }
2330fdd26906SClaire Weinan 
2331fdd26906SClaire Weinan         nlohmann::json& logServiceArrayLocal =
2332fdd26906SClaire Weinan             asyncResp->res.jsonValue["Members"];
2333fdd26906SClaire Weinan 
2334fdd26906SClaire Weinan         for (const std::string& path : subTreePaths)
2335fdd26906SClaire Weinan         {
2336fdd26906SClaire Weinan             if (path == "/xyz/openbmc_project/dump/bmc")
2337fdd26906SClaire Weinan             {
2338613dabeaSEd Tanous                 nlohmann::json::object_t member;
2339613dabeaSEd Tanous                 member["@odata.id"] =
2340613dabeaSEd Tanous                     "/redfish/v1/Managers/bmc/LogServices/Dump";
2341613dabeaSEd Tanous                 logServiceArrayLocal.push_back(std::move(member));
2342fdd26906SClaire Weinan             }
2343fdd26906SClaire Weinan             else if (path == "/xyz/openbmc_project/dump/faultlog")
2344fdd26906SClaire Weinan             {
2345613dabeaSEd Tanous                 nlohmann::json::object_t member;
2346613dabeaSEd Tanous                 member["@odata.id"] =
2347613dabeaSEd Tanous                     "/redfish/v1/Managers/bmc/LogServices/FaultLog";
2348613dabeaSEd Tanous                 logServiceArrayLocal.push_back(std::move(member));
2349fdd26906SClaire Weinan             }
2350fdd26906SClaire Weinan         }
2351fdd26906SClaire Weinan 
2352e1f26343SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] =
2353fdd26906SClaire Weinan             logServiceArrayLocal.size();
23547a1dbc48SGeorge Liu         });
2355fdd26906SClaire Weinan #endif
2356fdd26906SClaire Weinan }
2357fdd26906SClaire Weinan 
2358fdd26906SClaire Weinan inline void requestRoutesBMCLogServiceCollection(App& app)
2359fdd26906SClaire Weinan {
2360fdd26906SClaire Weinan     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/")
2361fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogServiceCollection)
2362fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(
2363dd72e87bSClaire Weinan             std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app)));
2364e1f26343SJason M. Bills }
2365e1f26343SJason M. Bills 
23667e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app)
2367e1f26343SJason M. Bills {
23687e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
2369ed398213SEd Tanous         .privileges(redfish::privileges::getLogService)
23707e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
237145ca1b86SEd Tanous             [&app](const crow::Request& req,
237245ca1b86SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
23733ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
23747e860f15SJohn Edward Broadbent         {
237545ca1b86SEd Tanous             return;
237645ca1b86SEd Tanous         }
2377e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
2378e1f26343SJason M. Bills             "#LogService.v1_1_0.LogService";
23790f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
23800f74e643SEd Tanous             "/redfish/v1/Managers/bmc/LogServices/Journal";
2381002d39b4SEd Tanous         asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service";
2382002d39b4SEd Tanous         asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service";
2383ed34a4adSEd Tanous         asyncResp->res.jsonValue["Id"] = "Journal";
2384e1f26343SJason M. Bills         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
23857c8c4058STejas Patil 
23867c8c4058STejas Patil         std::pair<std::string, std::string> redfishDateTimeOffset =
23872b82937eSEd Tanous             redfish::time_utils::getDateTimeOffsetNow();
2388002d39b4SEd Tanous         asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
23897c8c4058STejas Patil         asyncResp->res.jsonValue["DateTimeLocalOffset"] =
23907c8c4058STejas Patil             redfishDateTimeOffset.second;
23917c8c4058STejas Patil 
23921476687dSEd Tanous         asyncResp->res.jsonValue["Entries"]["@odata.id"] =
23931476687dSEd Tanous             "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
23947e860f15SJohn Edward Broadbent         });
2395e1f26343SJason M. Bills }
2396e1f26343SJason M. Bills 
23973a48b3a2SJason M. Bills static int
23983a48b3a2SJason M. Bills     fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID,
2399e1f26343SJason M. Bills                                sd_journal* journal,
24003a48b3a2SJason M. Bills                                nlohmann::json::object_t& bmcJournalLogEntryJson)
2401e1f26343SJason M. Bills {
2402e1f26343SJason M. Bills     // Get the Log Entry contents
2403e1f26343SJason M. Bills     int ret = 0;
2404e1f26343SJason M. Bills 
2405a8fe54f0SJason M. Bills     std::string message;
2406a8fe54f0SJason M. Bills     std::string_view syslogID;
2407a8fe54f0SJason M. Bills     ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID);
2408a8fe54f0SJason M. Bills     if (ret < 0)
2409a8fe54f0SJason M. Bills     {
2410a8fe54f0SJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: "
2411a8fe54f0SJason M. Bills                          << strerror(-ret);
2412a8fe54f0SJason M. Bills     }
2413a8fe54f0SJason M. Bills     if (!syslogID.empty())
2414a8fe54f0SJason M. Bills     {
2415a8fe54f0SJason M. Bills         message += std::string(syslogID) + ": ";
2416a8fe54f0SJason M. Bills     }
2417a8fe54f0SJason M. Bills 
241839e77504SEd Tanous     std::string_view msg;
241916428a1aSJason M. Bills     ret = getJournalMetadata(journal, "MESSAGE", msg);
2420e1f26343SJason M. Bills     if (ret < 0)
2421e1f26343SJason M. Bills     {
2422e1f26343SJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret);
2423e1f26343SJason M. Bills         return 1;
2424e1f26343SJason M. Bills     }
2425a8fe54f0SJason M. Bills     message += std::string(msg);
2426e1f26343SJason M. Bills 
2427e1f26343SJason M. Bills     // Get the severity from the PRIORITY field
2428271584abSEd Tanous     long int severity = 8; // Default to an invalid priority
242916428a1aSJason M. Bills     ret = getJournalMetadata(journal, "PRIORITY", 10, severity);
2430e1f26343SJason M. Bills     if (ret < 0)
2431e1f26343SJason M. Bills     {
2432e1f26343SJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret);
2433e1f26343SJason M. Bills     }
2434e1f26343SJason M. Bills 
2435e1f26343SJason M. Bills     // Get the Created time from the timestamp
243616428a1aSJason M. Bills     std::string entryTimeStr;
243716428a1aSJason M. Bills     if (!getEntryTimestamp(journal, entryTimeStr))
2438e1f26343SJason M. Bills     {
243916428a1aSJason M. Bills         return 1;
2440e1f26343SJason M. Bills     }
2441e1f26343SJason M. Bills 
2442e1f26343SJason M. Bills     // Fill in the log entry with the gathered data
24439c11a172SVijay Lobo     bmcJournalLogEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
2444eddfc437SWilly Tu     bmcJournalLogEntryJson["@odata.id"] = crow::utility::urlFromPieces(
2445eddfc437SWilly Tu         "redfish", "v1", "Managers", "bmc", "LogServices", "Journal", "Entries",
2446eddfc437SWilly Tu         bmcJournalLogEntryID);
244784afc48bSJason M. Bills     bmcJournalLogEntryJson["Name"] = "BMC Journal Entry";
244884afc48bSJason M. Bills     bmcJournalLogEntryJson["Id"] = bmcJournalLogEntryID;
244984afc48bSJason M. Bills     bmcJournalLogEntryJson["Message"] = std::move(message);
245084afc48bSJason M. Bills     bmcJournalLogEntryJson["EntryType"] = "Oem";
245184afc48bSJason M. Bills     bmcJournalLogEntryJson["Severity"] = severity <= 2   ? "Critical"
2452738c1e61SPatrick Williams                                          : severity <= 4 ? "Warning"
245384afc48bSJason M. Bills                                                          : "OK";
245484afc48bSJason M. Bills     bmcJournalLogEntryJson["OemRecordFormat"] = "BMC Journal Entry";
245584afc48bSJason M. Bills     bmcJournalLogEntryJson["Created"] = std::move(entryTimeStr);
2456e1f26343SJason M. Bills     return 0;
2457e1f26343SJason M. Bills }
2458e1f26343SJason M. Bills 
24597e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app)
2460e1f26343SJason M. Bills {
24617e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
2462ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntryCollection)
2463002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
2464002d39b4SEd Tanous             [&app](const crow::Request& req,
2465002d39b4SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
2466c937d2bfSEd Tanous         query_param::QueryCapabilities capabilities = {
2467c937d2bfSEd Tanous             .canDelegateTop = true,
2468c937d2bfSEd Tanous             .canDelegateSkip = true,
2469c937d2bfSEd Tanous         };
2470c937d2bfSEd Tanous         query_param::Query delegatedQuery;
2471c937d2bfSEd Tanous         if (!redfish::setUpRedfishRouteWithDelegation(
24723ba00073SCarson Labrado                 app, req, asyncResp, delegatedQuery, capabilities))
2473193ad2faSJason M. Bills         {
2474193ad2faSJason M. Bills             return;
2475193ad2faSJason M. Bills         }
24763648c8beSEd Tanous 
24773648c8beSEd Tanous         size_t skip = delegatedQuery.skip.value_or(0);
24785143f7a5SJiaqing Zhao         size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
24793648c8beSEd Tanous 
24807e860f15SJohn Edward Broadbent         // Collections don't include the static data added by SubRoute
24817e860f15SJohn Edward Broadbent         // because it has a duplicate entry for members
2482e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
2483e1f26343SJason M. Bills             "#LogEntryCollection.LogEntryCollection";
24840f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
24850f74e643SEd Tanous             "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
2486e1f26343SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries";
2487e1f26343SJason M. Bills         asyncResp->res.jsonValue["Description"] =
2488e1f26343SJason M. Bills             "Collection of BMC Journal Entries";
24890fda0f12SGeorge Liu         nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
2490e1f26343SJason M. Bills         logEntryArray = nlohmann::json::array();
2491e1f26343SJason M. Bills 
24927e860f15SJohn Edward Broadbent         // Go through the journal and use the timestamp to create a
24937e860f15SJohn Edward Broadbent         // unique ID for each entry
2494e1f26343SJason M. Bills         sd_journal* journalTmp = nullptr;
2495e1f26343SJason M. Bills         int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
2496e1f26343SJason M. Bills         if (ret < 0)
2497e1f26343SJason M. Bills         {
2498002d39b4SEd Tanous             BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
2499f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
2500e1f26343SJason M. Bills             return;
2501e1f26343SJason M. Bills         }
25020fda0f12SGeorge Liu         std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
25030fda0f12SGeorge Liu             journalTmp, sd_journal_close);
2504e1f26343SJason M. Bills         journalTmp = nullptr;
2505b01bf299SEd Tanous         uint64_t entryCount = 0;
2506e85d6b16SJason M. Bills         // Reset the unique ID on the first entry
2507e85d6b16SJason M. Bills         bool firstEntry = true;
2508e1f26343SJason M. Bills         SD_JOURNAL_FOREACH(journal.get())
2509e1f26343SJason M. Bills         {
2510193ad2faSJason M. Bills             entryCount++;
25117e860f15SJohn Edward Broadbent             // Handle paging using skip (number of entries to skip from
25127e860f15SJohn Edward Broadbent             // the start) and top (number of entries to display)
25133648c8beSEd Tanous             if (entryCount <= skip || entryCount > skip + top)
2514193ad2faSJason M. Bills             {
2515193ad2faSJason M. Bills                 continue;
2516193ad2faSJason M. Bills             }
2517193ad2faSJason M. Bills 
251816428a1aSJason M. Bills             std::string idStr;
2519e85d6b16SJason M. Bills             if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
2520e1f26343SJason M. Bills             {
2521e1f26343SJason M. Bills                 continue;
2522e1f26343SJason M. Bills             }
2523e85d6b16SJason M. Bills             firstEntry = false;
2524e85d6b16SJason M. Bills 
25253a48b3a2SJason M. Bills             nlohmann::json::object_t bmcJournalLogEntry;
2526c4bf6374SJason M. Bills             if (fillBMCJournalLogEntryJson(idStr, journal.get(),
2527c4bf6374SJason M. Bills                                            bmcJournalLogEntry) != 0)
2528e1f26343SJason M. Bills             {
2529f12894f8SJason M. Bills                 messages::internalError(asyncResp->res);
2530e1f26343SJason M. Bills                 return;
2531e1f26343SJason M. Bills             }
25323a48b3a2SJason M. Bills             logEntryArray.push_back(std::move(bmcJournalLogEntry));
2533e1f26343SJason M. Bills         }
2534193ad2faSJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
25353648c8beSEd Tanous         if (skip + top < entryCount)
2536193ad2faSJason M. Bills         {
2537193ad2faSJason M. Bills             asyncResp->res.jsonValue["Members@odata.nextLink"] =
25380fda0f12SGeorge Liu                 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" +
25393648c8beSEd Tanous                 std::to_string(skip + top);
2540193ad2faSJason M. Bills         }
25417e860f15SJohn Edward Broadbent         });
2542e1f26343SJason M. Bills }
2543e1f26343SJason M. Bills 
25447e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app)
2545e1f26343SJason M. Bills {
25467e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
25477e860f15SJohn Edward Broadbent                  "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/")
2548ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
25497e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
255045ca1b86SEd Tanous             [&app](const crow::Request& req,
25517e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
25527e860f15SJohn Edward Broadbent                    const std::string& entryID) {
25533ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
255445ca1b86SEd Tanous         {
255545ca1b86SEd Tanous             return;
255645ca1b86SEd Tanous         }
2557e1f26343SJason M. Bills         // Convert the unique ID back to a timestamp to find the entry
2558e1f26343SJason M. Bills         uint64_t ts = 0;
2559271584abSEd Tanous         uint64_t index = 0;
25608d1b46d7Szhanghch05         if (!getTimestampFromID(asyncResp, entryID, ts, index))
2561e1f26343SJason M. Bills         {
256216428a1aSJason M. Bills             return;
2563e1f26343SJason M. Bills         }
2564e1f26343SJason M. Bills 
2565e1f26343SJason M. Bills         sd_journal* journalTmp = nullptr;
2566e1f26343SJason M. Bills         int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
2567e1f26343SJason M. Bills         if (ret < 0)
2568e1f26343SJason M. Bills         {
2569002d39b4SEd Tanous             BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
2570f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
2571e1f26343SJason M. Bills             return;
2572e1f26343SJason M. Bills         }
2573002d39b4SEd Tanous         std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
2574002d39b4SEd Tanous             journalTmp, sd_journal_close);
2575e1f26343SJason M. Bills         journalTmp = nullptr;
25767e860f15SJohn Edward Broadbent         // Go to the timestamp in the log and move to the entry at the
25777e860f15SJohn Edward Broadbent         // index tracking the unique ID
2578af07e3f5SJason M. Bills         std::string idStr;
2579af07e3f5SJason M. Bills         bool firstEntry = true;
2580e1f26343SJason M. Bills         ret = sd_journal_seek_realtime_usec(journal.get(), ts);
25812056b6d1SManojkiran Eda         if (ret < 0)
25822056b6d1SManojkiran Eda         {
25832056b6d1SManojkiran Eda             BMCWEB_LOG_ERROR << "failed to seek to an entry in journal"
25842056b6d1SManojkiran Eda                              << strerror(-ret);
25852056b6d1SManojkiran Eda             messages::internalError(asyncResp->res);
25862056b6d1SManojkiran Eda             return;
25872056b6d1SManojkiran Eda         }
2588271584abSEd Tanous         for (uint64_t i = 0; i <= index; i++)
2589e1f26343SJason M. Bills         {
2590e1f26343SJason M. Bills             sd_journal_next(journal.get());
2591af07e3f5SJason M. Bills             if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
2592af07e3f5SJason M. Bills             {
2593af07e3f5SJason M. Bills                 messages::internalError(asyncResp->res);
2594af07e3f5SJason M. Bills                 return;
2595af07e3f5SJason M. Bills             }
2596af07e3f5SJason M. Bills             firstEntry = false;
2597af07e3f5SJason M. Bills         }
2598c4bf6374SJason M. Bills         // Confirm that the entry ID matches what was requested
2599af07e3f5SJason M. Bills         if (idStr != entryID)
2600c4bf6374SJason M. Bills         {
26019db4ba25SJiaqing Zhao             messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
2602c4bf6374SJason M. Bills             return;
2603c4bf6374SJason M. Bills         }
2604c4bf6374SJason M. Bills 
26053a48b3a2SJason M. Bills         nlohmann::json::object_t bmcJournalLogEntry;
2606c4bf6374SJason M. Bills         if (fillBMCJournalLogEntryJson(entryID, journal.get(),
26073a48b3a2SJason M. Bills                                        bmcJournalLogEntry) != 0)
2608e1f26343SJason M. Bills         {
2609f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
2610e1f26343SJason M. Bills             return;
2611e1f26343SJason M. Bills         }
2612d405bb51SJason M. Bills         asyncResp->res.jsonValue.update(bmcJournalLogEntry);
26137e860f15SJohn Edward Broadbent         });
2614c9bb6861Sraviteja-b }
2615c9bb6861Sraviteja-b 
2616fdd26906SClaire Weinan inline void
2617fdd26906SClaire Weinan     getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2618fdd26906SClaire Weinan                        const std::string& dumpType)
2619c9bb6861Sraviteja-b {
2620fdd26906SClaire Weinan     std::string dumpPath;
2621fdd26906SClaire Weinan     std::string overWritePolicy;
2622fdd26906SClaire Weinan     bool collectDiagnosticDataSupported = false;
2623fdd26906SClaire Weinan 
2624fdd26906SClaire Weinan     if (dumpType == "BMC")
262545ca1b86SEd Tanous     {
2626fdd26906SClaire Weinan         dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump";
2627fdd26906SClaire Weinan         overWritePolicy = "WrapsWhenFull";
2628fdd26906SClaire Weinan         collectDiagnosticDataSupported = true;
2629fdd26906SClaire Weinan     }
2630fdd26906SClaire Weinan     else if (dumpType == "FaultLog")
2631fdd26906SClaire Weinan     {
2632fdd26906SClaire Weinan         dumpPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog";
2633fdd26906SClaire Weinan         overWritePolicy = "Unknown";
2634fdd26906SClaire Weinan         collectDiagnosticDataSupported = false;
2635fdd26906SClaire Weinan     }
2636fdd26906SClaire Weinan     else if (dumpType == "System")
2637fdd26906SClaire Weinan     {
2638fdd26906SClaire Weinan         dumpPath = "/redfish/v1/Systems/system/LogServices/Dump";
2639fdd26906SClaire Weinan         overWritePolicy = "WrapsWhenFull";
2640fdd26906SClaire Weinan         collectDiagnosticDataSupported = true;
2641fdd26906SClaire Weinan     }
2642fdd26906SClaire Weinan     else
2643fdd26906SClaire Weinan     {
2644fdd26906SClaire Weinan         BMCWEB_LOG_ERROR << "getDumpServiceInfo() invalid dump type: "
2645fdd26906SClaire Weinan                          << dumpType;
2646fdd26906SClaire Weinan         messages::internalError(asyncResp->res);
264745ca1b86SEd Tanous         return;
264845ca1b86SEd Tanous     }
2649fdd26906SClaire Weinan 
2650fdd26906SClaire Weinan     asyncResp->res.jsonValue["@odata.id"] = dumpPath;
2651fdd26906SClaire Weinan     asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService";
2652c9bb6861Sraviteja-b     asyncResp->res.jsonValue["Name"] = "Dump LogService";
2653fdd26906SClaire Weinan     asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService";
2654fdd26906SClaire Weinan     asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename();
2655fdd26906SClaire Weinan     asyncResp->res.jsonValue["OverWritePolicy"] = std::move(overWritePolicy);
26567c8c4058STejas Patil 
26577c8c4058STejas Patil     std::pair<std::string, std::string> redfishDateTimeOffset =
26582b82937eSEd Tanous         redfish::time_utils::getDateTimeOffsetNow();
26590fda0f12SGeorge Liu     asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
26607c8c4058STejas Patil     asyncResp->res.jsonValue["DateTimeLocalOffset"] =
26617c8c4058STejas Patil         redfishDateTimeOffset.second;
26627c8c4058STejas Patil 
2663fdd26906SClaire Weinan     asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries";
2664fdd26906SClaire Weinan 
2665fdd26906SClaire Weinan     if (collectDiagnosticDataSupported)
2666fdd26906SClaire Weinan     {
2667002d39b4SEd Tanous         asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
26681476687dSEd Tanous                                 ["target"] =
2669fdd26906SClaire Weinan             dumpPath + "/Actions/LogService.CollectDiagnosticData";
2670fdd26906SClaire Weinan     }
26710d946211SClaire Weinan 
26720d946211SClaire Weinan     constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface};
26730d946211SClaire Weinan     dbus::utility::getSubTreePaths(
26740d946211SClaire Weinan         "/xyz/openbmc_project/dump", 0, interfaces,
26750d946211SClaire Weinan         [asyncResp, dumpType, dumpPath](
26760d946211SClaire Weinan             const boost::system::error_code& ec,
26770d946211SClaire Weinan             const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
26780d946211SClaire Weinan         if (ec)
26790d946211SClaire Weinan         {
26800d946211SClaire Weinan             BMCWEB_LOG_ERROR << "getDumpServiceInfo respHandler got error "
26810d946211SClaire Weinan                              << ec;
26820d946211SClaire Weinan             // Assume that getting an error simply means there are no dump
26830d946211SClaire Weinan             // LogServices. Return without adding any error response.
26840d946211SClaire Weinan             return;
26850d946211SClaire Weinan         }
26860d946211SClaire Weinan 
26870d946211SClaire Weinan         const std::string dbusDumpPath =
26880d946211SClaire Weinan             "/xyz/openbmc_project/dump/" +
26890d946211SClaire Weinan             boost::algorithm::to_lower_copy(dumpType);
26900d946211SClaire Weinan 
26910d946211SClaire Weinan         for (const std::string& path : subTreePaths)
26920d946211SClaire Weinan         {
26930d946211SClaire Weinan             if (path == dbusDumpPath)
26940d946211SClaire Weinan             {
26950d946211SClaire Weinan                 asyncResp->res
26960d946211SClaire Weinan                     .jsonValue["Actions"]["#LogService.ClearLog"]["target"] =
26970d946211SClaire Weinan                     dumpPath + "/Actions/LogService.ClearLog";
26980d946211SClaire Weinan                 break;
26990d946211SClaire Weinan             }
27000d946211SClaire Weinan         }
27010d946211SClaire Weinan         });
2702c9bb6861Sraviteja-b }
2703c9bb6861Sraviteja-b 
2704fdd26906SClaire Weinan inline void handleLogServicesDumpServiceGet(
2705fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2706fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
27077e860f15SJohn Edward Broadbent {
27083ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
270945ca1b86SEd Tanous     {
271045ca1b86SEd Tanous         return;
271145ca1b86SEd Tanous     }
2712fdd26906SClaire Weinan     getDumpServiceInfo(asyncResp, dumpType);
2713fdd26906SClaire Weinan }
2714c9bb6861Sraviteja-b 
271522d268cbSEd Tanous inline void handleLogServicesDumpServiceComputerSystemGet(
271622d268cbSEd Tanous     crow::App& app, const crow::Request& req,
271722d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
271822d268cbSEd Tanous     const std::string& chassisId)
271922d268cbSEd Tanous {
272022d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
272122d268cbSEd Tanous     {
272222d268cbSEd Tanous         return;
272322d268cbSEd Tanous     }
272422d268cbSEd Tanous     if (chassisId != "system")
272522d268cbSEd Tanous     {
272622d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
272722d268cbSEd Tanous         return;
272822d268cbSEd Tanous     }
272922d268cbSEd Tanous     getDumpServiceInfo(asyncResp, "System");
273022d268cbSEd Tanous }
273122d268cbSEd Tanous 
2732fdd26906SClaire Weinan inline void handleLogServicesDumpEntriesCollectionGet(
2733fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2734fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
2735fdd26906SClaire Weinan {
2736fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2737fdd26906SClaire Weinan     {
2738fdd26906SClaire Weinan         return;
2739fdd26906SClaire Weinan     }
2740fdd26906SClaire Weinan     getDumpEntryCollection(asyncResp, dumpType);
2741fdd26906SClaire Weinan }
2742fdd26906SClaire Weinan 
274322d268cbSEd Tanous inline void handleLogServicesDumpEntriesCollectionComputerSystemGet(
274422d268cbSEd Tanous     crow::App& app, const crow::Request& req,
274522d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
274622d268cbSEd Tanous     const std::string& chassisId)
274722d268cbSEd Tanous {
274822d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
274922d268cbSEd Tanous     {
275022d268cbSEd Tanous         return;
275122d268cbSEd Tanous     }
275222d268cbSEd Tanous     if (chassisId != "system")
275322d268cbSEd Tanous     {
275422d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
275522d268cbSEd Tanous         return;
275622d268cbSEd Tanous     }
275722d268cbSEd Tanous     getDumpEntryCollection(asyncResp, "System");
275822d268cbSEd Tanous }
275922d268cbSEd Tanous 
2760fdd26906SClaire Weinan inline void handleLogServicesDumpEntryGet(
2761fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2762fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2763fdd26906SClaire Weinan     const std::string& dumpId)
2764fdd26906SClaire Weinan {
2765fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2766fdd26906SClaire Weinan     {
2767fdd26906SClaire Weinan         return;
2768fdd26906SClaire Weinan     }
2769fdd26906SClaire Weinan     getDumpEntryById(asyncResp, dumpId, dumpType);
2770fdd26906SClaire Weinan }
277122d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemGet(
277222d268cbSEd Tanous     crow::App& app, const crow::Request& req,
277322d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
277422d268cbSEd Tanous     const std::string& chassisId, const std::string& dumpId)
277522d268cbSEd Tanous {
277622d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
277722d268cbSEd Tanous     {
277822d268cbSEd Tanous         return;
277922d268cbSEd Tanous     }
278022d268cbSEd Tanous     if (chassisId != "system")
278122d268cbSEd Tanous     {
278222d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
278322d268cbSEd Tanous         return;
278422d268cbSEd Tanous     }
278522d268cbSEd Tanous     getDumpEntryById(asyncResp, dumpId, "System");
278622d268cbSEd Tanous }
2787fdd26906SClaire Weinan 
2788fdd26906SClaire Weinan inline void handleLogServicesDumpEntryDelete(
2789fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2790fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2791fdd26906SClaire Weinan     const std::string& dumpId)
2792fdd26906SClaire Weinan {
2793fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2794fdd26906SClaire Weinan     {
2795fdd26906SClaire Weinan         return;
2796fdd26906SClaire Weinan     }
2797fdd26906SClaire Weinan     deleteDumpEntry(asyncResp, dumpId, dumpType);
2798fdd26906SClaire Weinan }
2799fdd26906SClaire Weinan 
280022d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemDelete(
280122d268cbSEd Tanous     crow::App& app, const crow::Request& req,
280222d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
280322d268cbSEd Tanous     const std::string& chassisId, const std::string& dumpId)
280422d268cbSEd Tanous {
280522d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
280622d268cbSEd Tanous     {
280722d268cbSEd Tanous         return;
280822d268cbSEd Tanous     }
280922d268cbSEd Tanous     if (chassisId != "system")
281022d268cbSEd Tanous     {
281122d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
281222d268cbSEd Tanous         return;
281322d268cbSEd Tanous     }
281422d268cbSEd Tanous     deleteDumpEntry(asyncResp, dumpId, "System");
281522d268cbSEd Tanous }
281622d268cbSEd Tanous 
2817fdd26906SClaire Weinan inline void handleLogServicesDumpCollectDiagnosticDataPost(
2818fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2819fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
2820fdd26906SClaire Weinan {
2821fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2822fdd26906SClaire Weinan     {
2823fdd26906SClaire Weinan         return;
2824fdd26906SClaire Weinan     }
2825fdd26906SClaire Weinan     createDump(asyncResp, req, dumpType);
2826fdd26906SClaire Weinan }
2827fdd26906SClaire Weinan 
282822d268cbSEd Tanous inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost(
282922d268cbSEd Tanous     crow::App& app, const crow::Request& req,
283022d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
283122d268cbSEd Tanous     const std::string& chassisId)
283222d268cbSEd Tanous {
283322d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
283422d268cbSEd Tanous     {
283522d268cbSEd Tanous         return;
283622d268cbSEd Tanous     }
283722d268cbSEd Tanous     if (chassisId != "system")
283822d268cbSEd Tanous     {
283922d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
284022d268cbSEd Tanous         return;
284122d268cbSEd Tanous     }
284222d268cbSEd Tanous     createDump(asyncResp, req, "System");
284322d268cbSEd Tanous }
284422d268cbSEd Tanous 
2845fdd26906SClaire Weinan inline void handleLogServicesDumpClearLogPost(
2846fdd26906SClaire Weinan     crow::App& app, const std::string& dumpType, const crow::Request& req,
2847fdd26906SClaire Weinan     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
2848fdd26906SClaire Weinan {
2849fdd26906SClaire Weinan     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2850fdd26906SClaire Weinan     {
2851fdd26906SClaire Weinan         return;
2852fdd26906SClaire Weinan     }
2853fdd26906SClaire Weinan     clearDump(asyncResp, dumpType);
2854fdd26906SClaire Weinan }
2855fdd26906SClaire Weinan 
285622d268cbSEd Tanous inline void handleLogServicesDumpClearLogComputerSystemPost(
285722d268cbSEd Tanous     crow::App& app, const crow::Request& req,
285822d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
285922d268cbSEd Tanous     const std::string& chassisId)
286022d268cbSEd Tanous {
286122d268cbSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
286222d268cbSEd Tanous     {
286322d268cbSEd Tanous         return;
286422d268cbSEd Tanous     }
286522d268cbSEd Tanous     if (chassisId != "system")
286622d268cbSEd Tanous     {
286722d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId);
286822d268cbSEd Tanous         return;
286922d268cbSEd Tanous     }
287022d268cbSEd Tanous     clearDump(asyncResp, "System");
287122d268cbSEd Tanous }
287222d268cbSEd Tanous 
2873fdd26906SClaire Weinan inline void requestRoutesBMCDumpService(App& app)
2874fdd26906SClaire Weinan {
2875fdd26906SClaire Weinan     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
2876fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogService)
2877fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2878fdd26906SClaire Weinan             handleLogServicesDumpServiceGet, std::ref(app), "BMC"));
2879fdd26906SClaire Weinan }
2880fdd26906SClaire Weinan 
2881fdd26906SClaire Weinan inline void requestRoutesBMCDumpEntryCollection(App& app)
2882fdd26906SClaire Weinan {
2883fdd26906SClaire Weinan     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
2884fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogEntryCollection)
2885fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2886fdd26906SClaire Weinan             handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC"));
2887c9bb6861Sraviteja-b }
2888c9bb6861Sraviteja-b 
28897e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app)
2890c9bb6861Sraviteja-b {
28917e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
28927e860f15SJohn Edward Broadbent                  "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/")
2893ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
2894fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2895fdd26906SClaire Weinan             handleLogServicesDumpEntryGet, std::ref(app), "BMC"));
2896fdd26906SClaire Weinan 
28977e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
28987e860f15SJohn Edward Broadbent                  "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/")
2899ed398213SEd Tanous         .privileges(redfish::privileges::deleteLogEntry)
2900fdd26906SClaire Weinan         .methods(boost::beast::http::verb::delete_)(std::bind_front(
2901fdd26906SClaire Weinan             handleLogServicesDumpEntryDelete, std::ref(app), "BMC"));
2902c9bb6861Sraviteja-b }
2903c9bb6861Sraviteja-b 
29047e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app)
2905c9bb6861Sraviteja-b {
29060fda0f12SGeorge Liu     BMCWEB_ROUTE(
29070fda0f12SGeorge Liu         app,
29080fda0f12SGeorge Liu         "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
2909ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
29107e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
2911fdd26906SClaire Weinan             std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost,
2912fdd26906SClaire Weinan                             std::ref(app), "BMC"));
2913a43be80fSAsmitha Karunanithi }
2914a43be80fSAsmitha Karunanithi 
29157e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app)
291680319af1SAsmitha Karunanithi {
29170fda0f12SGeorge Liu     BMCWEB_ROUTE(
29180fda0f12SGeorge Liu         app,
29190fda0f12SGeorge Liu         "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog/")
2920ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
2921fdd26906SClaire Weinan         .methods(boost::beast::http::verb::post)(std::bind_front(
2922fdd26906SClaire Weinan             handleLogServicesDumpClearLogPost, std::ref(app), "BMC"));
292345ca1b86SEd Tanous }
2924fdd26906SClaire Weinan 
2925fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpService(App& app)
2926fdd26906SClaire Weinan {
2927fdd26906SClaire Weinan     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/")
2928fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogService)
2929fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2930fdd26906SClaire Weinan             handleLogServicesDumpServiceGet, std::ref(app), "FaultLog"));
2931fdd26906SClaire Weinan }
2932fdd26906SClaire Weinan 
2933fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntryCollection(App& app)
2934fdd26906SClaire Weinan {
2935fdd26906SClaire Weinan     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/")
2936fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogEntryCollection)
2937fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(
2938fdd26906SClaire Weinan             std::bind_front(handleLogServicesDumpEntriesCollectionGet,
2939fdd26906SClaire Weinan                             std::ref(app), "FaultLog"));
2940fdd26906SClaire Weinan }
2941fdd26906SClaire Weinan 
2942fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntry(App& app)
2943fdd26906SClaire Weinan {
2944fdd26906SClaire Weinan     BMCWEB_ROUTE(app,
2945fdd26906SClaire Weinan                  "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/")
2946fdd26906SClaire Weinan         .privileges(redfish::privileges::getLogEntry)
2947fdd26906SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
2948fdd26906SClaire Weinan             handleLogServicesDumpEntryGet, std::ref(app), "FaultLog"));
2949fdd26906SClaire Weinan 
2950fdd26906SClaire Weinan     BMCWEB_ROUTE(app,
2951fdd26906SClaire Weinan                  "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/")
2952fdd26906SClaire Weinan         .privileges(redfish::privileges::deleteLogEntry)
2953fdd26906SClaire Weinan         .methods(boost::beast::http::verb::delete_)(std::bind_front(
2954fdd26906SClaire Weinan             handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog"));
2955fdd26906SClaire Weinan }
2956fdd26906SClaire Weinan 
2957fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpClear(App& app)
2958fdd26906SClaire Weinan {
2959fdd26906SClaire Weinan     BMCWEB_ROUTE(
2960fdd26906SClaire Weinan         app,
2961fdd26906SClaire Weinan         "/redfish/v1/Managers/bmc/LogServices/FaultLog/Actions/LogService.ClearLog/")
2962fdd26906SClaire Weinan         .privileges(redfish::privileges::postLogService)
2963fdd26906SClaire Weinan         .methods(boost::beast::http::verb::post)(std::bind_front(
2964fdd26906SClaire Weinan             handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog"));
29655cb1dd27SAsmitha Karunanithi }
29665cb1dd27SAsmitha Karunanithi 
29677e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app)
29685cb1dd27SAsmitha Karunanithi {
296922d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/")
2970ed398213SEd Tanous         .privileges(redfish::privileges::getLogService)
29716ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
297222d268cbSEd Tanous             handleLogServicesDumpServiceComputerSystemGet, std::ref(app)));
29735cb1dd27SAsmitha Karunanithi }
29745cb1dd27SAsmitha Karunanithi 
29757e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app)
29767e860f15SJohn Edward Broadbent {
297722d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/")
2978ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntryCollection)
297922d268cbSEd Tanous         .methods(boost::beast::http::verb::get)(std::bind_front(
298022d268cbSEd Tanous             handleLogServicesDumpEntriesCollectionComputerSystemGet,
298122d268cbSEd Tanous             std::ref(app)));
29825cb1dd27SAsmitha Karunanithi }
29835cb1dd27SAsmitha Karunanithi 
29847e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app)
29855cb1dd27SAsmitha Karunanithi {
29867e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
298722d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
2988ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
29896ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::get)(std::bind_front(
299022d268cbSEd Tanous             handleLogServicesDumpEntryComputerSystemGet, std::ref(app)));
29918d1b46d7Szhanghch05 
29927e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
299322d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/")
2994ed398213SEd Tanous         .privileges(redfish::privileges::deleteLogEntry)
29956ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::delete_)(std::bind_front(
299622d268cbSEd Tanous             handleLogServicesDumpEntryComputerSystemDelete, std::ref(app)));
29975cb1dd27SAsmitha Karunanithi }
2998c9bb6861Sraviteja-b 
29997e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app)
3000c9bb6861Sraviteja-b {
30010fda0f12SGeorge Liu     BMCWEB_ROUTE(
30020fda0f12SGeorge Liu         app,
300322d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
3004ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
300522d268cbSEd Tanous         .methods(boost::beast::http::verb::post)(std::bind_front(
300622d268cbSEd Tanous             handleLogServicesDumpCollectDiagnosticDataComputerSystemPost,
300722d268cbSEd Tanous             std::ref(app)));
3008a43be80fSAsmitha Karunanithi }
3009a43be80fSAsmitha Karunanithi 
30107e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app)
3011a43be80fSAsmitha Karunanithi {
30120fda0f12SGeorge Liu     BMCWEB_ROUTE(
30130fda0f12SGeorge Liu         app,
301422d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/")
3015ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
30166ab9ad54SClaire Weinan         .methods(boost::beast::http::verb::post)(std::bind_front(
301722d268cbSEd Tanous             handleLogServicesDumpClearLogComputerSystemPost, std::ref(app)));
3018013487e5Sraviteja-b }
3019013487e5Sraviteja-b 
30207e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app)
30211da66f75SEd Tanous {
30223946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
30233946028dSAppaRao Puli     // method for security reasons.
30241da66f75SEd Tanous     /**
30251da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
30261da66f75SEd Tanous      */
302722d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/")
3028ed398213SEd Tanous         // This is incorrect, should be:
3029ed398213SEd Tanous         //.privileges(redfish::privileges::getLogService)
3030432a890cSEd Tanous         .privileges({{"ConfigureManager"}})
3031002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
3032002d39b4SEd Tanous             [&app](const crow::Request& req,
303322d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
303422d268cbSEd Tanous                    const std::string& systemName) {
30353ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
303645ca1b86SEd Tanous         {
303745ca1b86SEd Tanous             return;
303845ca1b86SEd Tanous         }
303922d268cbSEd Tanous         if (systemName != "system")
304022d268cbSEd Tanous         {
304122d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
304222d268cbSEd Tanous                                        systemName);
304322d268cbSEd Tanous             return;
304422d268cbSEd Tanous         }
304522d268cbSEd Tanous 
30467e860f15SJohn Edward Broadbent         // Copy over the static data to include the entries added by
30477e860f15SJohn Edward Broadbent         // SubRoute
30480f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
3049424c4176SJason M. Bills             "/redfish/v1/Systems/system/LogServices/Crashdump";
3050e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
30518e6c099aSJason M. Bills             "#LogService.v1_2_0.LogService";
30524f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
30534f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
30544f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
3055e1f26343SJason M. Bills         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
3056e1f26343SJason M. Bills         asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
30577c8c4058STejas Patil 
30587c8c4058STejas Patil         std::pair<std::string, std::string> redfishDateTimeOffset =
30592b82937eSEd Tanous             redfish::time_utils::getDateTimeOffsetNow();
30607c8c4058STejas Patil         asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
30617c8c4058STejas Patil         asyncResp->res.jsonValue["DateTimeLocalOffset"] =
30627c8c4058STejas Patil             redfishDateTimeOffset.second;
30637c8c4058STejas Patil 
30641476687dSEd Tanous         asyncResp->res.jsonValue["Entries"]["@odata.id"] =
3065eddfc437SWilly Tu             crow::utility::urlFromPieces("redfish", "v1", "Systems", "system",
3066eddfc437SWilly Tu                                          "LogServices", "Crashdump", "Entries");
3067002d39b4SEd Tanous         asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] =
30681476687dSEd Tanous             "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog";
3069002d39b4SEd Tanous         asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
30701476687dSEd Tanous                                 ["target"] =
30711476687dSEd Tanous             "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData";
30727e860f15SJohn Edward Broadbent         });
30731da66f75SEd Tanous }
30741da66f75SEd Tanous 
30757e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app)
30765b61b5e8SJason M. Bills {
30770fda0f12SGeorge Liu     BMCWEB_ROUTE(
30780fda0f12SGeorge Liu         app,
307922d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/")
3080ed398213SEd Tanous         // This is incorrect, should be:
3081ed398213SEd Tanous         //.privileges(redfish::privileges::postLogService)
3082432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
30837e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
308445ca1b86SEd Tanous             [&app](const crow::Request& req,
308522d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
308622d268cbSEd Tanous                    const std::string& systemName) {
30873ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
308845ca1b86SEd Tanous         {
308945ca1b86SEd Tanous             return;
309045ca1b86SEd Tanous         }
309122d268cbSEd Tanous         if (systemName != "system")
309222d268cbSEd Tanous         {
309322d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
309422d268cbSEd Tanous                                        systemName);
309522d268cbSEd Tanous             return;
309622d268cbSEd Tanous         }
30975b61b5e8SJason M. Bills         crow::connections::systemBus->async_method_call(
30985e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec,
3099cb13a392SEd Tanous                         const std::string&) {
31005b61b5e8SJason M. Bills             if (ec)
31015b61b5e8SJason M. Bills             {
31025b61b5e8SJason M. Bills                 messages::internalError(asyncResp->res);
31035b61b5e8SJason M. Bills                 return;
31045b61b5e8SJason M. Bills             }
31055b61b5e8SJason M. Bills             messages::success(asyncResp->res);
31065b61b5e8SJason M. Bills             },
3107002d39b4SEd Tanous             crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
31087e860f15SJohn Edward Broadbent         });
31095b61b5e8SJason M. Bills }
31105b61b5e8SJason M. Bills 
31118d1b46d7Szhanghch05 static void
31128d1b46d7Szhanghch05     logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
31138d1b46d7Szhanghch05                       const std::string& logID, nlohmann::json& logEntryJson)
3114e855dd28SJason M. Bills {
3115043a0536SJohnathan Mantey     auto getStoredLogCallback =
3116b9d36b47SEd Tanous         [asyncResp, logID,
31175e7e2dc5SEd Tanous          &logEntryJson](const boost::system::error_code& ec,
3118b9d36b47SEd Tanous                         const dbus::utility::DBusPropertiesMap& params) {
3119e855dd28SJason M. Bills         if (ec)
3120e855dd28SJason M. Bills         {
3121e855dd28SJason M. Bills             BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
31221ddcf01aSJason M. Bills             if (ec.value() ==
31231ddcf01aSJason M. Bills                 boost::system::linux_error::bad_request_descriptor)
31241ddcf01aSJason M. Bills             {
3125002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
31261ddcf01aSJason M. Bills             }
31271ddcf01aSJason M. Bills             else
31281ddcf01aSJason M. Bills             {
3129e855dd28SJason M. Bills                 messages::internalError(asyncResp->res);
31301ddcf01aSJason M. Bills             }
3131e855dd28SJason M. Bills             return;
3132e855dd28SJason M. Bills         }
3133043a0536SJohnathan Mantey 
3134043a0536SJohnathan Mantey         std::string timestamp{};
3135043a0536SJohnathan Mantey         std::string filename{};
3136043a0536SJohnathan Mantey         std::string logfile{};
31372c70f800SEd Tanous         parseCrashdumpParameters(params, filename, timestamp, logfile);
3138043a0536SJohnathan Mantey 
3139043a0536SJohnathan Mantey         if (filename.empty() || timestamp.empty())
3140e855dd28SJason M. Bills         {
31419db4ba25SJiaqing Zhao             messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
3142e855dd28SJason M. Bills             return;
3143e855dd28SJason M. Bills         }
3144e855dd28SJason M. Bills 
3145043a0536SJohnathan Mantey         std::string crashdumpURI =
3146e855dd28SJason M. Bills             "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
3147043a0536SJohnathan Mantey             logID + "/" + filename;
314884afc48bSJason M. Bills         nlohmann::json::object_t logEntry;
31499c11a172SVijay Lobo         logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
3150eddfc437SWilly Tu         logEntry["@odata.id"] = crow::utility::urlFromPieces(
3151eddfc437SWilly Tu             "redfish", "v1", "Systems", "system", "LogServices", "Crashdump",
3152eddfc437SWilly Tu             "Entries", logID);
315384afc48bSJason M. Bills         logEntry["Name"] = "CPU Crashdump";
315484afc48bSJason M. Bills         logEntry["Id"] = logID;
315584afc48bSJason M. Bills         logEntry["EntryType"] = "Oem";
315684afc48bSJason M. Bills         logEntry["AdditionalDataURI"] = std::move(crashdumpURI);
315784afc48bSJason M. Bills         logEntry["DiagnosticDataType"] = "OEM";
315884afc48bSJason M. Bills         logEntry["OEMDiagnosticDataType"] = "PECICrashdump";
315984afc48bSJason M. Bills         logEntry["Created"] = std::move(timestamp);
31602b20ef6eSJason M. Bills 
31612b20ef6eSJason M. Bills         // If logEntryJson references an array of LogEntry resources
31622b20ef6eSJason M. Bills         // ('Members' list), then push this as a new entry, otherwise set it
31632b20ef6eSJason M. Bills         // directly
31642b20ef6eSJason M. Bills         if (logEntryJson.is_array())
31652b20ef6eSJason M. Bills         {
31662b20ef6eSJason M. Bills             logEntryJson.push_back(logEntry);
31672b20ef6eSJason M. Bills             asyncResp->res.jsonValue["Members@odata.count"] =
31682b20ef6eSJason M. Bills                 logEntryJson.size();
31692b20ef6eSJason M. Bills         }
31702b20ef6eSJason M. Bills         else
31712b20ef6eSJason M. Bills         {
3172d405bb51SJason M. Bills             logEntryJson.update(logEntry);
31732b20ef6eSJason M. Bills         }
3174e855dd28SJason M. Bills     };
3175d1bde9e5SKrzysztof Grobelny     sdbusplus::asio::getAllProperties(
3176d1bde9e5SKrzysztof Grobelny         *crow::connections::systemBus, crashdumpObject,
3177d1bde9e5SKrzysztof Grobelny         crashdumpPath + std::string("/") + logID, crashdumpInterface,
3178d1bde9e5SKrzysztof Grobelny         std::move(getStoredLogCallback));
3179e855dd28SJason M. Bills }
3180e855dd28SJason M. Bills 
31817e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app)
31821da66f75SEd Tanous {
31833946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
31843946028dSAppaRao Puli     // method for security reasons.
31851da66f75SEd Tanous     /**
31861da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
31871da66f75SEd Tanous      */
31887e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
318922d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/")
3190ed398213SEd Tanous         // This is incorrect, should be.
3191ed398213SEd Tanous         //.privileges(redfish::privileges::postLogEntryCollection)
3192432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
3193002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
3194002d39b4SEd Tanous             [&app](const crow::Request& req,
319522d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
319622d268cbSEd Tanous                    const std::string& systemName) {
31973ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
319845ca1b86SEd Tanous         {
319945ca1b86SEd Tanous             return;
320045ca1b86SEd Tanous         }
320122d268cbSEd Tanous         if (systemName != "system")
320222d268cbSEd Tanous         {
320322d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
320422d268cbSEd Tanous                                        systemName);
320522d268cbSEd Tanous             return;
320622d268cbSEd Tanous         }
320722d268cbSEd Tanous 
32087a1dbc48SGeorge Liu         constexpr std::array<std::string_view, 1> interfaces = {
32097a1dbc48SGeorge Liu             crashdumpInterface};
32107a1dbc48SGeorge Liu         dbus::utility::getSubTreePaths(
32117a1dbc48SGeorge Liu             "/", 0, interfaces,
32127a1dbc48SGeorge Liu             [asyncResp](const boost::system::error_code& ec,
32132b20ef6eSJason M. Bills                         const std::vector<std::string>& resp) {
32141da66f75SEd Tanous             if (ec)
32151da66f75SEd Tanous             {
32161da66f75SEd Tanous                 if (ec.value() !=
32171da66f75SEd Tanous                     boost::system::errc::no_such_file_or_directory)
32181da66f75SEd Tanous                 {
32191da66f75SEd Tanous                     BMCWEB_LOG_DEBUG << "failed to get entries ec: "
32201da66f75SEd Tanous                                      << ec.message();
3221f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
32221da66f75SEd Tanous                     return;
32231da66f75SEd Tanous                 }
32241da66f75SEd Tanous             }
3225e1f26343SJason M. Bills             asyncResp->res.jsonValue["@odata.type"] =
32261da66f75SEd Tanous                 "#LogEntryCollection.LogEntryCollection";
32270f74e643SEd Tanous             asyncResp->res.jsonValue["@odata.id"] =
3228424c4176SJason M. Bills                 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
3229002d39b4SEd Tanous             asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
3230e1f26343SJason M. Bills             asyncResp->res.jsonValue["Description"] =
3231424c4176SJason M. Bills                 "Collection of Crashdump Entries";
3232002d39b4SEd Tanous             asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3233a2dd60a6SBrandon Kim             asyncResp->res.jsonValue["Members@odata.count"] = 0;
32342b20ef6eSJason M. Bills 
32352b20ef6eSJason M. Bills             for (const std::string& path : resp)
32361da66f75SEd Tanous             {
32372b20ef6eSJason M. Bills                 const sdbusplus::message::object_path objPath(path);
3238e855dd28SJason M. Bills                 // Get the log ID
32392b20ef6eSJason M. Bills                 std::string logID = objPath.filename();
32402b20ef6eSJason M. Bills                 if (logID.empty())
32411da66f75SEd Tanous                 {
3242e855dd28SJason M. Bills                     continue;
32431da66f75SEd Tanous                 }
3244e855dd28SJason M. Bills                 // Add the log entry to the array
32452b20ef6eSJason M. Bills                 logCrashdumpEntry(asyncResp, logID,
32462b20ef6eSJason M. Bills                                   asyncResp->res.jsonValue["Members"]);
32471da66f75SEd Tanous             }
32487a1dbc48SGeorge Liu             });
32497e860f15SJohn Edward Broadbent         });
32501da66f75SEd Tanous }
32511da66f75SEd Tanous 
32527e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app)
32531da66f75SEd Tanous {
32543946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
32553946028dSAppaRao Puli     // method for security reasons.
32561da66f75SEd Tanous 
32577e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
325822d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/")
3259ed398213SEd Tanous         // this is incorrect, should be
3260ed398213SEd Tanous         // .privileges(redfish::privileges::getLogEntry)
3261432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
32627e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
326345ca1b86SEd Tanous             [&app](const crow::Request& req,
32647e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
326522d268cbSEd Tanous                    const std::string& systemName, const std::string& param) {
32663ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
326745ca1b86SEd Tanous         {
326845ca1b86SEd Tanous             return;
326945ca1b86SEd Tanous         }
327022d268cbSEd Tanous         if (systemName != "system")
327122d268cbSEd Tanous         {
327222d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
327322d268cbSEd Tanous                                        systemName);
327422d268cbSEd Tanous             return;
327522d268cbSEd Tanous         }
32767e860f15SJohn Edward Broadbent         const std::string& logID = param;
3277e855dd28SJason M. Bills         logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
32787e860f15SJohn Edward Broadbent         });
3279e855dd28SJason M. Bills }
3280e855dd28SJason M. Bills 
32817e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app)
3282e855dd28SJason M. Bills {
32833946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
32843946028dSAppaRao Puli     // method for security reasons.
32857e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
32867e860f15SJohn Edward Broadbent         app,
328722d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/")
3288ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
32897e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
3290a4ce114aSNan Zhou             [](const crow::Request& req,
32917e860f15SJohn Edward Broadbent                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
329222d268cbSEd Tanous                const std::string& systemName, const std::string& logID,
329322d268cbSEd Tanous                const std::string& fileName) {
32942a9beeedSShounak Mitra         // Do not call getRedfishRoute here since the crashdump file is not a
32952a9beeedSShounak Mitra         // Redfish resource.
329622d268cbSEd Tanous 
329722d268cbSEd Tanous         if (systemName != "system")
329822d268cbSEd Tanous         {
329922d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
330022d268cbSEd Tanous                                        systemName);
330122d268cbSEd Tanous             return;
330222d268cbSEd Tanous         }
330322d268cbSEd Tanous 
3304043a0536SJohnathan Mantey         auto getStoredLogCallback =
3305002d39b4SEd Tanous             [asyncResp, logID, fileName, url(boost::urls::url(req.urlView))](
33065e7e2dc5SEd Tanous                 const boost::system::error_code& ec,
3307002d39b4SEd Tanous                 const std::vector<
3308002d39b4SEd Tanous                     std::pair<std::string, dbus::utility::DbusVariantType>>&
33097e860f15SJohn Edward Broadbent                     resp) {
33101da66f75SEd Tanous             if (ec)
33111da66f75SEd Tanous             {
3312002d39b4SEd Tanous                 BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
3313f12894f8SJason M. Bills                 messages::internalError(asyncResp->res);
33141da66f75SEd Tanous                 return;
33151da66f75SEd Tanous             }
3316e855dd28SJason M. Bills 
3317043a0536SJohnathan Mantey             std::string dbusFilename{};
3318043a0536SJohnathan Mantey             std::string dbusTimestamp{};
3319043a0536SJohnathan Mantey             std::string dbusFilepath{};
3320043a0536SJohnathan Mantey 
3321002d39b4SEd Tanous             parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
3322002d39b4SEd Tanous                                      dbusFilepath);
3323043a0536SJohnathan Mantey 
3324043a0536SJohnathan Mantey             if (dbusFilename.empty() || dbusTimestamp.empty() ||
3325043a0536SJohnathan Mantey                 dbusFilepath.empty())
33261da66f75SEd Tanous             {
33279db4ba25SJiaqing Zhao                 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
33281da66f75SEd Tanous                 return;
33291da66f75SEd Tanous             }
3330e855dd28SJason M. Bills 
3331043a0536SJohnathan Mantey             // Verify the file name parameter is correct
3332043a0536SJohnathan Mantey             if (fileName != dbusFilename)
3333043a0536SJohnathan Mantey             {
33349db4ba25SJiaqing Zhao                 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
3335043a0536SJohnathan Mantey                 return;
3336043a0536SJohnathan Mantey             }
3337043a0536SJohnathan Mantey 
3338043a0536SJohnathan Mantey             if (!std::filesystem::exists(dbusFilepath))
3339043a0536SJohnathan Mantey             {
33409db4ba25SJiaqing Zhao                 messages::resourceNotFound(asyncResp->res, "LogEntry", logID);
3341043a0536SJohnathan Mantey                 return;
3342043a0536SJohnathan Mantey             }
3343002d39b4SEd Tanous             std::ifstream ifs(dbusFilepath, std::ios::in | std::ios::binary);
3344002d39b4SEd Tanous             asyncResp->res.body() =
3345002d39b4SEd Tanous                 std::string(std::istreambuf_iterator<char>{ifs}, {});
3346043a0536SJohnathan Mantey 
33477e860f15SJohn Edward Broadbent             // Configure this to be a file download when accessed
33487e860f15SJohn Edward Broadbent             // from a browser
3349d9f6c621SEd Tanous             asyncResp->res.addHeader(
3350d9f6c621SEd Tanous                 boost::beast::http::field::content_disposition, "attachment");
33511da66f75SEd Tanous         };
3352d1bde9e5SKrzysztof Grobelny         sdbusplus::asio::getAllProperties(
3353d1bde9e5SKrzysztof Grobelny             *crow::connections::systemBus, crashdumpObject,
3354d1bde9e5SKrzysztof Grobelny             crashdumpPath + std::string("/") + logID, crashdumpInterface,
3355d1bde9e5SKrzysztof Grobelny             std::move(getStoredLogCallback));
33567e860f15SJohn Edward Broadbent         });
33571da66f75SEd Tanous }
33581da66f75SEd Tanous 
3359c5a4c82aSJason M. Bills enum class OEMDiagnosticType
3360c5a4c82aSJason M. Bills {
3361c5a4c82aSJason M. Bills     onDemand,
3362c5a4c82aSJason M. Bills     telemetry,
3363c5a4c82aSJason M. Bills     invalid,
3364c5a4c82aSJason M. Bills };
3365c5a4c82aSJason M. Bills 
336626ccae32SEd Tanous inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr)
3367c5a4c82aSJason M. Bills {
3368c5a4c82aSJason M. Bills     if (oemDiagStr == "OnDemand")
3369c5a4c82aSJason M. Bills     {
3370c5a4c82aSJason M. Bills         return OEMDiagnosticType::onDemand;
3371c5a4c82aSJason M. Bills     }
3372c5a4c82aSJason M. Bills     if (oemDiagStr == "Telemetry")
3373c5a4c82aSJason M. Bills     {
3374c5a4c82aSJason M. Bills         return OEMDiagnosticType::telemetry;
3375c5a4c82aSJason M. Bills     }
3376c5a4c82aSJason M. Bills 
3377c5a4c82aSJason M. Bills     return OEMDiagnosticType::invalid;
3378c5a4c82aSJason M. Bills }
3379c5a4c82aSJason M. Bills 
33807e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app)
33811da66f75SEd Tanous {
33823946028dSAppaRao Puli     // Note: Deviated from redfish privilege registry for GET & HEAD
33833946028dSAppaRao Puli     // method for security reasons.
33840fda0f12SGeorge Liu     BMCWEB_ROUTE(
33850fda0f12SGeorge Liu         app,
338622d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/")
3387ed398213SEd Tanous         // The below is incorrect;  Should be ConfigureManager
3388ed398213SEd Tanous         //.privileges(redfish::privileges::postLogService)
3389432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
3390002d39b4SEd Tanous         .methods(boost::beast::http::verb::post)(
3391002d39b4SEd Tanous             [&app](const crow::Request& req,
339222d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
339322d268cbSEd Tanous                    const std::string& systemName) {
33943ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
339545ca1b86SEd Tanous         {
339645ca1b86SEd Tanous             return;
339745ca1b86SEd Tanous         }
339822d268cbSEd Tanous 
339922d268cbSEd Tanous         if (systemName != "system")
340022d268cbSEd Tanous         {
340122d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
340222d268cbSEd Tanous                                        systemName);
340322d268cbSEd Tanous             return;
340422d268cbSEd Tanous         }
340522d268cbSEd Tanous 
34068e6c099aSJason M. Bills         std::string diagnosticDataType;
34078e6c099aSJason M. Bills         std::string oemDiagnosticDataType;
340815ed6780SWilly Tu         if (!redfish::json_util::readJsonAction(
3409002d39b4SEd Tanous                 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
3410002d39b4SEd Tanous                 "OEMDiagnosticDataType", oemDiagnosticDataType))
34118e6c099aSJason M. Bills         {
34128e6c099aSJason M. Bills             return;
34138e6c099aSJason M. Bills         }
34148e6c099aSJason M. Bills 
34158e6c099aSJason M. Bills         if (diagnosticDataType != "OEM")
34168e6c099aSJason M. Bills         {
34178e6c099aSJason M. Bills             BMCWEB_LOG_ERROR
34188e6c099aSJason M. Bills                 << "Only OEM DiagnosticDataType supported for Crashdump";
34198e6c099aSJason M. Bills             messages::actionParameterValueFormatError(
34208e6c099aSJason M. Bills                 asyncResp->res, diagnosticDataType, "DiagnosticDataType",
34218e6c099aSJason M. Bills                 "CollectDiagnosticData");
34228e6c099aSJason M. Bills             return;
34238e6c099aSJason M. Bills         }
34248e6c099aSJason M. Bills 
3425c5a4c82aSJason M. Bills         OEMDiagnosticType oemDiagType =
3426c5a4c82aSJason M. Bills             getOEMDiagnosticType(oemDiagnosticDataType);
3427c5a4c82aSJason M. Bills 
3428c5a4c82aSJason M. Bills         std::string iface;
3429c5a4c82aSJason M. Bills         std::string method;
3430c5a4c82aSJason M. Bills         std::string taskMatchStr;
3431c5a4c82aSJason M. Bills         if (oemDiagType == OEMDiagnosticType::onDemand)
3432c5a4c82aSJason M. Bills         {
3433c5a4c82aSJason M. Bills             iface = crashdumpOnDemandInterface;
3434c5a4c82aSJason M. Bills             method = "GenerateOnDemandLog";
3435c5a4c82aSJason M. Bills             taskMatchStr = "type='signal',"
3436c5a4c82aSJason M. Bills                            "interface='org.freedesktop.DBus.Properties',"
3437c5a4c82aSJason M. Bills                            "member='PropertiesChanged',"
3438c5a4c82aSJason M. Bills                            "arg0namespace='com.intel.crashdump'";
3439c5a4c82aSJason M. Bills         }
3440c5a4c82aSJason M. Bills         else if (oemDiagType == OEMDiagnosticType::telemetry)
3441c5a4c82aSJason M. Bills         {
3442c5a4c82aSJason M. Bills             iface = crashdumpTelemetryInterface;
3443c5a4c82aSJason M. Bills             method = "GenerateTelemetryLog";
3444c5a4c82aSJason M. Bills             taskMatchStr = "type='signal',"
3445c5a4c82aSJason M. Bills                            "interface='org.freedesktop.DBus.Properties',"
3446c5a4c82aSJason M. Bills                            "member='PropertiesChanged',"
3447c5a4c82aSJason M. Bills                            "arg0namespace='com.intel.crashdump'";
3448c5a4c82aSJason M. Bills         }
3449c5a4c82aSJason M. Bills         else
3450c5a4c82aSJason M. Bills         {
3451c5a4c82aSJason M. Bills             BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: "
3452c5a4c82aSJason M. Bills                              << oemDiagnosticDataType;
3453c5a4c82aSJason M. Bills             messages::actionParameterValueFormatError(
3454002d39b4SEd Tanous                 asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType",
3455002d39b4SEd Tanous                 "CollectDiagnosticData");
3456c5a4c82aSJason M. Bills             return;
3457c5a4c82aSJason M. Bills         }
3458c5a4c82aSJason M. Bills 
3459c5a4c82aSJason M. Bills         auto collectCrashdumpCallback =
3460c5a4c82aSJason M. Bills             [asyncResp, payload(task::Payload(req)),
34615e7e2dc5SEd Tanous              taskMatchStr](const boost::system::error_code& ec,
346298be3e39SEd Tanous                            const std::string&) mutable {
34631da66f75SEd Tanous             if (ec)
34641da66f75SEd Tanous             {
3465002d39b4SEd Tanous                 if (ec.value() == boost::system::errc::operation_not_supported)
34661da66f75SEd Tanous                 {
3467f12894f8SJason M. Bills                     messages::resourceInStandby(asyncResp->res);
34681da66f75SEd Tanous                 }
34694363d3b2SJason M. Bills                 else if (ec.value() ==
34704363d3b2SJason M. Bills                          boost::system::errc::device_or_resource_busy)
34714363d3b2SJason M. Bills                 {
3472002d39b4SEd Tanous                     messages::serviceTemporarilyUnavailable(asyncResp->res,
3473002d39b4SEd Tanous                                                             "60");
34744363d3b2SJason M. Bills                 }
34751da66f75SEd Tanous                 else
34761da66f75SEd Tanous                 {
3477f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
34781da66f75SEd Tanous                 }
34791da66f75SEd Tanous                 return;
34801da66f75SEd Tanous             }
3481002d39b4SEd Tanous             std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
34825e7e2dc5SEd Tanous                 [](const boost::system::error_code& err, sdbusplus::message_t&,
3483002d39b4SEd Tanous                    const std::shared_ptr<task::TaskData>& taskData) {
348466afe4faSJames Feist                 if (!err)
348566afe4faSJames Feist                 {
3486002d39b4SEd Tanous                     taskData->messages.emplace_back(messages::taskCompletedOK(
3487e5d5006bSJames Feist                         std::to_string(taskData->index)));
3488831d6b09SJames Feist                     taskData->state = "Completed";
348966afe4faSJames Feist                 }
349032898ceaSJames Feist                 return task::completed;
349166afe4faSJames Feist                 },
3492c5a4c82aSJason M. Bills                 taskMatchStr);
3493c5a4c82aSJason M. Bills 
349446229577SJames Feist             task->startTimer(std::chrono::minutes(5));
349546229577SJames Feist             task->populateResp(asyncResp->res);
349698be3e39SEd Tanous             task->payload.emplace(std::move(payload));
34971da66f75SEd Tanous         };
34988e6c099aSJason M. Bills 
34991da66f75SEd Tanous         crow::connections::systemBus->async_method_call(
3500002d39b4SEd Tanous             std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath,
3501002d39b4SEd Tanous             iface, method);
35027e860f15SJohn Edward Broadbent         });
35036eda7685SKenny L. Ku }
35046eda7685SKenny L. Ku 
3505cb92c03bSAndrew Geissler /**
3506cb92c03bSAndrew Geissler  * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3507cb92c03bSAndrew Geissler  */
35087e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app)
3509cb92c03bSAndrew Geissler {
3510cb92c03bSAndrew Geissler     /**
3511cb92c03bSAndrew Geissler      * Function handles POST method request.
3512cb92c03bSAndrew Geissler      * The Clear Log actions does not require any parameter.The action deletes
3513cb92c03bSAndrew Geissler      * all entries found in the Entries collection for this Log Service.
3514cb92c03bSAndrew Geissler      */
35157e860f15SJohn Edward Broadbent 
35160fda0f12SGeorge Liu     BMCWEB_ROUTE(
35170fda0f12SGeorge Liu         app,
351822d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/")
3519ed398213SEd Tanous         .privileges(redfish::privileges::postLogService)
35207e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
352145ca1b86SEd Tanous             [&app](const crow::Request& req,
352222d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
352322d268cbSEd Tanous                    const std::string& systemName) {
35243ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
352545ca1b86SEd Tanous         {
352645ca1b86SEd Tanous             return;
352745ca1b86SEd Tanous         }
352822d268cbSEd Tanous         if (systemName != "system")
352922d268cbSEd Tanous         {
353022d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
353122d268cbSEd Tanous                                        systemName);
353222d268cbSEd Tanous             return;
353322d268cbSEd Tanous         }
3534cb92c03bSAndrew Geissler         BMCWEB_LOG_DEBUG << "Do delete all entries.";
3535cb92c03bSAndrew Geissler 
3536cb92c03bSAndrew Geissler         // Process response from Logging service.
35375e7e2dc5SEd Tanous         auto respHandler = [asyncResp](const boost::system::error_code& ec) {
3538002d39b4SEd Tanous             BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done";
3539cb92c03bSAndrew Geissler             if (ec)
3540cb92c03bSAndrew Geissler             {
3541cb92c03bSAndrew Geissler                 // TODO Handle for specific error code
3542002d39b4SEd Tanous                 BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec;
3543cb92c03bSAndrew Geissler                 asyncResp->res.result(
3544cb92c03bSAndrew Geissler                     boost::beast::http::status::internal_server_error);
3545cb92c03bSAndrew Geissler                 return;
3546cb92c03bSAndrew Geissler             }
3547cb92c03bSAndrew Geissler 
3548002d39b4SEd Tanous             asyncResp->res.result(boost::beast::http::status::no_content);
3549cb92c03bSAndrew Geissler         };
3550cb92c03bSAndrew Geissler 
3551cb92c03bSAndrew Geissler         // Make call to Logging service to request Clear Log
3552cb92c03bSAndrew Geissler         crow::connections::systemBus->async_method_call(
35532c70f800SEd Tanous             respHandler, "xyz.openbmc_project.Logging",
3554cb92c03bSAndrew Geissler             "/xyz/openbmc_project/logging",
3555cb92c03bSAndrew Geissler             "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
35567e860f15SJohn Edward Broadbent         });
3557cb92c03bSAndrew Geissler }
3558a3316fc6SZhikuiRen 
3559a3316fc6SZhikuiRen /****************************************************
3560a3316fc6SZhikuiRen  * Redfish PostCode interfaces
3561a3316fc6SZhikuiRen  * using DBUS interface: getPostCodesTS
3562a3316fc6SZhikuiRen  ******************************************************/
35637e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app)
3564a3316fc6SZhikuiRen {
356522d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/")
3566ed398213SEd Tanous         .privileges(redfish::privileges::getLogService)
3567002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
3568002d39b4SEd Tanous             [&app](const crow::Request& req,
356922d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
357022d268cbSEd Tanous                    const std::string& systemName) {
35713ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
357245ca1b86SEd Tanous         {
357345ca1b86SEd Tanous             return;
357445ca1b86SEd Tanous         }
357522d268cbSEd Tanous         if (systemName != "system")
357622d268cbSEd Tanous         {
357722d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
357822d268cbSEd Tanous                                        systemName);
357922d268cbSEd Tanous             return;
358022d268cbSEd Tanous         }
35811476687dSEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
35821476687dSEd Tanous             "/redfish/v1/Systems/system/LogServices/PostCodes";
35831476687dSEd Tanous         asyncResp->res.jsonValue["@odata.type"] =
35841476687dSEd Tanous             "#LogService.v1_1_0.LogService";
35851476687dSEd Tanous         asyncResp->res.jsonValue["Name"] = "POST Code Log Service";
35861476687dSEd Tanous         asyncResp->res.jsonValue["Description"] = "POST Code Log Service";
3587ed34a4adSEd Tanous         asyncResp->res.jsonValue["Id"] = "PostCodes";
35881476687dSEd Tanous         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
35891476687dSEd Tanous         asyncResp->res.jsonValue["Entries"]["@odata.id"] =
35901476687dSEd Tanous             "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
35917c8c4058STejas Patil 
35927c8c4058STejas Patil         std::pair<std::string, std::string> redfishDateTimeOffset =
35932b82937eSEd Tanous             redfish::time_utils::getDateTimeOffsetNow();
35940fda0f12SGeorge Liu         asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
35957c8c4058STejas Patil         asyncResp->res.jsonValue["DateTimeLocalOffset"] =
35967c8c4058STejas Patil             redfishDateTimeOffset.second;
35977c8c4058STejas Patil 
3598a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
35997e860f15SJohn Edward Broadbent             {"target",
36000fda0f12SGeorge Liu              "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog"}};
36017e860f15SJohn Edward Broadbent         });
3602a3316fc6SZhikuiRen }
3603a3316fc6SZhikuiRen 
36047e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app)
3605a3316fc6SZhikuiRen {
36060fda0f12SGeorge Liu     BMCWEB_ROUTE(
36070fda0f12SGeorge Liu         app,
360822d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/")
3609ed398213SEd Tanous         // The following privilege is incorrect;  It should be ConfigureManager
3610ed398213SEd Tanous         //.privileges(redfish::privileges::postLogService)
3611432a890cSEd Tanous         .privileges({{"ConfigureComponents"}})
36127e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::post)(
361345ca1b86SEd Tanous             [&app](const crow::Request& req,
361422d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
361522d268cbSEd Tanous                    const std::string& systemName) {
36163ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
361745ca1b86SEd Tanous         {
361845ca1b86SEd Tanous             return;
361945ca1b86SEd Tanous         }
362022d268cbSEd Tanous         if (systemName != "system")
362122d268cbSEd Tanous         {
362222d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
362322d268cbSEd Tanous                                        systemName);
362422d268cbSEd Tanous             return;
362522d268cbSEd Tanous         }
3626a3316fc6SZhikuiRen         BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
3627a3316fc6SZhikuiRen 
3628a3316fc6SZhikuiRen         // Make call to post-code service to request clear all
3629a3316fc6SZhikuiRen         crow::connections::systemBus->async_method_call(
36305e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec) {
3631a3316fc6SZhikuiRen             if (ec)
3632a3316fc6SZhikuiRen             {
3633a3316fc6SZhikuiRen                 // TODO Handle for specific error code
3634002d39b4SEd Tanous                 BMCWEB_LOG_ERROR << "doClearPostCodes resp_handler got error "
36357e860f15SJohn Edward Broadbent                                  << ec;
3636002d39b4SEd Tanous                 asyncResp->res.result(
3637002d39b4SEd Tanous                     boost::beast::http::status::internal_server_error);
3638a3316fc6SZhikuiRen                 messages::internalError(asyncResp->res);
3639a3316fc6SZhikuiRen                 return;
3640a3316fc6SZhikuiRen             }
3641a3316fc6SZhikuiRen             },
364215124765SJonathan Doman             "xyz.openbmc_project.State.Boot.PostCode0",
364315124765SJonathan Doman             "/xyz/openbmc_project/State/Boot/PostCode0",
3644a3316fc6SZhikuiRen             "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
36457e860f15SJohn Edward Broadbent         });
3646a3316fc6SZhikuiRen }
3647a3316fc6SZhikuiRen 
36486f284d24SJiaqing Zhao /**
36496f284d24SJiaqing Zhao  * @brief Parse post code ID and get the current value and index value
36506f284d24SJiaqing Zhao  *        eg: postCodeID=B1-2, currentValue=1, index=2
36516f284d24SJiaqing Zhao  *
36526f284d24SJiaqing Zhao  * @param[in]  postCodeID     Post Code ID
36536f284d24SJiaqing Zhao  * @param[out] currentValue   Current value
36546f284d24SJiaqing Zhao  * @param[out] index          Index value
36556f284d24SJiaqing Zhao  *
36566f284d24SJiaqing Zhao  * @return bool true if the parsing is successful, false the parsing fails
36576f284d24SJiaqing Zhao  */
36586f284d24SJiaqing Zhao inline static bool parsePostCode(const std::string& postCodeID,
36596f284d24SJiaqing Zhao                                  uint64_t& currentValue, uint16_t& index)
36606f284d24SJiaqing Zhao {
36616f284d24SJiaqing Zhao     std::vector<std::string> split;
366250ebd4afSEd Tanous     bmcweb::split(split, postCodeID, '-');
36636f284d24SJiaqing Zhao     if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B')
36646f284d24SJiaqing Zhao     {
36656f284d24SJiaqing Zhao         return false;
36666f284d24SJiaqing Zhao     }
36676f284d24SJiaqing Zhao 
36686f284d24SJiaqing Zhao     // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
36696f284d24SJiaqing Zhao     const char* start = split[0].data() + 1;
36706f284d24SJiaqing Zhao     // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
36716f284d24SJiaqing Zhao     const char* end = split[0].data() + split[0].size();
36726f284d24SJiaqing Zhao     auto [ptrIndex, ecIndex] = std::from_chars(start, end, index);
36736f284d24SJiaqing Zhao 
36746f284d24SJiaqing Zhao     if (ptrIndex != end || ecIndex != std::errc())
36756f284d24SJiaqing Zhao     {
36766f284d24SJiaqing Zhao         return false;
36776f284d24SJiaqing Zhao     }
36786f284d24SJiaqing Zhao 
36796f284d24SJiaqing Zhao     start = split[1].data();
36806f284d24SJiaqing Zhao 
36816f284d24SJiaqing Zhao     // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
36826f284d24SJiaqing Zhao     end = split[1].data() + split[1].size();
36836f284d24SJiaqing Zhao     auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue);
36846f284d24SJiaqing Zhao 
36856f284d24SJiaqing Zhao     return ptrValue == end && ecValue == std::errc();
36866f284d24SJiaqing Zhao }
36876f284d24SJiaqing Zhao 
36886f284d24SJiaqing Zhao static bool fillPostCodeEntry(
36898d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& aResp,
36906c9a279eSManojkiran Eda     const boost::container::flat_map<
36916c9a279eSManojkiran Eda         uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode,
3692a3316fc6SZhikuiRen     const uint16_t bootIndex, const uint64_t codeIndex = 0,
3693a3316fc6SZhikuiRen     const uint64_t skip = 0, const uint64_t top = 0)
3694a3316fc6SZhikuiRen {
3695a3316fc6SZhikuiRen     // Get the Message from the MessageRegistry
3696fffb8c1fSEd Tanous     const registries::Message* message =
3697fffb8c1fSEd Tanous         registries::getMessage("OpenBMC.0.2.BIOSPOSTCode");
3698a3316fc6SZhikuiRen 
3699a3316fc6SZhikuiRen     uint64_t currentCodeIndex = 0;
3700a3316fc6SZhikuiRen     uint64_t firstCodeTimeUs = 0;
37016c9a279eSManojkiran Eda     for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
37026c9a279eSManojkiran Eda              code : postcode)
3703a3316fc6SZhikuiRen     {
3704a3316fc6SZhikuiRen         currentCodeIndex++;
3705a3316fc6SZhikuiRen         std::string postcodeEntryID =
3706a3316fc6SZhikuiRen             "B" + std::to_string(bootIndex) + "-" +
3707a3316fc6SZhikuiRen             std::to_string(currentCodeIndex); // 1 based index in EntryID string
3708a3316fc6SZhikuiRen 
3709a3316fc6SZhikuiRen         uint64_t usecSinceEpoch = code.first;
3710a3316fc6SZhikuiRen         uint64_t usTimeOffset = 0;
3711a3316fc6SZhikuiRen 
3712a3316fc6SZhikuiRen         if (1 == currentCodeIndex)
3713a3316fc6SZhikuiRen         { // already incremented
3714a3316fc6SZhikuiRen             firstCodeTimeUs = code.first;
3715a3316fc6SZhikuiRen         }
3716a3316fc6SZhikuiRen         else
3717a3316fc6SZhikuiRen         {
3718a3316fc6SZhikuiRen             usTimeOffset = code.first - firstCodeTimeUs;
3719a3316fc6SZhikuiRen         }
3720a3316fc6SZhikuiRen 
3721a3316fc6SZhikuiRen         // skip if no specific codeIndex is specified and currentCodeIndex does
3722a3316fc6SZhikuiRen         // not fall between top and skip
3723a3316fc6SZhikuiRen         if ((codeIndex == 0) &&
3724a3316fc6SZhikuiRen             (currentCodeIndex <= skip || currentCodeIndex > top))
3725a3316fc6SZhikuiRen         {
3726a3316fc6SZhikuiRen             continue;
3727a3316fc6SZhikuiRen         }
3728a3316fc6SZhikuiRen 
37294e0453b1SGunnar Mills         // skip if a specific codeIndex is specified and does not match the
3730a3316fc6SZhikuiRen         // currentIndex
3731a3316fc6SZhikuiRen         if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3732a3316fc6SZhikuiRen         {
3733a3316fc6SZhikuiRen             // This is done for simplicity. 1st entry is needed to calculate
3734a3316fc6SZhikuiRen             // time offset. To improve efficiency, one can get to the entry
3735a3316fc6SZhikuiRen             // directly (possibly with flatmap's nth method)
3736a3316fc6SZhikuiRen             continue;
3737a3316fc6SZhikuiRen         }
3738a3316fc6SZhikuiRen 
3739a3316fc6SZhikuiRen         // currentCodeIndex is within top and skip or equal to specified code
3740a3316fc6SZhikuiRen         // index
3741a3316fc6SZhikuiRen 
3742a3316fc6SZhikuiRen         // Get the Created time from the timestamp
3743a3316fc6SZhikuiRen         std::string entryTimeStr;
37442a025611SKonstantin Aladyshev         entryTimeStr = redfish::time_utils::getDateTimeUintUs(usecSinceEpoch);
3745a3316fc6SZhikuiRen 
3746a3316fc6SZhikuiRen         // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3747a3316fc6SZhikuiRen         std::ostringstream hexCode;
3748a3316fc6SZhikuiRen         hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
37496c9a279eSManojkiran Eda                 << std::get<0>(code.second);
3750a3316fc6SZhikuiRen         std::ostringstream timeOffsetStr;
3751a3316fc6SZhikuiRen         // Set Fixed -Point Notation
3752a3316fc6SZhikuiRen         timeOffsetStr << std::fixed;
3753a3316fc6SZhikuiRen         // Set precision to 4 digits
3754a3316fc6SZhikuiRen         timeOffsetStr << std::setprecision(4);
3755a3316fc6SZhikuiRen         // Add double to stream
3756a3316fc6SZhikuiRen         timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3757a3316fc6SZhikuiRen         std::vector<std::string> messageArgs = {
3758a3316fc6SZhikuiRen             std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()};
3759a3316fc6SZhikuiRen 
3760a3316fc6SZhikuiRen         // Get MessageArgs template from message registry
3761a3316fc6SZhikuiRen         std::string msg;
3762a3316fc6SZhikuiRen         if (message != nullptr)
3763a3316fc6SZhikuiRen         {
3764a3316fc6SZhikuiRen             msg = message->message;
3765a3316fc6SZhikuiRen 
3766a3316fc6SZhikuiRen             // fill in this post code value
3767a3316fc6SZhikuiRen             int i = 0;
3768a3316fc6SZhikuiRen             for (const std::string& messageArg : messageArgs)
3769a3316fc6SZhikuiRen             {
3770a3316fc6SZhikuiRen                 std::string argStr = "%" + std::to_string(++i);
3771a3316fc6SZhikuiRen                 size_t argPos = msg.find(argStr);
3772a3316fc6SZhikuiRen                 if (argPos != std::string::npos)
3773a3316fc6SZhikuiRen                 {
3774a3316fc6SZhikuiRen                     msg.replace(argPos, argStr.length(), messageArg);
3775a3316fc6SZhikuiRen                 }
3776a3316fc6SZhikuiRen             }
3777a3316fc6SZhikuiRen         }
3778a3316fc6SZhikuiRen 
3779d4342a92STim Lee         // Get Severity template from message registry
3780d4342a92STim Lee         std::string severity;
3781d4342a92STim Lee         if (message != nullptr)
3782d4342a92STim Lee         {
37835f2b84eeSEd Tanous             severity = message->messageSeverity;
3784d4342a92STim Lee         }
3785d4342a92STim Lee 
37866f284d24SJiaqing Zhao         // Format entry
37876f284d24SJiaqing Zhao         nlohmann::json::object_t bmcLogEntry;
37889c11a172SVijay Lobo         bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
3789eddfc437SWilly Tu         bmcLogEntry["@odata.id"] = crow::utility::urlFromPieces(
3790eddfc437SWilly Tu             "redfish", "v1", "Systems", "system", "LogServices", "PostCodes",
3791eddfc437SWilly Tu             "Entries", postcodeEntryID);
379284afc48bSJason M. Bills         bmcLogEntry["Name"] = "POST Code Log Entry";
379384afc48bSJason M. Bills         bmcLogEntry["Id"] = postcodeEntryID;
379484afc48bSJason M. Bills         bmcLogEntry["Message"] = std::move(msg);
379584afc48bSJason M. Bills         bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode";
379684afc48bSJason M. Bills         bmcLogEntry["MessageArgs"] = std::move(messageArgs);
379784afc48bSJason M. Bills         bmcLogEntry["EntryType"] = "Event";
379884afc48bSJason M. Bills         bmcLogEntry["Severity"] = std::move(severity);
379984afc48bSJason M. Bills         bmcLogEntry["Created"] = entryTimeStr;
3800647b3cdcSGeorge Liu         if (!std::get<std::vector<uint8_t>>(code.second).empty())
3801647b3cdcSGeorge Liu         {
3802647b3cdcSGeorge Liu             bmcLogEntry["AdditionalDataURI"] =
3803647b3cdcSGeorge Liu                 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" +
3804647b3cdcSGeorge Liu                 postcodeEntryID + "/attachment";
3805647b3cdcSGeorge Liu         }
38066f284d24SJiaqing Zhao 
38076f284d24SJiaqing Zhao         // codeIndex is only specified when querying single entry, return only
38086f284d24SJiaqing Zhao         // that entry in this case
38096f284d24SJiaqing Zhao         if (codeIndex != 0)
38106f284d24SJiaqing Zhao         {
38116f284d24SJiaqing Zhao             aResp->res.jsonValue.update(bmcLogEntry);
38126f284d24SJiaqing Zhao             return true;
3813a3316fc6SZhikuiRen         }
38146f284d24SJiaqing Zhao 
38156f284d24SJiaqing Zhao         nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"];
38166f284d24SJiaqing Zhao         logEntryArray.push_back(std::move(bmcLogEntry));
38176f284d24SJiaqing Zhao     }
38186f284d24SJiaqing Zhao 
38196f284d24SJiaqing Zhao     // Return value is always false when querying multiple entries
38206f284d24SJiaqing Zhao     return false;
3821a3316fc6SZhikuiRen }
3822a3316fc6SZhikuiRen 
38238d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
38246f284d24SJiaqing Zhao                                 const std::string& entryId)
3825a3316fc6SZhikuiRen {
38266f284d24SJiaqing Zhao     uint16_t bootIndex = 0;
38276f284d24SJiaqing Zhao     uint64_t codeIndex = 0;
38286f284d24SJiaqing Zhao     if (!parsePostCode(entryId, codeIndex, bootIndex))
38296f284d24SJiaqing Zhao     {
38306f284d24SJiaqing Zhao         // Requested ID was not found
38316f284d24SJiaqing Zhao         messages::resourceNotFound(aResp->res, "LogEntry", entryId);
38326f284d24SJiaqing Zhao         return;
38336f284d24SJiaqing Zhao     }
38346f284d24SJiaqing Zhao 
38356f284d24SJiaqing Zhao     if (bootIndex == 0 || codeIndex == 0)
38366f284d24SJiaqing Zhao     {
38376f284d24SJiaqing Zhao         // 0 is an invalid index
38386f284d24SJiaqing Zhao         messages::resourceNotFound(aResp->res, "LogEntry", entryId);
38396f284d24SJiaqing Zhao         return;
38406f284d24SJiaqing Zhao     }
38416f284d24SJiaqing Zhao 
3842a3316fc6SZhikuiRen     crow::connections::systemBus->async_method_call(
38436f284d24SJiaqing Zhao         [aResp, entryId, bootIndex,
38445e7e2dc5SEd Tanous          codeIndex](const boost::system::error_code& ec,
38456c9a279eSManojkiran Eda                     const boost::container::flat_map<
38466c9a279eSManojkiran Eda                         uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
38476c9a279eSManojkiran Eda                         postcode) {
3848a3316fc6SZhikuiRen         if (ec)
3849a3316fc6SZhikuiRen         {
3850a3316fc6SZhikuiRen             BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3851a3316fc6SZhikuiRen             messages::internalError(aResp->res);
3852a3316fc6SZhikuiRen             return;
3853a3316fc6SZhikuiRen         }
3854a3316fc6SZhikuiRen 
3855a3316fc6SZhikuiRen         if (postcode.empty())
3856a3316fc6SZhikuiRen         {
38576f284d24SJiaqing Zhao             messages::resourceNotFound(aResp->res, "LogEntry", entryId);
3858a3316fc6SZhikuiRen             return;
3859a3316fc6SZhikuiRen         }
3860a3316fc6SZhikuiRen 
38616f284d24SJiaqing Zhao         if (!fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex))
38626f284d24SJiaqing Zhao         {
38636f284d24SJiaqing Zhao             messages::resourceNotFound(aResp->res, "LogEntry", entryId);
38646f284d24SJiaqing Zhao             return;
38656f284d24SJiaqing Zhao         }
3866a3316fc6SZhikuiRen         },
386715124765SJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode0",
386815124765SJonathan Doman         "/xyz/openbmc_project/State/Boot/PostCode0",
3869a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3870a3316fc6SZhikuiRen         bootIndex);
3871a3316fc6SZhikuiRen }
3872a3316fc6SZhikuiRen 
38738d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
3874a3316fc6SZhikuiRen                                const uint16_t bootIndex,
3875a3316fc6SZhikuiRen                                const uint16_t bootCount,
38763648c8beSEd Tanous                                const uint64_t entryCount, size_t skip,
38773648c8beSEd Tanous                                size_t top)
3878a3316fc6SZhikuiRen {
3879a3316fc6SZhikuiRen     crow::connections::systemBus->async_method_call(
3880a3316fc6SZhikuiRen         [aResp, bootIndex, bootCount, entryCount, skip,
38815e7e2dc5SEd Tanous          top](const boost::system::error_code& ec,
38826c9a279eSManojkiran Eda               const boost::container::flat_map<
38836c9a279eSManojkiran Eda                   uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
38846c9a279eSManojkiran Eda                   postcode) {
3885a3316fc6SZhikuiRen         if (ec)
3886a3316fc6SZhikuiRen         {
3887a3316fc6SZhikuiRen             BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3888a3316fc6SZhikuiRen             messages::internalError(aResp->res);
3889a3316fc6SZhikuiRen             return;
3890a3316fc6SZhikuiRen         }
3891a3316fc6SZhikuiRen 
3892a3316fc6SZhikuiRen         uint64_t endCount = entryCount;
3893a3316fc6SZhikuiRen         if (!postcode.empty())
3894a3316fc6SZhikuiRen         {
3895a3316fc6SZhikuiRen             endCount = entryCount + postcode.size();
38963648c8beSEd Tanous             if (skip < endCount && (top + skip) > entryCount)
3897a3316fc6SZhikuiRen             {
38983648c8beSEd Tanous                 uint64_t thisBootSkip =
38993648c8beSEd Tanous                     std::max(static_cast<uint64_t>(skip), entryCount) -
39003648c8beSEd Tanous                     entryCount;
3901a3316fc6SZhikuiRen                 uint64_t thisBootTop =
39023648c8beSEd Tanous                     std::min(static_cast<uint64_t>(top + skip), endCount) -
39033648c8beSEd Tanous                     entryCount;
3904a3316fc6SZhikuiRen 
3905002d39b4SEd Tanous                 fillPostCodeEntry(aResp, postcode, bootIndex, 0, thisBootSkip,
3906002d39b4SEd Tanous                                   thisBootTop);
3907a3316fc6SZhikuiRen             }
3908a3316fc6SZhikuiRen             aResp->res.jsonValue["Members@odata.count"] = endCount;
3909a3316fc6SZhikuiRen         }
3910a3316fc6SZhikuiRen 
3911a3316fc6SZhikuiRen         // continue to previous bootIndex
3912a3316fc6SZhikuiRen         if (bootIndex < bootCount)
3913a3316fc6SZhikuiRen         {
3914a3316fc6SZhikuiRen             getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1),
3915a3316fc6SZhikuiRen                                bootCount, endCount, skip, top);
3916a3316fc6SZhikuiRen         }
391781584abeSJiaqing Zhao         else if (skip + top < endCount)
3918a3316fc6SZhikuiRen         {
3919a3316fc6SZhikuiRen             aResp->res.jsonValue["Members@odata.nextLink"] =
39200fda0f12SGeorge Liu                 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries?$skip=" +
3921a3316fc6SZhikuiRen                 std::to_string(skip + top);
3922a3316fc6SZhikuiRen         }
3923a3316fc6SZhikuiRen         },
392415124765SJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode0",
392515124765SJonathan Doman         "/xyz/openbmc_project/State/Boot/PostCode0",
3926a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3927a3316fc6SZhikuiRen         bootIndex);
3928a3316fc6SZhikuiRen }
3929a3316fc6SZhikuiRen 
39308d1b46d7Szhanghch05 static void
39318d1b46d7Szhanghch05     getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
39323648c8beSEd Tanous                          size_t skip, size_t top)
3933a3316fc6SZhikuiRen {
3934a3316fc6SZhikuiRen     uint64_t entryCount = 0;
39351e1e598dSJonathan Doman     sdbusplus::asio::getProperty<uint16_t>(
39361e1e598dSJonathan Doman         *crow::connections::systemBus,
39371e1e598dSJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode0",
39381e1e598dSJonathan Doman         "/xyz/openbmc_project/State/Boot/PostCode0",
39391e1e598dSJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount",
39405e7e2dc5SEd Tanous         [aResp, entryCount, skip, top](const boost::system::error_code& ec,
39411e1e598dSJonathan Doman                                        const uint16_t bootCount) {
3942a3316fc6SZhikuiRen         if (ec)
3943a3316fc6SZhikuiRen         {
3944a3316fc6SZhikuiRen             BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
3945a3316fc6SZhikuiRen             messages::internalError(aResp->res);
3946a3316fc6SZhikuiRen             return;
3947a3316fc6SZhikuiRen         }
39481e1e598dSJonathan Doman         getPostCodeForBoot(aResp, 1, bootCount, entryCount, skip, top);
39491e1e598dSJonathan Doman         });
3950a3316fc6SZhikuiRen }
3951a3316fc6SZhikuiRen 
39527e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app)
3953a3316fc6SZhikuiRen {
39547e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
395522d268cbSEd Tanous                  "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/")
3956ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntryCollection)
39577e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
395845ca1b86SEd Tanous             [&app](const crow::Request& req,
395922d268cbSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
396022d268cbSEd Tanous                    const std::string& systemName) {
3961c937d2bfSEd Tanous         query_param::QueryCapabilities capabilities = {
3962c937d2bfSEd Tanous             .canDelegateTop = true,
3963c937d2bfSEd Tanous             .canDelegateSkip = true,
3964c937d2bfSEd Tanous         };
3965c937d2bfSEd Tanous         query_param::Query delegatedQuery;
3966c937d2bfSEd Tanous         if (!redfish::setUpRedfishRouteWithDelegation(
39673ba00073SCarson Labrado                 app, req, asyncResp, delegatedQuery, capabilities))
396845ca1b86SEd Tanous         {
396945ca1b86SEd Tanous             return;
397045ca1b86SEd Tanous         }
397122d268cbSEd Tanous 
397222d268cbSEd Tanous         if (systemName != "system")
397322d268cbSEd Tanous         {
397422d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
397522d268cbSEd Tanous                                        systemName);
397622d268cbSEd Tanous             return;
397722d268cbSEd Tanous         }
3978a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.type"] =
3979a3316fc6SZhikuiRen             "#LogEntryCollection.LogEntryCollection";
3980a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.id"] =
3981a3316fc6SZhikuiRen             "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
3982a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3983a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Description"] =
3984a3316fc6SZhikuiRen             "Collection of POST Code Log Entries";
3985a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3986a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members@odata.count"] = 0;
39873648c8beSEd Tanous         size_t skip = delegatedQuery.skip.value_or(0);
39885143f7a5SJiaqing Zhao         size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
39893648c8beSEd Tanous         getCurrentBootNumber(asyncResp, skip, top);
39907e860f15SJohn Edward Broadbent         });
3991a3316fc6SZhikuiRen }
3992a3316fc6SZhikuiRen 
3993647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app)
3994647b3cdcSGeorge Liu {
39950fda0f12SGeorge Liu     BMCWEB_ROUTE(
39960fda0f12SGeorge Liu         app,
399722d268cbSEd Tanous         "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/")
3998647b3cdcSGeorge Liu         .privileges(redfish::privileges::getLogEntry)
3999647b3cdcSGeorge Liu         .methods(boost::beast::http::verb::get)(
400045ca1b86SEd Tanous             [&app](const crow::Request& req,
4001647b3cdcSGeorge Liu                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
400222d268cbSEd Tanous                    const std::string& systemName,
4003647b3cdcSGeorge Liu                    const std::string& postCodeID) {
40043ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
400545ca1b86SEd Tanous         {
400645ca1b86SEd Tanous             return;
400745ca1b86SEd Tanous         }
400899351cd8SEd Tanous         if (http_helpers::isContentTypeAllowed(
400999351cd8SEd Tanous                 req.getHeaderValue("Accept"),
40104a0e1a0cSEd Tanous                 http_helpers::ContentType::OctetStream, true))
4011647b3cdcSGeorge Liu         {
4012002d39b4SEd Tanous             asyncResp->res.result(boost::beast::http::status::bad_request);
4013647b3cdcSGeorge Liu             return;
4014647b3cdcSGeorge Liu         }
401522d268cbSEd Tanous         if (systemName != "system")
401622d268cbSEd Tanous         {
401722d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
401822d268cbSEd Tanous                                        systemName);
401922d268cbSEd Tanous             return;
402022d268cbSEd Tanous         }
4021647b3cdcSGeorge Liu 
4022647b3cdcSGeorge Liu         uint64_t currentValue = 0;
4023647b3cdcSGeorge Liu         uint16_t index = 0;
4024647b3cdcSGeorge Liu         if (!parsePostCode(postCodeID, currentValue, index))
4025647b3cdcSGeorge Liu         {
4026002d39b4SEd Tanous             messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID);
4027647b3cdcSGeorge Liu             return;
4028647b3cdcSGeorge Liu         }
4029647b3cdcSGeorge Liu 
4030647b3cdcSGeorge Liu         crow::connections::systemBus->async_method_call(
4031647b3cdcSGeorge Liu             [asyncResp, postCodeID, currentValue](
40325e7e2dc5SEd Tanous                 const boost::system::error_code& ec,
4033002d39b4SEd Tanous                 const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>&
4034002d39b4SEd Tanous                     postcodes) {
4035647b3cdcSGeorge Liu             if (ec.value() == EBADR)
4036647b3cdcSGeorge Liu             {
4037002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "LogEntry",
4038002d39b4SEd Tanous                                            postCodeID);
4039647b3cdcSGeorge Liu                 return;
4040647b3cdcSGeorge Liu             }
4041647b3cdcSGeorge Liu             if (ec)
4042647b3cdcSGeorge Liu             {
4043647b3cdcSGeorge Liu                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
4044647b3cdcSGeorge Liu                 messages::internalError(asyncResp->res);
4045647b3cdcSGeorge Liu                 return;
4046647b3cdcSGeorge Liu             }
4047647b3cdcSGeorge Liu 
4048647b3cdcSGeorge Liu             size_t value = static_cast<size_t>(currentValue) - 1;
4049002d39b4SEd Tanous             if (value == std::string::npos || postcodes.size() < currentValue)
4050647b3cdcSGeorge Liu             {
4051*a7405d5fSGunnar Mills                 BMCWEB_LOG_WARNING << "Wrong currentValue value";
4052002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "LogEntry",
4053002d39b4SEd Tanous                                            postCodeID);
4054647b3cdcSGeorge Liu                 return;
4055647b3cdcSGeorge Liu             }
4056647b3cdcSGeorge Liu 
40579eb808c1SEd Tanous             const auto& [tID, c] = postcodes[value];
405846ff87baSEd Tanous             if (c.empty())
4059647b3cdcSGeorge Liu             {
4060*a7405d5fSGunnar Mills                 BMCWEB_LOG_WARNING << "No found post code data";
4061002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "LogEntry",
4062002d39b4SEd Tanous                                            postCodeID);
4063647b3cdcSGeorge Liu                 return;
4064647b3cdcSGeorge Liu             }
406546ff87baSEd Tanous             // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
406646ff87baSEd Tanous             const char* d = reinterpret_cast<const char*>(c.data());
406746ff87baSEd Tanous             std::string_view strData(d, c.size());
4068647b3cdcSGeorge Liu 
4069d9f6c621SEd Tanous             asyncResp->res.addHeader(boost::beast::http::field::content_type,
4070647b3cdcSGeorge Liu                                      "application/octet-stream");
4071d9f6c621SEd Tanous             asyncResp->res.addHeader(
4072d9f6c621SEd Tanous                 boost::beast::http::field::content_transfer_encoding, "Base64");
4073002d39b4SEd Tanous             asyncResp->res.body() = crow::utility::base64encode(strData);
4074647b3cdcSGeorge Liu             },
4075647b3cdcSGeorge Liu             "xyz.openbmc_project.State.Boot.PostCode0",
4076647b3cdcSGeorge Liu             "/xyz/openbmc_project/State/Boot/PostCode0",
4077002d39b4SEd Tanous             "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index);
4078647b3cdcSGeorge Liu         });
4079647b3cdcSGeorge Liu }
4080647b3cdcSGeorge Liu 
40817e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app)
4082a3316fc6SZhikuiRen {
40837e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(
408422d268cbSEd Tanous         app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/")
4085ed398213SEd Tanous         .privileges(redfish::privileges::getLogEntry)
40867e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
408745ca1b86SEd Tanous             [&app](const crow::Request& req,
40887e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
408922d268cbSEd Tanous                    const std::string& systemName, const std::string& targetID) {
40903ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
409145ca1b86SEd Tanous         {
409245ca1b86SEd Tanous             return;
409345ca1b86SEd Tanous         }
409422d268cbSEd Tanous         if (systemName != "system")
409522d268cbSEd Tanous         {
409622d268cbSEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
409722d268cbSEd Tanous                                        systemName);
409822d268cbSEd Tanous             return;
409922d268cbSEd Tanous         }
410022d268cbSEd Tanous 
41016f284d24SJiaqing Zhao         getPostCodeForEntry(asyncResp, targetID);
41027e860f15SJohn Edward Broadbent         });
4103a3316fc6SZhikuiRen }
4104a3316fc6SZhikuiRen 
41051da66f75SEd Tanous } // namespace redfish
4106