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 184851d45dSJason M. Bills #include "registries.hpp" 194851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 204851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2146229577SJames Feist #include "task.hpp" 221da66f75SEd Tanous 23e1f26343SJason M. Bills #include <systemd/sd-journal.h> 24400fd1fbSAdriana Kobylak #include <unistd.h> 25e1f26343SJason M. Bills 267e860f15SJohn Edward Broadbent #include <app.hpp> 27400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 284851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 294851d45dSJason M. Bills #include <boost/beast/core/span.hpp> 30400fd1fbSAdriana Kobylak #include <boost/beast/http.hpp> 311da66f75SEd Tanous #include <boost/container/flat_map.hpp> 321ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 33cb92c03bSAndrew Geissler #include <error_messages.hpp> 34ed398213SEd Tanous #include <registries/privilege_registry.hpp> 351214b7e7SGunnar Mills 364418c7f0SJames Feist #include <filesystem> 3775710de2SXiaochao Ma #include <optional> 38cd225da8SJason M. Bills #include <string_view> 39abf2add6SEd Tanous #include <variant> 401da66f75SEd Tanous 411da66f75SEd Tanous namespace redfish 421da66f75SEd Tanous { 431da66f75SEd Tanous 445b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 455b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 465b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 475b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 485b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 495b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 50424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 516eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 526eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 531da66f75SEd Tanous 544851d45dSJason M. Bills namespace message_registries 554851d45dSJason M. Bills { 564851d45dSJason M. Bills static const Message* getMessageFromRegistry( 574851d45dSJason M. Bills const std::string& messageKey, 584851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 594851d45dSJason M. Bills { 604851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 614851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 624851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 634851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 644851d45dSJason M. Bills messageKey.c_str()); 654851d45dSJason M. Bills }); 664851d45dSJason M. Bills if (messageIt != registry.cend()) 674851d45dSJason M. Bills { 684851d45dSJason M. Bills return &messageIt->second; 694851d45dSJason M. Bills } 704851d45dSJason M. Bills 714851d45dSJason M. Bills return nullptr; 724851d45dSJason M. Bills } 734851d45dSJason M. Bills 744851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 754851d45dSJason M. Bills { 764851d45dSJason M. Bills // Redfish MessageIds are in the form 774851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 784851d45dSJason M. Bills // the right Message 794851d45dSJason M. Bills std::vector<std::string> fields; 804851d45dSJason M. Bills fields.reserve(4); 814851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 824851d45dSJason M. Bills std::string& registryName = fields[0]; 834851d45dSJason M. Bills std::string& messageKey = fields[3]; 844851d45dSJason M. Bills 854851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 864851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 874851d45dSJason M. Bills { 884851d45dSJason M. Bills return getMessageFromRegistry( 894851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 904851d45dSJason M. Bills } 914851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 924851d45dSJason M. Bills { 934851d45dSJason M. Bills return getMessageFromRegistry( 944851d45dSJason M. Bills messageKey, 954851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 964851d45dSJason M. Bills } 974851d45dSJason M. Bills return nullptr; 984851d45dSJason M. Bills } 994851d45dSJason M. Bills } // namespace message_registries 1004851d45dSJason M. Bills 101f6150403SJames Feist namespace fs = std::filesystem; 1021da66f75SEd Tanous 103cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 10419bd78d9SPatrick Williams std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, 105cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 106cb92c03bSAndrew Geissler 107cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 108cb92c03bSAndrew Geissler sdbusplus::message::object_path, 109cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 110cb92c03bSAndrew Geissler 111cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 112cb92c03bSAndrew Geissler { 113d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 114d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 115d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 116d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 117cb92c03bSAndrew Geissler { 118cb92c03bSAndrew Geissler return "Critical"; 119cb92c03bSAndrew Geissler } 1203174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 121d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 122d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 123cb92c03bSAndrew Geissler { 124cb92c03bSAndrew Geissler return "OK"; 125cb92c03bSAndrew Geissler } 1263174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 127cb92c03bSAndrew Geissler { 128cb92c03bSAndrew Geissler return "Warning"; 129cb92c03bSAndrew Geissler } 130cb92c03bSAndrew Geissler return ""; 131cb92c03bSAndrew Geissler } 132cb92c03bSAndrew Geissler 1337e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 13439e77504SEd Tanous const std::string_view& field, 13539e77504SEd Tanous std::string_view& contents) 13616428a1aSJason M. Bills { 13716428a1aSJason M. Bills const char* data = nullptr; 13816428a1aSJason M. Bills size_t length = 0; 13916428a1aSJason M. Bills int ret = 0; 14016428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 141271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 142271584abSEd Tanous reinterpret_cast<const void**>(&data), &length); 14316428a1aSJason M. Bills if (ret < 0) 14416428a1aSJason M. Bills { 14516428a1aSJason M. Bills return ret; 14616428a1aSJason M. Bills } 14739e77504SEd Tanous contents = std::string_view(data, length); 14816428a1aSJason M. Bills // Only use the content after the "=" character. 14981ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 15016428a1aSJason M. Bills return ret; 15116428a1aSJason M. Bills } 15216428a1aSJason M. Bills 1537e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 1547e860f15SJohn Edward Broadbent const std::string_view& field, 1557e860f15SJohn Edward Broadbent const int& base, long int& contents) 15616428a1aSJason M. Bills { 15716428a1aSJason M. Bills int ret = 0; 15839e77504SEd Tanous std::string_view metadata; 15916428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 16016428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 16116428a1aSJason M. Bills if (ret < 0) 16216428a1aSJason M. Bills { 16316428a1aSJason M. Bills return ret; 16416428a1aSJason M. Bills } 165b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 16616428a1aSJason M. Bills return ret; 16716428a1aSJason M. Bills } 16816428a1aSJason M. Bills 1697e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1707e860f15SJohn Edward Broadbent std::string& entryTimestamp) 171a3316fc6SZhikuiRen { 172a3316fc6SZhikuiRen int ret = 0; 173a3316fc6SZhikuiRen uint64_t timestamp = 0; 174a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 175a3316fc6SZhikuiRen if (ret < 0) 176a3316fc6SZhikuiRen { 177a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 178a3316fc6SZhikuiRen << strerror(-ret); 179a3316fc6SZhikuiRen return false; 180a3316fc6SZhikuiRen } 1819c620e21SAsmitha Karunanithi entryTimestamp = crow::utility::getDateTime( 1829c620e21SAsmitha Karunanithi static_cast<std::time_t>(timestamp / 1000 / 1000)); 1839c620e21SAsmitha Karunanithi return true; 184a3316fc6SZhikuiRen } 185a3316fc6SZhikuiRen 1868d1b46d7Szhanghch05 static bool getSkipParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1878d1b46d7Szhanghch05 const crow::Request& req, uint64_t& skip) 18816428a1aSJason M. Bills { 1895a7e877eSJames Feist boost::urls::url_view::params_type::iterator it = 1905a7e877eSJames Feist req.urlParams.find("$skip"); 1915a7e877eSJames Feist if (it != req.urlParams.end()) 19216428a1aSJason M. Bills { 1935a7e877eSJames Feist std::string skipParam = it->value(); 19416428a1aSJason M. Bills char* ptr = nullptr; 1955a7e877eSJames Feist skip = std::strtoul(skipParam.c_str(), &ptr, 10); 1965a7e877eSJames Feist if (skipParam.empty() || *ptr != '\0') 19716428a1aSJason M. Bills { 19816428a1aSJason M. Bills 1998d1b46d7Szhanghch05 messages::queryParameterValueTypeError( 2008d1b46d7Szhanghch05 asyncResp->res, std::string(skipParam), "$skip"); 20116428a1aSJason M. Bills return false; 20216428a1aSJason M. Bills } 20316428a1aSJason M. Bills } 20416428a1aSJason M. Bills return true; 20516428a1aSJason M. Bills } 20616428a1aSJason M. Bills 207271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 2088d1b46d7Szhanghch05 static bool getTopParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2098d1b46d7Szhanghch05 const crow::Request& req, uint64_t& top) 21016428a1aSJason M. Bills { 2115a7e877eSJames Feist boost::urls::url_view::params_type::iterator it = 2125a7e877eSJames Feist req.urlParams.find("$top"); 2135a7e877eSJames Feist if (it != req.urlParams.end()) 21416428a1aSJason M. Bills { 2155a7e877eSJames Feist std::string topParam = it->value(); 21616428a1aSJason M. Bills char* ptr = nullptr; 2175a7e877eSJames Feist top = std::strtoul(topParam.c_str(), &ptr, 10); 2185a7e877eSJames Feist if (topParam.empty() || *ptr != '\0') 21916428a1aSJason M. Bills { 2208d1b46d7Szhanghch05 messages::queryParameterValueTypeError( 2218d1b46d7Szhanghch05 asyncResp->res, std::string(topParam), "$top"); 22216428a1aSJason M. Bills return false; 22316428a1aSJason M. Bills } 224271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 22516428a1aSJason M. Bills { 22616428a1aSJason M. Bills 22716428a1aSJason M. Bills messages::queryParameterOutOfRange( 2288d1b46d7Szhanghch05 asyncResp->res, std::to_string(top), "$top", 22916428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 23016428a1aSJason M. Bills return false; 23116428a1aSJason M. Bills } 23216428a1aSJason M. Bills } 23316428a1aSJason M. Bills return true; 23416428a1aSJason M. Bills } 23516428a1aSJason M. Bills 2367e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 237e85d6b16SJason M. Bills const bool firstEntry = true) 23816428a1aSJason M. Bills { 23916428a1aSJason M. Bills int ret = 0; 24016428a1aSJason M. Bills static uint64_t prevTs = 0; 24116428a1aSJason M. Bills static int index = 0; 242e85d6b16SJason M. Bills if (firstEntry) 243e85d6b16SJason M. Bills { 244e85d6b16SJason M. Bills prevTs = 0; 245e85d6b16SJason M. Bills } 246e85d6b16SJason M. Bills 24716428a1aSJason M. Bills // Get the entry timestamp 24816428a1aSJason M. Bills uint64_t curTs = 0; 24916428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 25016428a1aSJason M. Bills if (ret < 0) 25116428a1aSJason M. Bills { 25216428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 25316428a1aSJason M. Bills << strerror(-ret); 25416428a1aSJason M. Bills return false; 25516428a1aSJason M. Bills } 25616428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 25716428a1aSJason M. Bills if (curTs == prevTs) 25816428a1aSJason M. Bills { 25916428a1aSJason M. Bills index++; 26016428a1aSJason M. Bills } 26116428a1aSJason M. Bills else 26216428a1aSJason M. Bills { 26316428a1aSJason M. Bills // Otherwise, reset it 26416428a1aSJason M. Bills index = 0; 26516428a1aSJason M. Bills } 26616428a1aSJason M. Bills // Save the timestamp 26716428a1aSJason M. Bills prevTs = curTs; 26816428a1aSJason M. Bills 26916428a1aSJason M. Bills entryID = std::to_string(curTs); 27016428a1aSJason M. Bills if (index > 0) 27116428a1aSJason M. Bills { 27216428a1aSJason M. Bills entryID += "_" + std::to_string(index); 27316428a1aSJason M. Bills } 27416428a1aSJason M. Bills return true; 27516428a1aSJason M. Bills } 27616428a1aSJason M. Bills 277e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 278e85d6b16SJason M. Bills const bool firstEntry = true) 27995820184SJason M. Bills { 280271584abSEd Tanous static time_t prevTs = 0; 28195820184SJason M. Bills static int index = 0; 282e85d6b16SJason M. Bills if (firstEntry) 283e85d6b16SJason M. Bills { 284e85d6b16SJason M. Bills prevTs = 0; 285e85d6b16SJason M. Bills } 286e85d6b16SJason M. Bills 28795820184SJason M. Bills // Get the entry timestamp 288271584abSEd Tanous std::time_t curTs = 0; 28995820184SJason M. Bills std::tm timeStruct = {}; 29095820184SJason M. Bills std::istringstream entryStream(logEntry); 29195820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 29295820184SJason M. Bills { 29395820184SJason M. Bills curTs = std::mktime(&timeStruct); 29495820184SJason M. Bills } 29595820184SJason M. Bills // If the timestamp isn't unique, increment the index 29695820184SJason M. Bills if (curTs == prevTs) 29795820184SJason M. Bills { 29895820184SJason M. Bills index++; 29995820184SJason M. Bills } 30095820184SJason M. Bills else 30195820184SJason M. Bills { 30295820184SJason M. Bills // Otherwise, reset it 30395820184SJason M. Bills index = 0; 30495820184SJason M. Bills } 30595820184SJason M. Bills // Save the timestamp 30695820184SJason M. Bills prevTs = curTs; 30795820184SJason M. Bills 30895820184SJason M. Bills entryID = std::to_string(curTs); 30995820184SJason M. Bills if (index > 0) 31095820184SJason M. Bills { 31195820184SJason M. Bills entryID += "_" + std::to_string(index); 31295820184SJason M. Bills } 31395820184SJason M. Bills return true; 31495820184SJason M. Bills } 31595820184SJason M. Bills 3167e860f15SJohn Edward Broadbent inline static bool 3178d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3188d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 3198d1b46d7Szhanghch05 uint64_t& index) 32016428a1aSJason M. Bills { 32116428a1aSJason M. Bills if (entryID.empty()) 32216428a1aSJason M. Bills { 32316428a1aSJason M. Bills return false; 32416428a1aSJason M. Bills } 32516428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 32639e77504SEd Tanous std::string_view tsStr(entryID); 32716428a1aSJason M. Bills 32881ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 32916428a1aSJason M. Bills if (underscorePos != tsStr.npos) 33016428a1aSJason M. Bills { 33116428a1aSJason M. Bills // Timestamp has an index 33216428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 33339e77504SEd Tanous std::string_view indexStr(entryID); 33416428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 335*c0bd5e4bSEd Tanous auto [ptr, ec] = std::from_chars( 336*c0bd5e4bSEd Tanous indexStr.data(), indexStr.data() + indexStr.size(), index); 337*c0bd5e4bSEd Tanous if (ec != std::errc()) 33816428a1aSJason M. Bills { 3398d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 34016428a1aSJason M. Bills return false; 34116428a1aSJason M. Bills } 34216428a1aSJason M. Bills } 34316428a1aSJason M. Bills // Timestamp has no index 344*c0bd5e4bSEd Tanous auto [ptr, ec] = 345*c0bd5e4bSEd Tanous std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp); 346*c0bd5e4bSEd Tanous if (ec != std::errc()) 34716428a1aSJason M. Bills { 3488d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 34916428a1aSJason M. Bills return false; 35016428a1aSJason M. Bills } 35116428a1aSJason M. Bills return true; 35216428a1aSJason M. Bills } 35316428a1aSJason M. Bills 35495820184SJason M. Bills static bool 35595820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 35695820184SJason M. Bills { 35795820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 35895820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 35995820184SJason M. Bills 36095820184SJason M. Bills // Loop through the directory looking for redfish log files 36195820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 36295820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 36395820184SJason M. Bills { 36495820184SJason M. Bills // If we find a redfish log file, save the path 36595820184SJason M. Bills std::string filename = dirEnt.path().filename(); 36695820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 36795820184SJason M. Bills { 36895820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 36995820184SJason M. Bills } 37095820184SJason M. Bills } 37195820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 37295820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 37395820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 37495820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 37595820184SJason M. Bills 37695820184SJason M. Bills return !redfishLogFiles.empty(); 37795820184SJason M. Bills } 37895820184SJason M. Bills 3798d1b46d7Szhanghch05 inline void 3808d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3815cb1dd27SAsmitha Karunanithi const std::string& dumpType) 3825cb1dd27SAsmitha Karunanithi { 3835cb1dd27SAsmitha Karunanithi std::string dumpPath; 3845cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 3855cb1dd27SAsmitha Karunanithi { 3865cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 3875cb1dd27SAsmitha Karunanithi } 3885cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 3895cb1dd27SAsmitha Karunanithi { 3905cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 3915cb1dd27SAsmitha Karunanithi } 3925cb1dd27SAsmitha Karunanithi else 3935cb1dd27SAsmitha Karunanithi { 3945cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 3955cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 3965cb1dd27SAsmitha Karunanithi return; 3975cb1dd27SAsmitha Karunanithi } 3985cb1dd27SAsmitha Karunanithi 3995cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 4005cb1dd27SAsmitha Karunanithi [asyncResp, dumpPath, dumpType](const boost::system::error_code ec, 4015cb1dd27SAsmitha Karunanithi GetManagedObjectsType& resp) { 4025cb1dd27SAsmitha Karunanithi if (ec) 4035cb1dd27SAsmitha Karunanithi { 4045cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4055cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4065cb1dd27SAsmitha Karunanithi return; 4075cb1dd27SAsmitha Karunanithi } 4085cb1dd27SAsmitha Karunanithi 4095cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4105cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 411b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 412b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 413b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 414b47452b2SAsmitha Karunanithi "/entry/"; 4155cb1dd27SAsmitha Karunanithi 4165cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4175cb1dd27SAsmitha Karunanithi { 418b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 4195cb1dd27SAsmitha Karunanithi { 4205cb1dd27SAsmitha Karunanithi continue; 4215cb1dd27SAsmitha Karunanithi } 4225cb1dd27SAsmitha Karunanithi std::time_t timestamp; 4235cb1dd27SAsmitha Karunanithi uint64_t size = 0; 4245cb1dd27SAsmitha Karunanithi entriesArray.push_back({}); 4255cb1dd27SAsmitha Karunanithi nlohmann::json& thisEntry = entriesArray.back(); 4262dfd18efSEd Tanous 4272dfd18efSEd Tanous std::string entryID = object.first.filename(); 4282dfd18efSEd Tanous if (entryID.empty()) 4295cb1dd27SAsmitha Karunanithi { 4305cb1dd27SAsmitha Karunanithi continue; 4315cb1dd27SAsmitha Karunanithi } 4325cb1dd27SAsmitha Karunanithi 4335cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4345cb1dd27SAsmitha Karunanithi { 4355cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 4365cb1dd27SAsmitha Karunanithi { 4375cb1dd27SAsmitha Karunanithi 4385cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4395cb1dd27SAsmitha Karunanithi { 4405cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4415cb1dd27SAsmitha Karunanithi { 4425cb1dd27SAsmitha Karunanithi auto sizePtr = 4435cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4445cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4455cb1dd27SAsmitha Karunanithi { 4465cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4475cb1dd27SAsmitha Karunanithi break; 4485cb1dd27SAsmitha Karunanithi } 4495cb1dd27SAsmitha Karunanithi size = *sizePtr; 4505cb1dd27SAsmitha Karunanithi break; 4515cb1dd27SAsmitha Karunanithi } 4525cb1dd27SAsmitha Karunanithi } 4535cb1dd27SAsmitha Karunanithi } 4545cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4555cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 4565cb1dd27SAsmitha Karunanithi { 4575cb1dd27SAsmitha Karunanithi 4585cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4595cb1dd27SAsmitha Karunanithi { 4605cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 4615cb1dd27SAsmitha Karunanithi { 4625cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 4635cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4645cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 4655cb1dd27SAsmitha Karunanithi { 4665cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4675cb1dd27SAsmitha Karunanithi break; 4685cb1dd27SAsmitha Karunanithi } 4695cb1dd27SAsmitha Karunanithi timestamp = 4705cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 4715cb1dd27SAsmitha Karunanithi break; 4725cb1dd27SAsmitha Karunanithi } 4735cb1dd27SAsmitha Karunanithi } 4745cb1dd27SAsmitha Karunanithi } 4755cb1dd27SAsmitha Karunanithi } 4765cb1dd27SAsmitha Karunanithi 477d0dbeefdSEd Tanous thisEntry["@odata.type"] = "#LogEntry.v1_7_0.LogEntry"; 4785cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 4795cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 4805cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 4815cb1dd27SAsmitha Karunanithi thisEntry["Created"] = crow::utility::getDateTime(timestamp); 4825cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 4835cb1dd27SAsmitha Karunanithi 484d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataSizeBytes"] = size; 4855cb1dd27SAsmitha Karunanithi 4865cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 4875cb1dd27SAsmitha Karunanithi { 488d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 489d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 490de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 491de8d94a3SAbhishek Patel entryID + "/attachment"; 4925cb1dd27SAsmitha Karunanithi } 4935cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 4945cb1dd27SAsmitha Karunanithi { 495d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 496d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 497d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 498de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 499de8d94a3SAbhishek Patel entryID + "/attachment"; 5005cb1dd27SAsmitha Karunanithi } 5015cb1dd27SAsmitha Karunanithi } 5025cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 5035cb1dd27SAsmitha Karunanithi entriesArray.size(); 5045cb1dd27SAsmitha Karunanithi }, 5055cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5065cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5075cb1dd27SAsmitha Karunanithi } 5085cb1dd27SAsmitha Karunanithi 5098d1b46d7Szhanghch05 inline void 5108d1b46d7Szhanghch05 getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5118d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 5125cb1dd27SAsmitha Karunanithi { 5135cb1dd27SAsmitha Karunanithi std::string dumpPath; 5145cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5155cb1dd27SAsmitha Karunanithi { 5165cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5175cb1dd27SAsmitha Karunanithi } 5185cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5195cb1dd27SAsmitha Karunanithi { 5205cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5215cb1dd27SAsmitha Karunanithi } 5225cb1dd27SAsmitha Karunanithi else 5235cb1dd27SAsmitha Karunanithi { 5245cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5255cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5265cb1dd27SAsmitha Karunanithi return; 5275cb1dd27SAsmitha Karunanithi } 5285cb1dd27SAsmitha Karunanithi 5295cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 5305cb1dd27SAsmitha Karunanithi [asyncResp, entryID, dumpPath, dumpType]( 5315cb1dd27SAsmitha Karunanithi const boost::system::error_code ec, GetManagedObjectsType& resp) { 5325cb1dd27SAsmitha Karunanithi if (ec) 5335cb1dd27SAsmitha Karunanithi { 5345cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5355cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5365cb1dd27SAsmitha Karunanithi return; 5375cb1dd27SAsmitha Karunanithi } 5385cb1dd27SAsmitha Karunanithi 539b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 540b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 541b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 542b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 543b47452b2SAsmitha Karunanithi "/entry/"; 544b47452b2SAsmitha Karunanithi 5455cb1dd27SAsmitha Karunanithi for (auto& objectPath : resp) 5465cb1dd27SAsmitha Karunanithi { 547b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5485cb1dd27SAsmitha Karunanithi { 5495cb1dd27SAsmitha Karunanithi continue; 5505cb1dd27SAsmitha Karunanithi } 5515cb1dd27SAsmitha Karunanithi 5525cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 5535cb1dd27SAsmitha Karunanithi std::time_t timestamp; 5545cb1dd27SAsmitha Karunanithi uint64_t size = 0; 5555cb1dd27SAsmitha Karunanithi 5565cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 5575cb1dd27SAsmitha Karunanithi { 5585cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 5595cb1dd27SAsmitha Karunanithi { 5605cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 5615cb1dd27SAsmitha Karunanithi { 5625cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 5635cb1dd27SAsmitha Karunanithi { 5645cb1dd27SAsmitha Karunanithi auto sizePtr = 5655cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5665cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 5675cb1dd27SAsmitha Karunanithi { 5685cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5695cb1dd27SAsmitha Karunanithi break; 5705cb1dd27SAsmitha Karunanithi } 5715cb1dd27SAsmitha Karunanithi size = *sizePtr; 5725cb1dd27SAsmitha Karunanithi break; 5735cb1dd27SAsmitha Karunanithi } 5745cb1dd27SAsmitha Karunanithi } 5755cb1dd27SAsmitha Karunanithi } 5765cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 5775cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 5785cb1dd27SAsmitha Karunanithi { 5795cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 5805cb1dd27SAsmitha Karunanithi { 5815cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 5825cb1dd27SAsmitha Karunanithi { 5835cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 5845cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5855cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 5865cb1dd27SAsmitha Karunanithi { 5875cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5885cb1dd27SAsmitha Karunanithi break; 5895cb1dd27SAsmitha Karunanithi } 5905cb1dd27SAsmitha Karunanithi timestamp = 5915cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 5925cb1dd27SAsmitha Karunanithi break; 5935cb1dd27SAsmitha Karunanithi } 5945cb1dd27SAsmitha Karunanithi } 5955cb1dd27SAsmitha Karunanithi } 5965cb1dd27SAsmitha Karunanithi } 5975cb1dd27SAsmitha Karunanithi 5985cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 599d0dbeefdSEd Tanous "#LogEntry.v1_7_0.LogEntry"; 6005cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6015cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6025cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6035cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6045cb1dd27SAsmitha Karunanithi crow::utility::getDateTime(timestamp); 6055cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6065cb1dd27SAsmitha Karunanithi 607d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6085cb1dd27SAsmitha Karunanithi 6095cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6105cb1dd27SAsmitha Karunanithi { 611d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 612d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 613de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 614de8d94a3SAbhishek Patel entryID + "/attachment"; 6155cb1dd27SAsmitha Karunanithi } 6165cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6175cb1dd27SAsmitha Karunanithi { 618d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 619d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["OEMDiagnosticDataType"] = 6205cb1dd27SAsmitha Karunanithi "System"; 621d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 622de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 623de8d94a3SAbhishek Patel entryID + "/attachment"; 6245cb1dd27SAsmitha Karunanithi } 6255cb1dd27SAsmitha Karunanithi } 626b47452b2SAsmitha Karunanithi if (foundDumpEntry == false) 627b47452b2SAsmitha Karunanithi { 628b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 629b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 630b47452b2SAsmitha Karunanithi return; 631b47452b2SAsmitha Karunanithi } 6325cb1dd27SAsmitha Karunanithi }, 6335cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6345cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6355cb1dd27SAsmitha Karunanithi } 6365cb1dd27SAsmitha Karunanithi 6378d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6389878256fSStanley Chu const std::string& entryID, 639b47452b2SAsmitha Karunanithi const std::string& dumpType) 6405cb1dd27SAsmitha Karunanithi { 6413de8d8baSGeorge Liu auto respHandler = [asyncResp, 6423de8d8baSGeorge Liu entryID](const boost::system::error_code ec) { 6435cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6445cb1dd27SAsmitha Karunanithi if (ec) 6455cb1dd27SAsmitha Karunanithi { 6463de8d8baSGeorge Liu if (ec.value() == EBADR) 6473de8d8baSGeorge Liu { 6483de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 6493de8d8baSGeorge Liu return; 6503de8d8baSGeorge Liu } 6515cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 6525cb1dd27SAsmitha Karunanithi << ec; 6535cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6545cb1dd27SAsmitha Karunanithi return; 6555cb1dd27SAsmitha Karunanithi } 6565cb1dd27SAsmitha Karunanithi }; 6575cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 6585cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 659b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 660b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 661b47452b2SAsmitha Karunanithi entryID, 6625cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 6635cb1dd27SAsmitha Karunanithi } 6645cb1dd27SAsmitha Karunanithi 6658d1b46d7Szhanghch05 inline void 6668d1b46d7Szhanghch05 createDumpTaskCallback(const crow::Request& req, 6678d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6688d1b46d7Szhanghch05 const uint32_t& dumpId, const std::string& dumpPath, 669a43be80fSAsmitha Karunanithi const std::string& dumpType) 670a43be80fSAsmitha Karunanithi { 671a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 6726145ed6fSAsmitha Karunanithi [dumpId, dumpPath, dumpType]( 673a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 674a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 675cb13a392SEd Tanous if (err) 676cb13a392SEd Tanous { 6776145ed6fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Error in creating a dump"; 6786145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 6796145ed6fSAsmitha Karunanithi return task::completed; 680cb13a392SEd Tanous } 681a43be80fSAsmitha Karunanithi std::vector<std::pair< 682a43be80fSAsmitha Karunanithi std::string, 683a43be80fSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string>>>>> 684a43be80fSAsmitha Karunanithi interfacesList; 685a43be80fSAsmitha Karunanithi 686a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 687a43be80fSAsmitha Karunanithi 688a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 689a43be80fSAsmitha Karunanithi 690b47452b2SAsmitha Karunanithi if (objPath.str == 691b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 692b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 693b47452b2SAsmitha Karunanithi "/entry/" + std::to_string(dumpId)) 694a43be80fSAsmitha Karunanithi { 695a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 696a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 697a43be80fSAsmitha Karunanithi 698a43be80fSAsmitha Karunanithi std::string headerLoc = 699a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 700a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 701a43be80fSAsmitha Karunanithi std::move(headerLoc)); 702a43be80fSAsmitha Karunanithi 703a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 704b47452b2SAsmitha Karunanithi return task::completed; 7056145ed6fSAsmitha Karunanithi } 706a43be80fSAsmitha Karunanithi return task::completed; 707a43be80fSAsmitha Karunanithi }, 708a43be80fSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus." 709a43be80fSAsmitha Karunanithi "ObjectManager'," 710a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 711a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 712a43be80fSAsmitha Karunanithi 713a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 714a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 715a43be80fSAsmitha Karunanithi task->payload.emplace(req); 716a43be80fSAsmitha Karunanithi } 717a43be80fSAsmitha Karunanithi 7188d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7198d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 720a43be80fSAsmitha Karunanithi { 721a43be80fSAsmitha Karunanithi 722a43be80fSAsmitha Karunanithi std::string dumpPath; 723a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 724a43be80fSAsmitha Karunanithi { 725a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 726a43be80fSAsmitha Karunanithi } 727a43be80fSAsmitha Karunanithi else if (dumpType == "System") 728a43be80fSAsmitha Karunanithi { 729a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 730a43be80fSAsmitha Karunanithi } 731a43be80fSAsmitha Karunanithi else 732a43be80fSAsmitha Karunanithi { 733a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 734a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 735a43be80fSAsmitha Karunanithi return; 736a43be80fSAsmitha Karunanithi } 737a43be80fSAsmitha Karunanithi 738a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 739a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 740a43be80fSAsmitha Karunanithi 741a43be80fSAsmitha Karunanithi if (!redfish::json_util::readJson( 742a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 743a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 744a43be80fSAsmitha Karunanithi { 745a43be80fSAsmitha Karunanithi return; 746a43be80fSAsmitha Karunanithi } 747a43be80fSAsmitha Karunanithi 748a43be80fSAsmitha Karunanithi if (dumpType == "System") 749a43be80fSAsmitha Karunanithi { 750a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 751a43be80fSAsmitha Karunanithi { 752a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 753a43be80fSAsmitha Karunanithi "'DiagnosticDataType'/" 754a43be80fSAsmitha Karunanithi "'OEMDiagnosticDataType' value not found!"; 755a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 756a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 757a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 758a43be80fSAsmitha Karunanithi return; 759a43be80fSAsmitha Karunanithi } 7603174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 761a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 762a43be80fSAsmitha Karunanithi { 763a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 764a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 765a43be80fSAsmitha Karunanithi "System Dump creation parameters"); 766a43be80fSAsmitha Karunanithi return; 767a43be80fSAsmitha Karunanithi } 768a43be80fSAsmitha Karunanithi } 769a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 770a43be80fSAsmitha Karunanithi { 771a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 772a43be80fSAsmitha Karunanithi { 773a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 774a43be80fSAsmitha Karunanithi "'DiagnosticDataType' not found!"; 775a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 776a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 777a43be80fSAsmitha Karunanithi return; 778a43be80fSAsmitha Karunanithi } 7793174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 780a43be80fSAsmitha Karunanithi { 781a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 782a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 783a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 784a43be80fSAsmitha Karunanithi "BMC Dump creation parameters"); 785a43be80fSAsmitha Karunanithi return; 786a43be80fSAsmitha Karunanithi } 787a43be80fSAsmitha Karunanithi } 788a43be80fSAsmitha Karunanithi 789a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 790a43be80fSAsmitha Karunanithi [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec, 791a43be80fSAsmitha Karunanithi const uint32_t& dumpId) { 792a43be80fSAsmitha Karunanithi if (ec) 793a43be80fSAsmitha Karunanithi { 794a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 795a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 796a43be80fSAsmitha Karunanithi return; 797a43be80fSAsmitha Karunanithi } 798a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 799a43be80fSAsmitha Karunanithi 800a43be80fSAsmitha Karunanithi createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType); 801a43be80fSAsmitha Karunanithi }, 802b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 803b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 804b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 805a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 806a43be80fSAsmitha Karunanithi } 807a43be80fSAsmitha Karunanithi 8088d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8098d1b46d7Szhanghch05 const std::string& dumpType) 81080319af1SAsmitha Karunanithi { 811b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 812b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 8138d1b46d7Szhanghch05 81480319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 815b47452b2SAsmitha Karunanithi [asyncResp, dumpType](const boost::system::error_code ec, 81680319af1SAsmitha Karunanithi const std::vector<std::string>& subTreePaths) { 81780319af1SAsmitha Karunanithi if (ec) 81880319af1SAsmitha Karunanithi { 81980319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 82080319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 82180319af1SAsmitha Karunanithi return; 82280319af1SAsmitha Karunanithi } 82380319af1SAsmitha Karunanithi 82480319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 82580319af1SAsmitha Karunanithi { 8262dfd18efSEd Tanous sdbusplus::message::object_path objPath(path); 8272dfd18efSEd Tanous std::string logID = objPath.filename(); 8282dfd18efSEd Tanous if (logID.empty()) 82980319af1SAsmitha Karunanithi { 8302dfd18efSEd Tanous continue; 83180319af1SAsmitha Karunanithi } 8322dfd18efSEd Tanous deleteDumpEntry(asyncResp, logID, dumpType); 83380319af1SAsmitha Karunanithi } 83480319af1SAsmitha Karunanithi }, 83580319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 83680319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 83780319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 838b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, 839b47452b2SAsmitha Karunanithi std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." + 840b47452b2SAsmitha Karunanithi dumpType}); 84180319af1SAsmitha Karunanithi } 84280319af1SAsmitha Karunanithi 8437e860f15SJohn Edward Broadbent inline static void parseCrashdumpParameters( 844043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params, 845043a0536SJohnathan Mantey std::string& filename, std::string& timestamp, std::string& logfile) 846043a0536SJohnathan Mantey { 847043a0536SJohnathan Mantey for (auto property : params) 848043a0536SJohnathan Mantey { 849043a0536SJohnathan Mantey if (property.first == "Timestamp") 850043a0536SJohnathan Mantey { 851043a0536SJohnathan Mantey const std::string* value = 8528d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 853043a0536SJohnathan Mantey if (value != nullptr) 854043a0536SJohnathan Mantey { 855043a0536SJohnathan Mantey timestamp = *value; 856043a0536SJohnathan Mantey } 857043a0536SJohnathan Mantey } 858043a0536SJohnathan Mantey else if (property.first == "Filename") 859043a0536SJohnathan Mantey { 860043a0536SJohnathan Mantey const std::string* value = 8618d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 862043a0536SJohnathan Mantey if (value != nullptr) 863043a0536SJohnathan Mantey { 864043a0536SJohnathan Mantey filename = *value; 865043a0536SJohnathan Mantey } 866043a0536SJohnathan Mantey } 867043a0536SJohnathan Mantey else if (property.first == "Log") 868043a0536SJohnathan Mantey { 869043a0536SJohnathan Mantey const std::string* value = 8708d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 871043a0536SJohnathan Mantey if (value != nullptr) 872043a0536SJohnathan Mantey { 873043a0536SJohnathan Mantey logfile = *value; 874043a0536SJohnathan Mantey } 875043a0536SJohnathan Mantey } 876043a0536SJohnathan Mantey } 877043a0536SJohnathan Mantey } 878043a0536SJohnathan Mantey 879a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 8807e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 8811da66f75SEd Tanous { 882c4bf6374SJason M. Bills /** 883c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 884c4bf6374SJason M. Bills */ 8857e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/") 886ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 8877e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 8887e860f15SJohn Edward Broadbent [](const crow::Request&, 8897e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 8907e860f15SJohn Edward Broadbent 891c4bf6374SJason M. Bills { 8927e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 8937e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 894c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 895c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 896c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 897029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 8987e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 8997e860f15SJohn Edward Broadbent "System Log Services Collection"; 900c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 901c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 9027e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 9037e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 904c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 905029573d4SEd Tanous logServiceArray.push_back( 9067e860f15SJohn Edward Broadbent {{"@odata.id", 9077e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog"}}); 9085cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 909c9bb6861Sraviteja-b logServiceArray.push_back( 9107e860f15SJohn Edward Broadbent {{"@odata.id", 9117e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump"}}); 912c9bb6861Sraviteja-b #endif 913c9bb6861Sraviteja-b 914d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 915d53dd41fSJason M. Bills logServiceArray.push_back( 916cb92c03bSAndrew Geissler {{"@odata.id", 917424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 918d53dd41fSJason M. Bills #endif 919c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 920c4bf6374SJason M. Bills logServiceArray.size(); 921a3316fc6SZhikuiRen 922a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 923a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 924a3316fc6SZhikuiRen const std::vector<std::string>& subtreePath) { 925a3316fc6SZhikuiRen if (ec) 926a3316fc6SZhikuiRen { 927a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 928a3316fc6SZhikuiRen return; 929a3316fc6SZhikuiRen } 930a3316fc6SZhikuiRen 931a3316fc6SZhikuiRen for (auto& pathStr : subtreePath) 932a3316fc6SZhikuiRen { 933a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 934a3316fc6SZhikuiRen { 93523a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 936a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 93723a21a1cSEd Tanous logServiceArrayLocal.push_back( 938a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 939a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 9407e860f15SJohn Edward Broadbent asyncResp->res 9417e860f15SJohn Edward Broadbent .jsonValue["Members@odata.count"] = 94223a21a1cSEd Tanous logServiceArrayLocal.size(); 943a3316fc6SZhikuiRen return; 944a3316fc6SZhikuiRen } 945a3316fc6SZhikuiRen } 946a3316fc6SZhikuiRen }, 947a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 948a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 9497e860f15SJohn Edward Broadbent "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 9507e860f15SJohn Edward Broadbent 0, std::array<const char*, 1>{postCodeIface}); 9517e860f15SJohn Edward Broadbent }); 952c4bf6374SJason M. Bills } 953c4bf6374SJason M. Bills 9547e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 955c4bf6374SJason M. Bills { 9567e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 957ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 9587e860f15SJohn Edward Broadbent .methods( 9597e860f15SJohn Edward Broadbent boost::beast::http::verb:: 9607e860f15SJohn Edward Broadbent get)([](const crow::Request&, 9617e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 962c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 963029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 964c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 965c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 966c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 9677e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 9687e860f15SJohn Edward Broadbent "System Event Log Service"; 969c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 970c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 9717c8c4058STejas Patil 9727c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 9737c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 9747c8c4058STejas Patil 9757c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 9767c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 9777c8c4058STejas Patil redfishDateTimeOffset.second; 9787c8c4058STejas Patil 979c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 980c4bf6374SJason M. Bills {"@odata.id", 981029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 982e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 983e7d6c8b2SGunnar Mills 984e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 985e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 9867e860f15SJohn Edward Broadbent }); 987489640c6SJason M. Bills } 988489640c6SJason M. Bills 9897e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 990489640c6SJason M. Bills { 9917e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 992489640c6SJason M. Bills "LogService.ClearLog/") 993432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 9947e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 9957e860f15SJohn Edward Broadbent [](const crow::Request&, 9967e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 997489640c6SJason M. Bills // Clear the EventLog by deleting the log files 998489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 999489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1000489640c6SJason M. Bills { 1001489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1002489640c6SJason M. Bills { 1003489640c6SJason M. Bills std::error_code ec; 1004489640c6SJason M. Bills std::filesystem::remove(file, ec); 1005489640c6SJason M. Bills } 1006489640c6SJason M. Bills } 1007489640c6SJason M. Bills 1008489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1009489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1010489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1011489640c6SJason M. Bills if (ec) 1012489640c6SJason M. Bills { 10137e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " 10147e860f15SJohn Edward Broadbent << ec; 1015489640c6SJason M. Bills messages::internalError(asyncResp->res); 1016489640c6SJason M. Bills return; 1017489640c6SJason M. Bills } 1018489640c6SJason M. Bills 1019489640c6SJason M. Bills messages::success(asyncResp->res); 1020489640c6SJason M. Bills }, 1021489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 10227e860f15SJohn Edward Broadbent "org.freedesktop.systemd1.Manager", "ReloadUnit", 10237e860f15SJohn Edward Broadbent "rsyslog.service", "replace"); 10247e860f15SJohn Edward Broadbent }); 1025c4bf6374SJason M. Bills } 1026c4bf6374SJason M. Bills 102795820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 1028b5a76932SEd Tanous const std::string& logEntry, 102995820184SJason M. Bills nlohmann::json& logEntryJson) 1030c4bf6374SJason M. Bills { 103195820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1032cd225da8SJason M. Bills // First get the Timestamp 1033f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1034cd225da8SJason M. Bills if (space == std::string::npos) 103595820184SJason M. Bills { 103695820184SJason M. Bills return 1; 103795820184SJason M. Bills } 1038cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1039cd225da8SJason M. Bills // Then get the log contents 1040f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1041cd225da8SJason M. Bills if (entryStart == std::string::npos) 1042cd225da8SJason M. Bills { 1043cd225da8SJason M. Bills return 1; 1044cd225da8SJason M. Bills } 1045cd225da8SJason M. Bills std::string_view entry(logEntry); 1046cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1047cd225da8SJason M. Bills // Use split to separate the entry into its fields 1048cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1049cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1050cd225da8SJason M. Bills boost::token_compress_on); 1051cd225da8SJason M. Bills // We need at least a MessageId to be valid 1052cd225da8SJason M. Bills if (logEntryFields.size() < 1) 1053cd225da8SJason M. Bills { 1054cd225da8SJason M. Bills return 1; 1055cd225da8SJason M. Bills } 1056cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 105795820184SJason M. Bills 10584851d45dSJason M. Bills // Get the Message from the MessageRegistry 10594851d45dSJason M. Bills const message_registries::Message* message = 10604851d45dSJason M. Bills message_registries::getMessage(messageID); 1061c4bf6374SJason M. Bills 10624851d45dSJason M. Bills std::string msg; 10634851d45dSJason M. Bills std::string severity; 10644851d45dSJason M. Bills if (message != nullptr) 1065c4bf6374SJason M. Bills { 10664851d45dSJason M. Bills msg = message->message; 10674851d45dSJason M. Bills severity = message->severity; 1068c4bf6374SJason M. Bills } 1069c4bf6374SJason M. Bills 107015a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 107115a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 107215a86ff6SJason M. Bills if (logEntryFields.size() > 1) 107315a86ff6SJason M. Bills { 107415a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 107515a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 107615a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 107715a86ff6SJason M. Bills if (!messageArgsStart.empty()) 107815a86ff6SJason M. Bills { 107915a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 108015a86ff6SJason M. Bills } 108115a86ff6SJason M. Bills 108223a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1083c4bf6374SJason M. Bills 10844851d45dSJason M. Bills // Fill the MessageArgs into the Message 108595820184SJason M. Bills int i = 0; 108695820184SJason M. Bills for (const std::string& messageArg : messageArgs) 10874851d45dSJason M. Bills { 108895820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 10894851d45dSJason M. Bills size_t argPos = msg.find(argStr); 10904851d45dSJason M. Bills if (argPos != std::string::npos) 10914851d45dSJason M. Bills { 109295820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 10934851d45dSJason M. Bills } 10944851d45dSJason M. Bills } 109515a86ff6SJason M. Bills } 10964851d45dSJason M. Bills 109795820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 109895820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 109995820184SJason M. Bills // between the '.' and the '+', so just remove them. 1100f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1101f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 110295820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1103c4bf6374SJason M. Bills { 110495820184SJason M. Bills timestamp.erase(dot, plus - dot); 1105c4bf6374SJason M. Bills } 1106c4bf6374SJason M. Bills 1107c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 110895820184SJason M. Bills logEntryJson = { 1109d0dbeefdSEd Tanous {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1110029573d4SEd Tanous {"@odata.id", 1111897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 111295820184SJason M. Bills logEntryID}, 1113c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 111495820184SJason M. Bills {"Id", logEntryID}, 111595820184SJason M. Bills {"Message", std::move(msg)}, 111695820184SJason M. Bills {"MessageId", std::move(messageID)}, 1117f23b7296SEd Tanous {"MessageArgs", messageArgs}, 1118c4bf6374SJason M. Bills {"EntryType", "Event"}, 111995820184SJason M. Bills {"Severity", std::move(severity)}, 112095820184SJason M. Bills {"Created", std::move(timestamp)}}; 1121c4bf6374SJason M. Bills return 0; 1122c4bf6374SJason M. Bills } 1123c4bf6374SJason M. Bills 11247e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1125c4bf6374SJason M. Bills { 11267e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 11277e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 11288b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 11297e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 11307e860f15SJohn Edward Broadbent [](const crow::Request& req, 11317e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1132271584abSEd Tanous uint64_t skip = 0; 1133271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 11348d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 1135c4bf6374SJason M. Bills { 1136c4bf6374SJason M. Bills return; 1137c4bf6374SJason M. Bills } 11388d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 1139c4bf6374SJason M. Bills { 1140c4bf6374SJason M. Bills return; 1141c4bf6374SJason M. Bills } 11427e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 11437e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1144c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1145c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1146c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1147029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1148c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1149c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1150c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1151cb92c03bSAndrew Geissler 11527e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 11537e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 1154c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 11557e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 11567e860f15SJohn Edward Broadbent // entry 115795820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 115895820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1159b01bf299SEd Tanous uint64_t entryCount = 0; 1160cd225da8SJason M. Bills std::string logEntry; 116195820184SJason M. Bills 11627e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 11637e860f15SJohn Edward Broadbent // backwards 11647e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 11657e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1166c4bf6374SJason M. Bills { 1167cd225da8SJason M. Bills std::ifstream logStream(*it); 116895820184SJason M. Bills if (!logStream.is_open()) 1169c4bf6374SJason M. Bills { 1170c4bf6374SJason M. Bills continue; 1171c4bf6374SJason M. Bills } 1172c4bf6374SJason M. Bills 1173e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1174e85d6b16SJason M. Bills bool firstEntry = true; 117595820184SJason M. Bills while (std::getline(logStream, logEntry)) 117695820184SJason M. Bills { 1177c4bf6374SJason M. Bills entryCount++; 11787e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip 11797e860f15SJohn Edward Broadbent // from the start) and top (number of entries to 11807e860f15SJohn Edward Broadbent // display) 1181c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1182c4bf6374SJason M. Bills { 1183c4bf6374SJason M. Bills continue; 1184c4bf6374SJason M. Bills } 1185c4bf6374SJason M. Bills 1186c4bf6374SJason M. Bills std::string idStr; 1187e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1188c4bf6374SJason M. Bills { 1189c4bf6374SJason M. Bills continue; 1190c4bf6374SJason M. Bills } 1191c4bf6374SJason M. Bills 1192e85d6b16SJason M. Bills if (firstEntry) 1193e85d6b16SJason M. Bills { 1194e85d6b16SJason M. Bills firstEntry = false; 1195e85d6b16SJason M. Bills } 1196e85d6b16SJason M. Bills 1197c4bf6374SJason M. Bills logEntryArray.push_back({}); 1198c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 11997e860f15SJohn Edward Broadbent if (fillEventLogEntryJson(idStr, logEntry, 12007e860f15SJohn Edward Broadbent bmcLogEntry) != 0) 1201c4bf6374SJason M. Bills { 1202c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1203c4bf6374SJason M. Bills return; 1204c4bf6374SJason M. Bills } 1205c4bf6374SJason M. Bills } 120695820184SJason M. Bills } 1207c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1208c4bf6374SJason M. Bills if (skip + top < entryCount) 1209c4bf6374SJason M. Bills { 1210c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 121195820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 121295820184SJason M. Bills "Entries?$skip=" + 1213c4bf6374SJason M. Bills std::to_string(skip + top); 1214c4bf6374SJason M. Bills } 12157e860f15SJohn Edward Broadbent }); 1216897967deSJason M. Bills } 1217897967deSJason M. Bills 12187e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1219897967deSJason M. Bills { 12207e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 12217e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1222ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 12237e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 12247e860f15SJohn Edward Broadbent [](const crow::Request&, 12257e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12267e860f15SJohn Edward Broadbent const std::string& param) { 12277e860f15SJohn Edward Broadbent const std::string& targetID = param; 12288d1b46d7Szhanghch05 12297e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 12307e860f15SJohn Edward Broadbent // entry to find the target entry 1231897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1232897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1233897967deSJason M. Bills std::string logEntry; 1234897967deSJason M. Bills 12357e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12367e860f15SJohn Edward Broadbent // backwards 12377e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 12387e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1239897967deSJason M. Bills { 1240897967deSJason M. Bills std::ifstream logStream(*it); 1241897967deSJason M. Bills if (!logStream.is_open()) 1242897967deSJason M. Bills { 1243897967deSJason M. Bills continue; 1244897967deSJason M. Bills } 1245897967deSJason M. Bills 1246897967deSJason M. Bills // Reset the unique ID on the first entry 1247897967deSJason M. Bills bool firstEntry = true; 1248897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1249897967deSJason M. Bills { 1250897967deSJason M. Bills std::string idStr; 1251897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1252897967deSJason M. Bills { 1253897967deSJason M. Bills continue; 1254897967deSJason M. Bills } 1255897967deSJason M. Bills 1256897967deSJason M. Bills if (firstEntry) 1257897967deSJason M. Bills { 1258897967deSJason M. Bills firstEntry = false; 1259897967deSJason M. Bills } 1260897967deSJason M. Bills 1261897967deSJason M. Bills if (idStr == targetID) 1262897967deSJason M. Bills { 12637e860f15SJohn Edward Broadbent if (fillEventLogEntryJson( 12647e860f15SJohn Edward Broadbent idStr, logEntry, 1265897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1266897967deSJason M. Bills { 1267897967deSJason M. Bills messages::internalError(asyncResp->res); 1268897967deSJason M. Bills return; 1269897967deSJason M. Bills } 1270897967deSJason M. Bills return; 1271897967deSJason M. Bills } 1272897967deSJason M. Bills } 1273897967deSJason M. Bills } 1274897967deSJason M. Bills // Requested ID was not found 1275897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 12767e860f15SJohn Edward Broadbent }); 127708a4e4b5SAnthony Wilson } 127808a4e4b5SAnthony Wilson 12797e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 128008a4e4b5SAnthony Wilson { 12817e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 12827e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1283ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 12847e860f15SJohn Edward Broadbent .methods( 12857e860f15SJohn Edward Broadbent boost::beast::http::verb:: 12867e860f15SJohn Edward Broadbent get)([](const crow::Request&, 12877e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 12887e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 12897e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 129008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 129108a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 129208a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 129308a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 129408a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 129508a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 129608a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 129708a4e4b5SAnthony Wilson 1298cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1299cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1300cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1301cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1302cb92c03bSAndrew Geissler GetManagedObjectsType& resp) { 1303cb92c03bSAndrew Geissler if (ec) 1304cb92c03bSAndrew Geissler { 1305cb92c03bSAndrew Geissler // TODO Handle for specific error code 1306cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1307cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1308cb92c03bSAndrew Geissler << ec; 1309cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1310cb92c03bSAndrew Geissler return; 1311cb92c03bSAndrew Geissler } 1312cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1313cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1314cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 1315cb92c03bSAndrew Geissler for (auto& objectPath : resp) 1316cb92c03bSAndrew Geissler { 131766664f25SEd Tanous uint32_t* id = nullptr; 131866664f25SEd Tanous std::time_t timestamp{}; 1319d139c236SGeorge Liu std::time_t updateTimestamp{}; 132066664f25SEd Tanous std::string* severity = nullptr; 132166664f25SEd Tanous std::string* message = nullptr; 1322f86bb901SAdriana Kobylak std::string* filePath = nullptr; 132375710de2SXiaochao Ma bool resolved = false; 1324f86bb901SAdriana Kobylak for (auto& interfaceMap : objectPath.second) 1325f86bb901SAdriana Kobylak { 1326f86bb901SAdriana Kobylak if (interfaceMap.first == 1327f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1328f86bb901SAdriana Kobylak { 1329cb92c03bSAndrew Geissler for (auto& propertyMap : interfaceMap.second) 1330cb92c03bSAndrew Geissler { 1331cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1332cb92c03bSAndrew Geissler { 1333f86bb901SAdriana Kobylak id = std::get_if<uint32_t>( 1334f86bb901SAdriana Kobylak &propertyMap.second); 1335cb92c03bSAndrew Geissler } 1336cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1337cb92c03bSAndrew Geissler { 1338cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1339f86bb901SAdriana Kobylak std::get_if<uint64_t>( 1340f86bb901SAdriana Kobylak &propertyMap.second); 1341ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1342ebd45906SGeorge Liu { 13437e860f15SJohn Edward Broadbent timestamp = 13447e860f15SJohn Edward Broadbent crow::utility::getTimestamp( 13457e860f15SJohn Edward Broadbent *millisTimeStamp); 13467e860f15SJohn Edward Broadbent } 13477e860f15SJohn Edward Broadbent } 13487e860f15SJohn Edward Broadbent else if (propertyMap.first == 13497e860f15SJohn Edward Broadbent "UpdateTimestamp") 13507e860f15SJohn Edward Broadbent { 13517e860f15SJohn Edward Broadbent const uint64_t* millisTimeStamp = 13527e860f15SJohn Edward Broadbent std::get_if<uint64_t>( 13537e860f15SJohn Edward Broadbent &propertyMap.second); 13547e860f15SJohn Edward Broadbent if (millisTimeStamp != nullptr) 13557e860f15SJohn Edward Broadbent { 13567e860f15SJohn Edward Broadbent updateTimestamp = 13577e860f15SJohn Edward Broadbent crow::utility::getTimestamp( 13587e860f15SJohn Edward Broadbent *millisTimeStamp); 13597e860f15SJohn Edward Broadbent } 13607e860f15SJohn Edward Broadbent } 13617e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 13627e860f15SJohn Edward Broadbent { 13637e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 13647e860f15SJohn Edward Broadbent &propertyMap.second); 13657e860f15SJohn Edward Broadbent } 13667e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 13677e860f15SJohn Edward Broadbent { 13687e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 13697e860f15SJohn Edward Broadbent &propertyMap.second); 13707e860f15SJohn Edward Broadbent } 13717e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 13727e860f15SJohn Edward Broadbent { 13737e860f15SJohn Edward Broadbent bool* resolveptr = std::get_if<bool>( 13747e860f15SJohn Edward Broadbent &propertyMap.second); 13757e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 13767e860f15SJohn Edward Broadbent { 13777e860f15SJohn Edward Broadbent messages::internalError( 13787e860f15SJohn Edward Broadbent asyncResp->res); 13797e860f15SJohn Edward Broadbent return; 13807e860f15SJohn Edward Broadbent } 13817e860f15SJohn Edward Broadbent resolved = *resolveptr; 13827e860f15SJohn Edward Broadbent } 13837e860f15SJohn Edward Broadbent } 13847e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 13857e860f15SJohn Edward Broadbent severity == nullptr) 13867e860f15SJohn Edward Broadbent { 13877e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 13887e860f15SJohn Edward Broadbent return; 13897e860f15SJohn Edward Broadbent } 13907e860f15SJohn Edward Broadbent } 13917e860f15SJohn Edward Broadbent else if (interfaceMap.first == 13927e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 13937e860f15SJohn Edward Broadbent { 13947e860f15SJohn Edward Broadbent for (auto& propertyMap : interfaceMap.second) 13957e860f15SJohn Edward Broadbent { 13967e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 13977e860f15SJohn Edward Broadbent { 13987e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 13997e860f15SJohn Edward Broadbent &propertyMap.second); 14007e860f15SJohn Edward Broadbent } 14017e860f15SJohn Edward Broadbent } 14027e860f15SJohn Edward Broadbent } 14037e860f15SJohn Edward Broadbent } 14047e860f15SJohn Edward Broadbent // Object path without the 14057e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 14067e860f15SJohn Edward Broadbent // and continue. 14077e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14087e860f15SJohn Edward Broadbent severity == nullptr) 14097e860f15SJohn Edward Broadbent { 14107e860f15SJohn Edward Broadbent continue; 14117e860f15SJohn Edward Broadbent } 14127e860f15SJohn Edward Broadbent entriesArray.push_back({}); 14137e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 14147e860f15SJohn Edward Broadbent thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 14157e860f15SJohn Edward Broadbent thisEntry["@odata.id"] = 14167e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/" 14177e860f15SJohn Edward Broadbent "LogServices/EventLog/Entries/" + 14187e860f15SJohn Edward Broadbent std::to_string(*id); 14197e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 14207e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 14217e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 14227e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 14237e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 14247e860f15SJohn Edward Broadbent thisEntry["Severity"] = 14257e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 14267e860f15SJohn Edward Broadbent thisEntry["Created"] = 14277e860f15SJohn Edward Broadbent crow::utility::getDateTime(timestamp); 14287e860f15SJohn Edward Broadbent thisEntry["Modified"] = 14297e860f15SJohn Edward Broadbent crow::utility::getDateTime(updateTimestamp); 14307e860f15SJohn Edward Broadbent if (filePath != nullptr) 14317e860f15SJohn Edward Broadbent { 14327e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 14337e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/" 14347e860f15SJohn Edward Broadbent "EventLog/" 14357e860f15SJohn Edward Broadbent "Entries/" + 14367e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 14377e860f15SJohn Edward Broadbent } 14387e860f15SJohn Edward Broadbent } 14397e860f15SJohn Edward Broadbent std::sort(entriesArray.begin(), entriesArray.end(), 14407e860f15SJohn Edward Broadbent [](const nlohmann::json& left, 14417e860f15SJohn Edward Broadbent const nlohmann::json& right) { 14427e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 14437e860f15SJohn Edward Broadbent }); 14447e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 14457e860f15SJohn Edward Broadbent entriesArray.size(); 14467e860f15SJohn Edward Broadbent }, 14477e860f15SJohn Edward Broadbent "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 14487e860f15SJohn Edward Broadbent "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 14497e860f15SJohn Edward Broadbent }); 14507e860f15SJohn Edward Broadbent } 14517e860f15SJohn Edward Broadbent 14527e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 14537e860f15SJohn Edward Broadbent { 14547e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 14557e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1456ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 14577e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 14587e860f15SJohn Edward Broadbent [](const crow::Request&, 14597e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 14607e860f15SJohn Edward Broadbent const std::string& param) 14617e860f15SJohn Edward Broadbent 14627e860f15SJohn Edward Broadbent { 14637e860f15SJohn Edward Broadbent std::string entryID = param; 14647e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 14657e860f15SJohn Edward Broadbent 14667e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 14677e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 14687e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 14697e860f15SJohn Edward Broadbent [asyncResp, entryID](const boost::system::error_code ec, 14707e860f15SJohn Edward Broadbent GetManagedPropertyType& resp) { 14717e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 14727e860f15SJohn Edward Broadbent { 14737e860f15SJohn Edward Broadbent messages::resourceNotFound( 14747e860f15SJohn Edward Broadbent asyncResp->res, "EventLogEntry", entryID); 14757e860f15SJohn Edward Broadbent return; 14767e860f15SJohn Edward Broadbent } 14777e860f15SJohn Edward Broadbent if (ec) 14787e860f15SJohn Edward Broadbent { 14797e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "EventLogEntry (DBus) " 14807e860f15SJohn Edward Broadbent "resp_handler got error " 14817e860f15SJohn Edward Broadbent << ec; 14827e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 14837e860f15SJohn Edward Broadbent return; 14847e860f15SJohn Edward Broadbent } 14857e860f15SJohn Edward Broadbent uint32_t* id = nullptr; 14867e860f15SJohn Edward Broadbent std::time_t timestamp{}; 14877e860f15SJohn Edward Broadbent std::time_t updateTimestamp{}; 14887e860f15SJohn Edward Broadbent std::string* severity = nullptr; 14897e860f15SJohn Edward Broadbent std::string* message = nullptr; 14907e860f15SJohn Edward Broadbent std::string* filePath = nullptr; 14917e860f15SJohn Edward Broadbent bool resolved = false; 14927e860f15SJohn Edward Broadbent 14937e860f15SJohn Edward Broadbent for (auto& propertyMap : resp) 14947e860f15SJohn Edward Broadbent { 14957e860f15SJohn Edward Broadbent if (propertyMap.first == "Id") 14967e860f15SJohn Edward Broadbent { 14977e860f15SJohn Edward Broadbent id = std::get_if<uint32_t>(&propertyMap.second); 14987e860f15SJohn Edward Broadbent } 14997e860f15SJohn Edward Broadbent else if (propertyMap.first == "Timestamp") 15007e860f15SJohn Edward Broadbent { 15017e860f15SJohn Edward Broadbent const uint64_t* millisTimeStamp = 15027e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 15037e860f15SJohn Edward Broadbent if (millisTimeStamp != nullptr) 15047e860f15SJohn Edward Broadbent { 1505d139c236SGeorge Liu timestamp = crow::utility::getTimestamp( 1506cb92c03bSAndrew Geissler *millisTimeStamp); 1507d139c236SGeorge Liu } 1508ebd45906SGeorge Liu } 1509d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1510d139c236SGeorge Liu { 1511d139c236SGeorge Liu const uint64_t* millisTimeStamp = 15127e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 1513ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1514ebd45906SGeorge Liu { 1515ebd45906SGeorge Liu updateTimestamp = 1516ebd45906SGeorge Liu crow::utility::getTimestamp( 1517d139c236SGeorge Liu *millisTimeStamp); 1518cb92c03bSAndrew Geissler } 1519ebd45906SGeorge Liu } 1520cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1521cb92c03bSAndrew Geissler { 1522cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1523cb92c03bSAndrew Geissler &propertyMap.second); 1524cb92c03bSAndrew Geissler } 1525cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1526cb92c03bSAndrew Geissler { 1527cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1528cb92c03bSAndrew Geissler &propertyMap.second); 1529ae34c8e8SAdriana Kobylak } 153075710de2SXiaochao Ma else if (propertyMap.first == "Resolved") 153175710de2SXiaochao Ma { 153275710de2SXiaochao Ma bool* resolveptr = 153375710de2SXiaochao Ma std::get_if<bool>(&propertyMap.second); 153475710de2SXiaochao Ma if (resolveptr == nullptr) 153575710de2SXiaochao Ma { 153675710de2SXiaochao Ma messages::internalError(asyncResp->res); 153775710de2SXiaochao Ma return; 153875710de2SXiaochao Ma } 153975710de2SXiaochao Ma resolved = *resolveptr; 154075710de2SXiaochao Ma } 15417e860f15SJohn Edward Broadbent else if (propertyMap.first == "Path") 1542f86bb901SAdriana Kobylak { 1543f86bb901SAdriana Kobylak filePath = std::get_if<std::string>( 1544f86bb901SAdriana Kobylak &propertyMap.second); 1545f86bb901SAdriana Kobylak } 1546f86bb901SAdriana Kobylak } 1547f86bb901SAdriana Kobylak if (id == nullptr || message == nullptr || 1548f86bb901SAdriana Kobylak severity == nullptr) 1549f86bb901SAdriana Kobylak { 1550ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1551271584abSEd Tanous return; 1552271584abSEd Tanous } 1553f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 1554f86bb901SAdriana Kobylak "#LogEntry.v1_8_0.LogEntry"; 1555f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.id"] = 15567e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/" 15577e860f15SJohn Edward Broadbent "Entries/" + 1558f86bb901SAdriana Kobylak std::to_string(*id); 15597e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 15607e860f15SJohn Edward Broadbent "System Event Log Entry"; 1561f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1562f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1563f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 1564f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1565f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1566f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1567f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 1568f86bb901SAdriana Kobylak crow::utility::getDateTime(timestamp); 1569f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 1570f86bb901SAdriana Kobylak crow::utility::getDateTime(updateTimestamp); 1571f86bb901SAdriana Kobylak if (filePath != nullptr) 1572f86bb901SAdriana Kobylak { 1573f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 15747e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/" 15757e860f15SJohn Edward Broadbent "EventLog/" 15767e860f15SJohn Edward Broadbent "attachment/" + 15777e860f15SJohn Edward Broadbent std::to_string(*id); 1578f86bb901SAdriana Kobylak } 1579cb92c03bSAndrew Geissler }, 1580cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1581cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1582f86bb901SAdriana Kobylak "org.freedesktop.DBus.Properties", "GetAll", ""); 15837e860f15SJohn Edward Broadbent }); 1584336e96c6SChicago Duan 15857e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 15867e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1587ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 15887e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 15897e860f15SJohn Edward Broadbent [](const crow::Request& req, 15907e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 15917e860f15SJohn Edward Broadbent const std::string& entryId) { 159275710de2SXiaochao Ma std::optional<bool> resolved; 159375710de2SXiaochao Ma 15947e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "Resolved", 15957e860f15SJohn Edward Broadbent resolved)) 159675710de2SXiaochao Ma { 159775710de2SXiaochao Ma return; 159875710de2SXiaochao Ma } 159975710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 160075710de2SXiaochao Ma 160175710de2SXiaochao Ma crow::connections::systemBus->async_method_call( 16024f48d5f6SEd Tanous [asyncResp, entryId](const boost::system::error_code ec) { 160375710de2SXiaochao Ma if (ec) 160475710de2SXiaochao Ma { 160575710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 160675710de2SXiaochao Ma messages::internalError(asyncResp->res); 160775710de2SXiaochao Ma return; 160875710de2SXiaochao Ma } 160975710de2SXiaochao Ma }, 161075710de2SXiaochao Ma "xyz.openbmc_project.Logging", 161175710de2SXiaochao Ma "/xyz/openbmc_project/logging/entry/" + entryId, 161275710de2SXiaochao Ma "org.freedesktop.DBus.Properties", "Set", 161375710de2SXiaochao Ma "xyz.openbmc_project.Logging.Entry", "Resolved", 161475710de2SXiaochao Ma std::variant<bool>(*resolved)); 16157e860f15SJohn Edward Broadbent }); 161675710de2SXiaochao Ma 16177e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16187e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1619ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1620ed398213SEd Tanous 16217e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 16227e860f15SJohn Edward Broadbent [](const crow::Request&, 16237e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16247e860f15SJohn Edward Broadbent const std::string& param) 16257e860f15SJohn Edward Broadbent 1626336e96c6SChicago Duan { 1627336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1628336e96c6SChicago Duan 16297e860f15SJohn Edward Broadbent std::string entryID = param; 1630336e96c6SChicago Duan 1631336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1632336e96c6SChicago Duan 1633336e96c6SChicago Duan // Process response from Logging service. 16347e860f15SJohn Edward Broadbent auto respHandler = [asyncResp, entryID]( 16357e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 16367e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 16377e860f15SJohn Edward Broadbent << "EventLogEntry (DBus) doDelete callback: Done"; 1638336e96c6SChicago Duan if (ec) 1639336e96c6SChicago Duan { 16403de8d8baSGeorge Liu if (ec.value() == EBADR) 16413de8d8baSGeorge Liu { 16427e860f15SJohn Edward Broadbent messages::resourceNotFound(asyncResp->res, 16437e860f15SJohn Edward Broadbent "LogEntry", entryID); 16443de8d8baSGeorge Liu return; 16453de8d8baSGeorge Liu } 1646336e96c6SChicago Duan // TODO Handle for specific error code 16477e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "EventLogEntry (DBus) doDelete " 16487e860f15SJohn Edward Broadbent "respHandler got error " 1649336e96c6SChicago Duan << ec; 1650336e96c6SChicago Duan asyncResp->res.result( 1651336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1652336e96c6SChicago Duan return; 1653336e96c6SChicago Duan } 1654336e96c6SChicago Duan 1655336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1656336e96c6SChicago Duan }; 1657336e96c6SChicago Duan 1658336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1659336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1660336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1661336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1662336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 16637e860f15SJohn Edward Broadbent }); 1664400fd1fbSAdriana Kobylak } 1665400fd1fbSAdriana Kobylak 16667e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1667400fd1fbSAdriana Kobylak { 16687e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" 16697e860f15SJohn Edward Broadbent "<str>/attachment") 1670ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 16717e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 16727e860f15SJohn Edward Broadbent [](const crow::Request& req, 16737e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16747e860f15SJohn Edward Broadbent const std::string& param) 1675400fd1fbSAdriana Kobylak 16767e860f15SJohn Edward Broadbent { 1677753d034dSEd Tanous std::string_view acceptHeader = req.getHeaderValue("Accept"); 1678753d034dSEd Tanous // The iterators in boost/http/rfc7230.hpp end the string if '/' 1679753d034dSEd Tanous // is found, so replace it with arbitrary character '|' which is 1680753d034dSEd Tanous // not part of the Accept header syntax. 1681753d034dSEd Tanous std::string acceptStr = boost::replace_all_copy( 1682753d034dSEd Tanous std::string(acceptHeader), "/", "|"); 1683753d034dSEd Tanous boost::beast::http::ext_list acceptTypes{acceptStr}; 1684753d034dSEd Tanous bool supported = false; 1685753d034dSEd Tanous for (const auto& type : acceptTypes) 1686753d034dSEd Tanous { 1687753d034dSEd Tanous if ((type.first == "*|*") || 1688753d034dSEd Tanous (type.first == "application|octet-stream")) 1689753d034dSEd Tanous { 1690753d034dSEd Tanous supported = true; 1691753d034dSEd Tanous break; 1692753d034dSEd Tanous } 1693753d034dSEd Tanous } 1694753d034dSEd Tanous if (!supported) 1695400fd1fbSAdriana Kobylak { 16967e860f15SJohn Edward Broadbent asyncResp->res.result( 16977e860f15SJohn Edward Broadbent boost::beast::http::status::bad_request); 1698400fd1fbSAdriana Kobylak return; 1699400fd1fbSAdriana Kobylak } 1700400fd1fbSAdriana Kobylak 17017e860f15SJohn Edward Broadbent std::string entryID = param; 1702400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1703400fd1fbSAdriana Kobylak 1704400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 17057e860f15SJohn Edward Broadbent [asyncResp, 17067e860f15SJohn Edward Broadbent entryID](const boost::system::error_code ec, 1707400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 1708400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 1709400fd1fbSAdriana Kobylak { 17107e860f15SJohn Edward Broadbent messages::resourceNotFound( 17117e860f15SJohn Edward Broadbent asyncResp->res, "EventLogAttachment", entryID); 1712400fd1fbSAdriana Kobylak return; 1713400fd1fbSAdriana Kobylak } 1714400fd1fbSAdriana Kobylak if (ec) 1715400fd1fbSAdriana Kobylak { 1716400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1717400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1718400fd1fbSAdriana Kobylak return; 1719400fd1fbSAdriana Kobylak } 1720400fd1fbSAdriana Kobylak 1721400fd1fbSAdriana Kobylak int fd = -1; 1722400fd1fbSAdriana Kobylak fd = dup(unixfd); 1723400fd1fbSAdriana Kobylak if (fd == -1) 1724400fd1fbSAdriana Kobylak { 1725400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1726400fd1fbSAdriana Kobylak return; 1727400fd1fbSAdriana Kobylak } 1728400fd1fbSAdriana Kobylak 1729400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 1730400fd1fbSAdriana Kobylak if (size == -1) 1731400fd1fbSAdriana Kobylak { 1732400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1733400fd1fbSAdriana Kobylak return; 1734400fd1fbSAdriana Kobylak } 1735400fd1fbSAdriana Kobylak 1736400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 1737400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 1738400fd1fbSAdriana Kobylak if (size > maxFileSize) 1739400fd1fbSAdriana Kobylak { 1740400fd1fbSAdriana Kobylak BMCWEB_LOG_ERROR 1741400fd1fbSAdriana Kobylak << "File size exceeds maximum allowed size of " 1742400fd1fbSAdriana Kobylak << maxFileSize; 1743400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1744400fd1fbSAdriana Kobylak return; 1745400fd1fbSAdriana Kobylak } 1746400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 1747400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 1748400fd1fbSAdriana Kobylak if (rc == -1) 1749400fd1fbSAdriana Kobylak { 1750400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1751400fd1fbSAdriana Kobylak return; 1752400fd1fbSAdriana Kobylak } 1753400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 1754400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 1755400fd1fbSAdriana Kobylak { 1756400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1757400fd1fbSAdriana Kobylak return; 1758400fd1fbSAdriana Kobylak } 1759400fd1fbSAdriana Kobylak close(fd); 1760400fd1fbSAdriana Kobylak 1761400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 17627e860f15SJohn Edward Broadbent std::string output = 17637e860f15SJohn Edward Broadbent crow::utility::base64encode(strData); 1764400fd1fbSAdriana Kobylak 1765400fd1fbSAdriana Kobylak asyncResp->res.addHeader("Content-Type", 1766400fd1fbSAdriana Kobylak "application/octet-stream"); 17677e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Transfer-Encoding", 17687e860f15SJohn Edward Broadbent "Base64"); 1769400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 1770400fd1fbSAdriana Kobylak }, 1771400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 1772400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 1773400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 17747e860f15SJohn Edward Broadbent }); 17751da66f75SEd Tanous } 17761da66f75SEd Tanous 17777e860f15SJohn Edward Broadbent inline void requestRoutesBMCLogServiceCollection(App& app) 17781da66f75SEd Tanous { 17797e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 1780ad89dcf0SGunnar Mills .privileges(redfish::privileges::getLogServiceCollection) 17817e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 17827e860f15SJohn Edward Broadbent [](const crow::Request&, 17837e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 17847e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 17857e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1786e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 17871da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1788e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1789e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 17907e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 17917e860f15SJohn Edward Broadbent "Open BMC Log Services Collection"; 1792e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 17931da66f75SEd Tanous "Collection of LogServices for this Manager"; 17947e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 17957e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 1796c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 17975cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 17985cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 17997e860f15SJohn Edward Broadbent {{"@odata.id", 18007e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 18015cb1dd27SAsmitha Karunanithi #endif 1802c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1803c4bf6374SJason M. Bills logServiceArray.push_back( 18047e860f15SJohn Edward Broadbent {{"@odata.id", 18057e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1806c4bf6374SJason M. Bills #endif 1807e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1808c4bf6374SJason M. Bills logServiceArray.size(); 18097e860f15SJohn Edward Broadbent }); 1810e1f26343SJason M. Bills } 1811e1f26343SJason M. Bills 18127e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 1813e1f26343SJason M. Bills { 18147e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1815ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 18167e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 18177e860f15SJohn Edward Broadbent [](const crow::Request&, 18187e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 18198d1b46d7Szhanghch05 18207e860f15SJohn Edward Broadbent { 1821e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1822e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 18230f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18240f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 18257e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 18267e860f15SJohn Edward Broadbent "Open BMC Journal Log Service"; 18277e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 18287e860f15SJohn Edward Broadbent "BMC Journal Log Service"; 1829c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1830e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 18317c8c4058STejas Patil 18327c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 18337c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 18347c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 18357c8c4058STejas Patil redfishDateTimeOffset.first; 18367c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 18377c8c4058STejas Patil redfishDateTimeOffset.second; 18387c8c4058STejas Patil 1839cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1840cd50aa42SJason M. Bills {"@odata.id", 1841086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 18427e860f15SJohn Edward Broadbent }); 1843e1f26343SJason M. Bills } 1844e1f26343SJason M. Bills 1845c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 1846e1f26343SJason M. Bills sd_journal* journal, 1847c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 1848e1f26343SJason M. Bills { 1849e1f26343SJason M. Bills // Get the Log Entry contents 1850e1f26343SJason M. Bills int ret = 0; 1851e1f26343SJason M. Bills 1852a8fe54f0SJason M. Bills std::string message; 1853a8fe54f0SJason M. Bills std::string_view syslogID; 1854a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 1855a8fe54f0SJason M. Bills if (ret < 0) 1856a8fe54f0SJason M. Bills { 1857a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 1858a8fe54f0SJason M. Bills << strerror(-ret); 1859a8fe54f0SJason M. Bills } 1860a8fe54f0SJason M. Bills if (!syslogID.empty()) 1861a8fe54f0SJason M. Bills { 1862a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 1863a8fe54f0SJason M. Bills } 1864a8fe54f0SJason M. Bills 186539e77504SEd Tanous std::string_view msg; 186616428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1867e1f26343SJason M. Bills if (ret < 0) 1868e1f26343SJason M. Bills { 1869e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1870e1f26343SJason M. Bills return 1; 1871e1f26343SJason M. Bills } 1872a8fe54f0SJason M. Bills message += std::string(msg); 1873e1f26343SJason M. Bills 1874e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1875271584abSEd Tanous long int severity = 8; // Default to an invalid priority 187616428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1877e1f26343SJason M. Bills if (ret < 0) 1878e1f26343SJason M. Bills { 1879e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1880e1f26343SJason M. Bills } 1881e1f26343SJason M. Bills 1882e1f26343SJason M. Bills // Get the Created time from the timestamp 188316428a1aSJason M. Bills std::string entryTimeStr; 188416428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1885e1f26343SJason M. Bills { 188616428a1aSJason M. Bills return 1; 1887e1f26343SJason M. Bills } 1888e1f26343SJason M. Bills 1889e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1890c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 1891d0dbeefdSEd Tanous {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1892c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1893c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1894e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1895c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 1896a8fe54f0SJason M. Bills {"Message", std::move(message)}, 1897e1f26343SJason M. Bills {"EntryType", "Oem"}, 1898738c1e61SPatrick Williams {"Severity", severity <= 2 ? "Critical" 1899738c1e61SPatrick Williams : severity <= 4 ? "Warning" 1900738c1e61SPatrick Williams : "OK"}, 1901086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1902e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1903e1f26343SJason M. Bills return 0; 1904e1f26343SJason M. Bills } 1905e1f26343SJason M. Bills 19067e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 1907e1f26343SJason M. Bills { 19087e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1909ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 19107e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 19117e860f15SJohn Edward Broadbent [](const crow::Request& req, 19127e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1913193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1914271584abSEd Tanous uint64_t skip = 0; 1915271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 19168d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 1917193ad2faSJason M. Bills { 1918193ad2faSJason M. Bills return; 1919193ad2faSJason M. Bills } 19208d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 1921193ad2faSJason M. Bills { 1922193ad2faSJason M. Bills return; 1923193ad2faSJason M. Bills } 19247e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 19257e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1926e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1927e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 19280f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 19290f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1930e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1931e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1932e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 19337e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 19347e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 1935e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1936e1f26343SJason M. Bills 19377e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 19387e860f15SJohn Edward Broadbent // unique ID for each entry 1939e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1940e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1941e1f26343SJason M. Bills if (ret < 0) 1942e1f26343SJason M. Bills { 19437e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 19447e860f15SJohn Edward Broadbent << strerror(-ret); 1945f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1946e1f26343SJason M. Bills return; 1947e1f26343SJason M. Bills } 19487e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 19497e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 1950e1f26343SJason M. Bills journalTmp = nullptr; 1951b01bf299SEd Tanous uint64_t entryCount = 0; 1952e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1953e85d6b16SJason M. Bills bool firstEntry = true; 1954e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1955e1f26343SJason M. Bills { 1956193ad2faSJason M. Bills entryCount++; 19577e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 19587e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 1959193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1960193ad2faSJason M. Bills { 1961193ad2faSJason M. Bills continue; 1962193ad2faSJason M. Bills } 1963193ad2faSJason M. Bills 196416428a1aSJason M. Bills std::string idStr; 1965e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1966e1f26343SJason M. Bills { 1967e1f26343SJason M. Bills continue; 1968e1f26343SJason M. Bills } 1969e1f26343SJason M. Bills 1970e85d6b16SJason M. Bills if (firstEntry) 1971e85d6b16SJason M. Bills { 1972e85d6b16SJason M. Bills firstEntry = false; 1973e85d6b16SJason M. Bills } 1974e85d6b16SJason M. Bills 1975e1f26343SJason M. Bills logEntryArray.push_back({}); 1976c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 1977c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 1978c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 1979e1f26343SJason M. Bills { 1980f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1981e1f26343SJason M. Bills return; 1982e1f26343SJason M. Bills } 1983e1f26343SJason M. Bills } 1984193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1985193ad2faSJason M. Bills if (skip + top < entryCount) 1986193ad2faSJason M. Bills { 1987193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 19887e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/" 19897e860f15SJohn Edward Broadbent "Entries?$skip=" + 1990193ad2faSJason M. Bills std::to_string(skip + top); 1991193ad2faSJason M. Bills } 19927e860f15SJohn Edward Broadbent }); 1993e1f26343SJason M. Bills } 1994e1f26343SJason M. Bills 19957e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 1996e1f26343SJason M. Bills { 19977e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 19987e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 1999ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 20007e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 20017e860f15SJohn Edward Broadbent [](const crow::Request&, 20027e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 20037e860f15SJohn Edward Broadbent const std::string& entryID) { 2004e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2005e1f26343SJason M. Bills uint64_t ts = 0; 2006271584abSEd Tanous uint64_t index = 0; 20078d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2008e1f26343SJason M. Bills { 200916428a1aSJason M. Bills return; 2010e1f26343SJason M. Bills } 2011e1f26343SJason M. Bills 2012e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2013e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2014e1f26343SJason M. Bills if (ret < 0) 2015e1f26343SJason M. Bills { 20167e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 20177e860f15SJohn Edward Broadbent << strerror(-ret); 2018f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2019e1f26343SJason M. Bills return; 2020e1f26343SJason M. Bills } 20217e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 20227e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 2023e1f26343SJason M. Bills journalTmp = nullptr; 20247e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 20257e860f15SJohn Edward Broadbent // index tracking the unique ID 2026af07e3f5SJason M. Bills std::string idStr; 2027af07e3f5SJason M. Bills bool firstEntry = true; 2028e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 20292056b6d1SManojkiran Eda if (ret < 0) 20302056b6d1SManojkiran Eda { 20312056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 20322056b6d1SManojkiran Eda << strerror(-ret); 20332056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 20342056b6d1SManojkiran Eda return; 20352056b6d1SManojkiran Eda } 2036271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2037e1f26343SJason M. Bills { 2038e1f26343SJason M. Bills sd_journal_next(journal.get()); 2039af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2040af07e3f5SJason M. Bills { 2041af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2042af07e3f5SJason M. Bills return; 2043af07e3f5SJason M. Bills } 2044af07e3f5SJason M. Bills if (firstEntry) 2045af07e3f5SJason M. Bills { 2046af07e3f5SJason M. Bills firstEntry = false; 2047af07e3f5SJason M. Bills } 2048e1f26343SJason M. Bills } 2049c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2050af07e3f5SJason M. Bills if (idStr != entryID) 2051c4bf6374SJason M. Bills { 2052c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 2053c4bf6374SJason M. Bills return; 2054c4bf6374SJason M. Bills } 2055c4bf6374SJason M. Bills 2056c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 2057e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 2058e1f26343SJason M. Bills { 2059f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2060e1f26343SJason M. Bills return; 2061e1f26343SJason M. Bills } 20627e860f15SJohn Edward Broadbent }); 2063c9bb6861Sraviteja-b } 2064c9bb6861Sraviteja-b 20657e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpService(App& app) 2066c9bb6861Sraviteja-b { 20677e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2068ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 20697e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 20707e860f15SJohn Edward Broadbent [](const crow::Request&, 20717e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2072c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 20735cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 2074c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2075d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 2076c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 20775cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 20785cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2079c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 20807c8c4058STejas Patil 20817c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 20827c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 20837c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 20847c8c4058STejas Patil redfishDateTimeOffset.first; 20857c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 20867c8c4058STejas Patil redfishDateTimeOffset.second; 20877c8c4058STejas Patil 2088c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 20897e860f15SJohn Edward Broadbent {"@odata.id", 20907e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}}; 20915cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 20925cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 20935cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 20945cb1dd27SAsmitha Karunanithi "Actions/LogService.ClearLog"}}}, 2095d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 2096d337bb72SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 2097d337bb72SAsmitha Karunanithi "Actions/LogService.CollectDiagnosticData"}}}}; 20987e860f15SJohn Edward Broadbent }); 2099c9bb6861Sraviteja-b } 2100c9bb6861Sraviteja-b 21017e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntryCollection(App& app) 21027e860f15SJohn Edward Broadbent { 21037e860f15SJohn Edward Broadbent 2104c9bb6861Sraviteja-b /** 2105c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2106c9bb6861Sraviteja-b */ 21077e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2108ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 21097e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 21107e860f15SJohn Edward Broadbent [](const crow::Request&, 21117e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2112c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2113c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2114c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 21155cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 21165cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2117c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 21185cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2119c9bb6861Sraviteja-b 21205cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 21217e860f15SJohn Edward Broadbent }); 2122c9bb6861Sraviteja-b } 2123c9bb6861Sraviteja-b 21247e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2125c9bb6861Sraviteja-b { 21267e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 21277e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2128ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 21297e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 21307e860f15SJohn Edward Broadbent [](const crow::Request&, 21317e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 21327e860f15SJohn Edward Broadbent const std::string& param) { 21337e860f15SJohn Edward Broadbent getDumpEntryById(asyncResp, param, "BMC"); 21347e860f15SJohn Edward Broadbent }); 21357e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 21367e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2137ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 21387e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 21397e860f15SJohn Edward Broadbent [](const crow::Request&, 21407e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 21417e860f15SJohn Edward Broadbent const std::string& param) { 21427e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "bmc"); 21437e860f15SJohn Edward Broadbent }); 2144c9bb6861Sraviteja-b } 2145c9bb6861Sraviteja-b 21467e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2147c9bb6861Sraviteja-b { 21488d1b46d7Szhanghch05 21497e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 2150d337bb72SAsmitha Karunanithi "Actions/" 2151d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2152ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 21537e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 21547e860f15SJohn Edward Broadbent [](const crow::Request& req, 21557e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 21568d1b46d7Szhanghch05 createDump(asyncResp, req, "BMC"); 21577e860f15SJohn Edward Broadbent }); 2158a43be80fSAsmitha Karunanithi } 2159a43be80fSAsmitha Karunanithi 21607e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 216180319af1SAsmitha Karunanithi { 21627e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 216380319af1SAsmitha Karunanithi "Actions/" 216480319af1SAsmitha Karunanithi "LogService.ClearLog/") 2165ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 21667e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 21677e860f15SJohn Edward Broadbent [](const crow::Request&, 21687e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 21698d1b46d7Szhanghch05 clearDump(asyncResp, "BMC"); 21707e860f15SJohn Edward Broadbent }); 21715cb1dd27SAsmitha Karunanithi } 21725cb1dd27SAsmitha Karunanithi 21737e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 21745cb1dd27SAsmitha Karunanithi { 21757e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/") 2176ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 21777e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 21787e860f15SJohn Edward Broadbent [](const crow::Request&, 21797e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 21805cb1dd27SAsmitha Karunanithi 21817e860f15SJohn Edward Broadbent { 21825cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 21835cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 21845cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2185d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 21865cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 21877e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 21887e860f15SJohn Edward Broadbent "System Dump LogService"; 21895cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 21905cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 21917c8c4058STejas Patil 21927c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 21937c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 21947c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 21957c8c4058STejas Patil redfishDateTimeOffset.first; 21967c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 21977c8c4058STejas Patil redfishDateTimeOffset.second; 21987c8c4058STejas Patil 21995cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Entries"] = { 22005cb1dd27SAsmitha Karunanithi {"@odata.id", 22015cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"}}; 22025cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 22035cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 22047e860f15SJohn Edward Broadbent {{"target", 22057e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 22065cb1dd27SAsmitha Karunanithi "LogService.ClearLog"}}}, 2207d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 22087e860f15SJohn Edward Broadbent {{"target", 22097e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 2210d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData"}}}}; 22117e860f15SJohn Edward Broadbent }); 22125cb1dd27SAsmitha Karunanithi } 22135cb1dd27SAsmitha Karunanithi 22147e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 22157e860f15SJohn Edward Broadbent { 22167e860f15SJohn Edward Broadbent 22175cb1dd27SAsmitha Karunanithi /** 22185cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 22195cb1dd27SAsmitha Karunanithi */ 2220b2a3289dSAsmitha Karunanithi BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 2221ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 22227e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22237e860f15SJohn Edward Broadbent [](const crow::Request&, 2224864d6a17SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22255cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 22265cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 22275cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 22285cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 22295cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 22305cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 22315cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 22325cb1dd27SAsmitha Karunanithi 22335cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 22347e860f15SJohn Edward Broadbent }); 22355cb1dd27SAsmitha Karunanithi } 22365cb1dd27SAsmitha Karunanithi 22377e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 22385cb1dd27SAsmitha Karunanithi { 22397e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2240864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2241ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2242ed398213SEd Tanous 22437e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22447e860f15SJohn Edward Broadbent [](const crow::Request&, 22457e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22467e860f15SJohn Edward Broadbent const std::string& param) { 22477e860f15SJohn Edward Broadbent getDumpEntryById(asyncResp, param, "System"); 22487e860f15SJohn Edward Broadbent }); 22498d1b46d7Szhanghch05 22507e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2251864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2252ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 22537e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 22547e860f15SJohn Edward Broadbent [](const crow::Request&, 22557e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22567e860f15SJohn Edward Broadbent const std::string& param) { 22577e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "system"); 22587e860f15SJohn Edward Broadbent }); 22595cb1dd27SAsmitha Karunanithi } 2260c9bb6861Sraviteja-b 22617e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2262c9bb6861Sraviteja-b { 22637e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2264d337bb72SAsmitha Karunanithi "Actions/" 2265d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2266ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 22677e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 22687e860f15SJohn Edward Broadbent [](const crow::Request& req, 22697e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 22707e860f15SJohn Edward Broadbent 22717e860f15SJohn Edward Broadbent { createDump(asyncResp, req, "System"); }); 2272a43be80fSAsmitha Karunanithi } 2273a43be80fSAsmitha Karunanithi 22747e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2275a43be80fSAsmitha Karunanithi { 22767e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2277013487e5Sraviteja-b "Actions/" 2278013487e5Sraviteja-b "LogService.ClearLog/") 2279ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 22807e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 22817e860f15SJohn Edward Broadbent [](const crow::Request&, 22827e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 22837e860f15SJohn Edward Broadbent 22847e860f15SJohn Edward Broadbent { clearDump(asyncResp, "System"); }); 2285013487e5Sraviteja-b } 2286013487e5Sraviteja-b 22877e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 22881da66f75SEd Tanous { 22893946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 22903946028dSAppaRao Puli // method for security reasons. 22911da66f75SEd Tanous /** 22921da66f75SEd Tanous * Functions triggers appropriate requests on DBus 22931da66f75SEd Tanous */ 22947e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 2295ed398213SEd Tanous // This is incorrect, should be: 2296ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2297432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 22987e860f15SJohn Edward Broadbent .methods( 22997e860f15SJohn Edward Broadbent boost::beast::http::verb:: 23007e860f15SJohn Edward Broadbent get)([](const crow::Request&, 23017e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 23027e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 23037e860f15SJohn Edward Broadbent // SubRoute 23040f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2305424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2306e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 23078e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 23084f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 23094f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 23104f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2311e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2312e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 23137c8c4058STejas Patil 23147c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 23157c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 23167c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 23177c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 23187c8c4058STejas Patil redfishDateTimeOffset.second; 23197c8c4058STejas Patil 2320cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2321cd50aa42SJason M. Bills {"@odata.id", 2322424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 2323e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 23245b61b5e8SJason M. Bills {"#LogService.ClearLog", 23255b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 23265b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 23278e6c099aSJason M. Bills {"#LogService.CollectDiagnosticData", 2328424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 23298e6c099aSJason M. Bills "Actions/LogService.CollectDiagnosticData"}}}}; 23307e860f15SJohn Edward Broadbent }); 23311da66f75SEd Tanous } 23321da66f75SEd Tanous 23337e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 23345b61b5e8SJason M. Bills { 23357e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 23367e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 23375b61b5e8SJason M. Bills "LogService.ClearLog/") 2338ed398213SEd Tanous // This is incorrect, should be: 2339ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2340432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 23417e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 23427e860f15SJohn Edward Broadbent [](const crow::Request&, 23437e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 23445b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 23455b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2346cb13a392SEd Tanous const std::string&) { 23475b61b5e8SJason M. Bills if (ec) 23485b61b5e8SJason M. Bills { 23495b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 23505b61b5e8SJason M. Bills return; 23515b61b5e8SJason M. Bills } 23525b61b5e8SJason M. Bills messages::success(asyncResp->res); 23535b61b5e8SJason M. Bills }, 23547e860f15SJohn Edward Broadbent crashdumpObject, crashdumpPath, deleteAllInterface, 23557e860f15SJohn Edward Broadbent "DeleteAll"); 23567e860f15SJohn Edward Broadbent }); 23575b61b5e8SJason M. Bills } 23585b61b5e8SJason M. Bills 23598d1b46d7Szhanghch05 static void 23608d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 23618d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 2362e855dd28SJason M. Bills { 2363043a0536SJohnathan Mantey auto getStoredLogCallback = 2364043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 2365e855dd28SJason M. Bills const boost::system::error_code ec, 2366043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params) { 2367e855dd28SJason M. Bills if (ec) 2368e855dd28SJason M. Bills { 2369e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 23701ddcf01aSJason M. Bills if (ec.value() == 23711ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 23721ddcf01aSJason M. Bills { 2373043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2374043a0536SJohnathan Mantey logID); 23751ddcf01aSJason M. Bills } 23761ddcf01aSJason M. Bills else 23771ddcf01aSJason M. Bills { 2378e855dd28SJason M. Bills messages::internalError(asyncResp->res); 23791ddcf01aSJason M. Bills } 2380e855dd28SJason M. Bills return; 2381e855dd28SJason M. Bills } 2382043a0536SJohnathan Mantey 2383043a0536SJohnathan Mantey std::string timestamp{}; 2384043a0536SJohnathan Mantey std::string filename{}; 2385043a0536SJohnathan Mantey std::string logfile{}; 23862c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2387043a0536SJohnathan Mantey 2388043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2389e855dd28SJason M. Bills { 2390043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 2391e855dd28SJason M. Bills return; 2392e855dd28SJason M. Bills } 2393e855dd28SJason M. Bills 2394043a0536SJohnathan Mantey std::string crashdumpURI = 2395e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2396043a0536SJohnathan Mantey logID + "/" + filename; 2397d0dbeefdSEd Tanous logEntryJson = {{"@odata.type", "#LogEntry.v1_7_0.LogEntry"}, 2398043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 2399043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 2400e855dd28SJason M. Bills logID}, 2401e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2402e855dd28SJason M. Bills {"Id", logID}, 2403e855dd28SJason M. Bills {"EntryType", "Oem"}, 24048e6c099aSJason M. Bills {"AdditionalDataURI", std::move(crashdumpURI)}, 24058e6c099aSJason M. Bills {"DiagnosticDataType", "OEM"}, 24068e6c099aSJason M. Bills {"OEMDiagnosticDataType", "PECICrashdump"}, 2407043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2408e855dd28SJason M. Bills }; 2409e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 24105b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 24115b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2412043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2413e855dd28SJason M. Bills } 2414e855dd28SJason M. Bills 24157e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 24161da66f75SEd Tanous { 24173946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24183946028dSAppaRao Puli // method for security reasons. 24191da66f75SEd Tanous /** 24201da66f75SEd Tanous * Functions triggers appropriate requests on DBus 24211da66f75SEd Tanous */ 24227e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24237e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 2424ed398213SEd Tanous // This is incorrect, should be. 2425ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 2426432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 24277e860f15SJohn Edward Broadbent .methods( 24287e860f15SJohn Edward Broadbent boost::beast::http::verb:: 24297e860f15SJohn Edward Broadbent get)([](const crow::Request&, 24307e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24317e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 24327e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2433e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2434e1f26343SJason M. Bills const boost::system::error_code ec, 24357e860f15SJohn Edward Broadbent const std::vector<std::string>& 24367e860f15SJohn Edward Broadbent resp) { 24371da66f75SEd Tanous if (ec) 24381da66f75SEd Tanous { 24391da66f75SEd Tanous if (ec.value() != 24401da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 24411da66f75SEd Tanous { 24421da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 24431da66f75SEd Tanous << ec.message(); 2444f12894f8SJason M. Bills messages::internalError(asyncResp->res); 24451da66f75SEd Tanous return; 24461da66f75SEd Tanous } 24471da66f75SEd Tanous } 2448e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 24491da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 24500f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2451424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2452424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2453e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2454424c4176SJason M. Bills "Collection of Crashdump Entries"; 24557e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 24567e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 2457e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2458e855dd28SJason M. Bills std::vector<std::string> logIDs; 2459e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2460e855dd28SJason M. Bills // enough to hold them 24611da66f75SEd Tanous for (const std::string& objpath : resp) 24621da66f75SEd Tanous { 2463e855dd28SJason M. Bills // Get the log ID 2464f23b7296SEd Tanous std::size_t lastPos = objpath.rfind('/'); 2465e855dd28SJason M. Bills if (lastPos == std::string::npos) 24661da66f75SEd Tanous { 2467e855dd28SJason M. Bills continue; 24681da66f75SEd Tanous } 2469e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2470e855dd28SJason M. Bills 2471e855dd28SJason M. Bills // Add a space for the log entry to the array 2472e855dd28SJason M. Bills logEntryArray.push_back({}); 2473e855dd28SJason M. Bills } 2474e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2475e855dd28SJason M. Bills size_t index = 0; 2476e855dd28SJason M. Bills for (const std::string& logID : logIDs) 2477e855dd28SJason M. Bills { 2478e855dd28SJason M. Bills // Add the log entry to the array 2479e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 24801da66f75SEd Tanous } 2481e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2482e1f26343SJason M. Bills logEntryArray.size(); 24831da66f75SEd Tanous }; 24841da66f75SEd Tanous crow::connections::systemBus->async_method_call( 24851da66f75SEd Tanous std::move(getLogEntriesCallback), 24861da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 24871da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 24881da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 24895b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 24907e860f15SJohn Edward Broadbent }); 24911da66f75SEd Tanous } 24921da66f75SEd Tanous 24937e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 24941da66f75SEd Tanous { 24953946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24963946028dSAppaRao Puli // method for security reasons. 24971da66f75SEd Tanous 24987e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 24997e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/") 2500ed398213SEd Tanous // this is incorrect, should be 2501ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 2502432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 25037e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 25047e860f15SJohn Edward Broadbent [](const crow::Request&, 25057e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25067e860f15SJohn Edward Broadbent const std::string& param) { 25077e860f15SJohn Edward Broadbent const std::string& logID = param; 2508e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 25097e860f15SJohn Edward Broadbent }); 2510e855dd28SJason M. Bills } 2511e855dd28SJason M. Bills 25127e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 2513e855dd28SJason M. Bills { 25143946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25153946028dSAppaRao Puli // method for security reasons. 25167e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 25177e860f15SJohn Edward Broadbent app, 25187e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/") 2519ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 25207e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 25217e860f15SJohn Edward Broadbent [](const crow::Request&, 25227e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25237e860f15SJohn Edward Broadbent const std::string& logID, const std::string& fileName) { 2524043a0536SJohnathan Mantey auto getStoredLogCallback = 2525043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 2526abf2add6SEd Tanous const boost::system::error_code ec, 25277e860f15SJohn Edward Broadbent const std::vector<std::pair<std::string, VariantType>>& 25287e860f15SJohn Edward Broadbent resp) { 25291da66f75SEd Tanous if (ec) 25301da66f75SEd Tanous { 2531043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2532043a0536SJohnathan Mantey << ec.message(); 2533f12894f8SJason M. Bills messages::internalError(asyncResp->res); 25341da66f75SEd Tanous return; 25351da66f75SEd Tanous } 2536e855dd28SJason M. Bills 2537043a0536SJohnathan Mantey std::string dbusFilename{}; 2538043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2539043a0536SJohnathan Mantey std::string dbusFilepath{}; 2540043a0536SJohnathan Mantey 25417e860f15SJohn Edward Broadbent parseCrashdumpParameters(resp, dbusFilename, 25427e860f15SJohn Edward Broadbent dbusTimestamp, dbusFilepath); 2543043a0536SJohnathan Mantey 2544043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2545043a0536SJohnathan Mantey dbusFilepath.empty()) 25461da66f75SEd Tanous { 25477e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 25487e860f15SJohn Edward Broadbent fileName); 25491da66f75SEd Tanous return; 25501da66f75SEd Tanous } 2551e855dd28SJason M. Bills 2552043a0536SJohnathan Mantey // Verify the file name parameter is correct 2553043a0536SJohnathan Mantey if (fileName != dbusFilename) 2554043a0536SJohnathan Mantey { 25557e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 25567e860f15SJohn Edward Broadbent fileName); 2557043a0536SJohnathan Mantey return; 2558043a0536SJohnathan Mantey } 2559043a0536SJohnathan Mantey 2560043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2561043a0536SJohnathan Mantey { 25627e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 25637e860f15SJohn Edward Broadbent fileName); 2564043a0536SJohnathan Mantey return; 2565043a0536SJohnathan Mantey } 2566043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 2567043a0536SJohnathan Mantey std::ios::binary | 2568043a0536SJohnathan Mantey std::ios::ate); 2569043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 2570043a0536SJohnathan Mantey if (fileSize < 0) 2571043a0536SJohnathan Mantey { 2572043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 2573043a0536SJohnathan Mantey return; 2574043a0536SJohnathan Mantey } 2575043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 2576043a0536SJohnathan Mantey 2577043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 2578043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 2579043a0536SJohnathan Mantey 2580043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 2581043a0536SJohnathan Mantey 25827e860f15SJohn Edward Broadbent // The cast to std::string is intentional in order to 25837e860f15SJohn Edward Broadbent // use the assign() that applies move mechanics 2584043a0536SJohnathan Mantey asyncResp->res.body().assign( 2585043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 2586043a0536SJohnathan Mantey 25877e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 25887e860f15SJohn Edward Broadbent // from a browser 25897e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Disposition", 25907e860f15SJohn Edward Broadbent "attachment"); 25911da66f75SEd Tanous }; 25921da66f75SEd Tanous crow::connections::systemBus->async_method_call( 25935b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 25945b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 25957e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 25967e860f15SJohn Edward Broadbent crashdumpInterface); 25977e860f15SJohn Edward Broadbent }); 25981da66f75SEd Tanous } 25991da66f75SEd Tanous 26007e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 26011da66f75SEd Tanous { 26023946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 26033946028dSAppaRao Puli // method for security reasons. 26047e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/" 26057e860f15SJohn Edward Broadbent "Actions/LogService.CollectDiagnosticData/") 2606ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 2607ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2608432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 26097e860f15SJohn Edward Broadbent .methods( 26107e860f15SJohn Edward Broadbent boost::beast::http::verb:: 26117e860f15SJohn Edward Broadbent post)([](const crow::Request& req, 26127e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26138e6c099aSJason M. Bills std::string diagnosticDataType; 26148e6c099aSJason M. Bills std::string oemDiagnosticDataType; 26158e6c099aSJason M. Bills if (!redfish::json_util::readJson( 26167e860f15SJohn Edward Broadbent req, asyncResp->res, "DiagnosticDataType", 26177e860f15SJohn Edward Broadbent diagnosticDataType, "OEMDiagnosticDataType", 26187e860f15SJohn Edward Broadbent oemDiagnosticDataType)) 26198e6c099aSJason M. Bills { 26208e6c099aSJason M. Bills return; 26218e6c099aSJason M. Bills } 26228e6c099aSJason M. Bills 26238e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 26248e6c099aSJason M. Bills { 26258e6c099aSJason M. Bills BMCWEB_LOG_ERROR 26268e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 26278e6c099aSJason M. Bills messages::actionParameterValueFormatError( 26288e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 26298e6c099aSJason M. Bills "CollectDiagnosticData"); 26308e6c099aSJason M. Bills return; 26318e6c099aSJason M. Bills } 26328e6c099aSJason M. Bills 26338e6c099aSJason M. Bills auto collectCrashdumpCallback = [asyncResp, req]( 26347e860f15SJohn Edward Broadbent const boost::system::error_code 26357e860f15SJohn Edward Broadbent ec, 2636cb13a392SEd Tanous const std::string&) { 26371da66f75SEd Tanous if (ec) 26381da66f75SEd Tanous { 26397e860f15SJohn Edward Broadbent if (ec.value() == 26407e860f15SJohn Edward Broadbent boost::system::errc::operation_not_supported) 26411da66f75SEd Tanous { 2642f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 26431da66f75SEd Tanous } 26444363d3b2SJason M. Bills else if (ec.value() == 26454363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 26464363d3b2SJason M. Bills { 26474363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 26484363d3b2SJason M. Bills "60"); 26494363d3b2SJason M. Bills } 26501da66f75SEd Tanous else 26511da66f75SEd Tanous { 2652f12894f8SJason M. Bills messages::internalError(asyncResp->res); 26531da66f75SEd Tanous } 26541da66f75SEd Tanous return; 26551da66f75SEd Tanous } 26567e860f15SJohn Edward Broadbent std::shared_ptr<task::TaskData> task = 26577e860f15SJohn Edward Broadbent task::TaskData::createTask( 26587e860f15SJohn Edward Broadbent [](boost::system::error_code err, 26597e860f15SJohn Edward Broadbent sdbusplus::message::message&, 266066afe4faSJames Feist const std::shared_ptr<task::TaskData>& taskData) { 266166afe4faSJames Feist if (!err) 266266afe4faSJames Feist { 2663e5d5006bSJames Feist taskData->messages.emplace_back( 2664e5d5006bSJames Feist messages::taskCompletedOK( 2665e5d5006bSJames Feist std::to_string(taskData->index))); 2666831d6b09SJames Feist taskData->state = "Completed"; 266766afe4faSJames Feist } 266832898ceaSJames Feist return task::completed; 266966afe4faSJames Feist }, 26707e860f15SJohn Edward Broadbent "type='signal',interface='org.freedesktop.DBus." 26717e860f15SJohn Edward Broadbent "Properties'," 267246229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 267346229577SJames Feist "crashdump'"); 267446229577SJames Feist task->startTimer(std::chrono::minutes(5)); 267546229577SJames Feist task->populateResp(asyncResp->res); 2676fe306728SJames Feist task->payload.emplace(req); 26771da66f75SEd Tanous }; 26788e6c099aSJason M. Bills 26798e6c099aSJason M. Bills if (oemDiagnosticDataType == "OnDemand") 26808e6c099aSJason M. Bills { 26811da66f75SEd Tanous crow::connections::systemBus->async_method_call( 26828e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 26838e6c099aSJason M. Bills crashdumpPath, crashdumpOnDemandInterface, 26848e6c099aSJason M. Bills "GenerateOnDemandLog"); 26851da66f75SEd Tanous } 26868e6c099aSJason M. Bills else if (oemDiagnosticDataType == "Telemetry") 26876eda7685SKenny L. Ku { 26888e6c099aSJason M. Bills crow::connections::systemBus->async_method_call( 26898e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 26908e6c099aSJason M. Bills crashdumpPath, crashdumpTelemetryInterface, 26918e6c099aSJason M. Bills "GenerateTelemetryLog"); 26926eda7685SKenny L. Ku } 26936eda7685SKenny L. Ku else 26946eda7685SKenny L. Ku { 26958e6c099aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 26968e6c099aSJason M. Bills << oemDiagnosticDataType; 26978e6c099aSJason M. Bills messages::actionParameterValueFormatError( 26987e860f15SJohn Edward Broadbent asyncResp->res, oemDiagnosticDataType, 26997e860f15SJohn Edward Broadbent "OEMDiagnosticDataType", "CollectDiagnosticData"); 27006eda7685SKenny L. Ku return; 27016eda7685SKenny L. Ku } 27027e860f15SJohn Edward Broadbent }); 27036eda7685SKenny L. Ku } 27046eda7685SKenny L. Ku 2705cb92c03bSAndrew Geissler /** 2706cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2707cb92c03bSAndrew Geissler */ 27087e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 2709cb92c03bSAndrew Geissler { 2710cb92c03bSAndrew Geissler /** 2711cb92c03bSAndrew Geissler * Function handles POST method request. 2712cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 2713cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 2714cb92c03bSAndrew Geissler */ 27157e860f15SJohn Edward Broadbent 27167e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 27177e860f15SJohn Edward Broadbent "LogService.ClearLog/") 2718ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 27197e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 27207e860f15SJohn Edward Broadbent [](const crow::Request&, 27217e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2722cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 2723cb92c03bSAndrew Geissler 2724cb92c03bSAndrew Geissler // Process response from Logging service. 27257e860f15SJohn Edward Broadbent auto respHandler = [asyncResp]( 27267e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 27277e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 27287e860f15SJohn Edward Broadbent << "doClearLog resp_handler callback: Done"; 2729cb92c03bSAndrew Geissler if (ec) 2730cb92c03bSAndrew Geissler { 2731cb92c03bSAndrew Geissler // TODO Handle for specific error code 27327e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " 27337e860f15SJohn Edward Broadbent << ec; 2734cb92c03bSAndrew Geissler asyncResp->res.result( 2735cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 2736cb92c03bSAndrew Geissler return; 2737cb92c03bSAndrew Geissler } 2738cb92c03bSAndrew Geissler 27397e860f15SJohn Edward Broadbent asyncResp->res.result( 27407e860f15SJohn Edward Broadbent boost::beast::http::status::no_content); 2741cb92c03bSAndrew Geissler }; 2742cb92c03bSAndrew Geissler 2743cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 2744cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 27452c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 2746cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 2747cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 27487e860f15SJohn Edward Broadbent }); 2749cb92c03bSAndrew Geissler } 2750a3316fc6SZhikuiRen 2751a3316fc6SZhikuiRen /**************************************************** 2752a3316fc6SZhikuiRen * Redfish PostCode interfaces 2753a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 2754a3316fc6SZhikuiRen ******************************************************/ 27557e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 2756a3316fc6SZhikuiRen { 27577e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 2758ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 27597e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 27607e860f15SJohn Edward Broadbent [](const crow::Request&, 27617e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2762a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 27637e860f15SJohn Edward Broadbent {"@odata.id", 27647e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes"}, 2765a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 2766a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 2767a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 2768a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 2769a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 2770a3316fc6SZhikuiRen {"Entries", 27717e860f15SJohn Edward Broadbent {{"@odata.id", "/redfish/v1/Systems/system/LogServices/" 27727e860f15SJohn Edward Broadbent "PostCodes/Entries"}}}}; 27737c8c4058STejas Patil 27747c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 27757c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 27767c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 27777c8c4058STejas Patil redfishDateTimeOffset.first; 27787c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 27797c8c4058STejas Patil redfishDateTimeOffset.second; 27807c8c4058STejas Patil 2781a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 27827e860f15SJohn Edward Broadbent {"target", 27837e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/" 2784a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 27857e860f15SJohn Edward Broadbent }); 2786a3316fc6SZhikuiRen } 2787a3316fc6SZhikuiRen 27887e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 2789a3316fc6SZhikuiRen { 27907e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 27917e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 2792a3316fc6SZhikuiRen "LogService.ClearLog/") 2793ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 2794ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2795432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 27967e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 27977e860f15SJohn Edward Broadbent [](const crow::Request&, 27987e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2799a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 2800a3316fc6SZhikuiRen 2801a3316fc6SZhikuiRen // Make call to post-code service to request clear all 2802a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2803a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 2804a3316fc6SZhikuiRen if (ec) 2805a3316fc6SZhikuiRen { 2806a3316fc6SZhikuiRen // TODO Handle for specific error code 2807a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 28087e860f15SJohn Edward Broadbent << "doClearPostCodes resp_handler got error " 28097e860f15SJohn Edward Broadbent << ec; 28107e860f15SJohn Edward Broadbent asyncResp->res.result(boost::beast::http::status:: 28117e860f15SJohn Edward Broadbent internal_server_error); 2812a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 2813a3316fc6SZhikuiRen return; 2814a3316fc6SZhikuiRen } 2815a3316fc6SZhikuiRen }, 281615124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 281715124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 2818a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 28197e860f15SJohn Edward Broadbent }); 2820a3316fc6SZhikuiRen } 2821a3316fc6SZhikuiRen 2822a3316fc6SZhikuiRen static void fillPostCodeEntry( 28238d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 28246c9a279eSManojkiran Eda const boost::container::flat_map< 28256c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 2826a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 2827a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 2828a3316fc6SZhikuiRen { 2829a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 2830a3316fc6SZhikuiRen const message_registries::Message* message = 28314a0bf539SManojkiran Eda message_registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 2832a3316fc6SZhikuiRen 2833a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 2834a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 2835a3316fc6SZhikuiRen 2836a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 28376c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 28386c9a279eSManojkiran Eda code : postcode) 2839a3316fc6SZhikuiRen { 2840a3316fc6SZhikuiRen currentCodeIndex++; 2841a3316fc6SZhikuiRen std::string postcodeEntryID = 2842a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 2843a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 2844a3316fc6SZhikuiRen 2845a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 2846a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 2847a3316fc6SZhikuiRen 2848a3316fc6SZhikuiRen if (1 == currentCodeIndex) 2849a3316fc6SZhikuiRen { // already incremented 2850a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 2851a3316fc6SZhikuiRen } 2852a3316fc6SZhikuiRen else 2853a3316fc6SZhikuiRen { 2854a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 2855a3316fc6SZhikuiRen } 2856a3316fc6SZhikuiRen 2857a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 2858a3316fc6SZhikuiRen // not fall between top and skip 2859a3316fc6SZhikuiRen if ((codeIndex == 0) && 2860a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 2861a3316fc6SZhikuiRen { 2862a3316fc6SZhikuiRen continue; 2863a3316fc6SZhikuiRen } 2864a3316fc6SZhikuiRen 28654e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 2866a3316fc6SZhikuiRen // currentIndex 2867a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 2868a3316fc6SZhikuiRen { 2869a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 2870a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 2871a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 2872a3316fc6SZhikuiRen continue; 2873a3316fc6SZhikuiRen } 2874a3316fc6SZhikuiRen 2875a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 2876a3316fc6SZhikuiRen // index 2877a3316fc6SZhikuiRen 2878a3316fc6SZhikuiRen // Get the Created time from the timestamp 2879a3316fc6SZhikuiRen std::string entryTimeStr; 28809c620e21SAsmitha Karunanithi entryTimeStr = crow::utility::getDateTime( 28819c620e21SAsmitha Karunanithi static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000)); 2882a3316fc6SZhikuiRen 2883a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 2884a3316fc6SZhikuiRen std::ostringstream hexCode; 2885a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 28866c9a279eSManojkiran Eda << std::get<0>(code.second); 2887a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 2888a3316fc6SZhikuiRen // Set Fixed -Point Notation 2889a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 2890a3316fc6SZhikuiRen // Set precision to 4 digits 2891a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 2892a3316fc6SZhikuiRen // Add double to stream 2893a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 2894a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 2895a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 2896a3316fc6SZhikuiRen 2897a3316fc6SZhikuiRen // Get MessageArgs template from message registry 2898a3316fc6SZhikuiRen std::string msg; 2899a3316fc6SZhikuiRen if (message != nullptr) 2900a3316fc6SZhikuiRen { 2901a3316fc6SZhikuiRen msg = message->message; 2902a3316fc6SZhikuiRen 2903a3316fc6SZhikuiRen // fill in this post code value 2904a3316fc6SZhikuiRen int i = 0; 2905a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 2906a3316fc6SZhikuiRen { 2907a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 2908a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 2909a3316fc6SZhikuiRen if (argPos != std::string::npos) 2910a3316fc6SZhikuiRen { 2911a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 2912a3316fc6SZhikuiRen } 2913a3316fc6SZhikuiRen } 2914a3316fc6SZhikuiRen } 2915a3316fc6SZhikuiRen 2916d4342a92STim Lee // Get Severity template from message registry 2917d4342a92STim Lee std::string severity; 2918d4342a92STim Lee if (message != nullptr) 2919d4342a92STim Lee { 2920d4342a92STim Lee severity = message->severity; 2921d4342a92STim Lee } 2922d4342a92STim Lee 2923a3316fc6SZhikuiRen // add to AsyncResp 2924a3316fc6SZhikuiRen logEntryArray.push_back({}); 2925a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 2926d0dbeefdSEd Tanous bmcLogEntry = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 2927a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 2928a3316fc6SZhikuiRen "PostCodes/Entries/" + 2929a3316fc6SZhikuiRen postcodeEntryID}, 2930a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 2931a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 2932a3316fc6SZhikuiRen {"Message", std::move(msg)}, 29334a0bf539SManojkiran Eda {"MessageId", "OpenBMC.0.2.BIOSPOSTCode"}, 2934a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 2935a3316fc6SZhikuiRen {"EntryType", "Event"}, 2936a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 29379c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 2938a3316fc6SZhikuiRen } 2939a3316fc6SZhikuiRen } 2940a3316fc6SZhikuiRen 29418d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2942a3316fc6SZhikuiRen const uint16_t bootIndex, 2943a3316fc6SZhikuiRen const uint64_t codeIndex) 2944a3316fc6SZhikuiRen { 2945a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 29466c9a279eSManojkiran Eda [aResp, bootIndex, 29476c9a279eSManojkiran Eda codeIndex](const boost::system::error_code ec, 29486c9a279eSManojkiran Eda const boost::container::flat_map< 29496c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 29506c9a279eSManojkiran Eda postcode) { 2951a3316fc6SZhikuiRen if (ec) 2952a3316fc6SZhikuiRen { 2953a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 2954a3316fc6SZhikuiRen messages::internalError(aResp->res); 2955a3316fc6SZhikuiRen return; 2956a3316fc6SZhikuiRen } 2957a3316fc6SZhikuiRen 2958a3316fc6SZhikuiRen // skip the empty postcode boots 2959a3316fc6SZhikuiRen if (postcode.empty()) 2960a3316fc6SZhikuiRen { 2961a3316fc6SZhikuiRen return; 2962a3316fc6SZhikuiRen } 2963a3316fc6SZhikuiRen 2964a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 2965a3316fc6SZhikuiRen 2966a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 2967a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 2968a3316fc6SZhikuiRen }, 296915124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 297015124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 2971a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 2972a3316fc6SZhikuiRen bootIndex); 2973a3316fc6SZhikuiRen } 2974a3316fc6SZhikuiRen 29758d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2976a3316fc6SZhikuiRen const uint16_t bootIndex, 2977a3316fc6SZhikuiRen const uint16_t bootCount, 2978a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 2979a3316fc6SZhikuiRen const uint64_t top) 2980a3316fc6SZhikuiRen { 2981a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2982a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 2983a3316fc6SZhikuiRen top](const boost::system::error_code ec, 29846c9a279eSManojkiran Eda const boost::container::flat_map< 29856c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 29866c9a279eSManojkiran Eda postcode) { 2987a3316fc6SZhikuiRen if (ec) 2988a3316fc6SZhikuiRen { 2989a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 2990a3316fc6SZhikuiRen messages::internalError(aResp->res); 2991a3316fc6SZhikuiRen return; 2992a3316fc6SZhikuiRen } 2993a3316fc6SZhikuiRen 2994a3316fc6SZhikuiRen uint64_t endCount = entryCount; 2995a3316fc6SZhikuiRen if (!postcode.empty()) 2996a3316fc6SZhikuiRen { 2997a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 2998a3316fc6SZhikuiRen 2999a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3000a3316fc6SZhikuiRen { 3001a3316fc6SZhikuiRen uint64_t thisBootSkip = 3002a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3003a3316fc6SZhikuiRen uint64_t thisBootTop = 3004a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3005a3316fc6SZhikuiRen 3006a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3007a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3008a3316fc6SZhikuiRen } 3009a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3010a3316fc6SZhikuiRen } 3011a3316fc6SZhikuiRen 3012a3316fc6SZhikuiRen // continue to previous bootIndex 3013a3316fc6SZhikuiRen if (bootIndex < bootCount) 3014a3316fc6SZhikuiRen { 3015a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3016a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3017a3316fc6SZhikuiRen } 3018a3316fc6SZhikuiRen else 3019a3316fc6SZhikuiRen { 3020a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 3021a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3022a3316fc6SZhikuiRen "Entries?$skip=" + 3023a3316fc6SZhikuiRen std::to_string(skip + top); 3024a3316fc6SZhikuiRen } 3025a3316fc6SZhikuiRen }, 302615124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 302715124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3028a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3029a3316fc6SZhikuiRen bootIndex); 3030a3316fc6SZhikuiRen } 3031a3316fc6SZhikuiRen 30328d1b46d7Szhanghch05 static void 30338d1b46d7Szhanghch05 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3034a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3035a3316fc6SZhikuiRen { 3036a3316fc6SZhikuiRen uint64_t entryCount = 0; 3037a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3038a3316fc6SZhikuiRen [aResp, entryCount, skip, 3039a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3040a3316fc6SZhikuiRen const std::variant<uint16_t>& bootCount) { 3041a3316fc6SZhikuiRen if (ec) 3042a3316fc6SZhikuiRen { 3043a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3044a3316fc6SZhikuiRen messages::internalError(aResp->res); 3045a3316fc6SZhikuiRen return; 3046a3316fc6SZhikuiRen } 3047a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 3048a3316fc6SZhikuiRen if (pVal) 3049a3316fc6SZhikuiRen { 3050a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 3051a3316fc6SZhikuiRen } 3052a3316fc6SZhikuiRen else 3053a3316fc6SZhikuiRen { 3054a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 3055a3316fc6SZhikuiRen } 3056a3316fc6SZhikuiRen }, 305715124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 305815124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3059a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 3060a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 3061a3316fc6SZhikuiRen } 3062a3316fc6SZhikuiRen 30637e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3064a3316fc6SZhikuiRen { 30657e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 30667e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3067ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 30687e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 30697e860f15SJohn Edward Broadbent [](const crow::Request& req, 30707e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3071a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3072a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3073a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3074a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3075a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3076a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3077a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3078a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3079a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3080a3316fc6SZhikuiRen 3081a3316fc6SZhikuiRen uint64_t skip = 0; 3082a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 30838d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 3084a3316fc6SZhikuiRen { 3085a3316fc6SZhikuiRen return; 3086a3316fc6SZhikuiRen } 30878d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 3088a3316fc6SZhikuiRen { 3089a3316fc6SZhikuiRen return; 3090a3316fc6SZhikuiRen } 3091a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 30927e860f15SJohn Edward Broadbent }); 3093a3316fc6SZhikuiRen } 3094a3316fc6SZhikuiRen 30957e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 3096a3316fc6SZhikuiRen { 30977e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 30987e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/") 3099ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 31007e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 31017e860f15SJohn Edward Broadbent [](const crow::Request&, 31027e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 31037e860f15SJohn Edward Broadbent const std::string& targetID) { 3104a3316fc6SZhikuiRen size_t bootPos = targetID.find('B'); 3105a3316fc6SZhikuiRen if (bootPos == std::string::npos) 3106a3316fc6SZhikuiRen { 3107a3316fc6SZhikuiRen // Requested ID was not found 3108a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 3109a3316fc6SZhikuiRen return; 3110a3316fc6SZhikuiRen } 3111a3316fc6SZhikuiRen std::string_view bootIndexStr(targetID); 3112a3316fc6SZhikuiRen bootIndexStr.remove_prefix(bootPos + 1); 3113a3316fc6SZhikuiRen uint16_t bootIndex = 0; 3114a3316fc6SZhikuiRen uint64_t codeIndex = 0; 3115a3316fc6SZhikuiRen size_t dashPos = bootIndexStr.find('-'); 3116a3316fc6SZhikuiRen 3117a3316fc6SZhikuiRen if (dashPos == std::string::npos) 3118a3316fc6SZhikuiRen { 3119a3316fc6SZhikuiRen return; 3120a3316fc6SZhikuiRen } 3121a3316fc6SZhikuiRen std::string_view codeIndexStr(bootIndexStr); 3122a3316fc6SZhikuiRen bootIndexStr.remove_suffix(dashPos); 3123a3316fc6SZhikuiRen codeIndexStr.remove_prefix(dashPos + 1); 3124a3316fc6SZhikuiRen 3125a3316fc6SZhikuiRen bootIndex = static_cast<uint16_t>( 312623a21a1cSEd Tanous strtoul(std::string(bootIndexStr).c_str(), nullptr, 0)); 31277e860f15SJohn Edward Broadbent codeIndex = 31287e860f15SJohn Edward Broadbent strtoul(std::string(codeIndexStr).c_str(), nullptr, 0); 3129a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3130a3316fc6SZhikuiRen { 3131a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 31327e860f15SJohn Edward Broadbent << targetID; 3133a3316fc6SZhikuiRen } 3134a3316fc6SZhikuiRen 31357e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = 31367e860f15SJohn Edward Broadbent "#LogEntry.v1_4_0.LogEntry"; 3137a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3138a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3139a3316fc6SZhikuiRen "Entries"; 3140a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3141a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3142a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3143a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3144a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3145a3316fc6SZhikuiRen 3146a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 31477e860f15SJohn Edward Broadbent }); 3148a3316fc6SZhikuiRen } 3149a3316fc6SZhikuiRen 31501da66f75SEd Tanous } // namespace redfish 3151