xref: /openbmc/bmcweb/features/redfish/lib/log_services.hpp (revision f86bb901bf02b65ed25bc4545aaebe0f4dc891b3)
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 
181da66f75SEd Tanous #include "node.hpp"
194851d45dSJason M. Bills #include "registries.hpp"
204851d45dSJason M. Bills #include "registries/base_message_registry.hpp"
214851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp"
2246229577SJames Feist #include "task.hpp"
231da66f75SEd Tanous 
24e1f26343SJason M. Bills #include <systemd/sd-journal.h>
25e1f26343SJason M. Bills 
264851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp>
274851d45dSJason M. Bills #include <boost/beast/core/span.hpp>
281da66f75SEd Tanous #include <boost/container/flat_map.hpp>
291ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp>
30cb92c03bSAndrew Geissler #include <error_messages.hpp>
311214b7e7SGunnar Mills 
324418c7f0SJames Feist #include <filesystem>
3375710de2SXiaochao Ma #include <optional>
34cd225da8SJason M. Bills #include <string_view>
35abf2add6SEd Tanous #include <variant>
361da66f75SEd Tanous 
371da66f75SEd Tanous namespace redfish
381da66f75SEd Tanous {
391da66f75SEd Tanous 
405b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump";
415b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump";
425b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump";
435b61b5e8SJason M. Bills constexpr char const* deleteAllInterface =
445b61b5e8SJason M. Bills     "xyz.openbmc_project.Collection.DeleteAll";
455b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface =
46424c4176SJason M. Bills     "com.intel.crashdump.OnDemand";
475b61b5e8SJason M. Bills constexpr char const* crashdumpRawPECIInterface =
48424c4176SJason M. Bills     "com.intel.crashdump.SendRawPeci";
496eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface =
506eda7685SKenny L. Ku     "com.intel.crashdump.Telemetry";
511da66f75SEd Tanous 
524851d45dSJason M. Bills namespace message_registries
534851d45dSJason M. Bills {
544851d45dSJason M. Bills static const Message* getMessageFromRegistry(
554851d45dSJason M. Bills     const std::string& messageKey,
564851d45dSJason M. Bills     const boost::beast::span<const MessageEntry> registry)
574851d45dSJason M. Bills {
584851d45dSJason M. Bills     boost::beast::span<const MessageEntry>::const_iterator messageIt =
594851d45dSJason M. Bills         std::find_if(registry.cbegin(), registry.cend(),
604851d45dSJason M. Bills                      [&messageKey](const MessageEntry& messageEntry) {
614851d45dSJason M. Bills                          return !std::strcmp(messageEntry.first,
624851d45dSJason M. Bills                                              messageKey.c_str());
634851d45dSJason M. Bills                      });
644851d45dSJason M. Bills     if (messageIt != registry.cend())
654851d45dSJason M. Bills     {
664851d45dSJason M. Bills         return &messageIt->second;
674851d45dSJason M. Bills     }
684851d45dSJason M. Bills 
694851d45dSJason M. Bills     return nullptr;
704851d45dSJason M. Bills }
714851d45dSJason M. Bills 
724851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID)
734851d45dSJason M. Bills {
744851d45dSJason M. Bills     // Redfish MessageIds are in the form
754851d45dSJason M. Bills     // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
764851d45dSJason M. Bills     // the right Message
774851d45dSJason M. Bills     std::vector<std::string> fields;
784851d45dSJason M. Bills     fields.reserve(4);
794851d45dSJason M. Bills     boost::split(fields, messageID, boost::is_any_of("."));
804851d45dSJason M. Bills     std::string& registryName = fields[0];
814851d45dSJason M. Bills     std::string& messageKey = fields[3];
824851d45dSJason M. Bills 
834851d45dSJason M. Bills     // Find the right registry and check it for the MessageKey
844851d45dSJason M. Bills     if (std::string(base::header.registryPrefix) == registryName)
854851d45dSJason M. Bills     {
864851d45dSJason M. Bills         return getMessageFromRegistry(
874851d45dSJason M. Bills             messageKey, boost::beast::span<const MessageEntry>(base::registry));
884851d45dSJason M. Bills     }
894851d45dSJason M. Bills     if (std::string(openbmc::header.registryPrefix) == registryName)
904851d45dSJason M. Bills     {
914851d45dSJason M. Bills         return getMessageFromRegistry(
924851d45dSJason M. Bills             messageKey,
934851d45dSJason M. Bills             boost::beast::span<const MessageEntry>(openbmc::registry));
944851d45dSJason M. Bills     }
954851d45dSJason M. Bills     return nullptr;
964851d45dSJason M. Bills }
974851d45dSJason M. Bills } // namespace message_registries
984851d45dSJason M. Bills 
99f6150403SJames Feist namespace fs = std::filesystem;
1001da66f75SEd Tanous 
101cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map<
10219bd78d9SPatrick Williams     std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t,
103cb92c03bSAndrew Geissler                               int32_t, uint32_t, int64_t, uint64_t, double>>;
104cb92c03bSAndrew Geissler 
105cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map<
106cb92c03bSAndrew Geissler     sdbusplus::message::object_path,
107cb92c03bSAndrew Geissler     boost::container::flat_map<std::string, GetManagedPropertyType>>;
108cb92c03bSAndrew Geissler 
109cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s)
110cb92c03bSAndrew Geissler {
111d4d25793SEd Tanous     if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
112d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
113d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
114d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
115cb92c03bSAndrew Geissler     {
116cb92c03bSAndrew Geissler         return "Critical";
117cb92c03bSAndrew Geissler     }
1183174e4dfSEd Tanous     if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
119d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
120d4d25793SEd Tanous         (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
121cb92c03bSAndrew Geissler     {
122cb92c03bSAndrew Geissler         return "OK";
123cb92c03bSAndrew Geissler     }
1243174e4dfSEd Tanous     if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
125cb92c03bSAndrew Geissler     {
126cb92c03bSAndrew Geissler         return "Warning";
127cb92c03bSAndrew Geissler     }
128cb92c03bSAndrew Geissler     return "";
129cb92c03bSAndrew Geissler }
130cb92c03bSAndrew Geissler 
13116428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal,
13239e77504SEd Tanous                               const std::string_view& field,
13339e77504SEd Tanous                               std::string_view& contents)
13416428a1aSJason M. Bills {
13516428a1aSJason M. Bills     const char* data = nullptr;
13616428a1aSJason M. Bills     size_t length = 0;
13716428a1aSJason M. Bills     int ret = 0;
13816428a1aSJason M. Bills     // Get the metadata from the requested field of the journal entry
139271584abSEd Tanous     ret = sd_journal_get_data(journal, field.data(),
140271584abSEd Tanous                               reinterpret_cast<const void**>(&data), &length);
14116428a1aSJason M. Bills     if (ret < 0)
14216428a1aSJason M. Bills     {
14316428a1aSJason M. Bills         return ret;
14416428a1aSJason M. Bills     }
14539e77504SEd Tanous     contents = std::string_view(data, length);
14616428a1aSJason M. Bills     // Only use the content after the "=" character.
14781ce609eSEd Tanous     contents.remove_prefix(std::min(contents.find('=') + 1, contents.size()));
14816428a1aSJason M. Bills     return ret;
14916428a1aSJason M. Bills }
15016428a1aSJason M. Bills 
15116428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal,
15239e77504SEd Tanous                               const std::string_view& field, const int& base,
153271584abSEd Tanous                               long int& contents)
15416428a1aSJason M. Bills {
15516428a1aSJason M. Bills     int ret = 0;
15639e77504SEd Tanous     std::string_view metadata;
15716428a1aSJason M. Bills     // Get the metadata from the requested field of the journal entry
15816428a1aSJason M. Bills     ret = getJournalMetadata(journal, field, metadata);
15916428a1aSJason M. Bills     if (ret < 0)
16016428a1aSJason M. Bills     {
16116428a1aSJason M. Bills         return ret;
16216428a1aSJason M. Bills     }
163b01bf299SEd Tanous     contents = strtol(metadata.data(), nullptr, base);
16416428a1aSJason M. Bills     return ret;
16516428a1aSJason M. Bills }
16616428a1aSJason M. Bills 
167a3316fc6SZhikuiRen static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp)
168a3316fc6SZhikuiRen {
169a3316fc6SZhikuiRen     int ret = 0;
170a3316fc6SZhikuiRen     uint64_t timestamp = 0;
171a3316fc6SZhikuiRen     ret = sd_journal_get_realtime_usec(journal, &timestamp);
172a3316fc6SZhikuiRen     if (ret < 0)
173a3316fc6SZhikuiRen     {
174a3316fc6SZhikuiRen         BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
175a3316fc6SZhikuiRen                          << strerror(-ret);
176a3316fc6SZhikuiRen         return false;
177a3316fc6SZhikuiRen     }
1789c620e21SAsmitha Karunanithi     entryTimestamp = crow::utility::getDateTime(
1799c620e21SAsmitha Karunanithi         static_cast<std::time_t>(timestamp / 1000 / 1000));
1809c620e21SAsmitha Karunanithi     return true;
181a3316fc6SZhikuiRen }
182a3316fc6SZhikuiRen 
18316428a1aSJason M. Bills static bool getSkipParam(crow::Response& res, const crow::Request& req,
184271584abSEd Tanous                          uint64_t& skip)
18516428a1aSJason M. Bills {
1865a7e877eSJames Feist     boost::urls::url_view::params_type::iterator it =
1875a7e877eSJames Feist         req.urlParams.find("$skip");
1885a7e877eSJames Feist     if (it != req.urlParams.end())
18916428a1aSJason M. Bills     {
1905a7e877eSJames Feist         std::string skipParam = it->value();
19116428a1aSJason M. Bills         char* ptr = nullptr;
1925a7e877eSJames Feist         skip = std::strtoul(skipParam.c_str(), &ptr, 10);
1935a7e877eSJames Feist         if (skipParam.empty() || *ptr != '\0')
19416428a1aSJason M. Bills         {
19516428a1aSJason M. Bills 
19616428a1aSJason M. Bills             messages::queryParameterValueTypeError(res, std::string(skipParam),
19716428a1aSJason M. Bills                                                    "$skip");
19816428a1aSJason M. Bills             return false;
19916428a1aSJason M. Bills         }
20016428a1aSJason M. Bills     }
20116428a1aSJason M. Bills     return true;
20216428a1aSJason M. Bills }
20316428a1aSJason M. Bills 
204271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000;
20516428a1aSJason M. Bills static bool getTopParam(crow::Response& res, const crow::Request& req,
206271584abSEd Tanous                         uint64_t& top)
20716428a1aSJason M. Bills {
2085a7e877eSJames Feist     boost::urls::url_view::params_type::iterator it =
2095a7e877eSJames Feist         req.urlParams.find("$top");
2105a7e877eSJames Feist     if (it != req.urlParams.end())
21116428a1aSJason M. Bills     {
2125a7e877eSJames Feist         std::string topParam = it->value();
21316428a1aSJason M. Bills         char* ptr = nullptr;
2145a7e877eSJames Feist         top = std::strtoul(topParam.c_str(), &ptr, 10);
2155a7e877eSJames Feist         if (topParam.empty() || *ptr != '\0')
21616428a1aSJason M. Bills         {
21716428a1aSJason M. Bills             messages::queryParameterValueTypeError(res, std::string(topParam),
21816428a1aSJason M. Bills                                                    "$top");
21916428a1aSJason M. Bills             return false;
22016428a1aSJason M. Bills         }
221271584abSEd Tanous         if (top < 1U || top > maxEntriesPerPage)
22216428a1aSJason M. Bills         {
22316428a1aSJason M. Bills 
22416428a1aSJason M. Bills             messages::queryParameterOutOfRange(
22516428a1aSJason M. Bills                 res, std::to_string(top), "$top",
22616428a1aSJason M. Bills                 "1-" + std::to_string(maxEntriesPerPage));
22716428a1aSJason M. Bills             return false;
22816428a1aSJason M. Bills         }
22916428a1aSJason M. Bills     }
23016428a1aSJason M. Bills     return true;
23116428a1aSJason M. Bills }
23216428a1aSJason M. Bills 
233e85d6b16SJason M. Bills static bool getUniqueEntryID(sd_journal* journal, std::string& entryID,
234e85d6b16SJason M. Bills                              const bool firstEntry = true)
23516428a1aSJason M. Bills {
23616428a1aSJason M. Bills     int ret = 0;
23716428a1aSJason M. Bills     static uint64_t prevTs = 0;
23816428a1aSJason M. Bills     static int index = 0;
239e85d6b16SJason M. Bills     if (firstEntry)
240e85d6b16SJason M. Bills     {
241e85d6b16SJason M. Bills         prevTs = 0;
242e85d6b16SJason M. Bills     }
243e85d6b16SJason M. Bills 
24416428a1aSJason M. Bills     // Get the entry timestamp
24516428a1aSJason M. Bills     uint64_t curTs = 0;
24616428a1aSJason M. Bills     ret = sd_journal_get_realtime_usec(journal, &curTs);
24716428a1aSJason M. Bills     if (ret < 0)
24816428a1aSJason M. Bills     {
24916428a1aSJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
25016428a1aSJason M. Bills                          << strerror(-ret);
25116428a1aSJason M. Bills         return false;
25216428a1aSJason M. Bills     }
25316428a1aSJason M. Bills     // If the timestamp isn't unique, increment the index
25416428a1aSJason M. Bills     if (curTs == prevTs)
25516428a1aSJason M. Bills     {
25616428a1aSJason M. Bills         index++;
25716428a1aSJason M. Bills     }
25816428a1aSJason M. Bills     else
25916428a1aSJason M. Bills     {
26016428a1aSJason M. Bills         // Otherwise, reset it
26116428a1aSJason M. Bills         index = 0;
26216428a1aSJason M. Bills     }
26316428a1aSJason M. Bills     // Save the timestamp
26416428a1aSJason M. Bills     prevTs = curTs;
26516428a1aSJason M. Bills 
26616428a1aSJason M. Bills     entryID = std::to_string(curTs);
26716428a1aSJason M. Bills     if (index > 0)
26816428a1aSJason M. Bills     {
26916428a1aSJason M. Bills         entryID += "_" + std::to_string(index);
27016428a1aSJason M. Bills     }
27116428a1aSJason M. Bills     return true;
27216428a1aSJason M. Bills }
27316428a1aSJason M. Bills 
274e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
275e85d6b16SJason M. Bills                              const bool firstEntry = true)
27695820184SJason M. Bills {
277271584abSEd Tanous     static time_t prevTs = 0;
27895820184SJason M. Bills     static int index = 0;
279e85d6b16SJason M. Bills     if (firstEntry)
280e85d6b16SJason M. Bills     {
281e85d6b16SJason M. Bills         prevTs = 0;
282e85d6b16SJason M. Bills     }
283e85d6b16SJason M. Bills 
28495820184SJason M. Bills     // Get the entry timestamp
285271584abSEd Tanous     std::time_t curTs = 0;
28695820184SJason M. Bills     std::tm timeStruct = {};
28795820184SJason M. Bills     std::istringstream entryStream(logEntry);
28895820184SJason M. Bills     if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
28995820184SJason M. Bills     {
29095820184SJason M. Bills         curTs = std::mktime(&timeStruct);
29195820184SJason M. Bills     }
29295820184SJason M. Bills     // If the timestamp isn't unique, increment the index
29395820184SJason M. Bills     if (curTs == prevTs)
29495820184SJason M. Bills     {
29595820184SJason M. Bills         index++;
29695820184SJason M. Bills     }
29795820184SJason M. Bills     else
29895820184SJason M. Bills     {
29995820184SJason M. Bills         // Otherwise, reset it
30095820184SJason M. Bills         index = 0;
30195820184SJason M. Bills     }
30295820184SJason M. Bills     // Save the timestamp
30395820184SJason M. Bills     prevTs = curTs;
30495820184SJason M. Bills 
30595820184SJason M. Bills     entryID = std::to_string(curTs);
30695820184SJason M. Bills     if (index > 0)
30795820184SJason M. Bills     {
30895820184SJason M. Bills         entryID += "_" + std::to_string(index);
30995820184SJason M. Bills     }
31095820184SJason M. Bills     return true;
31195820184SJason M. Bills }
31295820184SJason M. Bills 
31316428a1aSJason M. Bills static bool getTimestampFromID(crow::Response& res, const std::string& entryID,
314271584abSEd Tanous                                uint64_t& timestamp, uint64_t& index)
31516428a1aSJason M. Bills {
31616428a1aSJason M. Bills     if (entryID.empty())
31716428a1aSJason M. Bills     {
31816428a1aSJason M. Bills         return false;
31916428a1aSJason M. Bills     }
32016428a1aSJason M. Bills     // Convert the unique ID back to a timestamp to find the entry
32139e77504SEd Tanous     std::string_view tsStr(entryID);
32216428a1aSJason M. Bills 
32381ce609eSEd Tanous     auto underscorePos = tsStr.find('_');
32416428a1aSJason M. Bills     if (underscorePos != tsStr.npos)
32516428a1aSJason M. Bills     {
32616428a1aSJason M. Bills         // Timestamp has an index
32716428a1aSJason M. Bills         tsStr.remove_suffix(tsStr.size() - underscorePos);
32839e77504SEd Tanous         std::string_view indexStr(entryID);
32916428a1aSJason M. Bills         indexStr.remove_prefix(underscorePos + 1);
33016428a1aSJason M. Bills         std::size_t pos;
33116428a1aSJason M. Bills         try
33216428a1aSJason M. Bills         {
33339e77504SEd Tanous             index = std::stoul(std::string(indexStr), &pos);
33416428a1aSJason M. Bills         }
335271584abSEd Tanous         catch (std::invalid_argument&)
33616428a1aSJason M. Bills         {
33716428a1aSJason M. Bills             messages::resourceMissingAtURI(res, entryID);
33816428a1aSJason M. Bills             return false;
33916428a1aSJason M. Bills         }
340271584abSEd Tanous         catch (std::out_of_range&)
34116428a1aSJason M. Bills         {
34216428a1aSJason M. Bills             messages::resourceMissingAtURI(res, entryID);
34316428a1aSJason M. Bills             return false;
34416428a1aSJason M. Bills         }
34516428a1aSJason M. Bills         if (pos != indexStr.size())
34616428a1aSJason M. Bills         {
34716428a1aSJason M. Bills             messages::resourceMissingAtURI(res, entryID);
34816428a1aSJason M. Bills             return false;
34916428a1aSJason M. Bills         }
35016428a1aSJason M. Bills     }
35116428a1aSJason M. Bills     // Timestamp has no index
35216428a1aSJason M. Bills     std::size_t pos;
35316428a1aSJason M. Bills     try
35416428a1aSJason M. Bills     {
35539e77504SEd Tanous         timestamp = std::stoull(std::string(tsStr), &pos);
35616428a1aSJason M. Bills     }
357271584abSEd Tanous     catch (std::invalid_argument&)
35816428a1aSJason M. Bills     {
35916428a1aSJason M. Bills         messages::resourceMissingAtURI(res, entryID);
36016428a1aSJason M. Bills         return false;
36116428a1aSJason M. Bills     }
362271584abSEd Tanous     catch (std::out_of_range&)
36316428a1aSJason M. Bills     {
36416428a1aSJason M. Bills         messages::resourceMissingAtURI(res, entryID);
36516428a1aSJason M. Bills         return false;
36616428a1aSJason M. Bills     }
36716428a1aSJason M. Bills     if (pos != tsStr.size())
36816428a1aSJason M. Bills     {
36916428a1aSJason M. Bills         messages::resourceMissingAtURI(res, entryID);
37016428a1aSJason M. Bills         return false;
37116428a1aSJason M. Bills     }
37216428a1aSJason M. Bills     return true;
37316428a1aSJason M. Bills }
37416428a1aSJason M. Bills 
37595820184SJason M. Bills static bool
37695820184SJason M. Bills     getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
37795820184SJason M. Bills {
37895820184SJason M. Bills     static const std::filesystem::path redfishLogDir = "/var/log";
37995820184SJason M. Bills     static const std::string redfishLogFilename = "redfish";
38095820184SJason M. Bills 
38195820184SJason M. Bills     // Loop through the directory looking for redfish log files
38295820184SJason M. Bills     for (const std::filesystem::directory_entry& dirEnt :
38395820184SJason M. Bills          std::filesystem::directory_iterator(redfishLogDir))
38495820184SJason M. Bills     {
38595820184SJason M. Bills         // If we find a redfish log file, save the path
38695820184SJason M. Bills         std::string filename = dirEnt.path().filename();
38795820184SJason M. Bills         if (boost::starts_with(filename, redfishLogFilename))
38895820184SJason M. Bills         {
38995820184SJason M. Bills             redfishLogFiles.emplace_back(redfishLogDir / filename);
39095820184SJason M. Bills         }
39195820184SJason M. Bills     }
39295820184SJason M. Bills     // As the log files rotate, they are appended with a ".#" that is higher for
39395820184SJason M. Bills     // the older logs. Since we don't expect more than 10 log files, we
39495820184SJason M. Bills     // can just sort the list to get them in order from newest to oldest
39595820184SJason M. Bills     std::sort(redfishLogFiles.begin(), redfishLogFiles.end());
39695820184SJason M. Bills 
39795820184SJason M. Bills     return !redfishLogFiles.empty();
39895820184SJason M. Bills }
39995820184SJason M. Bills 
4005cb1dd27SAsmitha Karunanithi inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp,
4015cb1dd27SAsmitha Karunanithi                                    const std::string& dumpType)
4025cb1dd27SAsmitha Karunanithi {
4035cb1dd27SAsmitha Karunanithi     std::string dumpPath;
4045cb1dd27SAsmitha Karunanithi     if (dumpType == "BMC")
4055cb1dd27SAsmitha Karunanithi     {
4065cb1dd27SAsmitha Karunanithi         dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
4075cb1dd27SAsmitha Karunanithi     }
4085cb1dd27SAsmitha Karunanithi     else if (dumpType == "System")
4095cb1dd27SAsmitha Karunanithi     {
4105cb1dd27SAsmitha Karunanithi         dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
4115cb1dd27SAsmitha Karunanithi     }
4125cb1dd27SAsmitha Karunanithi     else
4135cb1dd27SAsmitha Karunanithi     {
4145cb1dd27SAsmitha Karunanithi         BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
4155cb1dd27SAsmitha Karunanithi         messages::internalError(asyncResp->res);
4165cb1dd27SAsmitha Karunanithi         return;
4175cb1dd27SAsmitha Karunanithi     }
4185cb1dd27SAsmitha Karunanithi 
4195cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
4205cb1dd27SAsmitha Karunanithi         [asyncResp, dumpPath, dumpType](const boost::system::error_code ec,
4215cb1dd27SAsmitha Karunanithi                                         GetManagedObjectsType& resp) {
4225cb1dd27SAsmitha Karunanithi             if (ec)
4235cb1dd27SAsmitha Karunanithi             {
4245cb1dd27SAsmitha Karunanithi                 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
4255cb1dd27SAsmitha Karunanithi                 messages::internalError(asyncResp->res);
4265cb1dd27SAsmitha Karunanithi                 return;
4275cb1dd27SAsmitha Karunanithi             }
4285cb1dd27SAsmitha Karunanithi 
4295cb1dd27SAsmitha Karunanithi             nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
4305cb1dd27SAsmitha Karunanithi             entriesArray = nlohmann::json::array();
431b47452b2SAsmitha Karunanithi             std::string dumpEntryPath =
432b47452b2SAsmitha Karunanithi                 "/xyz/openbmc_project/dump/" +
433b47452b2SAsmitha Karunanithi                 std::string(boost::algorithm::to_lower_copy(dumpType)) +
434b47452b2SAsmitha Karunanithi                 "/entry/";
4355cb1dd27SAsmitha Karunanithi 
4365cb1dd27SAsmitha Karunanithi             for (auto& object : resp)
4375cb1dd27SAsmitha Karunanithi             {
438b47452b2SAsmitha Karunanithi                 if (object.first.str.find(dumpEntryPath) == std::string::npos)
4395cb1dd27SAsmitha Karunanithi                 {
4405cb1dd27SAsmitha Karunanithi                     continue;
4415cb1dd27SAsmitha Karunanithi                 }
4425cb1dd27SAsmitha Karunanithi                 std::time_t timestamp;
4435cb1dd27SAsmitha Karunanithi                 uint64_t size = 0;
4445cb1dd27SAsmitha Karunanithi                 entriesArray.push_back({});
4455cb1dd27SAsmitha Karunanithi                 nlohmann::json& thisEntry = entriesArray.back();
4462dfd18efSEd Tanous 
4472dfd18efSEd Tanous                 std::string entryID = object.first.filename();
4482dfd18efSEd Tanous                 if (entryID.empty())
4495cb1dd27SAsmitha Karunanithi                 {
4505cb1dd27SAsmitha Karunanithi                     continue;
4515cb1dd27SAsmitha Karunanithi                 }
4525cb1dd27SAsmitha Karunanithi 
4535cb1dd27SAsmitha Karunanithi                 for (auto& interfaceMap : object.second)
4545cb1dd27SAsmitha Karunanithi                 {
4555cb1dd27SAsmitha Karunanithi                     if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
4565cb1dd27SAsmitha Karunanithi                     {
4575cb1dd27SAsmitha Karunanithi 
4585cb1dd27SAsmitha Karunanithi                         for (auto& propertyMap : interfaceMap.second)
4595cb1dd27SAsmitha Karunanithi                         {
4605cb1dd27SAsmitha Karunanithi                             if (propertyMap.first == "Size")
4615cb1dd27SAsmitha Karunanithi                             {
4625cb1dd27SAsmitha Karunanithi                                 auto sizePtr =
4635cb1dd27SAsmitha Karunanithi                                     std::get_if<uint64_t>(&propertyMap.second);
4645cb1dd27SAsmitha Karunanithi                                 if (sizePtr == nullptr)
4655cb1dd27SAsmitha Karunanithi                                 {
4665cb1dd27SAsmitha Karunanithi                                     messages::internalError(asyncResp->res);
4675cb1dd27SAsmitha Karunanithi                                     break;
4685cb1dd27SAsmitha Karunanithi                                 }
4695cb1dd27SAsmitha Karunanithi                                 size = *sizePtr;
4705cb1dd27SAsmitha Karunanithi                                 break;
4715cb1dd27SAsmitha Karunanithi                             }
4725cb1dd27SAsmitha Karunanithi                         }
4735cb1dd27SAsmitha Karunanithi                     }
4745cb1dd27SAsmitha Karunanithi                     else if (interfaceMap.first ==
4755cb1dd27SAsmitha Karunanithi                              "xyz.openbmc_project.Time.EpochTime")
4765cb1dd27SAsmitha Karunanithi                     {
4775cb1dd27SAsmitha Karunanithi 
4785cb1dd27SAsmitha Karunanithi                         for (auto& propertyMap : interfaceMap.second)
4795cb1dd27SAsmitha Karunanithi                         {
4805cb1dd27SAsmitha Karunanithi                             if (propertyMap.first == "Elapsed")
4815cb1dd27SAsmitha Karunanithi                             {
4825cb1dd27SAsmitha Karunanithi                                 const uint64_t* usecsTimeStamp =
4835cb1dd27SAsmitha Karunanithi                                     std::get_if<uint64_t>(&propertyMap.second);
4845cb1dd27SAsmitha Karunanithi                                 if (usecsTimeStamp == nullptr)
4855cb1dd27SAsmitha Karunanithi                                 {
4865cb1dd27SAsmitha Karunanithi                                     messages::internalError(asyncResp->res);
4875cb1dd27SAsmitha Karunanithi                                     break;
4885cb1dd27SAsmitha Karunanithi                                 }
4895cb1dd27SAsmitha Karunanithi                                 timestamp =
4905cb1dd27SAsmitha Karunanithi                                     static_cast<std::time_t>(*usecsTimeStamp);
4915cb1dd27SAsmitha Karunanithi                                 break;
4925cb1dd27SAsmitha Karunanithi                             }
4935cb1dd27SAsmitha Karunanithi                         }
4945cb1dd27SAsmitha Karunanithi                     }
4955cb1dd27SAsmitha Karunanithi                 }
4965cb1dd27SAsmitha Karunanithi 
497d337bb72SAsmitha Karunanithi                 thisEntry["@odata.type"] = "#LogEntry.v1_7_0.LogEntry";
4985cb1dd27SAsmitha Karunanithi                 thisEntry["@odata.id"] = dumpPath + entryID;
4995cb1dd27SAsmitha Karunanithi                 thisEntry["Id"] = entryID;
5005cb1dd27SAsmitha Karunanithi                 thisEntry["EntryType"] = "Event";
5015cb1dd27SAsmitha Karunanithi                 thisEntry["Created"] = crow::utility::getDateTime(timestamp);
5025cb1dd27SAsmitha Karunanithi                 thisEntry["Name"] = dumpType + " Dump Entry";
5035cb1dd27SAsmitha Karunanithi 
504d337bb72SAsmitha Karunanithi                 thisEntry["AdditionalDataSizeBytes"] = size;
5055cb1dd27SAsmitha Karunanithi 
5065cb1dd27SAsmitha Karunanithi                 if (dumpType == "BMC")
5075cb1dd27SAsmitha Karunanithi                 {
508d337bb72SAsmitha Karunanithi                     thisEntry["DiagnosticDataType"] = "Manager";
509d337bb72SAsmitha Karunanithi                     thisEntry["AdditionalDataURI"] =
510d337bb72SAsmitha Karunanithi                         "/redfish/v1/Managers/bmc/LogServices/Dump/"
511d337bb72SAsmitha Karunanithi                         "attachment/" +
512d337bb72SAsmitha Karunanithi                         entryID;
5135cb1dd27SAsmitha Karunanithi                 }
5145cb1dd27SAsmitha Karunanithi                 else if (dumpType == "System")
5155cb1dd27SAsmitha Karunanithi                 {
516d337bb72SAsmitha Karunanithi                     thisEntry["DiagnosticDataType"] = "OEM";
517d337bb72SAsmitha Karunanithi                     thisEntry["OEMDiagnosticDataType"] = "System";
518d337bb72SAsmitha Karunanithi                     thisEntry["AdditionalDataURI"] =
519d337bb72SAsmitha Karunanithi                         "/redfish/v1/Systems/system/LogServices/Dump/"
520d337bb72SAsmitha Karunanithi                         "attachment/" +
521d337bb72SAsmitha Karunanithi                         entryID;
5225cb1dd27SAsmitha Karunanithi                 }
5235cb1dd27SAsmitha Karunanithi             }
5245cb1dd27SAsmitha Karunanithi             asyncResp->res.jsonValue["Members@odata.count"] =
5255cb1dd27SAsmitha Karunanithi                 entriesArray.size();
5265cb1dd27SAsmitha Karunanithi         },
5275cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
5285cb1dd27SAsmitha Karunanithi         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
5295cb1dd27SAsmitha Karunanithi }
5305cb1dd27SAsmitha Karunanithi 
5315cb1dd27SAsmitha Karunanithi inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp,
5325cb1dd27SAsmitha Karunanithi                              const std::string& entryID,
5335cb1dd27SAsmitha Karunanithi                              const std::string& dumpType)
5345cb1dd27SAsmitha Karunanithi {
5355cb1dd27SAsmitha Karunanithi     std::string dumpPath;
5365cb1dd27SAsmitha Karunanithi     if (dumpType == "BMC")
5375cb1dd27SAsmitha Karunanithi     {
5385cb1dd27SAsmitha Karunanithi         dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
5395cb1dd27SAsmitha Karunanithi     }
5405cb1dd27SAsmitha Karunanithi     else if (dumpType == "System")
5415cb1dd27SAsmitha Karunanithi     {
5425cb1dd27SAsmitha Karunanithi         dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
5435cb1dd27SAsmitha Karunanithi     }
5445cb1dd27SAsmitha Karunanithi     else
5455cb1dd27SAsmitha Karunanithi     {
5465cb1dd27SAsmitha Karunanithi         BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
5475cb1dd27SAsmitha Karunanithi         messages::internalError(asyncResp->res);
5485cb1dd27SAsmitha Karunanithi         return;
5495cb1dd27SAsmitha Karunanithi     }
5505cb1dd27SAsmitha Karunanithi 
5515cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
5525cb1dd27SAsmitha Karunanithi         [asyncResp, entryID, dumpPath, dumpType](
5535cb1dd27SAsmitha Karunanithi             const boost::system::error_code ec, GetManagedObjectsType& resp) {
5545cb1dd27SAsmitha Karunanithi             if (ec)
5555cb1dd27SAsmitha Karunanithi             {
5565cb1dd27SAsmitha Karunanithi                 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
5575cb1dd27SAsmitha Karunanithi                 messages::internalError(asyncResp->res);
5585cb1dd27SAsmitha Karunanithi                 return;
5595cb1dd27SAsmitha Karunanithi             }
5605cb1dd27SAsmitha Karunanithi 
561b47452b2SAsmitha Karunanithi             bool foundDumpEntry = false;
562b47452b2SAsmitha Karunanithi             std::string dumpEntryPath =
563b47452b2SAsmitha Karunanithi                 "/xyz/openbmc_project/dump/" +
564b47452b2SAsmitha Karunanithi                 std::string(boost::algorithm::to_lower_copy(dumpType)) +
565b47452b2SAsmitha Karunanithi                 "/entry/";
566b47452b2SAsmitha Karunanithi 
5675cb1dd27SAsmitha Karunanithi             for (auto& objectPath : resp)
5685cb1dd27SAsmitha Karunanithi             {
569b47452b2SAsmitha Karunanithi                 if (objectPath.first.str != dumpEntryPath + entryID)
5705cb1dd27SAsmitha Karunanithi                 {
5715cb1dd27SAsmitha Karunanithi                     continue;
5725cb1dd27SAsmitha Karunanithi                 }
5735cb1dd27SAsmitha Karunanithi 
5745cb1dd27SAsmitha Karunanithi                 foundDumpEntry = true;
5755cb1dd27SAsmitha Karunanithi                 std::time_t timestamp;
5765cb1dd27SAsmitha Karunanithi                 uint64_t size = 0;
5775cb1dd27SAsmitha Karunanithi 
5785cb1dd27SAsmitha Karunanithi                 for (auto& interfaceMap : objectPath.second)
5795cb1dd27SAsmitha Karunanithi                 {
5805cb1dd27SAsmitha Karunanithi                     if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
5815cb1dd27SAsmitha Karunanithi                     {
5825cb1dd27SAsmitha Karunanithi                         for (auto& propertyMap : interfaceMap.second)
5835cb1dd27SAsmitha Karunanithi                         {
5845cb1dd27SAsmitha Karunanithi                             if (propertyMap.first == "Size")
5855cb1dd27SAsmitha Karunanithi                             {
5865cb1dd27SAsmitha Karunanithi                                 auto sizePtr =
5875cb1dd27SAsmitha Karunanithi                                     std::get_if<uint64_t>(&propertyMap.second);
5885cb1dd27SAsmitha Karunanithi                                 if (sizePtr == nullptr)
5895cb1dd27SAsmitha Karunanithi                                 {
5905cb1dd27SAsmitha Karunanithi                                     messages::internalError(asyncResp->res);
5915cb1dd27SAsmitha Karunanithi                                     break;
5925cb1dd27SAsmitha Karunanithi                                 }
5935cb1dd27SAsmitha Karunanithi                                 size = *sizePtr;
5945cb1dd27SAsmitha Karunanithi                                 break;
5955cb1dd27SAsmitha Karunanithi                             }
5965cb1dd27SAsmitha Karunanithi                         }
5975cb1dd27SAsmitha Karunanithi                     }
5985cb1dd27SAsmitha Karunanithi                     else if (interfaceMap.first ==
5995cb1dd27SAsmitha Karunanithi                              "xyz.openbmc_project.Time.EpochTime")
6005cb1dd27SAsmitha Karunanithi                     {
6015cb1dd27SAsmitha Karunanithi                         for (auto& propertyMap : interfaceMap.second)
6025cb1dd27SAsmitha Karunanithi                         {
6035cb1dd27SAsmitha Karunanithi                             if (propertyMap.first == "Elapsed")
6045cb1dd27SAsmitha Karunanithi                             {
6055cb1dd27SAsmitha Karunanithi                                 const uint64_t* usecsTimeStamp =
6065cb1dd27SAsmitha Karunanithi                                     std::get_if<uint64_t>(&propertyMap.second);
6075cb1dd27SAsmitha Karunanithi                                 if (usecsTimeStamp == nullptr)
6085cb1dd27SAsmitha Karunanithi                                 {
6095cb1dd27SAsmitha Karunanithi                                     messages::internalError(asyncResp->res);
6105cb1dd27SAsmitha Karunanithi                                     break;
6115cb1dd27SAsmitha Karunanithi                                 }
6125cb1dd27SAsmitha Karunanithi                                 timestamp =
6135cb1dd27SAsmitha Karunanithi                                     static_cast<std::time_t>(*usecsTimeStamp);
6145cb1dd27SAsmitha Karunanithi                                 break;
6155cb1dd27SAsmitha Karunanithi                             }
6165cb1dd27SAsmitha Karunanithi                         }
6175cb1dd27SAsmitha Karunanithi                     }
6185cb1dd27SAsmitha Karunanithi                 }
6195cb1dd27SAsmitha Karunanithi 
6205cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["@odata.type"] =
621d337bb72SAsmitha Karunanithi                     "#LogEntry.v1_7_0.LogEntry";
6225cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID;
6235cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["Id"] = entryID;
6245cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["EntryType"] = "Event";
6255cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["Created"] =
6265cb1dd27SAsmitha Karunanithi                     crow::utility::getDateTime(timestamp);
6275cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
6285cb1dd27SAsmitha Karunanithi 
629d337bb72SAsmitha Karunanithi                 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
6305cb1dd27SAsmitha Karunanithi 
6315cb1dd27SAsmitha Karunanithi                 if (dumpType == "BMC")
6325cb1dd27SAsmitha Karunanithi                 {
633d337bb72SAsmitha Karunanithi                     asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
634d337bb72SAsmitha Karunanithi                     asyncResp->res.jsonValue["AdditionalDataURI"] =
6355cb1dd27SAsmitha Karunanithi                         "/redfish/v1/Managers/bmc/LogServices/Dump/"
6365cb1dd27SAsmitha Karunanithi                         "attachment/" +
6375cb1dd27SAsmitha Karunanithi                         entryID;
6385cb1dd27SAsmitha Karunanithi                 }
6395cb1dd27SAsmitha Karunanithi                 else if (dumpType == "System")
6405cb1dd27SAsmitha Karunanithi                 {
641d337bb72SAsmitha Karunanithi                     asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
642d337bb72SAsmitha Karunanithi                     asyncResp->res.jsonValue["OEMDiagnosticDataType"] =
6435cb1dd27SAsmitha Karunanithi                         "System";
644d337bb72SAsmitha Karunanithi                     asyncResp->res.jsonValue["AdditionalDataURI"] =
6455cb1dd27SAsmitha Karunanithi                         "/redfish/v1/Systems/system/LogServices/Dump/"
6465cb1dd27SAsmitha Karunanithi                         "attachment/" +
6475cb1dd27SAsmitha Karunanithi                         entryID;
6485cb1dd27SAsmitha Karunanithi                 }
6495cb1dd27SAsmitha Karunanithi             }
650b47452b2SAsmitha Karunanithi             if (foundDumpEntry == false)
651b47452b2SAsmitha Karunanithi             {
652b47452b2SAsmitha Karunanithi                 BMCWEB_LOG_ERROR << "Can't find Dump Entry";
653b47452b2SAsmitha Karunanithi                 messages::internalError(asyncResp->res);
654b47452b2SAsmitha Karunanithi                 return;
655b47452b2SAsmitha Karunanithi             }
6565cb1dd27SAsmitha Karunanithi         },
6575cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
6585cb1dd27SAsmitha Karunanithi         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
6595cb1dd27SAsmitha Karunanithi }
6605cb1dd27SAsmitha Karunanithi 
6619878256fSStanley Chu inline void deleteDumpEntry(const std::shared_ptr<AsyncResp>& asyncResp,
6629878256fSStanley Chu                             const std::string& entryID,
663b47452b2SAsmitha Karunanithi                             const std::string& dumpType)
6645cb1dd27SAsmitha Karunanithi {
6653de8d8baSGeorge Liu     auto respHandler = [asyncResp,
6663de8d8baSGeorge Liu                         entryID](const boost::system::error_code ec) {
6675cb1dd27SAsmitha Karunanithi         BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done";
6685cb1dd27SAsmitha Karunanithi         if (ec)
6695cb1dd27SAsmitha Karunanithi         {
6703de8d8baSGeorge Liu             if (ec.value() == EBADR)
6713de8d8baSGeorge Liu             {
6723de8d8baSGeorge Liu                 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
6733de8d8baSGeorge Liu                 return;
6743de8d8baSGeorge Liu             }
6755cb1dd27SAsmitha Karunanithi             BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error "
6765cb1dd27SAsmitha Karunanithi                              << ec;
6775cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
6785cb1dd27SAsmitha Karunanithi             return;
6795cb1dd27SAsmitha Karunanithi         }
6805cb1dd27SAsmitha Karunanithi     };
6815cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
6825cb1dd27SAsmitha Karunanithi         respHandler, "xyz.openbmc_project.Dump.Manager",
683b47452b2SAsmitha Karunanithi         "/xyz/openbmc_project/dump/" +
684b47452b2SAsmitha Karunanithi             std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" +
685b47452b2SAsmitha Karunanithi             entryID,
6865cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Object.Delete", "Delete");
6875cb1dd27SAsmitha Karunanithi }
6885cb1dd27SAsmitha Karunanithi 
689a43be80fSAsmitha Karunanithi inline void createDumpTaskCallback(const crow::Request& req,
690b5a76932SEd Tanous                                    const std::shared_ptr<AsyncResp>& asyncResp,
691a43be80fSAsmitha Karunanithi                                    const uint32_t& dumpId,
692a43be80fSAsmitha Karunanithi                                    const std::string& dumpPath,
693a43be80fSAsmitha Karunanithi                                    const std::string& dumpType)
694a43be80fSAsmitha Karunanithi {
695a43be80fSAsmitha Karunanithi     std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
6966145ed6fSAsmitha Karunanithi         [dumpId, dumpPath, dumpType](
697a43be80fSAsmitha Karunanithi             boost::system::error_code err, sdbusplus::message::message& m,
698a43be80fSAsmitha Karunanithi             const std::shared_ptr<task::TaskData>& taskData) {
699cb13a392SEd Tanous             if (err)
700cb13a392SEd Tanous             {
7016145ed6fSAsmitha Karunanithi                 BMCWEB_LOG_ERROR << "Error in creating a dump";
7026145ed6fSAsmitha Karunanithi                 taskData->state = "Cancelled";
7036145ed6fSAsmitha Karunanithi                 return task::completed;
704cb13a392SEd Tanous             }
705a43be80fSAsmitha Karunanithi             std::vector<std::pair<
706a43be80fSAsmitha Karunanithi                 std::string,
707a43be80fSAsmitha Karunanithi                 std::vector<std::pair<std::string, std::variant<std::string>>>>>
708a43be80fSAsmitha Karunanithi                 interfacesList;
709a43be80fSAsmitha Karunanithi 
710a43be80fSAsmitha Karunanithi             sdbusplus::message::object_path objPath;
711a43be80fSAsmitha Karunanithi 
712a43be80fSAsmitha Karunanithi             m.read(objPath, interfacesList);
713a43be80fSAsmitha Karunanithi 
714b47452b2SAsmitha Karunanithi             if (objPath.str ==
715b47452b2SAsmitha Karunanithi                 "/xyz/openbmc_project/dump/" +
716b47452b2SAsmitha Karunanithi                     std::string(boost::algorithm::to_lower_copy(dumpType)) +
717b47452b2SAsmitha Karunanithi                     "/entry/" + std::to_string(dumpId))
718a43be80fSAsmitha Karunanithi             {
719a43be80fSAsmitha Karunanithi                 nlohmann::json retMessage = messages::success();
720a43be80fSAsmitha Karunanithi                 taskData->messages.emplace_back(retMessage);
721a43be80fSAsmitha Karunanithi 
722a43be80fSAsmitha Karunanithi                 std::string headerLoc =
723a43be80fSAsmitha Karunanithi                     "Location: " + dumpPath + std::to_string(dumpId);
724a43be80fSAsmitha Karunanithi                 taskData->payload->httpHeaders.emplace_back(
725a43be80fSAsmitha Karunanithi                     std::move(headerLoc));
726a43be80fSAsmitha Karunanithi 
727a43be80fSAsmitha Karunanithi                 taskData->state = "Completed";
728b47452b2SAsmitha Karunanithi                 return task::completed;
7296145ed6fSAsmitha Karunanithi             }
730a43be80fSAsmitha Karunanithi             return task::completed;
731a43be80fSAsmitha Karunanithi         },
732a43be80fSAsmitha Karunanithi         "type='signal',interface='org.freedesktop.DBus."
733a43be80fSAsmitha Karunanithi         "ObjectManager',"
734a43be80fSAsmitha Karunanithi         "member='InterfacesAdded', "
735a43be80fSAsmitha Karunanithi         "path='/xyz/openbmc_project/dump'");
736a43be80fSAsmitha Karunanithi 
737a43be80fSAsmitha Karunanithi     task->startTimer(std::chrono::minutes(3));
738a43be80fSAsmitha Karunanithi     task->populateResp(asyncResp->res);
739a43be80fSAsmitha Karunanithi     task->payload.emplace(req);
740a43be80fSAsmitha Karunanithi }
741a43be80fSAsmitha Karunanithi 
742a43be80fSAsmitha Karunanithi inline void createDump(crow::Response& res, const crow::Request& req,
743a43be80fSAsmitha Karunanithi                        const std::string& dumpType)
744a43be80fSAsmitha Karunanithi {
745a43be80fSAsmitha Karunanithi     std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
746a43be80fSAsmitha Karunanithi 
747a43be80fSAsmitha Karunanithi     std::string dumpPath;
748a43be80fSAsmitha Karunanithi     if (dumpType == "BMC")
749a43be80fSAsmitha Karunanithi     {
750a43be80fSAsmitha Karunanithi         dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
751a43be80fSAsmitha Karunanithi     }
752a43be80fSAsmitha Karunanithi     else if (dumpType == "System")
753a43be80fSAsmitha Karunanithi     {
754a43be80fSAsmitha Karunanithi         dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
755a43be80fSAsmitha Karunanithi     }
756a43be80fSAsmitha Karunanithi     else
757a43be80fSAsmitha Karunanithi     {
758a43be80fSAsmitha Karunanithi         BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType;
759a43be80fSAsmitha Karunanithi         messages::internalError(asyncResp->res);
760a43be80fSAsmitha Karunanithi         return;
761a43be80fSAsmitha Karunanithi     }
762a43be80fSAsmitha Karunanithi 
763a43be80fSAsmitha Karunanithi     std::optional<std::string> diagnosticDataType;
764a43be80fSAsmitha Karunanithi     std::optional<std::string> oemDiagnosticDataType;
765a43be80fSAsmitha Karunanithi 
766a43be80fSAsmitha Karunanithi     if (!redfish::json_util::readJson(
767a43be80fSAsmitha Karunanithi             req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
768a43be80fSAsmitha Karunanithi             "OEMDiagnosticDataType", oemDiagnosticDataType))
769a43be80fSAsmitha Karunanithi     {
770a43be80fSAsmitha Karunanithi         return;
771a43be80fSAsmitha Karunanithi     }
772a43be80fSAsmitha Karunanithi 
773a43be80fSAsmitha Karunanithi     if (dumpType == "System")
774a43be80fSAsmitha Karunanithi     {
775a43be80fSAsmitha Karunanithi         if (!oemDiagnosticDataType || !diagnosticDataType)
776a43be80fSAsmitha Karunanithi         {
777a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "CreateDump action parameter "
778a43be80fSAsmitha Karunanithi                                 "'DiagnosticDataType'/"
779a43be80fSAsmitha Karunanithi                                 "'OEMDiagnosticDataType' value not found!";
780a43be80fSAsmitha Karunanithi             messages::actionParameterMissing(
781a43be80fSAsmitha Karunanithi                 asyncResp->res, "CollectDiagnosticData",
782a43be80fSAsmitha Karunanithi                 "DiagnosticDataType & OEMDiagnosticDataType");
783a43be80fSAsmitha Karunanithi             return;
784a43be80fSAsmitha Karunanithi         }
7853174e4dfSEd Tanous         if ((*oemDiagnosticDataType != "System") ||
786a43be80fSAsmitha Karunanithi             (*diagnosticDataType != "OEM"))
787a43be80fSAsmitha Karunanithi         {
788a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "Wrong parameter values passed";
789a43be80fSAsmitha Karunanithi             messages::invalidObject(asyncResp->res,
790a43be80fSAsmitha Karunanithi                                     "System Dump creation parameters");
791a43be80fSAsmitha Karunanithi             return;
792a43be80fSAsmitha Karunanithi         }
793a43be80fSAsmitha Karunanithi     }
794a43be80fSAsmitha Karunanithi     else if (dumpType == "BMC")
795a43be80fSAsmitha Karunanithi     {
796a43be80fSAsmitha Karunanithi         if (!diagnosticDataType)
797a43be80fSAsmitha Karunanithi         {
798a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "CreateDump action parameter "
799a43be80fSAsmitha Karunanithi                                 "'DiagnosticDataType' not found!";
800a43be80fSAsmitha Karunanithi             messages::actionParameterMissing(
801a43be80fSAsmitha Karunanithi                 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
802a43be80fSAsmitha Karunanithi             return;
803a43be80fSAsmitha Karunanithi         }
8043174e4dfSEd Tanous         if (*diagnosticDataType != "Manager")
805a43be80fSAsmitha Karunanithi         {
806a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR
807a43be80fSAsmitha Karunanithi                 << "Wrong parameter value passed for 'DiagnosticDataType'";
808a43be80fSAsmitha Karunanithi             messages::invalidObject(asyncResp->res,
809a43be80fSAsmitha Karunanithi                                     "BMC Dump creation parameters");
810a43be80fSAsmitha Karunanithi             return;
811a43be80fSAsmitha Karunanithi         }
812a43be80fSAsmitha Karunanithi     }
813a43be80fSAsmitha Karunanithi 
814a43be80fSAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
815a43be80fSAsmitha Karunanithi         [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec,
816a43be80fSAsmitha Karunanithi                                              const uint32_t& dumpId) {
817a43be80fSAsmitha Karunanithi             if (ec)
818a43be80fSAsmitha Karunanithi             {
819a43be80fSAsmitha Karunanithi                 BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
820a43be80fSAsmitha Karunanithi                 messages::internalError(asyncResp->res);
821a43be80fSAsmitha Karunanithi                 return;
822a43be80fSAsmitha Karunanithi             }
823a43be80fSAsmitha Karunanithi             BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId;
824a43be80fSAsmitha Karunanithi 
825a43be80fSAsmitha Karunanithi             createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType);
826a43be80fSAsmitha Karunanithi         },
827b47452b2SAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager",
828b47452b2SAsmitha Karunanithi         "/xyz/openbmc_project/dump/" +
829b47452b2SAsmitha Karunanithi             std::string(boost::algorithm::to_lower_copy(dumpType)),
830a43be80fSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Create", "CreateDump");
831a43be80fSAsmitha Karunanithi }
832a43be80fSAsmitha Karunanithi 
833b47452b2SAsmitha Karunanithi inline void clearDump(crow::Response& res, const std::string& dumpType)
83480319af1SAsmitha Karunanithi {
835b47452b2SAsmitha Karunanithi     std::string dumpTypeLowerCopy =
836b47452b2SAsmitha Karunanithi         std::string(boost::algorithm::to_lower_copy(dumpType));
83780319af1SAsmitha Karunanithi     std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
83880319af1SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
839b47452b2SAsmitha Karunanithi         [asyncResp, dumpType](const boost::system::error_code ec,
84080319af1SAsmitha Karunanithi                               const std::vector<std::string>& subTreePaths) {
84180319af1SAsmitha Karunanithi             if (ec)
84280319af1SAsmitha Karunanithi             {
84380319af1SAsmitha Karunanithi                 BMCWEB_LOG_ERROR << "resp_handler got error " << ec;
84480319af1SAsmitha Karunanithi                 messages::internalError(asyncResp->res);
84580319af1SAsmitha Karunanithi                 return;
84680319af1SAsmitha Karunanithi             }
84780319af1SAsmitha Karunanithi 
84880319af1SAsmitha Karunanithi             for (const std::string& path : subTreePaths)
84980319af1SAsmitha Karunanithi             {
8502dfd18efSEd Tanous                 sdbusplus::message::object_path objPath(path);
8512dfd18efSEd Tanous                 std::string logID = objPath.filename();
8522dfd18efSEd Tanous                 if (logID.empty())
85380319af1SAsmitha Karunanithi                 {
8542dfd18efSEd Tanous                     continue;
85580319af1SAsmitha Karunanithi                 }
8562dfd18efSEd Tanous                 deleteDumpEntry(asyncResp, logID, dumpType);
85780319af1SAsmitha Karunanithi             }
85880319af1SAsmitha Karunanithi         },
85980319af1SAsmitha Karunanithi         "xyz.openbmc_project.ObjectMapper",
86080319af1SAsmitha Karunanithi         "/xyz/openbmc_project/object_mapper",
86180319af1SAsmitha Karunanithi         "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
862b47452b2SAsmitha Karunanithi         "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0,
863b47452b2SAsmitha Karunanithi         std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." +
864b47452b2SAsmitha Karunanithi                                    dumpType});
86580319af1SAsmitha Karunanithi }
86680319af1SAsmitha Karunanithi 
8672c70f800SEd Tanous static void parseCrashdumpParameters(
868043a0536SJohnathan Mantey     const std::vector<std::pair<std::string, VariantType>>& params,
869043a0536SJohnathan Mantey     std::string& filename, std::string& timestamp, std::string& logfile)
870043a0536SJohnathan Mantey {
871043a0536SJohnathan Mantey     for (auto property : params)
872043a0536SJohnathan Mantey     {
873043a0536SJohnathan Mantey         if (property.first == "Timestamp")
874043a0536SJohnathan Mantey         {
875043a0536SJohnathan Mantey             const std::string* value =
8768d78b7a9SPatrick Williams                 std::get_if<std::string>(&property.second);
877043a0536SJohnathan Mantey             if (value != nullptr)
878043a0536SJohnathan Mantey             {
879043a0536SJohnathan Mantey                 timestamp = *value;
880043a0536SJohnathan Mantey             }
881043a0536SJohnathan Mantey         }
882043a0536SJohnathan Mantey         else if (property.first == "Filename")
883043a0536SJohnathan Mantey         {
884043a0536SJohnathan Mantey             const std::string* value =
8858d78b7a9SPatrick Williams                 std::get_if<std::string>(&property.second);
886043a0536SJohnathan Mantey             if (value != nullptr)
887043a0536SJohnathan Mantey             {
888043a0536SJohnathan Mantey                 filename = *value;
889043a0536SJohnathan Mantey             }
890043a0536SJohnathan Mantey         }
891043a0536SJohnathan Mantey         else if (property.first == "Log")
892043a0536SJohnathan Mantey         {
893043a0536SJohnathan Mantey             const std::string* value =
8948d78b7a9SPatrick Williams                 std::get_if<std::string>(&property.second);
895043a0536SJohnathan Mantey             if (value != nullptr)
896043a0536SJohnathan Mantey             {
897043a0536SJohnathan Mantey                 logfile = *value;
898043a0536SJohnathan Mantey             }
899043a0536SJohnathan Mantey         }
900043a0536SJohnathan Mantey     }
901043a0536SJohnathan Mantey }
902043a0536SJohnathan Mantey 
903a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode";
904c4bf6374SJason M. Bills class SystemLogServiceCollection : public Node
9051da66f75SEd Tanous {
9061da66f75SEd Tanous   public:
90752cc112dSEd Tanous     SystemLogServiceCollection(App& app) :
908029573d4SEd Tanous         Node(app, "/redfish/v1/Systems/system/LogServices/")
909c4bf6374SJason M. Bills     {
910c4bf6374SJason M. Bills         entityPrivileges = {
911c4bf6374SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
912c4bf6374SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
913c4bf6374SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
914c4bf6374SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
915c4bf6374SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
916c4bf6374SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
917c4bf6374SJason M. Bills     }
918c4bf6374SJason M. Bills 
919c4bf6374SJason M. Bills   private:
920c4bf6374SJason M. Bills     /**
921c4bf6374SJason M. Bills      * Functions triggers appropriate requests on DBus
922c4bf6374SJason M. Bills      */
923cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
924cb13a392SEd Tanous                const std::vector<std::string>&) override
925c4bf6374SJason M. Bills     {
926c4bf6374SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
927c4bf6374SJason M. Bills         // Collections don't include the static data added by SubRoute because
928c4bf6374SJason M. Bills         // it has a duplicate entry for members
929c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
930c4bf6374SJason M. Bills             "#LogServiceCollection.LogServiceCollection";
931c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
932029573d4SEd Tanous             "/redfish/v1/Systems/system/LogServices";
933c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
934c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] =
935c4bf6374SJason M. Bills             "Collection of LogServices for this Computer System";
936c4bf6374SJason M. Bills         nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
937c4bf6374SJason M. Bills         logServiceArray = nlohmann::json::array();
938029573d4SEd Tanous         logServiceArray.push_back(
939029573d4SEd Tanous             {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}});
9405cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
941c9bb6861Sraviteja-b         logServiceArray.push_back(
9425cb1dd27SAsmitha Karunanithi             {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}});
943c9bb6861Sraviteja-b #endif
944c9bb6861Sraviteja-b 
945d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
946d53dd41fSJason M. Bills         logServiceArray.push_back(
947cb92c03bSAndrew Geissler             {{"@odata.id",
948424c4176SJason M. Bills               "/redfish/v1/Systems/system/LogServices/Crashdump"}});
949d53dd41fSJason M. Bills #endif
950c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] =
951c4bf6374SJason M. Bills             logServiceArray.size();
952a3316fc6SZhikuiRen 
953a3316fc6SZhikuiRen         crow::connections::systemBus->async_method_call(
954a3316fc6SZhikuiRen             [asyncResp](const boost::system::error_code ec,
955a3316fc6SZhikuiRen                         const std::vector<std::string>& subtreePath) {
956a3316fc6SZhikuiRen                 if (ec)
957a3316fc6SZhikuiRen                 {
958a3316fc6SZhikuiRen                     BMCWEB_LOG_ERROR << ec;
959a3316fc6SZhikuiRen                     return;
960a3316fc6SZhikuiRen                 }
961a3316fc6SZhikuiRen 
962a3316fc6SZhikuiRen                 for (auto& pathStr : subtreePath)
963a3316fc6SZhikuiRen                 {
964a3316fc6SZhikuiRen                     if (pathStr.find("PostCode") != std::string::npos)
965a3316fc6SZhikuiRen                     {
96623a21a1cSEd Tanous                         nlohmann::json& logServiceArrayLocal =
967a3316fc6SZhikuiRen                             asyncResp->res.jsonValue["Members"];
96823a21a1cSEd Tanous                         logServiceArrayLocal.push_back(
969a3316fc6SZhikuiRen                             {{"@odata.id", "/redfish/v1/Systems/system/"
970a3316fc6SZhikuiRen                                            "LogServices/PostCodes"}});
971a3316fc6SZhikuiRen                         asyncResp->res.jsonValue["Members@odata.count"] =
97223a21a1cSEd Tanous                             logServiceArrayLocal.size();
973a3316fc6SZhikuiRen                         return;
974a3316fc6SZhikuiRen                     }
975a3316fc6SZhikuiRen                 }
976a3316fc6SZhikuiRen             },
977a3316fc6SZhikuiRen             "xyz.openbmc_project.ObjectMapper",
978a3316fc6SZhikuiRen             "/xyz/openbmc_project/object_mapper",
979a3316fc6SZhikuiRen             "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
980a3316fc6SZhikuiRen             std::array<const char*, 1>{postCodeIface});
981c4bf6374SJason M. Bills     }
982c4bf6374SJason M. Bills };
983c4bf6374SJason M. Bills 
984c4bf6374SJason M. Bills class EventLogService : public Node
985c4bf6374SJason M. Bills {
986c4bf6374SJason M. Bills   public:
98752cc112dSEd Tanous     EventLogService(App& app) :
988029573d4SEd Tanous         Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/")
989c4bf6374SJason M. Bills     {
990c4bf6374SJason M. Bills         entityPrivileges = {
991c4bf6374SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
992c4bf6374SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
993c4bf6374SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
994c4bf6374SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
995c4bf6374SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
996c4bf6374SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
997c4bf6374SJason M. Bills     }
998c4bf6374SJason M. Bills 
999c4bf6374SJason M. Bills   private:
1000cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
1001cb13a392SEd Tanous                const std::vector<std::string>&) override
1002c4bf6374SJason M. Bills     {
1003c4bf6374SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1004c4bf6374SJason M. Bills 
1005c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1006029573d4SEd Tanous             "/redfish/v1/Systems/system/LogServices/EventLog";
1007c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1008c4bf6374SJason M. Bills             "#LogService.v1_1_0.LogService";
1009c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Event Log Service";
1010c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] = "System Event Log Service";
1011c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Id"] = "EventLog";
1012c4bf6374SJason M. Bills         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1013c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Entries"] = {
1014c4bf6374SJason M. Bills             {"@odata.id",
1015029573d4SEd Tanous              "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}};
1016e7d6c8b2SGunnar Mills         asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
1017e7d6c8b2SGunnar Mills 
1018e7d6c8b2SGunnar Mills             {"target", "/redfish/v1/Systems/system/LogServices/EventLog/"
1019e7d6c8b2SGunnar Mills                        "Actions/LogService.ClearLog"}};
1020489640c6SJason M. Bills     }
1021489640c6SJason M. Bills };
1022489640c6SJason M. Bills 
10231f56a3a6STim Lee class JournalEventLogClear : public Node
1024489640c6SJason M. Bills {
1025489640c6SJason M. Bills   public:
102652cc112dSEd Tanous     JournalEventLogClear(App& app) :
1027489640c6SJason M. Bills         Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
1028489640c6SJason M. Bills                   "LogService.ClearLog/")
1029489640c6SJason M. Bills     {
1030489640c6SJason M. Bills         entityPrivileges = {
1031489640c6SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1032489640c6SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1033489640c6SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1034489640c6SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1035489640c6SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1036489640c6SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1037489640c6SJason M. Bills     }
1038489640c6SJason M. Bills 
1039489640c6SJason M. Bills   private:
1040cb13a392SEd Tanous     void doPost(crow::Response& res, const crow::Request&,
1041cb13a392SEd Tanous                 const std::vector<std::string>&) override
1042489640c6SJason M. Bills     {
1043489640c6SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1044489640c6SJason M. Bills 
1045489640c6SJason M. Bills         // Clear the EventLog by deleting the log files
1046489640c6SJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
1047489640c6SJason M. Bills         if (getRedfishLogFiles(redfishLogFiles))
1048489640c6SJason M. Bills         {
1049489640c6SJason M. Bills             for (const std::filesystem::path& file : redfishLogFiles)
1050489640c6SJason M. Bills             {
1051489640c6SJason M. Bills                 std::error_code ec;
1052489640c6SJason M. Bills                 std::filesystem::remove(file, ec);
1053489640c6SJason M. Bills             }
1054489640c6SJason M. Bills         }
1055489640c6SJason M. Bills 
1056489640c6SJason M. Bills         // Reload rsyslog so it knows to start new log files
1057489640c6SJason M. Bills         crow::connections::systemBus->async_method_call(
1058489640c6SJason M. Bills             [asyncResp](const boost::system::error_code ec) {
1059489640c6SJason M. Bills                 if (ec)
1060489640c6SJason M. Bills                 {
1061489640c6SJason M. Bills                     BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec;
1062489640c6SJason M. Bills                     messages::internalError(asyncResp->res);
1063489640c6SJason M. Bills                     return;
1064489640c6SJason M. Bills                 }
1065489640c6SJason M. Bills 
1066489640c6SJason M. Bills                 messages::success(asyncResp->res);
1067489640c6SJason M. Bills             },
1068489640c6SJason M. Bills             "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1069489640c6SJason M. Bills             "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1070489640c6SJason M. Bills             "replace");
1071c4bf6374SJason M. Bills     }
1072c4bf6374SJason M. Bills };
1073c4bf6374SJason M. Bills 
107495820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID,
1075b5a76932SEd Tanous                                  const std::string& logEntry,
107695820184SJason M. Bills                                  nlohmann::json& logEntryJson)
1077c4bf6374SJason M. Bills {
107895820184SJason M. Bills     // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
1079cd225da8SJason M. Bills     // First get the Timestamp
1080f23b7296SEd Tanous     size_t space = logEntry.find_first_of(' ');
1081cd225da8SJason M. Bills     if (space == std::string::npos)
108295820184SJason M. Bills     {
108395820184SJason M. Bills         return 1;
108495820184SJason M. Bills     }
1085cd225da8SJason M. Bills     std::string timestamp = logEntry.substr(0, space);
1086cd225da8SJason M. Bills     // Then get the log contents
1087f23b7296SEd Tanous     size_t entryStart = logEntry.find_first_not_of(' ', space);
1088cd225da8SJason M. Bills     if (entryStart == std::string::npos)
1089cd225da8SJason M. Bills     {
1090cd225da8SJason M. Bills         return 1;
1091cd225da8SJason M. Bills     }
1092cd225da8SJason M. Bills     std::string_view entry(logEntry);
1093cd225da8SJason M. Bills     entry.remove_prefix(entryStart);
1094cd225da8SJason M. Bills     // Use split to separate the entry into its fields
1095cd225da8SJason M. Bills     std::vector<std::string> logEntryFields;
1096cd225da8SJason M. Bills     boost::split(logEntryFields, entry, boost::is_any_of(","),
1097cd225da8SJason M. Bills                  boost::token_compress_on);
1098cd225da8SJason M. Bills     // We need at least a MessageId to be valid
1099cd225da8SJason M. Bills     if (logEntryFields.size() < 1)
1100cd225da8SJason M. Bills     {
1101cd225da8SJason M. Bills         return 1;
1102cd225da8SJason M. Bills     }
1103cd225da8SJason M. Bills     std::string& messageID = logEntryFields[0];
110495820184SJason M. Bills 
11054851d45dSJason M. Bills     // Get the Message from the MessageRegistry
11064851d45dSJason M. Bills     const message_registries::Message* message =
11074851d45dSJason M. Bills         message_registries::getMessage(messageID);
1108c4bf6374SJason M. Bills 
11094851d45dSJason M. Bills     std::string msg;
11104851d45dSJason M. Bills     std::string severity;
11114851d45dSJason M. Bills     if (message != nullptr)
1112c4bf6374SJason M. Bills     {
11134851d45dSJason M. Bills         msg = message->message;
11144851d45dSJason M. Bills         severity = message->severity;
1115c4bf6374SJason M. Bills     }
1116c4bf6374SJason M. Bills 
111715a86ff6SJason M. Bills     // Get the MessageArgs from the log if there are any
111815a86ff6SJason M. Bills     boost::beast::span<std::string> messageArgs;
111915a86ff6SJason M. Bills     if (logEntryFields.size() > 1)
112015a86ff6SJason M. Bills     {
112115a86ff6SJason M. Bills         std::string& messageArgsStart = logEntryFields[1];
112215a86ff6SJason M. Bills         // If the first string is empty, assume there are no MessageArgs
112315a86ff6SJason M. Bills         std::size_t messageArgsSize = 0;
112415a86ff6SJason M. Bills         if (!messageArgsStart.empty())
112515a86ff6SJason M. Bills         {
112615a86ff6SJason M. Bills             messageArgsSize = logEntryFields.size() - 1;
112715a86ff6SJason M. Bills         }
112815a86ff6SJason M. Bills 
112923a21a1cSEd Tanous         messageArgs = {&messageArgsStart, messageArgsSize};
1130c4bf6374SJason M. Bills 
11314851d45dSJason M. Bills         // Fill the MessageArgs into the Message
113295820184SJason M. Bills         int i = 0;
113395820184SJason M. Bills         for (const std::string& messageArg : messageArgs)
11344851d45dSJason M. Bills         {
113595820184SJason M. Bills             std::string argStr = "%" + std::to_string(++i);
11364851d45dSJason M. Bills             size_t argPos = msg.find(argStr);
11374851d45dSJason M. Bills             if (argPos != std::string::npos)
11384851d45dSJason M. Bills             {
113995820184SJason M. Bills                 msg.replace(argPos, argStr.length(), messageArg);
11404851d45dSJason M. Bills             }
11414851d45dSJason M. Bills         }
114215a86ff6SJason M. Bills     }
11434851d45dSJason M. Bills 
114495820184SJason M. Bills     // Get the Created time from the timestamp. The log timestamp is in RFC3339
114595820184SJason M. Bills     // format which matches the Redfish format except for the fractional seconds
114695820184SJason M. Bills     // between the '.' and the '+', so just remove them.
1147f23b7296SEd Tanous     std::size_t dot = timestamp.find_first_of('.');
1148f23b7296SEd Tanous     std::size_t plus = timestamp.find_first_of('+');
114995820184SJason M. Bills     if (dot != std::string::npos && plus != std::string::npos)
1150c4bf6374SJason M. Bills     {
115195820184SJason M. Bills         timestamp.erase(dot, plus - dot);
1152c4bf6374SJason M. Bills     }
1153c4bf6374SJason M. Bills 
1154c4bf6374SJason M. Bills     // Fill in the log entry with the gathered data
115595820184SJason M. Bills     logEntryJson = {
1156cb92c03bSAndrew Geissler         {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
1157029573d4SEd Tanous         {"@odata.id",
1158897967deSJason M. Bills          "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
115995820184SJason M. Bills              logEntryID},
1160c4bf6374SJason M. Bills         {"Name", "System Event Log Entry"},
116195820184SJason M. Bills         {"Id", logEntryID},
116295820184SJason M. Bills         {"Message", std::move(msg)},
116395820184SJason M. Bills         {"MessageId", std::move(messageID)},
1164f23b7296SEd Tanous         {"MessageArgs", messageArgs},
1165c4bf6374SJason M. Bills         {"EntryType", "Event"},
116695820184SJason M. Bills         {"Severity", std::move(severity)},
116795820184SJason M. Bills         {"Created", std::move(timestamp)}};
1168c4bf6374SJason M. Bills     return 0;
1169c4bf6374SJason M. Bills }
1170c4bf6374SJason M. Bills 
117127062605SAnthony Wilson class JournalEventLogEntryCollection : public Node
1172c4bf6374SJason M. Bills {
1173c4bf6374SJason M. Bills   public:
117452cc112dSEd Tanous     JournalEventLogEntryCollection(App& app) :
1175029573d4SEd Tanous         Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
1176c4bf6374SJason M. Bills     {
1177c4bf6374SJason M. Bills         entityPrivileges = {
1178c4bf6374SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1179c4bf6374SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1180c4bf6374SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1181c4bf6374SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1182c4bf6374SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1183c4bf6374SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1184c4bf6374SJason M. Bills     }
1185c4bf6374SJason M. Bills 
1186c4bf6374SJason M. Bills   private:
1187c4bf6374SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
1188cb13a392SEd Tanous                const std::vector<std::string>&) override
1189c4bf6374SJason M. Bills     {
1190c4bf6374SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1191271584abSEd Tanous         uint64_t skip = 0;
1192271584abSEd Tanous         uint64_t top = maxEntriesPerPage; // Show max entries by default
1193c4bf6374SJason M. Bills         if (!getSkipParam(asyncResp->res, req, skip))
1194c4bf6374SJason M. Bills         {
1195c4bf6374SJason M. Bills             return;
1196c4bf6374SJason M. Bills         }
1197c4bf6374SJason M. Bills         if (!getTopParam(asyncResp->res, req, top))
1198c4bf6374SJason M. Bills         {
1199c4bf6374SJason M. Bills             return;
1200c4bf6374SJason M. Bills         }
1201c4bf6374SJason M. Bills         // Collections don't include the static data added by SubRoute because
1202c4bf6374SJason M. Bills         // it has a duplicate entry for members
1203c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1204c4bf6374SJason M. Bills             "#LogEntryCollection.LogEntryCollection";
1205c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1206029573d4SEd Tanous             "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
1207c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1208c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] =
1209c4bf6374SJason M. Bills             "Collection of System Event Log Entries";
1210cb92c03bSAndrew Geissler 
1211c4bf6374SJason M. Bills         nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1212c4bf6374SJason M. Bills         logEntryArray = nlohmann::json::array();
121395820184SJason M. Bills         // Go through the log files and create a unique ID for each entry
121495820184SJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
121595820184SJason M. Bills         getRedfishLogFiles(redfishLogFiles);
1216b01bf299SEd Tanous         uint64_t entryCount = 0;
1217cd225da8SJason M. Bills         std::string logEntry;
121895820184SJason M. Bills 
121995820184SJason M. Bills         // Oldest logs are in the last file, so start there and loop backwards
1220cd225da8SJason M. Bills         for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1221cd225da8SJason M. Bills              it++)
1222c4bf6374SJason M. Bills         {
1223cd225da8SJason M. Bills             std::ifstream logStream(*it);
122495820184SJason M. Bills             if (!logStream.is_open())
1225c4bf6374SJason M. Bills             {
1226c4bf6374SJason M. Bills                 continue;
1227c4bf6374SJason M. Bills             }
1228c4bf6374SJason M. Bills 
1229e85d6b16SJason M. Bills             // Reset the unique ID on the first entry
1230e85d6b16SJason M. Bills             bool firstEntry = true;
123195820184SJason M. Bills             while (std::getline(logStream, logEntry))
123295820184SJason M. Bills             {
1233c4bf6374SJason M. Bills                 entryCount++;
1234c4bf6374SJason M. Bills                 // Handle paging using skip (number of entries to skip from the
1235c4bf6374SJason M. Bills                 // start) and top (number of entries to display)
1236c4bf6374SJason M. Bills                 if (entryCount <= skip || entryCount > skip + top)
1237c4bf6374SJason M. Bills                 {
1238c4bf6374SJason M. Bills                     continue;
1239c4bf6374SJason M. Bills                 }
1240c4bf6374SJason M. Bills 
1241c4bf6374SJason M. Bills                 std::string idStr;
1242e85d6b16SJason M. Bills                 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1243c4bf6374SJason M. Bills                 {
1244c4bf6374SJason M. Bills                     continue;
1245c4bf6374SJason M. Bills                 }
1246c4bf6374SJason M. Bills 
1247e85d6b16SJason M. Bills                 if (firstEntry)
1248e85d6b16SJason M. Bills                 {
1249e85d6b16SJason M. Bills                     firstEntry = false;
1250e85d6b16SJason M. Bills                 }
1251e85d6b16SJason M. Bills 
1252c4bf6374SJason M. Bills                 logEntryArray.push_back({});
1253c4bf6374SJason M. Bills                 nlohmann::json& bmcLogEntry = logEntryArray.back();
125495820184SJason M. Bills                 if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0)
1255c4bf6374SJason M. Bills                 {
1256c4bf6374SJason M. Bills                     messages::internalError(asyncResp->res);
1257c4bf6374SJason M. Bills                     return;
1258c4bf6374SJason M. Bills                 }
1259c4bf6374SJason M. Bills             }
126095820184SJason M. Bills         }
1261c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1262c4bf6374SJason M. Bills         if (skip + top < entryCount)
1263c4bf6374SJason M. Bills         {
1264c4bf6374SJason M. Bills             asyncResp->res.jsonValue["Members@odata.nextLink"] =
126595820184SJason M. Bills                 "/redfish/v1/Systems/system/LogServices/EventLog/"
126695820184SJason M. Bills                 "Entries?$skip=" +
1267c4bf6374SJason M. Bills                 std::to_string(skip + top);
1268c4bf6374SJason M. Bills         }
126908a4e4b5SAnthony Wilson     }
127008a4e4b5SAnthony Wilson };
127108a4e4b5SAnthony Wilson 
1272897967deSJason M. Bills class JournalEventLogEntry : public Node
1273897967deSJason M. Bills {
1274897967deSJason M. Bills   public:
127552cc112dSEd Tanous     JournalEventLogEntry(App& app) :
1276897967deSJason M. Bills         Node(app,
1277897967deSJason M. Bills              "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1278897967deSJason M. Bills              std::string())
1279897967deSJason M. Bills     {
1280897967deSJason M. Bills         entityPrivileges = {
1281897967deSJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1282897967deSJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1283897967deSJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1284897967deSJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1285897967deSJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1286897967deSJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1287897967deSJason M. Bills     }
1288897967deSJason M. Bills 
1289897967deSJason M. Bills   private:
1290cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
1291897967deSJason M. Bills                const std::vector<std::string>& params) override
1292897967deSJason M. Bills     {
1293897967deSJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1294897967deSJason M. Bills         if (params.size() != 1)
1295897967deSJason M. Bills         {
1296897967deSJason M. Bills             messages::internalError(asyncResp->res);
1297897967deSJason M. Bills             return;
1298897967deSJason M. Bills         }
1299897967deSJason M. Bills         const std::string& targetID = params[0];
1300897967deSJason M. Bills 
1301897967deSJason M. Bills         // Go through the log files and check the unique ID for each entry to
1302897967deSJason M. Bills         // find the target entry
1303897967deSJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
1304897967deSJason M. Bills         getRedfishLogFiles(redfishLogFiles);
1305897967deSJason M. Bills         std::string logEntry;
1306897967deSJason M. Bills 
1307897967deSJason M. Bills         // Oldest logs are in the last file, so start there and loop backwards
1308897967deSJason M. Bills         for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1309897967deSJason M. Bills              it++)
1310897967deSJason M. Bills         {
1311897967deSJason M. Bills             std::ifstream logStream(*it);
1312897967deSJason M. Bills             if (!logStream.is_open())
1313897967deSJason M. Bills             {
1314897967deSJason M. Bills                 continue;
1315897967deSJason M. Bills             }
1316897967deSJason M. Bills 
1317897967deSJason M. Bills             // Reset the unique ID on the first entry
1318897967deSJason M. Bills             bool firstEntry = true;
1319897967deSJason M. Bills             while (std::getline(logStream, logEntry))
1320897967deSJason M. Bills             {
1321897967deSJason M. Bills                 std::string idStr;
1322897967deSJason M. Bills                 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1323897967deSJason M. Bills                 {
1324897967deSJason M. Bills                     continue;
1325897967deSJason M. Bills                 }
1326897967deSJason M. Bills 
1327897967deSJason M. Bills                 if (firstEntry)
1328897967deSJason M. Bills                 {
1329897967deSJason M. Bills                     firstEntry = false;
1330897967deSJason M. Bills                 }
1331897967deSJason M. Bills 
1332897967deSJason M. Bills                 if (idStr == targetID)
1333897967deSJason M. Bills                 {
1334897967deSJason M. Bills                     if (fillEventLogEntryJson(idStr, logEntry,
1335897967deSJason M. Bills                                               asyncResp->res.jsonValue) != 0)
1336897967deSJason M. Bills                     {
1337897967deSJason M. Bills                         messages::internalError(asyncResp->res);
1338897967deSJason M. Bills                         return;
1339897967deSJason M. Bills                     }
1340897967deSJason M. Bills                     return;
1341897967deSJason M. Bills                 }
1342897967deSJason M. Bills             }
1343897967deSJason M. Bills         }
1344897967deSJason M. Bills         // Requested ID was not found
1345897967deSJason M. Bills         messages::resourceMissingAtURI(asyncResp->res, targetID);
1346897967deSJason M. Bills     }
1347897967deSJason M. Bills };
1348897967deSJason M. Bills 
134908a4e4b5SAnthony Wilson class DBusEventLogEntryCollection : public Node
135008a4e4b5SAnthony Wilson {
135108a4e4b5SAnthony Wilson   public:
135252cc112dSEd Tanous     DBusEventLogEntryCollection(App& app) :
135308a4e4b5SAnthony Wilson         Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
135408a4e4b5SAnthony Wilson     {
135508a4e4b5SAnthony Wilson         entityPrivileges = {
135608a4e4b5SAnthony Wilson             {boost::beast::http::verb::get, {{"Login"}}},
135708a4e4b5SAnthony Wilson             {boost::beast::http::verb::head, {{"Login"}}},
135808a4e4b5SAnthony Wilson             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
135908a4e4b5SAnthony Wilson             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
136008a4e4b5SAnthony Wilson             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
136108a4e4b5SAnthony Wilson             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
136208a4e4b5SAnthony Wilson     }
136308a4e4b5SAnthony Wilson 
136408a4e4b5SAnthony Wilson   private:
1365cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
1366cb13a392SEd Tanous                const std::vector<std::string>&) override
136708a4e4b5SAnthony Wilson     {
136808a4e4b5SAnthony Wilson         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
136908a4e4b5SAnthony Wilson 
137008a4e4b5SAnthony Wilson         // Collections don't include the static data added by SubRoute because
137108a4e4b5SAnthony Wilson         // it has a duplicate entry for members
137208a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["@odata.type"] =
137308a4e4b5SAnthony Wilson             "#LogEntryCollection.LogEntryCollection";
137408a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["@odata.id"] =
137508a4e4b5SAnthony Wilson             "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
137608a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
137708a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["Description"] =
137808a4e4b5SAnthony Wilson             "Collection of System Event Log Entries";
137908a4e4b5SAnthony Wilson 
1380cb92c03bSAndrew Geissler         // DBus implementation of EventLog/Entries
1381cb92c03bSAndrew Geissler         // Make call to Logging Service to find all log entry objects
1382cb92c03bSAndrew Geissler         crow::connections::systemBus->async_method_call(
1383cb92c03bSAndrew Geissler             [asyncResp](const boost::system::error_code ec,
1384cb92c03bSAndrew Geissler                         GetManagedObjectsType& resp) {
1385cb92c03bSAndrew Geissler                 if (ec)
1386cb92c03bSAndrew Geissler                 {
1387cb92c03bSAndrew Geissler                     // TODO Handle for specific error code
1388cb92c03bSAndrew Geissler                     BMCWEB_LOG_ERROR
1389cb92c03bSAndrew Geissler                         << "getLogEntriesIfaceData resp_handler got error "
1390cb92c03bSAndrew Geissler                         << ec;
1391cb92c03bSAndrew Geissler                     messages::internalError(asyncResp->res);
1392cb92c03bSAndrew Geissler                     return;
1393cb92c03bSAndrew Geissler                 }
1394cb92c03bSAndrew Geissler                 nlohmann::json& entriesArray =
1395cb92c03bSAndrew Geissler                     asyncResp->res.jsonValue["Members"];
1396cb92c03bSAndrew Geissler                 entriesArray = nlohmann::json::array();
1397cb92c03bSAndrew Geissler                 for (auto& objectPath : resp)
1398cb92c03bSAndrew Geissler                 {
139966664f25SEd Tanous                     uint32_t* id = nullptr;
140066664f25SEd Tanous                     std::time_t timestamp{};
1401d139c236SGeorge Liu                     std::time_t updateTimestamp{};
140266664f25SEd Tanous                     std::string* severity = nullptr;
140366664f25SEd Tanous                     std::string* message = nullptr;
1404*f86bb901SAdriana Kobylak                     std::string* filePath = nullptr;
140575710de2SXiaochao Ma                     bool resolved = false;
1406*f86bb901SAdriana Kobylak                     for (auto& interfaceMap : objectPath.second)
1407*f86bb901SAdriana Kobylak                     {
1408*f86bb901SAdriana Kobylak                         if (interfaceMap.first ==
1409*f86bb901SAdriana Kobylak                             "xyz.openbmc_project.Logging.Entry")
1410*f86bb901SAdriana Kobylak                         {
1411cb92c03bSAndrew Geissler                             for (auto& propertyMap : interfaceMap.second)
1412cb92c03bSAndrew Geissler                             {
1413cb92c03bSAndrew Geissler                                 if (propertyMap.first == "Id")
1414cb92c03bSAndrew Geissler                                 {
1415*f86bb901SAdriana Kobylak                                     id = std::get_if<uint32_t>(
1416*f86bb901SAdriana Kobylak                                         &propertyMap.second);
1417cb92c03bSAndrew Geissler                                 }
1418cb92c03bSAndrew Geissler                                 else if (propertyMap.first == "Timestamp")
1419cb92c03bSAndrew Geissler                                 {
1420cb92c03bSAndrew Geissler                                     const uint64_t* millisTimeStamp =
1421*f86bb901SAdriana Kobylak                                         std::get_if<uint64_t>(
1422*f86bb901SAdriana Kobylak                                             &propertyMap.second);
1423ae34c8e8SAdriana Kobylak                                     if (millisTimeStamp != nullptr)
1424ebd45906SGeorge Liu                                     {
1425d139c236SGeorge Liu                                         timestamp = crow::utility::getTimestamp(
1426cb92c03bSAndrew Geissler                                             *millisTimeStamp);
1427d139c236SGeorge Liu                                     }
1428ebd45906SGeorge Liu                                 }
1429d139c236SGeorge Liu                                 else if (propertyMap.first == "UpdateTimestamp")
1430d139c236SGeorge Liu                                 {
1431d139c236SGeorge Liu                                     const uint64_t* millisTimeStamp =
1432*f86bb901SAdriana Kobylak                                         std::get_if<uint64_t>(
1433*f86bb901SAdriana Kobylak                                             &propertyMap.second);
1434ae34c8e8SAdriana Kobylak                                     if (millisTimeStamp != nullptr)
1435ebd45906SGeorge Liu                                     {
1436ebd45906SGeorge Liu                                         updateTimestamp =
1437ebd45906SGeorge Liu                                             crow::utility::getTimestamp(
1438d139c236SGeorge Liu                                                 *millisTimeStamp);
1439cb92c03bSAndrew Geissler                                     }
1440ebd45906SGeorge Liu                                 }
1441cb92c03bSAndrew Geissler                                 else if (propertyMap.first == "Severity")
1442cb92c03bSAndrew Geissler                                 {
1443cb92c03bSAndrew Geissler                                     severity = std::get_if<std::string>(
1444cb92c03bSAndrew Geissler                                         &propertyMap.second);
1445cb92c03bSAndrew Geissler                                 }
1446cb92c03bSAndrew Geissler                                 else if (propertyMap.first == "Message")
1447cb92c03bSAndrew Geissler                                 {
1448cb92c03bSAndrew Geissler                                     message = std::get_if<std::string>(
1449cb92c03bSAndrew Geissler                                         &propertyMap.second);
1450ae34c8e8SAdriana Kobylak                                 }
145175710de2SXiaochao Ma                                 else if (propertyMap.first == "Resolved")
145275710de2SXiaochao Ma                                 {
145375710de2SXiaochao Ma                                     bool* resolveptr =
145475710de2SXiaochao Ma                                         std::get_if<bool>(&propertyMap.second);
145575710de2SXiaochao Ma                                     if (resolveptr == nullptr)
145675710de2SXiaochao Ma                                     {
145775710de2SXiaochao Ma                                         messages::internalError(asyncResp->res);
145875710de2SXiaochao Ma                                         return;
145975710de2SXiaochao Ma                                     }
146075710de2SXiaochao Ma                                     resolved = *resolveptr;
146175710de2SXiaochao Ma                                 }
1462ae34c8e8SAdriana Kobylak                             }
1463ae34c8e8SAdriana Kobylak                             if (id == nullptr || message == nullptr ||
1464ae34c8e8SAdriana Kobylak                                 severity == nullptr)
1465cb92c03bSAndrew Geissler                             {
14660f1d8ed9SAsmitha Karunanithi                                 messages::internalError(asyncResp->res);
1467ae34c8e8SAdriana Kobylak                                 return;
1468cb92c03bSAndrew Geissler                             }
1469*f86bb901SAdriana Kobylak                         }
1470*f86bb901SAdriana Kobylak                         else if (interfaceMap.first ==
1471*f86bb901SAdriana Kobylak                                  "xyz.openbmc_project.Common.FilePath")
1472*f86bb901SAdriana Kobylak                         {
1473*f86bb901SAdriana Kobylak                             for (auto& propertyMap : interfaceMap.second)
1474*f86bb901SAdriana Kobylak                             {
1475*f86bb901SAdriana Kobylak                                 if (propertyMap.first == "Path")
1476*f86bb901SAdriana Kobylak                                 {
1477*f86bb901SAdriana Kobylak                                     filePath = std::get_if<std::string>(
1478*f86bb901SAdriana Kobylak                                         &propertyMap.second);
1479*f86bb901SAdriana Kobylak                                 }
1480*f86bb901SAdriana Kobylak                             }
1481*f86bb901SAdriana Kobylak                         }
1482*f86bb901SAdriana Kobylak                     }
1483*f86bb901SAdriana Kobylak                     // Object path without the xyz.openbmc_project.Logging.Entry
1484*f86bb901SAdriana Kobylak                     // interface, ignore and continue.
1485*f86bb901SAdriana Kobylak                     if (id == nullptr || message == nullptr ||
1486*f86bb901SAdriana Kobylak                         severity == nullptr)
1487*f86bb901SAdriana Kobylak                     {
1488*f86bb901SAdriana Kobylak                         continue;
1489*f86bb901SAdriana Kobylak                     }
1490*f86bb901SAdriana Kobylak                     entriesArray.push_back({});
1491*f86bb901SAdriana Kobylak                     nlohmann::json& thisEntry = entriesArray.back();
1492*f86bb901SAdriana Kobylak                     thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry";
1493*f86bb901SAdriana Kobylak                     thisEntry["@odata.id"] = "/redfish/v1/Systems/system/"
1494*f86bb901SAdriana Kobylak                                              "LogServices/EventLog/Entries/" +
1495*f86bb901SAdriana Kobylak                                              std::to_string(*id);
1496*f86bb901SAdriana Kobylak                     thisEntry["Name"] = "System Event Log Entry";
1497*f86bb901SAdriana Kobylak                     thisEntry["Id"] = std::to_string(*id);
1498*f86bb901SAdriana Kobylak                     thisEntry["Message"] = *message;
1499*f86bb901SAdriana Kobylak                     thisEntry["Resolved"] = resolved;
1500*f86bb901SAdriana Kobylak                     thisEntry["EntryType"] = "Event";
1501*f86bb901SAdriana Kobylak                     thisEntry["Severity"] =
1502*f86bb901SAdriana Kobylak                         translateSeverityDbusToRedfish(*severity);
1503*f86bb901SAdriana Kobylak                     thisEntry["Created"] =
1504*f86bb901SAdriana Kobylak                         crow::utility::getDateTime(timestamp);
1505*f86bb901SAdriana Kobylak                     thisEntry["Modified"] =
1506*f86bb901SAdriana Kobylak                         crow::utility::getDateTime(updateTimestamp);
1507*f86bb901SAdriana Kobylak                     if (filePath != nullptr)
1508*f86bb901SAdriana Kobylak                     {
1509*f86bb901SAdriana Kobylak                         thisEntry["AdditionalDataURI"] =
1510cb92c03bSAndrew Geissler                             "/redfish/v1/Systems/system/LogServices/EventLog/"
1511*f86bb901SAdriana Kobylak                             "attachment/" +
1512*f86bb901SAdriana Kobylak                             std::to_string(*id);
1513cb92c03bSAndrew Geissler                     }
1514cb92c03bSAndrew Geissler                 }
1515cb92c03bSAndrew Geissler                 std::sort(entriesArray.begin(), entriesArray.end(),
1516cb92c03bSAndrew Geissler                           [](const nlohmann::json& left,
1517cb92c03bSAndrew Geissler                              const nlohmann::json& right) {
1518cb92c03bSAndrew Geissler                               return (left["Id"] <= right["Id"]);
1519cb92c03bSAndrew Geissler                           });
1520cb92c03bSAndrew Geissler                 asyncResp->res.jsonValue["Members@odata.count"] =
1521cb92c03bSAndrew Geissler                     entriesArray.size();
1522cb92c03bSAndrew Geissler             },
1523cb92c03bSAndrew Geissler             "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
1524cb92c03bSAndrew Geissler             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
1525c4bf6374SJason M. Bills     }
1526c4bf6374SJason M. Bills };
1527c4bf6374SJason M. Bills 
152808a4e4b5SAnthony Wilson class DBusEventLogEntry : public Node
1529c4bf6374SJason M. Bills {
1530c4bf6374SJason M. Bills   public:
153152cc112dSEd Tanous     DBusEventLogEntry(App& app) :
1532c4bf6374SJason M. Bills         Node(app,
1533029573d4SEd Tanous              "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1534029573d4SEd Tanous              std::string())
1535c4bf6374SJason M. Bills     {
1536c4bf6374SJason M. Bills         entityPrivileges = {
1537c4bf6374SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1538c4bf6374SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1539c4bf6374SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1540c4bf6374SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1541c4bf6374SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1542c4bf6374SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1543c4bf6374SJason M. Bills     }
1544c4bf6374SJason M. Bills 
1545c4bf6374SJason M. Bills   private:
1546cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
1547c4bf6374SJason M. Bills                const std::vector<std::string>& params) override
1548c4bf6374SJason M. Bills     {
1549c4bf6374SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1550029573d4SEd Tanous         if (params.size() != 1)
1551c4bf6374SJason M. Bills         {
1552c4bf6374SJason M. Bills             messages::internalError(asyncResp->res);
1553c4bf6374SJason M. Bills             return;
1554c4bf6374SJason M. Bills         }
1555ae34c8e8SAdriana Kobylak         std::string entryID = params[0];
1556ae34c8e8SAdriana Kobylak         dbus::utility::escapePathForDbus(entryID);
1557cb92c03bSAndrew Geissler 
1558cb92c03bSAndrew Geissler         // DBus implementation of EventLog/Entries
1559cb92c03bSAndrew Geissler         // Make call to Logging Service to find all log entry objects
1560cb92c03bSAndrew Geissler         crow::connections::systemBus->async_method_call(
1561cb92c03bSAndrew Geissler             [asyncResp, entryID](const boost::system::error_code ec,
1562cb92c03bSAndrew Geissler                                  GetManagedPropertyType& resp) {
1563ae34c8e8SAdriana Kobylak                 if (ec.value() == EBADR)
1564ae34c8e8SAdriana Kobylak                 {
1565ae34c8e8SAdriana Kobylak                     messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1566ae34c8e8SAdriana Kobylak                                                entryID);
1567ae34c8e8SAdriana Kobylak                     return;
1568ae34c8e8SAdriana Kobylak                 }
1569cb92c03bSAndrew Geissler                 if (ec)
1570cb92c03bSAndrew Geissler                 {
1571cb92c03bSAndrew Geissler                     BMCWEB_LOG_ERROR
1572cb92c03bSAndrew Geissler                         << "EventLogEntry (DBus) resp_handler got error " << ec;
1573cb92c03bSAndrew Geissler                     messages::internalError(asyncResp->res);
1574cb92c03bSAndrew Geissler                     return;
1575cb92c03bSAndrew Geissler                 }
157666664f25SEd Tanous                 uint32_t* id = nullptr;
157766664f25SEd Tanous                 std::time_t timestamp{};
1578d139c236SGeorge Liu                 std::time_t updateTimestamp{};
157966664f25SEd Tanous                 std::string* severity = nullptr;
158066664f25SEd Tanous                 std::string* message = nullptr;
1581*f86bb901SAdriana Kobylak                 std::string* filePath = nullptr;
158275710de2SXiaochao Ma                 bool resolved = false;
1583d139c236SGeorge Liu 
1584cb92c03bSAndrew Geissler                 for (auto& propertyMap : resp)
1585cb92c03bSAndrew Geissler                 {
1586cb92c03bSAndrew Geissler                     if (propertyMap.first == "Id")
1587cb92c03bSAndrew Geissler                     {
1588cb92c03bSAndrew Geissler                         id = std::get_if<uint32_t>(&propertyMap.second);
1589cb92c03bSAndrew Geissler                     }
1590cb92c03bSAndrew Geissler                     else if (propertyMap.first == "Timestamp")
1591cb92c03bSAndrew Geissler                     {
1592cb92c03bSAndrew Geissler                         const uint64_t* millisTimeStamp =
1593cb92c03bSAndrew Geissler                             std::get_if<uint64_t>(&propertyMap.second);
1594ae34c8e8SAdriana Kobylak                         if (millisTimeStamp != nullptr)
1595ebd45906SGeorge Liu                         {
1596cb92c03bSAndrew Geissler                             timestamp =
1597d139c236SGeorge Liu                                 crow::utility::getTimestamp(*millisTimeStamp);
1598d139c236SGeorge Liu                         }
1599ebd45906SGeorge Liu                     }
1600d139c236SGeorge Liu                     else if (propertyMap.first == "UpdateTimestamp")
1601d139c236SGeorge Liu                     {
1602d139c236SGeorge Liu                         const uint64_t* millisTimeStamp =
1603d139c236SGeorge Liu                             std::get_if<uint64_t>(&propertyMap.second);
1604ae34c8e8SAdriana Kobylak                         if (millisTimeStamp != nullptr)
1605ebd45906SGeorge Liu                         {
1606d139c236SGeorge Liu                             updateTimestamp =
1607d139c236SGeorge Liu                                 crow::utility::getTimestamp(*millisTimeStamp);
1608cb92c03bSAndrew Geissler                         }
1609ebd45906SGeorge Liu                     }
1610cb92c03bSAndrew Geissler                     else if (propertyMap.first == "Severity")
1611cb92c03bSAndrew Geissler                     {
1612cb92c03bSAndrew Geissler                         severity =
1613cb92c03bSAndrew Geissler                             std::get_if<std::string>(&propertyMap.second);
1614cb92c03bSAndrew Geissler                     }
1615cb92c03bSAndrew Geissler                     else if (propertyMap.first == "Message")
1616cb92c03bSAndrew Geissler                     {
1617cb92c03bSAndrew Geissler                         message = std::get_if<std::string>(&propertyMap.second);
1618cb92c03bSAndrew Geissler                     }
161975710de2SXiaochao Ma                     else if (propertyMap.first == "Resolved")
162075710de2SXiaochao Ma                     {
162175710de2SXiaochao Ma                         bool* resolveptr =
162275710de2SXiaochao Ma                             std::get_if<bool>(&propertyMap.second);
162375710de2SXiaochao Ma                         if (resolveptr == nullptr)
162475710de2SXiaochao Ma                         {
162575710de2SXiaochao Ma                             messages::internalError(asyncResp->res);
162675710de2SXiaochao Ma                             return;
162775710de2SXiaochao Ma                         }
162875710de2SXiaochao Ma                         resolved = *resolveptr;
162975710de2SXiaochao Ma                     }
1630*f86bb901SAdriana Kobylak                     else if (propertyMap.first == "Path")
1631*f86bb901SAdriana Kobylak                     {
1632*f86bb901SAdriana Kobylak                         filePath =
1633*f86bb901SAdriana Kobylak                             std::get_if<std::string>(&propertyMap.second);
1634*f86bb901SAdriana Kobylak                     }
1635cb92c03bSAndrew Geissler                 }
1636271584abSEd Tanous                 if (id == nullptr || message == nullptr || severity == nullptr)
1637271584abSEd Tanous                 {
1638ae34c8e8SAdriana Kobylak                     messages::internalError(asyncResp->res);
1639271584abSEd Tanous                     return;
1640271584abSEd Tanous                 }
1641*f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["@odata.type"] =
1642*f86bb901SAdriana Kobylak                     "#LogEntry.v1_8_0.LogEntry";
1643*f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["@odata.id"] =
1644*f86bb901SAdriana Kobylak                     "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
1645*f86bb901SAdriana Kobylak                     std::to_string(*id);
1646*f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["Name"] = "System Event Log Entry";
1647*f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["Id"] = std::to_string(*id);
1648*f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["Message"] = *message;
1649*f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["Resolved"] = resolved;
1650*f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["EntryType"] = "Event";
1651*f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["Severity"] =
1652*f86bb901SAdriana Kobylak                     translateSeverityDbusToRedfish(*severity);
1653*f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["Created"] =
1654*f86bb901SAdriana Kobylak                     crow::utility::getDateTime(timestamp);
1655*f86bb901SAdriana Kobylak                 asyncResp->res.jsonValue["Modified"] =
1656*f86bb901SAdriana Kobylak                     crow::utility::getDateTime(updateTimestamp);
1657*f86bb901SAdriana Kobylak                 if (filePath != nullptr)
1658*f86bb901SAdriana Kobylak                 {
1659*f86bb901SAdriana Kobylak                     asyncResp->res.jsonValue["AdditionalDataURI"] =
1660cb92c03bSAndrew Geissler                         "/redfish/v1/Systems/system/LogServices/EventLog/"
1661*f86bb901SAdriana Kobylak                         "attachment/" +
1662*f86bb901SAdriana Kobylak                         std::to_string(*id);
1663*f86bb901SAdriana Kobylak                 }
1664cb92c03bSAndrew Geissler             },
1665cb92c03bSAndrew Geissler             "xyz.openbmc_project.Logging",
1666cb92c03bSAndrew Geissler             "/xyz/openbmc_project/logging/entry/" + entryID,
1667*f86bb901SAdriana Kobylak             "org.freedesktop.DBus.Properties", "GetAll", "");
1668c4bf6374SJason M. Bills     }
1669336e96c6SChicago Duan 
167075710de2SXiaochao Ma     void doPatch(crow::Response& res, const crow::Request& req,
167175710de2SXiaochao Ma                  const std::vector<std::string>& params) override
167275710de2SXiaochao Ma     {
167375710de2SXiaochao Ma         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
167475710de2SXiaochao Ma 
167575710de2SXiaochao Ma         if (params.size() != 1)
167675710de2SXiaochao Ma         {
167775710de2SXiaochao Ma             messages::internalError(asyncResp->res);
167875710de2SXiaochao Ma             return;
167975710de2SXiaochao Ma         }
168075710de2SXiaochao Ma         std::string entryId = params[0];
168175710de2SXiaochao Ma 
168275710de2SXiaochao Ma         std::optional<bool> resolved;
168375710de2SXiaochao Ma 
168475710de2SXiaochao Ma         if (!json_util::readJson(req, res, "Resolved", resolved))
168575710de2SXiaochao Ma         {
168675710de2SXiaochao Ma             return;
168775710de2SXiaochao Ma         }
168875710de2SXiaochao Ma 
168975710de2SXiaochao Ma         if (resolved)
169075710de2SXiaochao Ma         {
169175710de2SXiaochao Ma             BMCWEB_LOG_DEBUG << "Set Resolved";
169275710de2SXiaochao Ma 
169375710de2SXiaochao Ma             crow::connections::systemBus->async_method_call(
169475710de2SXiaochao Ma                 [asyncResp, resolved,
169575710de2SXiaochao Ma                  entryId](const boost::system::error_code ec) {
169675710de2SXiaochao Ma                     if (ec)
169775710de2SXiaochao Ma                     {
169875710de2SXiaochao Ma                         BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
169975710de2SXiaochao Ma                         messages::internalError(asyncResp->res);
170075710de2SXiaochao Ma                         return;
170175710de2SXiaochao Ma                     }
170275710de2SXiaochao Ma                 },
170375710de2SXiaochao Ma                 "xyz.openbmc_project.Logging",
170475710de2SXiaochao Ma                 "/xyz/openbmc_project/logging/entry/" + entryId,
170575710de2SXiaochao Ma                 "org.freedesktop.DBus.Properties", "Set",
170675710de2SXiaochao Ma                 "xyz.openbmc_project.Logging.Entry", "Resolved",
170775710de2SXiaochao Ma                 std::variant<bool>(*resolved));
170875710de2SXiaochao Ma         }
170975710de2SXiaochao Ma     }
171075710de2SXiaochao Ma 
1711cb13a392SEd Tanous     void doDelete(crow::Response& res, const crow::Request&,
1712336e96c6SChicago Duan                   const std::vector<std::string>& params) override
1713336e96c6SChicago Duan     {
1714336e96c6SChicago Duan 
1715336e96c6SChicago Duan         BMCWEB_LOG_DEBUG << "Do delete single event entries.";
1716336e96c6SChicago Duan 
1717336e96c6SChicago Duan         auto asyncResp = std::make_shared<AsyncResp>(res);
1718336e96c6SChicago Duan 
1719336e96c6SChicago Duan         if (params.size() != 1)
1720336e96c6SChicago Duan         {
1721336e96c6SChicago Duan             messages::internalError(asyncResp->res);
1722336e96c6SChicago Duan             return;
1723336e96c6SChicago Duan         }
1724336e96c6SChicago Duan         std::string entryID = params[0];
1725336e96c6SChicago Duan 
1726336e96c6SChicago Duan         dbus::utility::escapePathForDbus(entryID);
1727336e96c6SChicago Duan 
1728336e96c6SChicago Duan         // Process response from Logging service.
17293de8d8baSGeorge Liu         auto respHandler = [asyncResp,
17303de8d8baSGeorge Liu                             entryID](const boost::system::error_code ec) {
1731336e96c6SChicago Duan             BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done";
1732336e96c6SChicago Duan             if (ec)
1733336e96c6SChicago Duan             {
17343de8d8baSGeorge Liu                 if (ec.value() == EBADR)
17353de8d8baSGeorge Liu                 {
17363de8d8baSGeorge Liu                     messages::resourceNotFound(asyncResp->res, "LogEntry",
17373de8d8baSGeorge Liu                                                entryID);
17383de8d8baSGeorge Liu                     return;
17393de8d8baSGeorge Liu                 }
1740336e96c6SChicago Duan                 // TODO Handle for specific error code
1741336e96c6SChicago Duan                 BMCWEB_LOG_ERROR
1742336e96c6SChicago Duan                     << "EventLogEntry (DBus) doDelete respHandler got error "
1743336e96c6SChicago Duan                     << ec;
1744336e96c6SChicago Duan                 asyncResp->res.result(
1745336e96c6SChicago Duan                     boost::beast::http::status::internal_server_error);
1746336e96c6SChicago Duan                 return;
1747336e96c6SChicago Duan             }
1748336e96c6SChicago Duan 
1749336e96c6SChicago Duan             asyncResp->res.result(boost::beast::http::status::ok);
1750336e96c6SChicago Duan         };
1751336e96c6SChicago Duan 
1752336e96c6SChicago Duan         // Make call to Logging service to request Delete Log
1753336e96c6SChicago Duan         crow::connections::systemBus->async_method_call(
1754336e96c6SChicago Duan             respHandler, "xyz.openbmc_project.Logging",
1755336e96c6SChicago Duan             "/xyz/openbmc_project/logging/entry/" + entryID,
1756336e96c6SChicago Duan             "xyz.openbmc_project.Object.Delete", "Delete");
1757336e96c6SChicago Duan     }
1758c4bf6374SJason M. Bills };
1759c4bf6374SJason M. Bills 
1760c4bf6374SJason M. Bills class BMCLogServiceCollection : public Node
1761c4bf6374SJason M. Bills {
1762c4bf6374SJason M. Bills   public:
176352cc112dSEd Tanous     BMCLogServiceCollection(App& app) :
17644ed77cd5SEd Tanous         Node(app, "/redfish/v1/Managers/bmc/LogServices/")
17651da66f75SEd Tanous     {
17661da66f75SEd Tanous         entityPrivileges = {
1767e1f26343SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1768e1f26343SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1769e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1770e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1771e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1772e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
17731da66f75SEd Tanous     }
17741da66f75SEd Tanous 
17751da66f75SEd Tanous   private:
17761da66f75SEd Tanous     /**
17771da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
17781da66f75SEd Tanous      */
1779cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
1780cb13a392SEd Tanous                const std::vector<std::string>&) override
17811da66f75SEd Tanous     {
1782e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
17831da66f75SEd Tanous         // Collections don't include the static data added by SubRoute because
17841da66f75SEd Tanous         // it has a duplicate entry for members
1785e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
17861da66f75SEd Tanous             "#LogServiceCollection.LogServiceCollection";
1787e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1788e1f26343SJason M. Bills             "/redfish/v1/Managers/bmc/LogServices";
1789e1f26343SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1790e1f26343SJason M. Bills         asyncResp->res.jsonValue["Description"] =
17911da66f75SEd Tanous             "Collection of LogServices for this Manager";
1792c4bf6374SJason M. Bills         nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1793c4bf6374SJason M. Bills         logServiceArray = nlohmann::json::array();
17945cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
17955cb1dd27SAsmitha Karunanithi         logServiceArray.push_back(
17965cb1dd27SAsmitha Karunanithi             {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}});
17975cb1dd27SAsmitha Karunanithi #endif
1798c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
1799c4bf6374SJason M. Bills         logServiceArray.push_back(
180008a4e4b5SAnthony Wilson             {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}});
1801c4bf6374SJason M. Bills #endif
1802e1f26343SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] =
1803c4bf6374SJason M. Bills             logServiceArray.size();
18041da66f75SEd Tanous     }
18051da66f75SEd Tanous };
18061da66f75SEd Tanous 
1807c4bf6374SJason M. Bills class BMCJournalLogService : public Node
18081da66f75SEd Tanous {
18091da66f75SEd Tanous   public:
181052cc112dSEd Tanous     BMCJournalLogService(App& app) :
1811c4bf6374SJason M. Bills         Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
1812e1f26343SJason M. Bills     {
1813e1f26343SJason M. Bills         entityPrivileges = {
1814e1f26343SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1815e1f26343SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1816e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1817e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1818e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1819e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1820e1f26343SJason M. Bills     }
1821e1f26343SJason M. Bills 
1822e1f26343SJason M. Bills   private:
1823cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
1824cb13a392SEd Tanous                const std::vector<std::string>&) override
1825e1f26343SJason M. Bills     {
1826e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1827e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1828e1f26343SJason M. Bills             "#LogService.v1_1_0.LogService";
18290f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
18300f74e643SEd Tanous             "/redfish/v1/Managers/bmc/LogServices/Journal";
1831c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service";
1832c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service";
1833c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Id"] = "BMC Journal";
1834e1f26343SJason M. Bills         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1835cd50aa42SJason M. Bills         asyncResp->res.jsonValue["Entries"] = {
1836cd50aa42SJason M. Bills             {"@odata.id",
1837086be238SEd Tanous              "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}};
1838e1f26343SJason M. Bills     }
1839e1f26343SJason M. Bills };
1840e1f26343SJason M. Bills 
1841c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID,
1842e1f26343SJason M. Bills                                       sd_journal* journal,
1843c4bf6374SJason M. Bills                                       nlohmann::json& bmcJournalLogEntryJson)
1844e1f26343SJason M. Bills {
1845e1f26343SJason M. Bills     // Get the Log Entry contents
1846e1f26343SJason M. Bills     int ret = 0;
1847e1f26343SJason M. Bills 
1848a8fe54f0SJason M. Bills     std::string message;
1849a8fe54f0SJason M. Bills     std::string_view syslogID;
1850a8fe54f0SJason M. Bills     ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID);
1851a8fe54f0SJason M. Bills     if (ret < 0)
1852a8fe54f0SJason M. Bills     {
1853a8fe54f0SJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: "
1854a8fe54f0SJason M. Bills                          << strerror(-ret);
1855a8fe54f0SJason M. Bills     }
1856a8fe54f0SJason M. Bills     if (!syslogID.empty())
1857a8fe54f0SJason M. Bills     {
1858a8fe54f0SJason M. Bills         message += std::string(syslogID) + ": ";
1859a8fe54f0SJason M. Bills     }
1860a8fe54f0SJason M. Bills 
186139e77504SEd Tanous     std::string_view msg;
186216428a1aSJason M. Bills     ret = getJournalMetadata(journal, "MESSAGE", msg);
1863e1f26343SJason M. Bills     if (ret < 0)
1864e1f26343SJason M. Bills     {
1865e1f26343SJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret);
1866e1f26343SJason M. Bills         return 1;
1867e1f26343SJason M. Bills     }
1868a8fe54f0SJason M. Bills     message += std::string(msg);
1869e1f26343SJason M. Bills 
1870e1f26343SJason M. Bills     // Get the severity from the PRIORITY field
1871271584abSEd Tanous     long int severity = 8; // Default to an invalid priority
187216428a1aSJason M. Bills     ret = getJournalMetadata(journal, "PRIORITY", 10, severity);
1873e1f26343SJason M. Bills     if (ret < 0)
1874e1f26343SJason M. Bills     {
1875e1f26343SJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret);
1876e1f26343SJason M. Bills     }
1877e1f26343SJason M. Bills 
1878e1f26343SJason M. Bills     // Get the Created time from the timestamp
187916428a1aSJason M. Bills     std::string entryTimeStr;
188016428a1aSJason M. Bills     if (!getEntryTimestamp(journal, entryTimeStr))
1881e1f26343SJason M. Bills     {
188216428a1aSJason M. Bills         return 1;
1883e1f26343SJason M. Bills     }
1884e1f26343SJason M. Bills 
1885e1f26343SJason M. Bills     // Fill in the log entry with the gathered data
1886c4bf6374SJason M. Bills     bmcJournalLogEntryJson = {
1887cb92c03bSAndrew Geissler         {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
1888c4bf6374SJason M. Bills         {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" +
1889c4bf6374SJason M. Bills                           bmcJournalLogEntryID},
1890e1f26343SJason M. Bills         {"Name", "BMC Journal Entry"},
1891c4bf6374SJason M. Bills         {"Id", bmcJournalLogEntryID},
1892a8fe54f0SJason M. Bills         {"Message", std::move(message)},
1893e1f26343SJason M. Bills         {"EntryType", "Oem"},
1894738c1e61SPatrick Williams         {"Severity", severity <= 2   ? "Critical"
1895738c1e61SPatrick Williams                      : severity <= 4 ? "Warning"
1896738c1e61SPatrick Williams                                      : "OK"},
1897086be238SEd Tanous         {"OemRecordFormat", "BMC Journal Entry"},
1898e1f26343SJason M. Bills         {"Created", std::move(entryTimeStr)}};
1899e1f26343SJason M. Bills     return 0;
1900e1f26343SJason M. Bills }
1901e1f26343SJason M. Bills 
1902c4bf6374SJason M. Bills class BMCJournalLogEntryCollection : public Node
1903e1f26343SJason M. Bills {
1904e1f26343SJason M. Bills   public:
190552cc112dSEd Tanous     BMCJournalLogEntryCollection(App& app) :
1906c4bf6374SJason M. Bills         Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
1907e1f26343SJason M. Bills     {
1908e1f26343SJason M. Bills         entityPrivileges = {
1909e1f26343SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1910e1f26343SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1911e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1912e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1913e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1914e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1915e1f26343SJason M. Bills     }
1916e1f26343SJason M. Bills 
1917e1f26343SJason M. Bills   private:
1918e1f26343SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
1919cb13a392SEd Tanous                const std::vector<std::string>&) override
1920e1f26343SJason M. Bills     {
1921e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1922193ad2faSJason M. Bills         static constexpr const long maxEntriesPerPage = 1000;
1923271584abSEd Tanous         uint64_t skip = 0;
1924271584abSEd Tanous         uint64_t top = maxEntriesPerPage; // Show max entries by default
192516428a1aSJason M. Bills         if (!getSkipParam(asyncResp->res, req, skip))
1926193ad2faSJason M. Bills         {
1927193ad2faSJason M. Bills             return;
1928193ad2faSJason M. Bills         }
192916428a1aSJason M. Bills         if (!getTopParam(asyncResp->res, req, top))
1930193ad2faSJason M. Bills         {
1931193ad2faSJason M. Bills             return;
1932193ad2faSJason M. Bills         }
1933e1f26343SJason M. Bills         // Collections don't include the static data added by SubRoute because
1934e1f26343SJason M. Bills         // it has a duplicate entry for members
1935e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1936e1f26343SJason M. Bills             "#LogEntryCollection.LogEntryCollection";
19370f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
19380f74e643SEd Tanous             "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
1939e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1940c4bf6374SJason M. Bills             "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
1941e1f26343SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries";
1942e1f26343SJason M. Bills         asyncResp->res.jsonValue["Description"] =
1943e1f26343SJason M. Bills             "Collection of BMC Journal Entries";
19440f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
19450f74e643SEd Tanous             "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries";
1946e1f26343SJason M. Bills         nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1947e1f26343SJason M. Bills         logEntryArray = nlohmann::json::array();
1948e1f26343SJason M. Bills 
1949e1f26343SJason M. Bills         // Go through the journal and use the timestamp to create a unique ID
1950e1f26343SJason M. Bills         // for each entry
1951e1f26343SJason M. Bills         sd_journal* journalTmp = nullptr;
1952e1f26343SJason M. Bills         int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1953e1f26343SJason M. Bills         if (ret < 0)
1954e1f26343SJason M. Bills         {
1955e1f26343SJason M. Bills             BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
1956f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
1957e1f26343SJason M. Bills             return;
1958e1f26343SJason M. Bills         }
1959e1f26343SJason M. Bills         std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1960e1f26343SJason M. Bills             journalTmp, sd_journal_close);
1961e1f26343SJason M. Bills         journalTmp = nullptr;
1962b01bf299SEd Tanous         uint64_t entryCount = 0;
1963e85d6b16SJason M. Bills         // Reset the unique ID on the first entry
1964e85d6b16SJason M. Bills         bool firstEntry = true;
1965e1f26343SJason M. Bills         SD_JOURNAL_FOREACH(journal.get())
1966e1f26343SJason M. Bills         {
1967193ad2faSJason M. Bills             entryCount++;
1968193ad2faSJason M. Bills             // Handle paging using skip (number of entries to skip from the
1969193ad2faSJason M. Bills             // start) and top (number of entries to display)
1970193ad2faSJason M. Bills             if (entryCount <= skip || entryCount > skip + top)
1971193ad2faSJason M. Bills             {
1972193ad2faSJason M. Bills                 continue;
1973193ad2faSJason M. Bills             }
1974193ad2faSJason M. Bills 
197516428a1aSJason M. Bills             std::string idStr;
1976e85d6b16SJason M. Bills             if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
1977e1f26343SJason M. Bills             {
1978e1f26343SJason M. Bills                 continue;
1979e1f26343SJason M. Bills             }
1980e1f26343SJason M. Bills 
1981e85d6b16SJason M. Bills             if (firstEntry)
1982e85d6b16SJason M. Bills             {
1983e85d6b16SJason M. Bills                 firstEntry = false;
1984e85d6b16SJason M. Bills             }
1985e85d6b16SJason M. Bills 
1986e1f26343SJason M. Bills             logEntryArray.push_back({});
1987c4bf6374SJason M. Bills             nlohmann::json& bmcJournalLogEntry = logEntryArray.back();
1988c4bf6374SJason M. Bills             if (fillBMCJournalLogEntryJson(idStr, journal.get(),
1989c4bf6374SJason M. Bills                                            bmcJournalLogEntry) != 0)
1990e1f26343SJason M. Bills             {
1991f12894f8SJason M. Bills                 messages::internalError(asyncResp->res);
1992e1f26343SJason M. Bills                 return;
1993e1f26343SJason M. Bills             }
1994e1f26343SJason M. Bills         }
1995193ad2faSJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1996193ad2faSJason M. Bills         if (skip + top < entryCount)
1997193ad2faSJason M. Bills         {
1998193ad2faSJason M. Bills             asyncResp->res.jsonValue["Members@odata.nextLink"] =
1999c4bf6374SJason M. Bills                 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" +
2000193ad2faSJason M. Bills                 std::to_string(skip + top);
2001193ad2faSJason M. Bills         }
2002e1f26343SJason M. Bills     }
2003e1f26343SJason M. Bills };
2004e1f26343SJason M. Bills 
2005c4bf6374SJason M. Bills class BMCJournalLogEntry : public Node
2006e1f26343SJason M. Bills {
2007e1f26343SJason M. Bills   public:
200852cc112dSEd Tanous     BMCJournalLogEntry(App& app) :
2009c4bf6374SJason M. Bills         Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/",
2010e1f26343SJason M. Bills              std::string())
2011e1f26343SJason M. Bills     {
2012e1f26343SJason M. Bills         entityPrivileges = {
2013e1f26343SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
2014e1f26343SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
2015e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2016e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2017e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2018e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2019e1f26343SJason M. Bills     }
2020e1f26343SJason M. Bills 
2021e1f26343SJason M. Bills   private:
2022cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
2023e1f26343SJason M. Bills                const std::vector<std::string>& params) override
2024e1f26343SJason M. Bills     {
2025e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2026e1f26343SJason M. Bills         if (params.size() != 1)
2027e1f26343SJason M. Bills         {
2028f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
2029e1f26343SJason M. Bills             return;
2030e1f26343SJason M. Bills         }
203116428a1aSJason M. Bills         const std::string& entryID = params[0];
2032e1f26343SJason M. Bills         // Convert the unique ID back to a timestamp to find the entry
2033e1f26343SJason M. Bills         uint64_t ts = 0;
2034271584abSEd Tanous         uint64_t index = 0;
203516428a1aSJason M. Bills         if (!getTimestampFromID(asyncResp->res, entryID, ts, index))
2036e1f26343SJason M. Bills         {
203716428a1aSJason M. Bills             return;
2038e1f26343SJason M. Bills         }
2039e1f26343SJason M. Bills 
2040e1f26343SJason M. Bills         sd_journal* journalTmp = nullptr;
2041e1f26343SJason M. Bills         int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
2042e1f26343SJason M. Bills         if (ret < 0)
2043e1f26343SJason M. Bills         {
2044e1f26343SJason M. Bills             BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
2045f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
2046e1f26343SJason M. Bills             return;
2047e1f26343SJason M. Bills         }
2048e1f26343SJason M. Bills         std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
2049e1f26343SJason M. Bills             journalTmp, sd_journal_close);
2050e1f26343SJason M. Bills         journalTmp = nullptr;
2051e1f26343SJason M. Bills         // Go to the timestamp in the log and move to the entry at the index
2052af07e3f5SJason M. Bills         // tracking the unique ID
2053af07e3f5SJason M. Bills         std::string idStr;
2054af07e3f5SJason M. Bills         bool firstEntry = true;
2055e1f26343SJason M. Bills         ret = sd_journal_seek_realtime_usec(journal.get(), ts);
20562056b6d1SManojkiran Eda         if (ret < 0)
20572056b6d1SManojkiran Eda         {
20582056b6d1SManojkiran Eda             BMCWEB_LOG_ERROR << "failed to seek to an entry in journal"
20592056b6d1SManojkiran Eda                              << strerror(-ret);
20602056b6d1SManojkiran Eda             messages::internalError(asyncResp->res);
20612056b6d1SManojkiran Eda             return;
20622056b6d1SManojkiran Eda         }
2063271584abSEd Tanous         for (uint64_t i = 0; i <= index; i++)
2064e1f26343SJason M. Bills         {
2065e1f26343SJason M. Bills             sd_journal_next(journal.get());
2066af07e3f5SJason M. Bills             if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
2067af07e3f5SJason M. Bills             {
2068af07e3f5SJason M. Bills                 messages::internalError(asyncResp->res);
2069af07e3f5SJason M. Bills                 return;
2070af07e3f5SJason M. Bills             }
2071af07e3f5SJason M. Bills             if (firstEntry)
2072af07e3f5SJason M. Bills             {
2073af07e3f5SJason M. Bills                 firstEntry = false;
2074af07e3f5SJason M. Bills             }
2075e1f26343SJason M. Bills         }
2076c4bf6374SJason M. Bills         // Confirm that the entry ID matches what was requested
2077af07e3f5SJason M. Bills         if (idStr != entryID)
2078c4bf6374SJason M. Bills         {
2079c4bf6374SJason M. Bills             messages::resourceMissingAtURI(asyncResp->res, entryID);
2080c4bf6374SJason M. Bills             return;
2081c4bf6374SJason M. Bills         }
2082c4bf6374SJason M. Bills 
2083c4bf6374SJason M. Bills         if (fillBMCJournalLogEntryJson(entryID, journal.get(),
2084e1f26343SJason M. Bills                                        asyncResp->res.jsonValue) != 0)
2085e1f26343SJason M. Bills         {
2086f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
2087e1f26343SJason M. Bills             return;
2088e1f26343SJason M. Bills         }
2089e1f26343SJason M. Bills     }
2090e1f26343SJason M. Bills };
2091e1f26343SJason M. Bills 
20925cb1dd27SAsmitha Karunanithi class BMCDumpService : public Node
2093c9bb6861Sraviteja-b {
2094c9bb6861Sraviteja-b   public:
209552cc112dSEd Tanous     BMCDumpService(App& app) :
20965cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
2097c9bb6861Sraviteja-b     {
2098c9bb6861Sraviteja-b         entityPrivileges = {
2099c9bb6861Sraviteja-b             {boost::beast::http::verb::get, {{"Login"}}},
2100c9bb6861Sraviteja-b             {boost::beast::http::verb::head, {{"Login"}}},
2101c9bb6861Sraviteja-b             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2102c9bb6861Sraviteja-b             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2103c9bb6861Sraviteja-b             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2104c9bb6861Sraviteja-b             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2105c9bb6861Sraviteja-b     }
2106c9bb6861Sraviteja-b 
2107c9bb6861Sraviteja-b   private:
2108cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
2109cb13a392SEd Tanous                const std::vector<std::string>&) override
2110c9bb6861Sraviteja-b     {
2111c9bb6861Sraviteja-b         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2112c9bb6861Sraviteja-b 
2113c9bb6861Sraviteja-b         asyncResp->res.jsonValue["@odata.id"] =
21145cb1dd27SAsmitha Karunanithi             "/redfish/v1/Managers/bmc/LogServices/Dump";
2115c9bb6861Sraviteja-b         asyncResp->res.jsonValue["@odata.type"] =
2116d337bb72SAsmitha Karunanithi             "#LogService.v1_2_0.LogService";
2117c9bb6861Sraviteja-b         asyncResp->res.jsonValue["Name"] = "Dump LogService";
21185cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Description"] = "BMC Dump LogService";
21195cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Id"] = "Dump";
2120c9bb6861Sraviteja-b         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2121c9bb6861Sraviteja-b         asyncResp->res.jsonValue["Entries"] = {
21225cb1dd27SAsmitha Karunanithi             {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}};
21235cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Actions"] = {
21245cb1dd27SAsmitha Karunanithi             {"#LogService.ClearLog",
21255cb1dd27SAsmitha Karunanithi              {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
21265cb1dd27SAsmitha Karunanithi                          "Actions/LogService.ClearLog"}}},
2127d337bb72SAsmitha Karunanithi             {"#LogService.CollectDiagnosticData",
2128d337bb72SAsmitha Karunanithi              {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2129d337bb72SAsmitha Karunanithi                          "Actions/LogService.CollectDiagnosticData"}}}};
2130c9bb6861Sraviteja-b     }
2131c9bb6861Sraviteja-b };
2132c9bb6861Sraviteja-b 
21335cb1dd27SAsmitha Karunanithi class BMCDumpEntryCollection : public Node
2134c9bb6861Sraviteja-b {
2135c9bb6861Sraviteja-b   public:
213652cc112dSEd Tanous     BMCDumpEntryCollection(App& app) :
21375cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
2138c9bb6861Sraviteja-b     {
2139c9bb6861Sraviteja-b         entityPrivileges = {
2140c9bb6861Sraviteja-b             {boost::beast::http::verb::get, {{"Login"}}},
2141c9bb6861Sraviteja-b             {boost::beast::http::verb::head, {{"Login"}}},
2142c9bb6861Sraviteja-b             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2143c9bb6861Sraviteja-b             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2144c9bb6861Sraviteja-b             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2145c9bb6861Sraviteja-b             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2146c9bb6861Sraviteja-b     }
2147c9bb6861Sraviteja-b 
2148c9bb6861Sraviteja-b   private:
2149c9bb6861Sraviteja-b     /**
2150c9bb6861Sraviteja-b      * Functions triggers appropriate requests on DBus
2151c9bb6861Sraviteja-b      */
2152cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
2153cb13a392SEd Tanous                const std::vector<std::string>&) override
2154c9bb6861Sraviteja-b     {
2155c9bb6861Sraviteja-b         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2156c9bb6861Sraviteja-b 
2157c9bb6861Sraviteja-b         asyncResp->res.jsonValue["@odata.type"] =
2158c9bb6861Sraviteja-b             "#LogEntryCollection.LogEntryCollection";
2159c9bb6861Sraviteja-b         asyncResp->res.jsonValue["@odata.id"] =
21605cb1dd27SAsmitha Karunanithi             "/redfish/v1/Managers/bmc/LogServices/Dump/Entries";
21615cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Name"] = "BMC Dump Entries";
2162c9bb6861Sraviteja-b         asyncResp->res.jsonValue["Description"] =
21635cb1dd27SAsmitha Karunanithi             "Collection of BMC Dump Entries";
2164c9bb6861Sraviteja-b 
21655cb1dd27SAsmitha Karunanithi         getDumpEntryCollection(asyncResp, "BMC");
2166c9bb6861Sraviteja-b     }
2167c9bb6861Sraviteja-b };
2168c9bb6861Sraviteja-b 
21695cb1dd27SAsmitha Karunanithi class BMCDumpEntry : public Node
2170c9bb6861Sraviteja-b {
2171c9bb6861Sraviteja-b   public:
217252cc112dSEd Tanous     BMCDumpEntry(App& app) :
21735cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/",
2174c9bb6861Sraviteja-b              std::string())
2175c9bb6861Sraviteja-b     {
2176c9bb6861Sraviteja-b         entityPrivileges = {
2177c9bb6861Sraviteja-b             {boost::beast::http::verb::get, {{"Login"}}},
2178c9bb6861Sraviteja-b             {boost::beast::http::verb::head, {{"Login"}}},
2179c9bb6861Sraviteja-b             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2180c9bb6861Sraviteja-b             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2181c9bb6861Sraviteja-b             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2182c9bb6861Sraviteja-b             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2183c9bb6861Sraviteja-b     }
2184c9bb6861Sraviteja-b 
2185c9bb6861Sraviteja-b   private:
2186cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
2187c9bb6861Sraviteja-b                const std::vector<std::string>& params) override
2188c9bb6861Sraviteja-b     {
2189c9bb6861Sraviteja-b         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2190c9bb6861Sraviteja-b         if (params.size() != 1)
2191c9bb6861Sraviteja-b         {
2192c9bb6861Sraviteja-b             messages::internalError(asyncResp->res);
2193c9bb6861Sraviteja-b             return;
2194c9bb6861Sraviteja-b         }
21955cb1dd27SAsmitha Karunanithi         getDumpEntryById(asyncResp, params[0], "BMC");
2196c9bb6861Sraviteja-b     }
2197c9bb6861Sraviteja-b 
2198cb13a392SEd Tanous     void doDelete(crow::Response& res, const crow::Request&,
2199c9bb6861Sraviteja-b                   const std::vector<std::string>& params) override
2200c9bb6861Sraviteja-b     {
22015cb1dd27SAsmitha Karunanithi         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2202c9bb6861Sraviteja-b         if (params.size() != 1)
2203c9bb6861Sraviteja-b         {
2204c9bb6861Sraviteja-b             messages::internalError(asyncResp->res);
2205c9bb6861Sraviteja-b             return;
2206c9bb6861Sraviteja-b         }
22079878256fSStanley Chu         deleteDumpEntry(asyncResp, params[0], "bmc");
22085cb1dd27SAsmitha Karunanithi     }
22095cb1dd27SAsmitha Karunanithi };
2210c9bb6861Sraviteja-b 
2211a43be80fSAsmitha Karunanithi class BMCDumpCreate : public Node
2212a43be80fSAsmitha Karunanithi {
2213a43be80fSAsmitha Karunanithi   public:
221452cc112dSEd Tanous     BMCDumpCreate(App& app) :
2215a43be80fSAsmitha Karunanithi         Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2216d337bb72SAsmitha Karunanithi                   "Actions/"
2217d337bb72SAsmitha Karunanithi                   "LogService.CollectDiagnosticData/")
2218a43be80fSAsmitha Karunanithi     {
2219a43be80fSAsmitha Karunanithi         entityPrivileges = {
2220a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
2221a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
2222a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2223a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2224a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2225a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2226a43be80fSAsmitha Karunanithi     }
2227a43be80fSAsmitha Karunanithi 
2228a43be80fSAsmitha Karunanithi   private:
2229a43be80fSAsmitha Karunanithi     void doPost(crow::Response& res, const crow::Request& req,
2230cb13a392SEd Tanous                 const std::vector<std::string>&) override
2231a43be80fSAsmitha Karunanithi     {
2232a43be80fSAsmitha Karunanithi         createDump(res, req, "BMC");
2233a43be80fSAsmitha Karunanithi     }
2234a43be80fSAsmitha Karunanithi };
2235a43be80fSAsmitha Karunanithi 
223680319af1SAsmitha Karunanithi class BMCDumpClear : public Node
223780319af1SAsmitha Karunanithi {
223880319af1SAsmitha Karunanithi   public:
223952cc112dSEd Tanous     BMCDumpClear(App& app) :
224080319af1SAsmitha Karunanithi         Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
224180319af1SAsmitha Karunanithi                   "Actions/"
224280319af1SAsmitha Karunanithi                   "LogService.ClearLog/")
224380319af1SAsmitha Karunanithi     {
224480319af1SAsmitha Karunanithi         entityPrivileges = {
224580319af1SAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
224680319af1SAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
224780319af1SAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
224880319af1SAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
224980319af1SAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
225080319af1SAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
225180319af1SAsmitha Karunanithi     }
225280319af1SAsmitha Karunanithi 
225380319af1SAsmitha Karunanithi   private:
2254cb13a392SEd Tanous     void doPost(crow::Response& res, const crow::Request&,
2255cb13a392SEd Tanous                 const std::vector<std::string>&) override
225680319af1SAsmitha Karunanithi     {
2257b47452b2SAsmitha Karunanithi         clearDump(res, "BMC");
225880319af1SAsmitha Karunanithi     }
225980319af1SAsmitha Karunanithi };
226080319af1SAsmitha Karunanithi 
22615cb1dd27SAsmitha Karunanithi class SystemDumpService : public Node
2262c9bb6861Sraviteja-b {
22635cb1dd27SAsmitha Karunanithi   public:
226452cc112dSEd Tanous     SystemDumpService(App& app) :
22655cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Systems/system/LogServices/Dump/")
22665cb1dd27SAsmitha Karunanithi     {
22675cb1dd27SAsmitha Karunanithi         entityPrivileges = {
22685cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
22695cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
22705cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
22715cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
22725cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
22735cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
22745cb1dd27SAsmitha Karunanithi     }
22755cb1dd27SAsmitha Karunanithi 
22765cb1dd27SAsmitha Karunanithi   private:
2277cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
2278cb13a392SEd Tanous                const std::vector<std::string>&) override
22795cb1dd27SAsmitha Karunanithi     {
22805cb1dd27SAsmitha Karunanithi         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
22815cb1dd27SAsmitha Karunanithi 
22825cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["@odata.id"] =
22835cb1dd27SAsmitha Karunanithi             "/redfish/v1/Systems/system/LogServices/Dump";
22845cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["@odata.type"] =
2285d337bb72SAsmitha Karunanithi             "#LogService.v1_2_0.LogService";
22865cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Name"] = "Dump LogService";
22875cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Description"] = "System Dump LogService";
22885cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Id"] = "Dump";
22895cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
22905cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Entries"] = {
22915cb1dd27SAsmitha Karunanithi             {"@odata.id",
22925cb1dd27SAsmitha Karunanithi              "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
22935cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Actions"] = {
22945cb1dd27SAsmitha Karunanithi             {"#LogService.ClearLog",
22955cb1dd27SAsmitha Karunanithi              {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
22965cb1dd27SAsmitha Karunanithi                          "LogService.ClearLog"}}},
2297d337bb72SAsmitha Karunanithi             {"#LogService.CollectDiagnosticData",
2298d337bb72SAsmitha Karunanithi              {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2299d337bb72SAsmitha Karunanithi                          "LogService.CollectDiagnosticData"}}}};
23005cb1dd27SAsmitha Karunanithi     }
23015cb1dd27SAsmitha Karunanithi };
23025cb1dd27SAsmitha Karunanithi 
23035cb1dd27SAsmitha Karunanithi class SystemDumpEntryCollection : public Node
23045cb1dd27SAsmitha Karunanithi {
23055cb1dd27SAsmitha Karunanithi   public:
230652cc112dSEd Tanous     SystemDumpEntryCollection(App& app) :
23075cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/")
23085cb1dd27SAsmitha Karunanithi     {
23095cb1dd27SAsmitha Karunanithi         entityPrivileges = {
23105cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
23115cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
23125cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
23135cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
23145cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
23155cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
23165cb1dd27SAsmitha Karunanithi     }
23175cb1dd27SAsmitha Karunanithi 
23185cb1dd27SAsmitha Karunanithi   private:
23195cb1dd27SAsmitha Karunanithi     /**
23205cb1dd27SAsmitha Karunanithi      * Functions triggers appropriate requests on DBus
23215cb1dd27SAsmitha Karunanithi      */
2322cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
2323cb13a392SEd Tanous                const std::vector<std::string>&) override
23245cb1dd27SAsmitha Karunanithi     {
23255cb1dd27SAsmitha Karunanithi         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
23265cb1dd27SAsmitha Karunanithi 
23275cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["@odata.type"] =
23285cb1dd27SAsmitha Karunanithi             "#LogEntryCollection.LogEntryCollection";
23295cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["@odata.id"] =
23305cb1dd27SAsmitha Karunanithi             "/redfish/v1/Systems/system/LogServices/Dump/Entries";
23315cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Name"] = "System Dump Entries";
23325cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Description"] =
23335cb1dd27SAsmitha Karunanithi             "Collection of System Dump Entries";
23345cb1dd27SAsmitha Karunanithi 
23355cb1dd27SAsmitha Karunanithi         getDumpEntryCollection(asyncResp, "System");
23365cb1dd27SAsmitha Karunanithi     }
23375cb1dd27SAsmitha Karunanithi };
23385cb1dd27SAsmitha Karunanithi 
23395cb1dd27SAsmitha Karunanithi class SystemDumpEntry : public Node
23405cb1dd27SAsmitha Karunanithi {
23415cb1dd27SAsmitha Karunanithi   public:
234252cc112dSEd Tanous     SystemDumpEntry(App& app) :
23435cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/",
23445cb1dd27SAsmitha Karunanithi              std::string())
23455cb1dd27SAsmitha Karunanithi     {
23465cb1dd27SAsmitha Karunanithi         entityPrivileges = {
23475cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
23485cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
23495cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
23505cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
23515cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
23525cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
23535cb1dd27SAsmitha Karunanithi     }
23545cb1dd27SAsmitha Karunanithi 
23555cb1dd27SAsmitha Karunanithi   private:
2356cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
23575cb1dd27SAsmitha Karunanithi                const std::vector<std::string>& params) override
23585cb1dd27SAsmitha Karunanithi     {
23595cb1dd27SAsmitha Karunanithi         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
23605cb1dd27SAsmitha Karunanithi         if (params.size() != 1)
23615cb1dd27SAsmitha Karunanithi         {
2362c9bb6861Sraviteja-b             messages::internalError(asyncResp->res);
2363c9bb6861Sraviteja-b             return;
2364c9bb6861Sraviteja-b         }
23655cb1dd27SAsmitha Karunanithi         getDumpEntryById(asyncResp, params[0], "System");
23665cb1dd27SAsmitha Karunanithi     }
2367c9bb6861Sraviteja-b 
2368cb13a392SEd Tanous     void doDelete(crow::Response& res, const crow::Request&,
23695cb1dd27SAsmitha Karunanithi                   const std::vector<std::string>& params) override
2370c9bb6861Sraviteja-b     {
23715cb1dd27SAsmitha Karunanithi         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
23725cb1dd27SAsmitha Karunanithi         if (params.size() != 1)
2373c9bb6861Sraviteja-b         {
23745cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
2375c9bb6861Sraviteja-b             return;
2376c9bb6861Sraviteja-b         }
23779878256fSStanley Chu         deleteDumpEntry(asyncResp, params[0], "system");
2378c9bb6861Sraviteja-b     }
2379c9bb6861Sraviteja-b };
2380c9bb6861Sraviteja-b 
2381a43be80fSAsmitha Karunanithi class SystemDumpCreate : public Node
2382a43be80fSAsmitha Karunanithi {
2383a43be80fSAsmitha Karunanithi   public:
238452cc112dSEd Tanous     SystemDumpCreate(App& app) :
2385a43be80fSAsmitha Karunanithi         Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
2386d337bb72SAsmitha Karunanithi                   "Actions/"
2387d337bb72SAsmitha Karunanithi                   "LogService.CollectDiagnosticData/")
2388a43be80fSAsmitha Karunanithi     {
2389a43be80fSAsmitha Karunanithi         entityPrivileges = {
2390a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
2391a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
2392a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2393a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2394a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2395a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2396a43be80fSAsmitha Karunanithi     }
2397a43be80fSAsmitha Karunanithi 
2398a43be80fSAsmitha Karunanithi   private:
2399a43be80fSAsmitha Karunanithi     void doPost(crow::Response& res, const crow::Request& req,
2400cb13a392SEd Tanous                 const std::vector<std::string>&) override
2401a43be80fSAsmitha Karunanithi     {
2402a43be80fSAsmitha Karunanithi         createDump(res, req, "System");
2403a43be80fSAsmitha Karunanithi     }
2404a43be80fSAsmitha Karunanithi };
2405a43be80fSAsmitha Karunanithi 
2406013487e5Sraviteja-b class SystemDumpClear : public Node
2407013487e5Sraviteja-b {
2408013487e5Sraviteja-b   public:
240952cc112dSEd Tanous     SystemDumpClear(App& app) :
241080319af1SAsmitha Karunanithi         Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
2411013487e5Sraviteja-b                   "Actions/"
2412013487e5Sraviteja-b                   "LogService.ClearLog/")
2413013487e5Sraviteja-b     {
2414013487e5Sraviteja-b         entityPrivileges = {
2415013487e5Sraviteja-b             {boost::beast::http::verb::get, {{"Login"}}},
2416013487e5Sraviteja-b             {boost::beast::http::verb::head, {{"Login"}}},
241780319af1SAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
241880319af1SAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
241980319af1SAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2420013487e5Sraviteja-b             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2421013487e5Sraviteja-b     }
2422013487e5Sraviteja-b 
2423013487e5Sraviteja-b   private:
2424cb13a392SEd Tanous     void doPost(crow::Response& res, const crow::Request&,
2425cb13a392SEd Tanous                 const std::vector<std::string>&) override
2426013487e5Sraviteja-b     {
2427b47452b2SAsmitha Karunanithi         clearDump(res, "System");
2428013487e5Sraviteja-b     }
2429013487e5Sraviteja-b };
2430013487e5Sraviteja-b 
2431424c4176SJason M. Bills class CrashdumpService : public Node
2432e1f26343SJason M. Bills {
2433e1f26343SJason M. Bills   public:
243452cc112dSEd Tanous     CrashdumpService(App& app) :
2435424c4176SJason M. Bills         Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/")
24361da66f75SEd Tanous     {
24373946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
24383946028dSAppaRao Puli         // method for security reasons.
24391da66f75SEd Tanous         entityPrivileges = {
24403946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
24413946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2442e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2443e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2444e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2445e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
24461da66f75SEd Tanous     }
24471da66f75SEd Tanous 
24481da66f75SEd Tanous   private:
24491da66f75SEd Tanous     /**
24501da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
24511da66f75SEd Tanous      */
2452cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
2453cb13a392SEd Tanous                const std::vector<std::string>&) override
24541da66f75SEd Tanous     {
2455e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
24561da66f75SEd Tanous         // Copy over the static data to include the entries added by SubRoute
24570f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
2458424c4176SJason M. Bills             "/redfish/v1/Systems/system/LogServices/Crashdump";
2459e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
24608e6c099aSJason M. Bills             "#LogService.v1_2_0.LogService";
24614f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
24624f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
24634f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
2464e1f26343SJason M. Bills         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2465e1f26343SJason M. Bills         asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
2466cd50aa42SJason M. Bills         asyncResp->res.jsonValue["Entries"] = {
2467cd50aa42SJason M. Bills             {"@odata.id",
2468424c4176SJason M. Bills              "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}};
2469e1f26343SJason M. Bills         asyncResp->res.jsonValue["Actions"] = {
24705b61b5e8SJason M. Bills             {"#LogService.ClearLog",
24715b61b5e8SJason M. Bills              {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
24725b61b5e8SJason M. Bills                          "Actions/LogService.ClearLog"}}},
24738e6c099aSJason M. Bills             {"#LogService.CollectDiagnosticData",
2474424c4176SJason M. Bills              {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
24758e6c099aSJason M. Bills                          "Actions/LogService.CollectDiagnosticData"}}}};
24761da66f75SEd Tanous 
24771da66f75SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI
24788e6c099aSJason M. Bills         asyncResp->res.jsonValue["Actions"]["Oem"] = {
2479424c4176SJason M. Bills             {"#Crashdump.SendRawPeci",
248008a4e4b5SAnthony Wilson              {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
24818e6c099aSJason M. Bills                          "Actions/Oem/Crashdump.SendRawPeci"}}}};
24821da66f75SEd Tanous #endif
24831da66f75SEd Tanous     }
24841da66f75SEd Tanous };
24851da66f75SEd Tanous 
24865b61b5e8SJason M. Bills class CrashdumpClear : public Node
24875b61b5e8SJason M. Bills {
24885b61b5e8SJason M. Bills   public:
248952cc112dSEd Tanous     CrashdumpClear(App& app) :
24905b61b5e8SJason M. Bills         Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
24915b61b5e8SJason M. Bills                   "LogService.ClearLog/")
24925b61b5e8SJason M. Bills     {
24933946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
24943946028dSAppaRao Puli         // method for security reasons.
24955b61b5e8SJason M. Bills         entityPrivileges = {
24963946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
24973946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
24985b61b5e8SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
24995b61b5e8SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
25005b61b5e8SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
25015b61b5e8SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
25025b61b5e8SJason M. Bills     }
25035b61b5e8SJason M. Bills 
25045b61b5e8SJason M. Bills   private:
2505cb13a392SEd Tanous     void doPost(crow::Response& res, const crow::Request&,
2506cb13a392SEd Tanous                 const std::vector<std::string>&) override
25075b61b5e8SJason M. Bills     {
25085b61b5e8SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
25095b61b5e8SJason M. Bills 
25105b61b5e8SJason M. Bills         crow::connections::systemBus->async_method_call(
25115b61b5e8SJason M. Bills             [asyncResp](const boost::system::error_code ec,
2512cb13a392SEd Tanous                         const std::string&) {
25135b61b5e8SJason M. Bills                 if (ec)
25145b61b5e8SJason M. Bills                 {
25155b61b5e8SJason M. Bills                     messages::internalError(asyncResp->res);
25165b61b5e8SJason M. Bills                     return;
25175b61b5e8SJason M. Bills                 }
25185b61b5e8SJason M. Bills                 messages::success(asyncResp->res);
25195b61b5e8SJason M. Bills             },
25205b61b5e8SJason M. Bills             crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
25215b61b5e8SJason M. Bills     }
25225b61b5e8SJason M. Bills };
25235b61b5e8SJason M. Bills 
2524b5a76932SEd Tanous static void logCrashdumpEntry(const std::shared_ptr<AsyncResp>& asyncResp,
2525e855dd28SJason M. Bills                               const std::string& logID,
2526e855dd28SJason M. Bills                               nlohmann::json& logEntryJson)
2527e855dd28SJason M. Bills {
2528043a0536SJohnathan Mantey     auto getStoredLogCallback =
2529043a0536SJohnathan Mantey         [asyncResp, logID, &logEntryJson](
2530e855dd28SJason M. Bills             const boost::system::error_code ec,
2531043a0536SJohnathan Mantey             const std::vector<std::pair<std::string, VariantType>>& params) {
2532e855dd28SJason M. Bills             if (ec)
2533e855dd28SJason M. Bills             {
2534e855dd28SJason M. Bills                 BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
25351ddcf01aSJason M. Bills                 if (ec.value() ==
25361ddcf01aSJason M. Bills                     boost::system::linux_error::bad_request_descriptor)
25371ddcf01aSJason M. Bills                 {
2538043a0536SJohnathan Mantey                     messages::resourceNotFound(asyncResp->res, "LogEntry",
2539043a0536SJohnathan Mantey                                                logID);
25401ddcf01aSJason M. Bills                 }
25411ddcf01aSJason M. Bills                 else
25421ddcf01aSJason M. Bills                 {
2543e855dd28SJason M. Bills                     messages::internalError(asyncResp->res);
25441ddcf01aSJason M. Bills                 }
2545e855dd28SJason M. Bills                 return;
2546e855dd28SJason M. Bills             }
2547043a0536SJohnathan Mantey 
2548043a0536SJohnathan Mantey             std::string timestamp{};
2549043a0536SJohnathan Mantey             std::string filename{};
2550043a0536SJohnathan Mantey             std::string logfile{};
25512c70f800SEd Tanous             parseCrashdumpParameters(params, filename, timestamp, logfile);
2552043a0536SJohnathan Mantey 
2553043a0536SJohnathan Mantey             if (filename.empty() || timestamp.empty())
2554e855dd28SJason M. Bills             {
2555043a0536SJohnathan Mantey                 messages::resourceMissingAtURI(asyncResp->res, logID);
2556e855dd28SJason M. Bills                 return;
2557e855dd28SJason M. Bills             }
2558e855dd28SJason M. Bills 
2559043a0536SJohnathan Mantey             std::string crashdumpURI =
2560e855dd28SJason M. Bills                 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
2561043a0536SJohnathan Mantey                 logID + "/" + filename;
25628e6c099aSJason M. Bills             logEntryJson = {{"@odata.type", "#LogEntry.v1_7_0.LogEntry"},
2563043a0536SJohnathan Mantey                             {"@odata.id", "/redfish/v1/Systems/system/"
2564043a0536SJohnathan Mantey                                           "LogServices/Crashdump/Entries/" +
2565e855dd28SJason M. Bills                                               logID},
2566e855dd28SJason M. Bills                             {"Name", "CPU Crashdump"},
2567e855dd28SJason M. Bills                             {"Id", logID},
2568e855dd28SJason M. Bills                             {"EntryType", "Oem"},
25698e6c099aSJason M. Bills                             {"AdditionalDataURI", std::move(crashdumpURI)},
25708e6c099aSJason M. Bills                             {"DiagnosticDataType", "OEM"},
25718e6c099aSJason M. Bills                             {"OEMDiagnosticDataType", "PECICrashdump"},
2572043a0536SJohnathan Mantey                             {"Created", std::move(timestamp)}};
2573e855dd28SJason M. Bills         };
2574e855dd28SJason M. Bills     crow::connections::systemBus->async_method_call(
25755b61b5e8SJason M. Bills         std::move(getStoredLogCallback), crashdumpObject,
25765b61b5e8SJason M. Bills         crashdumpPath + std::string("/") + logID,
2577043a0536SJohnathan Mantey         "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
2578e855dd28SJason M. Bills }
2579e855dd28SJason M. Bills 
2580424c4176SJason M. Bills class CrashdumpEntryCollection : public Node
25811da66f75SEd Tanous {
25821da66f75SEd Tanous   public:
258352cc112dSEd Tanous     CrashdumpEntryCollection(App& app) :
2584424c4176SJason M. Bills         Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/")
25851da66f75SEd Tanous     {
25863946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
25873946028dSAppaRao Puli         // method for security reasons.
25881da66f75SEd Tanous         entityPrivileges = {
25893946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
25903946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2591e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2592e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2593e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2594e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
25951da66f75SEd Tanous     }
25961da66f75SEd Tanous 
25971da66f75SEd Tanous   private:
25981da66f75SEd Tanous     /**
25991da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
26001da66f75SEd Tanous      */
2601cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
2602cb13a392SEd Tanous                const std::vector<std::string>&) override
26031da66f75SEd Tanous     {
2604e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
26051da66f75SEd Tanous         // Collections don't include the static data added by SubRoute because
26061da66f75SEd Tanous         // it has a duplicate entry for members
2607e1f26343SJason M. Bills         auto getLogEntriesCallback = [asyncResp](
2608e1f26343SJason M. Bills                                          const boost::system::error_code ec,
26091da66f75SEd Tanous                                          const std::vector<std::string>& resp) {
26101da66f75SEd Tanous             if (ec)
26111da66f75SEd Tanous             {
26121da66f75SEd Tanous                 if (ec.value() !=
26131da66f75SEd Tanous                     boost::system::errc::no_such_file_or_directory)
26141da66f75SEd Tanous                 {
26151da66f75SEd Tanous                     BMCWEB_LOG_DEBUG << "failed to get entries ec: "
26161da66f75SEd Tanous                                      << ec.message();
2617f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
26181da66f75SEd Tanous                     return;
26191da66f75SEd Tanous                 }
26201da66f75SEd Tanous             }
2621e1f26343SJason M. Bills             asyncResp->res.jsonValue["@odata.type"] =
26221da66f75SEd Tanous                 "#LogEntryCollection.LogEntryCollection";
26230f74e643SEd Tanous             asyncResp->res.jsonValue["@odata.id"] =
2624424c4176SJason M. Bills                 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
2625424c4176SJason M. Bills             asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
2626e1f26343SJason M. Bills             asyncResp->res.jsonValue["Description"] =
2627424c4176SJason M. Bills                 "Collection of Crashdump Entries";
2628e1f26343SJason M. Bills             nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
2629e1f26343SJason M. Bills             logEntryArray = nlohmann::json::array();
2630e855dd28SJason M. Bills             std::vector<std::string> logIDs;
2631e855dd28SJason M. Bills             // Get the list of log entries and build up an empty array big
2632e855dd28SJason M. Bills             // enough to hold them
26331da66f75SEd Tanous             for (const std::string& objpath : resp)
26341da66f75SEd Tanous             {
2635e855dd28SJason M. Bills                 // Get the log ID
2636f23b7296SEd Tanous                 std::size_t lastPos = objpath.rfind('/');
2637e855dd28SJason M. Bills                 if (lastPos == std::string::npos)
26381da66f75SEd Tanous                 {
2639e855dd28SJason M. Bills                     continue;
26401da66f75SEd Tanous                 }
2641e855dd28SJason M. Bills                 logIDs.emplace_back(objpath.substr(lastPos + 1));
2642e855dd28SJason M. Bills 
2643e855dd28SJason M. Bills                 // Add a space for the log entry to the array
2644e855dd28SJason M. Bills                 logEntryArray.push_back({});
2645e855dd28SJason M. Bills             }
2646e855dd28SJason M. Bills             // Now go through and set up async calls to fill in the entries
2647e855dd28SJason M. Bills             size_t index = 0;
2648e855dd28SJason M. Bills             for (const std::string& logID : logIDs)
2649e855dd28SJason M. Bills             {
2650e855dd28SJason M. Bills                 // Add the log entry to the array
2651e855dd28SJason M. Bills                 logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]);
26521da66f75SEd Tanous             }
2653e1f26343SJason M. Bills             asyncResp->res.jsonValue["Members@odata.count"] =
2654e1f26343SJason M. Bills                 logEntryArray.size();
26551da66f75SEd Tanous         };
26561da66f75SEd Tanous         crow::connections::systemBus->async_method_call(
26571da66f75SEd Tanous             std::move(getLogEntriesCallback),
26581da66f75SEd Tanous             "xyz.openbmc_project.ObjectMapper",
26591da66f75SEd Tanous             "/xyz/openbmc_project/object_mapper",
26601da66f75SEd Tanous             "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0,
26615b61b5e8SJason M. Bills             std::array<const char*, 1>{crashdumpInterface});
26621da66f75SEd Tanous     }
26631da66f75SEd Tanous };
26641da66f75SEd Tanous 
2665424c4176SJason M. Bills class CrashdumpEntry : public Node
26661da66f75SEd Tanous {
26671da66f75SEd Tanous   public:
266852cc112dSEd Tanous     CrashdumpEntry(App& app) :
2669d53dd41fSJason M. Bills         Node(app,
2670424c4176SJason M. Bills              "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/",
26711da66f75SEd Tanous              std::string())
26721da66f75SEd Tanous     {
26733946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
26743946028dSAppaRao Puli         // method for security reasons.
26751da66f75SEd Tanous         entityPrivileges = {
26763946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
26773946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2678e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2679e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2680e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2681e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
26821da66f75SEd Tanous     }
26831da66f75SEd Tanous 
26841da66f75SEd Tanous   private:
2685cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
26861da66f75SEd Tanous                const std::vector<std::string>& params) override
26871da66f75SEd Tanous     {
2688e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
26891da66f75SEd Tanous         if (params.size() != 1)
26901da66f75SEd Tanous         {
2691f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
26921da66f75SEd Tanous             return;
26931da66f75SEd Tanous         }
2694e855dd28SJason M. Bills         const std::string& logID = params[0];
2695e855dd28SJason M. Bills         logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2696e855dd28SJason M. Bills     }
2697e855dd28SJason M. Bills };
2698e855dd28SJason M. Bills 
2699e855dd28SJason M. Bills class CrashdumpFile : public Node
2700e855dd28SJason M. Bills {
2701e855dd28SJason M. Bills   public:
270252cc112dSEd Tanous     CrashdumpFile(App& app) :
2703e855dd28SJason M. Bills         Node(app,
2704e855dd28SJason M. Bills              "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/"
2705e855dd28SJason M. Bills              "<str>/",
2706e855dd28SJason M. Bills              std::string(), std::string())
2707e855dd28SJason M. Bills     {
27083946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
27093946028dSAppaRao Puli         // method for security reasons.
2710e855dd28SJason M. Bills         entityPrivileges = {
27113946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
27123946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2713e855dd28SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2714e855dd28SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2715e855dd28SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2716e855dd28SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2717e855dd28SJason M. Bills     }
2718e855dd28SJason M. Bills 
2719e855dd28SJason M. Bills   private:
2720cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
2721e855dd28SJason M. Bills                const std::vector<std::string>& params) override
2722e855dd28SJason M. Bills     {
2723e855dd28SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2724e855dd28SJason M. Bills         if (params.size() != 2)
2725e855dd28SJason M. Bills         {
2726e855dd28SJason M. Bills             messages::internalError(asyncResp->res);
2727e855dd28SJason M. Bills             return;
2728e855dd28SJason M. Bills         }
2729e855dd28SJason M. Bills         const std::string& logID = params[0];
2730e855dd28SJason M. Bills         const std::string& fileName = params[1];
2731e855dd28SJason M. Bills 
2732043a0536SJohnathan Mantey         auto getStoredLogCallback =
2733043a0536SJohnathan Mantey             [asyncResp, logID, fileName](
2734abf2add6SEd Tanous                 const boost::system::error_code ec,
2735043a0536SJohnathan Mantey                 const std::vector<std::pair<std::string, VariantType>>& resp) {
27361da66f75SEd Tanous                 if (ec)
27371da66f75SEd Tanous                 {
2738043a0536SJohnathan Mantey                     BMCWEB_LOG_DEBUG << "failed to get log ec: "
2739043a0536SJohnathan Mantey                                      << ec.message();
2740f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
27411da66f75SEd Tanous                     return;
27421da66f75SEd Tanous                 }
2743e855dd28SJason M. Bills 
2744043a0536SJohnathan Mantey                 std::string dbusFilename{};
2745043a0536SJohnathan Mantey                 std::string dbusTimestamp{};
2746043a0536SJohnathan Mantey                 std::string dbusFilepath{};
2747043a0536SJohnathan Mantey 
27482c70f800SEd Tanous                 parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
2749043a0536SJohnathan Mantey                                          dbusFilepath);
2750043a0536SJohnathan Mantey 
2751043a0536SJohnathan Mantey                 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2752043a0536SJohnathan Mantey                     dbusFilepath.empty())
27531da66f75SEd Tanous                 {
2754e855dd28SJason M. Bills                     messages::resourceMissingAtURI(asyncResp->res, fileName);
27551da66f75SEd Tanous                     return;
27561da66f75SEd Tanous                 }
2757e855dd28SJason M. Bills 
2758043a0536SJohnathan Mantey                 // Verify the file name parameter is correct
2759043a0536SJohnathan Mantey                 if (fileName != dbusFilename)
2760043a0536SJohnathan Mantey                 {
2761043a0536SJohnathan Mantey                     messages::resourceMissingAtURI(asyncResp->res, fileName);
2762043a0536SJohnathan Mantey                     return;
2763043a0536SJohnathan Mantey                 }
2764043a0536SJohnathan Mantey 
2765043a0536SJohnathan Mantey                 if (!std::filesystem::exists(dbusFilepath))
2766043a0536SJohnathan Mantey                 {
2767043a0536SJohnathan Mantey                     messages::resourceMissingAtURI(asyncResp->res, fileName);
2768043a0536SJohnathan Mantey                     return;
2769043a0536SJohnathan Mantey                 }
2770043a0536SJohnathan Mantey                 std::ifstream ifs(dbusFilepath, std::ios::in |
2771043a0536SJohnathan Mantey                                                     std::ios::binary |
2772043a0536SJohnathan Mantey                                                     std::ios::ate);
2773043a0536SJohnathan Mantey                 std::ifstream::pos_type fileSize = ifs.tellg();
2774043a0536SJohnathan Mantey                 if (fileSize < 0)
2775043a0536SJohnathan Mantey                 {
2776043a0536SJohnathan Mantey                     messages::generalError(asyncResp->res);
2777043a0536SJohnathan Mantey                     return;
2778043a0536SJohnathan Mantey                 }
2779043a0536SJohnathan Mantey                 ifs.seekg(0, std::ios::beg);
2780043a0536SJohnathan Mantey 
2781043a0536SJohnathan Mantey                 auto crashData = std::make_unique<char[]>(
2782043a0536SJohnathan Mantey                     static_cast<unsigned int>(fileSize));
2783043a0536SJohnathan Mantey 
2784043a0536SJohnathan Mantey                 ifs.read(crashData.get(), static_cast<int>(fileSize));
2785043a0536SJohnathan Mantey 
2786043a0536SJohnathan Mantey                 // The cast to std::string is intentional in order to use the
2787043a0536SJohnathan Mantey                 // assign() that applies move mechanics
2788043a0536SJohnathan Mantey                 asyncResp->res.body().assign(
2789043a0536SJohnathan Mantey                     static_cast<std::string>(crashData.get()));
2790043a0536SJohnathan Mantey 
2791043a0536SJohnathan Mantey                 // Configure this to be a file download when accessed from
2792043a0536SJohnathan Mantey                 // a browser
2793e855dd28SJason M. Bills                 asyncResp->res.addHeader("Content-Disposition", "attachment");
27941da66f75SEd Tanous             };
27951da66f75SEd Tanous         crow::connections::systemBus->async_method_call(
27965b61b5e8SJason M. Bills             std::move(getStoredLogCallback), crashdumpObject,
27975b61b5e8SJason M. Bills             crashdumpPath + std::string("/") + logID,
2798043a0536SJohnathan Mantey             "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
27991da66f75SEd Tanous     }
28001da66f75SEd Tanous };
28011da66f75SEd Tanous 
28028e6c099aSJason M. Bills class CrashdumpCollect : public Node
28031da66f75SEd Tanous {
28041da66f75SEd Tanous   public:
28058e6c099aSJason M. Bills     CrashdumpCollect(App& app) :
28068e6c099aSJason M. Bills         Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
28078e6c099aSJason M. Bills                   "LogService.CollectDiagnosticData/")
28081da66f75SEd Tanous     {
28093946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
28103946028dSAppaRao Puli         // method for security reasons.
28111da66f75SEd Tanous         entityPrivileges = {
28123946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
28133946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
28143946028dSAppaRao Puli             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
28153946028dSAppaRao Puli             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
28163946028dSAppaRao Puli             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
28173946028dSAppaRao Puli             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
28181da66f75SEd Tanous     }
28191da66f75SEd Tanous 
28201da66f75SEd Tanous   private:
28211da66f75SEd Tanous     void doPost(crow::Response& res, const crow::Request& req,
2822cb13a392SEd Tanous                 const std::vector<std::string>&) override
28231da66f75SEd Tanous     {
2824e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
28251da66f75SEd Tanous 
28268e6c099aSJason M. Bills         std::string diagnosticDataType;
28278e6c099aSJason M. Bills         std::string oemDiagnosticDataType;
28288e6c099aSJason M. Bills         if (!redfish::json_util::readJson(
28298e6c099aSJason M. Bills                 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
28308e6c099aSJason M. Bills                 "OEMDiagnosticDataType", oemDiagnosticDataType))
28318e6c099aSJason M. Bills         {
28328e6c099aSJason M. Bills             return;
28338e6c099aSJason M. Bills         }
28348e6c099aSJason M. Bills 
28358e6c099aSJason M. Bills         if (diagnosticDataType != "OEM")
28368e6c099aSJason M. Bills         {
28378e6c099aSJason M. Bills             BMCWEB_LOG_ERROR
28388e6c099aSJason M. Bills                 << "Only OEM DiagnosticDataType supported for Crashdump";
28398e6c099aSJason M. Bills             messages::actionParameterValueFormatError(
28408e6c099aSJason M. Bills                 asyncResp->res, diagnosticDataType, "DiagnosticDataType",
28418e6c099aSJason M. Bills                 "CollectDiagnosticData");
28428e6c099aSJason M. Bills             return;
28438e6c099aSJason M. Bills         }
28448e6c099aSJason M. Bills 
28458e6c099aSJason M. Bills         auto collectCrashdumpCallback = [asyncResp, req](
28468e6c099aSJason M. Bills                                             const boost::system::error_code ec,
2847cb13a392SEd Tanous                                             const std::string&) {
28481da66f75SEd Tanous             if (ec)
28491da66f75SEd Tanous             {
285046229577SJames Feist                 if (ec.value() == boost::system::errc::operation_not_supported)
28511da66f75SEd Tanous                 {
2852f12894f8SJason M. Bills                     messages::resourceInStandby(asyncResp->res);
28531da66f75SEd Tanous                 }
28544363d3b2SJason M. Bills                 else if (ec.value() ==
28554363d3b2SJason M. Bills                          boost::system::errc::device_or_resource_busy)
28564363d3b2SJason M. Bills                 {
28574363d3b2SJason M. Bills                     messages::serviceTemporarilyUnavailable(asyncResp->res,
28584363d3b2SJason M. Bills                                                             "60");
28594363d3b2SJason M. Bills                 }
28601da66f75SEd Tanous                 else
28611da66f75SEd Tanous                 {
2862f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
28631da66f75SEd Tanous                 }
28641da66f75SEd Tanous                 return;
28651da66f75SEd Tanous             }
286646229577SJames Feist             std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
286766afe4faSJames Feist                 [](boost::system::error_code err, sdbusplus::message::message&,
286866afe4faSJames Feist                    const std::shared_ptr<task::TaskData>& taskData) {
286966afe4faSJames Feist                     if (!err)
287066afe4faSJames Feist                     {
2871e5d5006bSJames Feist                         taskData->messages.emplace_back(
2872e5d5006bSJames Feist                             messages::taskCompletedOK(
2873e5d5006bSJames Feist                                 std::to_string(taskData->index)));
2874831d6b09SJames Feist                         taskData->state = "Completed";
287566afe4faSJames Feist                     }
287632898ceaSJames Feist                     return task::completed;
287766afe4faSJames Feist                 },
287846229577SJames Feist                 "type='signal',interface='org.freedesktop.DBus.Properties',"
287946229577SJames Feist                 "member='PropertiesChanged',arg0namespace='com.intel."
288046229577SJames Feist                 "crashdump'");
288146229577SJames Feist             task->startTimer(std::chrono::minutes(5));
288246229577SJames Feist             task->populateResp(asyncResp->res);
2883fe306728SJames Feist             task->payload.emplace(req);
28841da66f75SEd Tanous         };
28858e6c099aSJason M. Bills 
28868e6c099aSJason M. Bills         if (oemDiagnosticDataType == "OnDemand")
28878e6c099aSJason M. Bills         {
28881da66f75SEd Tanous             crow::connections::systemBus->async_method_call(
28898e6c099aSJason M. Bills                 std::move(collectCrashdumpCallback), crashdumpObject,
28908e6c099aSJason M. Bills                 crashdumpPath, crashdumpOnDemandInterface,
28918e6c099aSJason M. Bills                 "GenerateOnDemandLog");
28921da66f75SEd Tanous         }
28938e6c099aSJason M. Bills         else if (oemDiagnosticDataType == "Telemetry")
28946eda7685SKenny L. Ku         {
28958e6c099aSJason M. Bills             crow::connections::systemBus->async_method_call(
28968e6c099aSJason M. Bills                 std::move(collectCrashdumpCallback), crashdumpObject,
28978e6c099aSJason M. Bills                 crashdumpPath, crashdumpTelemetryInterface,
28988e6c099aSJason M. Bills                 "GenerateTelemetryLog");
28996eda7685SKenny L. Ku         }
29006eda7685SKenny L. Ku         else
29016eda7685SKenny L. Ku         {
29028e6c099aSJason M. Bills             BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: "
29038e6c099aSJason M. Bills                              << oemDiagnosticDataType;
29048e6c099aSJason M. Bills             messages::actionParameterValueFormatError(
29058e6c099aSJason M. Bills                 asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType",
29068e6c099aSJason M. Bills                 "CollectDiagnosticData");
29076eda7685SKenny L. Ku             return;
29086eda7685SKenny L. Ku         }
29096eda7685SKenny L. Ku     }
29106eda7685SKenny L. Ku };
29116eda7685SKenny L. Ku 
2912e1f26343SJason M. Bills class SendRawPECI : public Node
29131da66f75SEd Tanous {
29141da66f75SEd Tanous   public:
291552cc112dSEd Tanous     SendRawPECI(App& app) :
2916424c4176SJason M. Bills         Node(app,
2917424c4176SJason M. Bills              "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2918424c4176SJason M. Bills              "Crashdump.SendRawPeci/")
29191da66f75SEd Tanous     {
29203946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
29213946028dSAppaRao Puli         // method for security reasons.
29221da66f75SEd Tanous         entityPrivileges = {
29231da66f75SEd Tanous             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
29241da66f75SEd Tanous             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
29251da66f75SEd Tanous             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
29261da66f75SEd Tanous             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
29271da66f75SEd Tanous             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
29281da66f75SEd Tanous             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
29291da66f75SEd Tanous     }
29301da66f75SEd Tanous 
29311da66f75SEd Tanous   private:
29321da66f75SEd Tanous     void doPost(crow::Response& res, const crow::Request& req,
2933cb13a392SEd Tanous                 const std::vector<std::string>&) override
29341da66f75SEd Tanous     {
2935e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
29368724c297SKarthick Sundarrajan         std::vector<std::vector<uint8_t>> peciCommands;
29378724c297SKarthick Sundarrajan 
29388724c297SKarthick Sundarrajan         if (!json_util::readJson(req, res, "PECICommands", peciCommands))
29398724c297SKarthick Sundarrajan         {
29408724c297SKarthick Sundarrajan             return;
29418724c297SKarthick Sundarrajan         }
29428724c297SKarthick Sundarrajan         uint32_t idx = 0;
29438724c297SKarthick Sundarrajan         for (auto const& cmd : peciCommands)
29448724c297SKarthick Sundarrajan         {
29458724c297SKarthick Sundarrajan             if (cmd.size() < 3)
29468724c297SKarthick Sundarrajan             {
29478724c297SKarthick Sundarrajan                 std::string s("[");
29488724c297SKarthick Sundarrajan                 for (auto const& val : cmd)
29498724c297SKarthick Sundarrajan                 {
29508724c297SKarthick Sundarrajan                     if (val != *cmd.begin())
29518724c297SKarthick Sundarrajan                     {
29528724c297SKarthick Sundarrajan                         s += ",";
29538724c297SKarthick Sundarrajan                     }
29548724c297SKarthick Sundarrajan                     s += std::to_string(val);
29558724c297SKarthick Sundarrajan                 }
29568724c297SKarthick Sundarrajan                 s += "]";
29578724c297SKarthick Sundarrajan                 messages::actionParameterValueFormatError(
29588724c297SKarthick Sundarrajan                     res, s, "PECICommands[" + std::to_string(idx) + "]",
29598724c297SKarthick Sundarrajan                     "SendRawPeci");
29608724c297SKarthick Sundarrajan                 return;
29618724c297SKarthick Sundarrajan             }
29628724c297SKarthick Sundarrajan             idx++;
29638724c297SKarthick Sundarrajan         }
29641da66f75SEd Tanous         // Callback to return the Raw PECI response
2965e1f26343SJason M. Bills         auto sendRawPECICallback =
2966e1f26343SJason M. Bills             [asyncResp](const boost::system::error_code ec,
29678724c297SKarthick Sundarrajan                         const std::vector<std::vector<uint8_t>>& resp) {
29681da66f75SEd Tanous                 if (ec)
29691da66f75SEd Tanous                 {
29708724c297SKarthick Sundarrajan                     BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: "
29711da66f75SEd Tanous                                      << ec.message();
2972f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
29731da66f75SEd Tanous                     return;
29741da66f75SEd Tanous                 }
2975e1f26343SJason M. Bills                 asyncResp->res.jsonValue = {{"Name", "PECI Command Response"},
29761da66f75SEd Tanous                                             {"PECIResponse", resp}};
29771da66f75SEd Tanous             };
29781da66f75SEd Tanous         // Call the SendRawPECI command with the provided data
29791da66f75SEd Tanous         crow::connections::systemBus->async_method_call(
29805b61b5e8SJason M. Bills             std::move(sendRawPECICallback), crashdumpObject, crashdumpPath,
29818724c297SKarthick Sundarrajan             crashdumpRawPECIInterface, "SendRawPeci", peciCommands);
29821da66f75SEd Tanous     }
29831da66f75SEd Tanous };
29841da66f75SEd Tanous 
2985cb92c03bSAndrew Geissler /**
2986cb92c03bSAndrew Geissler  * DBusLogServiceActionsClear class supports POST method for ClearLog action.
2987cb92c03bSAndrew Geissler  */
2988cb92c03bSAndrew Geissler class DBusLogServiceActionsClear : public Node
2989cb92c03bSAndrew Geissler {
2990cb92c03bSAndrew Geissler   public:
299152cc112dSEd Tanous     DBusLogServiceActionsClear(App& app) :
2992cb92c03bSAndrew Geissler         Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
29937af91514SGunnar Mills                   "LogService.ClearLog/")
2994cb92c03bSAndrew Geissler     {
2995cb92c03bSAndrew Geissler         entityPrivileges = {
2996cb92c03bSAndrew Geissler             {boost::beast::http::verb::get, {{"Login"}}},
2997cb92c03bSAndrew Geissler             {boost::beast::http::verb::head, {{"Login"}}},
2998cb92c03bSAndrew Geissler             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2999cb92c03bSAndrew Geissler             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3000cb92c03bSAndrew Geissler             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3001cb92c03bSAndrew Geissler             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3002cb92c03bSAndrew Geissler     }
3003cb92c03bSAndrew Geissler 
3004cb92c03bSAndrew Geissler   private:
3005cb92c03bSAndrew Geissler     /**
3006cb92c03bSAndrew Geissler      * Function handles POST method request.
3007cb92c03bSAndrew Geissler      * The Clear Log actions does not require any parameter.The action deletes
3008cb92c03bSAndrew Geissler      * all entries found in the Entries collection for this Log Service.
3009cb92c03bSAndrew Geissler      */
3010cb13a392SEd Tanous     void doPost(crow::Response& res, const crow::Request&,
3011cb13a392SEd Tanous                 const std::vector<std::string>&) override
3012cb92c03bSAndrew Geissler     {
3013cb92c03bSAndrew Geissler         BMCWEB_LOG_DEBUG << "Do delete all entries.";
3014cb92c03bSAndrew Geissler 
3015cb92c03bSAndrew Geissler         auto asyncResp = std::make_shared<AsyncResp>(res);
3016cb92c03bSAndrew Geissler         // Process response from Logging service.
30172c70f800SEd Tanous         auto respHandler = [asyncResp](const boost::system::error_code ec) {
3018cb92c03bSAndrew Geissler             BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done";
3019cb92c03bSAndrew Geissler             if (ec)
3020cb92c03bSAndrew Geissler             {
3021cb92c03bSAndrew Geissler                 // TODO Handle for specific error code
3022cb92c03bSAndrew Geissler                 BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec;
3023cb92c03bSAndrew Geissler                 asyncResp->res.result(
3024cb92c03bSAndrew Geissler                     boost::beast::http::status::internal_server_error);
3025cb92c03bSAndrew Geissler                 return;
3026cb92c03bSAndrew Geissler             }
3027cb92c03bSAndrew Geissler 
3028cb92c03bSAndrew Geissler             asyncResp->res.result(boost::beast::http::status::no_content);
3029cb92c03bSAndrew Geissler         };
3030cb92c03bSAndrew Geissler 
3031cb92c03bSAndrew Geissler         // Make call to Logging service to request Clear Log
3032cb92c03bSAndrew Geissler         crow::connections::systemBus->async_method_call(
30332c70f800SEd Tanous             respHandler, "xyz.openbmc_project.Logging",
3034cb92c03bSAndrew Geissler             "/xyz/openbmc_project/logging",
3035cb92c03bSAndrew Geissler             "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3036cb92c03bSAndrew Geissler     }
3037cb92c03bSAndrew Geissler };
3038a3316fc6SZhikuiRen 
3039a3316fc6SZhikuiRen /****************************************************
3040a3316fc6SZhikuiRen  * Redfish PostCode interfaces
3041a3316fc6SZhikuiRen  * using DBUS interface: getPostCodesTS
3042a3316fc6SZhikuiRen  ******************************************************/
3043a3316fc6SZhikuiRen class PostCodesLogService : public Node
3044a3316fc6SZhikuiRen {
3045a3316fc6SZhikuiRen   public:
304652cc112dSEd Tanous     PostCodesLogService(App& app) :
3047a3316fc6SZhikuiRen         Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/")
3048a3316fc6SZhikuiRen     {
3049a3316fc6SZhikuiRen         entityPrivileges = {
3050a3316fc6SZhikuiRen             {boost::beast::http::verb::get, {{"Login"}}},
3051a3316fc6SZhikuiRen             {boost::beast::http::verb::head, {{"Login"}}},
3052a3316fc6SZhikuiRen             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3053a3316fc6SZhikuiRen             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3054a3316fc6SZhikuiRen             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3055a3316fc6SZhikuiRen             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3056a3316fc6SZhikuiRen     }
3057a3316fc6SZhikuiRen 
3058a3316fc6SZhikuiRen   private:
3059cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
3060cb13a392SEd Tanous                const std::vector<std::string>&) override
3061a3316fc6SZhikuiRen     {
3062a3316fc6SZhikuiRen         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3063a3316fc6SZhikuiRen 
3064a3316fc6SZhikuiRen         asyncResp->res.jsonValue = {
3065a3316fc6SZhikuiRen             {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"},
3066a3316fc6SZhikuiRen             {"@odata.type", "#LogService.v1_1_0.LogService"},
3067a3316fc6SZhikuiRen             {"Name", "POST Code Log Service"},
3068a3316fc6SZhikuiRen             {"Description", "POST Code Log Service"},
3069a3316fc6SZhikuiRen             {"Id", "BIOS POST Code Log"},
3070a3316fc6SZhikuiRen             {"OverWritePolicy", "WrapsWhenFull"},
3071a3316fc6SZhikuiRen             {"Entries",
3072a3316fc6SZhikuiRen              {{"@odata.id",
3073a3316fc6SZhikuiRen                "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}};
3074a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
3075a3316fc6SZhikuiRen             {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/"
3076a3316fc6SZhikuiRen                        "Actions/LogService.ClearLog"}};
3077a3316fc6SZhikuiRen     }
3078a3316fc6SZhikuiRen };
3079a3316fc6SZhikuiRen 
3080a3316fc6SZhikuiRen class PostCodesClear : public Node
3081a3316fc6SZhikuiRen {
3082a3316fc6SZhikuiRen   public:
308352cc112dSEd Tanous     PostCodesClear(App& app) :
3084a3316fc6SZhikuiRen         Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/"
3085a3316fc6SZhikuiRen                   "LogService.ClearLog/")
3086a3316fc6SZhikuiRen     {
3087a3316fc6SZhikuiRen         entityPrivileges = {
3088a3316fc6SZhikuiRen             {boost::beast::http::verb::get, {{"Login"}}},
3089a3316fc6SZhikuiRen             {boost::beast::http::verb::head, {{"Login"}}},
30903946028dSAppaRao Puli             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
30913946028dSAppaRao Puli             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
30923946028dSAppaRao Puli             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
30933946028dSAppaRao Puli             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
3094a3316fc6SZhikuiRen     }
3095a3316fc6SZhikuiRen 
3096a3316fc6SZhikuiRen   private:
3097cb13a392SEd Tanous     void doPost(crow::Response& res, const crow::Request&,
3098cb13a392SEd Tanous                 const std::vector<std::string>&) override
3099a3316fc6SZhikuiRen     {
3100a3316fc6SZhikuiRen         BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
3101a3316fc6SZhikuiRen 
3102a3316fc6SZhikuiRen         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3103a3316fc6SZhikuiRen         // Make call to post-code service to request clear all
3104a3316fc6SZhikuiRen         crow::connections::systemBus->async_method_call(
3105a3316fc6SZhikuiRen             [asyncResp](const boost::system::error_code ec) {
3106a3316fc6SZhikuiRen                 if (ec)
3107a3316fc6SZhikuiRen                 {
3108a3316fc6SZhikuiRen                     // TODO Handle for specific error code
3109a3316fc6SZhikuiRen                     BMCWEB_LOG_ERROR
3110a3316fc6SZhikuiRen                         << "doClearPostCodes resp_handler got error " << ec;
3111a3316fc6SZhikuiRen                     asyncResp->res.result(
3112a3316fc6SZhikuiRen                         boost::beast::http::status::internal_server_error);
3113a3316fc6SZhikuiRen                     messages::internalError(asyncResp->res);
3114a3316fc6SZhikuiRen                     return;
3115a3316fc6SZhikuiRen                 }
3116a3316fc6SZhikuiRen             },
311715124765SJonathan Doman             "xyz.openbmc_project.State.Boot.PostCode0",
311815124765SJonathan Doman             "/xyz/openbmc_project/State/Boot/PostCode0",
3119a3316fc6SZhikuiRen             "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3120a3316fc6SZhikuiRen     }
3121a3316fc6SZhikuiRen };
3122a3316fc6SZhikuiRen 
3123a3316fc6SZhikuiRen static void fillPostCodeEntry(
3124b5a76932SEd Tanous     const std::shared_ptr<AsyncResp>& aResp,
31256c9a279eSManojkiran Eda     const boost::container::flat_map<
31266c9a279eSManojkiran Eda         uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode,
3127a3316fc6SZhikuiRen     const uint16_t bootIndex, const uint64_t codeIndex = 0,
3128a3316fc6SZhikuiRen     const uint64_t skip = 0, const uint64_t top = 0)
3129a3316fc6SZhikuiRen {
3130a3316fc6SZhikuiRen     // Get the Message from the MessageRegistry
3131a3316fc6SZhikuiRen     const message_registries::Message* message =
3132a3316fc6SZhikuiRen         message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode");
3133a3316fc6SZhikuiRen 
3134a3316fc6SZhikuiRen     uint64_t currentCodeIndex = 0;
3135a3316fc6SZhikuiRen     nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"];
3136a3316fc6SZhikuiRen 
3137a3316fc6SZhikuiRen     uint64_t firstCodeTimeUs = 0;
31386c9a279eSManojkiran Eda     for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
31396c9a279eSManojkiran Eda              code : postcode)
3140a3316fc6SZhikuiRen     {
3141a3316fc6SZhikuiRen         currentCodeIndex++;
3142a3316fc6SZhikuiRen         std::string postcodeEntryID =
3143a3316fc6SZhikuiRen             "B" + std::to_string(bootIndex) + "-" +
3144a3316fc6SZhikuiRen             std::to_string(currentCodeIndex); // 1 based index in EntryID string
3145a3316fc6SZhikuiRen 
3146a3316fc6SZhikuiRen         uint64_t usecSinceEpoch = code.first;
3147a3316fc6SZhikuiRen         uint64_t usTimeOffset = 0;
3148a3316fc6SZhikuiRen 
3149a3316fc6SZhikuiRen         if (1 == currentCodeIndex)
3150a3316fc6SZhikuiRen         { // already incremented
3151a3316fc6SZhikuiRen             firstCodeTimeUs = code.first;
3152a3316fc6SZhikuiRen         }
3153a3316fc6SZhikuiRen         else
3154a3316fc6SZhikuiRen         {
3155a3316fc6SZhikuiRen             usTimeOffset = code.first - firstCodeTimeUs;
3156a3316fc6SZhikuiRen         }
3157a3316fc6SZhikuiRen 
3158a3316fc6SZhikuiRen         // skip if no specific codeIndex is specified and currentCodeIndex does
3159a3316fc6SZhikuiRen         // not fall between top and skip
3160a3316fc6SZhikuiRen         if ((codeIndex == 0) &&
3161a3316fc6SZhikuiRen             (currentCodeIndex <= skip || currentCodeIndex > top))
3162a3316fc6SZhikuiRen         {
3163a3316fc6SZhikuiRen             continue;
3164a3316fc6SZhikuiRen         }
3165a3316fc6SZhikuiRen 
31664e0453b1SGunnar Mills         // skip if a specific codeIndex is specified and does not match the
3167a3316fc6SZhikuiRen         // currentIndex
3168a3316fc6SZhikuiRen         if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3169a3316fc6SZhikuiRen         {
3170a3316fc6SZhikuiRen             // This is done for simplicity. 1st entry is needed to calculate
3171a3316fc6SZhikuiRen             // time offset. To improve efficiency, one can get to the entry
3172a3316fc6SZhikuiRen             // directly (possibly with flatmap's nth method)
3173a3316fc6SZhikuiRen             continue;
3174a3316fc6SZhikuiRen         }
3175a3316fc6SZhikuiRen 
3176a3316fc6SZhikuiRen         // currentCodeIndex is within top and skip or equal to specified code
3177a3316fc6SZhikuiRen         // index
3178a3316fc6SZhikuiRen 
3179a3316fc6SZhikuiRen         // Get the Created time from the timestamp
3180a3316fc6SZhikuiRen         std::string entryTimeStr;
31819c620e21SAsmitha Karunanithi         entryTimeStr = crow::utility::getDateTime(
31829c620e21SAsmitha Karunanithi             static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000));
3183a3316fc6SZhikuiRen 
3184a3316fc6SZhikuiRen         // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3185a3316fc6SZhikuiRen         std::ostringstream hexCode;
3186a3316fc6SZhikuiRen         hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
31876c9a279eSManojkiran Eda                 << std::get<0>(code.second);
3188a3316fc6SZhikuiRen         std::ostringstream timeOffsetStr;
3189a3316fc6SZhikuiRen         // Set Fixed -Point Notation
3190a3316fc6SZhikuiRen         timeOffsetStr << std::fixed;
3191a3316fc6SZhikuiRen         // Set precision to 4 digits
3192a3316fc6SZhikuiRen         timeOffsetStr << std::setprecision(4);
3193a3316fc6SZhikuiRen         // Add double to stream
3194a3316fc6SZhikuiRen         timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3195a3316fc6SZhikuiRen         std::vector<std::string> messageArgs = {
3196a3316fc6SZhikuiRen             std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()};
3197a3316fc6SZhikuiRen 
3198a3316fc6SZhikuiRen         // Get MessageArgs template from message registry
3199a3316fc6SZhikuiRen         std::string msg;
3200a3316fc6SZhikuiRen         if (message != nullptr)
3201a3316fc6SZhikuiRen         {
3202a3316fc6SZhikuiRen             msg = message->message;
3203a3316fc6SZhikuiRen 
3204a3316fc6SZhikuiRen             // fill in this post code value
3205a3316fc6SZhikuiRen             int i = 0;
3206a3316fc6SZhikuiRen             for (const std::string& messageArg : messageArgs)
3207a3316fc6SZhikuiRen             {
3208a3316fc6SZhikuiRen                 std::string argStr = "%" + std::to_string(++i);
3209a3316fc6SZhikuiRen                 size_t argPos = msg.find(argStr);
3210a3316fc6SZhikuiRen                 if (argPos != std::string::npos)
3211a3316fc6SZhikuiRen                 {
3212a3316fc6SZhikuiRen                     msg.replace(argPos, argStr.length(), messageArg);
3213a3316fc6SZhikuiRen                 }
3214a3316fc6SZhikuiRen             }
3215a3316fc6SZhikuiRen         }
3216a3316fc6SZhikuiRen 
3217d4342a92STim Lee         // Get Severity template from message registry
3218d4342a92STim Lee         std::string severity;
3219d4342a92STim Lee         if (message != nullptr)
3220d4342a92STim Lee         {
3221d4342a92STim Lee             severity = message->severity;
3222d4342a92STim Lee         }
3223d4342a92STim Lee 
3224a3316fc6SZhikuiRen         // add to AsyncResp
3225a3316fc6SZhikuiRen         logEntryArray.push_back({});
3226a3316fc6SZhikuiRen         nlohmann::json& bmcLogEntry = logEntryArray.back();
3227743e9a1fSGunnar Mills         bmcLogEntry = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
3228a3316fc6SZhikuiRen                        {"@odata.id", "/redfish/v1/Systems/system/LogServices/"
3229a3316fc6SZhikuiRen                                      "PostCodes/Entries/" +
3230a3316fc6SZhikuiRen                                          postcodeEntryID},
3231a3316fc6SZhikuiRen                        {"Name", "POST Code Log Entry"},
3232a3316fc6SZhikuiRen                        {"Id", postcodeEntryID},
3233a3316fc6SZhikuiRen                        {"Message", std::move(msg)},
3234a3316fc6SZhikuiRen                        {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"},
3235a3316fc6SZhikuiRen                        {"MessageArgs", std::move(messageArgs)},
3236a3316fc6SZhikuiRen                        {"EntryType", "Event"},
3237a3316fc6SZhikuiRen                        {"Severity", std::move(severity)},
32389c620e21SAsmitha Karunanithi                        {"Created", entryTimeStr}};
3239a3316fc6SZhikuiRen     }
3240a3316fc6SZhikuiRen }
3241a3316fc6SZhikuiRen 
3242b5a76932SEd Tanous static void getPostCodeForEntry(const std::shared_ptr<AsyncResp>& aResp,
3243a3316fc6SZhikuiRen                                 const uint16_t bootIndex,
3244a3316fc6SZhikuiRen                                 const uint64_t codeIndex)
3245a3316fc6SZhikuiRen {
3246a3316fc6SZhikuiRen     crow::connections::systemBus->async_method_call(
32476c9a279eSManojkiran Eda         [aResp, bootIndex,
32486c9a279eSManojkiran Eda          codeIndex](const boost::system::error_code ec,
32496c9a279eSManojkiran Eda                     const boost::container::flat_map<
32506c9a279eSManojkiran Eda                         uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
32516c9a279eSManojkiran Eda                         postcode) {
3252a3316fc6SZhikuiRen             if (ec)
3253a3316fc6SZhikuiRen             {
3254a3316fc6SZhikuiRen                 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3255a3316fc6SZhikuiRen                 messages::internalError(aResp->res);
3256a3316fc6SZhikuiRen                 return;
3257a3316fc6SZhikuiRen             }
3258a3316fc6SZhikuiRen 
3259a3316fc6SZhikuiRen             // skip the empty postcode boots
3260a3316fc6SZhikuiRen             if (postcode.empty())
3261a3316fc6SZhikuiRen             {
3262a3316fc6SZhikuiRen                 return;
3263a3316fc6SZhikuiRen             }
3264a3316fc6SZhikuiRen 
3265a3316fc6SZhikuiRen             fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex);
3266a3316fc6SZhikuiRen 
3267a3316fc6SZhikuiRen             aResp->res.jsonValue["Members@odata.count"] =
3268a3316fc6SZhikuiRen                 aResp->res.jsonValue["Members"].size();
3269a3316fc6SZhikuiRen         },
327015124765SJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode0",
327115124765SJonathan Doman         "/xyz/openbmc_project/State/Boot/PostCode0",
3272a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3273a3316fc6SZhikuiRen         bootIndex);
3274a3316fc6SZhikuiRen }
3275a3316fc6SZhikuiRen 
3276b5a76932SEd Tanous static void getPostCodeForBoot(const std::shared_ptr<AsyncResp>& aResp,
3277a3316fc6SZhikuiRen                                const uint16_t bootIndex,
3278a3316fc6SZhikuiRen                                const uint16_t bootCount,
3279a3316fc6SZhikuiRen                                const uint64_t entryCount, const uint64_t skip,
3280a3316fc6SZhikuiRen                                const uint64_t top)
3281a3316fc6SZhikuiRen {
3282a3316fc6SZhikuiRen     crow::connections::systemBus->async_method_call(
3283a3316fc6SZhikuiRen         [aResp, bootIndex, bootCount, entryCount, skip,
3284a3316fc6SZhikuiRen          top](const boost::system::error_code ec,
32856c9a279eSManojkiran Eda               const boost::container::flat_map<
32866c9a279eSManojkiran Eda                   uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
32876c9a279eSManojkiran Eda                   postcode) {
3288a3316fc6SZhikuiRen             if (ec)
3289a3316fc6SZhikuiRen             {
3290a3316fc6SZhikuiRen                 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3291a3316fc6SZhikuiRen                 messages::internalError(aResp->res);
3292a3316fc6SZhikuiRen                 return;
3293a3316fc6SZhikuiRen             }
3294a3316fc6SZhikuiRen 
3295a3316fc6SZhikuiRen             uint64_t endCount = entryCount;
3296a3316fc6SZhikuiRen             if (!postcode.empty())
3297a3316fc6SZhikuiRen             {
3298a3316fc6SZhikuiRen                 endCount = entryCount + postcode.size();
3299a3316fc6SZhikuiRen 
3300a3316fc6SZhikuiRen                 if ((skip < endCount) && ((top + skip) > entryCount))
3301a3316fc6SZhikuiRen                 {
3302a3316fc6SZhikuiRen                     uint64_t thisBootSkip =
3303a3316fc6SZhikuiRen                         std::max(skip, entryCount) - entryCount;
3304a3316fc6SZhikuiRen                     uint64_t thisBootTop =
3305a3316fc6SZhikuiRen                         std::min(top + skip, endCount) - entryCount;
3306a3316fc6SZhikuiRen 
3307a3316fc6SZhikuiRen                     fillPostCodeEntry(aResp, postcode, bootIndex, 0,
3308a3316fc6SZhikuiRen                                       thisBootSkip, thisBootTop);
3309a3316fc6SZhikuiRen                 }
3310a3316fc6SZhikuiRen                 aResp->res.jsonValue["Members@odata.count"] = endCount;
3311a3316fc6SZhikuiRen             }
3312a3316fc6SZhikuiRen 
3313a3316fc6SZhikuiRen             // continue to previous bootIndex
3314a3316fc6SZhikuiRen             if (bootIndex < bootCount)
3315a3316fc6SZhikuiRen             {
3316a3316fc6SZhikuiRen                 getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1),
3317a3316fc6SZhikuiRen                                    bootCount, endCount, skip, top);
3318a3316fc6SZhikuiRen             }
3319a3316fc6SZhikuiRen             else
3320a3316fc6SZhikuiRen             {
3321a3316fc6SZhikuiRen                 aResp->res.jsonValue["Members@odata.nextLink"] =
3322a3316fc6SZhikuiRen                     "/redfish/v1/Systems/system/LogServices/PostCodes/"
3323a3316fc6SZhikuiRen                     "Entries?$skip=" +
3324a3316fc6SZhikuiRen                     std::to_string(skip + top);
3325a3316fc6SZhikuiRen             }
3326a3316fc6SZhikuiRen         },
332715124765SJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode0",
332815124765SJonathan Doman         "/xyz/openbmc_project/State/Boot/PostCode0",
3329a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3330a3316fc6SZhikuiRen         bootIndex);
3331a3316fc6SZhikuiRen }
3332a3316fc6SZhikuiRen 
3333b5a76932SEd Tanous static void getCurrentBootNumber(const std::shared_ptr<AsyncResp>& aResp,
3334a3316fc6SZhikuiRen                                  const uint64_t skip, const uint64_t top)
3335a3316fc6SZhikuiRen {
3336a3316fc6SZhikuiRen     uint64_t entryCount = 0;
3337a3316fc6SZhikuiRen     crow::connections::systemBus->async_method_call(
3338a3316fc6SZhikuiRen         [aResp, entryCount, skip,
3339a3316fc6SZhikuiRen          top](const boost::system::error_code ec,
3340a3316fc6SZhikuiRen               const std::variant<uint16_t>& bootCount) {
3341a3316fc6SZhikuiRen             if (ec)
3342a3316fc6SZhikuiRen             {
3343a3316fc6SZhikuiRen                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
3344a3316fc6SZhikuiRen                 messages::internalError(aResp->res);
3345a3316fc6SZhikuiRen                 return;
3346a3316fc6SZhikuiRen             }
3347a3316fc6SZhikuiRen             auto pVal = std::get_if<uint16_t>(&bootCount);
3348a3316fc6SZhikuiRen             if (pVal)
3349a3316fc6SZhikuiRen             {
3350a3316fc6SZhikuiRen                 getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top);
3351a3316fc6SZhikuiRen             }
3352a3316fc6SZhikuiRen             else
3353a3316fc6SZhikuiRen             {
3354a3316fc6SZhikuiRen                 BMCWEB_LOG_DEBUG << "Post code boot index failed.";
3355a3316fc6SZhikuiRen             }
3356a3316fc6SZhikuiRen         },
335715124765SJonathan Doman         "xyz.openbmc_project.State.Boot.PostCode0",
335815124765SJonathan Doman         "/xyz/openbmc_project/State/Boot/PostCode0",
3359a3316fc6SZhikuiRen         "org.freedesktop.DBus.Properties", "Get",
3360a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
3361a3316fc6SZhikuiRen }
3362a3316fc6SZhikuiRen 
3363a3316fc6SZhikuiRen class PostCodesEntryCollection : public Node
3364a3316fc6SZhikuiRen {
3365a3316fc6SZhikuiRen   public:
336652cc112dSEd Tanous     PostCodesEntryCollection(App& app) :
3367a3316fc6SZhikuiRen         Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/")
3368a3316fc6SZhikuiRen     {
3369a3316fc6SZhikuiRen         entityPrivileges = {
3370a3316fc6SZhikuiRen             {boost::beast::http::verb::get, {{"Login"}}},
3371a3316fc6SZhikuiRen             {boost::beast::http::verb::head, {{"Login"}}},
3372a3316fc6SZhikuiRen             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3373a3316fc6SZhikuiRen             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3374a3316fc6SZhikuiRen             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3375a3316fc6SZhikuiRen             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3376a3316fc6SZhikuiRen     }
3377a3316fc6SZhikuiRen 
3378a3316fc6SZhikuiRen   private:
3379a3316fc6SZhikuiRen     void doGet(crow::Response& res, const crow::Request& req,
3380cb13a392SEd Tanous                const std::vector<std::string>&) override
3381a3316fc6SZhikuiRen     {
3382a3316fc6SZhikuiRen         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3383a3316fc6SZhikuiRen 
3384a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.type"] =
3385a3316fc6SZhikuiRen             "#LogEntryCollection.LogEntryCollection";
3386a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.id"] =
3387a3316fc6SZhikuiRen             "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
3388a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3389a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Description"] =
3390a3316fc6SZhikuiRen             "Collection of POST Code Log Entries";
3391a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3392a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members@odata.count"] = 0;
3393a3316fc6SZhikuiRen 
3394a3316fc6SZhikuiRen         uint64_t skip = 0;
3395a3316fc6SZhikuiRen         uint64_t top = maxEntriesPerPage; // Show max entries by default
3396a3316fc6SZhikuiRen         if (!getSkipParam(asyncResp->res, req, skip))
3397a3316fc6SZhikuiRen         {
3398a3316fc6SZhikuiRen             return;
3399a3316fc6SZhikuiRen         }
3400a3316fc6SZhikuiRen         if (!getTopParam(asyncResp->res, req, top))
3401a3316fc6SZhikuiRen         {
3402a3316fc6SZhikuiRen             return;
3403a3316fc6SZhikuiRen         }
3404a3316fc6SZhikuiRen         getCurrentBootNumber(asyncResp, skip, top);
3405a3316fc6SZhikuiRen     }
3406a3316fc6SZhikuiRen };
3407a3316fc6SZhikuiRen 
3408a3316fc6SZhikuiRen class PostCodesEntry : public Node
3409a3316fc6SZhikuiRen {
3410a3316fc6SZhikuiRen   public:
341152cc112dSEd Tanous     PostCodesEntry(App& app) :
3412a3316fc6SZhikuiRen         Node(app,
3413a3316fc6SZhikuiRen              "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/",
3414a3316fc6SZhikuiRen              std::string())
3415a3316fc6SZhikuiRen     {
3416a3316fc6SZhikuiRen         entityPrivileges = {
3417a3316fc6SZhikuiRen             {boost::beast::http::verb::get, {{"Login"}}},
3418a3316fc6SZhikuiRen             {boost::beast::http::verb::head, {{"Login"}}},
3419a3316fc6SZhikuiRen             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3420a3316fc6SZhikuiRen             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3421a3316fc6SZhikuiRen             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3422a3316fc6SZhikuiRen             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3423a3316fc6SZhikuiRen     }
3424a3316fc6SZhikuiRen 
3425a3316fc6SZhikuiRen   private:
3426cb13a392SEd Tanous     void doGet(crow::Response& res, const crow::Request&,
3427a3316fc6SZhikuiRen                const std::vector<std::string>& params) override
3428a3316fc6SZhikuiRen     {
3429a3316fc6SZhikuiRen         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3430a3316fc6SZhikuiRen         if (params.size() != 1)
3431a3316fc6SZhikuiRen         {
3432a3316fc6SZhikuiRen             messages::internalError(asyncResp->res);
3433a3316fc6SZhikuiRen             return;
3434a3316fc6SZhikuiRen         }
3435a3316fc6SZhikuiRen 
3436a3316fc6SZhikuiRen         const std::string& targetID = params[0];
3437a3316fc6SZhikuiRen 
3438a3316fc6SZhikuiRen         size_t bootPos = targetID.find('B');
3439a3316fc6SZhikuiRen         if (bootPos == std::string::npos)
3440a3316fc6SZhikuiRen         {
3441a3316fc6SZhikuiRen             // Requested ID was not found
3442a3316fc6SZhikuiRen             messages::resourceMissingAtURI(asyncResp->res, targetID);
3443a3316fc6SZhikuiRen             return;
3444a3316fc6SZhikuiRen         }
3445a3316fc6SZhikuiRen         std::string_view bootIndexStr(targetID);
3446a3316fc6SZhikuiRen         bootIndexStr.remove_prefix(bootPos + 1);
3447a3316fc6SZhikuiRen         uint16_t bootIndex = 0;
3448a3316fc6SZhikuiRen         uint64_t codeIndex = 0;
3449a3316fc6SZhikuiRen         size_t dashPos = bootIndexStr.find('-');
3450a3316fc6SZhikuiRen 
3451a3316fc6SZhikuiRen         if (dashPos == std::string::npos)
3452a3316fc6SZhikuiRen         {
3453a3316fc6SZhikuiRen             return;
3454a3316fc6SZhikuiRen         }
3455a3316fc6SZhikuiRen         std::string_view codeIndexStr(bootIndexStr);
3456a3316fc6SZhikuiRen         bootIndexStr.remove_suffix(dashPos);
3457a3316fc6SZhikuiRen         codeIndexStr.remove_prefix(dashPos + 1);
3458a3316fc6SZhikuiRen 
3459a3316fc6SZhikuiRen         bootIndex = static_cast<uint16_t>(
346023a21a1cSEd Tanous             strtoul(std::string(bootIndexStr).c_str(), nullptr, 0));
346123a21a1cSEd Tanous         codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0);
3462a3316fc6SZhikuiRen         if (bootIndex == 0 || codeIndex == 0)
3463a3316fc6SZhikuiRen         {
3464a3316fc6SZhikuiRen             BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string "
3465a3316fc6SZhikuiRen                              << params[0];
3466a3316fc6SZhikuiRen         }
3467a3316fc6SZhikuiRen 
3468a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry";
3469a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.id"] =
3470a3316fc6SZhikuiRen             "/redfish/v1/Systems/system/LogServices/PostCodes/"
3471a3316fc6SZhikuiRen             "Entries";
3472a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3473a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Description"] =
3474a3316fc6SZhikuiRen             "Collection of POST Code Log Entries";
3475a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3476a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members@odata.count"] = 0;
3477a3316fc6SZhikuiRen 
3478a3316fc6SZhikuiRen         getPostCodeForEntry(asyncResp, bootIndex, codeIndex);
3479a3316fc6SZhikuiRen     }
3480a3316fc6SZhikuiRen };
3481a3316fc6SZhikuiRen 
34821da66f75SEd Tanous } // namespace redfish
3483