xref: /openbmc/bmcweb/features/redfish/lib/log_services.hpp (revision a43be80f1b8f9f314e9e2fa2db0875fde1d5e8ba)
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>
300657843aSraviteja-b #include <dump_offload.hpp>
31cb92c03bSAndrew Geissler #include <error_messages.hpp>
321214b7e7SGunnar Mills 
334418c7f0SJames Feist #include <filesystem>
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 {
111cb92c03bSAndrew Geissler     if (s == "xyz.openbmc_project.Logging.Entry.Level.Alert")
112cb92c03bSAndrew Geissler     {
113cb92c03bSAndrew Geissler         return "Critical";
114cb92c03bSAndrew Geissler     }
115cb92c03bSAndrew Geissler     else if (s == "xyz.openbmc_project.Logging.Entry.Level.Critical")
116cb92c03bSAndrew Geissler     {
117cb92c03bSAndrew Geissler         return "Critical";
118cb92c03bSAndrew Geissler     }
119cb92c03bSAndrew Geissler     else if (s == "xyz.openbmc_project.Logging.Entry.Level.Debug")
120cb92c03bSAndrew Geissler     {
121cb92c03bSAndrew Geissler         return "OK";
122cb92c03bSAndrew Geissler     }
123cb92c03bSAndrew Geissler     else if (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency")
124cb92c03bSAndrew Geissler     {
125cb92c03bSAndrew Geissler         return "Critical";
126cb92c03bSAndrew Geissler     }
127cb92c03bSAndrew Geissler     else if (s == "xyz.openbmc_project.Logging.Entry.Level.Error")
128cb92c03bSAndrew Geissler     {
129cb92c03bSAndrew Geissler         return "Critical";
130cb92c03bSAndrew Geissler     }
131cb92c03bSAndrew Geissler     else if (s == "xyz.openbmc_project.Logging.Entry.Level.Informational")
132cb92c03bSAndrew Geissler     {
133cb92c03bSAndrew Geissler         return "OK";
134cb92c03bSAndrew Geissler     }
135cb92c03bSAndrew Geissler     else if (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")
136cb92c03bSAndrew Geissler     {
137cb92c03bSAndrew Geissler         return "OK";
138cb92c03bSAndrew Geissler     }
139cb92c03bSAndrew Geissler     else if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
140cb92c03bSAndrew Geissler     {
141cb92c03bSAndrew Geissler         return "Warning";
142cb92c03bSAndrew Geissler     }
143cb92c03bSAndrew Geissler     return "";
144cb92c03bSAndrew Geissler }
145cb92c03bSAndrew Geissler 
14616428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal,
14739e77504SEd Tanous                               const std::string_view& field,
14839e77504SEd Tanous                               std::string_view& contents)
14916428a1aSJason M. Bills {
15016428a1aSJason M. Bills     const char* data = nullptr;
15116428a1aSJason M. Bills     size_t length = 0;
15216428a1aSJason M. Bills     int ret = 0;
15316428a1aSJason M. Bills     // Get the metadata from the requested field of the journal entry
154271584abSEd Tanous     ret = sd_journal_get_data(journal, field.data(),
155271584abSEd Tanous                               reinterpret_cast<const void**>(&data), &length);
15616428a1aSJason M. Bills     if (ret < 0)
15716428a1aSJason M. Bills     {
15816428a1aSJason M. Bills         return ret;
15916428a1aSJason M. Bills     }
16039e77504SEd Tanous     contents = std::string_view(data, length);
16116428a1aSJason M. Bills     // Only use the content after the "=" character.
16216428a1aSJason M. Bills     contents.remove_prefix(std::min(contents.find("=") + 1, contents.size()));
16316428a1aSJason M. Bills     return ret;
16416428a1aSJason M. Bills }
16516428a1aSJason M. Bills 
16616428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal,
16739e77504SEd Tanous                               const std::string_view& field, const int& base,
168271584abSEd Tanous                               long int& contents)
16916428a1aSJason M. Bills {
17016428a1aSJason M. Bills     int ret = 0;
17139e77504SEd Tanous     std::string_view metadata;
17216428a1aSJason M. Bills     // Get the metadata from the requested field of the journal entry
17316428a1aSJason M. Bills     ret = getJournalMetadata(journal, field, metadata);
17416428a1aSJason M. Bills     if (ret < 0)
17516428a1aSJason M. Bills     {
17616428a1aSJason M. Bills         return ret;
17716428a1aSJason M. Bills     }
178b01bf299SEd Tanous     contents = strtol(metadata.data(), nullptr, base);
17916428a1aSJason M. Bills     return ret;
18016428a1aSJason M. Bills }
18116428a1aSJason M. Bills 
182a3316fc6SZhikuiRen static bool getTimestampStr(const uint64_t usecSinceEpoch,
183a3316fc6SZhikuiRen                             std::string& entryTimestamp)
18416428a1aSJason M. Bills {
185a3316fc6SZhikuiRen     time_t t = static_cast<time_t>(usecSinceEpoch / 1000 / 1000);
18616428a1aSJason M. Bills     struct tm* loctime = localtime(&t);
18716428a1aSJason M. Bills     char entryTime[64] = {};
18899131cd0SEd Tanous     if (nullptr != loctime)
18916428a1aSJason M. Bills     {
19016428a1aSJason M. Bills         strftime(entryTime, sizeof(entryTime), "%FT%T%z", loctime);
19116428a1aSJason M. Bills     }
19216428a1aSJason M. Bills     // Insert the ':' into the timezone
19339e77504SEd Tanous     std::string_view t1(entryTime);
19439e77504SEd Tanous     std::string_view t2(entryTime);
19516428a1aSJason M. Bills     if (t1.size() > 2 && t2.size() > 2)
19616428a1aSJason M. Bills     {
19716428a1aSJason M. Bills         t1.remove_suffix(2);
19816428a1aSJason M. Bills         t2.remove_prefix(t2.size() - 2);
19916428a1aSJason M. Bills     }
20039e77504SEd Tanous     entryTimestamp = std::string(t1) + ":" + std::string(t2);
20116428a1aSJason M. Bills     return true;
20216428a1aSJason M. Bills }
20316428a1aSJason M. Bills 
204a3316fc6SZhikuiRen static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp)
205a3316fc6SZhikuiRen {
206a3316fc6SZhikuiRen     int ret = 0;
207a3316fc6SZhikuiRen     uint64_t timestamp = 0;
208a3316fc6SZhikuiRen     ret = sd_journal_get_realtime_usec(journal, &timestamp);
209a3316fc6SZhikuiRen     if (ret < 0)
210a3316fc6SZhikuiRen     {
211a3316fc6SZhikuiRen         BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
212a3316fc6SZhikuiRen                          << strerror(-ret);
213a3316fc6SZhikuiRen         return false;
214a3316fc6SZhikuiRen     }
215a3316fc6SZhikuiRen     return getTimestampStr(timestamp, entryTimestamp);
216a3316fc6SZhikuiRen }
217a3316fc6SZhikuiRen 
21816428a1aSJason M. Bills static bool getSkipParam(crow::Response& res, const crow::Request& req,
219271584abSEd Tanous                          uint64_t& skip)
22016428a1aSJason M. Bills {
22116428a1aSJason M. Bills     char* skipParam = req.urlParams.get("$skip");
22216428a1aSJason M. Bills     if (skipParam != nullptr)
22316428a1aSJason M. Bills     {
22416428a1aSJason M. Bills         char* ptr = nullptr;
225271584abSEd Tanous         skip = std::strtoul(skipParam, &ptr, 10);
22616428a1aSJason M. Bills         if (*skipParam == '\0' || *ptr != '\0')
22716428a1aSJason M. Bills         {
22816428a1aSJason M. Bills 
22916428a1aSJason M. Bills             messages::queryParameterValueTypeError(res, std::string(skipParam),
23016428a1aSJason M. Bills                                                    "$skip");
23116428a1aSJason M. Bills             return false;
23216428a1aSJason M. Bills         }
23316428a1aSJason M. Bills     }
23416428a1aSJason M. Bills     return true;
23516428a1aSJason M. Bills }
23616428a1aSJason M. Bills 
237271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000;
23816428a1aSJason M. Bills static bool getTopParam(crow::Response& res, const crow::Request& req,
239271584abSEd Tanous                         uint64_t& top)
24016428a1aSJason M. Bills {
24116428a1aSJason M. Bills     char* topParam = req.urlParams.get("$top");
24216428a1aSJason M. Bills     if (topParam != nullptr)
24316428a1aSJason M. Bills     {
24416428a1aSJason M. Bills         char* ptr = nullptr;
245271584abSEd Tanous         top = std::strtoul(topParam, &ptr, 10);
24616428a1aSJason M. Bills         if (*topParam == '\0' || *ptr != '\0')
24716428a1aSJason M. Bills         {
24816428a1aSJason M. Bills             messages::queryParameterValueTypeError(res, std::string(topParam),
24916428a1aSJason M. Bills                                                    "$top");
25016428a1aSJason M. Bills             return false;
25116428a1aSJason M. Bills         }
252271584abSEd Tanous         if (top < 1U || top > maxEntriesPerPage)
25316428a1aSJason M. Bills         {
25416428a1aSJason M. Bills 
25516428a1aSJason M. Bills             messages::queryParameterOutOfRange(
25616428a1aSJason M. Bills                 res, std::to_string(top), "$top",
25716428a1aSJason M. Bills                 "1-" + std::to_string(maxEntriesPerPage));
25816428a1aSJason M. Bills             return false;
25916428a1aSJason M. Bills         }
26016428a1aSJason M. Bills     }
26116428a1aSJason M. Bills     return true;
26216428a1aSJason M. Bills }
26316428a1aSJason M. Bills 
264e85d6b16SJason M. Bills static bool getUniqueEntryID(sd_journal* journal, std::string& entryID,
265e85d6b16SJason M. Bills                              const bool firstEntry = true)
26616428a1aSJason M. Bills {
26716428a1aSJason M. Bills     int ret = 0;
26816428a1aSJason M. Bills     static uint64_t prevTs = 0;
26916428a1aSJason M. Bills     static int index = 0;
270e85d6b16SJason M. Bills     if (firstEntry)
271e85d6b16SJason M. Bills     {
272e85d6b16SJason M. Bills         prevTs = 0;
273e85d6b16SJason M. Bills     }
274e85d6b16SJason M. Bills 
27516428a1aSJason M. Bills     // Get the entry timestamp
27616428a1aSJason M. Bills     uint64_t curTs = 0;
27716428a1aSJason M. Bills     ret = sd_journal_get_realtime_usec(journal, &curTs);
27816428a1aSJason M. Bills     if (ret < 0)
27916428a1aSJason M. Bills     {
28016428a1aSJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
28116428a1aSJason M. Bills                          << strerror(-ret);
28216428a1aSJason M. Bills         return false;
28316428a1aSJason M. Bills     }
28416428a1aSJason M. Bills     // If the timestamp isn't unique, increment the index
28516428a1aSJason M. Bills     if (curTs == prevTs)
28616428a1aSJason M. Bills     {
28716428a1aSJason M. Bills         index++;
28816428a1aSJason M. Bills     }
28916428a1aSJason M. Bills     else
29016428a1aSJason M. Bills     {
29116428a1aSJason M. Bills         // Otherwise, reset it
29216428a1aSJason M. Bills         index = 0;
29316428a1aSJason M. Bills     }
29416428a1aSJason M. Bills     // Save the timestamp
29516428a1aSJason M. Bills     prevTs = curTs;
29616428a1aSJason M. Bills 
29716428a1aSJason M. Bills     entryID = std::to_string(curTs);
29816428a1aSJason M. Bills     if (index > 0)
29916428a1aSJason M. Bills     {
30016428a1aSJason M. Bills         entryID += "_" + std::to_string(index);
30116428a1aSJason M. Bills     }
30216428a1aSJason M. Bills     return true;
30316428a1aSJason M. Bills }
30416428a1aSJason M. Bills 
305e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
306e85d6b16SJason M. Bills                              const bool firstEntry = true)
30795820184SJason M. Bills {
308271584abSEd Tanous     static time_t prevTs = 0;
30995820184SJason M. Bills     static int index = 0;
310e85d6b16SJason M. Bills     if (firstEntry)
311e85d6b16SJason M. Bills     {
312e85d6b16SJason M. Bills         prevTs = 0;
313e85d6b16SJason M. Bills     }
314e85d6b16SJason M. Bills 
31595820184SJason M. Bills     // Get the entry timestamp
316271584abSEd Tanous     std::time_t curTs = 0;
31795820184SJason M. Bills     std::tm timeStruct = {};
31895820184SJason M. Bills     std::istringstream entryStream(logEntry);
31995820184SJason M. Bills     if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
32095820184SJason M. Bills     {
32195820184SJason M. Bills         curTs = std::mktime(&timeStruct);
32295820184SJason M. Bills     }
32395820184SJason M. Bills     // If the timestamp isn't unique, increment the index
32495820184SJason M. Bills     if (curTs == prevTs)
32595820184SJason M. Bills     {
32695820184SJason M. Bills         index++;
32795820184SJason M. Bills     }
32895820184SJason M. Bills     else
32995820184SJason M. Bills     {
33095820184SJason M. Bills         // Otherwise, reset it
33195820184SJason M. Bills         index = 0;
33295820184SJason M. Bills     }
33395820184SJason M. Bills     // Save the timestamp
33495820184SJason M. Bills     prevTs = curTs;
33595820184SJason M. Bills 
33695820184SJason M. Bills     entryID = std::to_string(curTs);
33795820184SJason M. Bills     if (index > 0)
33895820184SJason M. Bills     {
33995820184SJason M. Bills         entryID += "_" + std::to_string(index);
34095820184SJason M. Bills     }
34195820184SJason M. Bills     return true;
34295820184SJason M. Bills }
34395820184SJason M. Bills 
34416428a1aSJason M. Bills static bool getTimestampFromID(crow::Response& res, const std::string& entryID,
345271584abSEd Tanous                                uint64_t& timestamp, uint64_t& index)
34616428a1aSJason M. Bills {
34716428a1aSJason M. Bills     if (entryID.empty())
34816428a1aSJason M. Bills     {
34916428a1aSJason M. Bills         return false;
35016428a1aSJason M. Bills     }
35116428a1aSJason M. Bills     // Convert the unique ID back to a timestamp to find the entry
35239e77504SEd Tanous     std::string_view tsStr(entryID);
35316428a1aSJason M. Bills 
35416428a1aSJason M. Bills     auto underscorePos = tsStr.find("_");
35516428a1aSJason M. Bills     if (underscorePos != tsStr.npos)
35616428a1aSJason M. Bills     {
35716428a1aSJason M. Bills         // Timestamp has an index
35816428a1aSJason M. Bills         tsStr.remove_suffix(tsStr.size() - underscorePos);
35939e77504SEd Tanous         std::string_view indexStr(entryID);
36016428a1aSJason M. Bills         indexStr.remove_prefix(underscorePos + 1);
36116428a1aSJason M. Bills         std::size_t pos;
36216428a1aSJason M. Bills         try
36316428a1aSJason M. Bills         {
36439e77504SEd Tanous             index = std::stoul(std::string(indexStr), &pos);
36516428a1aSJason M. Bills         }
366271584abSEd Tanous         catch (std::invalid_argument&)
36716428a1aSJason M. Bills         {
36816428a1aSJason M. Bills             messages::resourceMissingAtURI(res, entryID);
36916428a1aSJason M. Bills             return false;
37016428a1aSJason M. Bills         }
371271584abSEd Tanous         catch (std::out_of_range&)
37216428a1aSJason M. Bills         {
37316428a1aSJason M. Bills             messages::resourceMissingAtURI(res, entryID);
37416428a1aSJason M. Bills             return false;
37516428a1aSJason M. Bills         }
37616428a1aSJason M. Bills         if (pos != indexStr.size())
37716428a1aSJason M. Bills         {
37816428a1aSJason M. Bills             messages::resourceMissingAtURI(res, entryID);
37916428a1aSJason M. Bills             return false;
38016428a1aSJason M. Bills         }
38116428a1aSJason M. Bills     }
38216428a1aSJason M. Bills     // Timestamp has no index
38316428a1aSJason M. Bills     std::size_t pos;
38416428a1aSJason M. Bills     try
38516428a1aSJason M. Bills     {
38639e77504SEd Tanous         timestamp = std::stoull(std::string(tsStr), &pos);
38716428a1aSJason M. Bills     }
388271584abSEd Tanous     catch (std::invalid_argument&)
38916428a1aSJason M. Bills     {
39016428a1aSJason M. Bills         messages::resourceMissingAtURI(res, entryID);
39116428a1aSJason M. Bills         return false;
39216428a1aSJason M. Bills     }
393271584abSEd Tanous     catch (std::out_of_range&)
39416428a1aSJason M. Bills     {
39516428a1aSJason M. Bills         messages::resourceMissingAtURI(res, entryID);
39616428a1aSJason M. Bills         return false;
39716428a1aSJason M. Bills     }
39816428a1aSJason M. Bills     if (pos != tsStr.size())
39916428a1aSJason M. Bills     {
40016428a1aSJason M. Bills         messages::resourceMissingAtURI(res, entryID);
40116428a1aSJason M. Bills         return false;
40216428a1aSJason M. Bills     }
40316428a1aSJason M. Bills     return true;
40416428a1aSJason M. Bills }
40516428a1aSJason M. Bills 
40695820184SJason M. Bills static bool
40795820184SJason M. Bills     getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
40895820184SJason M. Bills {
40995820184SJason M. Bills     static const std::filesystem::path redfishLogDir = "/var/log";
41095820184SJason M. Bills     static const std::string redfishLogFilename = "redfish";
41195820184SJason M. Bills 
41295820184SJason M. Bills     // Loop through the directory looking for redfish log files
41395820184SJason M. Bills     for (const std::filesystem::directory_entry& dirEnt :
41495820184SJason M. Bills          std::filesystem::directory_iterator(redfishLogDir))
41595820184SJason M. Bills     {
41695820184SJason M. Bills         // If we find a redfish log file, save the path
41795820184SJason M. Bills         std::string filename = dirEnt.path().filename();
41895820184SJason M. Bills         if (boost::starts_with(filename, redfishLogFilename))
41995820184SJason M. Bills         {
42095820184SJason M. Bills             redfishLogFiles.emplace_back(redfishLogDir / filename);
42195820184SJason M. Bills         }
42295820184SJason M. Bills     }
42395820184SJason M. Bills     // As the log files rotate, they are appended with a ".#" that is higher for
42495820184SJason M. Bills     // the older logs. Since we don't expect more than 10 log files, we
42595820184SJason M. Bills     // can just sort the list to get them in order from newest to oldest
42695820184SJason M. Bills     std::sort(redfishLogFiles.begin(), redfishLogFiles.end());
42795820184SJason M. Bills 
42895820184SJason M. Bills     return !redfishLogFiles.empty();
42995820184SJason M. Bills }
43095820184SJason M. Bills 
4315cb1dd27SAsmitha Karunanithi inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp,
4325cb1dd27SAsmitha Karunanithi                                    const std::string& dumpType)
4335cb1dd27SAsmitha Karunanithi {
4345cb1dd27SAsmitha Karunanithi     std::string dumpPath;
4355cb1dd27SAsmitha Karunanithi     if (dumpType == "BMC")
4365cb1dd27SAsmitha Karunanithi     {
4375cb1dd27SAsmitha Karunanithi         dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
4385cb1dd27SAsmitha Karunanithi     }
4395cb1dd27SAsmitha Karunanithi     else if (dumpType == "System")
4405cb1dd27SAsmitha Karunanithi     {
4415cb1dd27SAsmitha Karunanithi         dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
4425cb1dd27SAsmitha Karunanithi     }
4435cb1dd27SAsmitha Karunanithi     else
4445cb1dd27SAsmitha Karunanithi     {
4455cb1dd27SAsmitha Karunanithi         BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
4465cb1dd27SAsmitha Karunanithi         messages::internalError(asyncResp->res);
4475cb1dd27SAsmitha Karunanithi         return;
4485cb1dd27SAsmitha Karunanithi     }
4495cb1dd27SAsmitha Karunanithi 
4505cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
4515cb1dd27SAsmitha Karunanithi         [asyncResp, dumpPath, dumpType](const boost::system::error_code ec,
4525cb1dd27SAsmitha Karunanithi                                         GetManagedObjectsType& resp) {
4535cb1dd27SAsmitha Karunanithi             if (ec)
4545cb1dd27SAsmitha Karunanithi             {
4555cb1dd27SAsmitha Karunanithi                 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
4565cb1dd27SAsmitha Karunanithi                 messages::internalError(asyncResp->res);
4575cb1dd27SAsmitha Karunanithi                 return;
4585cb1dd27SAsmitha Karunanithi             }
4595cb1dd27SAsmitha Karunanithi 
4605cb1dd27SAsmitha Karunanithi             nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
4615cb1dd27SAsmitha Karunanithi             entriesArray = nlohmann::json::array();
4625cb1dd27SAsmitha Karunanithi 
4635cb1dd27SAsmitha Karunanithi             for (auto& object : resp)
4645cb1dd27SAsmitha Karunanithi             {
4655cb1dd27SAsmitha Karunanithi                 bool foundDumpEntry = false;
4665cb1dd27SAsmitha Karunanithi                 for (auto& interfaceMap : object.second)
4675cb1dd27SAsmitha Karunanithi                 {
4685cb1dd27SAsmitha Karunanithi                     if (interfaceMap.first ==
4695cb1dd27SAsmitha Karunanithi                         ("xyz.openbmc_project.Dump.Entry." + dumpType))
4705cb1dd27SAsmitha Karunanithi                     {
4715cb1dd27SAsmitha Karunanithi                         foundDumpEntry = true;
4725cb1dd27SAsmitha Karunanithi                         break;
4735cb1dd27SAsmitha Karunanithi                     }
4745cb1dd27SAsmitha Karunanithi                 }
4755cb1dd27SAsmitha Karunanithi 
4765cb1dd27SAsmitha Karunanithi                 if (foundDumpEntry == false)
4775cb1dd27SAsmitha Karunanithi                 {
4785cb1dd27SAsmitha Karunanithi                     continue;
4795cb1dd27SAsmitha Karunanithi                 }
4805cb1dd27SAsmitha Karunanithi                 std::time_t timestamp;
4815cb1dd27SAsmitha Karunanithi                 uint64_t size = 0;
4825cb1dd27SAsmitha Karunanithi                 entriesArray.push_back({});
4835cb1dd27SAsmitha Karunanithi                 nlohmann::json& thisEntry = entriesArray.back();
4845cb1dd27SAsmitha Karunanithi                 const std::string& path =
4855cb1dd27SAsmitha Karunanithi                     static_cast<const std::string&>(object.first);
4865cb1dd27SAsmitha Karunanithi                 std::size_t lastPos = path.rfind("/");
4875cb1dd27SAsmitha Karunanithi                 if (lastPos == std::string::npos)
4885cb1dd27SAsmitha Karunanithi                 {
4895cb1dd27SAsmitha Karunanithi                     continue;
4905cb1dd27SAsmitha Karunanithi                 }
4915cb1dd27SAsmitha Karunanithi                 std::string entryID = path.substr(lastPos + 1);
4925cb1dd27SAsmitha Karunanithi 
4935cb1dd27SAsmitha Karunanithi                 for (auto& interfaceMap : object.second)
4945cb1dd27SAsmitha Karunanithi                 {
4955cb1dd27SAsmitha Karunanithi                     if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
4965cb1dd27SAsmitha Karunanithi                     {
4975cb1dd27SAsmitha Karunanithi 
4985cb1dd27SAsmitha Karunanithi                         for (auto& propertyMap : interfaceMap.second)
4995cb1dd27SAsmitha Karunanithi                         {
5005cb1dd27SAsmitha Karunanithi                             if (propertyMap.first == "Size")
5015cb1dd27SAsmitha Karunanithi                             {
5025cb1dd27SAsmitha Karunanithi                                 auto sizePtr =
5035cb1dd27SAsmitha Karunanithi                                     std::get_if<uint64_t>(&propertyMap.second);
5045cb1dd27SAsmitha Karunanithi                                 if (sizePtr == nullptr)
5055cb1dd27SAsmitha Karunanithi                                 {
5065cb1dd27SAsmitha Karunanithi                                     messages::internalError(asyncResp->res);
5075cb1dd27SAsmitha Karunanithi                                     break;
5085cb1dd27SAsmitha Karunanithi                                 }
5095cb1dd27SAsmitha Karunanithi                                 size = *sizePtr;
5105cb1dd27SAsmitha Karunanithi                                 break;
5115cb1dd27SAsmitha Karunanithi                             }
5125cb1dd27SAsmitha Karunanithi                         }
5135cb1dd27SAsmitha Karunanithi                     }
5145cb1dd27SAsmitha Karunanithi                     else if (interfaceMap.first ==
5155cb1dd27SAsmitha Karunanithi                              "xyz.openbmc_project.Time.EpochTime")
5165cb1dd27SAsmitha Karunanithi                     {
5175cb1dd27SAsmitha Karunanithi 
5185cb1dd27SAsmitha Karunanithi                         for (auto& propertyMap : interfaceMap.second)
5195cb1dd27SAsmitha Karunanithi                         {
5205cb1dd27SAsmitha Karunanithi                             if (propertyMap.first == "Elapsed")
5215cb1dd27SAsmitha Karunanithi                             {
5225cb1dd27SAsmitha Karunanithi                                 const uint64_t* usecsTimeStamp =
5235cb1dd27SAsmitha Karunanithi                                     std::get_if<uint64_t>(&propertyMap.second);
5245cb1dd27SAsmitha Karunanithi                                 if (usecsTimeStamp == nullptr)
5255cb1dd27SAsmitha Karunanithi                                 {
5265cb1dd27SAsmitha Karunanithi                                     messages::internalError(asyncResp->res);
5275cb1dd27SAsmitha Karunanithi                                     break;
5285cb1dd27SAsmitha Karunanithi                                 }
5295cb1dd27SAsmitha Karunanithi                                 timestamp =
5305cb1dd27SAsmitha Karunanithi                                     static_cast<std::time_t>(*usecsTimeStamp);
5315cb1dd27SAsmitha Karunanithi                                 break;
5325cb1dd27SAsmitha Karunanithi                             }
5335cb1dd27SAsmitha Karunanithi                         }
5345cb1dd27SAsmitha Karunanithi                     }
5355cb1dd27SAsmitha Karunanithi                 }
5365cb1dd27SAsmitha Karunanithi 
5375cb1dd27SAsmitha Karunanithi                 thisEntry["@odata.type"] = "#LogEntry.v1_5_1.LogEntry";
5385cb1dd27SAsmitha Karunanithi                 thisEntry["@odata.id"] = dumpPath + entryID;
5395cb1dd27SAsmitha Karunanithi                 thisEntry["Id"] = entryID;
5405cb1dd27SAsmitha Karunanithi                 thisEntry["EntryType"] = "Event";
5415cb1dd27SAsmitha Karunanithi                 thisEntry["Created"] = crow::utility::getDateTime(timestamp);
5425cb1dd27SAsmitha Karunanithi                 thisEntry["Name"] = dumpType + " Dump Entry";
5435cb1dd27SAsmitha Karunanithi 
5445cb1dd27SAsmitha Karunanithi                 thisEntry["Oem"]["OpenBmc"]["@odata.type"] =
5455cb1dd27SAsmitha Karunanithi                     "#OemLogEntry.v1_0_0.OpenBmc";
5465cb1dd27SAsmitha Karunanithi                 thisEntry["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] = size;
5475cb1dd27SAsmitha Karunanithi 
5485cb1dd27SAsmitha Karunanithi                 if (dumpType == "BMC")
5495cb1dd27SAsmitha Karunanithi                 {
5505cb1dd27SAsmitha Karunanithi                     thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] =
5515cb1dd27SAsmitha Karunanithi                         "Manager";
5525cb1dd27SAsmitha Karunanithi                     thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] =
5535cb1dd27SAsmitha Karunanithi                         "/redfish/v1/Managers/bmc/LogServices/Dump/"
5545cb1dd27SAsmitha Karunanithi                         "attachment/" +
5555cb1dd27SAsmitha Karunanithi                         entryID;
5565cb1dd27SAsmitha Karunanithi                 }
5575cb1dd27SAsmitha Karunanithi                 else if (dumpType == "System")
5585cb1dd27SAsmitha Karunanithi                 {
5595cb1dd27SAsmitha Karunanithi                     thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] = "OEM";
5605cb1dd27SAsmitha Karunanithi                     thisEntry["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] =
5615cb1dd27SAsmitha Karunanithi                         "System";
5625cb1dd27SAsmitha Karunanithi                     thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] =
5635cb1dd27SAsmitha Karunanithi                         "/redfish/v1/Systems/system/LogServices/Dump/"
5645cb1dd27SAsmitha Karunanithi                         "attachment/" +
5655cb1dd27SAsmitha Karunanithi                         entryID;
5665cb1dd27SAsmitha Karunanithi                 }
5675cb1dd27SAsmitha Karunanithi             }
5685cb1dd27SAsmitha Karunanithi             asyncResp->res.jsonValue["Members@odata.count"] =
5695cb1dd27SAsmitha Karunanithi                 entriesArray.size();
5705cb1dd27SAsmitha Karunanithi         },
5715cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
5725cb1dd27SAsmitha Karunanithi         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
5735cb1dd27SAsmitha Karunanithi }
5745cb1dd27SAsmitha Karunanithi 
5755cb1dd27SAsmitha Karunanithi inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp,
5765cb1dd27SAsmitha Karunanithi                              const std::string& entryID,
5775cb1dd27SAsmitha Karunanithi                              const std::string& dumpType)
5785cb1dd27SAsmitha Karunanithi {
5795cb1dd27SAsmitha Karunanithi     std::string dumpPath;
5805cb1dd27SAsmitha Karunanithi     if (dumpType == "BMC")
5815cb1dd27SAsmitha Karunanithi     {
5825cb1dd27SAsmitha Karunanithi         dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
5835cb1dd27SAsmitha Karunanithi     }
5845cb1dd27SAsmitha Karunanithi     else if (dumpType == "System")
5855cb1dd27SAsmitha Karunanithi     {
5865cb1dd27SAsmitha Karunanithi         dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
5875cb1dd27SAsmitha Karunanithi     }
5885cb1dd27SAsmitha Karunanithi     else
5895cb1dd27SAsmitha Karunanithi     {
5905cb1dd27SAsmitha Karunanithi         BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
5915cb1dd27SAsmitha Karunanithi         messages::internalError(asyncResp->res);
5925cb1dd27SAsmitha Karunanithi         return;
5935cb1dd27SAsmitha Karunanithi     }
5945cb1dd27SAsmitha Karunanithi 
5955cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
5965cb1dd27SAsmitha Karunanithi         [asyncResp, entryID, dumpPath, dumpType](
5975cb1dd27SAsmitha Karunanithi             const boost::system::error_code ec, GetManagedObjectsType& resp) {
5985cb1dd27SAsmitha Karunanithi             if (ec)
5995cb1dd27SAsmitha Karunanithi             {
6005cb1dd27SAsmitha Karunanithi                 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
6015cb1dd27SAsmitha Karunanithi                 messages::internalError(asyncResp->res);
6025cb1dd27SAsmitha Karunanithi                 return;
6035cb1dd27SAsmitha Karunanithi             }
6045cb1dd27SAsmitha Karunanithi 
6055cb1dd27SAsmitha Karunanithi             for (auto& objectPath : resp)
6065cb1dd27SAsmitha Karunanithi             {
6075cb1dd27SAsmitha Karunanithi                 if (objectPath.first.str.find(
6085cb1dd27SAsmitha Karunanithi                         "/xyz/openbmc_project/dump/entry/" + entryID) ==
6095cb1dd27SAsmitha Karunanithi                     std::string::npos)
6105cb1dd27SAsmitha Karunanithi                 {
6115cb1dd27SAsmitha Karunanithi                     continue;
6125cb1dd27SAsmitha Karunanithi                 }
6135cb1dd27SAsmitha Karunanithi 
6145cb1dd27SAsmitha Karunanithi                 bool foundDumpEntry = false;
6155cb1dd27SAsmitha Karunanithi                 for (auto& interfaceMap : objectPath.second)
6165cb1dd27SAsmitha Karunanithi                 {
6175cb1dd27SAsmitha Karunanithi                     if (interfaceMap.first ==
6185cb1dd27SAsmitha Karunanithi                         ("xyz.openbmc_project.Dump.Entry." + dumpType))
6195cb1dd27SAsmitha Karunanithi                     {
6205cb1dd27SAsmitha Karunanithi                         foundDumpEntry = true;
6215cb1dd27SAsmitha Karunanithi                         break;
6225cb1dd27SAsmitha Karunanithi                     }
6235cb1dd27SAsmitha Karunanithi                 }
6245cb1dd27SAsmitha Karunanithi                 if (foundDumpEntry == false)
6255cb1dd27SAsmitha Karunanithi                 {
6265cb1dd27SAsmitha Karunanithi                     BMCWEB_LOG_ERROR << "Can't find Dump Entry";
6275cb1dd27SAsmitha Karunanithi                     messages::internalError(asyncResp->res);
6285cb1dd27SAsmitha Karunanithi                     return;
6295cb1dd27SAsmitha Karunanithi                 }
6305cb1dd27SAsmitha Karunanithi 
6315cb1dd27SAsmitha Karunanithi                 std::time_t timestamp;
6325cb1dd27SAsmitha Karunanithi                 uint64_t size = 0;
6335cb1dd27SAsmitha Karunanithi 
6345cb1dd27SAsmitha Karunanithi                 for (auto& interfaceMap : objectPath.second)
6355cb1dd27SAsmitha Karunanithi                 {
6365cb1dd27SAsmitha Karunanithi                     if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
6375cb1dd27SAsmitha Karunanithi                     {
6385cb1dd27SAsmitha Karunanithi                         for (auto& propertyMap : interfaceMap.second)
6395cb1dd27SAsmitha Karunanithi                         {
6405cb1dd27SAsmitha Karunanithi                             if (propertyMap.first == "Size")
6415cb1dd27SAsmitha Karunanithi                             {
6425cb1dd27SAsmitha Karunanithi                                 auto sizePtr =
6435cb1dd27SAsmitha Karunanithi                                     std::get_if<uint64_t>(&propertyMap.second);
6445cb1dd27SAsmitha Karunanithi                                 if (sizePtr == nullptr)
6455cb1dd27SAsmitha Karunanithi                                 {
6465cb1dd27SAsmitha Karunanithi                                     messages::internalError(asyncResp->res);
6475cb1dd27SAsmitha Karunanithi                                     break;
6485cb1dd27SAsmitha Karunanithi                                 }
6495cb1dd27SAsmitha Karunanithi                                 size = *sizePtr;
6505cb1dd27SAsmitha Karunanithi                                 break;
6515cb1dd27SAsmitha Karunanithi                             }
6525cb1dd27SAsmitha Karunanithi                         }
6535cb1dd27SAsmitha Karunanithi                     }
6545cb1dd27SAsmitha Karunanithi                     else if (interfaceMap.first ==
6555cb1dd27SAsmitha Karunanithi                              "xyz.openbmc_project.Time.EpochTime")
6565cb1dd27SAsmitha Karunanithi                     {
6575cb1dd27SAsmitha Karunanithi                         for (auto& propertyMap : interfaceMap.second)
6585cb1dd27SAsmitha Karunanithi                         {
6595cb1dd27SAsmitha Karunanithi                             if (propertyMap.first == "Elapsed")
6605cb1dd27SAsmitha Karunanithi                             {
6615cb1dd27SAsmitha Karunanithi                                 const uint64_t* usecsTimeStamp =
6625cb1dd27SAsmitha Karunanithi                                     std::get_if<uint64_t>(&propertyMap.second);
6635cb1dd27SAsmitha Karunanithi                                 if (usecsTimeStamp == nullptr)
6645cb1dd27SAsmitha Karunanithi                                 {
6655cb1dd27SAsmitha Karunanithi                                     messages::internalError(asyncResp->res);
6665cb1dd27SAsmitha Karunanithi                                     break;
6675cb1dd27SAsmitha Karunanithi                                 }
6685cb1dd27SAsmitha Karunanithi                                 timestamp =
6695cb1dd27SAsmitha Karunanithi                                     static_cast<std::time_t>(*usecsTimeStamp);
6705cb1dd27SAsmitha Karunanithi                                 break;
6715cb1dd27SAsmitha Karunanithi                             }
6725cb1dd27SAsmitha Karunanithi                         }
6735cb1dd27SAsmitha Karunanithi                     }
6745cb1dd27SAsmitha Karunanithi                 }
6755cb1dd27SAsmitha Karunanithi 
6765cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["@odata.type"] =
6775cb1dd27SAsmitha Karunanithi                     "#LogEntry.v1_5_1.LogEntry";
6785cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID;
6795cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["Id"] = entryID;
6805cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["EntryType"] = "Event";
6815cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["Created"] =
6825cb1dd27SAsmitha Karunanithi                     crow::utility::getDateTime(timestamp);
6835cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
6845cb1dd27SAsmitha Karunanithi 
6855cb1dd27SAsmitha Karunanithi                 asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] =
6865cb1dd27SAsmitha Karunanithi                     "#OemLogEntry.v1_0_0.OpenBmc";
6875cb1dd27SAsmitha Karunanithi                 asyncResp->res
6885cb1dd27SAsmitha Karunanithi                     .jsonValue["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] =
6895cb1dd27SAsmitha Karunanithi                     size;
6905cb1dd27SAsmitha Karunanithi 
6915cb1dd27SAsmitha Karunanithi                 if (dumpType == "BMC")
6925cb1dd27SAsmitha Karunanithi                 {
6935cb1dd27SAsmitha Karunanithi                     asyncResp->res
6945cb1dd27SAsmitha Karunanithi                         .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] =
6955cb1dd27SAsmitha Karunanithi                         "Manager";
6965cb1dd27SAsmitha Karunanithi                     asyncResp->res
6975cb1dd27SAsmitha Karunanithi                         .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] =
6985cb1dd27SAsmitha Karunanithi                         "/redfish/v1/Managers/bmc/LogServices/Dump/"
6995cb1dd27SAsmitha Karunanithi                         "attachment/" +
7005cb1dd27SAsmitha Karunanithi                         entryID;
7015cb1dd27SAsmitha Karunanithi                 }
7025cb1dd27SAsmitha Karunanithi                 else if (dumpType == "System")
7035cb1dd27SAsmitha Karunanithi                 {
7045cb1dd27SAsmitha Karunanithi                     asyncResp->res
7055cb1dd27SAsmitha Karunanithi                         .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] =
7065cb1dd27SAsmitha Karunanithi                         "OEM";
7075cb1dd27SAsmitha Karunanithi                     asyncResp->res
7085cb1dd27SAsmitha Karunanithi                         .jsonValue["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] =
7095cb1dd27SAsmitha Karunanithi                         "System";
7105cb1dd27SAsmitha Karunanithi                     asyncResp->res
7115cb1dd27SAsmitha Karunanithi                         .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] =
7125cb1dd27SAsmitha Karunanithi                         "/redfish/v1/Systems/system/LogServices/Dump/"
7135cb1dd27SAsmitha Karunanithi                         "attachment/" +
7145cb1dd27SAsmitha Karunanithi                         entryID;
7155cb1dd27SAsmitha Karunanithi                 }
7165cb1dd27SAsmitha Karunanithi             }
7175cb1dd27SAsmitha Karunanithi         },
7185cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
7195cb1dd27SAsmitha Karunanithi         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
7205cb1dd27SAsmitha Karunanithi }
7215cb1dd27SAsmitha Karunanithi 
7225cb1dd27SAsmitha Karunanithi inline void deleteDumpEntry(crow::Response& res, const std::string& entryID)
7235cb1dd27SAsmitha Karunanithi {
7245cb1dd27SAsmitha Karunanithi     std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
7255cb1dd27SAsmitha Karunanithi 
7265cb1dd27SAsmitha Karunanithi     auto respHandler = [asyncResp](const boost::system::error_code ec) {
7275cb1dd27SAsmitha Karunanithi         BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done";
7285cb1dd27SAsmitha Karunanithi         if (ec)
7295cb1dd27SAsmitha Karunanithi         {
7305cb1dd27SAsmitha Karunanithi             BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error "
7315cb1dd27SAsmitha Karunanithi                              << ec;
7325cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
7335cb1dd27SAsmitha Karunanithi             return;
7345cb1dd27SAsmitha Karunanithi         }
7355cb1dd27SAsmitha Karunanithi     };
7365cb1dd27SAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
7375cb1dd27SAsmitha Karunanithi         respHandler, "xyz.openbmc_project.Dump.Manager",
7385cb1dd27SAsmitha Karunanithi         "/xyz/openbmc_project/dump/entry/" + entryID,
7395cb1dd27SAsmitha Karunanithi         "xyz.openbmc_project.Object.Delete", "Delete");
7405cb1dd27SAsmitha Karunanithi }
7415cb1dd27SAsmitha Karunanithi 
742*a43be80fSAsmitha Karunanithi inline void createDumpTaskCallback(const crow::Request& req,
743*a43be80fSAsmitha Karunanithi                                    std::shared_ptr<AsyncResp> asyncResp,
744*a43be80fSAsmitha Karunanithi                                    const uint32_t& dumpId,
745*a43be80fSAsmitha Karunanithi                                    const std::string& dumpPath,
746*a43be80fSAsmitha Karunanithi                                    const std::string& dumpType)
747*a43be80fSAsmitha Karunanithi {
748*a43be80fSAsmitha Karunanithi     std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
749*a43be80fSAsmitha Karunanithi         [dumpId, dumpPath, dumpType](
750*a43be80fSAsmitha Karunanithi             boost::system::error_code err, sdbusplus::message::message& m,
751*a43be80fSAsmitha Karunanithi             const std::shared_ptr<task::TaskData>& taskData) {
752*a43be80fSAsmitha Karunanithi             std::vector<std::pair<
753*a43be80fSAsmitha Karunanithi                 std::string,
754*a43be80fSAsmitha Karunanithi                 std::vector<std::pair<std::string, std::variant<std::string>>>>>
755*a43be80fSAsmitha Karunanithi                 interfacesList;
756*a43be80fSAsmitha Karunanithi 
757*a43be80fSAsmitha Karunanithi             sdbusplus::message::object_path objPath;
758*a43be80fSAsmitha Karunanithi 
759*a43be80fSAsmitha Karunanithi             m.read(objPath, interfacesList);
760*a43be80fSAsmitha Karunanithi 
761*a43be80fSAsmitha Karunanithi             for (auto& interface : interfacesList)
762*a43be80fSAsmitha Karunanithi             {
763*a43be80fSAsmitha Karunanithi                 if (interface.first ==
764*a43be80fSAsmitha Karunanithi                     ("xyz.openbmc_project.Dump.Entry." + dumpType))
765*a43be80fSAsmitha Karunanithi                 {
766*a43be80fSAsmitha Karunanithi                     nlohmann::json retMessage = messages::success();
767*a43be80fSAsmitha Karunanithi                     taskData->messages.emplace_back(retMessage);
768*a43be80fSAsmitha Karunanithi 
769*a43be80fSAsmitha Karunanithi                     std::string headerLoc =
770*a43be80fSAsmitha Karunanithi                         "Location: " + dumpPath + std::to_string(dumpId);
771*a43be80fSAsmitha Karunanithi                     taskData->payload->httpHeaders.emplace_back(
772*a43be80fSAsmitha Karunanithi                         std::move(headerLoc));
773*a43be80fSAsmitha Karunanithi 
774*a43be80fSAsmitha Karunanithi                     taskData->state = "Completed";
775*a43be80fSAsmitha Karunanithi                     return task::completed;
776*a43be80fSAsmitha Karunanithi                 }
777*a43be80fSAsmitha Karunanithi             }
778*a43be80fSAsmitha Karunanithi             return !task::completed;
779*a43be80fSAsmitha Karunanithi         },
780*a43be80fSAsmitha Karunanithi         "type='signal',interface='org.freedesktop.DBus."
781*a43be80fSAsmitha Karunanithi         "ObjectManager',"
782*a43be80fSAsmitha Karunanithi         "member='InterfacesAdded', "
783*a43be80fSAsmitha Karunanithi         "path='/xyz/openbmc_project/dump'");
784*a43be80fSAsmitha Karunanithi 
785*a43be80fSAsmitha Karunanithi     task->startTimer(std::chrono::minutes(3));
786*a43be80fSAsmitha Karunanithi     task->populateResp(asyncResp->res);
787*a43be80fSAsmitha Karunanithi     task->payload.emplace(req);
788*a43be80fSAsmitha Karunanithi }
789*a43be80fSAsmitha Karunanithi 
790*a43be80fSAsmitha Karunanithi inline void createDump(crow::Response& res, const crow::Request& req,
791*a43be80fSAsmitha Karunanithi                        const std::string& dumpType)
792*a43be80fSAsmitha Karunanithi {
793*a43be80fSAsmitha Karunanithi     std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
794*a43be80fSAsmitha Karunanithi 
795*a43be80fSAsmitha Karunanithi     std::string dumpPath;
796*a43be80fSAsmitha Karunanithi     if (dumpType == "BMC")
797*a43be80fSAsmitha Karunanithi     {
798*a43be80fSAsmitha Karunanithi         dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
799*a43be80fSAsmitha Karunanithi     }
800*a43be80fSAsmitha Karunanithi     else if (dumpType == "System")
801*a43be80fSAsmitha Karunanithi     {
802*a43be80fSAsmitha Karunanithi         dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
803*a43be80fSAsmitha Karunanithi     }
804*a43be80fSAsmitha Karunanithi     else
805*a43be80fSAsmitha Karunanithi     {
806*a43be80fSAsmitha Karunanithi         BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType;
807*a43be80fSAsmitha Karunanithi         messages::internalError(asyncResp->res);
808*a43be80fSAsmitha Karunanithi         return;
809*a43be80fSAsmitha Karunanithi     }
810*a43be80fSAsmitha Karunanithi 
811*a43be80fSAsmitha Karunanithi     std::optional<std::string> diagnosticDataType;
812*a43be80fSAsmitha Karunanithi     std::optional<std::string> oemDiagnosticDataType;
813*a43be80fSAsmitha Karunanithi 
814*a43be80fSAsmitha Karunanithi     if (!redfish::json_util::readJson(
815*a43be80fSAsmitha Karunanithi             req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
816*a43be80fSAsmitha Karunanithi             "OEMDiagnosticDataType", oemDiagnosticDataType))
817*a43be80fSAsmitha Karunanithi     {
818*a43be80fSAsmitha Karunanithi         return;
819*a43be80fSAsmitha Karunanithi     }
820*a43be80fSAsmitha Karunanithi 
821*a43be80fSAsmitha Karunanithi     if (dumpType == "System")
822*a43be80fSAsmitha Karunanithi     {
823*a43be80fSAsmitha Karunanithi         if (!oemDiagnosticDataType || !diagnosticDataType)
824*a43be80fSAsmitha Karunanithi         {
825*a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "CreateDump action parameter "
826*a43be80fSAsmitha Karunanithi                                 "'DiagnosticDataType'/"
827*a43be80fSAsmitha Karunanithi                                 "'OEMDiagnosticDataType' value not found!";
828*a43be80fSAsmitha Karunanithi             messages::actionParameterMissing(
829*a43be80fSAsmitha Karunanithi                 asyncResp->res, "CollectDiagnosticData",
830*a43be80fSAsmitha Karunanithi                 "DiagnosticDataType & OEMDiagnosticDataType");
831*a43be80fSAsmitha Karunanithi             return;
832*a43be80fSAsmitha Karunanithi         }
833*a43be80fSAsmitha Karunanithi         else if ((*oemDiagnosticDataType != "System") ||
834*a43be80fSAsmitha Karunanithi                  (*diagnosticDataType != "OEM"))
835*a43be80fSAsmitha Karunanithi         {
836*a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "Wrong parameter values passed";
837*a43be80fSAsmitha Karunanithi             messages::invalidObject(asyncResp->res,
838*a43be80fSAsmitha Karunanithi                                     "System Dump creation parameters");
839*a43be80fSAsmitha Karunanithi             return;
840*a43be80fSAsmitha Karunanithi         }
841*a43be80fSAsmitha Karunanithi     }
842*a43be80fSAsmitha Karunanithi     else if (dumpType == "BMC")
843*a43be80fSAsmitha Karunanithi     {
844*a43be80fSAsmitha Karunanithi         if (!diagnosticDataType)
845*a43be80fSAsmitha Karunanithi         {
846*a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR << "CreateDump action parameter "
847*a43be80fSAsmitha Karunanithi                                 "'DiagnosticDataType' not found!";
848*a43be80fSAsmitha Karunanithi             messages::actionParameterMissing(
849*a43be80fSAsmitha Karunanithi                 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
850*a43be80fSAsmitha Karunanithi             return;
851*a43be80fSAsmitha Karunanithi         }
852*a43be80fSAsmitha Karunanithi         else if (*diagnosticDataType != "Manager")
853*a43be80fSAsmitha Karunanithi         {
854*a43be80fSAsmitha Karunanithi             BMCWEB_LOG_ERROR
855*a43be80fSAsmitha Karunanithi                 << "Wrong parameter value passed for 'DiagnosticDataType'";
856*a43be80fSAsmitha Karunanithi             messages::invalidObject(asyncResp->res,
857*a43be80fSAsmitha Karunanithi                                     "BMC Dump creation parameters");
858*a43be80fSAsmitha Karunanithi             return;
859*a43be80fSAsmitha Karunanithi         }
860*a43be80fSAsmitha Karunanithi     }
861*a43be80fSAsmitha Karunanithi 
862*a43be80fSAsmitha Karunanithi     crow::connections::systemBus->async_method_call(
863*a43be80fSAsmitha Karunanithi         [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec,
864*a43be80fSAsmitha Karunanithi                                              const uint32_t& dumpId) {
865*a43be80fSAsmitha Karunanithi             if (ec)
866*a43be80fSAsmitha Karunanithi             {
867*a43be80fSAsmitha Karunanithi                 BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
868*a43be80fSAsmitha Karunanithi                 messages::internalError(asyncResp->res);
869*a43be80fSAsmitha Karunanithi                 return;
870*a43be80fSAsmitha Karunanithi             }
871*a43be80fSAsmitha Karunanithi             BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId;
872*a43be80fSAsmitha Karunanithi 
873*a43be80fSAsmitha Karunanithi             createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType);
874*a43be80fSAsmitha Karunanithi         },
875*a43be80fSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
876*a43be80fSAsmitha Karunanithi         "xyz.openbmc_project.Dump.Create", "CreateDump");
877*a43be80fSAsmitha Karunanithi }
878*a43be80fSAsmitha Karunanithi 
879043a0536SJohnathan Mantey static void ParseCrashdumpParameters(
880043a0536SJohnathan Mantey     const std::vector<std::pair<std::string, VariantType>>& params,
881043a0536SJohnathan Mantey     std::string& filename, std::string& timestamp, std::string& logfile)
882043a0536SJohnathan Mantey {
883043a0536SJohnathan Mantey     for (auto property : params)
884043a0536SJohnathan Mantey     {
885043a0536SJohnathan Mantey         if (property.first == "Timestamp")
886043a0536SJohnathan Mantey         {
887043a0536SJohnathan Mantey             const std::string* value =
8888d78b7a9SPatrick Williams                 std::get_if<std::string>(&property.second);
889043a0536SJohnathan Mantey             if (value != nullptr)
890043a0536SJohnathan Mantey             {
891043a0536SJohnathan Mantey                 timestamp = *value;
892043a0536SJohnathan Mantey             }
893043a0536SJohnathan Mantey         }
894043a0536SJohnathan Mantey         else if (property.first == "Filename")
895043a0536SJohnathan Mantey         {
896043a0536SJohnathan Mantey             const std::string* value =
8978d78b7a9SPatrick Williams                 std::get_if<std::string>(&property.second);
898043a0536SJohnathan Mantey             if (value != nullptr)
899043a0536SJohnathan Mantey             {
900043a0536SJohnathan Mantey                 filename = *value;
901043a0536SJohnathan Mantey             }
902043a0536SJohnathan Mantey         }
903043a0536SJohnathan Mantey         else if (property.first == "Log")
904043a0536SJohnathan Mantey         {
905043a0536SJohnathan Mantey             const std::string* value =
9068d78b7a9SPatrick Williams                 std::get_if<std::string>(&property.second);
907043a0536SJohnathan Mantey             if (value != nullptr)
908043a0536SJohnathan Mantey             {
909043a0536SJohnathan Mantey                 logfile = *value;
910043a0536SJohnathan Mantey             }
911043a0536SJohnathan Mantey         }
912043a0536SJohnathan Mantey     }
913043a0536SJohnathan Mantey }
914043a0536SJohnathan Mantey 
915a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode";
916c4bf6374SJason M. Bills class SystemLogServiceCollection : public Node
9171da66f75SEd Tanous {
9181da66f75SEd Tanous   public:
9191da66f75SEd Tanous     template <typename CrowApp>
920c4bf6374SJason M. Bills     SystemLogServiceCollection(CrowApp& app) :
921029573d4SEd Tanous         Node(app, "/redfish/v1/Systems/system/LogServices/")
922c4bf6374SJason M. Bills     {
923c4bf6374SJason M. Bills         entityPrivileges = {
924c4bf6374SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
925c4bf6374SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
926c4bf6374SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
927c4bf6374SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
928c4bf6374SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
929c4bf6374SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
930c4bf6374SJason M. Bills     }
931c4bf6374SJason M. Bills 
932c4bf6374SJason M. Bills   private:
933c4bf6374SJason M. Bills     /**
934c4bf6374SJason M. Bills      * Functions triggers appropriate requests on DBus
935c4bf6374SJason M. Bills      */
936c4bf6374SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
937c4bf6374SJason M. Bills                const std::vector<std::string>& params) override
938c4bf6374SJason M. Bills     {
939c4bf6374SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
940c4bf6374SJason M. Bills         // Collections don't include the static data added by SubRoute because
941c4bf6374SJason M. Bills         // it has a duplicate entry for members
942c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
943c4bf6374SJason M. Bills             "#LogServiceCollection.LogServiceCollection";
944c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
945029573d4SEd Tanous             "/redfish/v1/Systems/system/LogServices";
946c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
947c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] =
948c4bf6374SJason M. Bills             "Collection of LogServices for this Computer System";
949c4bf6374SJason M. Bills         nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
950c4bf6374SJason M. Bills         logServiceArray = nlohmann::json::array();
951029573d4SEd Tanous         logServiceArray.push_back(
952029573d4SEd Tanous             {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}});
9535cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
954c9bb6861Sraviteja-b         logServiceArray.push_back(
9555cb1dd27SAsmitha Karunanithi             {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}});
956c9bb6861Sraviteja-b #endif
957c9bb6861Sraviteja-b 
958d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
959d53dd41fSJason M. Bills         logServiceArray.push_back(
960cb92c03bSAndrew Geissler             {{"@odata.id",
961424c4176SJason M. Bills               "/redfish/v1/Systems/system/LogServices/Crashdump"}});
962d53dd41fSJason M. Bills #endif
963c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] =
964c4bf6374SJason M. Bills             logServiceArray.size();
965a3316fc6SZhikuiRen 
966a3316fc6SZhikuiRen         crow::connections::systemBus->async_method_call(
967a3316fc6SZhikuiRen             [asyncResp](const boost::system::error_code ec,
968a3316fc6SZhikuiRen                         const std::vector<std::string>& subtreePath) {
969a3316fc6SZhikuiRen                 if (ec)
970a3316fc6SZhikuiRen                 {
971a3316fc6SZhikuiRen                     BMCWEB_LOG_ERROR << ec;
972a3316fc6SZhikuiRen                     return;
973a3316fc6SZhikuiRen                 }
974a3316fc6SZhikuiRen 
975a3316fc6SZhikuiRen                 for (auto& pathStr : subtreePath)
976a3316fc6SZhikuiRen                 {
977a3316fc6SZhikuiRen                     if (pathStr.find("PostCode") != std::string::npos)
978a3316fc6SZhikuiRen                     {
979a3316fc6SZhikuiRen                         nlohmann::json& logServiceArray =
980a3316fc6SZhikuiRen                             asyncResp->res.jsonValue["Members"];
981a3316fc6SZhikuiRen                         logServiceArray.push_back(
982a3316fc6SZhikuiRen                             {{"@odata.id", "/redfish/v1/Systems/system/"
983a3316fc6SZhikuiRen                                            "LogServices/PostCodes"}});
984a3316fc6SZhikuiRen                         asyncResp->res.jsonValue["Members@odata.count"] =
985a3316fc6SZhikuiRen                             logServiceArray.size();
986a3316fc6SZhikuiRen                         return;
987a3316fc6SZhikuiRen                     }
988a3316fc6SZhikuiRen                 }
989a3316fc6SZhikuiRen             },
990a3316fc6SZhikuiRen             "xyz.openbmc_project.ObjectMapper",
991a3316fc6SZhikuiRen             "/xyz/openbmc_project/object_mapper",
992a3316fc6SZhikuiRen             "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
993a3316fc6SZhikuiRen             std::array<const char*, 1>{postCodeIface});
994c4bf6374SJason M. Bills     }
995c4bf6374SJason M. Bills };
996c4bf6374SJason M. Bills 
997c4bf6374SJason M. Bills class EventLogService : public Node
998c4bf6374SJason M. Bills {
999c4bf6374SJason M. Bills   public:
1000c4bf6374SJason M. Bills     template <typename CrowApp>
1001c4bf6374SJason M. Bills     EventLogService(CrowApp& app) :
1002029573d4SEd Tanous         Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/")
1003c4bf6374SJason M. Bills     {
1004c4bf6374SJason M. Bills         entityPrivileges = {
1005c4bf6374SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1006c4bf6374SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1007c4bf6374SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1008c4bf6374SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1009c4bf6374SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1010c4bf6374SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1011c4bf6374SJason M. Bills     }
1012c4bf6374SJason M. Bills 
1013c4bf6374SJason M. Bills   private:
1014c4bf6374SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
1015c4bf6374SJason M. Bills                const std::vector<std::string>& params) override
1016c4bf6374SJason M. Bills     {
1017c4bf6374SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1018c4bf6374SJason M. Bills 
1019c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1020029573d4SEd Tanous             "/redfish/v1/Systems/system/LogServices/EventLog";
1021c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1022c4bf6374SJason M. Bills             "#LogService.v1_1_0.LogService";
1023c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Event Log Service";
1024c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] = "System Event Log Service";
1025c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Id"] = "EventLog";
1026c4bf6374SJason M. Bills         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1027c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Entries"] = {
1028c4bf6374SJason M. Bills             {"@odata.id",
1029029573d4SEd Tanous              "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}};
1030e7d6c8b2SGunnar Mills         asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
1031e7d6c8b2SGunnar Mills 
1032e7d6c8b2SGunnar Mills             {"target", "/redfish/v1/Systems/system/LogServices/EventLog/"
1033e7d6c8b2SGunnar Mills                        "Actions/LogService.ClearLog"}};
1034489640c6SJason M. Bills     }
1035489640c6SJason M. Bills };
1036489640c6SJason M. Bills 
10371f56a3a6STim Lee class JournalEventLogClear : public Node
1038489640c6SJason M. Bills {
1039489640c6SJason M. Bills   public:
10401f56a3a6STim Lee     JournalEventLogClear(CrowApp& app) :
1041489640c6SJason M. Bills         Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
1042489640c6SJason M. Bills                   "LogService.ClearLog/")
1043489640c6SJason M. Bills     {
1044489640c6SJason M. Bills         entityPrivileges = {
1045489640c6SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1046489640c6SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1047489640c6SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1048489640c6SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1049489640c6SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1050489640c6SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1051489640c6SJason M. Bills     }
1052489640c6SJason M. Bills 
1053489640c6SJason M. Bills   private:
1054489640c6SJason M. Bills     void doPost(crow::Response& res, const crow::Request& req,
1055489640c6SJason M. Bills                 const std::vector<std::string>& params) override
1056489640c6SJason M. Bills     {
1057489640c6SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1058489640c6SJason M. Bills 
1059489640c6SJason M. Bills         // Clear the EventLog by deleting the log files
1060489640c6SJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
1061489640c6SJason M. Bills         if (getRedfishLogFiles(redfishLogFiles))
1062489640c6SJason M. Bills         {
1063489640c6SJason M. Bills             for (const std::filesystem::path& file : redfishLogFiles)
1064489640c6SJason M. Bills             {
1065489640c6SJason M. Bills                 std::error_code ec;
1066489640c6SJason M. Bills                 std::filesystem::remove(file, ec);
1067489640c6SJason M. Bills             }
1068489640c6SJason M. Bills         }
1069489640c6SJason M. Bills 
1070489640c6SJason M. Bills         // Reload rsyslog so it knows to start new log files
1071489640c6SJason M. Bills         crow::connections::systemBus->async_method_call(
1072489640c6SJason M. Bills             [asyncResp](const boost::system::error_code ec) {
1073489640c6SJason M. Bills                 if (ec)
1074489640c6SJason M. Bills                 {
1075489640c6SJason M. Bills                     BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec;
1076489640c6SJason M. Bills                     messages::internalError(asyncResp->res);
1077489640c6SJason M. Bills                     return;
1078489640c6SJason M. Bills                 }
1079489640c6SJason M. Bills 
1080489640c6SJason M. Bills                 messages::success(asyncResp->res);
1081489640c6SJason M. Bills             },
1082489640c6SJason M. Bills             "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1083489640c6SJason M. Bills             "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1084489640c6SJason M. Bills             "replace");
1085c4bf6374SJason M. Bills     }
1086c4bf6374SJason M. Bills };
1087c4bf6374SJason M. Bills 
108895820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID,
108995820184SJason M. Bills                                  const std::string logEntry,
109095820184SJason M. Bills                                  nlohmann::json& logEntryJson)
1091c4bf6374SJason M. Bills {
109295820184SJason M. Bills     // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
1093cd225da8SJason M. Bills     // First get the Timestamp
1094cd225da8SJason M. Bills     size_t space = logEntry.find_first_of(" ");
1095cd225da8SJason M. Bills     if (space == std::string::npos)
109695820184SJason M. Bills     {
109795820184SJason M. Bills         return 1;
109895820184SJason M. Bills     }
1099cd225da8SJason M. Bills     std::string timestamp = logEntry.substr(0, space);
1100cd225da8SJason M. Bills     // Then get the log contents
1101cd225da8SJason M. Bills     size_t entryStart = logEntry.find_first_not_of(" ", space);
1102cd225da8SJason M. Bills     if (entryStart == std::string::npos)
1103cd225da8SJason M. Bills     {
1104cd225da8SJason M. Bills         return 1;
1105cd225da8SJason M. Bills     }
1106cd225da8SJason M. Bills     std::string_view entry(logEntry);
1107cd225da8SJason M. Bills     entry.remove_prefix(entryStart);
1108cd225da8SJason M. Bills     // Use split to separate the entry into its fields
1109cd225da8SJason M. Bills     std::vector<std::string> logEntryFields;
1110cd225da8SJason M. Bills     boost::split(logEntryFields, entry, boost::is_any_of(","),
1111cd225da8SJason M. Bills                  boost::token_compress_on);
1112cd225da8SJason M. Bills     // We need at least a MessageId to be valid
1113cd225da8SJason M. Bills     if (logEntryFields.size() < 1)
1114cd225da8SJason M. Bills     {
1115cd225da8SJason M. Bills         return 1;
1116cd225da8SJason M. Bills     }
1117cd225da8SJason M. Bills     std::string& messageID = logEntryFields[0];
111895820184SJason M. Bills 
11194851d45dSJason M. Bills     // Get the Message from the MessageRegistry
11204851d45dSJason M. Bills     const message_registries::Message* message =
11214851d45dSJason M. Bills         message_registries::getMessage(messageID);
1122c4bf6374SJason M. Bills 
11234851d45dSJason M. Bills     std::string msg;
11244851d45dSJason M. Bills     std::string severity;
11254851d45dSJason M. Bills     if (message != nullptr)
1126c4bf6374SJason M. Bills     {
11274851d45dSJason M. Bills         msg = message->message;
11284851d45dSJason M. Bills         severity = message->severity;
1129c4bf6374SJason M. Bills     }
1130c4bf6374SJason M. Bills 
113115a86ff6SJason M. Bills     // Get the MessageArgs from the log if there are any
113215a86ff6SJason M. Bills     boost::beast::span<std::string> messageArgs;
113315a86ff6SJason M. Bills     if (logEntryFields.size() > 1)
113415a86ff6SJason M. Bills     {
113515a86ff6SJason M. Bills         std::string& messageArgsStart = logEntryFields[1];
113615a86ff6SJason M. Bills         // If the first string is empty, assume there are no MessageArgs
113715a86ff6SJason M. Bills         std::size_t messageArgsSize = 0;
113815a86ff6SJason M. Bills         if (!messageArgsStart.empty())
113915a86ff6SJason M. Bills         {
114015a86ff6SJason M. Bills             messageArgsSize = logEntryFields.size() - 1;
114115a86ff6SJason M. Bills         }
114215a86ff6SJason M. Bills 
114315a86ff6SJason M. Bills         messageArgs = boost::beast::span(&messageArgsStart, messageArgsSize);
1144c4bf6374SJason M. Bills 
11454851d45dSJason M. Bills         // Fill the MessageArgs into the Message
114695820184SJason M. Bills         int i = 0;
114795820184SJason M. Bills         for (const std::string& messageArg : messageArgs)
11484851d45dSJason M. Bills         {
114995820184SJason M. Bills             std::string argStr = "%" + std::to_string(++i);
11504851d45dSJason M. Bills             size_t argPos = msg.find(argStr);
11514851d45dSJason M. Bills             if (argPos != std::string::npos)
11524851d45dSJason M. Bills             {
115395820184SJason M. Bills                 msg.replace(argPos, argStr.length(), messageArg);
11544851d45dSJason M. Bills             }
11554851d45dSJason M. Bills         }
115615a86ff6SJason M. Bills     }
11574851d45dSJason M. Bills 
115895820184SJason M. Bills     // Get the Created time from the timestamp. The log timestamp is in RFC3339
115995820184SJason M. Bills     // format which matches the Redfish format except for the fractional seconds
116095820184SJason M. Bills     // between the '.' and the '+', so just remove them.
116195820184SJason M. Bills     std::size_t dot = timestamp.find_first_of(".");
116295820184SJason M. Bills     std::size_t plus = timestamp.find_first_of("+");
116395820184SJason M. Bills     if (dot != std::string::npos && plus != std::string::npos)
1164c4bf6374SJason M. Bills     {
116595820184SJason M. Bills         timestamp.erase(dot, plus - dot);
1166c4bf6374SJason M. Bills     }
1167c4bf6374SJason M. Bills 
1168c4bf6374SJason M. Bills     // Fill in the log entry with the gathered data
116995820184SJason M. Bills     logEntryJson = {
1170cb92c03bSAndrew Geissler         {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
1171029573d4SEd Tanous         {"@odata.id",
1172897967deSJason M. Bills          "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
117395820184SJason M. Bills              logEntryID},
1174c4bf6374SJason M. Bills         {"Name", "System Event Log Entry"},
117595820184SJason M. Bills         {"Id", logEntryID},
117695820184SJason M. Bills         {"Message", std::move(msg)},
117795820184SJason M. Bills         {"MessageId", std::move(messageID)},
1178c4bf6374SJason M. Bills         {"MessageArgs", std::move(messageArgs)},
1179c4bf6374SJason M. Bills         {"EntryType", "Event"},
118095820184SJason M. Bills         {"Severity", std::move(severity)},
118195820184SJason M. Bills         {"Created", std::move(timestamp)}};
1182c4bf6374SJason M. Bills     return 0;
1183c4bf6374SJason M. Bills }
1184c4bf6374SJason M. Bills 
118527062605SAnthony Wilson class JournalEventLogEntryCollection : public Node
1186c4bf6374SJason M. Bills {
1187c4bf6374SJason M. Bills   public:
1188c4bf6374SJason M. Bills     template <typename CrowApp>
118927062605SAnthony Wilson     JournalEventLogEntryCollection(CrowApp& app) :
1190029573d4SEd Tanous         Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
1191c4bf6374SJason M. Bills     {
1192c4bf6374SJason M. Bills         entityPrivileges = {
1193c4bf6374SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1194c4bf6374SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1195c4bf6374SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1196c4bf6374SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1197c4bf6374SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1198c4bf6374SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1199c4bf6374SJason M. Bills     }
1200c4bf6374SJason M. Bills 
1201c4bf6374SJason M. Bills   private:
1202c4bf6374SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
1203c4bf6374SJason M. Bills                const std::vector<std::string>& params) override
1204c4bf6374SJason M. Bills     {
1205c4bf6374SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1206271584abSEd Tanous         uint64_t skip = 0;
1207271584abSEd Tanous         uint64_t top = maxEntriesPerPage; // Show max entries by default
1208c4bf6374SJason M. Bills         if (!getSkipParam(asyncResp->res, req, skip))
1209c4bf6374SJason M. Bills         {
1210c4bf6374SJason M. Bills             return;
1211c4bf6374SJason M. Bills         }
1212c4bf6374SJason M. Bills         if (!getTopParam(asyncResp->res, req, top))
1213c4bf6374SJason M. Bills         {
1214c4bf6374SJason M. Bills             return;
1215c4bf6374SJason M. Bills         }
1216c4bf6374SJason M. Bills         // Collections don't include the static data added by SubRoute because
1217c4bf6374SJason M. Bills         // it has a duplicate entry for members
1218c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1219c4bf6374SJason M. Bills             "#LogEntryCollection.LogEntryCollection";
1220c4bf6374SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1221029573d4SEd Tanous             "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
1222c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1223c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] =
1224c4bf6374SJason M. Bills             "Collection of System Event Log Entries";
1225cb92c03bSAndrew Geissler 
1226c4bf6374SJason M. Bills         nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1227c4bf6374SJason M. Bills         logEntryArray = nlohmann::json::array();
122895820184SJason M. Bills         // Go through the log files and create a unique ID for each entry
122995820184SJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
123095820184SJason M. Bills         getRedfishLogFiles(redfishLogFiles);
1231b01bf299SEd Tanous         uint64_t entryCount = 0;
1232cd225da8SJason M. Bills         std::string logEntry;
123395820184SJason M. Bills 
123495820184SJason M. Bills         // Oldest logs are in the last file, so start there and loop backwards
1235cd225da8SJason M. Bills         for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1236cd225da8SJason M. Bills              it++)
1237c4bf6374SJason M. Bills         {
1238cd225da8SJason M. Bills             std::ifstream logStream(*it);
123995820184SJason M. Bills             if (!logStream.is_open())
1240c4bf6374SJason M. Bills             {
1241c4bf6374SJason M. Bills                 continue;
1242c4bf6374SJason M. Bills             }
1243c4bf6374SJason M. Bills 
1244e85d6b16SJason M. Bills             // Reset the unique ID on the first entry
1245e85d6b16SJason M. Bills             bool firstEntry = true;
124695820184SJason M. Bills             while (std::getline(logStream, logEntry))
124795820184SJason M. Bills             {
1248c4bf6374SJason M. Bills                 entryCount++;
1249c4bf6374SJason M. Bills                 // Handle paging using skip (number of entries to skip from the
1250c4bf6374SJason M. Bills                 // start) and top (number of entries to display)
1251c4bf6374SJason M. Bills                 if (entryCount <= skip || entryCount > skip + top)
1252c4bf6374SJason M. Bills                 {
1253c4bf6374SJason M. Bills                     continue;
1254c4bf6374SJason M. Bills                 }
1255c4bf6374SJason M. Bills 
1256c4bf6374SJason M. Bills                 std::string idStr;
1257e85d6b16SJason M. Bills                 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1258c4bf6374SJason M. Bills                 {
1259c4bf6374SJason M. Bills                     continue;
1260c4bf6374SJason M. Bills                 }
1261c4bf6374SJason M. Bills 
1262e85d6b16SJason M. Bills                 if (firstEntry)
1263e85d6b16SJason M. Bills                 {
1264e85d6b16SJason M. Bills                     firstEntry = false;
1265e85d6b16SJason M. Bills                 }
1266e85d6b16SJason M. Bills 
1267c4bf6374SJason M. Bills                 logEntryArray.push_back({});
1268c4bf6374SJason M. Bills                 nlohmann::json& bmcLogEntry = logEntryArray.back();
126995820184SJason M. Bills                 if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0)
1270c4bf6374SJason M. Bills                 {
1271c4bf6374SJason M. Bills                     messages::internalError(asyncResp->res);
1272c4bf6374SJason M. Bills                     return;
1273c4bf6374SJason M. Bills                 }
1274c4bf6374SJason M. Bills             }
127595820184SJason M. Bills         }
1276c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1277c4bf6374SJason M. Bills         if (skip + top < entryCount)
1278c4bf6374SJason M. Bills         {
1279c4bf6374SJason M. Bills             asyncResp->res.jsonValue["Members@odata.nextLink"] =
128095820184SJason M. Bills                 "/redfish/v1/Systems/system/LogServices/EventLog/"
128195820184SJason M. Bills                 "Entries?$skip=" +
1282c4bf6374SJason M. Bills                 std::to_string(skip + top);
1283c4bf6374SJason M. Bills         }
128408a4e4b5SAnthony Wilson     }
128508a4e4b5SAnthony Wilson };
128608a4e4b5SAnthony Wilson 
1287897967deSJason M. Bills class JournalEventLogEntry : public Node
1288897967deSJason M. Bills {
1289897967deSJason M. Bills   public:
1290897967deSJason M. Bills     JournalEventLogEntry(CrowApp& app) :
1291897967deSJason M. Bills         Node(app,
1292897967deSJason M. Bills              "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1293897967deSJason M. Bills              std::string())
1294897967deSJason M. Bills     {
1295897967deSJason M. Bills         entityPrivileges = {
1296897967deSJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1297897967deSJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1298897967deSJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1299897967deSJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1300897967deSJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1301897967deSJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1302897967deSJason M. Bills     }
1303897967deSJason M. Bills 
1304897967deSJason M. Bills   private:
1305897967deSJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
1306897967deSJason M. Bills                const std::vector<std::string>& params) override
1307897967deSJason M. Bills     {
1308897967deSJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1309897967deSJason M. Bills         if (params.size() != 1)
1310897967deSJason M. Bills         {
1311897967deSJason M. Bills             messages::internalError(asyncResp->res);
1312897967deSJason M. Bills             return;
1313897967deSJason M. Bills         }
1314897967deSJason M. Bills         const std::string& targetID = params[0];
1315897967deSJason M. Bills 
1316897967deSJason M. Bills         // Go through the log files and check the unique ID for each entry to
1317897967deSJason M. Bills         // find the target entry
1318897967deSJason M. Bills         std::vector<std::filesystem::path> redfishLogFiles;
1319897967deSJason M. Bills         getRedfishLogFiles(redfishLogFiles);
1320897967deSJason M. Bills         std::string logEntry;
1321897967deSJason M. Bills 
1322897967deSJason M. Bills         // Oldest logs are in the last file, so start there and loop backwards
1323897967deSJason M. Bills         for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1324897967deSJason M. Bills              it++)
1325897967deSJason M. Bills         {
1326897967deSJason M. Bills             std::ifstream logStream(*it);
1327897967deSJason M. Bills             if (!logStream.is_open())
1328897967deSJason M. Bills             {
1329897967deSJason M. Bills                 continue;
1330897967deSJason M. Bills             }
1331897967deSJason M. Bills 
1332897967deSJason M. Bills             // Reset the unique ID on the first entry
1333897967deSJason M. Bills             bool firstEntry = true;
1334897967deSJason M. Bills             while (std::getline(logStream, logEntry))
1335897967deSJason M. Bills             {
1336897967deSJason M. Bills                 std::string idStr;
1337897967deSJason M. Bills                 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1338897967deSJason M. Bills                 {
1339897967deSJason M. Bills                     continue;
1340897967deSJason M. Bills                 }
1341897967deSJason M. Bills 
1342897967deSJason M. Bills                 if (firstEntry)
1343897967deSJason M. Bills                 {
1344897967deSJason M. Bills                     firstEntry = false;
1345897967deSJason M. Bills                 }
1346897967deSJason M. Bills 
1347897967deSJason M. Bills                 if (idStr == targetID)
1348897967deSJason M. Bills                 {
1349897967deSJason M. Bills                     if (fillEventLogEntryJson(idStr, logEntry,
1350897967deSJason M. Bills                                               asyncResp->res.jsonValue) != 0)
1351897967deSJason M. Bills                     {
1352897967deSJason M. Bills                         messages::internalError(asyncResp->res);
1353897967deSJason M. Bills                         return;
1354897967deSJason M. Bills                     }
1355897967deSJason M. Bills                     return;
1356897967deSJason M. Bills                 }
1357897967deSJason M. Bills             }
1358897967deSJason M. Bills         }
1359897967deSJason M. Bills         // Requested ID was not found
1360897967deSJason M. Bills         messages::resourceMissingAtURI(asyncResp->res, targetID);
1361897967deSJason M. Bills     }
1362897967deSJason M. Bills };
1363897967deSJason M. Bills 
136408a4e4b5SAnthony Wilson class DBusEventLogEntryCollection : public Node
136508a4e4b5SAnthony Wilson {
136608a4e4b5SAnthony Wilson   public:
136708a4e4b5SAnthony Wilson     template <typename CrowApp>
136808a4e4b5SAnthony Wilson     DBusEventLogEntryCollection(CrowApp& app) :
136908a4e4b5SAnthony Wilson         Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
137008a4e4b5SAnthony Wilson     {
137108a4e4b5SAnthony Wilson         entityPrivileges = {
137208a4e4b5SAnthony Wilson             {boost::beast::http::verb::get, {{"Login"}}},
137308a4e4b5SAnthony Wilson             {boost::beast::http::verb::head, {{"Login"}}},
137408a4e4b5SAnthony Wilson             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
137508a4e4b5SAnthony Wilson             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
137608a4e4b5SAnthony Wilson             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
137708a4e4b5SAnthony Wilson             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
137808a4e4b5SAnthony Wilson     }
137908a4e4b5SAnthony Wilson 
138008a4e4b5SAnthony Wilson   private:
138108a4e4b5SAnthony Wilson     void doGet(crow::Response& res, const crow::Request& req,
138208a4e4b5SAnthony Wilson                const std::vector<std::string>& params) override
138308a4e4b5SAnthony Wilson     {
138408a4e4b5SAnthony Wilson         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
138508a4e4b5SAnthony Wilson 
138608a4e4b5SAnthony Wilson         // Collections don't include the static data added by SubRoute because
138708a4e4b5SAnthony Wilson         // it has a duplicate entry for members
138808a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["@odata.type"] =
138908a4e4b5SAnthony Wilson             "#LogEntryCollection.LogEntryCollection";
139008a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["@odata.id"] =
139108a4e4b5SAnthony Wilson             "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
139208a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
139308a4e4b5SAnthony Wilson         asyncResp->res.jsonValue["Description"] =
139408a4e4b5SAnthony Wilson             "Collection of System Event Log Entries";
139508a4e4b5SAnthony Wilson 
1396cb92c03bSAndrew Geissler         // DBus implementation of EventLog/Entries
1397cb92c03bSAndrew Geissler         // Make call to Logging Service to find all log entry objects
1398cb92c03bSAndrew Geissler         crow::connections::systemBus->async_method_call(
1399cb92c03bSAndrew Geissler             [asyncResp](const boost::system::error_code ec,
1400cb92c03bSAndrew Geissler                         GetManagedObjectsType& resp) {
1401cb92c03bSAndrew Geissler                 if (ec)
1402cb92c03bSAndrew Geissler                 {
1403cb92c03bSAndrew Geissler                     // TODO Handle for specific error code
1404cb92c03bSAndrew Geissler                     BMCWEB_LOG_ERROR
1405cb92c03bSAndrew Geissler                         << "getLogEntriesIfaceData resp_handler got error "
1406cb92c03bSAndrew Geissler                         << ec;
1407cb92c03bSAndrew Geissler                     messages::internalError(asyncResp->res);
1408cb92c03bSAndrew Geissler                     return;
1409cb92c03bSAndrew Geissler                 }
1410cb92c03bSAndrew Geissler                 nlohmann::json& entriesArray =
1411cb92c03bSAndrew Geissler                     asyncResp->res.jsonValue["Members"];
1412cb92c03bSAndrew Geissler                 entriesArray = nlohmann::json::array();
1413cb92c03bSAndrew Geissler                 for (auto& objectPath : resp)
1414cb92c03bSAndrew Geissler                 {
1415cb92c03bSAndrew Geissler                     for (auto& interfaceMap : objectPath.second)
1416cb92c03bSAndrew Geissler                     {
1417cb92c03bSAndrew Geissler                         if (interfaceMap.first !=
1418cb92c03bSAndrew Geissler                             "xyz.openbmc_project.Logging.Entry")
1419cb92c03bSAndrew Geissler                         {
1420cb92c03bSAndrew Geissler                             BMCWEB_LOG_DEBUG << "Bailing early on "
1421cb92c03bSAndrew Geissler                                              << interfaceMap.first;
1422cb92c03bSAndrew Geissler                             continue;
1423cb92c03bSAndrew Geissler                         }
1424cb92c03bSAndrew Geissler                         entriesArray.push_back({});
1425cb92c03bSAndrew Geissler                         nlohmann::json& thisEntry = entriesArray.back();
142666664f25SEd Tanous                         uint32_t* id = nullptr;
142766664f25SEd Tanous                         std::time_t timestamp{};
142866664f25SEd Tanous                         std::string* severity = nullptr;
142966664f25SEd Tanous                         std::string* message = nullptr;
1430cb92c03bSAndrew Geissler                         for (auto& propertyMap : interfaceMap.second)
1431cb92c03bSAndrew Geissler                         {
1432cb92c03bSAndrew Geissler                             if (propertyMap.first == "Id")
1433cb92c03bSAndrew Geissler                             {
14348d78b7a9SPatrick Williams                                 id = std::get_if<uint32_t>(&propertyMap.second);
1435cb92c03bSAndrew Geissler                                 if (id == nullptr)
1436cb92c03bSAndrew Geissler                                 {
1437cb92c03bSAndrew Geissler                                     messages::propertyMissing(asyncResp->res,
1438cb92c03bSAndrew Geissler                                                               "Id");
1439cb92c03bSAndrew Geissler                                 }
1440cb92c03bSAndrew Geissler                             }
1441cb92c03bSAndrew Geissler                             else if (propertyMap.first == "Timestamp")
1442cb92c03bSAndrew Geissler                             {
1443cb92c03bSAndrew Geissler                                 const uint64_t* millisTimeStamp =
1444cb92c03bSAndrew Geissler                                     std::get_if<uint64_t>(&propertyMap.second);
1445cb92c03bSAndrew Geissler                                 if (millisTimeStamp == nullptr)
1446cb92c03bSAndrew Geissler                                 {
1447cb92c03bSAndrew Geissler                                     messages::propertyMissing(asyncResp->res,
1448cb92c03bSAndrew Geissler                                                               "Timestamp");
1449271584abSEd Tanous                                     continue;
1450cb92c03bSAndrew Geissler                                 }
1451cb92c03bSAndrew Geissler                                 // Retrieve Created property with format:
1452cb92c03bSAndrew Geissler                                 // yyyy-mm-ddThh:mm:ss
1453cb92c03bSAndrew Geissler                                 std::chrono::milliseconds chronoTimeStamp(
1454cb92c03bSAndrew Geissler                                     *millisTimeStamp);
1455271584abSEd Tanous                                 timestamp = std::chrono::duration_cast<
1456271584abSEd Tanous                                                 std::chrono::duration<int>>(
1457271584abSEd Tanous                                                 chronoTimeStamp)
1458cb92c03bSAndrew Geissler                                                 .count();
1459cb92c03bSAndrew Geissler                             }
1460cb92c03bSAndrew Geissler                             else if (propertyMap.first == "Severity")
1461cb92c03bSAndrew Geissler                             {
1462cb92c03bSAndrew Geissler                                 severity = std::get_if<std::string>(
1463cb92c03bSAndrew Geissler                                     &propertyMap.second);
1464cb92c03bSAndrew Geissler                                 if (severity == nullptr)
1465cb92c03bSAndrew Geissler                                 {
1466cb92c03bSAndrew Geissler                                     messages::propertyMissing(asyncResp->res,
1467cb92c03bSAndrew Geissler                                                               "Severity");
1468cb92c03bSAndrew Geissler                                 }
1469cb92c03bSAndrew Geissler                             }
1470cb92c03bSAndrew Geissler                             else if (propertyMap.first == "Message")
1471cb92c03bSAndrew Geissler                             {
1472cb92c03bSAndrew Geissler                                 message = std::get_if<std::string>(
1473cb92c03bSAndrew Geissler                                     &propertyMap.second);
1474cb92c03bSAndrew Geissler                                 if (message == nullptr)
1475cb92c03bSAndrew Geissler                                 {
1476cb92c03bSAndrew Geissler                                     messages::propertyMissing(asyncResp->res,
1477cb92c03bSAndrew Geissler                                                               "Message");
1478cb92c03bSAndrew Geissler                                 }
1479cb92c03bSAndrew Geissler                             }
1480cb92c03bSAndrew Geissler                         }
1481cb92c03bSAndrew Geissler                         thisEntry = {
1482cb92c03bSAndrew Geissler                             {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
1483cb92c03bSAndrew Geissler                             {"@odata.id",
1484cb92c03bSAndrew Geissler                              "/redfish/v1/Systems/system/LogServices/EventLog/"
1485cb92c03bSAndrew Geissler                              "Entries/" +
1486cb92c03bSAndrew Geissler                                  std::to_string(*id)},
148727062605SAnthony Wilson                             {"Name", "System Event Log Entry"},
1488cb92c03bSAndrew Geissler                             {"Id", std::to_string(*id)},
1489cb92c03bSAndrew Geissler                             {"Message", *message},
1490cb92c03bSAndrew Geissler                             {"EntryType", "Event"},
1491cb92c03bSAndrew Geissler                             {"Severity",
1492cb92c03bSAndrew Geissler                              translateSeverityDbusToRedfish(*severity)},
1493cb92c03bSAndrew Geissler                             {"Created", crow::utility::getDateTime(timestamp)}};
1494cb92c03bSAndrew Geissler                     }
1495cb92c03bSAndrew Geissler                 }
1496cb92c03bSAndrew Geissler                 std::sort(entriesArray.begin(), entriesArray.end(),
1497cb92c03bSAndrew Geissler                           [](const nlohmann::json& left,
1498cb92c03bSAndrew Geissler                              const nlohmann::json& right) {
1499cb92c03bSAndrew Geissler                               return (left["Id"] <= right["Id"]);
1500cb92c03bSAndrew Geissler                           });
1501cb92c03bSAndrew Geissler                 asyncResp->res.jsonValue["Members@odata.count"] =
1502cb92c03bSAndrew Geissler                     entriesArray.size();
1503cb92c03bSAndrew Geissler             },
1504cb92c03bSAndrew Geissler             "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
1505cb92c03bSAndrew Geissler             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
1506c4bf6374SJason M. Bills     }
1507c4bf6374SJason M. Bills };
1508c4bf6374SJason M. Bills 
150908a4e4b5SAnthony Wilson class DBusEventLogEntry : public Node
1510c4bf6374SJason M. Bills {
1511c4bf6374SJason M. Bills   public:
151208a4e4b5SAnthony Wilson     DBusEventLogEntry(CrowApp& app) :
1513c4bf6374SJason M. Bills         Node(app,
1514029573d4SEd Tanous              "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1515029573d4SEd Tanous              std::string())
1516c4bf6374SJason M. Bills     {
1517c4bf6374SJason M. Bills         entityPrivileges = {
1518c4bf6374SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1519c4bf6374SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1520c4bf6374SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1521c4bf6374SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1522c4bf6374SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1523c4bf6374SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1524c4bf6374SJason M. Bills     }
1525c4bf6374SJason M. Bills 
1526c4bf6374SJason M. Bills   private:
1527c4bf6374SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
1528c4bf6374SJason M. Bills                const std::vector<std::string>& params) override
1529c4bf6374SJason M. Bills     {
1530c4bf6374SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1531029573d4SEd Tanous         if (params.size() != 1)
1532c4bf6374SJason M. Bills         {
1533c4bf6374SJason M. Bills             messages::internalError(asyncResp->res);
1534c4bf6374SJason M. Bills             return;
1535c4bf6374SJason M. Bills         }
1536029573d4SEd Tanous         const std::string& entryID = params[0];
1537cb92c03bSAndrew Geissler 
1538cb92c03bSAndrew Geissler         // DBus implementation of EventLog/Entries
1539cb92c03bSAndrew Geissler         // Make call to Logging Service to find all log entry objects
1540cb92c03bSAndrew Geissler         crow::connections::systemBus->async_method_call(
1541cb92c03bSAndrew Geissler             [asyncResp, entryID](const boost::system::error_code ec,
1542cb92c03bSAndrew Geissler                                  GetManagedPropertyType& resp) {
1543cb92c03bSAndrew Geissler                 if (ec)
1544cb92c03bSAndrew Geissler                 {
1545cb92c03bSAndrew Geissler                     BMCWEB_LOG_ERROR
1546cb92c03bSAndrew Geissler                         << "EventLogEntry (DBus) resp_handler got error " << ec;
1547cb92c03bSAndrew Geissler                     messages::internalError(asyncResp->res);
1548cb92c03bSAndrew Geissler                     return;
1549cb92c03bSAndrew Geissler                 }
155066664f25SEd Tanous                 uint32_t* id = nullptr;
155166664f25SEd Tanous                 std::time_t timestamp{};
155266664f25SEd Tanous                 std::string* severity = nullptr;
155366664f25SEd Tanous                 std::string* message = nullptr;
1554cb92c03bSAndrew Geissler                 for (auto& propertyMap : resp)
1555cb92c03bSAndrew Geissler                 {
1556cb92c03bSAndrew Geissler                     if (propertyMap.first == "Id")
1557cb92c03bSAndrew Geissler                     {
1558cb92c03bSAndrew Geissler                         id = std::get_if<uint32_t>(&propertyMap.second);
1559cb92c03bSAndrew Geissler                         if (id == nullptr)
1560cb92c03bSAndrew Geissler                         {
1561cb92c03bSAndrew Geissler                             messages::propertyMissing(asyncResp->res, "Id");
1562cb92c03bSAndrew Geissler                         }
1563cb92c03bSAndrew Geissler                     }
1564cb92c03bSAndrew Geissler                     else if (propertyMap.first == "Timestamp")
1565cb92c03bSAndrew Geissler                     {
1566cb92c03bSAndrew Geissler                         const uint64_t* millisTimeStamp =
1567cb92c03bSAndrew Geissler                             std::get_if<uint64_t>(&propertyMap.second);
1568cb92c03bSAndrew Geissler                         if (millisTimeStamp == nullptr)
1569cb92c03bSAndrew Geissler                         {
1570cb92c03bSAndrew Geissler                             messages::propertyMissing(asyncResp->res,
1571cb92c03bSAndrew Geissler                                                       "Timestamp");
1572271584abSEd Tanous                             continue;
1573cb92c03bSAndrew Geissler                         }
1574cb92c03bSAndrew Geissler                         // Retrieve Created property with format:
1575cb92c03bSAndrew Geissler                         // yyyy-mm-ddThh:mm:ss
1576cb92c03bSAndrew Geissler                         std::chrono::milliseconds chronoTimeStamp(
1577cb92c03bSAndrew Geissler                             *millisTimeStamp);
1578cb92c03bSAndrew Geissler                         timestamp =
1579271584abSEd Tanous                             std::chrono::duration_cast<
1580271584abSEd Tanous                                 std::chrono::duration<int>>(chronoTimeStamp)
1581cb92c03bSAndrew Geissler                                 .count();
1582cb92c03bSAndrew Geissler                     }
1583cb92c03bSAndrew Geissler                     else if (propertyMap.first == "Severity")
1584cb92c03bSAndrew Geissler                     {
1585cb92c03bSAndrew Geissler                         severity =
1586cb92c03bSAndrew Geissler                             std::get_if<std::string>(&propertyMap.second);
1587cb92c03bSAndrew Geissler                         if (severity == nullptr)
1588cb92c03bSAndrew Geissler                         {
1589cb92c03bSAndrew Geissler                             messages::propertyMissing(asyncResp->res,
1590cb92c03bSAndrew Geissler                                                       "Severity");
1591cb92c03bSAndrew Geissler                         }
1592cb92c03bSAndrew Geissler                     }
1593cb92c03bSAndrew Geissler                     else if (propertyMap.first == "Message")
1594cb92c03bSAndrew Geissler                     {
1595cb92c03bSAndrew Geissler                         message = std::get_if<std::string>(&propertyMap.second);
1596cb92c03bSAndrew Geissler                         if (message == nullptr)
1597cb92c03bSAndrew Geissler                         {
1598cb92c03bSAndrew Geissler                             messages::propertyMissing(asyncResp->res,
1599cb92c03bSAndrew Geissler                                                       "Message");
1600cb92c03bSAndrew Geissler                         }
1601cb92c03bSAndrew Geissler                     }
1602cb92c03bSAndrew Geissler                 }
1603271584abSEd Tanous                 if (id == nullptr || message == nullptr || severity == nullptr)
1604271584abSEd Tanous                 {
1605271584abSEd Tanous                     return;
1606271584abSEd Tanous                 }
1607cb92c03bSAndrew Geissler                 asyncResp->res.jsonValue = {
1608cb92c03bSAndrew Geissler                     {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
1609cb92c03bSAndrew Geissler                     {"@odata.id",
1610cb92c03bSAndrew Geissler                      "/redfish/v1/Systems/system/LogServices/EventLog/"
1611cb92c03bSAndrew Geissler                      "Entries/" +
1612cb92c03bSAndrew Geissler                          std::to_string(*id)},
161327062605SAnthony Wilson                     {"Name", "System Event Log Entry"},
1614cb92c03bSAndrew Geissler                     {"Id", std::to_string(*id)},
1615cb92c03bSAndrew Geissler                     {"Message", *message},
1616cb92c03bSAndrew Geissler                     {"EntryType", "Event"},
1617cb92c03bSAndrew Geissler                     {"Severity", translateSeverityDbusToRedfish(*severity)},
161808a4e4b5SAnthony Wilson                     {"Created", crow::utility::getDateTime(timestamp)}};
1619cb92c03bSAndrew Geissler             },
1620cb92c03bSAndrew Geissler             "xyz.openbmc_project.Logging",
1621cb92c03bSAndrew Geissler             "/xyz/openbmc_project/logging/entry/" + entryID,
1622cb92c03bSAndrew Geissler             "org.freedesktop.DBus.Properties", "GetAll",
1623cb92c03bSAndrew Geissler             "xyz.openbmc_project.Logging.Entry");
1624c4bf6374SJason M. Bills     }
1625336e96c6SChicago Duan 
1626336e96c6SChicago Duan     void doDelete(crow::Response& res, const crow::Request& req,
1627336e96c6SChicago Duan                   const std::vector<std::string>& params) override
1628336e96c6SChicago Duan     {
1629336e96c6SChicago Duan 
1630336e96c6SChicago Duan         BMCWEB_LOG_DEBUG << "Do delete single event entries.";
1631336e96c6SChicago Duan 
1632336e96c6SChicago Duan         auto asyncResp = std::make_shared<AsyncResp>(res);
1633336e96c6SChicago Duan 
1634336e96c6SChicago Duan         if (params.size() != 1)
1635336e96c6SChicago Duan         {
1636336e96c6SChicago Duan             messages::internalError(asyncResp->res);
1637336e96c6SChicago Duan             return;
1638336e96c6SChicago Duan         }
1639336e96c6SChicago Duan         std::string entryID = params[0];
1640336e96c6SChicago Duan 
1641336e96c6SChicago Duan         dbus::utility::escapePathForDbus(entryID);
1642336e96c6SChicago Duan 
1643336e96c6SChicago Duan         // Process response from Logging service.
1644336e96c6SChicago Duan         auto respHandler = [asyncResp](const boost::system::error_code ec) {
1645336e96c6SChicago Duan             BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done";
1646336e96c6SChicago Duan             if (ec)
1647336e96c6SChicago Duan             {
1648336e96c6SChicago Duan                 // TODO Handle for specific error code
1649336e96c6SChicago Duan                 BMCWEB_LOG_ERROR
1650336e96c6SChicago Duan                     << "EventLogEntry (DBus) doDelete respHandler got error "
1651336e96c6SChicago Duan                     << ec;
1652336e96c6SChicago Duan                 asyncResp->res.result(
1653336e96c6SChicago Duan                     boost::beast::http::status::internal_server_error);
1654336e96c6SChicago Duan                 return;
1655336e96c6SChicago Duan             }
1656336e96c6SChicago Duan 
1657336e96c6SChicago Duan             asyncResp->res.result(boost::beast::http::status::ok);
1658336e96c6SChicago Duan         };
1659336e96c6SChicago Duan 
1660336e96c6SChicago Duan         // Make call to Logging service to request Delete Log
1661336e96c6SChicago Duan         crow::connections::systemBus->async_method_call(
1662336e96c6SChicago Duan             respHandler, "xyz.openbmc_project.Logging",
1663336e96c6SChicago Duan             "/xyz/openbmc_project/logging/entry/" + entryID,
1664336e96c6SChicago Duan             "xyz.openbmc_project.Object.Delete", "Delete");
1665336e96c6SChicago Duan     }
1666c4bf6374SJason M. Bills };
1667c4bf6374SJason M. Bills 
1668c4bf6374SJason M. Bills class BMCLogServiceCollection : public Node
1669c4bf6374SJason M. Bills {
1670c4bf6374SJason M. Bills   public:
1671c4bf6374SJason M. Bills     template <typename CrowApp>
1672c4bf6374SJason M. Bills     BMCLogServiceCollection(CrowApp& app) :
16734ed77cd5SEd Tanous         Node(app, "/redfish/v1/Managers/bmc/LogServices/")
16741da66f75SEd Tanous     {
16751da66f75SEd Tanous         entityPrivileges = {
1676e1f26343SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1677e1f26343SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1678e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1679e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1680e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1681e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
16821da66f75SEd Tanous     }
16831da66f75SEd Tanous 
16841da66f75SEd Tanous   private:
16851da66f75SEd Tanous     /**
16861da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
16871da66f75SEd Tanous      */
16881da66f75SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
16891da66f75SEd Tanous                const std::vector<std::string>& params) override
16901da66f75SEd Tanous     {
1691e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
16921da66f75SEd Tanous         // Collections don't include the static data added by SubRoute because
16931da66f75SEd Tanous         // it has a duplicate entry for members
1694e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
16951da66f75SEd Tanous             "#LogServiceCollection.LogServiceCollection";
1696e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1697e1f26343SJason M. Bills             "/redfish/v1/Managers/bmc/LogServices";
1698e1f26343SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1699e1f26343SJason M. Bills         asyncResp->res.jsonValue["Description"] =
17001da66f75SEd Tanous             "Collection of LogServices for this Manager";
1701c4bf6374SJason M. Bills         nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
1702c4bf6374SJason M. Bills         logServiceArray = nlohmann::json::array();
17035cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
17045cb1dd27SAsmitha Karunanithi         logServiceArray.push_back(
17055cb1dd27SAsmitha Karunanithi             {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}});
17065cb1dd27SAsmitha Karunanithi #endif
1707c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
1708c4bf6374SJason M. Bills         logServiceArray.push_back(
170908a4e4b5SAnthony Wilson             {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}});
1710c4bf6374SJason M. Bills #endif
1711e1f26343SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] =
1712c4bf6374SJason M. Bills             logServiceArray.size();
17131da66f75SEd Tanous     }
17141da66f75SEd Tanous };
17151da66f75SEd Tanous 
1716c4bf6374SJason M. Bills class BMCJournalLogService : public Node
17171da66f75SEd Tanous {
17181da66f75SEd Tanous   public:
17191da66f75SEd Tanous     template <typename CrowApp>
1720c4bf6374SJason M. Bills     BMCJournalLogService(CrowApp& app) :
1721c4bf6374SJason M. Bills         Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
1722e1f26343SJason M. Bills     {
1723e1f26343SJason M. Bills         entityPrivileges = {
1724e1f26343SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1725e1f26343SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1726e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1727e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1728e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1729e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1730e1f26343SJason M. Bills     }
1731e1f26343SJason M. Bills 
1732e1f26343SJason M. Bills   private:
1733e1f26343SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
1734e1f26343SJason M. Bills                const std::vector<std::string>& params) override
1735e1f26343SJason M. Bills     {
1736e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1737e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1738e1f26343SJason M. Bills             "#LogService.v1_1_0.LogService";
17390f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
17400f74e643SEd Tanous             "/redfish/v1/Managers/bmc/LogServices/Journal";
1741c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service";
1742c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service";
1743c4bf6374SJason M. Bills         asyncResp->res.jsonValue["Id"] = "BMC Journal";
1744e1f26343SJason M. Bills         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1745cd50aa42SJason M. Bills         asyncResp->res.jsonValue["Entries"] = {
1746cd50aa42SJason M. Bills             {"@odata.id",
1747086be238SEd Tanous              "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}};
1748e1f26343SJason M. Bills     }
1749e1f26343SJason M. Bills };
1750e1f26343SJason M. Bills 
1751c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID,
1752e1f26343SJason M. Bills                                       sd_journal* journal,
1753c4bf6374SJason M. Bills                                       nlohmann::json& bmcJournalLogEntryJson)
1754e1f26343SJason M. Bills {
1755e1f26343SJason M. Bills     // Get the Log Entry contents
1756e1f26343SJason M. Bills     int ret = 0;
1757e1f26343SJason M. Bills 
175839e77504SEd Tanous     std::string_view msg;
175916428a1aSJason M. Bills     ret = getJournalMetadata(journal, "MESSAGE", msg);
1760e1f26343SJason M. Bills     if (ret < 0)
1761e1f26343SJason M. Bills     {
1762e1f26343SJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret);
1763e1f26343SJason M. Bills         return 1;
1764e1f26343SJason M. Bills     }
1765e1f26343SJason M. Bills 
1766e1f26343SJason M. Bills     // Get the severity from the PRIORITY field
1767271584abSEd Tanous     long int severity = 8; // Default to an invalid priority
176816428a1aSJason M. Bills     ret = getJournalMetadata(journal, "PRIORITY", 10, severity);
1769e1f26343SJason M. Bills     if (ret < 0)
1770e1f26343SJason M. Bills     {
1771e1f26343SJason M. Bills         BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret);
1772e1f26343SJason M. Bills     }
1773e1f26343SJason M. Bills 
1774e1f26343SJason M. Bills     // Get the Created time from the timestamp
177516428a1aSJason M. Bills     std::string entryTimeStr;
177616428a1aSJason M. Bills     if (!getEntryTimestamp(journal, entryTimeStr))
1777e1f26343SJason M. Bills     {
177816428a1aSJason M. Bills         return 1;
1779e1f26343SJason M. Bills     }
1780e1f26343SJason M. Bills 
1781e1f26343SJason M. Bills     // Fill in the log entry with the gathered data
1782c4bf6374SJason M. Bills     bmcJournalLogEntryJson = {
1783cb92c03bSAndrew Geissler         {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
1784c4bf6374SJason M. Bills         {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" +
1785c4bf6374SJason M. Bills                           bmcJournalLogEntryID},
1786e1f26343SJason M. Bills         {"Name", "BMC Journal Entry"},
1787c4bf6374SJason M. Bills         {"Id", bmcJournalLogEntryID},
178816428a1aSJason M. Bills         {"Message", msg},
1789e1f26343SJason M. Bills         {"EntryType", "Oem"},
1790e1f26343SJason M. Bills         {"Severity",
1791b6a61a5eSJason M. Bills          severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"},
1792086be238SEd Tanous         {"OemRecordFormat", "BMC Journal Entry"},
1793e1f26343SJason M. Bills         {"Created", std::move(entryTimeStr)}};
1794e1f26343SJason M. Bills     return 0;
1795e1f26343SJason M. Bills }
1796e1f26343SJason M. Bills 
1797c4bf6374SJason M. Bills class BMCJournalLogEntryCollection : public Node
1798e1f26343SJason M. Bills {
1799e1f26343SJason M. Bills   public:
1800e1f26343SJason M. Bills     template <typename CrowApp>
1801c4bf6374SJason M. Bills     BMCJournalLogEntryCollection(CrowApp& app) :
1802c4bf6374SJason M. Bills         Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
1803e1f26343SJason M. Bills     {
1804e1f26343SJason M. Bills         entityPrivileges = {
1805e1f26343SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
1806e1f26343SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
1807e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1808e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1809e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1810e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1811e1f26343SJason M. Bills     }
1812e1f26343SJason M. Bills 
1813e1f26343SJason M. Bills   private:
1814e1f26343SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
1815e1f26343SJason M. Bills                const std::vector<std::string>& params) override
1816e1f26343SJason M. Bills     {
1817e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1818193ad2faSJason M. Bills         static constexpr const long maxEntriesPerPage = 1000;
1819271584abSEd Tanous         uint64_t skip = 0;
1820271584abSEd Tanous         uint64_t top = maxEntriesPerPage; // Show max entries by default
182116428a1aSJason M. Bills         if (!getSkipParam(asyncResp->res, req, skip))
1822193ad2faSJason M. Bills         {
1823193ad2faSJason M. Bills             return;
1824193ad2faSJason M. Bills         }
182516428a1aSJason M. Bills         if (!getTopParam(asyncResp->res, req, top))
1826193ad2faSJason M. Bills         {
1827193ad2faSJason M. Bills             return;
1828193ad2faSJason M. Bills         }
1829e1f26343SJason M. Bills         // Collections don't include the static data added by SubRoute because
1830e1f26343SJason M. Bills         // it has a duplicate entry for members
1831e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
1832e1f26343SJason M. Bills             "#LogEntryCollection.LogEntryCollection";
18330f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
18340f74e643SEd Tanous             "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
1835e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
1836c4bf6374SJason M. Bills             "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
1837e1f26343SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries";
1838e1f26343SJason M. Bills         asyncResp->res.jsonValue["Description"] =
1839e1f26343SJason M. Bills             "Collection of BMC Journal Entries";
18400f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
18410f74e643SEd Tanous             "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries";
1842e1f26343SJason M. Bills         nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
1843e1f26343SJason M. Bills         logEntryArray = nlohmann::json::array();
1844e1f26343SJason M. Bills 
1845e1f26343SJason M. Bills         // Go through the journal and use the timestamp to create a unique ID
1846e1f26343SJason M. Bills         // for each entry
1847e1f26343SJason M. Bills         sd_journal* journalTmp = nullptr;
1848e1f26343SJason M. Bills         int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1849e1f26343SJason M. Bills         if (ret < 0)
1850e1f26343SJason M. Bills         {
1851e1f26343SJason M. Bills             BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
1852f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
1853e1f26343SJason M. Bills             return;
1854e1f26343SJason M. Bills         }
1855e1f26343SJason M. Bills         std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1856e1f26343SJason M. Bills             journalTmp, sd_journal_close);
1857e1f26343SJason M. Bills         journalTmp = nullptr;
1858b01bf299SEd Tanous         uint64_t entryCount = 0;
1859e85d6b16SJason M. Bills         // Reset the unique ID on the first entry
1860e85d6b16SJason M. Bills         bool firstEntry = true;
1861e1f26343SJason M. Bills         SD_JOURNAL_FOREACH(journal.get())
1862e1f26343SJason M. Bills         {
1863193ad2faSJason M. Bills             entryCount++;
1864193ad2faSJason M. Bills             // Handle paging using skip (number of entries to skip from the
1865193ad2faSJason M. Bills             // start) and top (number of entries to display)
1866193ad2faSJason M. Bills             if (entryCount <= skip || entryCount > skip + top)
1867193ad2faSJason M. Bills             {
1868193ad2faSJason M. Bills                 continue;
1869193ad2faSJason M. Bills             }
1870193ad2faSJason M. Bills 
187116428a1aSJason M. Bills             std::string idStr;
1872e85d6b16SJason M. Bills             if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
1873e1f26343SJason M. Bills             {
1874e1f26343SJason M. Bills                 continue;
1875e1f26343SJason M. Bills             }
1876e1f26343SJason M. Bills 
1877e85d6b16SJason M. Bills             if (firstEntry)
1878e85d6b16SJason M. Bills             {
1879e85d6b16SJason M. Bills                 firstEntry = false;
1880e85d6b16SJason M. Bills             }
1881e85d6b16SJason M. Bills 
1882e1f26343SJason M. Bills             logEntryArray.push_back({});
1883c4bf6374SJason M. Bills             nlohmann::json& bmcJournalLogEntry = logEntryArray.back();
1884c4bf6374SJason M. Bills             if (fillBMCJournalLogEntryJson(idStr, journal.get(),
1885c4bf6374SJason M. Bills                                            bmcJournalLogEntry) != 0)
1886e1f26343SJason M. Bills             {
1887f12894f8SJason M. Bills                 messages::internalError(asyncResp->res);
1888e1f26343SJason M. Bills                 return;
1889e1f26343SJason M. Bills             }
1890e1f26343SJason M. Bills         }
1891193ad2faSJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1892193ad2faSJason M. Bills         if (skip + top < entryCount)
1893193ad2faSJason M. Bills         {
1894193ad2faSJason M. Bills             asyncResp->res.jsonValue["Members@odata.nextLink"] =
1895c4bf6374SJason M. Bills                 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" +
1896193ad2faSJason M. Bills                 std::to_string(skip + top);
1897193ad2faSJason M. Bills         }
1898e1f26343SJason M. Bills     }
1899e1f26343SJason M. Bills };
1900e1f26343SJason M. Bills 
1901c4bf6374SJason M. Bills class BMCJournalLogEntry : public Node
1902e1f26343SJason M. Bills {
1903e1f26343SJason M. Bills   public:
1904c4bf6374SJason M. Bills     BMCJournalLogEntry(CrowApp& app) :
1905c4bf6374SJason M. Bills         Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/",
1906e1f26343SJason M. Bills              std::string())
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,
1919e1f26343SJason M. Bills                const std::vector<std::string>& params) override
1920e1f26343SJason M. Bills     {
1921e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1922e1f26343SJason M. Bills         if (params.size() != 1)
1923e1f26343SJason M. Bills         {
1924f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
1925e1f26343SJason M. Bills             return;
1926e1f26343SJason M. Bills         }
192716428a1aSJason M. Bills         const std::string& entryID = params[0];
1928e1f26343SJason M. Bills         // Convert the unique ID back to a timestamp to find the entry
1929e1f26343SJason M. Bills         uint64_t ts = 0;
1930271584abSEd Tanous         uint64_t index = 0;
193116428a1aSJason M. Bills         if (!getTimestampFromID(asyncResp->res, entryID, ts, index))
1932e1f26343SJason M. Bills         {
193316428a1aSJason M. Bills             return;
1934e1f26343SJason M. Bills         }
1935e1f26343SJason M. Bills 
1936e1f26343SJason M. Bills         sd_journal* journalTmp = nullptr;
1937e1f26343SJason M. Bills         int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1938e1f26343SJason M. Bills         if (ret < 0)
1939e1f26343SJason M. Bills         {
1940e1f26343SJason M. Bills             BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
1941f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
1942e1f26343SJason M. Bills             return;
1943e1f26343SJason M. Bills         }
1944e1f26343SJason M. Bills         std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1945e1f26343SJason M. Bills             journalTmp, sd_journal_close);
1946e1f26343SJason M. Bills         journalTmp = nullptr;
1947e1f26343SJason M. Bills         // Go to the timestamp in the log and move to the entry at the index
1948af07e3f5SJason M. Bills         // tracking the unique ID
1949af07e3f5SJason M. Bills         std::string idStr;
1950af07e3f5SJason M. Bills         bool firstEntry = true;
1951e1f26343SJason M. Bills         ret = sd_journal_seek_realtime_usec(journal.get(), ts);
19522056b6d1SManojkiran Eda         if (ret < 0)
19532056b6d1SManojkiran Eda         {
19542056b6d1SManojkiran Eda             BMCWEB_LOG_ERROR << "failed to seek to an entry in journal"
19552056b6d1SManojkiran Eda                              << strerror(-ret);
19562056b6d1SManojkiran Eda             messages::internalError(asyncResp->res);
19572056b6d1SManojkiran Eda             return;
19582056b6d1SManojkiran Eda         }
1959271584abSEd Tanous         for (uint64_t i = 0; i <= index; i++)
1960e1f26343SJason M. Bills         {
1961e1f26343SJason M. Bills             sd_journal_next(journal.get());
1962af07e3f5SJason M. Bills             if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
1963af07e3f5SJason M. Bills             {
1964af07e3f5SJason M. Bills                 messages::internalError(asyncResp->res);
1965af07e3f5SJason M. Bills                 return;
1966af07e3f5SJason M. Bills             }
1967af07e3f5SJason M. Bills             if (firstEntry)
1968af07e3f5SJason M. Bills             {
1969af07e3f5SJason M. Bills                 firstEntry = false;
1970af07e3f5SJason M. Bills             }
1971e1f26343SJason M. Bills         }
1972c4bf6374SJason M. Bills         // Confirm that the entry ID matches what was requested
1973af07e3f5SJason M. Bills         if (idStr != entryID)
1974c4bf6374SJason M. Bills         {
1975c4bf6374SJason M. Bills             messages::resourceMissingAtURI(asyncResp->res, entryID);
1976c4bf6374SJason M. Bills             return;
1977c4bf6374SJason M. Bills         }
1978c4bf6374SJason M. Bills 
1979c4bf6374SJason M. Bills         if (fillBMCJournalLogEntryJson(entryID, journal.get(),
1980e1f26343SJason M. Bills                                        asyncResp->res.jsonValue) != 0)
1981e1f26343SJason M. Bills         {
1982f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
1983e1f26343SJason M. Bills             return;
1984e1f26343SJason M. Bills         }
1985e1f26343SJason M. Bills     }
1986e1f26343SJason M. Bills };
1987e1f26343SJason M. Bills 
19885cb1dd27SAsmitha Karunanithi class BMCDumpService : public Node
1989c9bb6861Sraviteja-b {
1990c9bb6861Sraviteja-b   public:
1991c9bb6861Sraviteja-b     template <typename CrowApp>
19925cb1dd27SAsmitha Karunanithi     BMCDumpService(CrowApp& app) :
19935cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
1994c9bb6861Sraviteja-b     {
1995c9bb6861Sraviteja-b         entityPrivileges = {
1996c9bb6861Sraviteja-b             {boost::beast::http::verb::get, {{"Login"}}},
1997c9bb6861Sraviteja-b             {boost::beast::http::verb::head, {{"Login"}}},
1998c9bb6861Sraviteja-b             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1999c9bb6861Sraviteja-b             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2000c9bb6861Sraviteja-b             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2001c9bb6861Sraviteja-b             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2002c9bb6861Sraviteja-b     }
2003c9bb6861Sraviteja-b 
2004c9bb6861Sraviteja-b   private:
2005c9bb6861Sraviteja-b     void doGet(crow::Response& res, const crow::Request& req,
2006c9bb6861Sraviteja-b                const std::vector<std::string>& params) override
2007c9bb6861Sraviteja-b     {
2008c9bb6861Sraviteja-b         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2009c9bb6861Sraviteja-b 
2010c9bb6861Sraviteja-b         asyncResp->res.jsonValue["@odata.id"] =
20115cb1dd27SAsmitha Karunanithi             "/redfish/v1/Managers/bmc/LogServices/Dump";
2012c9bb6861Sraviteja-b         asyncResp->res.jsonValue["@odata.type"] =
2013c9bb6861Sraviteja-b             "#LogService.v1_1_0.LogService";
2014c9bb6861Sraviteja-b         asyncResp->res.jsonValue["Name"] = "Dump LogService";
20155cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Description"] = "BMC Dump LogService";
20165cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Id"] = "Dump";
2017c9bb6861Sraviteja-b         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2018c9bb6861Sraviteja-b         asyncResp->res.jsonValue["Entries"] = {
20195cb1dd27SAsmitha Karunanithi             {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}};
20205cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Actions"] = {
20215cb1dd27SAsmitha Karunanithi             {"#LogService.ClearLog",
20225cb1dd27SAsmitha Karunanithi              {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
20235cb1dd27SAsmitha Karunanithi                          "Actions/LogService.ClearLog"}}},
20245cb1dd27SAsmitha Karunanithi             {"Oem",
20255cb1dd27SAsmitha Karunanithi              {{"#OemLogService.CollectDiagnosticData",
20265cb1dd27SAsmitha Karunanithi                {{"target",
20275cb1dd27SAsmitha Karunanithi                  "/redfish/v1/Managers/bmc/LogServices/Dump/"
20285cb1dd27SAsmitha Karunanithi                  "Actions/Oem/OemLogService.CollectDiagnosticData"}}}}}};
2029c9bb6861Sraviteja-b     }
2030c9bb6861Sraviteja-b };
2031c9bb6861Sraviteja-b 
20325cb1dd27SAsmitha Karunanithi class BMCDumpEntryCollection : public Node
2033c9bb6861Sraviteja-b {
2034c9bb6861Sraviteja-b   public:
2035c9bb6861Sraviteja-b     template <typename CrowApp>
20365cb1dd27SAsmitha Karunanithi     BMCDumpEntryCollection(CrowApp& app) :
20375cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
2038c9bb6861Sraviteja-b     {
2039c9bb6861Sraviteja-b         entityPrivileges = {
2040c9bb6861Sraviteja-b             {boost::beast::http::verb::get, {{"Login"}}},
2041c9bb6861Sraviteja-b             {boost::beast::http::verb::head, {{"Login"}}},
2042c9bb6861Sraviteja-b             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2043c9bb6861Sraviteja-b             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2044c9bb6861Sraviteja-b             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2045c9bb6861Sraviteja-b             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2046c9bb6861Sraviteja-b     }
2047c9bb6861Sraviteja-b 
2048c9bb6861Sraviteja-b   private:
2049c9bb6861Sraviteja-b     /**
2050c9bb6861Sraviteja-b      * Functions triggers appropriate requests on DBus
2051c9bb6861Sraviteja-b      */
2052c9bb6861Sraviteja-b     void doGet(crow::Response& res, const crow::Request& req,
2053c9bb6861Sraviteja-b                const std::vector<std::string>& params) override
2054c9bb6861Sraviteja-b     {
2055c9bb6861Sraviteja-b         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2056c9bb6861Sraviteja-b 
2057c9bb6861Sraviteja-b         asyncResp->res.jsonValue["@odata.type"] =
2058c9bb6861Sraviteja-b             "#LogEntryCollection.LogEntryCollection";
2059c9bb6861Sraviteja-b         asyncResp->res.jsonValue["@odata.id"] =
20605cb1dd27SAsmitha Karunanithi             "/redfish/v1/Managers/bmc/LogServices/Dump/Entries";
20615cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Name"] = "BMC Dump Entries";
2062c9bb6861Sraviteja-b         asyncResp->res.jsonValue["Description"] =
20635cb1dd27SAsmitha Karunanithi             "Collection of BMC Dump Entries";
2064c9bb6861Sraviteja-b 
20655cb1dd27SAsmitha Karunanithi         getDumpEntryCollection(asyncResp, "BMC");
2066c9bb6861Sraviteja-b     }
2067c9bb6861Sraviteja-b };
2068c9bb6861Sraviteja-b 
20695cb1dd27SAsmitha Karunanithi class BMCDumpEntry : public Node
2070c9bb6861Sraviteja-b {
2071c9bb6861Sraviteja-b   public:
20725cb1dd27SAsmitha Karunanithi     BMCDumpEntry(CrowApp& app) :
20735cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/",
2074c9bb6861Sraviteja-b              std::string())
2075c9bb6861Sraviteja-b     {
2076c9bb6861Sraviteja-b         entityPrivileges = {
2077c9bb6861Sraviteja-b             {boost::beast::http::verb::get, {{"Login"}}},
2078c9bb6861Sraviteja-b             {boost::beast::http::verb::head, {{"Login"}}},
2079c9bb6861Sraviteja-b             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2080c9bb6861Sraviteja-b             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2081c9bb6861Sraviteja-b             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2082c9bb6861Sraviteja-b             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2083c9bb6861Sraviteja-b     }
2084c9bb6861Sraviteja-b 
2085c9bb6861Sraviteja-b   private:
2086c9bb6861Sraviteja-b     void doGet(crow::Response& res, const crow::Request& req,
2087c9bb6861Sraviteja-b                const std::vector<std::string>& params) override
2088c9bb6861Sraviteja-b     {
2089c9bb6861Sraviteja-b         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2090c9bb6861Sraviteja-b         if (params.size() != 1)
2091c9bb6861Sraviteja-b         {
2092c9bb6861Sraviteja-b             messages::internalError(asyncResp->res);
2093c9bb6861Sraviteja-b             return;
2094c9bb6861Sraviteja-b         }
20955cb1dd27SAsmitha Karunanithi         getDumpEntryById(asyncResp, params[0], "BMC");
2096c9bb6861Sraviteja-b     }
2097c9bb6861Sraviteja-b 
2098c9bb6861Sraviteja-b     void doDelete(crow::Response& res, const crow::Request& req,
2099c9bb6861Sraviteja-b                   const std::vector<std::string>& params) override
2100c9bb6861Sraviteja-b     {
21015cb1dd27SAsmitha Karunanithi         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2102c9bb6861Sraviteja-b         if (params.size() != 1)
2103c9bb6861Sraviteja-b         {
2104c9bb6861Sraviteja-b             messages::internalError(asyncResp->res);
2105c9bb6861Sraviteja-b             return;
2106c9bb6861Sraviteja-b         }
21075cb1dd27SAsmitha Karunanithi         deleteDumpEntry(asyncResp->res, params[0]);
21085cb1dd27SAsmitha Karunanithi     }
21095cb1dd27SAsmitha Karunanithi };
2110c9bb6861Sraviteja-b 
2111*a43be80fSAsmitha Karunanithi class BMCDumpCreate : public Node
2112*a43be80fSAsmitha Karunanithi {
2113*a43be80fSAsmitha Karunanithi   public:
2114*a43be80fSAsmitha Karunanithi     BMCDumpCreate(CrowApp& app) :
2115*a43be80fSAsmitha Karunanithi         Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2116*a43be80fSAsmitha Karunanithi                   "Actions/Oem/"
2117*a43be80fSAsmitha Karunanithi                   "OemLogService.CollectDiagnosticData/")
2118*a43be80fSAsmitha Karunanithi     {
2119*a43be80fSAsmitha Karunanithi         entityPrivileges = {
2120*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
2121*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
2122*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2123*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2124*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2125*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2126*a43be80fSAsmitha Karunanithi     }
2127*a43be80fSAsmitha Karunanithi 
2128*a43be80fSAsmitha Karunanithi   private:
2129*a43be80fSAsmitha Karunanithi     void doPost(crow::Response& res, const crow::Request& req,
2130*a43be80fSAsmitha Karunanithi                 const std::vector<std::string>& params) override
2131*a43be80fSAsmitha Karunanithi     {
2132*a43be80fSAsmitha Karunanithi         createDump(res, req, "BMC");
2133*a43be80fSAsmitha Karunanithi     }
2134*a43be80fSAsmitha Karunanithi };
2135*a43be80fSAsmitha Karunanithi 
21365cb1dd27SAsmitha Karunanithi class SystemDumpService : public Node
2137c9bb6861Sraviteja-b {
21385cb1dd27SAsmitha Karunanithi   public:
21395cb1dd27SAsmitha Karunanithi     template <typename CrowApp>
21405cb1dd27SAsmitha Karunanithi     SystemDumpService(CrowApp& app) :
21415cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Systems/system/LogServices/Dump/")
21425cb1dd27SAsmitha Karunanithi     {
21435cb1dd27SAsmitha Karunanithi         entityPrivileges = {
21445cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
21455cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
21465cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
21475cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
21485cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
21495cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
21505cb1dd27SAsmitha Karunanithi     }
21515cb1dd27SAsmitha Karunanithi 
21525cb1dd27SAsmitha Karunanithi   private:
21535cb1dd27SAsmitha Karunanithi     void doGet(crow::Response& res, const crow::Request& req,
21545cb1dd27SAsmitha Karunanithi                const std::vector<std::string>& params) override
21555cb1dd27SAsmitha Karunanithi     {
21565cb1dd27SAsmitha Karunanithi         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
21575cb1dd27SAsmitha Karunanithi 
21585cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["@odata.id"] =
21595cb1dd27SAsmitha Karunanithi             "/redfish/v1/Systems/system/LogServices/Dump";
21605cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["@odata.type"] =
21615cb1dd27SAsmitha Karunanithi             "#LogService.v1_1_0.LogService";
21625cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Name"] = "Dump LogService";
21635cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Description"] = "System Dump LogService";
21645cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Id"] = "Dump";
21655cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
21665cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Entries"] = {
21675cb1dd27SAsmitha Karunanithi             {"@odata.id",
21685cb1dd27SAsmitha Karunanithi              "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
21695cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Actions"] = {
21705cb1dd27SAsmitha Karunanithi             {"#LogService.ClearLog",
21715cb1dd27SAsmitha Karunanithi              {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
21725cb1dd27SAsmitha Karunanithi                          "LogService.ClearLog"}}},
21735cb1dd27SAsmitha Karunanithi             {"Oem",
21745cb1dd27SAsmitha Karunanithi              {{"#OemLogService.CollectDiagnosticData",
21755cb1dd27SAsmitha Karunanithi                {{"target",
21765cb1dd27SAsmitha Karunanithi                  "/redfish/v1/Systems/system/LogServices/Dump/Actions/Oem/"
21775cb1dd27SAsmitha Karunanithi                  "OemLogService.CollectDiagnosticData"}}}}}};
21785cb1dd27SAsmitha Karunanithi     }
21795cb1dd27SAsmitha Karunanithi };
21805cb1dd27SAsmitha Karunanithi 
21815cb1dd27SAsmitha Karunanithi class SystemDumpEntryCollection : public Node
21825cb1dd27SAsmitha Karunanithi {
21835cb1dd27SAsmitha Karunanithi   public:
21845cb1dd27SAsmitha Karunanithi     template <typename CrowApp>
21855cb1dd27SAsmitha Karunanithi     SystemDumpEntryCollection(CrowApp& app) :
21865cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/")
21875cb1dd27SAsmitha Karunanithi     {
21885cb1dd27SAsmitha Karunanithi         entityPrivileges = {
21895cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
21905cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
21915cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
21925cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
21935cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
21945cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
21955cb1dd27SAsmitha Karunanithi     }
21965cb1dd27SAsmitha Karunanithi 
21975cb1dd27SAsmitha Karunanithi   private:
21985cb1dd27SAsmitha Karunanithi     /**
21995cb1dd27SAsmitha Karunanithi      * Functions triggers appropriate requests on DBus
22005cb1dd27SAsmitha Karunanithi      */
22015cb1dd27SAsmitha Karunanithi     void doGet(crow::Response& res, const crow::Request& req,
22025cb1dd27SAsmitha Karunanithi                const std::vector<std::string>& params) override
22035cb1dd27SAsmitha Karunanithi     {
22045cb1dd27SAsmitha Karunanithi         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
22055cb1dd27SAsmitha Karunanithi 
22065cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["@odata.type"] =
22075cb1dd27SAsmitha Karunanithi             "#LogEntryCollection.LogEntryCollection";
22085cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["@odata.id"] =
22095cb1dd27SAsmitha Karunanithi             "/redfish/v1/Systems/system/LogServices/Dump/Entries";
22105cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Name"] = "System Dump Entries";
22115cb1dd27SAsmitha Karunanithi         asyncResp->res.jsonValue["Description"] =
22125cb1dd27SAsmitha Karunanithi             "Collection of System Dump Entries";
22135cb1dd27SAsmitha Karunanithi 
22145cb1dd27SAsmitha Karunanithi         getDumpEntryCollection(asyncResp, "System");
22155cb1dd27SAsmitha Karunanithi     }
22165cb1dd27SAsmitha Karunanithi };
22175cb1dd27SAsmitha Karunanithi 
22185cb1dd27SAsmitha Karunanithi class SystemDumpEntry : public Node
22195cb1dd27SAsmitha Karunanithi {
22205cb1dd27SAsmitha Karunanithi   public:
22215cb1dd27SAsmitha Karunanithi     SystemDumpEntry(CrowApp& app) :
22225cb1dd27SAsmitha Karunanithi         Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/",
22235cb1dd27SAsmitha Karunanithi              std::string())
22245cb1dd27SAsmitha Karunanithi     {
22255cb1dd27SAsmitha Karunanithi         entityPrivileges = {
22265cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
22275cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
22285cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
22295cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
22305cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
22315cb1dd27SAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
22325cb1dd27SAsmitha Karunanithi     }
22335cb1dd27SAsmitha Karunanithi 
22345cb1dd27SAsmitha Karunanithi   private:
22355cb1dd27SAsmitha Karunanithi     void doGet(crow::Response& res, const crow::Request& req,
22365cb1dd27SAsmitha Karunanithi                const std::vector<std::string>& params) override
22375cb1dd27SAsmitha Karunanithi     {
22385cb1dd27SAsmitha Karunanithi         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
22395cb1dd27SAsmitha Karunanithi         if (params.size() != 1)
22405cb1dd27SAsmitha Karunanithi         {
2241c9bb6861Sraviteja-b             messages::internalError(asyncResp->res);
2242c9bb6861Sraviteja-b             return;
2243c9bb6861Sraviteja-b         }
22445cb1dd27SAsmitha Karunanithi         getDumpEntryById(asyncResp, params[0], "System");
22455cb1dd27SAsmitha Karunanithi     }
2246c9bb6861Sraviteja-b 
22475cb1dd27SAsmitha Karunanithi     void doDelete(crow::Response& res, const crow::Request& req,
22485cb1dd27SAsmitha Karunanithi                   const std::vector<std::string>& params) override
2249c9bb6861Sraviteja-b     {
22505cb1dd27SAsmitha Karunanithi         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
22515cb1dd27SAsmitha Karunanithi         if (params.size() != 1)
2252c9bb6861Sraviteja-b         {
22535cb1dd27SAsmitha Karunanithi             messages::internalError(asyncResp->res);
2254c9bb6861Sraviteja-b             return;
2255c9bb6861Sraviteja-b         }
22565cb1dd27SAsmitha Karunanithi         deleteDumpEntry(asyncResp->res, params[0]);
2257c9bb6861Sraviteja-b     }
2258c9bb6861Sraviteja-b };
2259c9bb6861Sraviteja-b 
2260*a43be80fSAsmitha Karunanithi class SystemDumpCreate : public Node
2261*a43be80fSAsmitha Karunanithi {
2262*a43be80fSAsmitha Karunanithi   public:
2263*a43be80fSAsmitha Karunanithi     SystemDumpCreate(CrowApp& app) :
2264*a43be80fSAsmitha Karunanithi         Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
2265*a43be80fSAsmitha Karunanithi                   "Actions/Oem/"
2266*a43be80fSAsmitha Karunanithi                   "OemLogService.CollectDiagnosticData/")
2267*a43be80fSAsmitha Karunanithi     {
2268*a43be80fSAsmitha Karunanithi         entityPrivileges = {
2269*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::get, {{"Login"}}},
2270*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::head, {{"Login"}}},
2271*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2272*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2273*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2274*a43be80fSAsmitha Karunanithi             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2275*a43be80fSAsmitha Karunanithi     }
2276*a43be80fSAsmitha Karunanithi 
2277*a43be80fSAsmitha Karunanithi   private:
2278*a43be80fSAsmitha Karunanithi     void doPost(crow::Response& res, const crow::Request& req,
2279*a43be80fSAsmitha Karunanithi                 const std::vector<std::string>& params) override
2280*a43be80fSAsmitha Karunanithi     {
2281*a43be80fSAsmitha Karunanithi         createDump(res, req, "System");
2282*a43be80fSAsmitha Karunanithi     }
2283*a43be80fSAsmitha Karunanithi };
2284*a43be80fSAsmitha Karunanithi 
22850657843aSraviteja-b class SystemDumpEntryDownload : public Node
22860657843aSraviteja-b {
22870657843aSraviteja-b   public:
22880657843aSraviteja-b     SystemDumpEntryDownload(CrowApp& app) :
22890657843aSraviteja-b         Node(app,
22900657843aSraviteja-b              "/redfish/v1/Systems/system/LogServices/System/Entries/<str>/"
22910657843aSraviteja-b              "Actions/"
22920657843aSraviteja-b              "LogEntry.DownloadLog/",
22930657843aSraviteja-b              std::string())
22940657843aSraviteja-b     {
22950657843aSraviteja-b         entityPrivileges = {
22960657843aSraviteja-b             {boost::beast::http::verb::get, {{"Login"}}},
22970657843aSraviteja-b             {boost::beast::http::verb::head, {{"Login"}}},
22980657843aSraviteja-b             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
22990657843aSraviteja-b     }
23000657843aSraviteja-b 
23010657843aSraviteja-b   private:
23020657843aSraviteja-b     void doPost(crow::Response& res, const crow::Request& req,
23030657843aSraviteja-b                 const std::vector<std::string>& params) override
23040657843aSraviteja-b     {
23050657843aSraviteja-b         if (params.size() != 1)
23060657843aSraviteja-b         {
23070657843aSraviteja-b             messages::internalError(res);
23080657843aSraviteja-b             return;
23090657843aSraviteja-b         }
23100657843aSraviteja-b         const std::string& entryID = params[0];
23110657843aSraviteja-b         crow::obmc_dump::handleDumpOffloadUrl(req, res, entryID);
23120657843aSraviteja-b     }
23130657843aSraviteja-b };
23140657843aSraviteja-b 
2315013487e5Sraviteja-b class SystemDumpClear : public Node
2316013487e5Sraviteja-b {
2317013487e5Sraviteja-b   public:
2318013487e5Sraviteja-b     SystemDumpClear(CrowApp& app) :
2319013487e5Sraviteja-b         Node(app, "/redfish/v1/Systems/system/LogServices/System/"
2320013487e5Sraviteja-b                   "Actions/"
2321013487e5Sraviteja-b                   "LogService.ClearLog/")
2322013487e5Sraviteja-b     {
2323013487e5Sraviteja-b         entityPrivileges = {
2324013487e5Sraviteja-b             {boost::beast::http::verb::get, {{"Login"}}},
2325013487e5Sraviteja-b             {boost::beast::http::verb::head, {{"Login"}}},
2326013487e5Sraviteja-b             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2327013487e5Sraviteja-b     }
2328013487e5Sraviteja-b 
2329013487e5Sraviteja-b   private:
2330013487e5Sraviteja-b     void doPost(crow::Response& res, const crow::Request& req,
2331013487e5Sraviteja-b                 const std::vector<std::string>& params) override
2332013487e5Sraviteja-b     {
2333013487e5Sraviteja-b 
2334013487e5Sraviteja-b         auto asyncResp = std::make_shared<AsyncResp>(res);
2335013487e5Sraviteja-b         crow::connections::systemBus->async_method_call(
2336013487e5Sraviteja-b             [asyncResp](const boost::system::error_code ec,
2337013487e5Sraviteja-b                         const std::vector<std::string>& dumpList) {
2338013487e5Sraviteja-b                 if (ec)
2339013487e5Sraviteja-b                 {
2340013487e5Sraviteja-b                     messages::internalError(asyncResp->res);
2341013487e5Sraviteja-b                     return;
2342013487e5Sraviteja-b                 }
2343013487e5Sraviteja-b 
2344013487e5Sraviteja-b                 for (const std::string& objectPath : dumpList)
2345013487e5Sraviteja-b                 {
2346013487e5Sraviteja-b                     std::size_t pos = objectPath.rfind("/");
2347013487e5Sraviteja-b                     if (pos != std::string::npos)
2348013487e5Sraviteja-b                     {
2349013487e5Sraviteja-b                         std::string logID = objectPath.substr(pos + 1);
23505cb1dd27SAsmitha Karunanithi                         deleteDumpEntry(asyncResp->res, logID);
2351013487e5Sraviteja-b                     }
2352013487e5Sraviteja-b                 }
2353013487e5Sraviteja-b             },
2354013487e5Sraviteja-b             "xyz.openbmc_project.ObjectMapper",
2355013487e5Sraviteja-b             "/xyz/openbmc_project/object_mapper",
2356013487e5Sraviteja-b             "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
2357013487e5Sraviteja-b             "/xyz/openbmc_project/dump", 0,
2358013487e5Sraviteja-b             std::array<const char*, 1>{
2359013487e5Sraviteja-b                 "xyz.openbmc_project.Dump.Entry.System"});
2360013487e5Sraviteja-b     }
2361013487e5Sraviteja-b };
2362013487e5Sraviteja-b 
2363424c4176SJason M. Bills class CrashdumpService : public Node
2364e1f26343SJason M. Bills {
2365e1f26343SJason M. Bills   public:
2366e1f26343SJason M. Bills     template <typename CrowApp>
2367424c4176SJason M. Bills     CrashdumpService(CrowApp& app) :
2368424c4176SJason M. Bills         Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/")
23691da66f75SEd Tanous     {
23703946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
23713946028dSAppaRao Puli         // method for security reasons.
23721da66f75SEd Tanous         entityPrivileges = {
23733946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
23743946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2375e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2376e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2377e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2378e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
23791da66f75SEd Tanous     }
23801da66f75SEd Tanous 
23811da66f75SEd Tanous   private:
23821da66f75SEd Tanous     /**
23831da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
23841da66f75SEd Tanous      */
23851da66f75SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
23861da66f75SEd Tanous                const std::vector<std::string>& params) override
23871da66f75SEd Tanous     {
2388e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
23891da66f75SEd Tanous         // Copy over the static data to include the entries added by SubRoute
23900f74e643SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
2391424c4176SJason M. Bills             "/redfish/v1/Systems/system/LogServices/Crashdump";
2392e1f26343SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
2393e1f26343SJason M. Bills             "#LogService.v1_1_0.LogService";
23944f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
23954f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
23964f50ae4bSGunnar Mills         asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
2397e1f26343SJason M. Bills         asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2398e1f26343SJason M. Bills         asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
2399cd50aa42SJason M. Bills         asyncResp->res.jsonValue["Entries"] = {
2400cd50aa42SJason M. Bills             {"@odata.id",
2401424c4176SJason M. Bills              "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}};
2402e1f26343SJason M. Bills         asyncResp->res.jsonValue["Actions"] = {
24035b61b5e8SJason M. Bills             {"#LogService.ClearLog",
24045b61b5e8SJason M. Bills              {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
24055b61b5e8SJason M. Bills                          "Actions/LogService.ClearLog"}}},
24061da66f75SEd Tanous             {"Oem",
2407424c4176SJason M. Bills              {{"#Crashdump.OnDemand",
2408424c4176SJason M. Bills                {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
24096eda7685SKenny L. Ku                            "Actions/Oem/Crashdump.OnDemand"}}},
24106eda7685SKenny L. Ku               {"#Crashdump.Telemetry",
24116eda7685SKenny L. Ku                {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
24126eda7685SKenny L. Ku                            "Actions/Oem/Crashdump.Telemetry"}}}}}};
24131da66f75SEd Tanous 
24141da66f75SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI
2415e1f26343SJason M. Bills         asyncResp->res.jsonValue["Actions"]["Oem"].push_back(
2416424c4176SJason M. Bills             {"#Crashdump.SendRawPeci",
241708a4e4b5SAnthony Wilson              {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2418424c4176SJason M. Bills                          "Actions/Oem/Crashdump.SendRawPeci"}}});
24191da66f75SEd Tanous #endif
24201da66f75SEd Tanous     }
24211da66f75SEd Tanous };
24221da66f75SEd Tanous 
24235b61b5e8SJason M. Bills class CrashdumpClear : public Node
24245b61b5e8SJason M. Bills {
24255b61b5e8SJason M. Bills   public:
24265b61b5e8SJason M. Bills     CrashdumpClear(CrowApp& app) :
24275b61b5e8SJason M. Bills         Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
24285b61b5e8SJason M. Bills                   "LogService.ClearLog/")
24295b61b5e8SJason M. Bills     {
24303946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
24313946028dSAppaRao Puli         // method for security reasons.
24325b61b5e8SJason M. Bills         entityPrivileges = {
24333946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
24343946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
24355b61b5e8SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
24365b61b5e8SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
24375b61b5e8SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
24385b61b5e8SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
24395b61b5e8SJason M. Bills     }
24405b61b5e8SJason M. Bills 
24415b61b5e8SJason M. Bills   private:
24425b61b5e8SJason M. Bills     void doPost(crow::Response& res, const crow::Request& req,
24435b61b5e8SJason M. Bills                 const std::vector<std::string>& params) override
24445b61b5e8SJason M. Bills     {
24455b61b5e8SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
24465b61b5e8SJason M. Bills 
24475b61b5e8SJason M. Bills         crow::connections::systemBus->async_method_call(
24485b61b5e8SJason M. Bills             [asyncResp](const boost::system::error_code ec,
24495b61b5e8SJason M. Bills                         const std::string& resp) {
24505b61b5e8SJason M. Bills                 if (ec)
24515b61b5e8SJason M. Bills                 {
24525b61b5e8SJason M. Bills                     messages::internalError(asyncResp->res);
24535b61b5e8SJason M. Bills                     return;
24545b61b5e8SJason M. Bills                 }
24555b61b5e8SJason M. Bills                 messages::success(asyncResp->res);
24565b61b5e8SJason M. Bills             },
24575b61b5e8SJason M. Bills             crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
24585b61b5e8SJason M. Bills     }
24595b61b5e8SJason M. Bills };
24605b61b5e8SJason M. Bills 
2461e855dd28SJason M. Bills static void logCrashdumpEntry(std::shared_ptr<AsyncResp> asyncResp,
2462e855dd28SJason M. Bills                               const std::string& logID,
2463e855dd28SJason M. Bills                               nlohmann::json& logEntryJson)
2464e855dd28SJason M. Bills {
2465043a0536SJohnathan Mantey     auto getStoredLogCallback =
2466043a0536SJohnathan Mantey         [asyncResp, logID, &logEntryJson](
2467e855dd28SJason M. Bills             const boost::system::error_code ec,
2468043a0536SJohnathan Mantey             const std::vector<std::pair<std::string, VariantType>>& params) {
2469e855dd28SJason M. Bills             if (ec)
2470e855dd28SJason M. Bills             {
2471e855dd28SJason M. Bills                 BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
24721ddcf01aSJason M. Bills                 if (ec.value() ==
24731ddcf01aSJason M. Bills                     boost::system::linux_error::bad_request_descriptor)
24741ddcf01aSJason M. Bills                 {
2475043a0536SJohnathan Mantey                     messages::resourceNotFound(asyncResp->res, "LogEntry",
2476043a0536SJohnathan Mantey                                                logID);
24771ddcf01aSJason M. Bills                 }
24781ddcf01aSJason M. Bills                 else
24791ddcf01aSJason M. Bills                 {
2480e855dd28SJason M. Bills                     messages::internalError(asyncResp->res);
24811ddcf01aSJason M. Bills                 }
2482e855dd28SJason M. Bills                 return;
2483e855dd28SJason M. Bills             }
2484043a0536SJohnathan Mantey 
2485043a0536SJohnathan Mantey             std::string timestamp{};
2486043a0536SJohnathan Mantey             std::string filename{};
2487043a0536SJohnathan Mantey             std::string logfile{};
2488043a0536SJohnathan Mantey             ParseCrashdumpParameters(params, filename, timestamp, logfile);
2489043a0536SJohnathan Mantey 
2490043a0536SJohnathan Mantey             if (filename.empty() || timestamp.empty())
2491e855dd28SJason M. Bills             {
2492043a0536SJohnathan Mantey                 messages::resourceMissingAtURI(asyncResp->res, logID);
2493e855dd28SJason M. Bills                 return;
2494e855dd28SJason M. Bills             }
2495e855dd28SJason M. Bills 
2496043a0536SJohnathan Mantey             std::string crashdumpURI =
2497e855dd28SJason M. Bills                 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
2498043a0536SJohnathan Mantey                 logID + "/" + filename;
2499043a0536SJohnathan Mantey             logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
2500043a0536SJohnathan Mantey                             {"@odata.id", "/redfish/v1/Systems/system/"
2501043a0536SJohnathan Mantey                                           "LogServices/Crashdump/Entries/" +
2502e855dd28SJason M. Bills                                               logID},
2503e855dd28SJason M. Bills                             {"Name", "CPU Crashdump"},
2504e855dd28SJason M. Bills                             {"Id", logID},
2505e855dd28SJason M. Bills                             {"EntryType", "Oem"},
2506e855dd28SJason M. Bills                             {"OemRecordFormat", "Crashdump URI"},
2507043a0536SJohnathan Mantey                             {"Message", std::move(crashdumpURI)},
2508043a0536SJohnathan Mantey                             {"Created", std::move(timestamp)}};
2509e855dd28SJason M. Bills         };
2510e855dd28SJason M. Bills     crow::connections::systemBus->async_method_call(
25115b61b5e8SJason M. Bills         std::move(getStoredLogCallback), crashdumpObject,
25125b61b5e8SJason M. Bills         crashdumpPath + std::string("/") + logID,
2513043a0536SJohnathan Mantey         "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
2514e855dd28SJason M. Bills }
2515e855dd28SJason M. Bills 
2516424c4176SJason M. Bills class CrashdumpEntryCollection : public Node
25171da66f75SEd Tanous {
25181da66f75SEd Tanous   public:
25191da66f75SEd Tanous     template <typename CrowApp>
2520424c4176SJason M. Bills     CrashdumpEntryCollection(CrowApp& app) :
2521424c4176SJason M. Bills         Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/")
25221da66f75SEd Tanous     {
25233946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
25243946028dSAppaRao Puli         // method for security reasons.
25251da66f75SEd Tanous         entityPrivileges = {
25263946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
25273946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2528e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2529e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2530e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2531e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
25321da66f75SEd Tanous     }
25331da66f75SEd Tanous 
25341da66f75SEd Tanous   private:
25351da66f75SEd Tanous     /**
25361da66f75SEd Tanous      * Functions triggers appropriate requests on DBus
25371da66f75SEd Tanous      */
25381da66f75SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
25391da66f75SEd Tanous                const std::vector<std::string>& params) override
25401da66f75SEd Tanous     {
2541e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
25421da66f75SEd Tanous         // Collections don't include the static data added by SubRoute because
25431da66f75SEd Tanous         // it has a duplicate entry for members
2544e1f26343SJason M. Bills         auto getLogEntriesCallback = [asyncResp](
2545e1f26343SJason M. Bills                                          const boost::system::error_code ec,
25461da66f75SEd Tanous                                          const std::vector<std::string>& resp) {
25471da66f75SEd Tanous             if (ec)
25481da66f75SEd Tanous             {
25491da66f75SEd Tanous                 if (ec.value() !=
25501da66f75SEd Tanous                     boost::system::errc::no_such_file_or_directory)
25511da66f75SEd Tanous                 {
25521da66f75SEd Tanous                     BMCWEB_LOG_DEBUG << "failed to get entries ec: "
25531da66f75SEd Tanous                                      << ec.message();
2554f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
25551da66f75SEd Tanous                     return;
25561da66f75SEd Tanous                 }
25571da66f75SEd Tanous             }
2558e1f26343SJason M. Bills             asyncResp->res.jsonValue["@odata.type"] =
25591da66f75SEd Tanous                 "#LogEntryCollection.LogEntryCollection";
25600f74e643SEd Tanous             asyncResp->res.jsonValue["@odata.id"] =
2561424c4176SJason M. Bills                 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
2562424c4176SJason M. Bills             asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
2563e1f26343SJason M. Bills             asyncResp->res.jsonValue["Description"] =
2564424c4176SJason M. Bills                 "Collection of Crashdump Entries";
2565e1f26343SJason M. Bills             nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
2566e1f26343SJason M. Bills             logEntryArray = nlohmann::json::array();
2567e855dd28SJason M. Bills             std::vector<std::string> logIDs;
2568e855dd28SJason M. Bills             // Get the list of log entries and build up an empty array big
2569e855dd28SJason M. Bills             // enough to hold them
25701da66f75SEd Tanous             for (const std::string& objpath : resp)
25711da66f75SEd Tanous             {
2572e855dd28SJason M. Bills                 // Get the log ID
25734ed77cd5SEd Tanous                 std::size_t lastPos = objpath.rfind("/");
2574e855dd28SJason M. Bills                 if (lastPos == std::string::npos)
25751da66f75SEd Tanous                 {
2576e855dd28SJason M. Bills                     continue;
25771da66f75SEd Tanous                 }
2578e855dd28SJason M. Bills                 logIDs.emplace_back(objpath.substr(lastPos + 1));
2579e855dd28SJason M. Bills 
2580e855dd28SJason M. Bills                 // Add a space for the log entry to the array
2581e855dd28SJason M. Bills                 logEntryArray.push_back({});
2582e855dd28SJason M. Bills             }
2583e855dd28SJason M. Bills             // Now go through and set up async calls to fill in the entries
2584e855dd28SJason M. Bills             size_t index = 0;
2585e855dd28SJason M. Bills             for (const std::string& logID : logIDs)
2586e855dd28SJason M. Bills             {
2587e855dd28SJason M. Bills                 // Add the log entry to the array
2588e855dd28SJason M. Bills                 logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]);
25891da66f75SEd Tanous             }
2590e1f26343SJason M. Bills             asyncResp->res.jsonValue["Members@odata.count"] =
2591e1f26343SJason M. Bills                 logEntryArray.size();
25921da66f75SEd Tanous         };
25931da66f75SEd Tanous         crow::connections::systemBus->async_method_call(
25941da66f75SEd Tanous             std::move(getLogEntriesCallback),
25951da66f75SEd Tanous             "xyz.openbmc_project.ObjectMapper",
25961da66f75SEd Tanous             "/xyz/openbmc_project/object_mapper",
25971da66f75SEd Tanous             "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0,
25985b61b5e8SJason M. Bills             std::array<const char*, 1>{crashdumpInterface});
25991da66f75SEd Tanous     }
26001da66f75SEd Tanous };
26011da66f75SEd Tanous 
2602424c4176SJason M. Bills class CrashdumpEntry : public Node
26031da66f75SEd Tanous {
26041da66f75SEd Tanous   public:
2605424c4176SJason M. Bills     CrashdumpEntry(CrowApp& app) :
2606d53dd41fSJason M. Bills         Node(app,
2607424c4176SJason M. Bills              "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/",
26081da66f75SEd Tanous              std::string())
26091da66f75SEd Tanous     {
26103946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
26113946028dSAppaRao Puli         // method for security reasons.
26121da66f75SEd Tanous         entityPrivileges = {
26133946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
26143946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2615e1f26343SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2616e1f26343SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2617e1f26343SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2618e1f26343SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
26191da66f75SEd Tanous     }
26201da66f75SEd Tanous 
26211da66f75SEd Tanous   private:
26221da66f75SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
26231da66f75SEd Tanous                const std::vector<std::string>& params) override
26241da66f75SEd Tanous     {
2625e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
26261da66f75SEd Tanous         if (params.size() != 1)
26271da66f75SEd Tanous         {
2628f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
26291da66f75SEd Tanous             return;
26301da66f75SEd Tanous         }
2631e855dd28SJason M. Bills         const std::string& logID = params[0];
2632e855dd28SJason M. Bills         logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2633e855dd28SJason M. Bills     }
2634e855dd28SJason M. Bills };
2635e855dd28SJason M. Bills 
2636e855dd28SJason M. Bills class CrashdumpFile : public Node
2637e855dd28SJason M. Bills {
2638e855dd28SJason M. Bills   public:
2639e855dd28SJason M. Bills     CrashdumpFile(CrowApp& app) :
2640e855dd28SJason M. Bills         Node(app,
2641e855dd28SJason M. Bills              "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/"
2642e855dd28SJason M. Bills              "<str>/",
2643e855dd28SJason M. Bills              std::string(), std::string())
2644e855dd28SJason M. Bills     {
26453946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
26463946028dSAppaRao Puli         // method for security reasons.
2647e855dd28SJason M. Bills         entityPrivileges = {
26483946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
26493946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2650e855dd28SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2651e855dd28SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2652e855dd28SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2653e855dd28SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2654e855dd28SJason M. Bills     }
2655e855dd28SJason M. Bills 
2656e855dd28SJason M. Bills   private:
2657e855dd28SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
2658e855dd28SJason M. Bills                const std::vector<std::string>& params) override
2659e855dd28SJason M. Bills     {
2660e855dd28SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2661e855dd28SJason M. Bills         if (params.size() != 2)
2662e855dd28SJason M. Bills         {
2663e855dd28SJason M. Bills             messages::internalError(asyncResp->res);
2664e855dd28SJason M. Bills             return;
2665e855dd28SJason M. Bills         }
2666e855dd28SJason M. Bills         const std::string& logID = params[0];
2667e855dd28SJason M. Bills         const std::string& fileName = params[1];
2668e855dd28SJason M. Bills 
2669043a0536SJohnathan Mantey         auto getStoredLogCallback =
2670043a0536SJohnathan Mantey             [asyncResp, logID, fileName](
2671abf2add6SEd Tanous                 const boost::system::error_code ec,
2672043a0536SJohnathan Mantey                 const std::vector<std::pair<std::string, VariantType>>& resp) {
26731da66f75SEd Tanous                 if (ec)
26741da66f75SEd Tanous                 {
2675043a0536SJohnathan Mantey                     BMCWEB_LOG_DEBUG << "failed to get log ec: "
2676043a0536SJohnathan Mantey                                      << ec.message();
2677f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
26781da66f75SEd Tanous                     return;
26791da66f75SEd Tanous                 }
2680e855dd28SJason M. Bills 
2681043a0536SJohnathan Mantey                 std::string dbusFilename{};
2682043a0536SJohnathan Mantey                 std::string dbusTimestamp{};
2683043a0536SJohnathan Mantey                 std::string dbusFilepath{};
2684043a0536SJohnathan Mantey 
2685043a0536SJohnathan Mantey                 ParseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
2686043a0536SJohnathan Mantey                                          dbusFilepath);
2687043a0536SJohnathan Mantey 
2688043a0536SJohnathan Mantey                 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2689043a0536SJohnathan Mantey                     dbusFilepath.empty())
26901da66f75SEd Tanous                 {
2691e855dd28SJason M. Bills                     messages::resourceMissingAtURI(asyncResp->res, fileName);
26921da66f75SEd Tanous                     return;
26931da66f75SEd Tanous                 }
2694e855dd28SJason M. Bills 
2695043a0536SJohnathan Mantey                 // Verify the file name parameter is correct
2696043a0536SJohnathan Mantey                 if (fileName != dbusFilename)
2697043a0536SJohnathan Mantey                 {
2698043a0536SJohnathan Mantey                     messages::resourceMissingAtURI(asyncResp->res, fileName);
2699043a0536SJohnathan Mantey                     return;
2700043a0536SJohnathan Mantey                 }
2701043a0536SJohnathan Mantey 
2702043a0536SJohnathan Mantey                 if (!std::filesystem::exists(dbusFilepath))
2703043a0536SJohnathan Mantey                 {
2704043a0536SJohnathan Mantey                     messages::resourceMissingAtURI(asyncResp->res, fileName);
2705043a0536SJohnathan Mantey                     return;
2706043a0536SJohnathan Mantey                 }
2707043a0536SJohnathan Mantey                 std::ifstream ifs(dbusFilepath, std::ios::in |
2708043a0536SJohnathan Mantey                                                     std::ios::binary |
2709043a0536SJohnathan Mantey                                                     std::ios::ate);
2710043a0536SJohnathan Mantey                 std::ifstream::pos_type fileSize = ifs.tellg();
2711043a0536SJohnathan Mantey                 if (fileSize < 0)
2712043a0536SJohnathan Mantey                 {
2713043a0536SJohnathan Mantey                     messages::generalError(asyncResp->res);
2714043a0536SJohnathan Mantey                     return;
2715043a0536SJohnathan Mantey                 }
2716043a0536SJohnathan Mantey                 ifs.seekg(0, std::ios::beg);
2717043a0536SJohnathan Mantey 
2718043a0536SJohnathan Mantey                 auto crashData = std::make_unique<char[]>(
2719043a0536SJohnathan Mantey                     static_cast<unsigned int>(fileSize));
2720043a0536SJohnathan Mantey 
2721043a0536SJohnathan Mantey                 ifs.read(crashData.get(), static_cast<int>(fileSize));
2722043a0536SJohnathan Mantey 
2723043a0536SJohnathan Mantey                 // The cast to std::string is intentional in order to use the
2724043a0536SJohnathan Mantey                 // assign() that applies move mechanics
2725043a0536SJohnathan Mantey                 asyncResp->res.body().assign(
2726043a0536SJohnathan Mantey                     static_cast<std::string>(crashData.get()));
2727043a0536SJohnathan Mantey 
2728043a0536SJohnathan Mantey                 // Configure this to be a file download when accessed from
2729043a0536SJohnathan Mantey                 // a browser
2730e855dd28SJason M. Bills                 asyncResp->res.addHeader("Content-Disposition", "attachment");
27311da66f75SEd Tanous             };
27321da66f75SEd Tanous         crow::connections::systemBus->async_method_call(
27335b61b5e8SJason M. Bills             std::move(getStoredLogCallback), crashdumpObject,
27345b61b5e8SJason M. Bills             crashdumpPath + std::string("/") + logID,
2735043a0536SJohnathan Mantey             "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
27361da66f75SEd Tanous     }
27371da66f75SEd Tanous };
27381da66f75SEd Tanous 
2739424c4176SJason M. Bills class OnDemandCrashdump : public Node
27401da66f75SEd Tanous {
27411da66f75SEd Tanous   public:
2742424c4176SJason M. Bills     OnDemandCrashdump(CrowApp& app) :
2743424c4176SJason M. Bills         Node(app,
2744424c4176SJason M. Bills              "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2745424c4176SJason M. Bills              "Crashdump.OnDemand/")
27461da66f75SEd Tanous     {
27473946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
27483946028dSAppaRao Puli         // method for security reasons.
27491da66f75SEd Tanous         entityPrivileges = {
27503946028dSAppaRao Puli             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
27513946028dSAppaRao Puli             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
27523946028dSAppaRao Puli             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
27533946028dSAppaRao Puli             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
27543946028dSAppaRao Puli             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
27553946028dSAppaRao Puli             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
27561da66f75SEd Tanous     }
27571da66f75SEd Tanous 
27581da66f75SEd Tanous   private:
27591da66f75SEd Tanous     void doPost(crow::Response& res, const crow::Request& req,
27601da66f75SEd Tanous                 const std::vector<std::string>& params) override
27611da66f75SEd Tanous     {
2762e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
27631da66f75SEd Tanous 
2764fe306728SJames Feist         auto generateonDemandLogCallback = [asyncResp,
2765fe306728SJames Feist                                             req](const boost::system::error_code
276646229577SJames Feist                                                      ec,
27671da66f75SEd Tanous                                                  const std::string& resp) {
27681da66f75SEd Tanous             if (ec)
27691da66f75SEd Tanous             {
277046229577SJames Feist                 if (ec.value() == boost::system::errc::operation_not_supported)
27711da66f75SEd Tanous                 {
2772f12894f8SJason M. Bills                     messages::resourceInStandby(asyncResp->res);
27731da66f75SEd Tanous                 }
27744363d3b2SJason M. Bills                 else if (ec.value() ==
27754363d3b2SJason M. Bills                          boost::system::errc::device_or_resource_busy)
27764363d3b2SJason M. Bills                 {
27774363d3b2SJason M. Bills                     messages::serviceTemporarilyUnavailable(asyncResp->res,
27784363d3b2SJason M. Bills                                                             "60");
27794363d3b2SJason M. Bills                 }
27801da66f75SEd Tanous                 else
27811da66f75SEd Tanous                 {
2782f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
27831da66f75SEd Tanous                 }
27841da66f75SEd Tanous                 return;
27851da66f75SEd Tanous             }
278646229577SJames Feist             std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
278766afe4faSJames Feist                 [](boost::system::error_code err, sdbusplus::message::message&,
278866afe4faSJames Feist                    const std::shared_ptr<task::TaskData>& taskData) {
278966afe4faSJames Feist                     if (!err)
279066afe4faSJames Feist                     {
2791e5d5006bSJames Feist                         taskData->messages.emplace_back(
2792e5d5006bSJames Feist                             messages::taskCompletedOK(
2793e5d5006bSJames Feist                                 std::to_string(taskData->index)));
2794831d6b09SJames Feist                         taskData->state = "Completed";
279566afe4faSJames Feist                     }
279632898ceaSJames Feist                     return task::completed;
279766afe4faSJames Feist                 },
279846229577SJames Feist                 "type='signal',interface='org.freedesktop.DBus.Properties',"
279946229577SJames Feist                 "member='PropertiesChanged',arg0namespace='com.intel."
280046229577SJames Feist                 "crashdump'");
280146229577SJames Feist             task->startTimer(std::chrono::minutes(5));
280246229577SJames Feist             task->populateResp(asyncResp->res);
2803fe306728SJames Feist             task->payload.emplace(req);
28041da66f75SEd Tanous         };
28051da66f75SEd Tanous         crow::connections::systemBus->async_method_call(
28065b61b5e8SJason M. Bills             std::move(generateonDemandLogCallback), crashdumpObject,
28075b61b5e8SJason M. Bills             crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog");
28081da66f75SEd Tanous     }
28091da66f75SEd Tanous };
28101da66f75SEd Tanous 
28116eda7685SKenny L. Ku class TelemetryCrashdump : public Node
28126eda7685SKenny L. Ku {
28136eda7685SKenny L. Ku   public:
28146eda7685SKenny L. Ku     TelemetryCrashdump(CrowApp& app) :
28156eda7685SKenny L. Ku         Node(app,
28166eda7685SKenny L. Ku              "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
28176eda7685SKenny L. Ku              "Crashdump.Telemetry/")
28186eda7685SKenny L. Ku     {
28196eda7685SKenny L. Ku         // Note: Deviated from redfish privilege registry for GET & HEAD
28206eda7685SKenny L. Ku         // method for security reasons.
28216eda7685SKenny L. Ku         entityPrivileges = {
28226eda7685SKenny L. Ku             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
28236eda7685SKenny L. Ku             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
28246eda7685SKenny L. Ku             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
28256eda7685SKenny L. Ku             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
28266eda7685SKenny L. Ku             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
28276eda7685SKenny L. Ku             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
28286eda7685SKenny L. Ku     }
28296eda7685SKenny L. Ku 
28306eda7685SKenny L. Ku   private:
28316eda7685SKenny L. Ku     void doPost(crow::Response& res, const crow::Request& req,
28326eda7685SKenny L. Ku                 const std::vector<std::string>& params) override
28336eda7685SKenny L. Ku     {
28346eda7685SKenny L. Ku         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
28356eda7685SKenny L. Ku 
28366eda7685SKenny L. Ku         auto generateTelemetryLogCallback = [asyncResp, req](
28376eda7685SKenny L. Ku                                                 const boost::system::error_code
28386eda7685SKenny L. Ku                                                     ec,
28396eda7685SKenny L. Ku                                                 const std::string& resp) {
28406eda7685SKenny L. Ku             if (ec)
28416eda7685SKenny L. Ku             {
28426eda7685SKenny L. Ku                 if (ec.value() == boost::system::errc::operation_not_supported)
28436eda7685SKenny L. Ku                 {
28446eda7685SKenny L. Ku                     messages::resourceInStandby(asyncResp->res);
28456eda7685SKenny L. Ku                 }
28466eda7685SKenny L. Ku                 else if (ec.value() ==
28476eda7685SKenny L. Ku                          boost::system::errc::device_or_resource_busy)
28486eda7685SKenny L. Ku                 {
28496eda7685SKenny L. Ku                     messages::serviceTemporarilyUnavailable(asyncResp->res,
28506eda7685SKenny L. Ku                                                             "60");
28516eda7685SKenny L. Ku                 }
28526eda7685SKenny L. Ku                 else
28536eda7685SKenny L. Ku                 {
28546eda7685SKenny L. Ku                     messages::internalError(asyncResp->res);
28556eda7685SKenny L. Ku                 }
28566eda7685SKenny L. Ku                 return;
28576eda7685SKenny L. Ku             }
28586eda7685SKenny L. Ku             std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
28596eda7685SKenny L. Ku                 [](boost::system::error_code err, sdbusplus::message::message&,
28606eda7685SKenny L. Ku                    const std::shared_ptr<task::TaskData>& taskData) {
28616eda7685SKenny L. Ku                     if (!err)
28626eda7685SKenny L. Ku                     {
28636eda7685SKenny L. Ku                         taskData->messages.emplace_back(
28646eda7685SKenny L. Ku                             messages::taskCompletedOK(
28656eda7685SKenny L. Ku                                 std::to_string(taskData->index)));
28666eda7685SKenny L. Ku                         taskData->state = "Completed";
28676eda7685SKenny L. Ku                     }
28686eda7685SKenny L. Ku                     return task::completed;
28696eda7685SKenny L. Ku                 },
28706eda7685SKenny L. Ku                 "type='signal',interface='org.freedesktop.DBus.Properties',"
28716eda7685SKenny L. Ku                 "member='PropertiesChanged',arg0namespace='com.intel."
28726eda7685SKenny L. Ku                 "crashdump'");
28736eda7685SKenny L. Ku             task->startTimer(std::chrono::minutes(5));
28746eda7685SKenny L. Ku             task->populateResp(asyncResp->res);
28756eda7685SKenny L. Ku             task->payload.emplace(req);
28766eda7685SKenny L. Ku         };
28776eda7685SKenny L. Ku         crow::connections::systemBus->async_method_call(
28786eda7685SKenny L. Ku             std::move(generateTelemetryLogCallback), crashdumpObject,
28796eda7685SKenny L. Ku             crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog");
28806eda7685SKenny L. Ku     }
28816eda7685SKenny L. Ku };
28826eda7685SKenny L. Ku 
2883e1f26343SJason M. Bills class SendRawPECI : public Node
28841da66f75SEd Tanous {
28851da66f75SEd Tanous   public:
2886e1f26343SJason M. Bills     SendRawPECI(CrowApp& app) :
2887424c4176SJason M. Bills         Node(app,
2888424c4176SJason M. Bills              "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2889424c4176SJason M. Bills              "Crashdump.SendRawPeci/")
28901da66f75SEd Tanous     {
28913946028dSAppaRao Puli         // Note: Deviated from redfish privilege registry for GET & HEAD
28923946028dSAppaRao Puli         // method for security reasons.
28931da66f75SEd Tanous         entityPrivileges = {
28941da66f75SEd Tanous             {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
28951da66f75SEd Tanous             {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
28961da66f75SEd Tanous             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
28971da66f75SEd Tanous             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
28981da66f75SEd Tanous             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
28991da66f75SEd Tanous             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
29001da66f75SEd Tanous     }
29011da66f75SEd Tanous 
29021da66f75SEd Tanous   private:
29031da66f75SEd Tanous     void doPost(crow::Response& res, const crow::Request& req,
29041da66f75SEd Tanous                 const std::vector<std::string>& params) override
29051da66f75SEd Tanous     {
2906e1f26343SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
29078724c297SKarthick Sundarrajan         std::vector<std::vector<uint8_t>> peciCommands;
29088724c297SKarthick Sundarrajan 
29098724c297SKarthick Sundarrajan         nlohmann::json reqJson =
29108724c297SKarthick Sundarrajan             nlohmann::json::parse(req.body, nullptr, false);
29118724c297SKarthick Sundarrajan         if (reqJson.find("PECICommands") != reqJson.end())
29128724c297SKarthick Sundarrajan         {
29138724c297SKarthick Sundarrajan             if (!json_util::readJson(req, res, "PECICommands", peciCommands))
29148724c297SKarthick Sundarrajan             {
29158724c297SKarthick Sundarrajan                 return;
29168724c297SKarthick Sundarrajan             }
29178724c297SKarthick Sundarrajan             uint32_t idx = 0;
29188724c297SKarthick Sundarrajan             for (auto const& cmd : peciCommands)
29198724c297SKarthick Sundarrajan             {
29208724c297SKarthick Sundarrajan                 if (cmd.size() < 3)
29218724c297SKarthick Sundarrajan                 {
29228724c297SKarthick Sundarrajan                     std::string s("[");
29238724c297SKarthick Sundarrajan                     for (auto const& val : cmd)
29248724c297SKarthick Sundarrajan                     {
29258724c297SKarthick Sundarrajan                         if (val != *cmd.begin())
29268724c297SKarthick Sundarrajan                         {
29278724c297SKarthick Sundarrajan                             s += ",";
29288724c297SKarthick Sundarrajan                         }
29298724c297SKarthick Sundarrajan                         s += std::to_string(val);
29308724c297SKarthick Sundarrajan                     }
29318724c297SKarthick Sundarrajan                     s += "]";
29328724c297SKarthick Sundarrajan                     messages::actionParameterValueFormatError(
29338724c297SKarthick Sundarrajan                         res, s, "PECICommands[" + std::to_string(idx) + "]",
29348724c297SKarthick Sundarrajan                         "SendRawPeci");
29358724c297SKarthick Sundarrajan                     return;
29368724c297SKarthick Sundarrajan                 }
29378724c297SKarthick Sundarrajan                 idx++;
29388724c297SKarthick Sundarrajan             }
29398724c297SKarthick Sundarrajan         }
29408724c297SKarthick Sundarrajan         else
29418724c297SKarthick Sundarrajan         {
29428724c297SKarthick Sundarrajan             /* This interface is deprecated */
2943b1556427SEd Tanous             uint8_t clientAddress = 0;
2944b1556427SEd Tanous             uint8_t readLength = 0;
29451da66f75SEd Tanous             std::vector<uint8_t> peciCommand;
2946b1556427SEd Tanous             if (!json_util::readJson(req, res, "ClientAddress", clientAddress,
2947b1556427SEd Tanous                                      "ReadLength", readLength, "PECICommand",
2948b1556427SEd Tanous                                      peciCommand))
29491da66f75SEd Tanous             {
29501da66f75SEd Tanous                 return;
29511da66f75SEd Tanous             }
29528724c297SKarthick Sundarrajan             peciCommands.push_back({clientAddress, 0, readLength});
29538724c297SKarthick Sundarrajan             peciCommands[0].insert(peciCommands[0].end(), peciCommand.begin(),
29548724c297SKarthick Sundarrajan                                    peciCommand.end());
29558724c297SKarthick Sundarrajan         }
29561da66f75SEd Tanous         // Callback to return the Raw PECI response
2957e1f26343SJason M. Bills         auto sendRawPECICallback =
2958e1f26343SJason M. Bills             [asyncResp](const boost::system::error_code ec,
29598724c297SKarthick Sundarrajan                         const std::vector<std::vector<uint8_t>>& resp) {
29601da66f75SEd Tanous                 if (ec)
29611da66f75SEd Tanous                 {
29628724c297SKarthick Sundarrajan                     BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: "
29631da66f75SEd Tanous                                      << ec.message();
2964f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
29651da66f75SEd Tanous                     return;
29661da66f75SEd Tanous                 }
2967e1f26343SJason M. Bills                 asyncResp->res.jsonValue = {{"Name", "PECI Command Response"},
29681da66f75SEd Tanous                                             {"PECIResponse", resp}};
29691da66f75SEd Tanous             };
29701da66f75SEd Tanous         // Call the SendRawPECI command with the provided data
29711da66f75SEd Tanous         crow::connections::systemBus->async_method_call(
29725b61b5e8SJason M. Bills             std::move(sendRawPECICallback), crashdumpObject, crashdumpPath,
29738724c297SKarthick Sundarrajan             crashdumpRawPECIInterface, "SendRawPeci", peciCommands);
29741da66f75SEd Tanous     }
29751da66f75SEd Tanous };
29761da66f75SEd Tanous 
2977cb92c03bSAndrew Geissler /**
2978cb92c03bSAndrew Geissler  * DBusLogServiceActionsClear class supports POST method for ClearLog action.
2979cb92c03bSAndrew Geissler  */
2980cb92c03bSAndrew Geissler class DBusLogServiceActionsClear : public Node
2981cb92c03bSAndrew Geissler {
2982cb92c03bSAndrew Geissler   public:
2983cb92c03bSAndrew Geissler     DBusLogServiceActionsClear(CrowApp& app) :
2984cb92c03bSAndrew Geissler         Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
29857af91514SGunnar Mills                   "LogService.ClearLog/")
2986cb92c03bSAndrew Geissler     {
2987cb92c03bSAndrew Geissler         entityPrivileges = {
2988cb92c03bSAndrew Geissler             {boost::beast::http::verb::get, {{"Login"}}},
2989cb92c03bSAndrew Geissler             {boost::beast::http::verb::head, {{"Login"}}},
2990cb92c03bSAndrew Geissler             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2991cb92c03bSAndrew Geissler             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2992cb92c03bSAndrew Geissler             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2993cb92c03bSAndrew Geissler             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2994cb92c03bSAndrew Geissler     }
2995cb92c03bSAndrew Geissler 
2996cb92c03bSAndrew Geissler   private:
2997cb92c03bSAndrew Geissler     /**
2998cb92c03bSAndrew Geissler      * Function handles POST method request.
2999cb92c03bSAndrew Geissler      * The Clear Log actions does not require any parameter.The action deletes
3000cb92c03bSAndrew Geissler      * all entries found in the Entries collection for this Log Service.
3001cb92c03bSAndrew Geissler      */
3002cb92c03bSAndrew Geissler     void doPost(crow::Response& res, const crow::Request& req,
3003cb92c03bSAndrew Geissler                 const std::vector<std::string>& params) override
3004cb92c03bSAndrew Geissler     {
3005cb92c03bSAndrew Geissler         BMCWEB_LOG_DEBUG << "Do delete all entries.";
3006cb92c03bSAndrew Geissler 
3007cb92c03bSAndrew Geissler         auto asyncResp = std::make_shared<AsyncResp>(res);
3008cb92c03bSAndrew Geissler         // Process response from Logging service.
3009cb92c03bSAndrew Geissler         auto resp_handler = [asyncResp](const boost::system::error_code ec) {
3010cb92c03bSAndrew Geissler             BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done";
3011cb92c03bSAndrew Geissler             if (ec)
3012cb92c03bSAndrew Geissler             {
3013cb92c03bSAndrew Geissler                 // TODO Handle for specific error code
3014cb92c03bSAndrew Geissler                 BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec;
3015cb92c03bSAndrew Geissler                 asyncResp->res.result(
3016cb92c03bSAndrew Geissler                     boost::beast::http::status::internal_server_error);
3017cb92c03bSAndrew Geissler                 return;
3018cb92c03bSAndrew Geissler             }
3019cb92c03bSAndrew Geissler 
3020cb92c03bSAndrew Geissler             asyncResp->res.result(boost::beast::http::status::no_content);
3021cb92c03bSAndrew Geissler         };
3022cb92c03bSAndrew Geissler 
3023cb92c03bSAndrew Geissler         // Make call to Logging service to request Clear Log
3024cb92c03bSAndrew Geissler         crow::connections::systemBus->async_method_call(
3025cb92c03bSAndrew Geissler             resp_handler, "xyz.openbmc_project.Logging",
3026cb92c03bSAndrew Geissler             "/xyz/openbmc_project/logging",
3027cb92c03bSAndrew Geissler             "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3028cb92c03bSAndrew Geissler     }
3029cb92c03bSAndrew Geissler };
3030a3316fc6SZhikuiRen 
3031a3316fc6SZhikuiRen /****************************************************
3032a3316fc6SZhikuiRen  * Redfish PostCode interfaces
3033a3316fc6SZhikuiRen  * using DBUS interface: getPostCodesTS
3034a3316fc6SZhikuiRen  ******************************************************/
3035a3316fc6SZhikuiRen class PostCodesLogService : public Node
3036a3316fc6SZhikuiRen {
3037a3316fc6SZhikuiRen   public:
3038a3316fc6SZhikuiRen     PostCodesLogService(CrowApp& app) :
3039a3316fc6SZhikuiRen         Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/")
3040a3316fc6SZhikuiRen     {
3041a3316fc6SZhikuiRen         entityPrivileges = {
3042a3316fc6SZhikuiRen             {boost::beast::http::verb::get, {{"Login"}}},
3043a3316fc6SZhikuiRen             {boost::beast::http::verb::head, {{"Login"}}},
3044a3316fc6SZhikuiRen             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3045a3316fc6SZhikuiRen             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3046a3316fc6SZhikuiRen             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3047a3316fc6SZhikuiRen             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3048a3316fc6SZhikuiRen     }
3049a3316fc6SZhikuiRen 
3050a3316fc6SZhikuiRen   private:
3051a3316fc6SZhikuiRen     void doGet(crow::Response& res, const crow::Request& req,
3052a3316fc6SZhikuiRen                const std::vector<std::string>& params) override
3053a3316fc6SZhikuiRen     {
3054a3316fc6SZhikuiRen         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3055a3316fc6SZhikuiRen 
3056a3316fc6SZhikuiRen         asyncResp->res.jsonValue = {
3057a3316fc6SZhikuiRen             {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"},
3058a3316fc6SZhikuiRen             {"@odata.type", "#LogService.v1_1_0.LogService"},
3059a3316fc6SZhikuiRen             {"@odata.context", "/redfish/v1/$metadata#LogService.LogService"},
3060a3316fc6SZhikuiRen             {"Name", "POST Code Log Service"},
3061a3316fc6SZhikuiRen             {"Description", "POST Code Log Service"},
3062a3316fc6SZhikuiRen             {"Id", "BIOS POST Code Log"},
3063a3316fc6SZhikuiRen             {"OverWritePolicy", "WrapsWhenFull"},
3064a3316fc6SZhikuiRen             {"Entries",
3065a3316fc6SZhikuiRen              {{"@odata.id",
3066a3316fc6SZhikuiRen                "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}};
3067a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
3068a3316fc6SZhikuiRen             {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/"
3069a3316fc6SZhikuiRen                        "Actions/LogService.ClearLog"}};
3070a3316fc6SZhikuiRen     }
3071a3316fc6SZhikuiRen };
3072a3316fc6SZhikuiRen 
3073a3316fc6SZhikuiRen class PostCodesClear : public Node
3074a3316fc6SZhikuiRen {
3075a3316fc6SZhikuiRen   public:
3076a3316fc6SZhikuiRen     PostCodesClear(CrowApp& app) :
3077a3316fc6SZhikuiRen         Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/"
3078a3316fc6SZhikuiRen                   "LogService.ClearLog/")
3079a3316fc6SZhikuiRen     {
3080a3316fc6SZhikuiRen         entityPrivileges = {
3081a3316fc6SZhikuiRen             {boost::beast::http::verb::get, {{"Login"}}},
3082a3316fc6SZhikuiRen             {boost::beast::http::verb::head, {{"Login"}}},
30833946028dSAppaRao Puli             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
30843946028dSAppaRao Puli             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
30853946028dSAppaRao Puli             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
30863946028dSAppaRao Puli             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
3087a3316fc6SZhikuiRen     }
3088a3316fc6SZhikuiRen 
3089a3316fc6SZhikuiRen   private:
3090a3316fc6SZhikuiRen     void doPost(crow::Response& res, const crow::Request& req,
3091a3316fc6SZhikuiRen                 const std::vector<std::string>& params) override
3092a3316fc6SZhikuiRen     {
3093a3316fc6SZhikuiRen         BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
3094a3316fc6SZhikuiRen 
3095a3316fc6SZhikuiRen         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3096a3316fc6SZhikuiRen         // Make call to post-code service to request clear all
3097a3316fc6SZhikuiRen         crow::connections::systemBus->async_method_call(
3098a3316fc6SZhikuiRen             [asyncResp](const boost::system::error_code ec) {
3099a3316fc6SZhikuiRen                 if (ec)
3100a3316fc6SZhikuiRen                 {
3101a3316fc6SZhikuiRen                     // TODO Handle for specific error code
3102a3316fc6SZhikuiRen                     BMCWEB_LOG_ERROR
3103a3316fc6SZhikuiRen                         << "doClearPostCodes resp_handler got error " << ec;
3104a3316fc6SZhikuiRen                     asyncResp->res.result(
3105a3316fc6SZhikuiRen                         boost::beast::http::status::internal_server_error);
3106a3316fc6SZhikuiRen                     messages::internalError(asyncResp->res);
3107a3316fc6SZhikuiRen                     return;
3108a3316fc6SZhikuiRen                 }
3109a3316fc6SZhikuiRen             },
3110a3316fc6SZhikuiRen             "xyz.openbmc_project.State.Boot.PostCode",
3111a3316fc6SZhikuiRen             "/xyz/openbmc_project/State/Boot/PostCode",
3112a3316fc6SZhikuiRen             "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3113a3316fc6SZhikuiRen     }
3114a3316fc6SZhikuiRen };
3115a3316fc6SZhikuiRen 
3116a3316fc6SZhikuiRen static void fillPostCodeEntry(
3117a3316fc6SZhikuiRen     std::shared_ptr<AsyncResp> aResp,
3118a3316fc6SZhikuiRen     const boost::container::flat_map<uint64_t, uint64_t>& postcode,
3119a3316fc6SZhikuiRen     const uint16_t bootIndex, const uint64_t codeIndex = 0,
3120a3316fc6SZhikuiRen     const uint64_t skip = 0, const uint64_t top = 0)
3121a3316fc6SZhikuiRen {
3122a3316fc6SZhikuiRen     // Get the Message from the MessageRegistry
3123a3316fc6SZhikuiRen     const message_registries::Message* message =
3124a3316fc6SZhikuiRen         message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode");
3125a3316fc6SZhikuiRen 
3126a3316fc6SZhikuiRen     uint64_t currentCodeIndex = 0;
3127a3316fc6SZhikuiRen     nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"];
3128a3316fc6SZhikuiRen 
3129a3316fc6SZhikuiRen     uint64_t firstCodeTimeUs = 0;
3130a3316fc6SZhikuiRen     for (const std::pair<uint64_t, uint64_t>& code : postcode)
3131a3316fc6SZhikuiRen     {
3132a3316fc6SZhikuiRen         currentCodeIndex++;
3133a3316fc6SZhikuiRen         std::string postcodeEntryID =
3134a3316fc6SZhikuiRen             "B" + std::to_string(bootIndex) + "-" +
3135a3316fc6SZhikuiRen             std::to_string(currentCodeIndex); // 1 based index in EntryID string
3136a3316fc6SZhikuiRen 
3137a3316fc6SZhikuiRen         uint64_t usecSinceEpoch = code.first;
3138a3316fc6SZhikuiRen         uint64_t usTimeOffset = 0;
3139a3316fc6SZhikuiRen 
3140a3316fc6SZhikuiRen         if (1 == currentCodeIndex)
3141a3316fc6SZhikuiRen         { // already incremented
3142a3316fc6SZhikuiRen             firstCodeTimeUs = code.first;
3143a3316fc6SZhikuiRen         }
3144a3316fc6SZhikuiRen         else
3145a3316fc6SZhikuiRen         {
3146a3316fc6SZhikuiRen             usTimeOffset = code.first - firstCodeTimeUs;
3147a3316fc6SZhikuiRen         }
3148a3316fc6SZhikuiRen 
3149a3316fc6SZhikuiRen         // skip if no specific codeIndex is specified and currentCodeIndex does
3150a3316fc6SZhikuiRen         // not fall between top and skip
3151a3316fc6SZhikuiRen         if ((codeIndex == 0) &&
3152a3316fc6SZhikuiRen             (currentCodeIndex <= skip || currentCodeIndex > top))
3153a3316fc6SZhikuiRen         {
3154a3316fc6SZhikuiRen             continue;
3155a3316fc6SZhikuiRen         }
3156a3316fc6SZhikuiRen 
31574e0453b1SGunnar Mills         // skip if a specific codeIndex is specified and does not match the
3158a3316fc6SZhikuiRen         // currentIndex
3159a3316fc6SZhikuiRen         if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3160a3316fc6SZhikuiRen         {
3161a3316fc6SZhikuiRen             // This is done for simplicity. 1st entry is needed to calculate
3162a3316fc6SZhikuiRen             // time offset. To improve efficiency, one can get to the entry
3163a3316fc6SZhikuiRen             // directly (possibly with flatmap's nth method)
3164a3316fc6SZhikuiRen             continue;
3165a3316fc6SZhikuiRen         }
3166a3316fc6SZhikuiRen 
3167a3316fc6SZhikuiRen         // currentCodeIndex is within top and skip or equal to specified code
3168a3316fc6SZhikuiRen         // index
3169a3316fc6SZhikuiRen 
3170a3316fc6SZhikuiRen         // Get the Created time from the timestamp
3171a3316fc6SZhikuiRen         std::string entryTimeStr;
3172a3316fc6SZhikuiRen         if (!getTimestampStr(usecSinceEpoch, entryTimeStr))
3173a3316fc6SZhikuiRen         {
3174a3316fc6SZhikuiRen             continue;
3175a3316fc6SZhikuiRen         }
3176a3316fc6SZhikuiRen 
3177a3316fc6SZhikuiRen         // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3178a3316fc6SZhikuiRen         std::ostringstream hexCode;
3179a3316fc6SZhikuiRen         hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
3180a3316fc6SZhikuiRen                 << code.second;
3181a3316fc6SZhikuiRen         std::ostringstream timeOffsetStr;
3182a3316fc6SZhikuiRen         // Set Fixed -Point Notation
3183a3316fc6SZhikuiRen         timeOffsetStr << std::fixed;
3184a3316fc6SZhikuiRen         // Set precision to 4 digits
3185a3316fc6SZhikuiRen         timeOffsetStr << std::setprecision(4);
3186a3316fc6SZhikuiRen         // Add double to stream
3187a3316fc6SZhikuiRen         timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3188a3316fc6SZhikuiRen         std::vector<std::string> messageArgs = {
3189a3316fc6SZhikuiRen             std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()};
3190a3316fc6SZhikuiRen 
3191a3316fc6SZhikuiRen         // Get MessageArgs template from message registry
3192a3316fc6SZhikuiRen         std::string msg;
3193a3316fc6SZhikuiRen         if (message != nullptr)
3194a3316fc6SZhikuiRen         {
3195a3316fc6SZhikuiRen             msg = message->message;
3196a3316fc6SZhikuiRen 
3197a3316fc6SZhikuiRen             // fill in this post code value
3198a3316fc6SZhikuiRen             int i = 0;
3199a3316fc6SZhikuiRen             for (const std::string& messageArg : messageArgs)
3200a3316fc6SZhikuiRen             {
3201a3316fc6SZhikuiRen                 std::string argStr = "%" + std::to_string(++i);
3202a3316fc6SZhikuiRen                 size_t argPos = msg.find(argStr);
3203a3316fc6SZhikuiRen                 if (argPos != std::string::npos)
3204a3316fc6SZhikuiRen                 {
3205a3316fc6SZhikuiRen                     msg.replace(argPos, argStr.length(), messageArg);
3206a3316fc6SZhikuiRen                 }
3207a3316fc6SZhikuiRen             }
3208a3316fc6SZhikuiRen         }
3209a3316fc6SZhikuiRen 
3210d4342a92STim Lee         // Get Severity template from message registry
3211d4342a92STim Lee         std::string severity;
3212d4342a92STim Lee         if (message != nullptr)
3213d4342a92STim Lee         {
3214d4342a92STim Lee             severity = message->severity;
3215d4342a92STim Lee         }
3216d4342a92STim Lee 
3217a3316fc6SZhikuiRen         // add to AsyncResp
3218a3316fc6SZhikuiRen         logEntryArray.push_back({});
3219a3316fc6SZhikuiRen         nlohmann::json& bmcLogEntry = logEntryArray.back();
3220a3316fc6SZhikuiRen         bmcLogEntry = {
3221a3316fc6SZhikuiRen             {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
3222a3316fc6SZhikuiRen             {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"},
3223a3316fc6SZhikuiRen             {"@odata.id", "/redfish/v1/Systems/system/LogServices/"
3224a3316fc6SZhikuiRen                           "PostCodes/Entries/" +
3225a3316fc6SZhikuiRen                               postcodeEntryID},
3226a3316fc6SZhikuiRen             {"Name", "POST Code Log Entry"},
3227a3316fc6SZhikuiRen             {"Id", postcodeEntryID},
3228a3316fc6SZhikuiRen             {"Message", std::move(msg)},
3229a3316fc6SZhikuiRen             {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"},
3230a3316fc6SZhikuiRen             {"MessageArgs", std::move(messageArgs)},
3231a3316fc6SZhikuiRen             {"EntryType", "Event"},
3232a3316fc6SZhikuiRen             {"Severity", std::move(severity)},
3233a3316fc6SZhikuiRen             {"Created", std::move(entryTimeStr)}};
3234a3316fc6SZhikuiRen     }
3235a3316fc6SZhikuiRen }
3236a3316fc6SZhikuiRen 
3237a3316fc6SZhikuiRen static void getPostCodeForEntry(std::shared_ptr<AsyncResp> aResp,
3238a3316fc6SZhikuiRen                                 const uint16_t bootIndex,
3239a3316fc6SZhikuiRen                                 const uint64_t codeIndex)
3240a3316fc6SZhikuiRen {
3241a3316fc6SZhikuiRen     crow::connections::systemBus->async_method_call(
3242a3316fc6SZhikuiRen         [aResp, bootIndex, codeIndex](
3243a3316fc6SZhikuiRen             const boost::system::error_code ec,
3244a3316fc6SZhikuiRen             const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
3245a3316fc6SZhikuiRen             if (ec)
3246a3316fc6SZhikuiRen             {
3247a3316fc6SZhikuiRen                 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3248a3316fc6SZhikuiRen                 messages::internalError(aResp->res);
3249a3316fc6SZhikuiRen                 return;
3250a3316fc6SZhikuiRen             }
3251a3316fc6SZhikuiRen 
3252a3316fc6SZhikuiRen             // skip the empty postcode boots
3253a3316fc6SZhikuiRen             if (postcode.empty())
3254a3316fc6SZhikuiRen             {
3255a3316fc6SZhikuiRen                 return;
3256a3316fc6SZhikuiRen             }
3257a3316fc6SZhikuiRen 
3258a3316fc6SZhikuiRen             fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex);
3259a3316fc6SZhikuiRen 
3260a3316fc6SZhikuiRen             aResp->res.jsonValue["Members@odata.count"] =
3261a3316fc6SZhikuiRen                 aResp->res.jsonValue["Members"].size();
3262a3316fc6SZhikuiRen         },
3263a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode",
3264a3316fc6SZhikuiRen         "/xyz/openbmc_project/State/Boot/PostCode",
3265a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3266a3316fc6SZhikuiRen         bootIndex);
3267a3316fc6SZhikuiRen }
3268a3316fc6SZhikuiRen 
3269a3316fc6SZhikuiRen static void getPostCodeForBoot(std::shared_ptr<AsyncResp> aResp,
3270a3316fc6SZhikuiRen                                const uint16_t bootIndex,
3271a3316fc6SZhikuiRen                                const uint16_t bootCount,
3272a3316fc6SZhikuiRen                                const uint64_t entryCount, const uint64_t skip,
3273a3316fc6SZhikuiRen                                const uint64_t top)
3274a3316fc6SZhikuiRen {
3275a3316fc6SZhikuiRen     crow::connections::systemBus->async_method_call(
3276a3316fc6SZhikuiRen         [aResp, bootIndex, bootCount, entryCount, skip,
3277a3316fc6SZhikuiRen          top](const boost::system::error_code ec,
3278a3316fc6SZhikuiRen               const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
3279a3316fc6SZhikuiRen             if (ec)
3280a3316fc6SZhikuiRen             {
3281a3316fc6SZhikuiRen                 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3282a3316fc6SZhikuiRen                 messages::internalError(aResp->res);
3283a3316fc6SZhikuiRen                 return;
3284a3316fc6SZhikuiRen             }
3285a3316fc6SZhikuiRen 
3286a3316fc6SZhikuiRen             uint64_t endCount = entryCount;
3287a3316fc6SZhikuiRen             if (!postcode.empty())
3288a3316fc6SZhikuiRen             {
3289a3316fc6SZhikuiRen                 endCount = entryCount + postcode.size();
3290a3316fc6SZhikuiRen 
3291a3316fc6SZhikuiRen                 if ((skip < endCount) && ((top + skip) > entryCount))
3292a3316fc6SZhikuiRen                 {
3293a3316fc6SZhikuiRen                     uint64_t thisBootSkip =
3294a3316fc6SZhikuiRen                         std::max(skip, entryCount) - entryCount;
3295a3316fc6SZhikuiRen                     uint64_t thisBootTop =
3296a3316fc6SZhikuiRen                         std::min(top + skip, endCount) - entryCount;
3297a3316fc6SZhikuiRen 
3298a3316fc6SZhikuiRen                     fillPostCodeEntry(aResp, postcode, bootIndex, 0,
3299a3316fc6SZhikuiRen                                       thisBootSkip, thisBootTop);
3300a3316fc6SZhikuiRen                 }
3301a3316fc6SZhikuiRen                 aResp->res.jsonValue["Members@odata.count"] = endCount;
3302a3316fc6SZhikuiRen             }
3303a3316fc6SZhikuiRen 
3304a3316fc6SZhikuiRen             // continue to previous bootIndex
3305a3316fc6SZhikuiRen             if (bootIndex < bootCount)
3306a3316fc6SZhikuiRen             {
3307a3316fc6SZhikuiRen                 getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1),
3308a3316fc6SZhikuiRen                                    bootCount, endCount, skip, top);
3309a3316fc6SZhikuiRen             }
3310a3316fc6SZhikuiRen             else
3311a3316fc6SZhikuiRen             {
3312a3316fc6SZhikuiRen                 aResp->res.jsonValue["Members@odata.nextLink"] =
3313a3316fc6SZhikuiRen                     "/redfish/v1/Systems/system/LogServices/PostCodes/"
3314a3316fc6SZhikuiRen                     "Entries?$skip=" +
3315a3316fc6SZhikuiRen                     std::to_string(skip + top);
3316a3316fc6SZhikuiRen             }
3317a3316fc6SZhikuiRen         },
3318a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode",
3319a3316fc6SZhikuiRen         "/xyz/openbmc_project/State/Boot/PostCode",
3320a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3321a3316fc6SZhikuiRen         bootIndex);
3322a3316fc6SZhikuiRen }
3323a3316fc6SZhikuiRen 
3324a3316fc6SZhikuiRen static void getCurrentBootNumber(std::shared_ptr<AsyncResp> aResp,
3325a3316fc6SZhikuiRen                                  const uint64_t skip, const uint64_t top)
3326a3316fc6SZhikuiRen {
3327a3316fc6SZhikuiRen     uint64_t entryCount = 0;
3328a3316fc6SZhikuiRen     crow::connections::systemBus->async_method_call(
3329a3316fc6SZhikuiRen         [aResp, entryCount, skip,
3330a3316fc6SZhikuiRen          top](const boost::system::error_code ec,
3331a3316fc6SZhikuiRen               const std::variant<uint16_t>& bootCount) {
3332a3316fc6SZhikuiRen             if (ec)
3333a3316fc6SZhikuiRen             {
3334a3316fc6SZhikuiRen                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
3335a3316fc6SZhikuiRen                 messages::internalError(aResp->res);
3336a3316fc6SZhikuiRen                 return;
3337a3316fc6SZhikuiRen             }
3338a3316fc6SZhikuiRen             auto pVal = std::get_if<uint16_t>(&bootCount);
3339a3316fc6SZhikuiRen             if (pVal)
3340a3316fc6SZhikuiRen             {
3341a3316fc6SZhikuiRen                 getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top);
3342a3316fc6SZhikuiRen             }
3343a3316fc6SZhikuiRen             else
3344a3316fc6SZhikuiRen             {
3345a3316fc6SZhikuiRen                 BMCWEB_LOG_DEBUG << "Post code boot index failed.";
3346a3316fc6SZhikuiRen             }
3347a3316fc6SZhikuiRen         },
3348a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode",
3349a3316fc6SZhikuiRen         "/xyz/openbmc_project/State/Boot/PostCode",
3350a3316fc6SZhikuiRen         "org.freedesktop.DBus.Properties", "Get",
3351a3316fc6SZhikuiRen         "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
3352a3316fc6SZhikuiRen }
3353a3316fc6SZhikuiRen 
3354a3316fc6SZhikuiRen class PostCodesEntryCollection : public Node
3355a3316fc6SZhikuiRen {
3356a3316fc6SZhikuiRen   public:
3357a3316fc6SZhikuiRen     template <typename CrowApp>
3358a3316fc6SZhikuiRen     PostCodesEntryCollection(CrowApp& app) :
3359a3316fc6SZhikuiRen         Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/")
3360a3316fc6SZhikuiRen     {
3361a3316fc6SZhikuiRen         entityPrivileges = {
3362a3316fc6SZhikuiRen             {boost::beast::http::verb::get, {{"Login"}}},
3363a3316fc6SZhikuiRen             {boost::beast::http::verb::head, {{"Login"}}},
3364a3316fc6SZhikuiRen             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3365a3316fc6SZhikuiRen             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3366a3316fc6SZhikuiRen             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3367a3316fc6SZhikuiRen             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3368a3316fc6SZhikuiRen     }
3369a3316fc6SZhikuiRen 
3370a3316fc6SZhikuiRen   private:
3371a3316fc6SZhikuiRen     void doGet(crow::Response& res, const crow::Request& req,
3372a3316fc6SZhikuiRen                const std::vector<std::string>& params) override
3373a3316fc6SZhikuiRen     {
3374a3316fc6SZhikuiRen         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3375a3316fc6SZhikuiRen 
3376a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.type"] =
3377a3316fc6SZhikuiRen             "#LogEntryCollection.LogEntryCollection";
3378a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.context"] =
3379a3316fc6SZhikuiRen             "/redfish/v1/"
3380a3316fc6SZhikuiRen             "$metadata#LogEntryCollection.LogEntryCollection";
3381a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.id"] =
3382a3316fc6SZhikuiRen             "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
3383a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3384a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Description"] =
3385a3316fc6SZhikuiRen             "Collection of POST Code Log Entries";
3386a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3387a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members@odata.count"] = 0;
3388a3316fc6SZhikuiRen 
3389a3316fc6SZhikuiRen         uint64_t skip = 0;
3390a3316fc6SZhikuiRen         uint64_t top = maxEntriesPerPage; // Show max entries by default
3391a3316fc6SZhikuiRen         if (!getSkipParam(asyncResp->res, req, skip))
3392a3316fc6SZhikuiRen         {
3393a3316fc6SZhikuiRen             return;
3394a3316fc6SZhikuiRen         }
3395a3316fc6SZhikuiRen         if (!getTopParam(asyncResp->res, req, top))
3396a3316fc6SZhikuiRen         {
3397a3316fc6SZhikuiRen             return;
3398a3316fc6SZhikuiRen         }
3399a3316fc6SZhikuiRen         getCurrentBootNumber(asyncResp, skip, top);
3400a3316fc6SZhikuiRen     }
3401a3316fc6SZhikuiRen };
3402a3316fc6SZhikuiRen 
3403a3316fc6SZhikuiRen class PostCodesEntry : public Node
3404a3316fc6SZhikuiRen {
3405a3316fc6SZhikuiRen   public:
3406a3316fc6SZhikuiRen     PostCodesEntry(CrowApp& app) :
3407a3316fc6SZhikuiRen         Node(app,
3408a3316fc6SZhikuiRen              "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/",
3409a3316fc6SZhikuiRen              std::string())
3410a3316fc6SZhikuiRen     {
3411a3316fc6SZhikuiRen         entityPrivileges = {
3412a3316fc6SZhikuiRen             {boost::beast::http::verb::get, {{"Login"}}},
3413a3316fc6SZhikuiRen             {boost::beast::http::verb::head, {{"Login"}}},
3414a3316fc6SZhikuiRen             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3415a3316fc6SZhikuiRen             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3416a3316fc6SZhikuiRen             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3417a3316fc6SZhikuiRen             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3418a3316fc6SZhikuiRen     }
3419a3316fc6SZhikuiRen 
3420a3316fc6SZhikuiRen   private:
3421a3316fc6SZhikuiRen     void doGet(crow::Response& res, const crow::Request& req,
3422a3316fc6SZhikuiRen                const std::vector<std::string>& params) override
3423a3316fc6SZhikuiRen     {
3424a3316fc6SZhikuiRen         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3425a3316fc6SZhikuiRen         if (params.size() != 1)
3426a3316fc6SZhikuiRen         {
3427a3316fc6SZhikuiRen             messages::internalError(asyncResp->res);
3428a3316fc6SZhikuiRen             return;
3429a3316fc6SZhikuiRen         }
3430a3316fc6SZhikuiRen 
3431a3316fc6SZhikuiRen         const std::string& targetID = params[0];
3432a3316fc6SZhikuiRen 
3433a3316fc6SZhikuiRen         size_t bootPos = targetID.find('B');
3434a3316fc6SZhikuiRen         if (bootPos == std::string::npos)
3435a3316fc6SZhikuiRen         {
3436a3316fc6SZhikuiRen             // Requested ID was not found
3437a3316fc6SZhikuiRen             messages::resourceMissingAtURI(asyncResp->res, targetID);
3438a3316fc6SZhikuiRen             return;
3439a3316fc6SZhikuiRen         }
3440a3316fc6SZhikuiRen         std::string_view bootIndexStr(targetID);
3441a3316fc6SZhikuiRen         bootIndexStr.remove_prefix(bootPos + 1);
3442a3316fc6SZhikuiRen         uint16_t bootIndex = 0;
3443a3316fc6SZhikuiRen         uint64_t codeIndex = 0;
3444a3316fc6SZhikuiRen         size_t dashPos = bootIndexStr.find('-');
3445a3316fc6SZhikuiRen 
3446a3316fc6SZhikuiRen         if (dashPos == std::string::npos)
3447a3316fc6SZhikuiRen         {
3448a3316fc6SZhikuiRen             return;
3449a3316fc6SZhikuiRen         }
3450a3316fc6SZhikuiRen         std::string_view codeIndexStr(bootIndexStr);
3451a3316fc6SZhikuiRen         bootIndexStr.remove_suffix(dashPos);
3452a3316fc6SZhikuiRen         codeIndexStr.remove_prefix(dashPos + 1);
3453a3316fc6SZhikuiRen 
3454a3316fc6SZhikuiRen         bootIndex = static_cast<uint16_t>(
3455a3316fc6SZhikuiRen             strtoul(std::string(bootIndexStr).c_str(), NULL, 0));
3456a3316fc6SZhikuiRen         codeIndex = strtoul(std::string(codeIndexStr).c_str(), NULL, 0);
3457a3316fc6SZhikuiRen         if (bootIndex == 0 || codeIndex == 0)
3458a3316fc6SZhikuiRen         {
3459a3316fc6SZhikuiRen             BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string "
3460a3316fc6SZhikuiRen                              << params[0];
3461a3316fc6SZhikuiRen         }
3462a3316fc6SZhikuiRen 
3463a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry";
3464a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.context"] =
3465a3316fc6SZhikuiRen             "/redfish/v1/$metadata#LogEntry.LogEntry";
3466a3316fc6SZhikuiRen         asyncResp->res.jsonValue["@odata.id"] =
3467a3316fc6SZhikuiRen             "/redfish/v1/Systems/system/LogServices/PostCodes/"
3468a3316fc6SZhikuiRen             "Entries";
3469a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3470a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Description"] =
3471a3316fc6SZhikuiRen             "Collection of POST Code Log Entries";
3472a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3473a3316fc6SZhikuiRen         asyncResp->res.jsonValue["Members@odata.count"] = 0;
3474a3316fc6SZhikuiRen 
3475a3316fc6SZhikuiRen         getPostCodeForEntry(asyncResp, bootIndex, codeIndex);
3476a3316fc6SZhikuiRen     }
3477a3316fc6SZhikuiRen };
3478a3316fc6SZhikuiRen 
34791da66f75SEd Tanous } // namespace redfish
3480