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 18b7028ebfSSpencer Ku #include "gzfile.hpp" 19647b3cdcSGeorge Liu #include "http_utility.hpp" 20b7028ebfSSpencer Ku #include "human_sort.hpp" 214851d45dSJason M. Bills #include "registries.hpp" 224851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 234851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2446229577SJames Feist #include "task.hpp" 251da66f75SEd Tanous 26e1f26343SJason M. Bills #include <systemd/sd-journal.h> 27400fd1fbSAdriana Kobylak #include <unistd.h> 28e1f26343SJason M. Bills 297e860f15SJohn Edward Broadbent #include <app.hpp> 30400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 314851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 32400fd1fbSAdriana Kobylak #include <boost/beast/http.hpp> 331da66f75SEd Tanous #include <boost/container/flat_map.hpp> 341ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 35168e20c1SEd Tanous #include <dbus_utility.hpp> 36cb92c03bSAndrew Geissler #include <error_messages.hpp> 3745ca1b86SEd Tanous #include <query.hpp> 38ed398213SEd Tanous #include <registries/privilege_registry.hpp> 391214b7e7SGunnar Mills 40647b3cdcSGeorge Liu #include <charconv> 414418c7f0SJames Feist #include <filesystem> 4275710de2SXiaochao Ma #include <optional> 4326702d01SEd Tanous #include <span> 44cd225da8SJason M. Bills #include <string_view> 45abf2add6SEd Tanous #include <variant> 461da66f75SEd Tanous 471da66f75SEd Tanous namespace redfish 481da66f75SEd Tanous { 491da66f75SEd Tanous 505b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 515b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 525b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 535b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 545b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 555b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 56424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 576eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 586eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 591da66f75SEd Tanous 60fffb8c1fSEd Tanous namespace registries 614851d45dSJason M. Bills { 6226702d01SEd Tanous static const Message* 6326702d01SEd Tanous getMessageFromRegistry(const std::string& messageKey, 6426702d01SEd Tanous const std::span<const MessageEntry> registry) 654851d45dSJason M. Bills { 6626702d01SEd Tanous std::span<const MessageEntry>::iterator messageIt = std::find_if( 6726702d01SEd Tanous registry.begin(), registry.end(), 684851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 69e662eae8SEd Tanous return std::strcmp(messageEntry.first, messageKey.c_str()) == 0; 704851d45dSJason M. Bills }); 7126702d01SEd Tanous if (messageIt != registry.end()) 724851d45dSJason M. Bills { 734851d45dSJason M. Bills return &messageIt->second; 744851d45dSJason M. Bills } 754851d45dSJason M. Bills 764851d45dSJason M. Bills return nullptr; 774851d45dSJason M. Bills } 784851d45dSJason M. Bills 794851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 804851d45dSJason M. Bills { 814851d45dSJason M. Bills // Redfish MessageIds are in the form 824851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 834851d45dSJason M. Bills // the right Message 844851d45dSJason M. Bills std::vector<std::string> fields; 854851d45dSJason M. Bills fields.reserve(4); 864851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 874851d45dSJason M. Bills std::string& registryName = fields[0]; 884851d45dSJason M. Bills std::string& messageKey = fields[3]; 894851d45dSJason M. Bills 904851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 914851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 924851d45dSJason M. Bills { 934851d45dSJason M. Bills return getMessageFromRegistry( 9426702d01SEd Tanous messageKey, std::span<const MessageEntry>(base::registry)); 954851d45dSJason M. Bills } 964851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 974851d45dSJason M. Bills { 984851d45dSJason M. Bills return getMessageFromRegistry( 9926702d01SEd Tanous messageKey, std::span<const MessageEntry>(openbmc::registry)); 1004851d45dSJason M. Bills } 1014851d45dSJason M. Bills return nullptr; 1024851d45dSJason M. Bills } 103fffb8c1fSEd Tanous } // namespace registries 1044851d45dSJason M. Bills 105f6150403SJames Feist namespace fs = std::filesystem; 1061da66f75SEd Tanous 107cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 108cb92c03bSAndrew Geissler { 109d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 110d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 111d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 112d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 113cb92c03bSAndrew Geissler { 114cb92c03bSAndrew Geissler return "Critical"; 115cb92c03bSAndrew Geissler } 1163174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 117d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 118d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 119cb92c03bSAndrew Geissler { 120cb92c03bSAndrew Geissler return "OK"; 121cb92c03bSAndrew Geissler } 1223174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 123cb92c03bSAndrew Geissler { 124cb92c03bSAndrew Geissler return "Warning"; 125cb92c03bSAndrew Geissler } 126cb92c03bSAndrew Geissler return ""; 127cb92c03bSAndrew Geissler } 128cb92c03bSAndrew Geissler 1297e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 13039e77504SEd Tanous const std::string_view& field, 13139e77504SEd Tanous std::string_view& contents) 13216428a1aSJason M. Bills { 13316428a1aSJason M. Bills const char* data = nullptr; 13416428a1aSJason M. Bills size_t length = 0; 13516428a1aSJason M. Bills int ret = 0; 13616428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 13746ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 13846ff87baSEd Tanous const void** dataVoid = reinterpret_cast<const void**>(&data); 13946ff87baSEd Tanous 14046ff87baSEd Tanous ret = sd_journal_get_data(journal, field.data(), dataVoid, &length); 14116428a1aSJason M. Bills if (ret < 0) 14216428a1aSJason M. Bills { 14316428a1aSJason M. Bills return ret; 14416428a1aSJason M. Bills } 14539e77504SEd Tanous contents = std::string_view(data, length); 14616428a1aSJason M. Bills // Only use the content after the "=" character. 14781ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 14816428a1aSJason M. Bills return ret; 14916428a1aSJason M. Bills } 15016428a1aSJason M. Bills 1517e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 1527e860f15SJohn Edward Broadbent const std::string_view& field, 1537e860f15SJohn Edward Broadbent const int& base, long int& contents) 15416428a1aSJason M. Bills { 15516428a1aSJason M. Bills int ret = 0; 15639e77504SEd Tanous std::string_view metadata; 15716428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 15816428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 15916428a1aSJason M. Bills if (ret < 0) 16016428a1aSJason M. Bills { 16116428a1aSJason M. Bills return ret; 16216428a1aSJason M. Bills } 163b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 16416428a1aSJason M. Bills return ret; 16516428a1aSJason M. Bills } 16616428a1aSJason M. Bills 1677e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1687e860f15SJohn Edward Broadbent std::string& entryTimestamp) 169a3316fc6SZhikuiRen { 170a3316fc6SZhikuiRen int ret = 0; 171a3316fc6SZhikuiRen uint64_t timestamp = 0; 172a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 173a3316fc6SZhikuiRen if (ret < 0) 174a3316fc6SZhikuiRen { 175a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 176a3316fc6SZhikuiRen << strerror(-ret); 177a3316fc6SZhikuiRen return false; 178a3316fc6SZhikuiRen } 1791d8782e7SNan Zhou entryTimestamp = crow::utility::getDateTimeUint(timestamp / 1000 / 1000); 1809c620e21SAsmitha Karunanithi return true; 181a3316fc6SZhikuiRen } 18250b8a43aSEd Tanous 1837e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 184e85d6b16SJason M. Bills const bool firstEntry = true) 18516428a1aSJason M. Bills { 18616428a1aSJason M. Bills int ret = 0; 18716428a1aSJason M. Bills static uint64_t prevTs = 0; 18816428a1aSJason M. Bills static int index = 0; 189e85d6b16SJason M. Bills if (firstEntry) 190e85d6b16SJason M. Bills { 191e85d6b16SJason M. Bills prevTs = 0; 192e85d6b16SJason M. Bills } 193e85d6b16SJason M. Bills 19416428a1aSJason M. Bills // Get the entry timestamp 19516428a1aSJason M. Bills uint64_t curTs = 0; 19616428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 19716428a1aSJason M. Bills if (ret < 0) 19816428a1aSJason M. Bills { 19916428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 20016428a1aSJason M. Bills << strerror(-ret); 20116428a1aSJason M. Bills return false; 20216428a1aSJason M. Bills } 20316428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 20416428a1aSJason M. Bills if (curTs == prevTs) 20516428a1aSJason M. Bills { 20616428a1aSJason M. Bills index++; 20716428a1aSJason M. Bills } 20816428a1aSJason M. Bills else 20916428a1aSJason M. Bills { 21016428a1aSJason M. Bills // Otherwise, reset it 21116428a1aSJason M. Bills index = 0; 21216428a1aSJason M. Bills } 21316428a1aSJason M. Bills // Save the timestamp 21416428a1aSJason M. Bills prevTs = curTs; 21516428a1aSJason M. Bills 21616428a1aSJason M. Bills entryID = std::to_string(curTs); 21716428a1aSJason M. Bills if (index > 0) 21816428a1aSJason M. Bills { 21916428a1aSJason M. Bills entryID += "_" + std::to_string(index); 22016428a1aSJason M. Bills } 22116428a1aSJason M. Bills return true; 22216428a1aSJason M. Bills } 22316428a1aSJason M. Bills 224e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 225e85d6b16SJason M. Bills const bool firstEntry = true) 22695820184SJason M. Bills { 227271584abSEd Tanous static time_t prevTs = 0; 22895820184SJason M. Bills static int index = 0; 229e85d6b16SJason M. Bills if (firstEntry) 230e85d6b16SJason M. Bills { 231e85d6b16SJason M. Bills prevTs = 0; 232e85d6b16SJason M. Bills } 233e85d6b16SJason M. Bills 23495820184SJason M. Bills // Get the entry timestamp 235271584abSEd Tanous std::time_t curTs = 0; 23695820184SJason M. Bills std::tm timeStruct = {}; 23795820184SJason M. Bills std::istringstream entryStream(logEntry); 23895820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 23995820184SJason M. Bills { 24095820184SJason M. Bills curTs = std::mktime(&timeStruct); 24195820184SJason M. Bills } 24295820184SJason M. Bills // If the timestamp isn't unique, increment the index 24395820184SJason M. Bills if (curTs == prevTs) 24495820184SJason M. Bills { 24595820184SJason M. Bills index++; 24695820184SJason M. Bills } 24795820184SJason M. Bills else 24895820184SJason M. Bills { 24995820184SJason M. Bills // Otherwise, reset it 25095820184SJason M. Bills index = 0; 25195820184SJason M. Bills } 25295820184SJason M. Bills // Save the timestamp 25395820184SJason M. Bills prevTs = curTs; 25495820184SJason M. Bills 25595820184SJason M. Bills entryID = std::to_string(curTs); 25695820184SJason M. Bills if (index > 0) 25795820184SJason M. Bills { 25895820184SJason M. Bills entryID += "_" + std::to_string(index); 25995820184SJason M. Bills } 26095820184SJason M. Bills return true; 26195820184SJason M. Bills } 26295820184SJason M. Bills 2637e860f15SJohn Edward Broadbent inline static bool 2648d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2658d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 2668d1b46d7Szhanghch05 uint64_t& index) 26716428a1aSJason M. Bills { 26816428a1aSJason M. Bills if (entryID.empty()) 26916428a1aSJason M. Bills { 27016428a1aSJason M. Bills return false; 27116428a1aSJason M. Bills } 27216428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 27339e77504SEd Tanous std::string_view tsStr(entryID); 27416428a1aSJason M. Bills 27581ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 27671d5d8dbSEd Tanous if (underscorePos != std::string_view::npos) 27716428a1aSJason M. Bills { 27816428a1aSJason M. Bills // Timestamp has an index 27916428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 28039e77504SEd Tanous std::string_view indexStr(entryID); 28116428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 282c0bd5e4bSEd Tanous auto [ptr, ec] = std::from_chars( 283c0bd5e4bSEd Tanous indexStr.data(), indexStr.data() + indexStr.size(), index); 284c0bd5e4bSEd Tanous if (ec != std::errc()) 28516428a1aSJason M. Bills { 286ace85d60SEd Tanous messages::resourceMissingAtURI( 287ace85d60SEd Tanous asyncResp->res, crow::utility::urlFromPieces(entryID)); 28816428a1aSJason M. Bills return false; 28916428a1aSJason M. Bills } 29016428a1aSJason M. Bills } 29116428a1aSJason M. Bills // Timestamp has no index 292c0bd5e4bSEd Tanous auto [ptr, ec] = 293c0bd5e4bSEd Tanous std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp); 294c0bd5e4bSEd Tanous if (ec != std::errc()) 29516428a1aSJason M. Bills { 296ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, 297ace85d60SEd Tanous crow::utility::urlFromPieces(entryID)); 29816428a1aSJason M. Bills return false; 29916428a1aSJason M. Bills } 30016428a1aSJason M. Bills return true; 30116428a1aSJason M. Bills } 30216428a1aSJason M. Bills 30395820184SJason M. Bills static bool 30495820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 30595820184SJason M. Bills { 30695820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 30795820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 30895820184SJason M. Bills 30995820184SJason M. Bills // Loop through the directory looking for redfish log files 31095820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 31195820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 31295820184SJason M. Bills { 31395820184SJason M. Bills // If we find a redfish log file, save the path 31495820184SJason M. Bills std::string filename = dirEnt.path().filename(); 31595820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 31695820184SJason M. Bills { 31795820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 31895820184SJason M. Bills } 31995820184SJason M. Bills } 32095820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 32195820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 32295820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 32395820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 32495820184SJason M. Bills 32595820184SJason M. Bills return !redfishLogFiles.empty(); 32695820184SJason M. Bills } 32795820184SJason M. Bills 3288d1b46d7Szhanghch05 inline void 3298d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3305cb1dd27SAsmitha Karunanithi const std::string& dumpType) 3315cb1dd27SAsmitha Karunanithi { 3325cb1dd27SAsmitha Karunanithi std::string dumpPath; 3335cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 3345cb1dd27SAsmitha Karunanithi { 3355cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 3365cb1dd27SAsmitha Karunanithi } 3375cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 3385cb1dd27SAsmitha Karunanithi { 3395cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 3405cb1dd27SAsmitha Karunanithi } 3415cb1dd27SAsmitha Karunanithi else 3425cb1dd27SAsmitha Karunanithi { 3435cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 3445cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 3455cb1dd27SAsmitha Karunanithi return; 3465cb1dd27SAsmitha Karunanithi } 3475cb1dd27SAsmitha Karunanithi 3485cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 349711ac7a9SEd Tanous [asyncResp, dumpPath, 350711ac7a9SEd Tanous dumpType](const boost::system::error_code ec, 351711ac7a9SEd Tanous dbus::utility::ManagedObjectType& resp) { 3525cb1dd27SAsmitha Karunanithi if (ec) 3535cb1dd27SAsmitha Karunanithi { 3545cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 3555cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 3565cb1dd27SAsmitha Karunanithi return; 3575cb1dd27SAsmitha Karunanithi } 3585cb1dd27SAsmitha Karunanithi 3595cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 3605cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 361b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 362b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 363b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 364b47452b2SAsmitha Karunanithi "/entry/"; 3655cb1dd27SAsmitha Karunanithi 3665cb1dd27SAsmitha Karunanithi for (auto& object : resp) 3675cb1dd27SAsmitha Karunanithi { 368b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 3695cb1dd27SAsmitha Karunanithi { 3705cb1dd27SAsmitha Karunanithi continue; 3715cb1dd27SAsmitha Karunanithi } 3721d8782e7SNan Zhou uint64_t timestamp = 0; 3735cb1dd27SAsmitha Karunanithi uint64_t size = 0; 37435440d18SAsmitha Karunanithi std::string dumpStatus; 37535440d18SAsmitha Karunanithi nlohmann::json thisEntry; 3762dfd18efSEd Tanous 3772dfd18efSEd Tanous std::string entryID = object.first.filename(); 3782dfd18efSEd Tanous if (entryID.empty()) 3795cb1dd27SAsmitha Karunanithi { 3805cb1dd27SAsmitha Karunanithi continue; 3815cb1dd27SAsmitha Karunanithi } 3825cb1dd27SAsmitha Karunanithi 3835cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 3845cb1dd27SAsmitha Karunanithi { 38535440d18SAsmitha Karunanithi if (interfaceMap.first == 38635440d18SAsmitha Karunanithi "xyz.openbmc_project.Common.Progress") 38735440d18SAsmitha Karunanithi { 3889eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 38935440d18SAsmitha Karunanithi { 39035440d18SAsmitha Karunanithi if (propertyMap.first == "Status") 39135440d18SAsmitha Karunanithi { 39255f79e6fSEd Tanous const auto* status = std::get_if<std::string>( 39335440d18SAsmitha Karunanithi &propertyMap.second); 39435440d18SAsmitha Karunanithi if (status == nullptr) 39535440d18SAsmitha Karunanithi { 39635440d18SAsmitha Karunanithi messages::internalError(asyncResp->res); 39735440d18SAsmitha Karunanithi break; 39835440d18SAsmitha Karunanithi } 39935440d18SAsmitha Karunanithi dumpStatus = *status; 40035440d18SAsmitha Karunanithi } 40135440d18SAsmitha Karunanithi } 40235440d18SAsmitha Karunanithi } 40335440d18SAsmitha Karunanithi else if (interfaceMap.first == 40435440d18SAsmitha Karunanithi "xyz.openbmc_project.Dump.Entry") 4055cb1dd27SAsmitha Karunanithi { 4065cb1dd27SAsmitha Karunanithi 4075cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4085cb1dd27SAsmitha Karunanithi { 4095cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4105cb1dd27SAsmitha Karunanithi { 41155f79e6fSEd Tanous const auto* sizePtr = 4125cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4135cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4145cb1dd27SAsmitha Karunanithi { 4155cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4165cb1dd27SAsmitha Karunanithi break; 4175cb1dd27SAsmitha Karunanithi } 4185cb1dd27SAsmitha Karunanithi size = *sizePtr; 4195cb1dd27SAsmitha Karunanithi break; 4205cb1dd27SAsmitha Karunanithi } 4215cb1dd27SAsmitha Karunanithi } 4225cb1dd27SAsmitha Karunanithi } 4235cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4245cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 4255cb1dd27SAsmitha Karunanithi { 4265cb1dd27SAsmitha Karunanithi 4279eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 4285cb1dd27SAsmitha Karunanithi { 4295cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 4305cb1dd27SAsmitha Karunanithi { 4315cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 4325cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4335cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 4345cb1dd27SAsmitha Karunanithi { 4355cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4365cb1dd27SAsmitha Karunanithi break; 4375cb1dd27SAsmitha Karunanithi } 4381d8782e7SNan Zhou timestamp = (*usecsTimeStamp / 1000 / 1000); 4395cb1dd27SAsmitha Karunanithi break; 4405cb1dd27SAsmitha Karunanithi } 4415cb1dd27SAsmitha Karunanithi } 4425cb1dd27SAsmitha Karunanithi } 4435cb1dd27SAsmitha Karunanithi } 4445cb1dd27SAsmitha Karunanithi 4450fda0f12SGeorge Liu if (dumpStatus != 4460fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 44735440d18SAsmitha Karunanithi !dumpStatus.empty()) 44835440d18SAsmitha Karunanithi { 44935440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 45035440d18SAsmitha Karunanithi continue; 45135440d18SAsmitha Karunanithi } 45235440d18SAsmitha Karunanithi 453647b3cdcSGeorge Liu thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 4545cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 4555cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 4565cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 4571d8782e7SNan Zhou thisEntry["Created"] = 4581d8782e7SNan Zhou crow::utility::getDateTimeUint(timestamp); 4595cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 4605cb1dd27SAsmitha Karunanithi 461d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataSizeBytes"] = size; 4625cb1dd27SAsmitha Karunanithi 4635cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 4645cb1dd27SAsmitha Karunanithi { 465d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 466d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 467de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 468de8d94a3SAbhishek Patel entryID + "/attachment"; 4695cb1dd27SAsmitha Karunanithi } 4705cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 4715cb1dd27SAsmitha Karunanithi { 472d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 473d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 474d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 475de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 476de8d94a3SAbhishek Patel entryID + "/attachment"; 4775cb1dd27SAsmitha Karunanithi } 47835440d18SAsmitha Karunanithi entriesArray.push_back(std::move(thisEntry)); 4795cb1dd27SAsmitha Karunanithi } 4805cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 4815cb1dd27SAsmitha Karunanithi entriesArray.size(); 4825cb1dd27SAsmitha Karunanithi }, 4835cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 4845cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 4855cb1dd27SAsmitha Karunanithi } 4865cb1dd27SAsmitha Karunanithi 4878d1b46d7Szhanghch05 inline void 48845ca1b86SEd Tanous getDumpEntryById(crow::App& app, const crow::Request& req, 48945ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4908d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 4915cb1dd27SAsmitha Karunanithi { 49245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 49345ca1b86SEd Tanous { 49445ca1b86SEd Tanous return; 49545ca1b86SEd Tanous } 4965cb1dd27SAsmitha Karunanithi std::string dumpPath; 4975cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 4985cb1dd27SAsmitha Karunanithi { 4995cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5005cb1dd27SAsmitha Karunanithi } 5015cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5025cb1dd27SAsmitha Karunanithi { 5035cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5045cb1dd27SAsmitha Karunanithi } 5055cb1dd27SAsmitha Karunanithi else 5065cb1dd27SAsmitha Karunanithi { 5075cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5085cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5095cb1dd27SAsmitha Karunanithi return; 5105cb1dd27SAsmitha Karunanithi } 5115cb1dd27SAsmitha Karunanithi 5125cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 513711ac7a9SEd Tanous [asyncResp, entryID, dumpPath, 514711ac7a9SEd Tanous dumpType](const boost::system::error_code ec, 515711ac7a9SEd Tanous dbus::utility::ManagedObjectType& resp) { 5165cb1dd27SAsmitha Karunanithi if (ec) 5175cb1dd27SAsmitha Karunanithi { 5185cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5195cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5205cb1dd27SAsmitha Karunanithi return; 5215cb1dd27SAsmitha Karunanithi } 5225cb1dd27SAsmitha Karunanithi 523b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 524b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 525b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 526b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 527b47452b2SAsmitha Karunanithi "/entry/"; 528b47452b2SAsmitha Karunanithi 5299eb808c1SEd Tanous for (const auto& objectPath : resp) 5305cb1dd27SAsmitha Karunanithi { 531b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5325cb1dd27SAsmitha Karunanithi { 5335cb1dd27SAsmitha Karunanithi continue; 5345cb1dd27SAsmitha Karunanithi } 5355cb1dd27SAsmitha Karunanithi 5365cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 5371d8782e7SNan Zhou uint64_t timestamp = 0; 5385cb1dd27SAsmitha Karunanithi uint64_t size = 0; 53935440d18SAsmitha Karunanithi std::string dumpStatus; 5405cb1dd27SAsmitha Karunanithi 5419eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 5425cb1dd27SAsmitha Karunanithi { 54335440d18SAsmitha Karunanithi if (interfaceMap.first == 54435440d18SAsmitha Karunanithi "xyz.openbmc_project.Common.Progress") 54535440d18SAsmitha Karunanithi { 5469eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 54735440d18SAsmitha Karunanithi { 54835440d18SAsmitha Karunanithi if (propertyMap.first == "Status") 54935440d18SAsmitha Karunanithi { 5509eb808c1SEd Tanous const std::string* status = 5519eb808c1SEd Tanous std::get_if<std::string>( 55235440d18SAsmitha Karunanithi &propertyMap.second); 55335440d18SAsmitha Karunanithi if (status == nullptr) 55435440d18SAsmitha Karunanithi { 55535440d18SAsmitha Karunanithi messages::internalError(asyncResp->res); 55635440d18SAsmitha Karunanithi break; 55735440d18SAsmitha Karunanithi } 55835440d18SAsmitha Karunanithi dumpStatus = *status; 55935440d18SAsmitha Karunanithi } 56035440d18SAsmitha Karunanithi } 56135440d18SAsmitha Karunanithi } 56235440d18SAsmitha Karunanithi else if (interfaceMap.first == 56335440d18SAsmitha Karunanithi "xyz.openbmc_project.Dump.Entry") 5645cb1dd27SAsmitha Karunanithi { 5659eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 5665cb1dd27SAsmitha Karunanithi { 5675cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 5685cb1dd27SAsmitha Karunanithi { 5699eb808c1SEd Tanous const uint64_t* sizePtr = 5705cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5715cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 5725cb1dd27SAsmitha Karunanithi { 5735cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5745cb1dd27SAsmitha Karunanithi break; 5755cb1dd27SAsmitha Karunanithi } 5765cb1dd27SAsmitha Karunanithi size = *sizePtr; 5775cb1dd27SAsmitha Karunanithi break; 5785cb1dd27SAsmitha Karunanithi } 5795cb1dd27SAsmitha Karunanithi } 5805cb1dd27SAsmitha Karunanithi } 5815cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 5825cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 5835cb1dd27SAsmitha Karunanithi { 5849eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 5855cb1dd27SAsmitha Karunanithi { 5865cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 5875cb1dd27SAsmitha Karunanithi { 5885cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 5895cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5905cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 5915cb1dd27SAsmitha Karunanithi { 5925cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5935cb1dd27SAsmitha Karunanithi break; 5945cb1dd27SAsmitha Karunanithi } 5951d8782e7SNan Zhou timestamp = *usecsTimeStamp / 1000 / 1000; 5965cb1dd27SAsmitha Karunanithi break; 5975cb1dd27SAsmitha Karunanithi } 5985cb1dd27SAsmitha Karunanithi } 5995cb1dd27SAsmitha Karunanithi } 6005cb1dd27SAsmitha Karunanithi } 6015cb1dd27SAsmitha Karunanithi 6020fda0f12SGeorge Liu if (dumpStatus != 6030fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 60435440d18SAsmitha Karunanithi !dumpStatus.empty()) 60535440d18SAsmitha Karunanithi { 60635440d18SAsmitha Karunanithi // Dump status is not Complete 60735440d18SAsmitha Karunanithi // return not found until status is changed to Completed 60835440d18SAsmitha Karunanithi messages::resourceNotFound(asyncResp->res, 60935440d18SAsmitha Karunanithi dumpType + " dump", entryID); 61035440d18SAsmitha Karunanithi return; 61135440d18SAsmitha Karunanithi } 61235440d18SAsmitha Karunanithi 6135cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 614647b3cdcSGeorge Liu "#LogEntry.v1_8_0.LogEntry"; 6155cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6165cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6175cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6185cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6191d8782e7SNan Zhou crow::utility::getDateTimeUint(timestamp); 6205cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6215cb1dd27SAsmitha Karunanithi 622d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6235cb1dd27SAsmitha Karunanithi 6245cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6255cb1dd27SAsmitha Karunanithi { 626d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 627d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 628de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 629de8d94a3SAbhishek Patel entryID + "/attachment"; 6305cb1dd27SAsmitha Karunanithi } 6315cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6325cb1dd27SAsmitha Karunanithi { 633d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 634d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["OEMDiagnosticDataType"] = 6355cb1dd27SAsmitha Karunanithi "System"; 636d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 637de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 638de8d94a3SAbhishek Patel entryID + "/attachment"; 6395cb1dd27SAsmitha Karunanithi } 6405cb1dd27SAsmitha Karunanithi } 641e05aec50SEd Tanous if (!foundDumpEntry) 642b47452b2SAsmitha Karunanithi { 643b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 644b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 645b47452b2SAsmitha Karunanithi return; 646b47452b2SAsmitha Karunanithi } 6475cb1dd27SAsmitha Karunanithi }, 6485cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6495cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6505cb1dd27SAsmitha Karunanithi } 6515cb1dd27SAsmitha Karunanithi 6528d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6539878256fSStanley Chu const std::string& entryID, 654b47452b2SAsmitha Karunanithi const std::string& dumpType) 6555cb1dd27SAsmitha Karunanithi { 6563de8d8baSGeorge Liu auto respHandler = [asyncResp, 6573de8d8baSGeorge Liu entryID](const boost::system::error_code ec) { 6585cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6595cb1dd27SAsmitha Karunanithi if (ec) 6605cb1dd27SAsmitha Karunanithi { 6613de8d8baSGeorge Liu if (ec.value() == EBADR) 6623de8d8baSGeorge Liu { 6633de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 6643de8d8baSGeorge Liu return; 6653de8d8baSGeorge Liu } 6665cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 6675cb1dd27SAsmitha Karunanithi << ec; 6685cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6695cb1dd27SAsmitha Karunanithi return; 6705cb1dd27SAsmitha Karunanithi } 6715cb1dd27SAsmitha Karunanithi }; 6725cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 6735cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 674b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 675b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 676b47452b2SAsmitha Karunanithi entryID, 6775cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 6785cb1dd27SAsmitha Karunanithi } 6795cb1dd27SAsmitha Karunanithi 6808d1b46d7Szhanghch05 inline void 68198be3e39SEd Tanous createDumpTaskCallback(task::Payload&& payload, 6828d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6838d1b46d7Szhanghch05 const uint32_t& dumpId, const std::string& dumpPath, 684a43be80fSAsmitha Karunanithi const std::string& dumpType) 685a43be80fSAsmitha Karunanithi { 686a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 6876145ed6fSAsmitha Karunanithi [dumpId, dumpPath, dumpType]( 688a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 689a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 690cb13a392SEd Tanous if (err) 691cb13a392SEd Tanous { 6926145ed6fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Error in creating a dump"; 6936145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 6946145ed6fSAsmitha Karunanithi return task::completed; 695cb13a392SEd Tanous } 696b9d36b47SEd Tanous 697b9d36b47SEd Tanous dbus::utility::DBusInteracesMap interfacesList; 698a43be80fSAsmitha Karunanithi 699a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 700a43be80fSAsmitha Karunanithi 701a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 702a43be80fSAsmitha Karunanithi 703b47452b2SAsmitha Karunanithi if (objPath.str == 704b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 705b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 706b47452b2SAsmitha Karunanithi "/entry/" + std::to_string(dumpId)) 707a43be80fSAsmitha Karunanithi { 708a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 709a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 710a43be80fSAsmitha Karunanithi 711a43be80fSAsmitha Karunanithi std::string headerLoc = 712a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 713a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 714a43be80fSAsmitha Karunanithi std::move(headerLoc)); 715a43be80fSAsmitha Karunanithi 716a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 717b47452b2SAsmitha Karunanithi return task::completed; 7186145ed6fSAsmitha Karunanithi } 719a43be80fSAsmitha Karunanithi return task::completed; 720a43be80fSAsmitha Karunanithi }, 7214978b63fSJason M. Bills "type='signal',interface='org.freedesktop.DBus.ObjectManager'," 722a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 723a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 724a43be80fSAsmitha Karunanithi 725a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 726a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 72798be3e39SEd Tanous task->payload.emplace(std::move(payload)); 728a43be80fSAsmitha Karunanithi } 729a43be80fSAsmitha Karunanithi 7308d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7318d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 732a43be80fSAsmitha Karunanithi { 733a43be80fSAsmitha Karunanithi std::string dumpPath; 734a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 735a43be80fSAsmitha Karunanithi { 736a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 737a43be80fSAsmitha Karunanithi } 738a43be80fSAsmitha Karunanithi else if (dumpType == "System") 739a43be80fSAsmitha Karunanithi { 740a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 741a43be80fSAsmitha Karunanithi } 742a43be80fSAsmitha Karunanithi else 743a43be80fSAsmitha Karunanithi { 744a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 745a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 746a43be80fSAsmitha Karunanithi return; 747a43be80fSAsmitha Karunanithi } 748a43be80fSAsmitha Karunanithi 749a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 750a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 751a43be80fSAsmitha Karunanithi 75215ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 753a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 754a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 755a43be80fSAsmitha Karunanithi { 756a43be80fSAsmitha Karunanithi return; 757a43be80fSAsmitha Karunanithi } 758a43be80fSAsmitha Karunanithi 759a43be80fSAsmitha Karunanithi if (dumpType == "System") 760a43be80fSAsmitha Karunanithi { 761a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 762a43be80fSAsmitha Karunanithi { 7634978b63fSJason M. Bills BMCWEB_LOG_ERROR 7644978b63fSJason M. Bills << "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"; 765a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 766a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 767a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 768a43be80fSAsmitha Karunanithi return; 769a43be80fSAsmitha Karunanithi } 7703174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 771a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 772a43be80fSAsmitha Karunanithi { 773a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 774ace85d60SEd Tanous messages::internalError(asyncResp->res); 775a43be80fSAsmitha Karunanithi return; 776a43be80fSAsmitha Karunanithi } 777a43be80fSAsmitha Karunanithi } 778a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 779a43be80fSAsmitha Karunanithi { 780a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 781a43be80fSAsmitha Karunanithi { 7820fda0f12SGeorge Liu BMCWEB_LOG_ERROR 7830fda0f12SGeorge Liu << "CreateDump action parameter 'DiagnosticDataType' not found!"; 784a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 785a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 786a43be80fSAsmitha Karunanithi return; 787a43be80fSAsmitha Karunanithi } 7883174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 789a43be80fSAsmitha Karunanithi { 790a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 791a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 792ace85d60SEd Tanous messages::internalError(asyncResp->res); 793a43be80fSAsmitha Karunanithi return; 794a43be80fSAsmitha Karunanithi } 795a43be80fSAsmitha Karunanithi } 796a43be80fSAsmitha Karunanithi 797a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 79898be3e39SEd Tanous [asyncResp, payload(task::Payload(req)), dumpPath, 79998be3e39SEd Tanous dumpType](const boost::system::error_code ec, 80098be3e39SEd Tanous const uint32_t& dumpId) mutable { 801a43be80fSAsmitha Karunanithi if (ec) 802a43be80fSAsmitha Karunanithi { 803a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 804a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 805a43be80fSAsmitha Karunanithi return; 806a43be80fSAsmitha Karunanithi } 807a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 808a43be80fSAsmitha Karunanithi 80998be3e39SEd Tanous createDumpTaskCallback(std::move(payload), asyncResp, dumpId, 81098be3e39SEd Tanous dumpPath, dumpType); 811a43be80fSAsmitha Karunanithi }, 812b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 813b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 814b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 815a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 816a43be80fSAsmitha Karunanithi } 817a43be80fSAsmitha Karunanithi 8188d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8198d1b46d7Szhanghch05 const std::string& dumpType) 82080319af1SAsmitha Karunanithi { 821b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 822b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 8238d1b46d7Szhanghch05 82480319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 825b9d36b47SEd Tanous [asyncResp, dumpType]( 826b9d36b47SEd Tanous const boost::system::error_code ec, 827b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 82880319af1SAsmitha Karunanithi if (ec) 82980319af1SAsmitha Karunanithi { 83080319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 83180319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 83280319af1SAsmitha Karunanithi return; 83380319af1SAsmitha Karunanithi } 83480319af1SAsmitha Karunanithi 83580319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 83680319af1SAsmitha Karunanithi { 8372dfd18efSEd Tanous sdbusplus::message::object_path objPath(path); 8382dfd18efSEd Tanous std::string logID = objPath.filename(); 8392dfd18efSEd Tanous if (logID.empty()) 84080319af1SAsmitha Karunanithi { 8412dfd18efSEd Tanous continue; 84280319af1SAsmitha Karunanithi } 8432dfd18efSEd Tanous deleteDumpEntry(asyncResp, logID, dumpType); 84480319af1SAsmitha Karunanithi } 84580319af1SAsmitha Karunanithi }, 84680319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 84780319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 84880319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 849b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, 850b47452b2SAsmitha Karunanithi std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." + 851b47452b2SAsmitha Karunanithi dumpType}); 85280319af1SAsmitha Karunanithi } 85380319af1SAsmitha Karunanithi 854b9d36b47SEd Tanous inline static void 855b9d36b47SEd Tanous parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params, 856b9d36b47SEd Tanous std::string& filename, std::string& timestamp, 857b9d36b47SEd Tanous std::string& logfile) 858043a0536SJohnathan Mantey { 859043a0536SJohnathan Mantey for (auto property : params) 860043a0536SJohnathan Mantey { 861043a0536SJohnathan Mantey if (property.first == "Timestamp") 862043a0536SJohnathan Mantey { 863043a0536SJohnathan Mantey const std::string* value = 8648d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 865043a0536SJohnathan Mantey if (value != nullptr) 866043a0536SJohnathan Mantey { 867043a0536SJohnathan Mantey timestamp = *value; 868043a0536SJohnathan Mantey } 869043a0536SJohnathan Mantey } 870043a0536SJohnathan Mantey else if (property.first == "Filename") 871043a0536SJohnathan Mantey { 872043a0536SJohnathan Mantey const std::string* value = 8738d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 874043a0536SJohnathan Mantey if (value != nullptr) 875043a0536SJohnathan Mantey { 876043a0536SJohnathan Mantey filename = *value; 877043a0536SJohnathan Mantey } 878043a0536SJohnathan Mantey } 879043a0536SJohnathan Mantey else if (property.first == "Log") 880043a0536SJohnathan Mantey { 881043a0536SJohnathan Mantey const std::string* value = 8828d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 883043a0536SJohnathan Mantey if (value != nullptr) 884043a0536SJohnathan Mantey { 885043a0536SJohnathan Mantey logfile = *value; 886043a0536SJohnathan Mantey } 887043a0536SJohnathan Mantey } 888043a0536SJohnathan Mantey } 889043a0536SJohnathan Mantey } 890043a0536SJohnathan Mantey 891a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 8927e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 8931da66f75SEd Tanous { 894c4bf6374SJason M. Bills /** 895c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 896c4bf6374SJason M. Bills */ 8977e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/") 898ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 89945ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 90045ca1b86SEd Tanous const std::shared_ptr< 90145ca1b86SEd Tanous bmcweb::AsyncResp>& 90245ca1b86SEd Tanous asyncResp) { 90345ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 904c4bf6374SJason M. Bills { 90545ca1b86SEd Tanous return; 90645ca1b86SEd Tanous } 9077e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 9087e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 909c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 910c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 911c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 912029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 91345ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 914c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 915c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 9167e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 9177e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 918c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 919*1476687dSEd Tanous nlohmann::json::object_t eventLog; 920*1476687dSEd Tanous eventLog["@odata.id"] = 921*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 922*1476687dSEd Tanous logServiceArray.push_back(std::move(eventLog)); 9235cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 924*1476687dSEd Tanous nlohmann::json::object_t dumpLog; 925*1476687dSEd Tanous eventLog["@odata.id"] = 926*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump"; 927*1476687dSEd Tanous logServiceArray.push_back(std::move(dumpLog)); 928c9bb6861Sraviteja-b #endif 929c9bb6861Sraviteja-b 930d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 931*1476687dSEd Tanous nlohmann::json::object_t crashdump; 932*1476687dSEd Tanous crashdump["@odata.id"] = 933*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump"; 934*1476687dSEd Tanous logServiceArray.push_back(std::move(crashdump)); 935d53dd41fSJason M. Bills #endif 936b7028ebfSSpencer Ku 937b7028ebfSSpencer Ku #ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER 938*1476687dSEd Tanous nlohmann::json::object_t hostlogger; 939*1476687dSEd Tanous hostlogger["@odata.id"] = 940*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger"; 941*1476687dSEd Tanous logServiceArray.push_back(std::move(hostlogger)); 942b7028ebfSSpencer Ku #endif 943c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 944c4bf6374SJason M. Bills logServiceArray.size(); 945a3316fc6SZhikuiRen 946a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 94745ca1b86SEd Tanous [asyncResp](const boost::system::error_code ec, 948b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& 949b9d36b47SEd Tanous subtreePath) { 950a3316fc6SZhikuiRen if (ec) 951a3316fc6SZhikuiRen { 952a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 953a3316fc6SZhikuiRen return; 954a3316fc6SZhikuiRen } 955a3316fc6SZhikuiRen 95655f79e6fSEd Tanous for (const auto& pathStr : subtreePath) 957a3316fc6SZhikuiRen { 958a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 959a3316fc6SZhikuiRen { 96023a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 961a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 96223a21a1cSEd Tanous logServiceArrayLocal.push_back( 9630fda0f12SGeorge Liu {{"@odata.id", 9640fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes"}}); 96545ca1b86SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 96623a21a1cSEd Tanous logServiceArrayLocal.size(); 967a3316fc6SZhikuiRen return; 968a3316fc6SZhikuiRen } 969a3316fc6SZhikuiRen } 970a3316fc6SZhikuiRen }, 971a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 972a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 97345ca1b86SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 97445ca1b86SEd Tanous std::array<const char*, 1>{postCodeIface}); 9757e860f15SJohn Edward Broadbent }); 976c4bf6374SJason M. Bills } 977c4bf6374SJason M. Bills 9787e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 979c4bf6374SJason M. Bills { 9807e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 981ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 98245ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 98345ca1b86SEd Tanous const std::shared_ptr< 98445ca1b86SEd Tanous bmcweb::AsyncResp>& 98545ca1b86SEd Tanous asyncResp) { 98645ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 98745ca1b86SEd Tanous { 98845ca1b86SEd Tanous return; 98945ca1b86SEd Tanous } 990c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 991029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 992c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 993c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 994c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 9957e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 9967e860f15SJohn Edward Broadbent "System Event Log Service"; 997c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 998c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 9997c8c4058STejas Patil 10007c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 10017c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 10027c8c4058STejas Patil 10037c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 10047c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 10057c8c4058STejas Patil redfishDateTimeOffset.second; 10067c8c4058STejas Patil 1007*1476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 1008*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1009e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1010e7d6c8b2SGunnar Mills 10110fda0f12SGeorge Liu {"target", 10120fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog"}}; 10137e860f15SJohn Edward Broadbent }); 1014489640c6SJason M. Bills } 1015489640c6SJason M. Bills 10167e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1017489640c6SJason M. Bills { 10184978b63fSJason M. Bills BMCWEB_ROUTE( 10194978b63fSJason M. Bills app, 10204978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/") 1021432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 10227e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 102345ca1b86SEd Tanous [&app](const crow::Request& req, 10247e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 102545ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 102645ca1b86SEd Tanous { 102745ca1b86SEd Tanous return; 102845ca1b86SEd Tanous } 1029489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1030489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1031489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1032489640c6SJason M. Bills { 1033489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1034489640c6SJason M. Bills { 1035489640c6SJason M. Bills std::error_code ec; 1036489640c6SJason M. Bills std::filesystem::remove(file, ec); 1037489640c6SJason M. Bills } 1038489640c6SJason M. Bills } 1039489640c6SJason M. Bills 1040489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1041489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1042489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1043489640c6SJason M. Bills if (ec) 1044489640c6SJason M. Bills { 10457e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " 10467e860f15SJohn Edward Broadbent << ec; 1047489640c6SJason M. Bills messages::internalError(asyncResp->res); 1048489640c6SJason M. Bills return; 1049489640c6SJason M. Bills } 1050489640c6SJason M. Bills 1051489640c6SJason M. Bills messages::success(asyncResp->res); 1052489640c6SJason M. Bills }, 1053489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 10547e860f15SJohn Edward Broadbent "org.freedesktop.systemd1.Manager", "ReloadUnit", 10557e860f15SJohn Edward Broadbent "rsyslog.service", "replace"); 10567e860f15SJohn Edward Broadbent }); 1057c4bf6374SJason M. Bills } 1058c4bf6374SJason M. Bills 105995820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 1060b5a76932SEd Tanous const std::string& logEntry, 106195820184SJason M. Bills nlohmann::json& logEntryJson) 1062c4bf6374SJason M. Bills { 106395820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1064cd225da8SJason M. Bills // First get the Timestamp 1065f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1066cd225da8SJason M. Bills if (space == std::string::npos) 106795820184SJason M. Bills { 106895820184SJason M. Bills return 1; 106995820184SJason M. Bills } 1070cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1071cd225da8SJason M. Bills // Then get the log contents 1072f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1073cd225da8SJason M. Bills if (entryStart == std::string::npos) 1074cd225da8SJason M. Bills { 1075cd225da8SJason M. Bills return 1; 1076cd225da8SJason M. Bills } 1077cd225da8SJason M. Bills std::string_view entry(logEntry); 1078cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1079cd225da8SJason M. Bills // Use split to separate the entry into its fields 1080cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1081cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1082cd225da8SJason M. Bills boost::token_compress_on); 1083cd225da8SJason M. Bills // We need at least a MessageId to be valid 108426f6976fSEd Tanous if (logEntryFields.empty()) 1085cd225da8SJason M. Bills { 1086cd225da8SJason M. Bills return 1; 1087cd225da8SJason M. Bills } 1088cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 108995820184SJason M. Bills 10904851d45dSJason M. Bills // Get the Message from the MessageRegistry 1091fffb8c1fSEd Tanous const registries::Message* message = registries::getMessage(messageID); 1092c4bf6374SJason M. Bills 109354417b02SSui Chen if (message == nullptr) 1094c4bf6374SJason M. Bills { 109554417b02SSui Chen BMCWEB_LOG_WARNING << "Log entry not found in registry: " << logEntry; 109654417b02SSui Chen return 0; 1097c4bf6374SJason M. Bills } 1098c4bf6374SJason M. Bills 109954417b02SSui Chen std::string msg = message->message; 110054417b02SSui Chen 110115a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 110226702d01SEd Tanous std::span<std::string> messageArgs; 110315a86ff6SJason M. Bills if (logEntryFields.size() > 1) 110415a86ff6SJason M. Bills { 110515a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 110615a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 110715a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 110815a86ff6SJason M. Bills if (!messageArgsStart.empty()) 110915a86ff6SJason M. Bills { 111015a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 111115a86ff6SJason M. Bills } 111215a86ff6SJason M. Bills 111323a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1114c4bf6374SJason M. Bills 11154851d45dSJason M. Bills // Fill the MessageArgs into the Message 111695820184SJason M. Bills int i = 0; 111795820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11184851d45dSJason M. Bills { 111995820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11204851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11214851d45dSJason M. Bills if (argPos != std::string::npos) 11224851d45dSJason M. Bills { 112395820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11244851d45dSJason M. Bills } 11254851d45dSJason M. Bills } 112615a86ff6SJason M. Bills } 11274851d45dSJason M. Bills 112895820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 112995820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 113095820184SJason M. Bills // between the '.' and the '+', so just remove them. 1131f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1132f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 113395820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1134c4bf6374SJason M. Bills { 113595820184SJason M. Bills timestamp.erase(dot, plus - dot); 1136c4bf6374SJason M. Bills } 1137c4bf6374SJason M. Bills 1138c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 113995820184SJason M. Bills logEntryJson = { 1140647b3cdcSGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 1141029573d4SEd Tanous {"@odata.id", 1142897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 114395820184SJason M. Bills logEntryID}, 1144c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 114595820184SJason M. Bills {"Id", logEntryID}, 114695820184SJason M. Bills {"Message", std::move(msg)}, 114795820184SJason M. Bills {"MessageId", std::move(messageID)}, 1148f23b7296SEd Tanous {"MessageArgs", messageArgs}, 1149c4bf6374SJason M. Bills {"EntryType", "Event"}, 115054417b02SSui Chen {"Severity", message->messageSeverity}, 115195820184SJason M. Bills {"Created", std::move(timestamp)}}; 1152c4bf6374SJason M. Bills return 0; 1153c4bf6374SJason M. Bills } 1154c4bf6374SJason M. Bills 11557e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1156c4bf6374SJason M. Bills { 11577e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 11587e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 11598b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 116045ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 116145ca1b86SEd Tanous const std::shared_ptr< 116245ca1b86SEd Tanous bmcweb::AsyncResp>& 116345ca1b86SEd Tanous asyncResp) { 1164c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1165c937d2bfSEd Tanous .canDelegateTop = true, 1166c937d2bfSEd Tanous .canDelegateSkip = true, 1167c937d2bfSEd Tanous }; 1168c937d2bfSEd Tanous query_param::Query delegatedQuery; 1169c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 1170c937d2bfSEd Tanous app, req, asyncResp->res, delegatedQuery, capabilities)) 1171c4bf6374SJason M. Bills { 1172c4bf6374SJason M. Bills return; 1173c4bf6374SJason M. Bills } 11747e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 11757e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1176c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1177c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1178c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1179029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1180c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1181c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1182c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1183cb92c03bSAndrew Geissler 11844978b63fSJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1185c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 11867e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 11877e860f15SJohn Edward Broadbent // entry 118895820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 118995820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1190b01bf299SEd Tanous uint64_t entryCount = 0; 1191cd225da8SJason M. Bills std::string logEntry; 119295820184SJason M. Bills 11937e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 11947e860f15SJohn Edward Broadbent // backwards 11957e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 11967e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1197c4bf6374SJason M. Bills { 1198cd225da8SJason M. Bills std::ifstream logStream(*it); 119995820184SJason M. Bills if (!logStream.is_open()) 1200c4bf6374SJason M. Bills { 1201c4bf6374SJason M. Bills continue; 1202c4bf6374SJason M. Bills } 1203c4bf6374SJason M. Bills 1204e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1205e85d6b16SJason M. Bills bool firstEntry = true; 120695820184SJason M. Bills while (std::getline(logStream, logEntry)) 120795820184SJason M. Bills { 1208c4bf6374SJason M. Bills entryCount++; 12097e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip 12107e860f15SJohn Edward Broadbent // from the start) and top (number of entries to 12117e860f15SJohn Edward Broadbent // display) 1212c937d2bfSEd Tanous if (entryCount <= delegatedQuery.skip || 1213c937d2bfSEd Tanous entryCount > delegatedQuery.skip + delegatedQuery.top) 1214c4bf6374SJason M. Bills { 1215c4bf6374SJason M. Bills continue; 1216c4bf6374SJason M. Bills } 1217c4bf6374SJason M. Bills 1218c4bf6374SJason M. Bills std::string idStr; 1219e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1220c4bf6374SJason M. Bills { 1221c4bf6374SJason M. Bills continue; 1222c4bf6374SJason M. Bills } 1223c4bf6374SJason M. Bills 1224e85d6b16SJason M. Bills if (firstEntry) 1225e85d6b16SJason M. Bills { 1226e85d6b16SJason M. Bills firstEntry = false; 1227e85d6b16SJason M. Bills } 1228e85d6b16SJason M. Bills 1229c4bf6374SJason M. Bills logEntryArray.push_back({}); 1230c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 12314978b63fSJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 12324978b63fSJason M. Bills 0) 1233c4bf6374SJason M. Bills { 1234c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1235c4bf6374SJason M. Bills return; 1236c4bf6374SJason M. Bills } 1237c4bf6374SJason M. Bills } 123895820184SJason M. Bills } 1239c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1240c937d2bfSEd Tanous if (delegatedQuery.skip + delegatedQuery.top < entryCount) 1241c4bf6374SJason M. Bills { 1242c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 12434978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries?$skip=" + 1244c937d2bfSEd Tanous std::to_string(delegatedQuery.skip + delegatedQuery.top); 1245c4bf6374SJason M. Bills } 12467e860f15SJohn Edward Broadbent }); 1247897967deSJason M. Bills } 1248897967deSJason M. Bills 12497e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1250897967deSJason M. Bills { 12517e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 12527e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1253ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 12547e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 125545ca1b86SEd Tanous [&app](const crow::Request& req, 12567e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12577e860f15SJohn Edward Broadbent const std::string& param) { 125845ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 125945ca1b86SEd Tanous { 126045ca1b86SEd Tanous return; 126145ca1b86SEd Tanous } 12627e860f15SJohn Edward Broadbent const std::string& targetID = param; 12638d1b46d7Szhanghch05 12647e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 12657e860f15SJohn Edward Broadbent // entry to find the target entry 1266897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1267897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1268897967deSJason M. Bills std::string logEntry; 1269897967deSJason M. Bills 12707e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12717e860f15SJohn Edward Broadbent // backwards 12727e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 12737e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1274897967deSJason M. Bills { 1275897967deSJason M. Bills std::ifstream logStream(*it); 1276897967deSJason M. Bills if (!logStream.is_open()) 1277897967deSJason M. Bills { 1278897967deSJason M. Bills continue; 1279897967deSJason M. Bills } 1280897967deSJason M. Bills 1281897967deSJason M. Bills // Reset the unique ID on the first entry 1282897967deSJason M. Bills bool firstEntry = true; 1283897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1284897967deSJason M. Bills { 1285897967deSJason M. Bills std::string idStr; 1286897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1287897967deSJason M. Bills { 1288897967deSJason M. Bills continue; 1289897967deSJason M. Bills } 1290897967deSJason M. Bills 1291897967deSJason M. Bills if (firstEntry) 1292897967deSJason M. Bills { 1293897967deSJason M. Bills firstEntry = false; 1294897967deSJason M. Bills } 1295897967deSJason M. Bills 1296897967deSJason M. Bills if (idStr == targetID) 1297897967deSJason M. Bills { 12987e860f15SJohn Edward Broadbent if (fillEventLogEntryJson( 12997e860f15SJohn Edward Broadbent idStr, logEntry, 1300897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1301897967deSJason M. Bills { 1302897967deSJason M. Bills messages::internalError(asyncResp->res); 1303897967deSJason M. Bills return; 1304897967deSJason M. Bills } 1305897967deSJason M. Bills return; 1306897967deSJason M. Bills } 1307897967deSJason M. Bills } 1308897967deSJason M. Bills } 1309897967deSJason M. Bills // Requested ID was not found 1310ace85d60SEd Tanous messages::resourceMissingAtURI( 1311ace85d60SEd Tanous asyncResp->res, crow::utility::urlFromPieces(targetID)); 13127e860f15SJohn Edward Broadbent }); 131308a4e4b5SAnthony Wilson } 131408a4e4b5SAnthony Wilson 13157e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 131608a4e4b5SAnthony Wilson { 13177e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 13187e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1319ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 132045ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 132145ca1b86SEd Tanous const std::shared_ptr< 132245ca1b86SEd Tanous bmcweb::AsyncResp>& 132345ca1b86SEd Tanous asyncResp) { 132445ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 132545ca1b86SEd Tanous { 132645ca1b86SEd Tanous return; 132745ca1b86SEd Tanous } 13287e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 13297e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 133008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 133108a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 133208a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 133308a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 133408a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 133508a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 133608a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 133708a4e4b5SAnthony Wilson 1338cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1339cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1340cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1341cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1342914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& resp) { 1343cb92c03bSAndrew Geissler if (ec) 1344cb92c03bSAndrew Geissler { 1345cb92c03bSAndrew Geissler // TODO Handle for specific error code 1346cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1347cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1348cb92c03bSAndrew Geissler << ec; 1349cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1350cb92c03bSAndrew Geissler return; 1351cb92c03bSAndrew Geissler } 1352cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1353cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1354cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 13559eb808c1SEd Tanous for (const auto& objectPath : resp) 1356cb92c03bSAndrew Geissler { 1357914e2d5dSEd Tanous const uint32_t* id = nullptr; 1358c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1359c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1360914e2d5dSEd Tanous const std::string* severity = nullptr; 1361914e2d5dSEd Tanous const std::string* message = nullptr; 1362914e2d5dSEd Tanous const std::string* filePath = nullptr; 136375710de2SXiaochao Ma bool resolved = false; 13649eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 1365f86bb901SAdriana Kobylak { 1366f86bb901SAdriana Kobylak if (interfaceMap.first == 1367f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1368f86bb901SAdriana Kobylak { 13699eb808c1SEd Tanous for (const auto& propertyMap : 13709eb808c1SEd Tanous interfaceMap.second) 1371cb92c03bSAndrew Geissler { 1372cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1373cb92c03bSAndrew Geissler { 1374f86bb901SAdriana Kobylak id = std::get_if<uint32_t>( 1375f86bb901SAdriana Kobylak &propertyMap.second); 1376cb92c03bSAndrew Geissler } 1377cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1378cb92c03bSAndrew Geissler { 1379c419c759SEd Tanous timestamp = std::get_if<uint64_t>( 1380f86bb901SAdriana Kobylak &propertyMap.second); 13817e860f15SJohn Edward Broadbent } 13827e860f15SJohn Edward Broadbent else if (propertyMap.first == 13837e860f15SJohn Edward Broadbent "UpdateTimestamp") 13847e860f15SJohn Edward Broadbent { 1385c419c759SEd Tanous updateTimestamp = std::get_if<uint64_t>( 13867e860f15SJohn Edward Broadbent &propertyMap.second); 13877e860f15SJohn Edward Broadbent } 13887e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 13897e860f15SJohn Edward Broadbent { 13907e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 13917e860f15SJohn Edward Broadbent &propertyMap.second); 13927e860f15SJohn Edward Broadbent } 13937e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 13947e860f15SJohn Edward Broadbent { 13957e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 13967e860f15SJohn Edward Broadbent &propertyMap.second); 13977e860f15SJohn Edward Broadbent } 13987e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 13997e860f15SJohn Edward Broadbent { 1400914e2d5dSEd Tanous const bool* resolveptr = 1401914e2d5dSEd Tanous std::get_if<bool>( 14027e860f15SJohn Edward Broadbent &propertyMap.second); 14037e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 14047e860f15SJohn Edward Broadbent { 14057e860f15SJohn Edward Broadbent messages::internalError( 14067e860f15SJohn Edward Broadbent asyncResp->res); 14077e860f15SJohn Edward Broadbent return; 14087e860f15SJohn Edward Broadbent } 14097e860f15SJohn Edward Broadbent resolved = *resolveptr; 14107e860f15SJohn Edward Broadbent } 14117e860f15SJohn Edward Broadbent } 14127e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14137e860f15SJohn Edward Broadbent severity == nullptr) 14147e860f15SJohn Edward Broadbent { 14157e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 14167e860f15SJohn Edward Broadbent return; 14177e860f15SJohn Edward Broadbent } 14187e860f15SJohn Edward Broadbent } 14197e860f15SJohn Edward Broadbent else if (interfaceMap.first == 14207e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 14217e860f15SJohn Edward Broadbent { 14229eb808c1SEd Tanous for (const auto& propertyMap : 14239eb808c1SEd Tanous interfaceMap.second) 14247e860f15SJohn Edward Broadbent { 14257e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 14267e860f15SJohn Edward Broadbent { 14277e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 14287e860f15SJohn Edward Broadbent &propertyMap.second); 14297e860f15SJohn Edward Broadbent } 14307e860f15SJohn Edward Broadbent } 14317e860f15SJohn Edward Broadbent } 14327e860f15SJohn Edward Broadbent } 14337e860f15SJohn Edward Broadbent // Object path without the 14347e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 14357e860f15SJohn Edward Broadbent // and continue. 14367e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 1437c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1438c419c759SEd Tanous updateTimestamp == nullptr) 14397e860f15SJohn Edward Broadbent { 14407e860f15SJohn Edward Broadbent continue; 14417e860f15SJohn Edward Broadbent } 14427e860f15SJohn Edward Broadbent entriesArray.push_back({}); 14437e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 14447e860f15SJohn Edward Broadbent thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 14457e860f15SJohn Edward Broadbent thisEntry["@odata.id"] = 14460fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 14477e860f15SJohn Edward Broadbent std::to_string(*id); 14487e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 14497e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 14507e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 14517e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 14527e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 14537e860f15SJohn Edward Broadbent thisEntry["Severity"] = 14547e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 14557e860f15SJohn Edward Broadbent thisEntry["Created"] = 1456c419c759SEd Tanous crow::utility::getDateTimeUintMs(*timestamp); 14577e860f15SJohn Edward Broadbent thisEntry["Modified"] = 1458c419c759SEd Tanous crow::utility::getDateTimeUintMs(*updateTimestamp); 14597e860f15SJohn Edward Broadbent if (filePath != nullptr) 14607e860f15SJohn Edward Broadbent { 14617e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 14620fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 14637e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 14647e860f15SJohn Edward Broadbent } 14657e860f15SJohn Edward Broadbent } 14667e860f15SJohn Edward Broadbent std::sort(entriesArray.begin(), entriesArray.end(), 14677e860f15SJohn Edward Broadbent [](const nlohmann::json& left, 14687e860f15SJohn Edward Broadbent const nlohmann::json& right) { 14697e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 14707e860f15SJohn Edward Broadbent }); 14717e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 14727e860f15SJohn Edward Broadbent entriesArray.size(); 14737e860f15SJohn Edward Broadbent }, 14747e860f15SJohn Edward Broadbent "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 14757e860f15SJohn Edward Broadbent "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 14767e860f15SJohn Edward Broadbent }); 14777e860f15SJohn Edward Broadbent } 14787e860f15SJohn Edward Broadbent 14797e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 14807e860f15SJohn Edward Broadbent { 14817e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 14827e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1483ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 148445ca1b86SEd Tanous .methods( 148545ca1b86SEd Tanous boost::beast::http::verb:: 148645ca1b86SEd Tanous get)([&app](const crow::Request& req, 14877e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 148845ca1b86SEd Tanous const std::string& param) { 148945ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 14907e860f15SJohn Edward Broadbent { 149145ca1b86SEd Tanous return; 149245ca1b86SEd Tanous } 14937e860f15SJohn Edward Broadbent std::string entryID = param; 14947e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 14957e860f15SJohn Edward Broadbent 14967e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 14977e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 14987e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 1499b9d36b47SEd Tanous [asyncResp, 1500b9d36b47SEd Tanous entryID](const boost::system::error_code ec, 1501b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 15027e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 15037e860f15SJohn Edward Broadbent { 150445ca1b86SEd Tanous messages::resourceNotFound(asyncResp->res, 150545ca1b86SEd Tanous "EventLogEntry", entryID); 15067e860f15SJohn Edward Broadbent return; 15077e860f15SJohn Edward Broadbent } 15087e860f15SJohn Edward Broadbent if (ec) 15097e860f15SJohn Edward Broadbent { 15100fda0f12SGeorge Liu BMCWEB_LOG_ERROR 15110fda0f12SGeorge Liu << "EventLogEntry (DBus) resp_handler got error " 15127e860f15SJohn Edward Broadbent << ec; 15137e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 15147e860f15SJohn Edward Broadbent return; 15157e860f15SJohn Edward Broadbent } 1516914e2d5dSEd Tanous const uint32_t* id = nullptr; 1517c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1518c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1519914e2d5dSEd Tanous const std::string* severity = nullptr; 1520914e2d5dSEd Tanous const std::string* message = nullptr; 1521914e2d5dSEd Tanous const std::string* filePath = nullptr; 15227e860f15SJohn Edward Broadbent bool resolved = false; 15237e860f15SJohn Edward Broadbent 15249eb808c1SEd Tanous for (const auto& propertyMap : resp) 15257e860f15SJohn Edward Broadbent { 15267e860f15SJohn Edward Broadbent if (propertyMap.first == "Id") 15277e860f15SJohn Edward Broadbent { 15287e860f15SJohn Edward Broadbent id = std::get_if<uint32_t>(&propertyMap.second); 15297e860f15SJohn Edward Broadbent } 15307e860f15SJohn Edward Broadbent else if (propertyMap.first == "Timestamp") 15317e860f15SJohn Edward Broadbent { 1532c419c759SEd Tanous timestamp = 15337e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 1534ebd45906SGeorge Liu } 1535d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1536d139c236SGeorge Liu { 1537ebd45906SGeorge Liu updateTimestamp = 1538c419c759SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 1539ebd45906SGeorge Liu } 1540cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1541cb92c03bSAndrew Geissler { 154245ca1b86SEd Tanous severity = 154345ca1b86SEd Tanous std::get_if<std::string>(&propertyMap.second); 1544cb92c03bSAndrew Geissler } 1545cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1546cb92c03bSAndrew Geissler { 154745ca1b86SEd Tanous message = 154845ca1b86SEd Tanous std::get_if<std::string>(&propertyMap.second); 1549ae34c8e8SAdriana Kobylak } 155075710de2SXiaochao Ma else if (propertyMap.first == "Resolved") 155175710de2SXiaochao Ma { 1552914e2d5dSEd Tanous const bool* resolveptr = 155375710de2SXiaochao Ma std::get_if<bool>(&propertyMap.second); 155475710de2SXiaochao Ma if (resolveptr == nullptr) 155575710de2SXiaochao Ma { 155675710de2SXiaochao Ma messages::internalError(asyncResp->res); 155775710de2SXiaochao Ma return; 155875710de2SXiaochao Ma } 155975710de2SXiaochao Ma resolved = *resolveptr; 156075710de2SXiaochao Ma } 15617e860f15SJohn Edward Broadbent else if (propertyMap.first == "Path") 1562f86bb901SAdriana Kobylak { 156345ca1b86SEd Tanous filePath = 156445ca1b86SEd Tanous std::get_if<std::string>(&propertyMap.second); 1565f86bb901SAdriana Kobylak } 1566f86bb901SAdriana Kobylak } 1567f86bb901SAdriana Kobylak if (id == nullptr || message == nullptr || 1568c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1569c419c759SEd Tanous updateTimestamp == nullptr) 1570f86bb901SAdriana Kobylak { 1571ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1572271584abSEd Tanous return; 1573271584abSEd Tanous } 1574f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 1575f86bb901SAdriana Kobylak "#LogEntry.v1_8_0.LogEntry"; 1576f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.id"] = 15770fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 1578f86bb901SAdriana Kobylak std::to_string(*id); 157945ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Event Log Entry"; 1580f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1581f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1582f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 1583f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1584f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1585f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1586f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 1587c419c759SEd Tanous crow::utility::getDateTimeUintMs(*timestamp); 1588f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 1589c419c759SEd Tanous crow::utility::getDateTimeUintMs(*updateTimestamp); 1590f86bb901SAdriana Kobylak if (filePath != nullptr) 1591f86bb901SAdriana Kobylak { 1592f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 15930fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/attachment/" + 15947e860f15SJohn Edward Broadbent std::to_string(*id); 1595f86bb901SAdriana Kobylak } 1596cb92c03bSAndrew Geissler }, 1597cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1598cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1599f86bb901SAdriana Kobylak "org.freedesktop.DBus.Properties", "GetAll", ""); 16007e860f15SJohn Edward Broadbent }); 1601336e96c6SChicago Duan 16027e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16037e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1604ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 16057e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 160645ca1b86SEd Tanous [&app](const crow::Request& req, 16077e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16087e860f15SJohn Edward Broadbent const std::string& entryId) { 160945ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 161045ca1b86SEd Tanous { 161145ca1b86SEd Tanous return; 161245ca1b86SEd Tanous } 161375710de2SXiaochao Ma std::optional<bool> resolved; 161475710de2SXiaochao Ma 161515ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", 16167e860f15SJohn Edward Broadbent resolved)) 161775710de2SXiaochao Ma { 161875710de2SXiaochao Ma return; 161975710de2SXiaochao Ma } 162075710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 162175710de2SXiaochao Ma 162275710de2SXiaochao Ma crow::connections::systemBus->async_method_call( 16234f48d5f6SEd Tanous [asyncResp, entryId](const boost::system::error_code ec) { 162475710de2SXiaochao Ma if (ec) 162575710de2SXiaochao Ma { 162675710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 162775710de2SXiaochao Ma messages::internalError(asyncResp->res); 162875710de2SXiaochao Ma return; 162975710de2SXiaochao Ma } 163075710de2SXiaochao Ma }, 163175710de2SXiaochao Ma "xyz.openbmc_project.Logging", 163275710de2SXiaochao Ma "/xyz/openbmc_project/logging/entry/" + entryId, 163375710de2SXiaochao Ma "org.freedesktop.DBus.Properties", "Set", 163475710de2SXiaochao Ma "xyz.openbmc_project.Logging.Entry", "Resolved", 1635168e20c1SEd Tanous dbus::utility::DbusVariantType(*resolved)); 16367e860f15SJohn Edward Broadbent }); 163775710de2SXiaochao Ma 16387e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16397e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1640ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1641ed398213SEd Tanous 164245ca1b86SEd Tanous .methods(boost::beast::http::verb:: 164345ca1b86SEd Tanous delete_)([&app](const crow::Request& req, 164445ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& 164545ca1b86SEd Tanous asyncResp, 164645ca1b86SEd Tanous const std::string& param) { 164745ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 1648336e96c6SChicago Duan { 164945ca1b86SEd Tanous return; 165045ca1b86SEd Tanous } 1651336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1652336e96c6SChicago Duan 16537e860f15SJohn Edward Broadbent std::string entryID = param; 1654336e96c6SChicago Duan 1655336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1656336e96c6SChicago Duan 1657336e96c6SChicago Duan // Process response from Logging service. 165845ca1b86SEd Tanous auto respHandler = [asyncResp, 165945ca1b86SEd Tanous entryID](const boost::system::error_code ec) { 16607e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 16617e860f15SJohn Edward Broadbent << "EventLogEntry (DBus) doDelete callback: Done"; 1662336e96c6SChicago Duan if (ec) 1663336e96c6SChicago Duan { 16643de8d8baSGeorge Liu if (ec.value() == EBADR) 16653de8d8baSGeorge Liu { 166645ca1b86SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 166745ca1b86SEd Tanous entryID); 16683de8d8baSGeorge Liu return; 16693de8d8baSGeorge Liu } 1670336e96c6SChicago Duan // TODO Handle for specific error code 16710fda0f12SGeorge Liu BMCWEB_LOG_ERROR 16720fda0f12SGeorge Liu << "EventLogEntry (DBus) doDelete respHandler got error " 1673336e96c6SChicago Duan << ec; 1674336e96c6SChicago Duan asyncResp->res.result( 1675336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1676336e96c6SChicago Duan return; 1677336e96c6SChicago Duan } 1678336e96c6SChicago Duan 1679336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1680336e96c6SChicago Duan }; 1681336e96c6SChicago Duan 1682336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1683336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1684336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1685336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1686336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 16877e860f15SJohn Edward Broadbent }); 1688400fd1fbSAdriana Kobylak } 1689400fd1fbSAdriana Kobylak 16907e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1691400fd1fbSAdriana Kobylak { 16920fda0f12SGeorge Liu BMCWEB_ROUTE( 16930fda0f12SGeorge Liu app, 16940fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/attachment") 1695ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 16967e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 169745ca1b86SEd Tanous [&app](const crow::Request& req, 16987e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 169945ca1b86SEd Tanous const std::string& param) { 170045ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 17017e860f15SJohn Edward Broadbent { 170245ca1b86SEd Tanous return; 170345ca1b86SEd Tanous } 1704647b3cdcSGeorge Liu if (!http_helpers::isOctetAccepted( 1705647b3cdcSGeorge Liu req.getHeaderValue("Accept"))) 1706400fd1fbSAdriana Kobylak { 17077e860f15SJohn Edward Broadbent asyncResp->res.result( 17087e860f15SJohn Edward Broadbent boost::beast::http::status::bad_request); 1709400fd1fbSAdriana Kobylak return; 1710400fd1fbSAdriana Kobylak } 1711400fd1fbSAdriana Kobylak 17127e860f15SJohn Edward Broadbent std::string entryID = param; 1713400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1714400fd1fbSAdriana Kobylak 1715400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 17167e860f15SJohn Edward Broadbent [asyncResp, 17177e860f15SJohn Edward Broadbent entryID](const boost::system::error_code ec, 1718400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 1719400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 1720400fd1fbSAdriana Kobylak { 17217e860f15SJohn Edward Broadbent messages::resourceNotFound( 17227e860f15SJohn Edward Broadbent asyncResp->res, "EventLogAttachment", entryID); 1723400fd1fbSAdriana Kobylak return; 1724400fd1fbSAdriana Kobylak } 1725400fd1fbSAdriana Kobylak if (ec) 1726400fd1fbSAdriana Kobylak { 1727400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1728400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1729400fd1fbSAdriana Kobylak return; 1730400fd1fbSAdriana Kobylak } 1731400fd1fbSAdriana Kobylak 1732400fd1fbSAdriana Kobylak int fd = -1; 1733400fd1fbSAdriana Kobylak fd = dup(unixfd); 1734400fd1fbSAdriana Kobylak if (fd == -1) 1735400fd1fbSAdriana Kobylak { 1736400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1737400fd1fbSAdriana Kobylak return; 1738400fd1fbSAdriana Kobylak } 1739400fd1fbSAdriana Kobylak 1740400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 1741400fd1fbSAdriana Kobylak if (size == -1) 1742400fd1fbSAdriana Kobylak { 1743400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1744400fd1fbSAdriana Kobylak return; 1745400fd1fbSAdriana Kobylak } 1746400fd1fbSAdriana Kobylak 1747400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 1748400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 1749400fd1fbSAdriana Kobylak if (size > maxFileSize) 1750400fd1fbSAdriana Kobylak { 1751400fd1fbSAdriana Kobylak BMCWEB_LOG_ERROR 1752400fd1fbSAdriana Kobylak << "File size exceeds maximum allowed size of " 1753400fd1fbSAdriana Kobylak << maxFileSize; 1754400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1755400fd1fbSAdriana Kobylak return; 1756400fd1fbSAdriana Kobylak } 1757400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 1758400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 1759400fd1fbSAdriana Kobylak if (rc == -1) 1760400fd1fbSAdriana Kobylak { 1761400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1762400fd1fbSAdriana Kobylak return; 1763400fd1fbSAdriana Kobylak } 1764400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 1765400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 1766400fd1fbSAdriana Kobylak { 1767400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1768400fd1fbSAdriana Kobylak return; 1769400fd1fbSAdriana Kobylak } 1770400fd1fbSAdriana Kobylak close(fd); 1771400fd1fbSAdriana Kobylak 1772400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 17737e860f15SJohn Edward Broadbent std::string output = 17747e860f15SJohn Edward Broadbent crow::utility::base64encode(strData); 1775400fd1fbSAdriana Kobylak 1776400fd1fbSAdriana Kobylak asyncResp->res.addHeader("Content-Type", 1777400fd1fbSAdriana Kobylak "application/octet-stream"); 17787e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Transfer-Encoding", 17797e860f15SJohn Edward Broadbent "Base64"); 1780400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 1781400fd1fbSAdriana Kobylak }, 1782400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 1783400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 1784400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 17857e860f15SJohn Edward Broadbent }); 17861da66f75SEd Tanous } 17871da66f75SEd Tanous 1788b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 1789b7028ebfSSpencer Ku 1790b7028ebfSSpencer Ku inline bool 1791b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 1792b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 1793b7028ebfSSpencer Ku { 1794b7028ebfSSpencer Ku std::error_code ec; 1795b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 1796b7028ebfSSpencer Ku if (ec) 1797b7028ebfSSpencer Ku { 1798b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << ec.message(); 1799b7028ebfSSpencer Ku return false; 1800b7028ebfSSpencer Ku } 1801b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 1802b7028ebfSSpencer Ku { 1803b7028ebfSSpencer Ku std::string filename = it.path().filename(); 1804b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 1805b7028ebfSSpencer Ku // path 1806b7028ebfSSpencer Ku if (boost::starts_with(filename, "log")) 1807b7028ebfSSpencer Ku { 1808b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 1809b7028ebfSSpencer Ku } 1810b7028ebfSSpencer Ku } 1811b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 1812b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 1813b7028ebfSSpencer Ku // descending order. 1814b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 1815b7028ebfSSpencer Ku AlphanumLess<std::string>()); 1816b7028ebfSSpencer Ku 1817b7028ebfSSpencer Ku return true; 1818b7028ebfSSpencer Ku } 1819b7028ebfSSpencer Ku 1820b7028ebfSSpencer Ku inline bool 1821b7028ebfSSpencer Ku getHostLoggerEntries(std::vector<std::filesystem::path>& hostLoggerFiles, 1822c937d2bfSEd Tanous uint64_t skip, uint64_t top, 1823b7028ebfSSpencer Ku std::vector<std::string>& logEntries, size_t& logCount) 1824b7028ebfSSpencer Ku { 1825b7028ebfSSpencer Ku GzFileReader logFile; 1826b7028ebfSSpencer Ku 1827b7028ebfSSpencer Ku // Go though all log files and expose host logs. 1828b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 1829b7028ebfSSpencer Ku { 1830b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 1831b7028ebfSSpencer Ku { 1832b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to expose host logs"; 1833b7028ebfSSpencer Ku return false; 1834b7028ebfSSpencer Ku } 1835b7028ebfSSpencer Ku } 1836b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 1837b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 1838b7028ebfSSpencer Ku if (!lastMessage.empty()) 1839b7028ebfSSpencer Ku { 1840b7028ebfSSpencer Ku logCount++; 1841b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 1842b7028ebfSSpencer Ku { 1843b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 1844b7028ebfSSpencer Ku } 1845b7028ebfSSpencer Ku } 1846b7028ebfSSpencer Ku return true; 1847b7028ebfSSpencer Ku } 1848b7028ebfSSpencer Ku 1849b7028ebfSSpencer Ku inline void fillHostLoggerEntryJson(const std::string& logEntryID, 1850b7028ebfSSpencer Ku const std::string& msg, 1851b7028ebfSSpencer Ku nlohmann::json& logEntryJson) 1852b7028ebfSSpencer Ku { 1853b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 1854b7028ebfSSpencer Ku logEntryJson = { 1855b7028ebfSSpencer Ku {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1856b7028ebfSSpencer Ku {"@odata.id", 1857b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/" + 1858b7028ebfSSpencer Ku logEntryID}, 1859b7028ebfSSpencer Ku {"Name", "Host Logger Entry"}, 1860b7028ebfSSpencer Ku {"Id", logEntryID}, 1861b7028ebfSSpencer Ku {"Message", msg}, 1862b7028ebfSSpencer Ku {"EntryType", "Oem"}, 1863b7028ebfSSpencer Ku {"Severity", "OK"}, 1864b7028ebfSSpencer Ku {"OemRecordFormat", "Host Logger Entry"}}; 1865b7028ebfSSpencer Ku } 1866b7028ebfSSpencer Ku 1867b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 1868b7028ebfSSpencer Ku { 1869b7028ebfSSpencer Ku BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/HostLogger/") 1870b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 1871*1476687dSEd Tanous .methods(boost::beast::http::verb::get)( 1872*1476687dSEd Tanous [&app](const crow::Request& req, 1873*1476687dSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 187445ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 187545ca1b86SEd Tanous { 187645ca1b86SEd Tanous return; 187745ca1b86SEd Tanous } 1878b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1879b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"; 1880b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1881b7028ebfSSpencer Ku "#LogService.v1_1_0.LogService"; 1882b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 1883b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 1884b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 1885*1476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 1886*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 1887b7028ebfSSpencer Ku }); 1888b7028ebfSSpencer Ku } 1889b7028ebfSSpencer Ku 1890b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 1891b7028ebfSSpencer Ku { 1892b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 1893b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/") 1894b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 189545ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 189645ca1b86SEd Tanous const std::shared_ptr< 189745ca1b86SEd Tanous bmcweb::AsyncResp>& 189845ca1b86SEd Tanous asyncResp) { 1899c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1900c937d2bfSEd Tanous .canDelegateTop = true, 1901c937d2bfSEd Tanous .canDelegateSkip = true, 1902c937d2bfSEd Tanous }; 1903c937d2bfSEd Tanous query_param::Query delegatedQuery; 1904c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 1905c937d2bfSEd Tanous app, req, asyncResp->res, delegatedQuery, capabilities)) 1906b7028ebfSSpencer Ku { 1907b7028ebfSSpencer Ku return; 1908b7028ebfSSpencer Ku } 1909b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1910b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 1911b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1912b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 1913b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 1914b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 1915b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 19160fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1917b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 1918b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 1919b7028ebfSSpencer Ku 1920b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 1921b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 1922b7028ebfSSpencer Ku { 1923b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 1924b7028ebfSSpencer Ku return; 1925b7028ebfSSpencer Ku } 1926b7028ebfSSpencer Ku 1927b7028ebfSSpencer Ku size_t logCount = 0; 1928b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 1929b7028ebfSSpencer Ku // control by skip and top. 1930b7028ebfSSpencer Ku std::vector<std::string> logEntries; 1931c937d2bfSEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, delegatedQuery.skip, 1932c937d2bfSEd Tanous delegatedQuery.top, logEntries, logCount)) 1933b7028ebfSSpencer Ku { 1934b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 1935b7028ebfSSpencer Ku return; 1936b7028ebfSSpencer Ku } 1937b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 1938b7028ebfSSpencer Ku // log count 193926f6976fSEd Tanous if (logEntries.empty()) 1940b7028ebfSSpencer Ku { 1941b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 1942b7028ebfSSpencer Ku return; 1943b7028ebfSSpencer Ku } 194426f6976fSEd Tanous if (!logEntries.empty()) 1945b7028ebfSSpencer Ku { 1946b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 1947b7028ebfSSpencer Ku { 1948b7028ebfSSpencer Ku logEntryArray.push_back({}); 1949b7028ebfSSpencer Ku nlohmann::json& hostLogEntry = logEntryArray.back(); 1950c937d2bfSEd Tanous fillHostLoggerEntryJson( 1951c937d2bfSEd Tanous std::to_string(delegatedQuery.skip + i), logEntries[i], 1952c937d2bfSEd Tanous hostLogEntry); 1953b7028ebfSSpencer Ku } 1954b7028ebfSSpencer Ku 1955b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 1956c937d2bfSEd Tanous if (delegatedQuery.skip + delegatedQuery.top < logCount) 1957b7028ebfSSpencer Ku { 1958b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 19590fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/HostLogger/Entries?$skip=" + 1960c937d2bfSEd Tanous std::to_string(delegatedQuery.skip + 1961c937d2bfSEd Tanous delegatedQuery.top); 1962b7028ebfSSpencer Ku } 1963b7028ebfSSpencer Ku } 1964b7028ebfSSpencer Ku }); 1965b7028ebfSSpencer Ku } 1966b7028ebfSSpencer Ku 1967b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 1968b7028ebfSSpencer Ku { 1969b7028ebfSSpencer Ku BMCWEB_ROUTE( 1970b7028ebfSSpencer Ku app, "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/<str>/") 1971b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 1972b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 197345ca1b86SEd Tanous [&app](const crow::Request& req, 1974b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1975b7028ebfSSpencer Ku const std::string& param) { 197645ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 197745ca1b86SEd Tanous { 197845ca1b86SEd Tanous return; 197945ca1b86SEd Tanous } 1980b7028ebfSSpencer Ku const std::string& targetID = param; 1981b7028ebfSSpencer Ku 1982b7028ebfSSpencer Ku uint64_t idInt = 0; 1983ca45aa3cSEd Tanous 1984ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 1985ca45aa3cSEd Tanous const char* end = targetID.data() + targetID.size(); 1986ca45aa3cSEd Tanous 1987ca45aa3cSEd Tanous auto [ptr, ec] = std::from_chars(targetID.data(), end, idInt); 1988b7028ebfSSpencer Ku if (ec == std::errc::invalid_argument) 1989b7028ebfSSpencer Ku { 1990ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 1991b7028ebfSSpencer Ku return; 1992b7028ebfSSpencer Ku } 1993b7028ebfSSpencer Ku if (ec == std::errc::result_out_of_range) 1994b7028ebfSSpencer Ku { 1995ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 1996b7028ebfSSpencer Ku return; 1997b7028ebfSSpencer Ku } 1998b7028ebfSSpencer Ku 1999b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2000b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2001b7028ebfSSpencer Ku { 2002b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 2003b7028ebfSSpencer Ku return; 2004b7028ebfSSpencer Ku } 2005b7028ebfSSpencer Ku 2006b7028ebfSSpencer Ku size_t logCount = 0; 2007b7028ebfSSpencer Ku uint64_t top = 1; 2008b7028ebfSSpencer Ku std::vector<std::string> logEntries; 2009b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 2010b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 2011b7028ebfSSpencer Ku // get that entry 2012b7028ebfSSpencer Ku if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, 2013b7028ebfSSpencer Ku logEntries, logCount)) 2014b7028ebfSSpencer Ku { 2015b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2016b7028ebfSSpencer Ku return; 2017b7028ebfSSpencer Ku } 2018b7028ebfSSpencer Ku 2019b7028ebfSSpencer Ku if (!logEntries.empty()) 2020b7028ebfSSpencer Ku { 2021b7028ebfSSpencer Ku fillHostLoggerEntryJson(targetID, logEntries[0], 2022b7028ebfSSpencer Ku asyncResp->res.jsonValue); 2023b7028ebfSSpencer Ku return; 2024b7028ebfSSpencer Ku } 2025b7028ebfSSpencer Ku 2026b7028ebfSSpencer Ku // Requested ID was not found 2027ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2028b7028ebfSSpencer Ku }); 2029b7028ebfSSpencer Ku } 2030b7028ebfSSpencer Ku 20317e860f15SJohn Edward Broadbent inline void requestRoutesBMCLogServiceCollection(App& app) 20321da66f75SEd Tanous { 20337e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 2034ad89dcf0SGunnar Mills .privileges(redfish::privileges::getLogServiceCollection) 20357e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 203645ca1b86SEd Tanous [&app](const crow::Request& req, 20377e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 203845ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 203945ca1b86SEd Tanous { 204045ca1b86SEd Tanous return; 204145ca1b86SEd Tanous } 20427e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 20437e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2044e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 20451da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2046e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 2047e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 20487e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 20497e860f15SJohn Edward Broadbent "Open BMC Log Services Collection"; 2050e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 20511da66f75SEd Tanous "Collection of LogServices for this Manager"; 20527e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 20537e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 2054c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 20555cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 20565cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 20577e860f15SJohn Edward Broadbent {{"@odata.id", 20587e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 20595cb1dd27SAsmitha Karunanithi #endif 2060c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 2061c4bf6374SJason M. Bills logServiceArray.push_back( 20627e860f15SJohn Edward Broadbent {{"@odata.id", 20637e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 2064c4bf6374SJason M. Bills #endif 2065e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2066c4bf6374SJason M. Bills logServiceArray.size(); 20677e860f15SJohn Edward Broadbent }); 2068e1f26343SJason M. Bills } 2069e1f26343SJason M. Bills 20707e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 2071e1f26343SJason M. Bills { 20727e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 2073ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 20747e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 207545ca1b86SEd Tanous [&app](const crow::Request& req, 207645ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 207745ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 20787e860f15SJohn Edward Broadbent { 207945ca1b86SEd Tanous return; 208045ca1b86SEd Tanous } 2081e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2082e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 20830f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 20840f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 20857e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 20867e860f15SJohn Edward Broadbent "Open BMC Journal Log Service"; 20877e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 20887e860f15SJohn Edward Broadbent "BMC Journal Log Service"; 2089c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 2090e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 20917c8c4058STejas Patil 20927c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 20937c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 20947c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 20957c8c4058STejas Patil redfishDateTimeOffset.first; 20967c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 20977c8c4058STejas Patil redfishDateTimeOffset.second; 20987c8c4058STejas Patil 2099*1476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 2100*1476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 21017e860f15SJohn Edward Broadbent }); 2102e1f26343SJason M. Bills } 2103e1f26343SJason M. Bills 2104c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 2105e1f26343SJason M. Bills sd_journal* journal, 2106c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 2107e1f26343SJason M. Bills { 2108e1f26343SJason M. Bills // Get the Log Entry contents 2109e1f26343SJason M. Bills int ret = 0; 2110e1f26343SJason M. Bills 2111a8fe54f0SJason M. Bills std::string message; 2112a8fe54f0SJason M. Bills std::string_view syslogID; 2113a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 2114a8fe54f0SJason M. Bills if (ret < 0) 2115a8fe54f0SJason M. Bills { 2116a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 2117a8fe54f0SJason M. Bills << strerror(-ret); 2118a8fe54f0SJason M. Bills } 2119a8fe54f0SJason M. Bills if (!syslogID.empty()) 2120a8fe54f0SJason M. Bills { 2121a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 2122a8fe54f0SJason M. Bills } 2123a8fe54f0SJason M. Bills 212439e77504SEd Tanous std::string_view msg; 212516428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 2126e1f26343SJason M. Bills if (ret < 0) 2127e1f26343SJason M. Bills { 2128e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 2129e1f26343SJason M. Bills return 1; 2130e1f26343SJason M. Bills } 2131a8fe54f0SJason M. Bills message += std::string(msg); 2132e1f26343SJason M. Bills 2133e1f26343SJason M. Bills // Get the severity from the PRIORITY field 2134271584abSEd Tanous long int severity = 8; // Default to an invalid priority 213516428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 2136e1f26343SJason M. Bills if (ret < 0) 2137e1f26343SJason M. Bills { 2138e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 2139e1f26343SJason M. Bills } 2140e1f26343SJason M. Bills 2141e1f26343SJason M. Bills // Get the Created time from the timestamp 214216428a1aSJason M. Bills std::string entryTimeStr; 214316428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 2144e1f26343SJason M. Bills { 214516428a1aSJason M. Bills return 1; 2146e1f26343SJason M. Bills } 2147e1f26343SJason M. Bills 2148e1f26343SJason M. Bills // Fill in the log entry with the gathered data 2149c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 2150647b3cdcSGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 2151c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 2152c4bf6374SJason M. Bills bmcJournalLogEntryID}, 2153e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 2154c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 2155a8fe54f0SJason M. Bills {"Message", std::move(message)}, 2156e1f26343SJason M. Bills {"EntryType", "Oem"}, 2157738c1e61SPatrick Williams {"Severity", severity <= 2 ? "Critical" 2158738c1e61SPatrick Williams : severity <= 4 ? "Warning" 2159738c1e61SPatrick Williams : "OK"}, 2160086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 2161e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 2162e1f26343SJason M. Bills return 0; 2163e1f26343SJason M. Bills } 2164e1f26343SJason M. Bills 21657e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 2166e1f26343SJason M. Bills { 21677e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 2168ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 216945ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 217045ca1b86SEd Tanous const std::shared_ptr< 217145ca1b86SEd Tanous bmcweb::AsyncResp>& 217245ca1b86SEd Tanous asyncResp) { 2173c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2174c937d2bfSEd Tanous .canDelegateTop = true, 2175c937d2bfSEd Tanous .canDelegateSkip = true, 2176c937d2bfSEd Tanous }; 2177c937d2bfSEd Tanous query_param::Query delegatedQuery; 2178c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 2179c937d2bfSEd Tanous app, req, asyncResp->res, delegatedQuery, capabilities)) 2180193ad2faSJason M. Bills { 2181193ad2faSJason M. Bills return; 2182193ad2faSJason M. Bills } 21837e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 21847e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2185e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2186e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 21870f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 21880f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 2189e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 2190e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2191e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 21920fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2193e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2194e1f26343SJason M. Bills 21957e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 21967e860f15SJohn Edward Broadbent // unique ID for each entry 2197e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2198e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2199e1f26343SJason M. Bills if (ret < 0) 2200e1f26343SJason M. Bills { 22017e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 22027e860f15SJohn Edward Broadbent << strerror(-ret); 2203f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2204e1f26343SJason M. Bills return; 2205e1f26343SJason M. Bills } 22060fda0f12SGeorge Liu std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 22070fda0f12SGeorge Liu journalTmp, sd_journal_close); 2208e1f26343SJason M. Bills journalTmp = nullptr; 2209b01bf299SEd Tanous uint64_t entryCount = 0; 2210e85d6b16SJason M. Bills // Reset the unique ID on the first entry 2211e85d6b16SJason M. Bills bool firstEntry = true; 2212e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 2213e1f26343SJason M. Bills { 2214193ad2faSJason M. Bills entryCount++; 22157e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 22167e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 2217c937d2bfSEd Tanous if (entryCount <= delegatedQuery.skip || 2218c937d2bfSEd Tanous entryCount > delegatedQuery.skip + delegatedQuery.top) 2219193ad2faSJason M. Bills { 2220193ad2faSJason M. Bills continue; 2221193ad2faSJason M. Bills } 2222193ad2faSJason M. Bills 222316428a1aSJason M. Bills std::string idStr; 2224e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2225e1f26343SJason M. Bills { 2226e1f26343SJason M. Bills continue; 2227e1f26343SJason M. Bills } 2228e1f26343SJason M. Bills 2229e85d6b16SJason M. Bills if (firstEntry) 2230e85d6b16SJason M. Bills { 2231e85d6b16SJason M. Bills firstEntry = false; 2232e85d6b16SJason M. Bills } 2233e85d6b16SJason M. Bills 2234e1f26343SJason M. Bills logEntryArray.push_back({}); 2235c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 2236c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 2237c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 2238e1f26343SJason M. Bills { 2239f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2240e1f26343SJason M. Bills return; 2241e1f26343SJason M. Bills } 2242e1f26343SJason M. Bills } 2243193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 2244c937d2bfSEd Tanous if (delegatedQuery.skip + delegatedQuery.top < entryCount) 2245193ad2faSJason M. Bills { 2246193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 22470fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 2248c937d2bfSEd Tanous std::to_string(delegatedQuery.skip + delegatedQuery.top); 2249193ad2faSJason M. Bills } 22507e860f15SJohn Edward Broadbent }); 2251e1f26343SJason M. Bills } 2252e1f26343SJason M. Bills 22537e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 2254e1f26343SJason M. Bills { 22557e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 22567e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 2257ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 22587e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 225945ca1b86SEd Tanous [&app](const crow::Request& req, 22607e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22617e860f15SJohn Edward Broadbent const std::string& entryID) { 226245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 226345ca1b86SEd Tanous { 226445ca1b86SEd Tanous return; 226545ca1b86SEd Tanous } 2266e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2267e1f26343SJason M. Bills uint64_t ts = 0; 2268271584abSEd Tanous uint64_t index = 0; 22698d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2270e1f26343SJason M. Bills { 227116428a1aSJason M. Bills return; 2272e1f26343SJason M. Bills } 2273e1f26343SJason M. Bills 2274e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2275e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2276e1f26343SJason M. Bills if (ret < 0) 2277e1f26343SJason M. Bills { 22787e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 22797e860f15SJohn Edward Broadbent << strerror(-ret); 2280f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2281e1f26343SJason M. Bills return; 2282e1f26343SJason M. Bills } 22837e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 22847e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 2285e1f26343SJason M. Bills journalTmp = nullptr; 22867e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 22877e860f15SJohn Edward Broadbent // index tracking the unique ID 2288af07e3f5SJason M. Bills std::string idStr; 2289af07e3f5SJason M. Bills bool firstEntry = true; 2290e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 22912056b6d1SManojkiran Eda if (ret < 0) 22922056b6d1SManojkiran Eda { 22932056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 22942056b6d1SManojkiran Eda << strerror(-ret); 22952056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 22962056b6d1SManojkiran Eda return; 22972056b6d1SManojkiran Eda } 2298271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2299e1f26343SJason M. Bills { 2300e1f26343SJason M. Bills sd_journal_next(journal.get()); 2301af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2302af07e3f5SJason M. Bills { 2303af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2304af07e3f5SJason M. Bills return; 2305af07e3f5SJason M. Bills } 2306af07e3f5SJason M. Bills if (firstEntry) 2307af07e3f5SJason M. Bills { 2308af07e3f5SJason M. Bills firstEntry = false; 2309af07e3f5SJason M. Bills } 2310e1f26343SJason M. Bills } 2311c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2312af07e3f5SJason M. Bills if (idStr != entryID) 2313c4bf6374SJason M. Bills { 2314ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2315c4bf6374SJason M. Bills return; 2316c4bf6374SJason M. Bills } 2317c4bf6374SJason M. Bills 2318c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 2319e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 2320e1f26343SJason M. Bills { 2321f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2322e1f26343SJason M. Bills return; 2323e1f26343SJason M. Bills } 23247e860f15SJohn Edward Broadbent }); 2325c9bb6861Sraviteja-b } 2326c9bb6861Sraviteja-b 23277e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpService(App& app) 2328c9bb6861Sraviteja-b { 23297e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2330ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 233145ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 233245ca1b86SEd Tanous const std::shared_ptr< 233345ca1b86SEd Tanous bmcweb::AsyncResp>& 233445ca1b86SEd Tanous asyncResp) { 233545ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 233645ca1b86SEd Tanous { 233745ca1b86SEd Tanous return; 233845ca1b86SEd Tanous } 2339c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 23405cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 2341c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2342d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 2343c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 23445cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 23455cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2346c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 23477c8c4058STejas Patil 23487c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 23497c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 23500fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 23517c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 23527c8c4058STejas Patil redfishDateTimeOffset.second; 23537c8c4058STejas Patil 2354*1476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 2355*1476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 2356*1476687dSEd Tanous asyncResp->res 2357*1476687dSEd Tanous .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 2358*1476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog"; 2359*1476687dSEd Tanous asyncResp->res 2360*1476687dSEd Tanous .jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 2361*1476687dSEd Tanous ["target"] = 2362*1476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData"; 23637e860f15SJohn Edward Broadbent }); 2364c9bb6861Sraviteja-b } 2365c9bb6861Sraviteja-b 23667e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntryCollection(App& app) 23677e860f15SJohn Edward Broadbent { 23687e860f15SJohn Edward Broadbent 2369c9bb6861Sraviteja-b /** 2370c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2371c9bb6861Sraviteja-b */ 23727e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2373ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 23747e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 237545ca1b86SEd Tanous [&app](const crow::Request& req, 23767e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 237745ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 237845ca1b86SEd Tanous { 237945ca1b86SEd Tanous return; 238045ca1b86SEd Tanous } 2381c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2382c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2383c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 23845cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 23855cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2386c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 23875cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2388c9bb6861Sraviteja-b 23895cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 23907e860f15SJohn Edward Broadbent }); 2391c9bb6861Sraviteja-b } 2392c9bb6861Sraviteja-b 23937e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2394c9bb6861Sraviteja-b { 23957e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 23967e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2397ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 23987e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 239945ca1b86SEd Tanous [&app](const crow::Request& req, 24007e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24017e860f15SJohn Edward Broadbent const std::string& param) { 240245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 240345ca1b86SEd Tanous { 240445ca1b86SEd Tanous return; 240545ca1b86SEd Tanous } 240645ca1b86SEd Tanous 240745ca1b86SEd Tanous getDumpEntryById(app, req, asyncResp, param, "BMC"); 24087e860f15SJohn Edward Broadbent }); 24097e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24107e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2411ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 24127e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 241345ca1b86SEd Tanous [&app](const crow::Request& req, 24147e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24157e860f15SJohn Edward Broadbent const std::string& param) { 241645ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 241745ca1b86SEd Tanous { 241845ca1b86SEd Tanous return; 241945ca1b86SEd Tanous } 24207e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "bmc"); 24217e860f15SJohn Edward Broadbent }); 2422c9bb6861Sraviteja-b } 2423c9bb6861Sraviteja-b 24247e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2425c9bb6861Sraviteja-b { 24260fda0f12SGeorge Liu BMCWEB_ROUTE( 24270fda0f12SGeorge Liu app, 24280fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2429ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 24307e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 243145ca1b86SEd Tanous [&app](const crow::Request& req, 24327e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 243345ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 243445ca1b86SEd Tanous { 243545ca1b86SEd Tanous return; 243645ca1b86SEd Tanous } 24378d1b46d7Szhanghch05 createDump(asyncResp, req, "BMC"); 24387e860f15SJohn Edward Broadbent }); 2439a43be80fSAsmitha Karunanithi } 2440a43be80fSAsmitha Karunanithi 24417e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 244280319af1SAsmitha Karunanithi { 24430fda0f12SGeorge Liu BMCWEB_ROUTE( 24440fda0f12SGeorge Liu app, 24450fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog/") 2446ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 24477e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 244845ca1b86SEd Tanous [&app](const crow::Request& req, 24497e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 245045ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 245145ca1b86SEd Tanous { 245245ca1b86SEd Tanous return; 245345ca1b86SEd Tanous } 24548d1b46d7Szhanghch05 clearDump(asyncResp, "BMC"); 24557e860f15SJohn Edward Broadbent }); 24565cb1dd27SAsmitha Karunanithi } 24575cb1dd27SAsmitha Karunanithi 24587e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 24595cb1dd27SAsmitha Karunanithi { 24607e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/") 2461ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 246245ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 246345ca1b86SEd Tanous const std::shared_ptr< 246445ca1b86SEd Tanous bmcweb::AsyncResp>& 246545ca1b86SEd Tanous asyncResp) { 246645ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 24677e860f15SJohn Edward Broadbent { 246845ca1b86SEd Tanous return; 246945ca1b86SEd Tanous } 24705cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 24715cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 24725cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2473d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 24745cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 247545ca1b86SEd Tanous asyncResp->res.jsonValue["Description"] = "System Dump LogService"; 24765cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 24775cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 24787c8c4058STejas Patil 24797c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 24807c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 248145ca1b86SEd Tanous asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 24827c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 24837c8c4058STejas Patil redfishDateTimeOffset.second; 24847c8c4058STejas Patil 2485*1476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 2486*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 2487*1476687dSEd Tanous asyncResp->res 2488*1476687dSEd Tanous .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 2489*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog"; 2490*1476687dSEd Tanous 2491*1476687dSEd Tanous asyncResp->res 2492*1476687dSEd Tanous .jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 2493*1476687dSEd Tanous ["target"] = 2494*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData"; 24957e860f15SJohn Edward Broadbent }); 24965cb1dd27SAsmitha Karunanithi } 24975cb1dd27SAsmitha Karunanithi 24987e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 24997e860f15SJohn Edward Broadbent { 25007e860f15SJohn Edward Broadbent 25015cb1dd27SAsmitha Karunanithi /** 25025cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 25035cb1dd27SAsmitha Karunanithi */ 2504b2a3289dSAsmitha Karunanithi BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 2505ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 25067e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 250745ca1b86SEd Tanous [&app](const crow::Request& req, 2508864d6a17SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 250945ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 251045ca1b86SEd Tanous { 251145ca1b86SEd Tanous return; 251245ca1b86SEd Tanous } 25135cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 25145cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 25155cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 25165cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 25175cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 25185cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 25195cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 25205cb1dd27SAsmitha Karunanithi 25215cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 25227e860f15SJohn Edward Broadbent }); 25235cb1dd27SAsmitha Karunanithi } 25245cb1dd27SAsmitha Karunanithi 25257e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 25265cb1dd27SAsmitha Karunanithi { 25277e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2528864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2529ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2530ed398213SEd Tanous 25317e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 253245ca1b86SEd Tanous [&app](const crow::Request& req, 25337e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25347e860f15SJohn Edward Broadbent const std::string& param) { 253545ca1b86SEd Tanous getDumpEntryById(app, req, asyncResp, param, "System"); 25367e860f15SJohn Edward Broadbent }); 25378d1b46d7Szhanghch05 25387e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2539864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2540ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 25417e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 254245ca1b86SEd Tanous [&app](const crow::Request& req, 25437e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25447e860f15SJohn Edward Broadbent const std::string& param) { 254545ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 254645ca1b86SEd Tanous { 254745ca1b86SEd Tanous return; 254845ca1b86SEd Tanous } 25497e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "system"); 25507e860f15SJohn Edward Broadbent }); 25515cb1dd27SAsmitha Karunanithi } 2552c9bb6861Sraviteja-b 25537e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2554c9bb6861Sraviteja-b { 25550fda0f12SGeorge Liu BMCWEB_ROUTE( 25560fda0f12SGeorge Liu app, 25570fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2558ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 25597e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 256045ca1b86SEd Tanous [&app](const crow::Request& req, 256145ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 256245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 256345ca1b86SEd Tanous { 256445ca1b86SEd Tanous return; 256545ca1b86SEd Tanous } 256645ca1b86SEd Tanous createDump(asyncResp, req, "System"); 256745ca1b86SEd Tanous }); 2568a43be80fSAsmitha Karunanithi } 2569a43be80fSAsmitha Karunanithi 25707e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2571a43be80fSAsmitha Karunanithi { 25720fda0f12SGeorge Liu BMCWEB_ROUTE( 25730fda0f12SGeorge Liu app, 25740fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog/") 2575ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 25767e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 257745ca1b86SEd Tanous [&app](const crow::Request& req, 25787e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 25797e860f15SJohn Edward Broadbent 258045ca1b86SEd Tanous { 258145ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 258245ca1b86SEd Tanous { 258345ca1b86SEd Tanous return; 258445ca1b86SEd Tanous } 258545ca1b86SEd Tanous clearDump(asyncResp, "System"); 258645ca1b86SEd Tanous }); 2587013487e5Sraviteja-b } 2588013487e5Sraviteja-b 25897e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 25901da66f75SEd Tanous { 25913946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25923946028dSAppaRao Puli // method for security reasons. 25931da66f75SEd Tanous /** 25941da66f75SEd Tanous * Functions triggers appropriate requests on DBus 25951da66f75SEd Tanous */ 25967e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 2597ed398213SEd Tanous // This is incorrect, should be: 2598ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2599432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 260045ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 260145ca1b86SEd Tanous const std::shared_ptr< 260245ca1b86SEd Tanous bmcweb::AsyncResp>& 260345ca1b86SEd Tanous asyncResp) { 260445ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 260545ca1b86SEd Tanous { 260645ca1b86SEd Tanous return; 260745ca1b86SEd Tanous } 26087e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 26097e860f15SJohn Edward Broadbent // SubRoute 26100f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2611424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2612e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 26138e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 26144f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 26154f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 26164f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2617e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2618e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 26197c8c4058STejas Patil 26207c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 26217c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 26227c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 26237c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 26247c8c4058STejas Patil redfishDateTimeOffset.second; 26257c8c4058STejas Patil 2626*1476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 2627*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2628*1476687dSEd Tanous asyncResp->res 2629*1476687dSEd Tanous .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 2630*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog"; 2631*1476687dSEd Tanous asyncResp->res 2632*1476687dSEd Tanous .jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 2633*1476687dSEd Tanous ["target"] = 2634*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData"; 26357e860f15SJohn Edward Broadbent }); 26361da66f75SEd Tanous } 26371da66f75SEd Tanous 26387e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 26395b61b5e8SJason M. Bills { 26400fda0f12SGeorge Liu BMCWEB_ROUTE( 26410fda0f12SGeorge Liu app, 26420fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog/") 2643ed398213SEd Tanous // This is incorrect, should be: 2644ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2645432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 26467e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 264745ca1b86SEd Tanous [&app](const crow::Request& req, 26487e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 264945ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 265045ca1b86SEd Tanous { 265145ca1b86SEd Tanous return; 265245ca1b86SEd Tanous } 26535b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 26545b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2655cb13a392SEd Tanous const std::string&) { 26565b61b5e8SJason M. Bills if (ec) 26575b61b5e8SJason M. Bills { 26585b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 26595b61b5e8SJason M. Bills return; 26605b61b5e8SJason M. Bills } 26615b61b5e8SJason M. Bills messages::success(asyncResp->res); 26625b61b5e8SJason M. Bills }, 26637e860f15SJohn Edward Broadbent crashdumpObject, crashdumpPath, deleteAllInterface, 26647e860f15SJohn Edward Broadbent "DeleteAll"); 26657e860f15SJohn Edward Broadbent }); 26665b61b5e8SJason M. Bills } 26675b61b5e8SJason M. Bills 26688d1b46d7Szhanghch05 static void 26698d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26708d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 2671e855dd28SJason M. Bills { 2672043a0536SJohnathan Mantey auto getStoredLogCallback = 2673b9d36b47SEd Tanous [asyncResp, logID, 2674b9d36b47SEd Tanous &logEntryJson](const boost::system::error_code ec, 2675b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& params) { 2676e855dd28SJason M. Bills if (ec) 2677e855dd28SJason M. Bills { 2678e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 26791ddcf01aSJason M. Bills if (ec.value() == 26801ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 26811ddcf01aSJason M. Bills { 2682043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2683043a0536SJohnathan Mantey logID); 26841ddcf01aSJason M. Bills } 26851ddcf01aSJason M. Bills else 26861ddcf01aSJason M. Bills { 2687e855dd28SJason M. Bills messages::internalError(asyncResp->res); 26881ddcf01aSJason M. Bills } 2689e855dd28SJason M. Bills return; 2690e855dd28SJason M. Bills } 2691043a0536SJohnathan Mantey 2692043a0536SJohnathan Mantey std::string timestamp{}; 2693043a0536SJohnathan Mantey std::string filename{}; 2694043a0536SJohnathan Mantey std::string logfile{}; 26952c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2696043a0536SJohnathan Mantey 2697043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2698e855dd28SJason M. Bills { 2699ace85d60SEd Tanous messages::resourceMissingAtURI( 2700ace85d60SEd Tanous asyncResp->res, crow::utility::urlFromPieces(logID)); 2701e855dd28SJason M. Bills return; 2702e855dd28SJason M. Bills } 2703e855dd28SJason M. Bills 2704043a0536SJohnathan Mantey std::string crashdumpURI = 2705e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2706043a0536SJohnathan Mantey logID + "/" + filename; 27072b20ef6eSJason M. Bills nlohmann::json logEntry = { 27084978b63fSJason M. Bills {"@odata.type", "#LogEntry.v1_7_0.LogEntry"}, 27094978b63fSJason M. Bills {"@odata.id", 27104978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2711e855dd28SJason M. Bills logID}, 2712e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2713e855dd28SJason M. Bills {"Id", logID}, 2714e855dd28SJason M. Bills {"EntryType", "Oem"}, 27158e6c099aSJason M. Bills {"AdditionalDataURI", std::move(crashdumpURI)}, 27168e6c099aSJason M. Bills {"DiagnosticDataType", "OEM"}, 27178e6c099aSJason M. Bills {"OEMDiagnosticDataType", "PECICrashdump"}, 2718043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 27192b20ef6eSJason M. Bills 27202b20ef6eSJason M. Bills // If logEntryJson references an array of LogEntry resources 27212b20ef6eSJason M. Bills // ('Members' list), then push this as a new entry, otherwise set it 27222b20ef6eSJason M. Bills // directly 27232b20ef6eSJason M. Bills if (logEntryJson.is_array()) 27242b20ef6eSJason M. Bills { 27252b20ef6eSJason M. Bills logEntryJson.push_back(logEntry); 27262b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 27272b20ef6eSJason M. Bills logEntryJson.size(); 27282b20ef6eSJason M. Bills } 27292b20ef6eSJason M. Bills else 27302b20ef6eSJason M. Bills { 27312b20ef6eSJason M. Bills logEntryJson = logEntry; 27322b20ef6eSJason M. Bills } 2733e855dd28SJason M. Bills }; 2734e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 27355b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 27365b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2737043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2738e855dd28SJason M. Bills } 2739e855dd28SJason M. Bills 27407e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 27411da66f75SEd Tanous { 27423946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 27433946028dSAppaRao Puli // method for security reasons. 27441da66f75SEd Tanous /** 27451da66f75SEd Tanous * Functions triggers appropriate requests on DBus 27461da66f75SEd Tanous */ 27477e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 27487e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 2749ed398213SEd Tanous // This is incorrect, should be. 2750ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 2751432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 275245ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 275345ca1b86SEd Tanous const std::shared_ptr< 275445ca1b86SEd Tanous bmcweb::AsyncResp>& 275545ca1b86SEd Tanous asyncResp) { 275645ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 275745ca1b86SEd Tanous { 275845ca1b86SEd Tanous return; 275945ca1b86SEd Tanous } 27602b20ef6eSJason M. Bills crow::connections::systemBus->async_method_call( 27612b20ef6eSJason M. Bills [asyncResp](const boost::system::error_code ec, 27622b20ef6eSJason M. Bills const std::vector<std::string>& resp) { 27631da66f75SEd Tanous if (ec) 27641da66f75SEd Tanous { 27651da66f75SEd Tanous if (ec.value() != 27661da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 27671da66f75SEd Tanous { 27681da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 27691da66f75SEd Tanous << ec.message(); 2770f12894f8SJason M. Bills messages::internalError(asyncResp->res); 27711da66f75SEd Tanous return; 27721da66f75SEd Tanous } 27731da66f75SEd Tanous } 2774e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 27751da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 27760f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2777424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 27782b20ef6eSJason M. Bills asyncResp->res.jsonValue["Name"] = 27792b20ef6eSJason M. Bills "Open BMC Crashdump Entries"; 2780e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2781424c4176SJason M. Bills "Collection of Crashdump Entries"; 27822b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"] = 27832b20ef6eSJason M. Bills nlohmann::json::array(); 2784a2dd60a6SBrandon Kim asyncResp->res.jsonValue["Members@odata.count"] = 0; 27852b20ef6eSJason M. Bills 27862b20ef6eSJason M. Bills for (const std::string& path : resp) 27871da66f75SEd Tanous { 27882b20ef6eSJason M. Bills const sdbusplus::message::object_path objPath(path); 2789e855dd28SJason M. Bills // Get the log ID 27902b20ef6eSJason M. Bills std::string logID = objPath.filename(); 27912b20ef6eSJason M. Bills if (logID.empty()) 27921da66f75SEd Tanous { 2793e855dd28SJason M. Bills continue; 27941da66f75SEd Tanous } 2795e855dd28SJason M. Bills // Add the log entry to the array 27962b20ef6eSJason M. Bills logCrashdumpEntry(asyncResp, logID, 27972b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"]); 27981da66f75SEd Tanous } 27992b20ef6eSJason M. Bills }, 28001da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 28011da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 28021da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 28035b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 28047e860f15SJohn Edward Broadbent }); 28051da66f75SEd Tanous } 28061da66f75SEd Tanous 28077e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 28081da66f75SEd Tanous { 28093946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28103946028dSAppaRao Puli // method for security reasons. 28111da66f75SEd Tanous 28127e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 28137e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/") 2814ed398213SEd Tanous // this is incorrect, should be 2815ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 2816432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 28177e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 281845ca1b86SEd Tanous [&app](const crow::Request& req, 28197e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 28207e860f15SJohn Edward Broadbent const std::string& param) { 282145ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 282245ca1b86SEd Tanous { 282345ca1b86SEd Tanous return; 282445ca1b86SEd Tanous } 28257e860f15SJohn Edward Broadbent const std::string& logID = param; 2826e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 28277e860f15SJohn Edward Broadbent }); 2828e855dd28SJason M. Bills } 2829e855dd28SJason M. Bills 28307e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 2831e855dd28SJason M. Bills { 28323946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28333946028dSAppaRao Puli // method for security reasons. 28347e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 28357e860f15SJohn Edward Broadbent app, 28367e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/") 2837ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 28387e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 283945ca1b86SEd Tanous [&app](const crow::Request& req, 28407e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 28417e860f15SJohn Edward Broadbent const std::string& logID, const std::string& fileName) { 284245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 284345ca1b86SEd Tanous { 284445ca1b86SEd Tanous return; 284545ca1b86SEd Tanous } 2846043a0536SJohnathan Mantey auto getStoredLogCallback = 2847ace85d60SEd Tanous [asyncResp, logID, fileName, 2848ace85d60SEd Tanous url(boost::urls::url(req.urlView))]( 2849abf2add6SEd Tanous const boost::system::error_code ec, 2850168e20c1SEd Tanous const std::vector<std::pair< 2851168e20c1SEd Tanous std::string, dbus::utility::DbusVariantType>>& 28527e860f15SJohn Edward Broadbent resp) { 28531da66f75SEd Tanous if (ec) 28541da66f75SEd Tanous { 2855043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2856043a0536SJohnathan Mantey << ec.message(); 2857f12894f8SJason M. Bills messages::internalError(asyncResp->res); 28581da66f75SEd Tanous return; 28591da66f75SEd Tanous } 2860e855dd28SJason M. Bills 2861043a0536SJohnathan Mantey std::string dbusFilename{}; 2862043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2863043a0536SJohnathan Mantey std::string dbusFilepath{}; 2864043a0536SJohnathan Mantey 28657e860f15SJohn Edward Broadbent parseCrashdumpParameters(resp, dbusFilename, 28667e860f15SJohn Edward Broadbent dbusTimestamp, dbusFilepath); 2867043a0536SJohnathan Mantey 2868043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2869043a0536SJohnathan Mantey dbusFilepath.empty()) 28701da66f75SEd Tanous { 2871ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 28721da66f75SEd Tanous return; 28731da66f75SEd Tanous } 2874e855dd28SJason M. Bills 2875043a0536SJohnathan Mantey // Verify the file name parameter is correct 2876043a0536SJohnathan Mantey if (fileName != dbusFilename) 2877043a0536SJohnathan Mantey { 2878ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 2879043a0536SJohnathan Mantey return; 2880043a0536SJohnathan Mantey } 2881043a0536SJohnathan Mantey 2882043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2883043a0536SJohnathan Mantey { 2884ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 2885043a0536SJohnathan Mantey return; 2886043a0536SJohnathan Mantey } 28872d31491bSJason M. Bills std::ifstream ifs(dbusFilepath, 28882d31491bSJason M. Bills std::ios::in | std::ios::binary); 28892d31491bSJason M. Bills asyncResp->res.body() = std::string( 28902d31491bSJason M. Bills std::istreambuf_iterator<char>{ifs}, {}); 2891043a0536SJohnathan Mantey 28927e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 28937e860f15SJohn Edward Broadbent // from a browser 28947e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Disposition", 28957e860f15SJohn Edward Broadbent "attachment"); 28961da66f75SEd Tanous }; 28971da66f75SEd Tanous crow::connections::systemBus->async_method_call( 28985b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 28995b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 29007e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 29017e860f15SJohn Edward Broadbent crashdumpInterface); 29027e860f15SJohn Edward Broadbent }); 29031da66f75SEd Tanous } 29041da66f75SEd Tanous 2905c5a4c82aSJason M. Bills enum class OEMDiagnosticType 2906c5a4c82aSJason M. Bills { 2907c5a4c82aSJason M. Bills onDemand, 2908c5a4c82aSJason M. Bills telemetry, 2909c5a4c82aSJason M. Bills invalid, 2910c5a4c82aSJason M. Bills }; 2911c5a4c82aSJason M. Bills 2912f7725d79SEd Tanous inline OEMDiagnosticType 2913f7725d79SEd Tanous getOEMDiagnosticType(const std::string_view& oemDiagStr) 2914c5a4c82aSJason M. Bills { 2915c5a4c82aSJason M. Bills if (oemDiagStr == "OnDemand") 2916c5a4c82aSJason M. Bills { 2917c5a4c82aSJason M. Bills return OEMDiagnosticType::onDemand; 2918c5a4c82aSJason M. Bills } 2919c5a4c82aSJason M. Bills if (oemDiagStr == "Telemetry") 2920c5a4c82aSJason M. Bills { 2921c5a4c82aSJason M. Bills return OEMDiagnosticType::telemetry; 2922c5a4c82aSJason M. Bills } 2923c5a4c82aSJason M. Bills 2924c5a4c82aSJason M. Bills return OEMDiagnosticType::invalid; 2925c5a4c82aSJason M. Bills } 2926c5a4c82aSJason M. Bills 29277e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 29281da66f75SEd Tanous { 29293946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 29303946028dSAppaRao Puli // method for security reasons. 29310fda0f12SGeorge Liu BMCWEB_ROUTE( 29320fda0f12SGeorge Liu app, 29330fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") 2934ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 2935ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2936432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 29377e860f15SJohn Edward Broadbent .methods( 29387e860f15SJohn Edward Broadbent boost::beast::http::verb:: 293945ca1b86SEd Tanous post)([&app]( 294045ca1b86SEd Tanous const crow::Request& req, 29417e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 294245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 294345ca1b86SEd Tanous { 294445ca1b86SEd Tanous return; 294545ca1b86SEd Tanous } 29468e6c099aSJason M. Bills std::string diagnosticDataType; 29478e6c099aSJason M. Bills std::string oemDiagnosticDataType; 294815ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 29497e860f15SJohn Edward Broadbent req, asyncResp->res, "DiagnosticDataType", 29507e860f15SJohn Edward Broadbent diagnosticDataType, "OEMDiagnosticDataType", 29517e860f15SJohn Edward Broadbent oemDiagnosticDataType)) 29528e6c099aSJason M. Bills { 29538e6c099aSJason M. Bills return; 29548e6c099aSJason M. Bills } 29558e6c099aSJason M. Bills 29568e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 29578e6c099aSJason M. Bills { 29588e6c099aSJason M. Bills BMCWEB_LOG_ERROR 29598e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 29608e6c099aSJason M. Bills messages::actionParameterValueFormatError( 29618e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 29628e6c099aSJason M. Bills "CollectDiagnosticData"); 29638e6c099aSJason M. Bills return; 29648e6c099aSJason M. Bills } 29658e6c099aSJason M. Bills 2966c5a4c82aSJason M. Bills OEMDiagnosticType oemDiagType = 2967c5a4c82aSJason M. Bills getOEMDiagnosticType(oemDiagnosticDataType); 2968c5a4c82aSJason M. Bills 2969c5a4c82aSJason M. Bills std::string iface; 2970c5a4c82aSJason M. Bills std::string method; 2971c5a4c82aSJason M. Bills std::string taskMatchStr; 2972c5a4c82aSJason M. Bills if (oemDiagType == OEMDiagnosticType::onDemand) 2973c5a4c82aSJason M. Bills { 2974c5a4c82aSJason M. Bills iface = crashdumpOnDemandInterface; 2975c5a4c82aSJason M. Bills method = "GenerateOnDemandLog"; 2976c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 2977c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 2978c5a4c82aSJason M. Bills "member='PropertiesChanged'," 2979c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 2980c5a4c82aSJason M. Bills } 2981c5a4c82aSJason M. Bills else if (oemDiagType == OEMDiagnosticType::telemetry) 2982c5a4c82aSJason M. Bills { 2983c5a4c82aSJason M. Bills iface = crashdumpTelemetryInterface; 2984c5a4c82aSJason M. Bills method = "GenerateTelemetryLog"; 2985c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 2986c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 2987c5a4c82aSJason M. Bills "member='PropertiesChanged'," 2988c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 2989c5a4c82aSJason M. Bills } 2990c5a4c82aSJason M. Bills else 2991c5a4c82aSJason M. Bills { 2992c5a4c82aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 2993c5a4c82aSJason M. Bills << oemDiagnosticDataType; 2994c5a4c82aSJason M. Bills messages::actionParameterValueFormatError( 2995c5a4c82aSJason M. Bills asyncResp->res, oemDiagnosticDataType, 2996c5a4c82aSJason M. Bills "OEMDiagnosticDataType", "CollectDiagnosticData"); 2997c5a4c82aSJason M. Bills return; 2998c5a4c82aSJason M. Bills } 2999c5a4c82aSJason M. Bills 3000c5a4c82aSJason M. Bills auto collectCrashdumpCallback = 3001c5a4c82aSJason M. Bills [asyncResp, payload(task::Payload(req)), 3002c5a4c82aSJason M. Bills taskMatchStr](const boost::system::error_code ec, 300398be3e39SEd Tanous const std::string&) mutable { 30041da66f75SEd Tanous if (ec) 30051da66f75SEd Tanous { 30067e860f15SJohn Edward Broadbent if (ec.value() == 30077e860f15SJohn Edward Broadbent boost::system::errc::operation_not_supported) 30081da66f75SEd Tanous { 3009f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 30101da66f75SEd Tanous } 30114363d3b2SJason M. Bills else if (ec.value() == 30124363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 30134363d3b2SJason M. Bills { 3014c5a4c82aSJason M. Bills messages::serviceTemporarilyUnavailable( 3015c5a4c82aSJason M. Bills asyncResp->res, "60"); 30164363d3b2SJason M. Bills } 30171da66f75SEd Tanous else 30181da66f75SEd Tanous { 3019f12894f8SJason M. Bills messages::internalError(asyncResp->res); 30201da66f75SEd Tanous } 30211da66f75SEd Tanous return; 30221da66f75SEd Tanous } 3023c5a4c82aSJason M. Bills std::shared_ptr<task::TaskData> task = 3024c5a4c82aSJason M. Bills task::TaskData::createTask( 30257e860f15SJohn Edward Broadbent [](boost::system::error_code err, 30267e860f15SJohn Edward Broadbent sdbusplus::message::message&, 3027c5a4c82aSJason M. Bills const std::shared_ptr<task::TaskData>& 3028c5a4c82aSJason M. Bills taskData) { 302966afe4faSJames Feist if (!err) 303066afe4faSJames Feist { 3031e5d5006bSJames Feist taskData->messages.emplace_back( 3032e5d5006bSJames Feist messages::taskCompletedOK( 3033e5d5006bSJames Feist std::to_string(taskData->index))); 3034831d6b09SJames Feist taskData->state = "Completed"; 303566afe4faSJames Feist } 303632898ceaSJames Feist return task::completed; 303766afe4faSJames Feist }, 3038c5a4c82aSJason M. Bills taskMatchStr); 3039c5a4c82aSJason M. Bills 304046229577SJames Feist task->startTimer(std::chrono::minutes(5)); 304146229577SJames Feist task->populateResp(asyncResp->res); 304298be3e39SEd Tanous task->payload.emplace(std::move(payload)); 30431da66f75SEd Tanous }; 30448e6c099aSJason M. Bills 30451da66f75SEd Tanous crow::connections::systemBus->async_method_call( 30468e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 3047c5a4c82aSJason M. Bills crashdumpPath, iface, method); 30487e860f15SJohn Edward Broadbent }); 30496eda7685SKenny L. Ku } 30506eda7685SKenny L. Ku 3051cb92c03bSAndrew Geissler /** 3052cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 3053cb92c03bSAndrew Geissler */ 30547e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 3055cb92c03bSAndrew Geissler { 3056cb92c03bSAndrew Geissler /** 3057cb92c03bSAndrew Geissler * Function handles POST method request. 3058cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3059cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3060cb92c03bSAndrew Geissler */ 30617e860f15SJohn Edward Broadbent 30620fda0f12SGeorge Liu BMCWEB_ROUTE( 30630fda0f12SGeorge Liu app, 30640fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/") 3065ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 30667e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 306745ca1b86SEd Tanous [&app](const crow::Request& req, 30687e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 306945ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 307045ca1b86SEd Tanous { 307145ca1b86SEd Tanous return; 307245ca1b86SEd Tanous } 3073cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 3074cb92c03bSAndrew Geissler 3075cb92c03bSAndrew Geissler // Process response from Logging service. 30767e860f15SJohn Edward Broadbent auto respHandler = [asyncResp]( 30777e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 30787e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 30797e860f15SJohn Edward Broadbent << "doClearLog resp_handler callback: Done"; 3080cb92c03bSAndrew Geissler if (ec) 3081cb92c03bSAndrew Geissler { 3082cb92c03bSAndrew Geissler // TODO Handle for specific error code 30837e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " 30847e860f15SJohn Edward Broadbent << ec; 3085cb92c03bSAndrew Geissler asyncResp->res.result( 3086cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3087cb92c03bSAndrew Geissler return; 3088cb92c03bSAndrew Geissler } 3089cb92c03bSAndrew Geissler 30907e860f15SJohn Edward Broadbent asyncResp->res.result( 30917e860f15SJohn Edward Broadbent boost::beast::http::status::no_content); 3092cb92c03bSAndrew Geissler }; 3093cb92c03bSAndrew Geissler 3094cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3095cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 30962c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 3097cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3098cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 30997e860f15SJohn Edward Broadbent }); 3100cb92c03bSAndrew Geissler } 3101a3316fc6SZhikuiRen 3102a3316fc6SZhikuiRen /**************************************************** 3103a3316fc6SZhikuiRen * Redfish PostCode interfaces 3104a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3105a3316fc6SZhikuiRen ******************************************************/ 31067e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 3107a3316fc6SZhikuiRen { 31087e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 3109ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 311045ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 311145ca1b86SEd Tanous const std::shared_ptr< 311245ca1b86SEd Tanous bmcweb::AsyncResp>& 311345ca1b86SEd Tanous asyncResp) { 311445ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 311545ca1b86SEd Tanous { 311645ca1b86SEd Tanous return; 311745ca1b86SEd Tanous } 3118*1476687dSEd Tanous 3119*1476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3120*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes"; 3121*1476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 3122*1476687dSEd Tanous "#LogService.v1_1_0.LogService"; 3123*1476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "POST Code Log Service"; 3124*1476687dSEd Tanous asyncResp->res.jsonValue["Description"] = "POST Code Log Service"; 3125*1476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "BIOS POST Code Log"; 3126*1476687dSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 3127*1476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 3128*1476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 31297c8c4058STejas Patil 31307c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 31317c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 31320fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 31337c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 31347c8c4058STejas Patil redfishDateTimeOffset.second; 31357c8c4058STejas Patil 3136a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 31377e860f15SJohn Edward Broadbent {"target", 31380fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog"}}; 31397e860f15SJohn Edward Broadbent }); 3140a3316fc6SZhikuiRen } 3141a3316fc6SZhikuiRen 31427e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3143a3316fc6SZhikuiRen { 31440fda0f12SGeorge Liu BMCWEB_ROUTE( 31450fda0f12SGeorge Liu app, 31460fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog/") 3147ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3148ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3149432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 31507e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 315145ca1b86SEd Tanous [&app](const crow::Request& req, 31527e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 315345ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 315445ca1b86SEd Tanous { 315545ca1b86SEd Tanous return; 315645ca1b86SEd Tanous } 3157a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3158a3316fc6SZhikuiRen 3159a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3160a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3161a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3162a3316fc6SZhikuiRen if (ec) 3163a3316fc6SZhikuiRen { 3164a3316fc6SZhikuiRen // TODO Handle for specific error code 3165a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 31667e860f15SJohn Edward Broadbent << "doClearPostCodes resp_handler got error " 31677e860f15SJohn Edward Broadbent << ec; 31687e860f15SJohn Edward Broadbent asyncResp->res.result(boost::beast::http::status:: 31697e860f15SJohn Edward Broadbent internal_server_error); 3170a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3171a3316fc6SZhikuiRen return; 3172a3316fc6SZhikuiRen } 3173a3316fc6SZhikuiRen }, 317415124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 317515124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3176a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 31777e860f15SJohn Edward Broadbent }); 3178a3316fc6SZhikuiRen } 3179a3316fc6SZhikuiRen 3180a3316fc6SZhikuiRen static void fillPostCodeEntry( 31818d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 31826c9a279eSManojkiran Eda const boost::container::flat_map< 31836c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3184a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3185a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3186a3316fc6SZhikuiRen { 3187a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3188fffb8c1fSEd Tanous const registries::Message* message = 3189fffb8c1fSEd Tanous registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3190a3316fc6SZhikuiRen 3191a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3192a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 3193a3316fc6SZhikuiRen 3194a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 31956c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 31966c9a279eSManojkiran Eda code : postcode) 3197a3316fc6SZhikuiRen { 3198a3316fc6SZhikuiRen currentCodeIndex++; 3199a3316fc6SZhikuiRen std::string postcodeEntryID = 3200a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3201a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3202a3316fc6SZhikuiRen 3203a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3204a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3205a3316fc6SZhikuiRen 3206a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3207a3316fc6SZhikuiRen { // already incremented 3208a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3209a3316fc6SZhikuiRen } 3210a3316fc6SZhikuiRen else 3211a3316fc6SZhikuiRen { 3212a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3213a3316fc6SZhikuiRen } 3214a3316fc6SZhikuiRen 3215a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3216a3316fc6SZhikuiRen // not fall between top and skip 3217a3316fc6SZhikuiRen if ((codeIndex == 0) && 3218a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3219a3316fc6SZhikuiRen { 3220a3316fc6SZhikuiRen continue; 3221a3316fc6SZhikuiRen } 3222a3316fc6SZhikuiRen 32234e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3224a3316fc6SZhikuiRen // currentIndex 3225a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3226a3316fc6SZhikuiRen { 3227a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3228a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3229a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3230a3316fc6SZhikuiRen continue; 3231a3316fc6SZhikuiRen } 3232a3316fc6SZhikuiRen 3233a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3234a3316fc6SZhikuiRen // index 3235a3316fc6SZhikuiRen 3236a3316fc6SZhikuiRen // Get the Created time from the timestamp 3237a3316fc6SZhikuiRen std::string entryTimeStr; 32381d8782e7SNan Zhou entryTimeStr = 32391d8782e7SNan Zhou crow::utility::getDateTimeUint(usecSinceEpoch / 1000 / 1000); 3240a3316fc6SZhikuiRen 3241a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3242a3316fc6SZhikuiRen std::ostringstream hexCode; 3243a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 32446c9a279eSManojkiran Eda << std::get<0>(code.second); 3245a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3246a3316fc6SZhikuiRen // Set Fixed -Point Notation 3247a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3248a3316fc6SZhikuiRen // Set precision to 4 digits 3249a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3250a3316fc6SZhikuiRen // Add double to stream 3251a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3252a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3253a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3254a3316fc6SZhikuiRen 3255a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3256a3316fc6SZhikuiRen std::string msg; 3257a3316fc6SZhikuiRen if (message != nullptr) 3258a3316fc6SZhikuiRen { 3259a3316fc6SZhikuiRen msg = message->message; 3260a3316fc6SZhikuiRen 3261a3316fc6SZhikuiRen // fill in this post code value 3262a3316fc6SZhikuiRen int i = 0; 3263a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3264a3316fc6SZhikuiRen { 3265a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3266a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3267a3316fc6SZhikuiRen if (argPos != std::string::npos) 3268a3316fc6SZhikuiRen { 3269a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3270a3316fc6SZhikuiRen } 3271a3316fc6SZhikuiRen } 3272a3316fc6SZhikuiRen } 3273a3316fc6SZhikuiRen 3274d4342a92STim Lee // Get Severity template from message registry 3275d4342a92STim Lee std::string severity; 3276d4342a92STim Lee if (message != nullptr) 3277d4342a92STim Lee { 32785f2b84eeSEd Tanous severity = message->messageSeverity; 3279d4342a92STim Lee } 3280d4342a92STim Lee 3281a3316fc6SZhikuiRen // add to AsyncResp 3282a3316fc6SZhikuiRen logEntryArray.push_back({}); 3283a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 32840fda0f12SGeorge Liu bmcLogEntry = { 32850fda0f12SGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 32860fda0f12SGeorge Liu {"@odata.id", 32870fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3288a3316fc6SZhikuiRen postcodeEntryID}, 3289a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 3290a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 3291a3316fc6SZhikuiRen {"Message", std::move(msg)}, 32924a0bf539SManojkiran Eda {"MessageId", "OpenBMC.0.2.BIOSPOSTCode"}, 3293a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 3294a3316fc6SZhikuiRen {"EntryType", "Event"}, 3295a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 32969c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 3297647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 3298647b3cdcSGeorge Liu { 3299647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 3300647b3cdcSGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3301647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 3302647b3cdcSGeorge Liu } 3303a3316fc6SZhikuiRen } 3304a3316fc6SZhikuiRen } 3305a3316fc6SZhikuiRen 33068d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3307a3316fc6SZhikuiRen const uint16_t bootIndex, 3308a3316fc6SZhikuiRen const uint64_t codeIndex) 3309a3316fc6SZhikuiRen { 3310a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 33116c9a279eSManojkiran Eda [aResp, bootIndex, 33126c9a279eSManojkiran Eda codeIndex](const boost::system::error_code ec, 33136c9a279eSManojkiran Eda const boost::container::flat_map< 33146c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 33156c9a279eSManojkiran Eda postcode) { 3316a3316fc6SZhikuiRen if (ec) 3317a3316fc6SZhikuiRen { 3318a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3319a3316fc6SZhikuiRen messages::internalError(aResp->res); 3320a3316fc6SZhikuiRen return; 3321a3316fc6SZhikuiRen } 3322a3316fc6SZhikuiRen 3323a3316fc6SZhikuiRen // skip the empty postcode boots 3324a3316fc6SZhikuiRen if (postcode.empty()) 3325a3316fc6SZhikuiRen { 3326a3316fc6SZhikuiRen return; 3327a3316fc6SZhikuiRen } 3328a3316fc6SZhikuiRen 3329a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3330a3316fc6SZhikuiRen 3331a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3332a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3333a3316fc6SZhikuiRen }, 333415124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 333515124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3336a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3337a3316fc6SZhikuiRen bootIndex); 3338a3316fc6SZhikuiRen } 3339a3316fc6SZhikuiRen 33408d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3341a3316fc6SZhikuiRen const uint16_t bootIndex, 3342a3316fc6SZhikuiRen const uint16_t bootCount, 3343a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 3344a3316fc6SZhikuiRen const uint64_t top) 3345a3316fc6SZhikuiRen { 3346a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3347a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3348a3316fc6SZhikuiRen top](const boost::system::error_code ec, 33496c9a279eSManojkiran Eda const boost::container::flat_map< 33506c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 33516c9a279eSManojkiran Eda postcode) { 3352a3316fc6SZhikuiRen if (ec) 3353a3316fc6SZhikuiRen { 3354a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3355a3316fc6SZhikuiRen messages::internalError(aResp->res); 3356a3316fc6SZhikuiRen return; 3357a3316fc6SZhikuiRen } 3358a3316fc6SZhikuiRen 3359a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3360a3316fc6SZhikuiRen if (!postcode.empty()) 3361a3316fc6SZhikuiRen { 3362a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 3363a3316fc6SZhikuiRen 3364a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3365a3316fc6SZhikuiRen { 3366a3316fc6SZhikuiRen uint64_t thisBootSkip = 3367a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3368a3316fc6SZhikuiRen uint64_t thisBootTop = 3369a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3370a3316fc6SZhikuiRen 3371a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3372a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3373a3316fc6SZhikuiRen } 3374a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3375a3316fc6SZhikuiRen } 3376a3316fc6SZhikuiRen 3377a3316fc6SZhikuiRen // continue to previous bootIndex 3378a3316fc6SZhikuiRen if (bootIndex < bootCount) 3379a3316fc6SZhikuiRen { 3380a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3381a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3382a3316fc6SZhikuiRen } 3383a3316fc6SZhikuiRen else 3384a3316fc6SZhikuiRen { 3385a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 33860fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries?$skip=" + 3387a3316fc6SZhikuiRen std::to_string(skip + top); 3388a3316fc6SZhikuiRen } 3389a3316fc6SZhikuiRen }, 339015124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 339115124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3392a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3393a3316fc6SZhikuiRen bootIndex); 3394a3316fc6SZhikuiRen } 3395a3316fc6SZhikuiRen 33968d1b46d7Szhanghch05 static void 33978d1b46d7Szhanghch05 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3398a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3399a3316fc6SZhikuiRen { 3400a3316fc6SZhikuiRen uint64_t entryCount = 0; 34011e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint16_t>( 34021e1e598dSJonathan Doman *crow::connections::systemBus, 34031e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 34041e1e598dSJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 34051e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", 34061e1e598dSJonathan Doman [aResp, entryCount, skip, top](const boost::system::error_code ec, 34071e1e598dSJonathan Doman const uint16_t bootCount) { 3408a3316fc6SZhikuiRen if (ec) 3409a3316fc6SZhikuiRen { 3410a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3411a3316fc6SZhikuiRen messages::internalError(aResp->res); 3412a3316fc6SZhikuiRen return; 3413a3316fc6SZhikuiRen } 34141e1e598dSJonathan Doman getPostCodeForBoot(aResp, 1, bootCount, entryCount, skip, top); 34151e1e598dSJonathan Doman }); 3416a3316fc6SZhikuiRen } 3417a3316fc6SZhikuiRen 34187e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3419a3316fc6SZhikuiRen { 34207e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 34217e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3422ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 34237e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 342445ca1b86SEd Tanous [&app](const crow::Request& req, 34257e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3426c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 3427c937d2bfSEd Tanous .canDelegateTop = true, 3428c937d2bfSEd Tanous .canDelegateSkip = true, 3429c937d2bfSEd Tanous }; 3430c937d2bfSEd Tanous query_param::Query delegatedQuery; 3431c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 3432c937d2bfSEd Tanous app, req, asyncResp->res, delegatedQuery, capabilities)) 343345ca1b86SEd Tanous { 343445ca1b86SEd Tanous return; 343545ca1b86SEd Tanous } 3436a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3437a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3438a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3439a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3440a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3441a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3442a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3443a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3444a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3445a3316fc6SZhikuiRen 3446c937d2bfSEd Tanous getCurrentBootNumber(asyncResp, delegatedQuery.skip, 3447c937d2bfSEd Tanous delegatedQuery.top); 34487e860f15SJohn Edward Broadbent }); 3449a3316fc6SZhikuiRen } 3450a3316fc6SZhikuiRen 3451647b3cdcSGeorge Liu /** 3452647b3cdcSGeorge Liu * @brief Parse post code ID and get the current value and index value 3453647b3cdcSGeorge Liu * eg: postCodeID=B1-2, currentValue=1, index=2 3454647b3cdcSGeorge Liu * 3455647b3cdcSGeorge Liu * @param[in] postCodeID Post Code ID 3456647b3cdcSGeorge Liu * @param[out] currentValue Current value 3457647b3cdcSGeorge Liu * @param[out] index Index value 3458647b3cdcSGeorge Liu * 3459647b3cdcSGeorge Liu * @return bool true if the parsing is successful, false the parsing fails 3460647b3cdcSGeorge Liu */ 3461647b3cdcSGeorge Liu inline static bool parsePostCode(const std::string& postCodeID, 3462647b3cdcSGeorge Liu uint64_t& currentValue, uint16_t& index) 3463647b3cdcSGeorge Liu { 3464647b3cdcSGeorge Liu std::vector<std::string> split; 3465647b3cdcSGeorge Liu boost::algorithm::split(split, postCodeID, boost::is_any_of("-")); 3466647b3cdcSGeorge Liu if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B') 3467647b3cdcSGeorge Liu { 3468647b3cdcSGeorge Liu return false; 3469647b3cdcSGeorge Liu } 3470647b3cdcSGeorge Liu 3471ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3472647b3cdcSGeorge Liu const char* start = split[0].data() + 1; 3473ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3474647b3cdcSGeorge Liu const char* end = split[0].data() + split[0].size(); 3475647b3cdcSGeorge Liu auto [ptrIndex, ecIndex] = std::from_chars(start, end, index); 3476647b3cdcSGeorge Liu 3477647b3cdcSGeorge Liu if (ptrIndex != end || ecIndex != std::errc()) 3478647b3cdcSGeorge Liu { 3479647b3cdcSGeorge Liu return false; 3480647b3cdcSGeorge Liu } 3481647b3cdcSGeorge Liu 3482647b3cdcSGeorge Liu start = split[1].data(); 3483ca45aa3cSEd Tanous 3484ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3485647b3cdcSGeorge Liu end = split[1].data() + split[1].size(); 3486647b3cdcSGeorge Liu auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue); 3487647b3cdcSGeorge Liu 3488dcf2ebc0SEd Tanous return ptrValue == end && ecValue != std::errc(); 3489647b3cdcSGeorge Liu } 3490647b3cdcSGeorge Liu 3491647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3492647b3cdcSGeorge Liu { 34930fda0f12SGeorge Liu BMCWEB_ROUTE( 34940fda0f12SGeorge Liu app, 34950fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/attachment/") 3496647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 3497647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 349845ca1b86SEd Tanous [&app](const crow::Request& req, 3499647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3500647b3cdcSGeorge Liu const std::string& postCodeID) { 350145ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 350245ca1b86SEd Tanous { 350345ca1b86SEd Tanous return; 350445ca1b86SEd Tanous } 3505647b3cdcSGeorge Liu if (!http_helpers::isOctetAccepted( 3506647b3cdcSGeorge Liu req.getHeaderValue("Accept"))) 3507647b3cdcSGeorge Liu { 3508647b3cdcSGeorge Liu asyncResp->res.result( 3509647b3cdcSGeorge Liu boost::beast::http::status::bad_request); 3510647b3cdcSGeorge Liu return; 3511647b3cdcSGeorge Liu } 3512647b3cdcSGeorge Liu 3513647b3cdcSGeorge Liu uint64_t currentValue = 0; 3514647b3cdcSGeorge Liu uint16_t index = 0; 3515647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 3516647b3cdcSGeorge Liu { 3517647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", 3518647b3cdcSGeorge Liu postCodeID); 3519647b3cdcSGeorge Liu return; 3520647b3cdcSGeorge Liu } 3521647b3cdcSGeorge Liu 3522647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 3523647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 3524647b3cdcSGeorge Liu const boost::system::error_code ec, 3525647b3cdcSGeorge Liu const std::vector<std::tuple< 3526647b3cdcSGeorge Liu uint64_t, std::vector<uint8_t>>>& postcodes) { 3527647b3cdcSGeorge Liu if (ec.value() == EBADR) 3528647b3cdcSGeorge Liu { 3529647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3530647b3cdcSGeorge Liu "LogEntry", postCodeID); 3531647b3cdcSGeorge Liu return; 3532647b3cdcSGeorge Liu } 3533647b3cdcSGeorge Liu if (ec) 3534647b3cdcSGeorge Liu { 3535647b3cdcSGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3536647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 3537647b3cdcSGeorge Liu return; 3538647b3cdcSGeorge Liu } 3539647b3cdcSGeorge Liu 3540647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 3541647b3cdcSGeorge Liu if (value == std::string::npos || 3542647b3cdcSGeorge Liu postcodes.size() < currentValue) 3543647b3cdcSGeorge Liu { 3544647b3cdcSGeorge Liu BMCWEB_LOG_ERROR << "Wrong currentValue value"; 3545647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3546647b3cdcSGeorge Liu "LogEntry", postCodeID); 3547647b3cdcSGeorge Liu return; 3548647b3cdcSGeorge Liu } 3549647b3cdcSGeorge Liu 35509eb808c1SEd Tanous const auto& [tID, c] = postcodes[value]; 355146ff87baSEd Tanous if (c.empty()) 3552647b3cdcSGeorge Liu { 3553647b3cdcSGeorge Liu BMCWEB_LOG_INFO << "No found post code data"; 3554647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3555647b3cdcSGeorge Liu "LogEntry", postCodeID); 3556647b3cdcSGeorge Liu return; 3557647b3cdcSGeorge Liu } 355846ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 355946ff87baSEd Tanous const char* d = reinterpret_cast<const char*>(c.data()); 356046ff87baSEd Tanous std::string_view strData(d, c.size()); 3561647b3cdcSGeorge Liu 3562647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Type", 3563647b3cdcSGeorge Liu "application/octet-stream"); 3564647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Transfer-Encoding", 3565647b3cdcSGeorge Liu "Base64"); 3566647b3cdcSGeorge Liu asyncResp->res.body() = 3567647b3cdcSGeorge Liu crow::utility::base64encode(strData); 3568647b3cdcSGeorge Liu }, 3569647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 3570647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 3571647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", 3572647b3cdcSGeorge Liu index); 3573647b3cdcSGeorge Liu }); 3574647b3cdcSGeorge Liu } 3575647b3cdcSGeorge Liu 35767e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 3577a3316fc6SZhikuiRen { 35787e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 35797e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/") 3580ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 35817e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 358245ca1b86SEd Tanous [&app](const crow::Request& req, 35837e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 35847e860f15SJohn Edward Broadbent const std::string& targetID) { 358545ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 358645ca1b86SEd Tanous { 358745ca1b86SEd Tanous return; 358845ca1b86SEd Tanous } 3589647b3cdcSGeorge Liu uint16_t bootIndex = 0; 3590647b3cdcSGeorge Liu uint64_t codeIndex = 0; 3591647b3cdcSGeorge Liu if (!parsePostCode(targetID, codeIndex, bootIndex)) 3592a3316fc6SZhikuiRen { 3593a3316fc6SZhikuiRen // Requested ID was not found 3594ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 3595a3316fc6SZhikuiRen return; 3596a3316fc6SZhikuiRen } 3597a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3598a3316fc6SZhikuiRen { 3599a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 36007e860f15SJohn Edward Broadbent << targetID; 3601a3316fc6SZhikuiRen } 3602a3316fc6SZhikuiRen 36037e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = 36047e860f15SJohn Edward Broadbent "#LogEntry.v1_4_0.LogEntry"; 3605a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 36060fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3607a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3608a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3609a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3610a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3611a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3612a3316fc6SZhikuiRen 3613a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 36147e860f15SJohn Edward Broadbent }); 3615a3316fc6SZhikuiRen } 3616a3316fc6SZhikuiRen 36171da66f75SEd Tanous } // namespace redfish 3618