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 366*565dfb6fSClaire Weinan std::sort(resp.begin(), resp.end(), 367*565dfb6fSClaire Weinan [](const auto& l, const auto& r) { 368*565dfb6fSClaire Weinan return AlphanumLess<std::string>()( 369*565dfb6fSClaire Weinan l.first.filename(), r.first.filename()); 370*565dfb6fSClaire Weinan }); 371*565dfb6fSClaire Weinan 3725cb1dd27SAsmitha Karunanithi for (auto& object : resp) 3735cb1dd27SAsmitha Karunanithi { 374b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 3755cb1dd27SAsmitha Karunanithi { 3765cb1dd27SAsmitha Karunanithi continue; 3775cb1dd27SAsmitha Karunanithi } 3781d8782e7SNan Zhou uint64_t timestamp = 0; 3795cb1dd27SAsmitha Karunanithi uint64_t size = 0; 38035440d18SAsmitha Karunanithi std::string dumpStatus; 38135440d18SAsmitha Karunanithi nlohmann::json thisEntry; 3822dfd18efSEd Tanous 3832dfd18efSEd Tanous std::string entryID = object.first.filename(); 3842dfd18efSEd Tanous if (entryID.empty()) 3855cb1dd27SAsmitha Karunanithi { 3865cb1dd27SAsmitha Karunanithi continue; 3875cb1dd27SAsmitha Karunanithi } 3885cb1dd27SAsmitha Karunanithi 3895cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 3905cb1dd27SAsmitha Karunanithi { 39135440d18SAsmitha Karunanithi if (interfaceMap.first == 39235440d18SAsmitha Karunanithi "xyz.openbmc_project.Common.Progress") 39335440d18SAsmitha Karunanithi { 3949eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 39535440d18SAsmitha Karunanithi { 39635440d18SAsmitha Karunanithi if (propertyMap.first == "Status") 39735440d18SAsmitha Karunanithi { 39855f79e6fSEd Tanous const auto* status = std::get_if<std::string>( 39935440d18SAsmitha Karunanithi &propertyMap.second); 40035440d18SAsmitha Karunanithi if (status == nullptr) 40135440d18SAsmitha Karunanithi { 40235440d18SAsmitha Karunanithi messages::internalError(asyncResp->res); 40335440d18SAsmitha Karunanithi break; 40435440d18SAsmitha Karunanithi } 40535440d18SAsmitha Karunanithi dumpStatus = *status; 40635440d18SAsmitha Karunanithi } 40735440d18SAsmitha Karunanithi } 40835440d18SAsmitha Karunanithi } 40935440d18SAsmitha Karunanithi else if (interfaceMap.first == 41035440d18SAsmitha Karunanithi "xyz.openbmc_project.Dump.Entry") 4115cb1dd27SAsmitha Karunanithi { 4125cb1dd27SAsmitha Karunanithi 4135cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4145cb1dd27SAsmitha Karunanithi { 4155cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4165cb1dd27SAsmitha Karunanithi { 41755f79e6fSEd Tanous const auto* sizePtr = 4185cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4195cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4205cb1dd27SAsmitha Karunanithi { 4215cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4225cb1dd27SAsmitha Karunanithi break; 4235cb1dd27SAsmitha Karunanithi } 4245cb1dd27SAsmitha Karunanithi size = *sizePtr; 4255cb1dd27SAsmitha Karunanithi break; 4265cb1dd27SAsmitha Karunanithi } 4275cb1dd27SAsmitha Karunanithi } 4285cb1dd27SAsmitha Karunanithi } 4295cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4305cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 4315cb1dd27SAsmitha Karunanithi { 4325cb1dd27SAsmitha Karunanithi 4339eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 4345cb1dd27SAsmitha Karunanithi { 4355cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 4365cb1dd27SAsmitha Karunanithi { 4375cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 4385cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4395cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 4405cb1dd27SAsmitha Karunanithi { 4415cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4425cb1dd27SAsmitha Karunanithi break; 4435cb1dd27SAsmitha Karunanithi } 4441d8782e7SNan Zhou timestamp = (*usecsTimeStamp / 1000 / 1000); 4455cb1dd27SAsmitha Karunanithi break; 4465cb1dd27SAsmitha Karunanithi } 4475cb1dd27SAsmitha Karunanithi } 4485cb1dd27SAsmitha Karunanithi } 4495cb1dd27SAsmitha Karunanithi } 4505cb1dd27SAsmitha Karunanithi 4510fda0f12SGeorge Liu if (dumpStatus != 4520fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 45335440d18SAsmitha Karunanithi !dumpStatus.empty()) 45435440d18SAsmitha Karunanithi { 45535440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 45635440d18SAsmitha Karunanithi continue; 45735440d18SAsmitha Karunanithi } 45835440d18SAsmitha Karunanithi 459647b3cdcSGeorge Liu thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 4605cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 4615cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 4625cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 4631d8782e7SNan Zhou thisEntry["Created"] = 4641d8782e7SNan Zhou crow::utility::getDateTimeUint(timestamp); 4655cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 4665cb1dd27SAsmitha Karunanithi 467d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataSizeBytes"] = size; 4685cb1dd27SAsmitha Karunanithi 4695cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 4705cb1dd27SAsmitha Karunanithi { 471d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 472d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 473de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 474de8d94a3SAbhishek Patel entryID + "/attachment"; 4755cb1dd27SAsmitha Karunanithi } 4765cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 4775cb1dd27SAsmitha Karunanithi { 478d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 479d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 480d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 481de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 482de8d94a3SAbhishek Patel entryID + "/attachment"; 4835cb1dd27SAsmitha Karunanithi } 48435440d18SAsmitha Karunanithi entriesArray.push_back(std::move(thisEntry)); 4855cb1dd27SAsmitha Karunanithi } 4865cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 4875cb1dd27SAsmitha Karunanithi entriesArray.size(); 4885cb1dd27SAsmitha Karunanithi }, 4895cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 4905cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 4915cb1dd27SAsmitha Karunanithi } 4925cb1dd27SAsmitha Karunanithi 4938d1b46d7Szhanghch05 inline void 49445ca1b86SEd Tanous getDumpEntryById(crow::App& app, const crow::Request& req, 49545ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4968d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 4975cb1dd27SAsmitha Karunanithi { 49845ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 49945ca1b86SEd Tanous { 50045ca1b86SEd Tanous return; 50145ca1b86SEd Tanous } 5025cb1dd27SAsmitha Karunanithi std::string dumpPath; 5035cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5045cb1dd27SAsmitha Karunanithi { 5055cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5065cb1dd27SAsmitha Karunanithi } 5075cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5085cb1dd27SAsmitha Karunanithi { 5095cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5105cb1dd27SAsmitha Karunanithi } 5115cb1dd27SAsmitha Karunanithi else 5125cb1dd27SAsmitha Karunanithi { 5135cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5145cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5155cb1dd27SAsmitha Karunanithi return; 5165cb1dd27SAsmitha Karunanithi } 5175cb1dd27SAsmitha Karunanithi 5185cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 519711ac7a9SEd Tanous [asyncResp, entryID, dumpPath, 520711ac7a9SEd Tanous dumpType](const boost::system::error_code ec, 521711ac7a9SEd Tanous dbus::utility::ManagedObjectType& resp) { 5225cb1dd27SAsmitha Karunanithi if (ec) 5235cb1dd27SAsmitha Karunanithi { 5245cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5255cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5265cb1dd27SAsmitha Karunanithi return; 5275cb1dd27SAsmitha Karunanithi } 5285cb1dd27SAsmitha Karunanithi 529b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 530b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 531b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 532b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 533b47452b2SAsmitha Karunanithi "/entry/"; 534b47452b2SAsmitha Karunanithi 5359eb808c1SEd Tanous for (const auto& objectPath : resp) 5365cb1dd27SAsmitha Karunanithi { 537b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5385cb1dd27SAsmitha Karunanithi { 5395cb1dd27SAsmitha Karunanithi continue; 5405cb1dd27SAsmitha Karunanithi } 5415cb1dd27SAsmitha Karunanithi 5425cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 5431d8782e7SNan Zhou uint64_t timestamp = 0; 5445cb1dd27SAsmitha Karunanithi uint64_t size = 0; 54535440d18SAsmitha Karunanithi std::string dumpStatus; 5465cb1dd27SAsmitha Karunanithi 5479eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 5485cb1dd27SAsmitha Karunanithi { 54935440d18SAsmitha Karunanithi if (interfaceMap.first == 55035440d18SAsmitha Karunanithi "xyz.openbmc_project.Common.Progress") 55135440d18SAsmitha Karunanithi { 5529eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 55335440d18SAsmitha Karunanithi { 55435440d18SAsmitha Karunanithi if (propertyMap.first == "Status") 55535440d18SAsmitha Karunanithi { 5569eb808c1SEd Tanous const std::string* status = 5579eb808c1SEd Tanous std::get_if<std::string>( 55835440d18SAsmitha Karunanithi &propertyMap.second); 55935440d18SAsmitha Karunanithi if (status == nullptr) 56035440d18SAsmitha Karunanithi { 56135440d18SAsmitha Karunanithi messages::internalError(asyncResp->res); 56235440d18SAsmitha Karunanithi break; 56335440d18SAsmitha Karunanithi } 56435440d18SAsmitha Karunanithi dumpStatus = *status; 56535440d18SAsmitha Karunanithi } 56635440d18SAsmitha Karunanithi } 56735440d18SAsmitha Karunanithi } 56835440d18SAsmitha Karunanithi else if (interfaceMap.first == 56935440d18SAsmitha Karunanithi "xyz.openbmc_project.Dump.Entry") 5705cb1dd27SAsmitha Karunanithi { 5719eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 5725cb1dd27SAsmitha Karunanithi { 5735cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 5745cb1dd27SAsmitha Karunanithi { 5759eb808c1SEd Tanous const uint64_t* sizePtr = 5765cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5775cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 5785cb1dd27SAsmitha Karunanithi { 5795cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5805cb1dd27SAsmitha Karunanithi break; 5815cb1dd27SAsmitha Karunanithi } 5825cb1dd27SAsmitha Karunanithi size = *sizePtr; 5835cb1dd27SAsmitha Karunanithi break; 5845cb1dd27SAsmitha Karunanithi } 5855cb1dd27SAsmitha Karunanithi } 5865cb1dd27SAsmitha Karunanithi } 5875cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 5885cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 5895cb1dd27SAsmitha Karunanithi { 5909eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 5915cb1dd27SAsmitha Karunanithi { 5925cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 5935cb1dd27SAsmitha Karunanithi { 5945cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 5955cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5965cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 5975cb1dd27SAsmitha Karunanithi { 5985cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5995cb1dd27SAsmitha Karunanithi break; 6005cb1dd27SAsmitha Karunanithi } 6011d8782e7SNan Zhou timestamp = *usecsTimeStamp / 1000 / 1000; 6025cb1dd27SAsmitha Karunanithi break; 6035cb1dd27SAsmitha Karunanithi } 6045cb1dd27SAsmitha Karunanithi } 6055cb1dd27SAsmitha Karunanithi } 6065cb1dd27SAsmitha Karunanithi } 6075cb1dd27SAsmitha Karunanithi 6080fda0f12SGeorge Liu if (dumpStatus != 6090fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 61035440d18SAsmitha Karunanithi !dumpStatus.empty()) 61135440d18SAsmitha Karunanithi { 61235440d18SAsmitha Karunanithi // Dump status is not Complete 61335440d18SAsmitha Karunanithi // return not found until status is changed to Completed 61435440d18SAsmitha Karunanithi messages::resourceNotFound(asyncResp->res, 61535440d18SAsmitha Karunanithi dumpType + " dump", entryID); 61635440d18SAsmitha Karunanithi return; 61735440d18SAsmitha Karunanithi } 61835440d18SAsmitha Karunanithi 6195cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 620647b3cdcSGeorge Liu "#LogEntry.v1_8_0.LogEntry"; 6215cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6225cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6235cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6245cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6251d8782e7SNan Zhou crow::utility::getDateTimeUint(timestamp); 6265cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6275cb1dd27SAsmitha Karunanithi 628d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6295cb1dd27SAsmitha Karunanithi 6305cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6315cb1dd27SAsmitha Karunanithi { 632d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 633d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 634de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 635de8d94a3SAbhishek Patel entryID + "/attachment"; 6365cb1dd27SAsmitha Karunanithi } 6375cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6385cb1dd27SAsmitha Karunanithi { 639d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 640d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["OEMDiagnosticDataType"] = 6415cb1dd27SAsmitha Karunanithi "System"; 642d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 643de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 644de8d94a3SAbhishek Patel entryID + "/attachment"; 6455cb1dd27SAsmitha Karunanithi } 6465cb1dd27SAsmitha Karunanithi } 647e05aec50SEd Tanous if (!foundDumpEntry) 648b47452b2SAsmitha Karunanithi { 649b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 650b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 651b47452b2SAsmitha Karunanithi return; 652b47452b2SAsmitha Karunanithi } 6535cb1dd27SAsmitha Karunanithi }, 6545cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6555cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6565cb1dd27SAsmitha Karunanithi } 6575cb1dd27SAsmitha Karunanithi 6588d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6599878256fSStanley Chu const std::string& entryID, 660b47452b2SAsmitha Karunanithi const std::string& dumpType) 6615cb1dd27SAsmitha Karunanithi { 6623de8d8baSGeorge Liu auto respHandler = [asyncResp, 6633de8d8baSGeorge Liu entryID](const boost::system::error_code ec) { 6645cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6655cb1dd27SAsmitha Karunanithi if (ec) 6665cb1dd27SAsmitha Karunanithi { 6673de8d8baSGeorge Liu if (ec.value() == EBADR) 6683de8d8baSGeorge Liu { 6693de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 6703de8d8baSGeorge Liu return; 6713de8d8baSGeorge Liu } 6725cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 6735cb1dd27SAsmitha Karunanithi << ec; 6745cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6755cb1dd27SAsmitha Karunanithi return; 6765cb1dd27SAsmitha Karunanithi } 6775cb1dd27SAsmitha Karunanithi }; 6785cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 6795cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 680b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 681b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 682b47452b2SAsmitha Karunanithi entryID, 6835cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 6845cb1dd27SAsmitha Karunanithi } 6855cb1dd27SAsmitha Karunanithi 6868d1b46d7Szhanghch05 inline void 68798be3e39SEd Tanous createDumpTaskCallback(task::Payload&& payload, 6888d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6898d1b46d7Szhanghch05 const uint32_t& dumpId, const std::string& dumpPath, 690a43be80fSAsmitha Karunanithi const std::string& dumpType) 691a43be80fSAsmitha Karunanithi { 692a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 6936145ed6fSAsmitha Karunanithi [dumpId, dumpPath, dumpType]( 694a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 695a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 696cb13a392SEd Tanous if (err) 697cb13a392SEd Tanous { 6986145ed6fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Error in creating a dump"; 6996145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 7006145ed6fSAsmitha Karunanithi return task::completed; 701cb13a392SEd Tanous } 702b9d36b47SEd Tanous 703b9d36b47SEd Tanous dbus::utility::DBusInteracesMap interfacesList; 704a43be80fSAsmitha Karunanithi 705a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 706a43be80fSAsmitha Karunanithi 707a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 708a43be80fSAsmitha Karunanithi 709b47452b2SAsmitha Karunanithi if (objPath.str == 710b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 711b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 712b47452b2SAsmitha Karunanithi "/entry/" + std::to_string(dumpId)) 713a43be80fSAsmitha Karunanithi { 714a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 715a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 716a43be80fSAsmitha Karunanithi 717a43be80fSAsmitha Karunanithi std::string headerLoc = 718a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 719a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 720a43be80fSAsmitha Karunanithi std::move(headerLoc)); 721a43be80fSAsmitha Karunanithi 722a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 723b47452b2SAsmitha Karunanithi return task::completed; 7246145ed6fSAsmitha Karunanithi } 725a43be80fSAsmitha Karunanithi return task::completed; 726a43be80fSAsmitha Karunanithi }, 7274978b63fSJason M. Bills "type='signal',interface='org.freedesktop.DBus.ObjectManager'," 728a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 729a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 730a43be80fSAsmitha Karunanithi 731a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 732a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 73398be3e39SEd Tanous task->payload.emplace(std::move(payload)); 734a43be80fSAsmitha Karunanithi } 735a43be80fSAsmitha Karunanithi 7368d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7378d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 738a43be80fSAsmitha Karunanithi { 739a43be80fSAsmitha Karunanithi std::string dumpPath; 740a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 741a43be80fSAsmitha Karunanithi { 742a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 743a43be80fSAsmitha Karunanithi } 744a43be80fSAsmitha Karunanithi else if (dumpType == "System") 745a43be80fSAsmitha Karunanithi { 746a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 747a43be80fSAsmitha Karunanithi } 748a43be80fSAsmitha Karunanithi else 749a43be80fSAsmitha Karunanithi { 750a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 751a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 752a43be80fSAsmitha Karunanithi return; 753a43be80fSAsmitha Karunanithi } 754a43be80fSAsmitha Karunanithi 755a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 756a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 757a43be80fSAsmitha Karunanithi 75815ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 759a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 760a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 761a43be80fSAsmitha Karunanithi { 762a43be80fSAsmitha Karunanithi return; 763a43be80fSAsmitha Karunanithi } 764a43be80fSAsmitha Karunanithi 765a43be80fSAsmitha Karunanithi if (dumpType == "System") 766a43be80fSAsmitha Karunanithi { 767a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 768a43be80fSAsmitha Karunanithi { 7694978b63fSJason M. Bills BMCWEB_LOG_ERROR 7704978b63fSJason M. Bills << "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"; 771a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 772a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 773a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 774a43be80fSAsmitha Karunanithi return; 775a43be80fSAsmitha Karunanithi } 7763174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 777a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 778a43be80fSAsmitha Karunanithi { 779a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 780ace85d60SEd Tanous messages::internalError(asyncResp->res); 781a43be80fSAsmitha Karunanithi return; 782a43be80fSAsmitha Karunanithi } 783a43be80fSAsmitha Karunanithi } 784a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 785a43be80fSAsmitha Karunanithi { 786a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 787a43be80fSAsmitha Karunanithi { 7880fda0f12SGeorge Liu BMCWEB_LOG_ERROR 7890fda0f12SGeorge Liu << "CreateDump action parameter 'DiagnosticDataType' not found!"; 790a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 791a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 792a43be80fSAsmitha Karunanithi return; 793a43be80fSAsmitha Karunanithi } 7943174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 795a43be80fSAsmitha Karunanithi { 796a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 797a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 798ace85d60SEd Tanous messages::internalError(asyncResp->res); 799a43be80fSAsmitha Karunanithi return; 800a43be80fSAsmitha Karunanithi } 801a43be80fSAsmitha Karunanithi } 802a43be80fSAsmitha Karunanithi 803a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 80498be3e39SEd Tanous [asyncResp, payload(task::Payload(req)), dumpPath, 80598be3e39SEd Tanous dumpType](const boost::system::error_code ec, 80698be3e39SEd Tanous const uint32_t& dumpId) mutable { 807a43be80fSAsmitha Karunanithi if (ec) 808a43be80fSAsmitha Karunanithi { 809a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 810a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 811a43be80fSAsmitha Karunanithi return; 812a43be80fSAsmitha Karunanithi } 813a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 814a43be80fSAsmitha Karunanithi 81598be3e39SEd Tanous createDumpTaskCallback(std::move(payload), asyncResp, dumpId, 81698be3e39SEd Tanous dumpPath, dumpType); 817a43be80fSAsmitha Karunanithi }, 818b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 819b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 820b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 821a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 822a43be80fSAsmitha Karunanithi } 823a43be80fSAsmitha Karunanithi 8248d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8258d1b46d7Szhanghch05 const std::string& dumpType) 82680319af1SAsmitha Karunanithi { 827b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 828b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 8298d1b46d7Szhanghch05 83080319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 831b9d36b47SEd Tanous [asyncResp, dumpType]( 832b9d36b47SEd Tanous const boost::system::error_code ec, 833b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 83480319af1SAsmitha Karunanithi if (ec) 83580319af1SAsmitha Karunanithi { 83680319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 83780319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 83880319af1SAsmitha Karunanithi return; 83980319af1SAsmitha Karunanithi } 84080319af1SAsmitha Karunanithi 84180319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 84280319af1SAsmitha Karunanithi { 8432dfd18efSEd Tanous sdbusplus::message::object_path objPath(path); 8442dfd18efSEd Tanous std::string logID = objPath.filename(); 8452dfd18efSEd Tanous if (logID.empty()) 84680319af1SAsmitha Karunanithi { 8472dfd18efSEd Tanous continue; 84880319af1SAsmitha Karunanithi } 8492dfd18efSEd Tanous deleteDumpEntry(asyncResp, logID, dumpType); 85080319af1SAsmitha Karunanithi } 85180319af1SAsmitha Karunanithi }, 85280319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 85380319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 85480319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 855b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, 856b47452b2SAsmitha Karunanithi std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." + 857b47452b2SAsmitha Karunanithi dumpType}); 85880319af1SAsmitha Karunanithi } 85980319af1SAsmitha Karunanithi 860b9d36b47SEd Tanous inline static void 861b9d36b47SEd Tanous parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params, 862b9d36b47SEd Tanous std::string& filename, std::string& timestamp, 863b9d36b47SEd Tanous std::string& logfile) 864043a0536SJohnathan Mantey { 865043a0536SJohnathan Mantey for (auto property : params) 866043a0536SJohnathan Mantey { 867043a0536SJohnathan Mantey if (property.first == "Timestamp") 868043a0536SJohnathan Mantey { 869043a0536SJohnathan Mantey const std::string* value = 8708d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 871043a0536SJohnathan Mantey if (value != nullptr) 872043a0536SJohnathan Mantey { 873043a0536SJohnathan Mantey timestamp = *value; 874043a0536SJohnathan Mantey } 875043a0536SJohnathan Mantey } 876043a0536SJohnathan Mantey else if (property.first == "Filename") 877043a0536SJohnathan Mantey { 878043a0536SJohnathan Mantey const std::string* value = 8798d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 880043a0536SJohnathan Mantey if (value != nullptr) 881043a0536SJohnathan Mantey { 882043a0536SJohnathan Mantey filename = *value; 883043a0536SJohnathan Mantey } 884043a0536SJohnathan Mantey } 885043a0536SJohnathan Mantey else if (property.first == "Log") 886043a0536SJohnathan Mantey { 887043a0536SJohnathan Mantey const std::string* value = 8888d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 889043a0536SJohnathan Mantey if (value != nullptr) 890043a0536SJohnathan Mantey { 891043a0536SJohnathan Mantey logfile = *value; 892043a0536SJohnathan Mantey } 893043a0536SJohnathan Mantey } 894043a0536SJohnathan Mantey } 895043a0536SJohnathan Mantey } 896043a0536SJohnathan Mantey 897a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 8987e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 8991da66f75SEd Tanous { 900c4bf6374SJason M. Bills /** 901c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 902c4bf6374SJason M. Bills */ 9037e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/") 904ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 90545ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 90645ca1b86SEd Tanous const std::shared_ptr< 90745ca1b86SEd Tanous bmcweb::AsyncResp>& 90845ca1b86SEd Tanous asyncResp) { 90945ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 910c4bf6374SJason M. Bills { 91145ca1b86SEd Tanous return; 91245ca1b86SEd Tanous } 9137e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 9147e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 915c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 916c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 917c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 918029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 91945ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 920c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 921c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 9227e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 9237e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 924c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 9251476687dSEd Tanous nlohmann::json::object_t eventLog; 9261476687dSEd Tanous eventLog["@odata.id"] = 9271476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 9281476687dSEd Tanous logServiceArray.push_back(std::move(eventLog)); 9295cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 9301476687dSEd Tanous nlohmann::json::object_t dumpLog; 9311476687dSEd Tanous eventLog["@odata.id"] = 9321476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump"; 9331476687dSEd Tanous logServiceArray.push_back(std::move(dumpLog)); 934c9bb6861Sraviteja-b #endif 935c9bb6861Sraviteja-b 936d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 9371476687dSEd Tanous nlohmann::json::object_t crashdump; 9381476687dSEd Tanous crashdump["@odata.id"] = 9391476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump"; 9401476687dSEd Tanous logServiceArray.push_back(std::move(crashdump)); 941d53dd41fSJason M. Bills #endif 942b7028ebfSSpencer Ku 943b7028ebfSSpencer Ku #ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER 9441476687dSEd Tanous nlohmann::json::object_t hostlogger; 9451476687dSEd Tanous hostlogger["@odata.id"] = 9461476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger"; 9471476687dSEd Tanous logServiceArray.push_back(std::move(hostlogger)); 948b7028ebfSSpencer Ku #endif 949c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 950c4bf6374SJason M. Bills logServiceArray.size(); 951a3316fc6SZhikuiRen 952a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 95345ca1b86SEd Tanous [asyncResp](const boost::system::error_code ec, 954b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& 955b9d36b47SEd Tanous subtreePath) { 956a3316fc6SZhikuiRen if (ec) 957a3316fc6SZhikuiRen { 958a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 959a3316fc6SZhikuiRen return; 960a3316fc6SZhikuiRen } 961a3316fc6SZhikuiRen 96255f79e6fSEd Tanous for (const auto& pathStr : subtreePath) 963a3316fc6SZhikuiRen { 964a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 965a3316fc6SZhikuiRen { 96623a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 967a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 96823a21a1cSEd Tanous logServiceArrayLocal.push_back( 9690fda0f12SGeorge Liu {{"@odata.id", 9700fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes"}}); 97145ca1b86SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 97223a21a1cSEd Tanous logServiceArrayLocal.size(); 973a3316fc6SZhikuiRen return; 974a3316fc6SZhikuiRen } 975a3316fc6SZhikuiRen } 976a3316fc6SZhikuiRen }, 977a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 978a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 97945ca1b86SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 98045ca1b86SEd Tanous std::array<const char*, 1>{postCodeIface}); 9817e860f15SJohn Edward Broadbent }); 982c4bf6374SJason M. Bills } 983c4bf6374SJason M. Bills 9847e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 985c4bf6374SJason M. Bills { 9867e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 987ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 98845ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 98945ca1b86SEd Tanous const std::shared_ptr< 99045ca1b86SEd Tanous bmcweb::AsyncResp>& 99145ca1b86SEd Tanous asyncResp) { 99245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 99345ca1b86SEd Tanous { 99445ca1b86SEd Tanous return; 99545ca1b86SEd Tanous } 996c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 997029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 998c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 999c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 1000c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 10017e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 10027e860f15SJohn Edward Broadbent "System Event Log Service"; 1003c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1004c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 10057c8c4058STejas Patil 10067c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 10077c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 10087c8c4058STejas Patil 10097c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 10107c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 10117c8c4058STejas Patil redfishDateTimeOffset.second; 10127c8c4058STejas Patil 10131476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 10141476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1015e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1016e7d6c8b2SGunnar Mills 10170fda0f12SGeorge Liu {"target", 10180fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog"}}; 10197e860f15SJohn Edward Broadbent }); 1020489640c6SJason M. Bills } 1021489640c6SJason M. Bills 10227e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1023489640c6SJason M. Bills { 10244978b63fSJason M. Bills BMCWEB_ROUTE( 10254978b63fSJason M. Bills app, 10264978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/") 1027432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 10287e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 102945ca1b86SEd Tanous [&app](const crow::Request& req, 10307e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 103145ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 103245ca1b86SEd Tanous { 103345ca1b86SEd Tanous return; 103445ca1b86SEd Tanous } 1035489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1036489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1037489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1038489640c6SJason M. Bills { 1039489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1040489640c6SJason M. Bills { 1041489640c6SJason M. Bills std::error_code ec; 1042489640c6SJason M. Bills std::filesystem::remove(file, ec); 1043489640c6SJason M. Bills } 1044489640c6SJason M. Bills } 1045489640c6SJason M. Bills 1046489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1047489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1048489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1049489640c6SJason M. Bills if (ec) 1050489640c6SJason M. Bills { 10517e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " 10527e860f15SJohn Edward Broadbent << ec; 1053489640c6SJason M. Bills messages::internalError(asyncResp->res); 1054489640c6SJason M. Bills return; 1055489640c6SJason M. Bills } 1056489640c6SJason M. Bills 1057489640c6SJason M. Bills messages::success(asyncResp->res); 1058489640c6SJason M. Bills }, 1059489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 10607e860f15SJohn Edward Broadbent "org.freedesktop.systemd1.Manager", "ReloadUnit", 10617e860f15SJohn Edward Broadbent "rsyslog.service", "replace"); 10627e860f15SJohn Edward Broadbent }); 1063c4bf6374SJason M. Bills } 1064c4bf6374SJason M. Bills 106595820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 1066b5a76932SEd Tanous const std::string& logEntry, 106795820184SJason M. Bills nlohmann::json& logEntryJson) 1068c4bf6374SJason M. Bills { 106995820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1070cd225da8SJason M. Bills // First get the Timestamp 1071f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1072cd225da8SJason M. Bills if (space == std::string::npos) 107395820184SJason M. Bills { 107495820184SJason M. Bills return 1; 107595820184SJason M. Bills } 1076cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1077cd225da8SJason M. Bills // Then get the log contents 1078f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1079cd225da8SJason M. Bills if (entryStart == std::string::npos) 1080cd225da8SJason M. Bills { 1081cd225da8SJason M. Bills return 1; 1082cd225da8SJason M. Bills } 1083cd225da8SJason M. Bills std::string_view entry(logEntry); 1084cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1085cd225da8SJason M. Bills // Use split to separate the entry into its fields 1086cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1087cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1088cd225da8SJason M. Bills boost::token_compress_on); 1089cd225da8SJason M. Bills // We need at least a MessageId to be valid 109026f6976fSEd Tanous if (logEntryFields.empty()) 1091cd225da8SJason M. Bills { 1092cd225da8SJason M. Bills return 1; 1093cd225da8SJason M. Bills } 1094cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 109595820184SJason M. Bills 10964851d45dSJason M. Bills // Get the Message from the MessageRegistry 1097fffb8c1fSEd Tanous const registries::Message* message = registries::getMessage(messageID); 1098c4bf6374SJason M. Bills 109954417b02SSui Chen if (message == nullptr) 1100c4bf6374SJason M. Bills { 110154417b02SSui Chen BMCWEB_LOG_WARNING << "Log entry not found in registry: " << logEntry; 110254417b02SSui Chen return 0; 1103c4bf6374SJason M. Bills } 1104c4bf6374SJason M. Bills 110554417b02SSui Chen std::string msg = message->message; 110654417b02SSui Chen 110715a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 110826702d01SEd Tanous std::span<std::string> messageArgs; 110915a86ff6SJason M. Bills if (logEntryFields.size() > 1) 111015a86ff6SJason M. Bills { 111115a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 111215a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 111315a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 111415a86ff6SJason M. Bills if (!messageArgsStart.empty()) 111515a86ff6SJason M. Bills { 111615a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 111715a86ff6SJason M. Bills } 111815a86ff6SJason M. Bills 111923a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1120c4bf6374SJason M. Bills 11214851d45dSJason M. Bills // Fill the MessageArgs into the Message 112295820184SJason M. Bills int i = 0; 112395820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11244851d45dSJason M. Bills { 112595820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11264851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11274851d45dSJason M. Bills if (argPos != std::string::npos) 11284851d45dSJason M. Bills { 112995820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11304851d45dSJason M. Bills } 11314851d45dSJason M. Bills } 113215a86ff6SJason M. Bills } 11334851d45dSJason M. Bills 113495820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 113595820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 113695820184SJason M. Bills // between the '.' and the '+', so just remove them. 1137f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1138f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 113995820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1140c4bf6374SJason M. Bills { 114195820184SJason M. Bills timestamp.erase(dot, plus - dot); 1142c4bf6374SJason M. Bills } 1143c4bf6374SJason M. Bills 1144c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 114595820184SJason M. Bills logEntryJson = { 1146647b3cdcSGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 1147029573d4SEd Tanous {"@odata.id", 1148897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 114995820184SJason M. Bills logEntryID}, 1150c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 115195820184SJason M. Bills {"Id", logEntryID}, 115295820184SJason M. Bills {"Message", std::move(msg)}, 115395820184SJason M. Bills {"MessageId", std::move(messageID)}, 1154f23b7296SEd Tanous {"MessageArgs", messageArgs}, 1155c4bf6374SJason M. Bills {"EntryType", "Event"}, 115654417b02SSui Chen {"Severity", message->messageSeverity}, 115795820184SJason M. Bills {"Created", std::move(timestamp)}}; 1158c4bf6374SJason M. Bills return 0; 1159c4bf6374SJason M. Bills } 1160c4bf6374SJason M. Bills 11617e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1162c4bf6374SJason M. Bills { 11637e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 11647e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 11658b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 116645ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 116745ca1b86SEd Tanous const std::shared_ptr< 116845ca1b86SEd Tanous bmcweb::AsyncResp>& 116945ca1b86SEd Tanous asyncResp) { 1170c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1171c937d2bfSEd Tanous .canDelegateTop = true, 1172c937d2bfSEd Tanous .canDelegateSkip = true, 1173c937d2bfSEd Tanous }; 1174c937d2bfSEd Tanous query_param::Query delegatedQuery; 1175c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 1176c937d2bfSEd Tanous app, req, asyncResp->res, delegatedQuery, capabilities)) 1177c4bf6374SJason M. Bills { 1178c4bf6374SJason M. Bills return; 1179c4bf6374SJason M. Bills } 11807e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 11817e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1182c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1183c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1184c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1185029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1186c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1187c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1188c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1189cb92c03bSAndrew Geissler 11904978b63fSJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1191c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 11927e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 11937e860f15SJohn Edward Broadbent // entry 119495820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 119595820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1196b01bf299SEd Tanous uint64_t entryCount = 0; 1197cd225da8SJason M. Bills std::string logEntry; 119895820184SJason M. Bills 11997e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12007e860f15SJohn Edward Broadbent // backwards 12017e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 12027e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1203c4bf6374SJason M. Bills { 1204cd225da8SJason M. Bills std::ifstream logStream(*it); 120595820184SJason M. Bills if (!logStream.is_open()) 1206c4bf6374SJason M. Bills { 1207c4bf6374SJason M. Bills continue; 1208c4bf6374SJason M. Bills } 1209c4bf6374SJason M. Bills 1210e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1211e85d6b16SJason M. Bills bool firstEntry = true; 121295820184SJason M. Bills while (std::getline(logStream, logEntry)) 121395820184SJason M. Bills { 1214c4bf6374SJason M. Bills entryCount++; 12157e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip 12167e860f15SJohn Edward Broadbent // from the start) and top (number of entries to 12177e860f15SJohn Edward Broadbent // display) 1218c937d2bfSEd Tanous if (entryCount <= delegatedQuery.skip || 1219c937d2bfSEd Tanous entryCount > delegatedQuery.skip + delegatedQuery.top) 1220c4bf6374SJason M. Bills { 1221c4bf6374SJason M. Bills continue; 1222c4bf6374SJason M. Bills } 1223c4bf6374SJason M. Bills 1224c4bf6374SJason M. Bills std::string idStr; 1225e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1226c4bf6374SJason M. Bills { 1227c4bf6374SJason M. Bills continue; 1228c4bf6374SJason M. Bills } 1229c4bf6374SJason M. Bills 1230e85d6b16SJason M. Bills if (firstEntry) 1231e85d6b16SJason M. Bills { 1232e85d6b16SJason M. Bills firstEntry = false; 1233e85d6b16SJason M. Bills } 1234e85d6b16SJason M. Bills 1235c4bf6374SJason M. Bills logEntryArray.push_back({}); 1236c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 12374978b63fSJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 12384978b63fSJason M. Bills 0) 1239c4bf6374SJason M. Bills { 1240c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1241c4bf6374SJason M. Bills return; 1242c4bf6374SJason M. Bills } 1243c4bf6374SJason M. Bills } 124495820184SJason M. Bills } 1245c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1246c937d2bfSEd Tanous if (delegatedQuery.skip + delegatedQuery.top < entryCount) 1247c4bf6374SJason M. Bills { 1248c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 12494978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries?$skip=" + 1250c937d2bfSEd Tanous std::to_string(delegatedQuery.skip + delegatedQuery.top); 1251c4bf6374SJason M. Bills } 12527e860f15SJohn Edward Broadbent }); 1253897967deSJason M. Bills } 1254897967deSJason M. Bills 12557e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1256897967deSJason M. Bills { 12577e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 12587e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1259ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 12607e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 126145ca1b86SEd Tanous [&app](const crow::Request& req, 12627e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12637e860f15SJohn Edward Broadbent const std::string& param) { 126445ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 126545ca1b86SEd Tanous { 126645ca1b86SEd Tanous return; 126745ca1b86SEd Tanous } 12687e860f15SJohn Edward Broadbent const std::string& targetID = param; 12698d1b46d7Szhanghch05 12707e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 12717e860f15SJohn Edward Broadbent // entry to find the target entry 1272897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1273897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1274897967deSJason M. Bills std::string logEntry; 1275897967deSJason M. Bills 12767e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12777e860f15SJohn Edward Broadbent // backwards 12787e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 12797e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1280897967deSJason M. Bills { 1281897967deSJason M. Bills std::ifstream logStream(*it); 1282897967deSJason M. Bills if (!logStream.is_open()) 1283897967deSJason M. Bills { 1284897967deSJason M. Bills continue; 1285897967deSJason M. Bills } 1286897967deSJason M. Bills 1287897967deSJason M. Bills // Reset the unique ID on the first entry 1288897967deSJason M. Bills bool firstEntry = true; 1289897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1290897967deSJason M. Bills { 1291897967deSJason M. Bills std::string idStr; 1292897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1293897967deSJason M. Bills { 1294897967deSJason M. Bills continue; 1295897967deSJason M. Bills } 1296897967deSJason M. Bills 1297897967deSJason M. Bills if (firstEntry) 1298897967deSJason M. Bills { 1299897967deSJason M. Bills firstEntry = false; 1300897967deSJason M. Bills } 1301897967deSJason M. Bills 1302897967deSJason M. Bills if (idStr == targetID) 1303897967deSJason M. Bills { 13047e860f15SJohn Edward Broadbent if (fillEventLogEntryJson( 13057e860f15SJohn Edward Broadbent idStr, logEntry, 1306897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1307897967deSJason M. Bills { 1308897967deSJason M. Bills messages::internalError(asyncResp->res); 1309897967deSJason M. Bills return; 1310897967deSJason M. Bills } 1311897967deSJason M. Bills return; 1312897967deSJason M. Bills } 1313897967deSJason M. Bills } 1314897967deSJason M. Bills } 1315897967deSJason M. Bills // Requested ID was not found 1316ace85d60SEd Tanous messages::resourceMissingAtURI( 1317ace85d60SEd Tanous asyncResp->res, crow::utility::urlFromPieces(targetID)); 13187e860f15SJohn Edward Broadbent }); 131908a4e4b5SAnthony Wilson } 132008a4e4b5SAnthony Wilson 13217e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 132208a4e4b5SAnthony Wilson { 13237e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 13247e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1325ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 132645ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 132745ca1b86SEd Tanous const std::shared_ptr< 132845ca1b86SEd Tanous bmcweb::AsyncResp>& 132945ca1b86SEd Tanous asyncResp) { 133045ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 133145ca1b86SEd Tanous { 133245ca1b86SEd Tanous return; 133345ca1b86SEd Tanous } 13347e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 13357e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 133608a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 133708a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 133808a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 133908a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 134008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 134108a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 134208a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 134308a4e4b5SAnthony Wilson 1344cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1345cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1346cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1347cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1348914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& resp) { 1349cb92c03bSAndrew Geissler if (ec) 1350cb92c03bSAndrew Geissler { 1351cb92c03bSAndrew Geissler // TODO Handle for specific error code 1352cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1353cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1354cb92c03bSAndrew Geissler << ec; 1355cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1356cb92c03bSAndrew Geissler return; 1357cb92c03bSAndrew Geissler } 1358cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1359cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1360cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 13619eb808c1SEd Tanous for (const auto& objectPath : resp) 1362cb92c03bSAndrew Geissler { 1363914e2d5dSEd Tanous const uint32_t* id = nullptr; 1364c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1365c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1366914e2d5dSEd Tanous const std::string* severity = nullptr; 1367914e2d5dSEd Tanous const std::string* message = nullptr; 1368914e2d5dSEd Tanous const std::string* filePath = nullptr; 136975710de2SXiaochao Ma bool resolved = false; 13709eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 1371f86bb901SAdriana Kobylak { 1372f86bb901SAdriana Kobylak if (interfaceMap.first == 1373f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1374f86bb901SAdriana Kobylak { 13759eb808c1SEd Tanous for (const auto& propertyMap : 13769eb808c1SEd Tanous interfaceMap.second) 1377cb92c03bSAndrew Geissler { 1378cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1379cb92c03bSAndrew Geissler { 1380f86bb901SAdriana Kobylak id = std::get_if<uint32_t>( 1381f86bb901SAdriana Kobylak &propertyMap.second); 1382cb92c03bSAndrew Geissler } 1383cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1384cb92c03bSAndrew Geissler { 1385c419c759SEd Tanous timestamp = std::get_if<uint64_t>( 1386f86bb901SAdriana Kobylak &propertyMap.second); 13877e860f15SJohn Edward Broadbent } 13887e860f15SJohn Edward Broadbent else if (propertyMap.first == 13897e860f15SJohn Edward Broadbent "UpdateTimestamp") 13907e860f15SJohn Edward Broadbent { 1391c419c759SEd Tanous updateTimestamp = std::get_if<uint64_t>( 13927e860f15SJohn Edward Broadbent &propertyMap.second); 13937e860f15SJohn Edward Broadbent } 13947e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 13957e860f15SJohn Edward Broadbent { 13967e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 13977e860f15SJohn Edward Broadbent &propertyMap.second); 13987e860f15SJohn Edward Broadbent } 13997e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 14007e860f15SJohn Edward Broadbent { 14017e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 14027e860f15SJohn Edward Broadbent &propertyMap.second); 14037e860f15SJohn Edward Broadbent } 14047e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 14057e860f15SJohn Edward Broadbent { 1406914e2d5dSEd Tanous const bool* resolveptr = 1407914e2d5dSEd Tanous std::get_if<bool>( 14087e860f15SJohn Edward Broadbent &propertyMap.second); 14097e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 14107e860f15SJohn Edward Broadbent { 14117e860f15SJohn Edward Broadbent messages::internalError( 14127e860f15SJohn Edward Broadbent asyncResp->res); 14137e860f15SJohn Edward Broadbent return; 14147e860f15SJohn Edward Broadbent } 14157e860f15SJohn Edward Broadbent resolved = *resolveptr; 14167e860f15SJohn Edward Broadbent } 14177e860f15SJohn Edward Broadbent } 14187e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14197e860f15SJohn Edward Broadbent severity == nullptr) 14207e860f15SJohn Edward Broadbent { 14217e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 14227e860f15SJohn Edward Broadbent return; 14237e860f15SJohn Edward Broadbent } 14247e860f15SJohn Edward Broadbent } 14257e860f15SJohn Edward Broadbent else if (interfaceMap.first == 14267e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 14277e860f15SJohn Edward Broadbent { 14289eb808c1SEd Tanous for (const auto& propertyMap : 14299eb808c1SEd Tanous interfaceMap.second) 14307e860f15SJohn Edward Broadbent { 14317e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 14327e860f15SJohn Edward Broadbent { 14337e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 14347e860f15SJohn Edward Broadbent &propertyMap.second); 14357e860f15SJohn Edward Broadbent } 14367e860f15SJohn Edward Broadbent } 14377e860f15SJohn Edward Broadbent } 14387e860f15SJohn Edward Broadbent } 14397e860f15SJohn Edward Broadbent // Object path without the 14407e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 14417e860f15SJohn Edward Broadbent // and continue. 14427e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 1443c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1444c419c759SEd Tanous updateTimestamp == nullptr) 14457e860f15SJohn Edward Broadbent { 14467e860f15SJohn Edward Broadbent continue; 14477e860f15SJohn Edward Broadbent } 14487e860f15SJohn Edward Broadbent entriesArray.push_back({}); 14497e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 14507e860f15SJohn Edward Broadbent thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 14517e860f15SJohn Edward Broadbent thisEntry["@odata.id"] = 14520fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 14537e860f15SJohn Edward Broadbent std::to_string(*id); 14547e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 14557e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 14567e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 14577e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 14587e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 14597e860f15SJohn Edward Broadbent thisEntry["Severity"] = 14607e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 14617e860f15SJohn Edward Broadbent thisEntry["Created"] = 1462c419c759SEd Tanous crow::utility::getDateTimeUintMs(*timestamp); 14637e860f15SJohn Edward Broadbent thisEntry["Modified"] = 1464c419c759SEd Tanous crow::utility::getDateTimeUintMs(*updateTimestamp); 14657e860f15SJohn Edward Broadbent if (filePath != nullptr) 14667e860f15SJohn Edward Broadbent { 14677e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 14680fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 14697e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 14707e860f15SJohn Edward Broadbent } 14717e860f15SJohn Edward Broadbent } 14727e860f15SJohn Edward Broadbent std::sort(entriesArray.begin(), entriesArray.end(), 14737e860f15SJohn Edward Broadbent [](const nlohmann::json& left, 14747e860f15SJohn Edward Broadbent const nlohmann::json& right) { 14757e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 14767e860f15SJohn Edward Broadbent }); 14777e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 14787e860f15SJohn Edward Broadbent entriesArray.size(); 14797e860f15SJohn Edward Broadbent }, 14807e860f15SJohn Edward Broadbent "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 14817e860f15SJohn Edward Broadbent "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 14827e860f15SJohn Edward Broadbent }); 14837e860f15SJohn Edward Broadbent } 14847e860f15SJohn Edward Broadbent 14857e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 14867e860f15SJohn Edward Broadbent { 14877e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 14887e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1489ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 149045ca1b86SEd Tanous .methods( 149145ca1b86SEd Tanous boost::beast::http::verb:: 149245ca1b86SEd Tanous get)([&app](const crow::Request& req, 14937e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 149445ca1b86SEd Tanous const std::string& param) { 149545ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 14967e860f15SJohn Edward Broadbent { 149745ca1b86SEd Tanous return; 149845ca1b86SEd Tanous } 14997e860f15SJohn Edward Broadbent std::string entryID = param; 15007e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 15017e860f15SJohn Edward Broadbent 15027e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 15037e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 15047e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 1505b9d36b47SEd Tanous [asyncResp, 1506b9d36b47SEd Tanous entryID](const boost::system::error_code ec, 1507b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 15087e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 15097e860f15SJohn Edward Broadbent { 151045ca1b86SEd Tanous messages::resourceNotFound(asyncResp->res, 151145ca1b86SEd Tanous "EventLogEntry", entryID); 15127e860f15SJohn Edward Broadbent return; 15137e860f15SJohn Edward Broadbent } 15147e860f15SJohn Edward Broadbent if (ec) 15157e860f15SJohn Edward Broadbent { 15160fda0f12SGeorge Liu BMCWEB_LOG_ERROR 15170fda0f12SGeorge Liu << "EventLogEntry (DBus) resp_handler got error " 15187e860f15SJohn Edward Broadbent << ec; 15197e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 15207e860f15SJohn Edward Broadbent return; 15217e860f15SJohn Edward Broadbent } 1522914e2d5dSEd Tanous const uint32_t* id = nullptr; 1523c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1524c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1525914e2d5dSEd Tanous const std::string* severity = nullptr; 1526914e2d5dSEd Tanous const std::string* message = nullptr; 1527914e2d5dSEd Tanous const std::string* filePath = nullptr; 15287e860f15SJohn Edward Broadbent bool resolved = false; 15297e860f15SJohn Edward Broadbent 15309eb808c1SEd Tanous for (const auto& propertyMap : resp) 15317e860f15SJohn Edward Broadbent { 15327e860f15SJohn Edward Broadbent if (propertyMap.first == "Id") 15337e860f15SJohn Edward Broadbent { 15347e860f15SJohn Edward Broadbent id = std::get_if<uint32_t>(&propertyMap.second); 15357e860f15SJohn Edward Broadbent } 15367e860f15SJohn Edward Broadbent else if (propertyMap.first == "Timestamp") 15377e860f15SJohn Edward Broadbent { 1538c419c759SEd Tanous timestamp = 15397e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 1540ebd45906SGeorge Liu } 1541d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1542d139c236SGeorge Liu { 1543ebd45906SGeorge Liu updateTimestamp = 1544c419c759SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 1545ebd45906SGeorge Liu } 1546cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1547cb92c03bSAndrew Geissler { 154845ca1b86SEd Tanous severity = 154945ca1b86SEd Tanous std::get_if<std::string>(&propertyMap.second); 1550cb92c03bSAndrew Geissler } 1551cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1552cb92c03bSAndrew Geissler { 155345ca1b86SEd Tanous message = 155445ca1b86SEd Tanous std::get_if<std::string>(&propertyMap.second); 1555ae34c8e8SAdriana Kobylak } 155675710de2SXiaochao Ma else if (propertyMap.first == "Resolved") 155775710de2SXiaochao Ma { 1558914e2d5dSEd Tanous const bool* resolveptr = 155975710de2SXiaochao Ma std::get_if<bool>(&propertyMap.second); 156075710de2SXiaochao Ma if (resolveptr == nullptr) 156175710de2SXiaochao Ma { 156275710de2SXiaochao Ma messages::internalError(asyncResp->res); 156375710de2SXiaochao Ma return; 156475710de2SXiaochao Ma } 156575710de2SXiaochao Ma resolved = *resolveptr; 156675710de2SXiaochao Ma } 15677e860f15SJohn Edward Broadbent else if (propertyMap.first == "Path") 1568f86bb901SAdriana Kobylak { 156945ca1b86SEd Tanous filePath = 157045ca1b86SEd Tanous std::get_if<std::string>(&propertyMap.second); 1571f86bb901SAdriana Kobylak } 1572f86bb901SAdriana Kobylak } 1573f86bb901SAdriana Kobylak if (id == nullptr || message == nullptr || 1574c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1575c419c759SEd Tanous updateTimestamp == nullptr) 1576f86bb901SAdriana Kobylak { 1577ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1578271584abSEd Tanous return; 1579271584abSEd Tanous } 1580f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 1581f86bb901SAdriana Kobylak "#LogEntry.v1_8_0.LogEntry"; 1582f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.id"] = 15830fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 1584f86bb901SAdriana Kobylak std::to_string(*id); 158545ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Event Log Entry"; 1586f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1587f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1588f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 1589f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1590f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1591f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1592f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 1593c419c759SEd Tanous crow::utility::getDateTimeUintMs(*timestamp); 1594f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 1595c419c759SEd Tanous crow::utility::getDateTimeUintMs(*updateTimestamp); 1596f86bb901SAdriana Kobylak if (filePath != nullptr) 1597f86bb901SAdriana Kobylak { 1598f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 15990fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/attachment/" + 16007e860f15SJohn Edward Broadbent std::to_string(*id); 1601f86bb901SAdriana Kobylak } 1602cb92c03bSAndrew Geissler }, 1603cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1604cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1605f86bb901SAdriana Kobylak "org.freedesktop.DBus.Properties", "GetAll", ""); 16067e860f15SJohn Edward Broadbent }); 1607336e96c6SChicago Duan 16087e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16097e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1610ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 16117e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 161245ca1b86SEd Tanous [&app](const crow::Request& req, 16137e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16147e860f15SJohn Edward Broadbent const std::string& entryId) { 161545ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 161645ca1b86SEd Tanous { 161745ca1b86SEd Tanous return; 161845ca1b86SEd Tanous } 161975710de2SXiaochao Ma std::optional<bool> resolved; 162075710de2SXiaochao Ma 162115ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", 16227e860f15SJohn Edward Broadbent resolved)) 162375710de2SXiaochao Ma { 162475710de2SXiaochao Ma return; 162575710de2SXiaochao Ma } 162675710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 162775710de2SXiaochao Ma 162875710de2SXiaochao Ma crow::connections::systemBus->async_method_call( 16294f48d5f6SEd Tanous [asyncResp, entryId](const boost::system::error_code ec) { 163075710de2SXiaochao Ma if (ec) 163175710de2SXiaochao Ma { 163275710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 163375710de2SXiaochao Ma messages::internalError(asyncResp->res); 163475710de2SXiaochao Ma return; 163575710de2SXiaochao Ma } 163675710de2SXiaochao Ma }, 163775710de2SXiaochao Ma "xyz.openbmc_project.Logging", 163875710de2SXiaochao Ma "/xyz/openbmc_project/logging/entry/" + entryId, 163975710de2SXiaochao Ma "org.freedesktop.DBus.Properties", "Set", 164075710de2SXiaochao Ma "xyz.openbmc_project.Logging.Entry", "Resolved", 1641168e20c1SEd Tanous dbus::utility::DbusVariantType(*resolved)); 16427e860f15SJohn Edward Broadbent }); 164375710de2SXiaochao Ma 16447e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16457e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1646ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1647ed398213SEd Tanous 164845ca1b86SEd Tanous .methods(boost::beast::http::verb:: 164945ca1b86SEd Tanous delete_)([&app](const crow::Request& req, 165045ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& 165145ca1b86SEd Tanous asyncResp, 165245ca1b86SEd Tanous const std::string& param) { 165345ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 1654336e96c6SChicago Duan { 165545ca1b86SEd Tanous return; 165645ca1b86SEd Tanous } 1657336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1658336e96c6SChicago Duan 16597e860f15SJohn Edward Broadbent std::string entryID = param; 1660336e96c6SChicago Duan 1661336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1662336e96c6SChicago Duan 1663336e96c6SChicago Duan // Process response from Logging service. 166445ca1b86SEd Tanous auto respHandler = [asyncResp, 166545ca1b86SEd Tanous entryID](const boost::system::error_code ec) { 16667e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 16677e860f15SJohn Edward Broadbent << "EventLogEntry (DBus) doDelete callback: Done"; 1668336e96c6SChicago Duan if (ec) 1669336e96c6SChicago Duan { 16703de8d8baSGeorge Liu if (ec.value() == EBADR) 16713de8d8baSGeorge Liu { 167245ca1b86SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 167345ca1b86SEd Tanous entryID); 16743de8d8baSGeorge Liu return; 16753de8d8baSGeorge Liu } 1676336e96c6SChicago Duan // TODO Handle for specific error code 16770fda0f12SGeorge Liu BMCWEB_LOG_ERROR 16780fda0f12SGeorge Liu << "EventLogEntry (DBus) doDelete respHandler got error " 1679336e96c6SChicago Duan << ec; 1680336e96c6SChicago Duan asyncResp->res.result( 1681336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1682336e96c6SChicago Duan return; 1683336e96c6SChicago Duan } 1684336e96c6SChicago Duan 1685336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1686336e96c6SChicago Duan }; 1687336e96c6SChicago Duan 1688336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1689336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1690336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1691336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1692336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 16937e860f15SJohn Edward Broadbent }); 1694400fd1fbSAdriana Kobylak } 1695400fd1fbSAdriana Kobylak 16967e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1697400fd1fbSAdriana Kobylak { 16980fda0f12SGeorge Liu BMCWEB_ROUTE( 16990fda0f12SGeorge Liu app, 17000fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/attachment") 1701ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 17027e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 170345ca1b86SEd Tanous [&app](const crow::Request& req, 17047e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 170545ca1b86SEd Tanous const std::string& param) { 170645ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 17077e860f15SJohn Edward Broadbent { 170845ca1b86SEd Tanous return; 170945ca1b86SEd Tanous } 1710647b3cdcSGeorge Liu if (!http_helpers::isOctetAccepted( 1711647b3cdcSGeorge Liu req.getHeaderValue("Accept"))) 1712400fd1fbSAdriana Kobylak { 17137e860f15SJohn Edward Broadbent asyncResp->res.result( 17147e860f15SJohn Edward Broadbent boost::beast::http::status::bad_request); 1715400fd1fbSAdriana Kobylak return; 1716400fd1fbSAdriana Kobylak } 1717400fd1fbSAdriana Kobylak 17187e860f15SJohn Edward Broadbent std::string entryID = param; 1719400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1720400fd1fbSAdriana Kobylak 1721400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 17227e860f15SJohn Edward Broadbent [asyncResp, 17237e860f15SJohn Edward Broadbent entryID](const boost::system::error_code ec, 1724400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 1725400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 1726400fd1fbSAdriana Kobylak { 17277e860f15SJohn Edward Broadbent messages::resourceNotFound( 17287e860f15SJohn Edward Broadbent asyncResp->res, "EventLogAttachment", entryID); 1729400fd1fbSAdriana Kobylak return; 1730400fd1fbSAdriana Kobylak } 1731400fd1fbSAdriana Kobylak if (ec) 1732400fd1fbSAdriana Kobylak { 1733400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1734400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1735400fd1fbSAdriana Kobylak return; 1736400fd1fbSAdriana Kobylak } 1737400fd1fbSAdriana Kobylak 1738400fd1fbSAdriana Kobylak int fd = -1; 1739400fd1fbSAdriana Kobylak fd = dup(unixfd); 1740400fd1fbSAdriana Kobylak if (fd == -1) 1741400fd1fbSAdriana Kobylak { 1742400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1743400fd1fbSAdriana Kobylak return; 1744400fd1fbSAdriana Kobylak } 1745400fd1fbSAdriana Kobylak 1746400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 1747400fd1fbSAdriana Kobylak if (size == -1) 1748400fd1fbSAdriana Kobylak { 1749400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1750400fd1fbSAdriana Kobylak return; 1751400fd1fbSAdriana Kobylak } 1752400fd1fbSAdriana Kobylak 1753400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 1754400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 1755400fd1fbSAdriana Kobylak if (size > maxFileSize) 1756400fd1fbSAdriana Kobylak { 1757400fd1fbSAdriana Kobylak BMCWEB_LOG_ERROR 1758400fd1fbSAdriana Kobylak << "File size exceeds maximum allowed size of " 1759400fd1fbSAdriana Kobylak << maxFileSize; 1760400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1761400fd1fbSAdriana Kobylak return; 1762400fd1fbSAdriana Kobylak } 1763400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 1764400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 1765400fd1fbSAdriana Kobylak if (rc == -1) 1766400fd1fbSAdriana Kobylak { 1767400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1768400fd1fbSAdriana Kobylak return; 1769400fd1fbSAdriana Kobylak } 1770400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 1771400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 1772400fd1fbSAdriana Kobylak { 1773400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1774400fd1fbSAdriana Kobylak return; 1775400fd1fbSAdriana Kobylak } 1776400fd1fbSAdriana Kobylak close(fd); 1777400fd1fbSAdriana Kobylak 1778400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 17797e860f15SJohn Edward Broadbent std::string output = 17807e860f15SJohn Edward Broadbent crow::utility::base64encode(strData); 1781400fd1fbSAdriana Kobylak 1782400fd1fbSAdriana Kobylak asyncResp->res.addHeader("Content-Type", 1783400fd1fbSAdriana Kobylak "application/octet-stream"); 17847e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Transfer-Encoding", 17857e860f15SJohn Edward Broadbent "Base64"); 1786400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 1787400fd1fbSAdriana Kobylak }, 1788400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 1789400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 1790400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 17917e860f15SJohn Edward Broadbent }); 17921da66f75SEd Tanous } 17931da66f75SEd Tanous 1794b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 1795b7028ebfSSpencer Ku 1796b7028ebfSSpencer Ku inline bool 1797b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 1798b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 1799b7028ebfSSpencer Ku { 1800b7028ebfSSpencer Ku std::error_code ec; 1801b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 1802b7028ebfSSpencer Ku if (ec) 1803b7028ebfSSpencer Ku { 1804b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << ec.message(); 1805b7028ebfSSpencer Ku return false; 1806b7028ebfSSpencer Ku } 1807b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 1808b7028ebfSSpencer Ku { 1809b7028ebfSSpencer Ku std::string filename = it.path().filename(); 1810b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 1811b7028ebfSSpencer Ku // path 1812b7028ebfSSpencer Ku if (boost::starts_with(filename, "log")) 1813b7028ebfSSpencer Ku { 1814b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 1815b7028ebfSSpencer Ku } 1816b7028ebfSSpencer Ku } 1817b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 1818b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 1819b7028ebfSSpencer Ku // descending order. 1820b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 1821b7028ebfSSpencer Ku AlphanumLess<std::string>()); 1822b7028ebfSSpencer Ku 1823b7028ebfSSpencer Ku return true; 1824b7028ebfSSpencer Ku } 1825b7028ebfSSpencer Ku 1826b7028ebfSSpencer Ku inline bool 1827b7028ebfSSpencer Ku getHostLoggerEntries(std::vector<std::filesystem::path>& hostLoggerFiles, 1828c937d2bfSEd Tanous uint64_t skip, uint64_t top, 1829b7028ebfSSpencer Ku std::vector<std::string>& logEntries, size_t& logCount) 1830b7028ebfSSpencer Ku { 1831b7028ebfSSpencer Ku GzFileReader logFile; 1832b7028ebfSSpencer Ku 1833b7028ebfSSpencer Ku // Go though all log files and expose host logs. 1834b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 1835b7028ebfSSpencer Ku { 1836b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 1837b7028ebfSSpencer Ku { 1838b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to expose host logs"; 1839b7028ebfSSpencer Ku return false; 1840b7028ebfSSpencer Ku } 1841b7028ebfSSpencer Ku } 1842b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 1843b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 1844b7028ebfSSpencer Ku if (!lastMessage.empty()) 1845b7028ebfSSpencer Ku { 1846b7028ebfSSpencer Ku logCount++; 1847b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 1848b7028ebfSSpencer Ku { 1849b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 1850b7028ebfSSpencer Ku } 1851b7028ebfSSpencer Ku } 1852b7028ebfSSpencer Ku return true; 1853b7028ebfSSpencer Ku } 1854b7028ebfSSpencer Ku 1855b7028ebfSSpencer Ku inline void fillHostLoggerEntryJson(const std::string& logEntryID, 1856b7028ebfSSpencer Ku const std::string& msg, 1857b7028ebfSSpencer Ku nlohmann::json& logEntryJson) 1858b7028ebfSSpencer Ku { 1859b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 1860b7028ebfSSpencer Ku logEntryJson = { 1861b7028ebfSSpencer Ku {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1862b7028ebfSSpencer Ku {"@odata.id", 1863b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/" + 1864b7028ebfSSpencer Ku logEntryID}, 1865b7028ebfSSpencer Ku {"Name", "Host Logger Entry"}, 1866b7028ebfSSpencer Ku {"Id", logEntryID}, 1867b7028ebfSSpencer Ku {"Message", msg}, 1868b7028ebfSSpencer Ku {"EntryType", "Oem"}, 1869b7028ebfSSpencer Ku {"Severity", "OK"}, 1870b7028ebfSSpencer Ku {"OemRecordFormat", "Host Logger Entry"}}; 1871b7028ebfSSpencer Ku } 1872b7028ebfSSpencer Ku 1873b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 1874b7028ebfSSpencer Ku { 1875b7028ebfSSpencer Ku BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/HostLogger/") 1876b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 18771476687dSEd Tanous .methods(boost::beast::http::verb::get)( 18781476687dSEd Tanous [&app](const crow::Request& req, 18791476687dSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 188045ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 188145ca1b86SEd Tanous { 188245ca1b86SEd Tanous return; 188345ca1b86SEd Tanous } 1884b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1885b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"; 1886b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1887b7028ebfSSpencer Ku "#LogService.v1_1_0.LogService"; 1888b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 1889b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 1890b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 18911476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 18921476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 1893b7028ebfSSpencer Ku }); 1894b7028ebfSSpencer Ku } 1895b7028ebfSSpencer Ku 1896b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 1897b7028ebfSSpencer Ku { 1898b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 1899b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/") 1900b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 190145ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 190245ca1b86SEd Tanous const std::shared_ptr< 190345ca1b86SEd Tanous bmcweb::AsyncResp>& 190445ca1b86SEd Tanous asyncResp) { 1905c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1906c937d2bfSEd Tanous .canDelegateTop = true, 1907c937d2bfSEd Tanous .canDelegateSkip = true, 1908c937d2bfSEd Tanous }; 1909c937d2bfSEd Tanous query_param::Query delegatedQuery; 1910c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 1911c937d2bfSEd Tanous app, req, asyncResp->res, delegatedQuery, capabilities)) 1912b7028ebfSSpencer Ku { 1913b7028ebfSSpencer Ku return; 1914b7028ebfSSpencer Ku } 1915b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1916b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 1917b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1918b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 1919b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 1920b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 1921b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 19220fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1923b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 1924b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 1925b7028ebfSSpencer Ku 1926b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 1927b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 1928b7028ebfSSpencer Ku { 1929b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 1930b7028ebfSSpencer Ku return; 1931b7028ebfSSpencer Ku } 1932b7028ebfSSpencer Ku 1933b7028ebfSSpencer Ku size_t logCount = 0; 1934b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 1935b7028ebfSSpencer Ku // control by skip and top. 1936b7028ebfSSpencer Ku std::vector<std::string> logEntries; 1937c937d2bfSEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, delegatedQuery.skip, 1938c937d2bfSEd Tanous delegatedQuery.top, logEntries, logCount)) 1939b7028ebfSSpencer Ku { 1940b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 1941b7028ebfSSpencer Ku return; 1942b7028ebfSSpencer Ku } 1943b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 1944b7028ebfSSpencer Ku // log count 194526f6976fSEd Tanous if (logEntries.empty()) 1946b7028ebfSSpencer Ku { 1947b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 1948b7028ebfSSpencer Ku return; 1949b7028ebfSSpencer Ku } 195026f6976fSEd Tanous if (!logEntries.empty()) 1951b7028ebfSSpencer Ku { 1952b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 1953b7028ebfSSpencer Ku { 1954b7028ebfSSpencer Ku logEntryArray.push_back({}); 1955b7028ebfSSpencer Ku nlohmann::json& hostLogEntry = logEntryArray.back(); 1956c937d2bfSEd Tanous fillHostLoggerEntryJson( 1957c937d2bfSEd Tanous std::to_string(delegatedQuery.skip + i), logEntries[i], 1958c937d2bfSEd Tanous hostLogEntry); 1959b7028ebfSSpencer Ku } 1960b7028ebfSSpencer Ku 1961b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 1962c937d2bfSEd Tanous if (delegatedQuery.skip + delegatedQuery.top < logCount) 1963b7028ebfSSpencer Ku { 1964b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 19650fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/HostLogger/Entries?$skip=" + 1966c937d2bfSEd Tanous std::to_string(delegatedQuery.skip + 1967c937d2bfSEd Tanous delegatedQuery.top); 1968b7028ebfSSpencer Ku } 1969b7028ebfSSpencer Ku } 1970b7028ebfSSpencer Ku }); 1971b7028ebfSSpencer Ku } 1972b7028ebfSSpencer Ku 1973b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 1974b7028ebfSSpencer Ku { 1975b7028ebfSSpencer Ku BMCWEB_ROUTE( 1976b7028ebfSSpencer Ku app, "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/<str>/") 1977b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 1978b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 197945ca1b86SEd Tanous [&app](const crow::Request& req, 1980b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1981b7028ebfSSpencer Ku const std::string& param) { 198245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 198345ca1b86SEd Tanous { 198445ca1b86SEd Tanous return; 198545ca1b86SEd Tanous } 1986b7028ebfSSpencer Ku const std::string& targetID = param; 1987b7028ebfSSpencer Ku 1988b7028ebfSSpencer Ku uint64_t idInt = 0; 1989ca45aa3cSEd Tanous 1990ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 1991ca45aa3cSEd Tanous const char* end = targetID.data() + targetID.size(); 1992ca45aa3cSEd Tanous 1993ca45aa3cSEd Tanous auto [ptr, ec] = std::from_chars(targetID.data(), end, idInt); 1994b7028ebfSSpencer Ku if (ec == std::errc::invalid_argument) 1995b7028ebfSSpencer Ku { 1996ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 1997b7028ebfSSpencer Ku return; 1998b7028ebfSSpencer Ku } 1999b7028ebfSSpencer Ku if (ec == std::errc::result_out_of_range) 2000b7028ebfSSpencer Ku { 2001ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2002b7028ebfSSpencer Ku return; 2003b7028ebfSSpencer Ku } 2004b7028ebfSSpencer Ku 2005b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2006b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2007b7028ebfSSpencer Ku { 2008b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 2009b7028ebfSSpencer Ku return; 2010b7028ebfSSpencer Ku } 2011b7028ebfSSpencer Ku 2012b7028ebfSSpencer Ku size_t logCount = 0; 2013b7028ebfSSpencer Ku uint64_t top = 1; 2014b7028ebfSSpencer Ku std::vector<std::string> logEntries; 2015b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 2016b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 2017b7028ebfSSpencer Ku // get that entry 2018b7028ebfSSpencer Ku if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, 2019b7028ebfSSpencer Ku logEntries, logCount)) 2020b7028ebfSSpencer Ku { 2021b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2022b7028ebfSSpencer Ku return; 2023b7028ebfSSpencer Ku } 2024b7028ebfSSpencer Ku 2025b7028ebfSSpencer Ku if (!logEntries.empty()) 2026b7028ebfSSpencer Ku { 2027b7028ebfSSpencer Ku fillHostLoggerEntryJson(targetID, logEntries[0], 2028b7028ebfSSpencer Ku asyncResp->res.jsonValue); 2029b7028ebfSSpencer Ku return; 2030b7028ebfSSpencer Ku } 2031b7028ebfSSpencer Ku 2032b7028ebfSSpencer Ku // Requested ID was not found 2033ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2034b7028ebfSSpencer Ku }); 2035b7028ebfSSpencer Ku } 2036b7028ebfSSpencer Ku 20377e860f15SJohn Edward Broadbent inline void requestRoutesBMCLogServiceCollection(App& app) 20381da66f75SEd Tanous { 20397e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 2040ad89dcf0SGunnar Mills .privileges(redfish::privileges::getLogServiceCollection) 20417e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 204245ca1b86SEd Tanous [&app](const crow::Request& req, 20437e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 204445ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 204545ca1b86SEd Tanous { 204645ca1b86SEd Tanous return; 204745ca1b86SEd Tanous } 20487e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 20497e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2050e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 20511da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2052e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 2053e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 20547e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 20557e860f15SJohn Edward Broadbent "Open BMC Log Services Collection"; 2056e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 20571da66f75SEd Tanous "Collection of LogServices for this Manager"; 20587e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 20597e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 2060c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 20615cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 20625cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 20637e860f15SJohn Edward Broadbent {{"@odata.id", 20647e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 20655cb1dd27SAsmitha Karunanithi #endif 2066c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 2067c4bf6374SJason M. Bills logServiceArray.push_back( 20687e860f15SJohn Edward Broadbent {{"@odata.id", 20697e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 2070c4bf6374SJason M. Bills #endif 2071e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2072c4bf6374SJason M. Bills logServiceArray.size(); 20737e860f15SJohn Edward Broadbent }); 2074e1f26343SJason M. Bills } 2075e1f26343SJason M. Bills 20767e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 2077e1f26343SJason M. Bills { 20787e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 2079ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 20807e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 208145ca1b86SEd Tanous [&app](const crow::Request& req, 208245ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 208345ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 20847e860f15SJohn Edward Broadbent { 208545ca1b86SEd Tanous return; 208645ca1b86SEd Tanous } 2087e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2088e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 20890f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 20900f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 20917e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 20927e860f15SJohn Edward Broadbent "Open BMC Journal Log Service"; 20937e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 20947e860f15SJohn Edward Broadbent "BMC Journal Log Service"; 2095c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 2096e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 20977c8c4058STejas Patil 20987c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 20997c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 21007c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 21017c8c4058STejas Patil redfishDateTimeOffset.first; 21027c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 21037c8c4058STejas Patil redfishDateTimeOffset.second; 21047c8c4058STejas Patil 21051476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 21061476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 21077e860f15SJohn Edward Broadbent }); 2108e1f26343SJason M. Bills } 2109e1f26343SJason M. Bills 2110c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 2111e1f26343SJason M. Bills sd_journal* journal, 2112c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 2113e1f26343SJason M. Bills { 2114e1f26343SJason M. Bills // Get the Log Entry contents 2115e1f26343SJason M. Bills int ret = 0; 2116e1f26343SJason M. Bills 2117a8fe54f0SJason M. Bills std::string message; 2118a8fe54f0SJason M. Bills std::string_view syslogID; 2119a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 2120a8fe54f0SJason M. Bills if (ret < 0) 2121a8fe54f0SJason M. Bills { 2122a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 2123a8fe54f0SJason M. Bills << strerror(-ret); 2124a8fe54f0SJason M. Bills } 2125a8fe54f0SJason M. Bills if (!syslogID.empty()) 2126a8fe54f0SJason M. Bills { 2127a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 2128a8fe54f0SJason M. Bills } 2129a8fe54f0SJason M. Bills 213039e77504SEd Tanous std::string_view msg; 213116428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 2132e1f26343SJason M. Bills if (ret < 0) 2133e1f26343SJason M. Bills { 2134e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 2135e1f26343SJason M. Bills return 1; 2136e1f26343SJason M. Bills } 2137a8fe54f0SJason M. Bills message += std::string(msg); 2138e1f26343SJason M. Bills 2139e1f26343SJason M. Bills // Get the severity from the PRIORITY field 2140271584abSEd Tanous long int severity = 8; // Default to an invalid priority 214116428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 2142e1f26343SJason M. Bills if (ret < 0) 2143e1f26343SJason M. Bills { 2144e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 2145e1f26343SJason M. Bills } 2146e1f26343SJason M. Bills 2147e1f26343SJason M. Bills // Get the Created time from the timestamp 214816428a1aSJason M. Bills std::string entryTimeStr; 214916428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 2150e1f26343SJason M. Bills { 215116428a1aSJason M. Bills return 1; 2152e1f26343SJason M. Bills } 2153e1f26343SJason M. Bills 2154e1f26343SJason M. Bills // Fill in the log entry with the gathered data 2155c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 2156647b3cdcSGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 2157c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 2158c4bf6374SJason M. Bills bmcJournalLogEntryID}, 2159e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 2160c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 2161a8fe54f0SJason M. Bills {"Message", std::move(message)}, 2162e1f26343SJason M. Bills {"EntryType", "Oem"}, 2163738c1e61SPatrick Williams {"Severity", severity <= 2 ? "Critical" 2164738c1e61SPatrick Williams : severity <= 4 ? "Warning" 2165738c1e61SPatrick Williams : "OK"}, 2166086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 2167e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 2168e1f26343SJason M. Bills return 0; 2169e1f26343SJason M. Bills } 2170e1f26343SJason M. Bills 21717e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 2172e1f26343SJason M. Bills { 21737e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 2174ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 217545ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 217645ca1b86SEd Tanous const std::shared_ptr< 217745ca1b86SEd Tanous bmcweb::AsyncResp>& 217845ca1b86SEd Tanous asyncResp) { 2179c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2180c937d2bfSEd Tanous .canDelegateTop = true, 2181c937d2bfSEd Tanous .canDelegateSkip = true, 2182c937d2bfSEd Tanous }; 2183c937d2bfSEd Tanous query_param::Query delegatedQuery; 2184c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 2185c937d2bfSEd Tanous app, req, asyncResp->res, delegatedQuery, capabilities)) 2186193ad2faSJason M. Bills { 2187193ad2faSJason M. Bills return; 2188193ad2faSJason M. Bills } 21897e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 21907e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2191e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2192e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 21930f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 21940f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 2195e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 2196e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2197e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 21980fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2199e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2200e1f26343SJason M. Bills 22017e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 22027e860f15SJohn Edward Broadbent // unique ID for each entry 2203e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2204e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2205e1f26343SJason M. Bills if (ret < 0) 2206e1f26343SJason M. Bills { 22077e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 22087e860f15SJohn Edward Broadbent << strerror(-ret); 2209f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2210e1f26343SJason M. Bills return; 2211e1f26343SJason M. Bills } 22120fda0f12SGeorge Liu std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 22130fda0f12SGeorge Liu journalTmp, sd_journal_close); 2214e1f26343SJason M. Bills journalTmp = nullptr; 2215b01bf299SEd Tanous uint64_t entryCount = 0; 2216e85d6b16SJason M. Bills // Reset the unique ID on the first entry 2217e85d6b16SJason M. Bills bool firstEntry = true; 2218e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 2219e1f26343SJason M. Bills { 2220193ad2faSJason M. Bills entryCount++; 22217e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 22227e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 2223c937d2bfSEd Tanous if (entryCount <= delegatedQuery.skip || 2224c937d2bfSEd Tanous entryCount > delegatedQuery.skip + delegatedQuery.top) 2225193ad2faSJason M. Bills { 2226193ad2faSJason M. Bills continue; 2227193ad2faSJason M. Bills } 2228193ad2faSJason M. Bills 222916428a1aSJason M. Bills std::string idStr; 2230e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2231e1f26343SJason M. Bills { 2232e1f26343SJason M. Bills continue; 2233e1f26343SJason M. Bills } 2234e1f26343SJason M. Bills 2235e85d6b16SJason M. Bills if (firstEntry) 2236e85d6b16SJason M. Bills { 2237e85d6b16SJason M. Bills firstEntry = false; 2238e85d6b16SJason M. Bills } 2239e85d6b16SJason M. Bills 2240e1f26343SJason M. Bills logEntryArray.push_back({}); 2241c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 2242c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 2243c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 2244e1f26343SJason M. Bills { 2245f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2246e1f26343SJason M. Bills return; 2247e1f26343SJason M. Bills } 2248e1f26343SJason M. Bills } 2249193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 2250c937d2bfSEd Tanous if (delegatedQuery.skip + delegatedQuery.top < entryCount) 2251193ad2faSJason M. Bills { 2252193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 22530fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 2254c937d2bfSEd Tanous std::to_string(delegatedQuery.skip + delegatedQuery.top); 2255193ad2faSJason M. Bills } 22567e860f15SJohn Edward Broadbent }); 2257e1f26343SJason M. Bills } 2258e1f26343SJason M. Bills 22597e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 2260e1f26343SJason M. Bills { 22617e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 22627e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 2263ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 22647e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 226545ca1b86SEd Tanous [&app](const crow::Request& req, 22667e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22677e860f15SJohn Edward Broadbent const std::string& entryID) { 226845ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 226945ca1b86SEd Tanous { 227045ca1b86SEd Tanous return; 227145ca1b86SEd Tanous } 2272e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2273e1f26343SJason M. Bills uint64_t ts = 0; 2274271584abSEd Tanous uint64_t index = 0; 22758d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2276e1f26343SJason M. Bills { 227716428a1aSJason M. Bills return; 2278e1f26343SJason M. Bills } 2279e1f26343SJason M. Bills 2280e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2281e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2282e1f26343SJason M. Bills if (ret < 0) 2283e1f26343SJason M. Bills { 22847e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 22857e860f15SJohn Edward Broadbent << strerror(-ret); 2286f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2287e1f26343SJason M. Bills return; 2288e1f26343SJason M. Bills } 22897e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 22907e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 2291e1f26343SJason M. Bills journalTmp = nullptr; 22927e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 22937e860f15SJohn Edward Broadbent // index tracking the unique ID 2294af07e3f5SJason M. Bills std::string idStr; 2295af07e3f5SJason M. Bills bool firstEntry = true; 2296e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 22972056b6d1SManojkiran Eda if (ret < 0) 22982056b6d1SManojkiran Eda { 22992056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 23002056b6d1SManojkiran Eda << strerror(-ret); 23012056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 23022056b6d1SManojkiran Eda return; 23032056b6d1SManojkiran Eda } 2304271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2305e1f26343SJason M. Bills { 2306e1f26343SJason M. Bills sd_journal_next(journal.get()); 2307af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2308af07e3f5SJason M. Bills { 2309af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2310af07e3f5SJason M. Bills return; 2311af07e3f5SJason M. Bills } 2312af07e3f5SJason M. Bills if (firstEntry) 2313af07e3f5SJason M. Bills { 2314af07e3f5SJason M. Bills firstEntry = false; 2315af07e3f5SJason M. Bills } 2316e1f26343SJason M. Bills } 2317c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2318af07e3f5SJason M. Bills if (idStr != entryID) 2319c4bf6374SJason M. Bills { 2320ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2321c4bf6374SJason M. Bills return; 2322c4bf6374SJason M. Bills } 2323c4bf6374SJason M. Bills 2324c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 2325e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 2326e1f26343SJason M. Bills { 2327f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2328e1f26343SJason M. Bills return; 2329e1f26343SJason M. Bills } 23307e860f15SJohn Edward Broadbent }); 2331c9bb6861Sraviteja-b } 2332c9bb6861Sraviteja-b 23337e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpService(App& app) 2334c9bb6861Sraviteja-b { 23357e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2336ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 233745ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 233845ca1b86SEd Tanous const std::shared_ptr< 233945ca1b86SEd Tanous bmcweb::AsyncResp>& 234045ca1b86SEd Tanous asyncResp) { 234145ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 234245ca1b86SEd Tanous { 234345ca1b86SEd Tanous return; 234445ca1b86SEd Tanous } 2345c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 23465cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 2347c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2348d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 2349c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 23505cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 23515cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2352c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 23537c8c4058STejas Patil 23547c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 23557c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 23560fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 23577c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 23587c8c4058STejas Patil redfishDateTimeOffset.second; 23597c8c4058STejas Patil 23601476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 23611476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 23621476687dSEd Tanous asyncResp->res 23631476687dSEd Tanous .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 23641476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog"; 23651476687dSEd Tanous asyncResp->res 23661476687dSEd Tanous .jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 23671476687dSEd Tanous ["target"] = 23681476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData"; 23697e860f15SJohn Edward Broadbent }); 2370c9bb6861Sraviteja-b } 2371c9bb6861Sraviteja-b 23727e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntryCollection(App& app) 23737e860f15SJohn Edward Broadbent { 23747e860f15SJohn Edward Broadbent 2375c9bb6861Sraviteja-b /** 2376c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2377c9bb6861Sraviteja-b */ 23787e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2379ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 23807e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 238145ca1b86SEd Tanous [&app](const crow::Request& req, 23827e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 238345ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 238445ca1b86SEd Tanous { 238545ca1b86SEd Tanous return; 238645ca1b86SEd Tanous } 2387c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2388c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2389c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 23905cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 23915cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2392c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 23935cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2394c9bb6861Sraviteja-b 23955cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 23967e860f15SJohn Edward Broadbent }); 2397c9bb6861Sraviteja-b } 2398c9bb6861Sraviteja-b 23997e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2400c9bb6861Sraviteja-b { 24017e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24027e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2403ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 24047e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 240545ca1b86SEd Tanous [&app](const crow::Request& req, 24067e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24077e860f15SJohn Edward Broadbent const std::string& param) { 240845ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 240945ca1b86SEd Tanous { 241045ca1b86SEd Tanous return; 241145ca1b86SEd Tanous } 241245ca1b86SEd Tanous 241345ca1b86SEd Tanous getDumpEntryById(app, req, asyncResp, param, "BMC"); 24147e860f15SJohn Edward Broadbent }); 24157e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24167e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2417ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 24187e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 241945ca1b86SEd Tanous [&app](const crow::Request& req, 24207e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24217e860f15SJohn Edward Broadbent const std::string& param) { 242245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 242345ca1b86SEd Tanous { 242445ca1b86SEd Tanous return; 242545ca1b86SEd Tanous } 24267e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "bmc"); 24277e860f15SJohn Edward Broadbent }); 2428c9bb6861Sraviteja-b } 2429c9bb6861Sraviteja-b 24307e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2431c9bb6861Sraviteja-b { 24320fda0f12SGeorge Liu BMCWEB_ROUTE( 24330fda0f12SGeorge Liu app, 24340fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2435ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 24367e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 243745ca1b86SEd Tanous [&app](const crow::Request& req, 24387e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 243945ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 244045ca1b86SEd Tanous { 244145ca1b86SEd Tanous return; 244245ca1b86SEd Tanous } 24438d1b46d7Szhanghch05 createDump(asyncResp, req, "BMC"); 24447e860f15SJohn Edward Broadbent }); 2445a43be80fSAsmitha Karunanithi } 2446a43be80fSAsmitha Karunanithi 24477e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 244880319af1SAsmitha Karunanithi { 24490fda0f12SGeorge Liu BMCWEB_ROUTE( 24500fda0f12SGeorge Liu app, 24510fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog/") 2452ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 24537e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 245445ca1b86SEd Tanous [&app](const crow::Request& req, 24557e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 245645ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 245745ca1b86SEd Tanous { 245845ca1b86SEd Tanous return; 245945ca1b86SEd Tanous } 24608d1b46d7Szhanghch05 clearDump(asyncResp, "BMC"); 24617e860f15SJohn Edward Broadbent }); 24625cb1dd27SAsmitha Karunanithi } 24635cb1dd27SAsmitha Karunanithi 24647e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 24655cb1dd27SAsmitha Karunanithi { 24667e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/") 2467ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 246845ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 246945ca1b86SEd Tanous const std::shared_ptr< 247045ca1b86SEd Tanous bmcweb::AsyncResp>& 247145ca1b86SEd Tanous asyncResp) { 247245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 24737e860f15SJohn Edward Broadbent { 247445ca1b86SEd Tanous return; 247545ca1b86SEd Tanous } 24765cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 24775cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 24785cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2479d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 24805cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 248145ca1b86SEd Tanous asyncResp->res.jsonValue["Description"] = "System Dump LogService"; 24825cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 24835cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 24847c8c4058STejas Patil 24857c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 24867c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 248745ca1b86SEd Tanous asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 24887c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 24897c8c4058STejas Patil redfishDateTimeOffset.second; 24907c8c4058STejas Patil 24911476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 24921476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 24931476687dSEd Tanous asyncResp->res 24941476687dSEd Tanous .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 24951476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog"; 24961476687dSEd Tanous 24971476687dSEd Tanous asyncResp->res 24981476687dSEd Tanous .jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 24991476687dSEd Tanous ["target"] = 25001476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData"; 25017e860f15SJohn Edward Broadbent }); 25025cb1dd27SAsmitha Karunanithi } 25035cb1dd27SAsmitha Karunanithi 25047e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 25057e860f15SJohn Edward Broadbent { 25067e860f15SJohn Edward Broadbent 25075cb1dd27SAsmitha Karunanithi /** 25085cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 25095cb1dd27SAsmitha Karunanithi */ 2510b2a3289dSAsmitha Karunanithi BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 2511ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 25127e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 251345ca1b86SEd Tanous [&app](const crow::Request& req, 2514864d6a17SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 251545ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 251645ca1b86SEd Tanous { 251745ca1b86SEd Tanous return; 251845ca1b86SEd Tanous } 25195cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 25205cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 25215cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 25225cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 25235cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 25245cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 25255cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 25265cb1dd27SAsmitha Karunanithi 25275cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 25287e860f15SJohn Edward Broadbent }); 25295cb1dd27SAsmitha Karunanithi } 25305cb1dd27SAsmitha Karunanithi 25317e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 25325cb1dd27SAsmitha Karunanithi { 25337e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2534864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2535ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2536ed398213SEd Tanous 25377e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 253845ca1b86SEd Tanous [&app](const crow::Request& req, 25397e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25407e860f15SJohn Edward Broadbent const std::string& param) { 254145ca1b86SEd Tanous getDumpEntryById(app, req, asyncResp, param, "System"); 25427e860f15SJohn Edward Broadbent }); 25438d1b46d7Szhanghch05 25447e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2545864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2546ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 25477e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 254845ca1b86SEd Tanous [&app](const crow::Request& req, 25497e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25507e860f15SJohn Edward Broadbent const std::string& param) { 255145ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 255245ca1b86SEd Tanous { 255345ca1b86SEd Tanous return; 255445ca1b86SEd Tanous } 25557e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "system"); 25567e860f15SJohn Edward Broadbent }); 25575cb1dd27SAsmitha Karunanithi } 2558c9bb6861Sraviteja-b 25597e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2560c9bb6861Sraviteja-b { 25610fda0f12SGeorge Liu BMCWEB_ROUTE( 25620fda0f12SGeorge Liu app, 25630fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2564ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 25657e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 256645ca1b86SEd Tanous [&app](const crow::Request& req, 256745ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 256845ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 256945ca1b86SEd Tanous { 257045ca1b86SEd Tanous return; 257145ca1b86SEd Tanous } 257245ca1b86SEd Tanous createDump(asyncResp, req, "System"); 257345ca1b86SEd Tanous }); 2574a43be80fSAsmitha Karunanithi } 2575a43be80fSAsmitha Karunanithi 25767e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2577a43be80fSAsmitha Karunanithi { 25780fda0f12SGeorge Liu BMCWEB_ROUTE( 25790fda0f12SGeorge Liu app, 25800fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog/") 2581ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 25827e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 258345ca1b86SEd Tanous [&app](const crow::Request& req, 25847e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 25857e860f15SJohn Edward Broadbent 258645ca1b86SEd Tanous { 258745ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 258845ca1b86SEd Tanous { 258945ca1b86SEd Tanous return; 259045ca1b86SEd Tanous } 259145ca1b86SEd Tanous clearDump(asyncResp, "System"); 259245ca1b86SEd Tanous }); 2593013487e5Sraviteja-b } 2594013487e5Sraviteja-b 25957e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 25961da66f75SEd Tanous { 25973946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25983946028dSAppaRao Puli // method for security reasons. 25991da66f75SEd Tanous /** 26001da66f75SEd Tanous * Functions triggers appropriate requests on DBus 26011da66f75SEd Tanous */ 26027e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 2603ed398213SEd Tanous // This is incorrect, should be: 2604ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2605432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 260645ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 260745ca1b86SEd Tanous const std::shared_ptr< 260845ca1b86SEd Tanous bmcweb::AsyncResp>& 260945ca1b86SEd Tanous asyncResp) { 261045ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 261145ca1b86SEd Tanous { 261245ca1b86SEd Tanous return; 261345ca1b86SEd Tanous } 26147e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 26157e860f15SJohn Edward Broadbent // SubRoute 26160f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2617424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2618e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 26198e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 26204f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 26214f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 26224f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2623e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2624e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 26257c8c4058STejas Patil 26267c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 26277c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 26287c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 26297c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 26307c8c4058STejas Patil redfishDateTimeOffset.second; 26317c8c4058STejas Patil 26321476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 26331476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 26341476687dSEd Tanous asyncResp->res 26351476687dSEd Tanous .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 26361476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog"; 26371476687dSEd Tanous asyncResp->res 26381476687dSEd Tanous .jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 26391476687dSEd Tanous ["target"] = 26401476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData"; 26417e860f15SJohn Edward Broadbent }); 26421da66f75SEd Tanous } 26431da66f75SEd Tanous 26447e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 26455b61b5e8SJason M. Bills { 26460fda0f12SGeorge Liu BMCWEB_ROUTE( 26470fda0f12SGeorge Liu app, 26480fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog/") 2649ed398213SEd Tanous // This is incorrect, should be: 2650ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2651432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 26527e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 265345ca1b86SEd Tanous [&app](const crow::Request& req, 26547e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 265545ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 265645ca1b86SEd Tanous { 265745ca1b86SEd Tanous return; 265845ca1b86SEd Tanous } 26595b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 26605b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2661cb13a392SEd Tanous const std::string&) { 26625b61b5e8SJason M. Bills if (ec) 26635b61b5e8SJason M. Bills { 26645b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 26655b61b5e8SJason M. Bills return; 26665b61b5e8SJason M. Bills } 26675b61b5e8SJason M. Bills messages::success(asyncResp->res); 26685b61b5e8SJason M. Bills }, 26697e860f15SJohn Edward Broadbent crashdumpObject, crashdumpPath, deleteAllInterface, 26707e860f15SJohn Edward Broadbent "DeleteAll"); 26717e860f15SJohn Edward Broadbent }); 26725b61b5e8SJason M. Bills } 26735b61b5e8SJason M. Bills 26748d1b46d7Szhanghch05 static void 26758d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26768d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 2677e855dd28SJason M. Bills { 2678043a0536SJohnathan Mantey auto getStoredLogCallback = 2679b9d36b47SEd Tanous [asyncResp, logID, 2680b9d36b47SEd Tanous &logEntryJson](const boost::system::error_code ec, 2681b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& params) { 2682e855dd28SJason M. Bills if (ec) 2683e855dd28SJason M. Bills { 2684e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 26851ddcf01aSJason M. Bills if (ec.value() == 26861ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 26871ddcf01aSJason M. Bills { 2688043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2689043a0536SJohnathan Mantey logID); 26901ddcf01aSJason M. Bills } 26911ddcf01aSJason M. Bills else 26921ddcf01aSJason M. Bills { 2693e855dd28SJason M. Bills messages::internalError(asyncResp->res); 26941ddcf01aSJason M. Bills } 2695e855dd28SJason M. Bills return; 2696e855dd28SJason M. Bills } 2697043a0536SJohnathan Mantey 2698043a0536SJohnathan Mantey std::string timestamp{}; 2699043a0536SJohnathan Mantey std::string filename{}; 2700043a0536SJohnathan Mantey std::string logfile{}; 27012c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2702043a0536SJohnathan Mantey 2703043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2704e855dd28SJason M. Bills { 2705ace85d60SEd Tanous messages::resourceMissingAtURI( 2706ace85d60SEd Tanous asyncResp->res, crow::utility::urlFromPieces(logID)); 2707e855dd28SJason M. Bills return; 2708e855dd28SJason M. Bills } 2709e855dd28SJason M. Bills 2710043a0536SJohnathan Mantey std::string crashdumpURI = 2711e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2712043a0536SJohnathan Mantey logID + "/" + filename; 27132b20ef6eSJason M. Bills nlohmann::json logEntry = { 27144978b63fSJason M. Bills {"@odata.type", "#LogEntry.v1_7_0.LogEntry"}, 27154978b63fSJason M. Bills {"@odata.id", 27164978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2717e855dd28SJason M. Bills logID}, 2718e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2719e855dd28SJason M. Bills {"Id", logID}, 2720e855dd28SJason M. Bills {"EntryType", "Oem"}, 27218e6c099aSJason M. Bills {"AdditionalDataURI", std::move(crashdumpURI)}, 27228e6c099aSJason M. Bills {"DiagnosticDataType", "OEM"}, 27238e6c099aSJason M. Bills {"OEMDiagnosticDataType", "PECICrashdump"}, 2724043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 27252b20ef6eSJason M. Bills 27262b20ef6eSJason M. Bills // If logEntryJson references an array of LogEntry resources 27272b20ef6eSJason M. Bills // ('Members' list), then push this as a new entry, otherwise set it 27282b20ef6eSJason M. Bills // directly 27292b20ef6eSJason M. Bills if (logEntryJson.is_array()) 27302b20ef6eSJason M. Bills { 27312b20ef6eSJason M. Bills logEntryJson.push_back(logEntry); 27322b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 27332b20ef6eSJason M. Bills logEntryJson.size(); 27342b20ef6eSJason M. Bills } 27352b20ef6eSJason M. Bills else 27362b20ef6eSJason M. Bills { 27372b20ef6eSJason M. Bills logEntryJson = logEntry; 27382b20ef6eSJason M. Bills } 2739e855dd28SJason M. Bills }; 2740e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 27415b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 27425b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2743043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2744e855dd28SJason M. Bills } 2745e855dd28SJason M. Bills 27467e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 27471da66f75SEd Tanous { 27483946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 27493946028dSAppaRao Puli // method for security reasons. 27501da66f75SEd Tanous /** 27511da66f75SEd Tanous * Functions triggers appropriate requests on DBus 27521da66f75SEd Tanous */ 27537e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 27547e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 2755ed398213SEd Tanous // This is incorrect, should be. 2756ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 2757432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 275845ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 275945ca1b86SEd Tanous const std::shared_ptr< 276045ca1b86SEd Tanous bmcweb::AsyncResp>& 276145ca1b86SEd Tanous asyncResp) { 276245ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 276345ca1b86SEd Tanous { 276445ca1b86SEd Tanous return; 276545ca1b86SEd Tanous } 27662b20ef6eSJason M. Bills crow::connections::systemBus->async_method_call( 27672b20ef6eSJason M. Bills [asyncResp](const boost::system::error_code ec, 27682b20ef6eSJason M. Bills const std::vector<std::string>& resp) { 27691da66f75SEd Tanous if (ec) 27701da66f75SEd Tanous { 27711da66f75SEd Tanous if (ec.value() != 27721da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 27731da66f75SEd Tanous { 27741da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 27751da66f75SEd Tanous << ec.message(); 2776f12894f8SJason M. Bills messages::internalError(asyncResp->res); 27771da66f75SEd Tanous return; 27781da66f75SEd Tanous } 27791da66f75SEd Tanous } 2780e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 27811da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 27820f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2783424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 27842b20ef6eSJason M. Bills asyncResp->res.jsonValue["Name"] = 27852b20ef6eSJason M. Bills "Open BMC Crashdump Entries"; 2786e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2787424c4176SJason M. Bills "Collection of Crashdump Entries"; 27882b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"] = 27892b20ef6eSJason M. Bills nlohmann::json::array(); 2790a2dd60a6SBrandon Kim asyncResp->res.jsonValue["Members@odata.count"] = 0; 27912b20ef6eSJason M. Bills 27922b20ef6eSJason M. Bills for (const std::string& path : resp) 27931da66f75SEd Tanous { 27942b20ef6eSJason M. Bills const sdbusplus::message::object_path objPath(path); 2795e855dd28SJason M. Bills // Get the log ID 27962b20ef6eSJason M. Bills std::string logID = objPath.filename(); 27972b20ef6eSJason M. Bills if (logID.empty()) 27981da66f75SEd Tanous { 2799e855dd28SJason M. Bills continue; 28001da66f75SEd Tanous } 2801e855dd28SJason M. Bills // Add the log entry to the array 28022b20ef6eSJason M. Bills logCrashdumpEntry(asyncResp, logID, 28032b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"]); 28041da66f75SEd Tanous } 28052b20ef6eSJason M. Bills }, 28061da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 28071da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 28081da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 28095b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 28107e860f15SJohn Edward Broadbent }); 28111da66f75SEd Tanous } 28121da66f75SEd Tanous 28137e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 28141da66f75SEd Tanous { 28153946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28163946028dSAppaRao Puli // method for security reasons. 28171da66f75SEd Tanous 28187e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 28197e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/") 2820ed398213SEd Tanous // this is incorrect, should be 2821ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 2822432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 28237e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 282445ca1b86SEd Tanous [&app](const crow::Request& req, 28257e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 28267e860f15SJohn Edward Broadbent const std::string& param) { 282745ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 282845ca1b86SEd Tanous { 282945ca1b86SEd Tanous return; 283045ca1b86SEd Tanous } 28317e860f15SJohn Edward Broadbent const std::string& logID = param; 2832e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 28337e860f15SJohn Edward Broadbent }); 2834e855dd28SJason M. Bills } 2835e855dd28SJason M. Bills 28367e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 2837e855dd28SJason M. Bills { 28383946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28393946028dSAppaRao Puli // method for security reasons. 28407e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 28417e860f15SJohn Edward Broadbent app, 28427e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/") 2843ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 28447e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 284545ca1b86SEd Tanous [&app](const crow::Request& req, 28467e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 28477e860f15SJohn Edward Broadbent const std::string& logID, const std::string& fileName) { 284845ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 284945ca1b86SEd Tanous { 285045ca1b86SEd Tanous return; 285145ca1b86SEd Tanous } 2852043a0536SJohnathan Mantey auto getStoredLogCallback = 2853ace85d60SEd Tanous [asyncResp, logID, fileName, 2854ace85d60SEd Tanous url(boost::urls::url(req.urlView))]( 2855abf2add6SEd Tanous const boost::system::error_code ec, 2856168e20c1SEd Tanous const std::vector<std::pair< 2857168e20c1SEd Tanous std::string, dbus::utility::DbusVariantType>>& 28587e860f15SJohn Edward Broadbent resp) { 28591da66f75SEd Tanous if (ec) 28601da66f75SEd Tanous { 2861043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2862043a0536SJohnathan Mantey << ec.message(); 2863f12894f8SJason M. Bills messages::internalError(asyncResp->res); 28641da66f75SEd Tanous return; 28651da66f75SEd Tanous } 2866e855dd28SJason M. Bills 2867043a0536SJohnathan Mantey std::string dbusFilename{}; 2868043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2869043a0536SJohnathan Mantey std::string dbusFilepath{}; 2870043a0536SJohnathan Mantey 28717e860f15SJohn Edward Broadbent parseCrashdumpParameters(resp, dbusFilename, 28727e860f15SJohn Edward Broadbent dbusTimestamp, dbusFilepath); 2873043a0536SJohnathan Mantey 2874043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2875043a0536SJohnathan Mantey dbusFilepath.empty()) 28761da66f75SEd Tanous { 2877ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 28781da66f75SEd Tanous return; 28791da66f75SEd Tanous } 2880e855dd28SJason M. Bills 2881043a0536SJohnathan Mantey // Verify the file name parameter is correct 2882043a0536SJohnathan Mantey if (fileName != dbusFilename) 2883043a0536SJohnathan Mantey { 2884ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 2885043a0536SJohnathan Mantey return; 2886043a0536SJohnathan Mantey } 2887043a0536SJohnathan Mantey 2888043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2889043a0536SJohnathan Mantey { 2890ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 2891043a0536SJohnathan Mantey return; 2892043a0536SJohnathan Mantey } 28932d31491bSJason M. Bills std::ifstream ifs(dbusFilepath, 28942d31491bSJason M. Bills std::ios::in | std::ios::binary); 28952d31491bSJason M. Bills asyncResp->res.body() = std::string( 28962d31491bSJason M. Bills std::istreambuf_iterator<char>{ifs}, {}); 2897043a0536SJohnathan Mantey 28987e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 28997e860f15SJohn Edward Broadbent // from a browser 29007e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Disposition", 29017e860f15SJohn Edward Broadbent "attachment"); 29021da66f75SEd Tanous }; 29031da66f75SEd Tanous crow::connections::systemBus->async_method_call( 29045b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 29055b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 29067e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 29077e860f15SJohn Edward Broadbent crashdumpInterface); 29087e860f15SJohn Edward Broadbent }); 29091da66f75SEd Tanous } 29101da66f75SEd Tanous 2911c5a4c82aSJason M. Bills enum class OEMDiagnosticType 2912c5a4c82aSJason M. Bills { 2913c5a4c82aSJason M. Bills onDemand, 2914c5a4c82aSJason M. Bills telemetry, 2915c5a4c82aSJason M. Bills invalid, 2916c5a4c82aSJason M. Bills }; 2917c5a4c82aSJason M. Bills 2918f7725d79SEd Tanous inline OEMDiagnosticType 2919f7725d79SEd Tanous getOEMDiagnosticType(const std::string_view& oemDiagStr) 2920c5a4c82aSJason M. Bills { 2921c5a4c82aSJason M. Bills if (oemDiagStr == "OnDemand") 2922c5a4c82aSJason M. Bills { 2923c5a4c82aSJason M. Bills return OEMDiagnosticType::onDemand; 2924c5a4c82aSJason M. Bills } 2925c5a4c82aSJason M. Bills if (oemDiagStr == "Telemetry") 2926c5a4c82aSJason M. Bills { 2927c5a4c82aSJason M. Bills return OEMDiagnosticType::telemetry; 2928c5a4c82aSJason M. Bills } 2929c5a4c82aSJason M. Bills 2930c5a4c82aSJason M. Bills return OEMDiagnosticType::invalid; 2931c5a4c82aSJason M. Bills } 2932c5a4c82aSJason M. Bills 29337e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 29341da66f75SEd Tanous { 29353946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 29363946028dSAppaRao Puli // method for security reasons. 29370fda0f12SGeorge Liu BMCWEB_ROUTE( 29380fda0f12SGeorge Liu app, 29390fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") 2940ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 2941ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2942432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 29437e860f15SJohn Edward Broadbent .methods( 29447e860f15SJohn Edward Broadbent boost::beast::http::verb:: 294545ca1b86SEd Tanous post)([&app]( 294645ca1b86SEd Tanous const crow::Request& req, 29477e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 294845ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 294945ca1b86SEd Tanous { 295045ca1b86SEd Tanous return; 295145ca1b86SEd Tanous } 29528e6c099aSJason M. Bills std::string diagnosticDataType; 29538e6c099aSJason M. Bills std::string oemDiagnosticDataType; 295415ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 29557e860f15SJohn Edward Broadbent req, asyncResp->res, "DiagnosticDataType", 29567e860f15SJohn Edward Broadbent diagnosticDataType, "OEMDiagnosticDataType", 29577e860f15SJohn Edward Broadbent oemDiagnosticDataType)) 29588e6c099aSJason M. Bills { 29598e6c099aSJason M. Bills return; 29608e6c099aSJason M. Bills } 29618e6c099aSJason M. Bills 29628e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 29638e6c099aSJason M. Bills { 29648e6c099aSJason M. Bills BMCWEB_LOG_ERROR 29658e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 29668e6c099aSJason M. Bills messages::actionParameterValueFormatError( 29678e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 29688e6c099aSJason M. Bills "CollectDiagnosticData"); 29698e6c099aSJason M. Bills return; 29708e6c099aSJason M. Bills } 29718e6c099aSJason M. Bills 2972c5a4c82aSJason M. Bills OEMDiagnosticType oemDiagType = 2973c5a4c82aSJason M. Bills getOEMDiagnosticType(oemDiagnosticDataType); 2974c5a4c82aSJason M. Bills 2975c5a4c82aSJason M. Bills std::string iface; 2976c5a4c82aSJason M. Bills std::string method; 2977c5a4c82aSJason M. Bills std::string taskMatchStr; 2978c5a4c82aSJason M. Bills if (oemDiagType == OEMDiagnosticType::onDemand) 2979c5a4c82aSJason M. Bills { 2980c5a4c82aSJason M. Bills iface = crashdumpOnDemandInterface; 2981c5a4c82aSJason M. Bills method = "GenerateOnDemandLog"; 2982c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 2983c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 2984c5a4c82aSJason M. Bills "member='PropertiesChanged'," 2985c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 2986c5a4c82aSJason M. Bills } 2987c5a4c82aSJason M. Bills else if (oemDiagType == OEMDiagnosticType::telemetry) 2988c5a4c82aSJason M. Bills { 2989c5a4c82aSJason M. Bills iface = crashdumpTelemetryInterface; 2990c5a4c82aSJason M. Bills method = "GenerateTelemetryLog"; 2991c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 2992c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 2993c5a4c82aSJason M. Bills "member='PropertiesChanged'," 2994c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 2995c5a4c82aSJason M. Bills } 2996c5a4c82aSJason M. Bills else 2997c5a4c82aSJason M. Bills { 2998c5a4c82aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 2999c5a4c82aSJason M. Bills << oemDiagnosticDataType; 3000c5a4c82aSJason M. Bills messages::actionParameterValueFormatError( 3001c5a4c82aSJason M. Bills asyncResp->res, oemDiagnosticDataType, 3002c5a4c82aSJason M. Bills "OEMDiagnosticDataType", "CollectDiagnosticData"); 3003c5a4c82aSJason M. Bills return; 3004c5a4c82aSJason M. Bills } 3005c5a4c82aSJason M. Bills 3006c5a4c82aSJason M. Bills auto collectCrashdumpCallback = 3007c5a4c82aSJason M. Bills [asyncResp, payload(task::Payload(req)), 3008c5a4c82aSJason M. Bills taskMatchStr](const boost::system::error_code ec, 300998be3e39SEd Tanous const std::string&) mutable { 30101da66f75SEd Tanous if (ec) 30111da66f75SEd Tanous { 30127e860f15SJohn Edward Broadbent if (ec.value() == 30137e860f15SJohn Edward Broadbent boost::system::errc::operation_not_supported) 30141da66f75SEd Tanous { 3015f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 30161da66f75SEd Tanous } 30174363d3b2SJason M. Bills else if (ec.value() == 30184363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 30194363d3b2SJason M. Bills { 3020c5a4c82aSJason M. Bills messages::serviceTemporarilyUnavailable( 3021c5a4c82aSJason M. Bills asyncResp->res, "60"); 30224363d3b2SJason M. Bills } 30231da66f75SEd Tanous else 30241da66f75SEd Tanous { 3025f12894f8SJason M. Bills messages::internalError(asyncResp->res); 30261da66f75SEd Tanous } 30271da66f75SEd Tanous return; 30281da66f75SEd Tanous } 3029c5a4c82aSJason M. Bills std::shared_ptr<task::TaskData> task = 3030c5a4c82aSJason M. Bills task::TaskData::createTask( 30317e860f15SJohn Edward Broadbent [](boost::system::error_code err, 30327e860f15SJohn Edward Broadbent sdbusplus::message::message&, 3033c5a4c82aSJason M. Bills const std::shared_ptr<task::TaskData>& 3034c5a4c82aSJason M. Bills taskData) { 303566afe4faSJames Feist if (!err) 303666afe4faSJames Feist { 3037e5d5006bSJames Feist taskData->messages.emplace_back( 3038e5d5006bSJames Feist messages::taskCompletedOK( 3039e5d5006bSJames Feist std::to_string(taskData->index))); 3040831d6b09SJames Feist taskData->state = "Completed"; 304166afe4faSJames Feist } 304232898ceaSJames Feist return task::completed; 304366afe4faSJames Feist }, 3044c5a4c82aSJason M. Bills taskMatchStr); 3045c5a4c82aSJason M. Bills 304646229577SJames Feist task->startTimer(std::chrono::minutes(5)); 304746229577SJames Feist task->populateResp(asyncResp->res); 304898be3e39SEd Tanous task->payload.emplace(std::move(payload)); 30491da66f75SEd Tanous }; 30508e6c099aSJason M. Bills 30511da66f75SEd Tanous crow::connections::systemBus->async_method_call( 30528e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 3053c5a4c82aSJason M. Bills crashdumpPath, iface, method); 30547e860f15SJohn Edward Broadbent }); 30556eda7685SKenny L. Ku } 30566eda7685SKenny L. Ku 3057cb92c03bSAndrew Geissler /** 3058cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 3059cb92c03bSAndrew Geissler */ 30607e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 3061cb92c03bSAndrew Geissler { 3062cb92c03bSAndrew Geissler /** 3063cb92c03bSAndrew Geissler * Function handles POST method request. 3064cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3065cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3066cb92c03bSAndrew Geissler */ 30677e860f15SJohn Edward Broadbent 30680fda0f12SGeorge Liu BMCWEB_ROUTE( 30690fda0f12SGeorge Liu app, 30700fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/") 3071ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 30727e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 307345ca1b86SEd Tanous [&app](const crow::Request& req, 30747e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 307545ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 307645ca1b86SEd Tanous { 307745ca1b86SEd Tanous return; 307845ca1b86SEd Tanous } 3079cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 3080cb92c03bSAndrew Geissler 3081cb92c03bSAndrew Geissler // Process response from Logging service. 30827e860f15SJohn Edward Broadbent auto respHandler = [asyncResp]( 30837e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 30847e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 30857e860f15SJohn Edward Broadbent << "doClearLog resp_handler callback: Done"; 3086cb92c03bSAndrew Geissler if (ec) 3087cb92c03bSAndrew Geissler { 3088cb92c03bSAndrew Geissler // TODO Handle for specific error code 30897e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " 30907e860f15SJohn Edward Broadbent << ec; 3091cb92c03bSAndrew Geissler asyncResp->res.result( 3092cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3093cb92c03bSAndrew Geissler return; 3094cb92c03bSAndrew Geissler } 3095cb92c03bSAndrew Geissler 30967e860f15SJohn Edward Broadbent asyncResp->res.result( 30977e860f15SJohn Edward Broadbent boost::beast::http::status::no_content); 3098cb92c03bSAndrew Geissler }; 3099cb92c03bSAndrew Geissler 3100cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3101cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 31022c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 3103cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3104cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 31057e860f15SJohn Edward Broadbent }); 3106cb92c03bSAndrew Geissler } 3107a3316fc6SZhikuiRen 3108a3316fc6SZhikuiRen /**************************************************** 3109a3316fc6SZhikuiRen * Redfish PostCode interfaces 3110a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3111a3316fc6SZhikuiRen ******************************************************/ 31127e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 3113a3316fc6SZhikuiRen { 31147e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 3115ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 311645ca1b86SEd Tanous .methods(boost::beast::http::verb::get)([&app](const crow::Request& req, 311745ca1b86SEd Tanous const std::shared_ptr< 311845ca1b86SEd Tanous bmcweb::AsyncResp>& 311945ca1b86SEd Tanous asyncResp) { 312045ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 312145ca1b86SEd Tanous { 312245ca1b86SEd Tanous return; 312345ca1b86SEd Tanous } 31241476687dSEd Tanous 31251476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 31261476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes"; 31271476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 31281476687dSEd Tanous "#LogService.v1_1_0.LogService"; 31291476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "POST Code Log Service"; 31301476687dSEd Tanous asyncResp->res.jsonValue["Description"] = "POST Code Log Service"; 31311476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "BIOS POST Code Log"; 31321476687dSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 31331476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 31341476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 31357c8c4058STejas Patil 31367c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 31377c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 31380fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 31397c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 31407c8c4058STejas Patil redfishDateTimeOffset.second; 31417c8c4058STejas Patil 3142a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 31437e860f15SJohn Edward Broadbent {"target", 31440fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog"}}; 31457e860f15SJohn Edward Broadbent }); 3146a3316fc6SZhikuiRen } 3147a3316fc6SZhikuiRen 31487e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3149a3316fc6SZhikuiRen { 31500fda0f12SGeorge Liu BMCWEB_ROUTE( 31510fda0f12SGeorge Liu app, 31520fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog/") 3153ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3154ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3155432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 31567e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 315745ca1b86SEd Tanous [&app](const crow::Request& req, 31587e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 315945ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 316045ca1b86SEd Tanous { 316145ca1b86SEd Tanous return; 316245ca1b86SEd Tanous } 3163a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3164a3316fc6SZhikuiRen 3165a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3166a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3167a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3168a3316fc6SZhikuiRen if (ec) 3169a3316fc6SZhikuiRen { 3170a3316fc6SZhikuiRen // TODO Handle for specific error code 3171a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 31727e860f15SJohn Edward Broadbent << "doClearPostCodes resp_handler got error " 31737e860f15SJohn Edward Broadbent << ec; 31747e860f15SJohn Edward Broadbent asyncResp->res.result(boost::beast::http::status:: 31757e860f15SJohn Edward Broadbent internal_server_error); 3176a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3177a3316fc6SZhikuiRen return; 3178a3316fc6SZhikuiRen } 3179a3316fc6SZhikuiRen }, 318015124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 318115124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3182a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 31837e860f15SJohn Edward Broadbent }); 3184a3316fc6SZhikuiRen } 3185a3316fc6SZhikuiRen 3186a3316fc6SZhikuiRen static void fillPostCodeEntry( 31878d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 31886c9a279eSManojkiran Eda const boost::container::flat_map< 31896c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3190a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3191a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3192a3316fc6SZhikuiRen { 3193a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3194fffb8c1fSEd Tanous const registries::Message* message = 3195fffb8c1fSEd Tanous registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3196a3316fc6SZhikuiRen 3197a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3198a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 3199a3316fc6SZhikuiRen 3200a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 32016c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 32026c9a279eSManojkiran Eda code : postcode) 3203a3316fc6SZhikuiRen { 3204a3316fc6SZhikuiRen currentCodeIndex++; 3205a3316fc6SZhikuiRen std::string postcodeEntryID = 3206a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3207a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3208a3316fc6SZhikuiRen 3209a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3210a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3211a3316fc6SZhikuiRen 3212a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3213a3316fc6SZhikuiRen { // already incremented 3214a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3215a3316fc6SZhikuiRen } 3216a3316fc6SZhikuiRen else 3217a3316fc6SZhikuiRen { 3218a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3219a3316fc6SZhikuiRen } 3220a3316fc6SZhikuiRen 3221a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3222a3316fc6SZhikuiRen // not fall between top and skip 3223a3316fc6SZhikuiRen if ((codeIndex == 0) && 3224a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3225a3316fc6SZhikuiRen { 3226a3316fc6SZhikuiRen continue; 3227a3316fc6SZhikuiRen } 3228a3316fc6SZhikuiRen 32294e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3230a3316fc6SZhikuiRen // currentIndex 3231a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3232a3316fc6SZhikuiRen { 3233a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3234a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3235a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3236a3316fc6SZhikuiRen continue; 3237a3316fc6SZhikuiRen } 3238a3316fc6SZhikuiRen 3239a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3240a3316fc6SZhikuiRen // index 3241a3316fc6SZhikuiRen 3242a3316fc6SZhikuiRen // Get the Created time from the timestamp 3243a3316fc6SZhikuiRen std::string entryTimeStr; 32441d8782e7SNan Zhou entryTimeStr = 32451d8782e7SNan Zhou crow::utility::getDateTimeUint(usecSinceEpoch / 1000 / 1000); 3246a3316fc6SZhikuiRen 3247a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3248a3316fc6SZhikuiRen std::ostringstream hexCode; 3249a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 32506c9a279eSManojkiran Eda << std::get<0>(code.second); 3251a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3252a3316fc6SZhikuiRen // Set Fixed -Point Notation 3253a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3254a3316fc6SZhikuiRen // Set precision to 4 digits 3255a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3256a3316fc6SZhikuiRen // Add double to stream 3257a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3258a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3259a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3260a3316fc6SZhikuiRen 3261a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3262a3316fc6SZhikuiRen std::string msg; 3263a3316fc6SZhikuiRen if (message != nullptr) 3264a3316fc6SZhikuiRen { 3265a3316fc6SZhikuiRen msg = message->message; 3266a3316fc6SZhikuiRen 3267a3316fc6SZhikuiRen // fill in this post code value 3268a3316fc6SZhikuiRen int i = 0; 3269a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3270a3316fc6SZhikuiRen { 3271a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3272a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3273a3316fc6SZhikuiRen if (argPos != std::string::npos) 3274a3316fc6SZhikuiRen { 3275a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3276a3316fc6SZhikuiRen } 3277a3316fc6SZhikuiRen } 3278a3316fc6SZhikuiRen } 3279a3316fc6SZhikuiRen 3280d4342a92STim Lee // Get Severity template from message registry 3281d4342a92STim Lee std::string severity; 3282d4342a92STim Lee if (message != nullptr) 3283d4342a92STim Lee { 32845f2b84eeSEd Tanous severity = message->messageSeverity; 3285d4342a92STim Lee } 3286d4342a92STim Lee 3287a3316fc6SZhikuiRen // add to AsyncResp 3288a3316fc6SZhikuiRen logEntryArray.push_back({}); 3289a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 32900fda0f12SGeorge Liu bmcLogEntry = { 32910fda0f12SGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 32920fda0f12SGeorge Liu {"@odata.id", 32930fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3294a3316fc6SZhikuiRen postcodeEntryID}, 3295a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 3296a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 3297a3316fc6SZhikuiRen {"Message", std::move(msg)}, 32984a0bf539SManojkiran Eda {"MessageId", "OpenBMC.0.2.BIOSPOSTCode"}, 3299a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 3300a3316fc6SZhikuiRen {"EntryType", "Event"}, 3301a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 33029c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 3303647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 3304647b3cdcSGeorge Liu { 3305647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 3306647b3cdcSGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3307647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 3308647b3cdcSGeorge Liu } 3309a3316fc6SZhikuiRen } 3310a3316fc6SZhikuiRen } 3311a3316fc6SZhikuiRen 33128d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3313a3316fc6SZhikuiRen const uint16_t bootIndex, 3314a3316fc6SZhikuiRen const uint64_t codeIndex) 3315a3316fc6SZhikuiRen { 3316a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 33176c9a279eSManojkiran Eda [aResp, bootIndex, 33186c9a279eSManojkiran Eda codeIndex](const boost::system::error_code ec, 33196c9a279eSManojkiran Eda const boost::container::flat_map< 33206c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 33216c9a279eSManojkiran Eda postcode) { 3322a3316fc6SZhikuiRen if (ec) 3323a3316fc6SZhikuiRen { 3324a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3325a3316fc6SZhikuiRen messages::internalError(aResp->res); 3326a3316fc6SZhikuiRen return; 3327a3316fc6SZhikuiRen } 3328a3316fc6SZhikuiRen 3329a3316fc6SZhikuiRen // skip the empty postcode boots 3330a3316fc6SZhikuiRen if (postcode.empty()) 3331a3316fc6SZhikuiRen { 3332a3316fc6SZhikuiRen return; 3333a3316fc6SZhikuiRen } 3334a3316fc6SZhikuiRen 3335a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3336a3316fc6SZhikuiRen 3337a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3338a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3339a3316fc6SZhikuiRen }, 334015124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 334115124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3342a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3343a3316fc6SZhikuiRen bootIndex); 3344a3316fc6SZhikuiRen } 3345a3316fc6SZhikuiRen 33468d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3347a3316fc6SZhikuiRen const uint16_t bootIndex, 3348a3316fc6SZhikuiRen const uint16_t bootCount, 3349a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 3350a3316fc6SZhikuiRen const uint64_t top) 3351a3316fc6SZhikuiRen { 3352a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3353a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3354a3316fc6SZhikuiRen top](const boost::system::error_code ec, 33556c9a279eSManojkiran Eda const boost::container::flat_map< 33566c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 33576c9a279eSManojkiran Eda postcode) { 3358a3316fc6SZhikuiRen if (ec) 3359a3316fc6SZhikuiRen { 3360a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3361a3316fc6SZhikuiRen messages::internalError(aResp->res); 3362a3316fc6SZhikuiRen return; 3363a3316fc6SZhikuiRen } 3364a3316fc6SZhikuiRen 3365a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3366a3316fc6SZhikuiRen if (!postcode.empty()) 3367a3316fc6SZhikuiRen { 3368a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 3369a3316fc6SZhikuiRen 3370a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3371a3316fc6SZhikuiRen { 3372a3316fc6SZhikuiRen uint64_t thisBootSkip = 3373a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3374a3316fc6SZhikuiRen uint64_t thisBootTop = 3375a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3376a3316fc6SZhikuiRen 3377a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3378a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3379a3316fc6SZhikuiRen } 3380a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3381a3316fc6SZhikuiRen } 3382a3316fc6SZhikuiRen 3383a3316fc6SZhikuiRen // continue to previous bootIndex 3384a3316fc6SZhikuiRen if (bootIndex < bootCount) 3385a3316fc6SZhikuiRen { 3386a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3387a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3388a3316fc6SZhikuiRen } 3389a3316fc6SZhikuiRen else 3390a3316fc6SZhikuiRen { 3391a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 33920fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries?$skip=" + 3393a3316fc6SZhikuiRen std::to_string(skip + top); 3394a3316fc6SZhikuiRen } 3395a3316fc6SZhikuiRen }, 339615124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 339715124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3398a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3399a3316fc6SZhikuiRen bootIndex); 3400a3316fc6SZhikuiRen } 3401a3316fc6SZhikuiRen 34028d1b46d7Szhanghch05 static void 34038d1b46d7Szhanghch05 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3404a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3405a3316fc6SZhikuiRen { 3406a3316fc6SZhikuiRen uint64_t entryCount = 0; 34071e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint16_t>( 34081e1e598dSJonathan Doman *crow::connections::systemBus, 34091e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 34101e1e598dSJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 34111e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", 34121e1e598dSJonathan Doman [aResp, entryCount, skip, top](const boost::system::error_code ec, 34131e1e598dSJonathan Doman const uint16_t bootCount) { 3414a3316fc6SZhikuiRen if (ec) 3415a3316fc6SZhikuiRen { 3416a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3417a3316fc6SZhikuiRen messages::internalError(aResp->res); 3418a3316fc6SZhikuiRen return; 3419a3316fc6SZhikuiRen } 34201e1e598dSJonathan Doman getPostCodeForBoot(aResp, 1, bootCount, entryCount, skip, top); 34211e1e598dSJonathan Doman }); 3422a3316fc6SZhikuiRen } 3423a3316fc6SZhikuiRen 34247e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3425a3316fc6SZhikuiRen { 34267e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 34277e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3428ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 34297e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 343045ca1b86SEd Tanous [&app](const crow::Request& req, 34317e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3432c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 3433c937d2bfSEd Tanous .canDelegateTop = true, 3434c937d2bfSEd Tanous .canDelegateSkip = true, 3435c937d2bfSEd Tanous }; 3436c937d2bfSEd Tanous query_param::Query delegatedQuery; 3437c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 3438c937d2bfSEd Tanous app, req, asyncResp->res, delegatedQuery, capabilities)) 343945ca1b86SEd Tanous { 344045ca1b86SEd Tanous return; 344145ca1b86SEd Tanous } 3442a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3443a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3444a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3445a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3446a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3447a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3448a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3449a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3450a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3451a3316fc6SZhikuiRen 3452c937d2bfSEd Tanous getCurrentBootNumber(asyncResp, delegatedQuery.skip, 3453c937d2bfSEd Tanous delegatedQuery.top); 34547e860f15SJohn Edward Broadbent }); 3455a3316fc6SZhikuiRen } 3456a3316fc6SZhikuiRen 3457647b3cdcSGeorge Liu /** 3458647b3cdcSGeorge Liu * @brief Parse post code ID and get the current value and index value 3459647b3cdcSGeorge Liu * eg: postCodeID=B1-2, currentValue=1, index=2 3460647b3cdcSGeorge Liu * 3461647b3cdcSGeorge Liu * @param[in] postCodeID Post Code ID 3462647b3cdcSGeorge Liu * @param[out] currentValue Current value 3463647b3cdcSGeorge Liu * @param[out] index Index value 3464647b3cdcSGeorge Liu * 3465647b3cdcSGeorge Liu * @return bool true if the parsing is successful, false the parsing fails 3466647b3cdcSGeorge Liu */ 3467647b3cdcSGeorge Liu inline static bool parsePostCode(const std::string& postCodeID, 3468647b3cdcSGeorge Liu uint64_t& currentValue, uint16_t& index) 3469647b3cdcSGeorge Liu { 3470647b3cdcSGeorge Liu std::vector<std::string> split; 3471647b3cdcSGeorge Liu boost::algorithm::split(split, postCodeID, boost::is_any_of("-")); 3472647b3cdcSGeorge Liu if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B') 3473647b3cdcSGeorge Liu { 3474647b3cdcSGeorge Liu return false; 3475647b3cdcSGeorge Liu } 3476647b3cdcSGeorge Liu 3477ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3478647b3cdcSGeorge Liu const char* start = split[0].data() + 1; 3479ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3480647b3cdcSGeorge Liu const char* end = split[0].data() + split[0].size(); 3481647b3cdcSGeorge Liu auto [ptrIndex, ecIndex] = std::from_chars(start, end, index); 3482647b3cdcSGeorge Liu 3483647b3cdcSGeorge Liu if (ptrIndex != end || ecIndex != std::errc()) 3484647b3cdcSGeorge Liu { 3485647b3cdcSGeorge Liu return false; 3486647b3cdcSGeorge Liu } 3487647b3cdcSGeorge Liu 3488647b3cdcSGeorge Liu start = split[1].data(); 3489ca45aa3cSEd Tanous 3490ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3491647b3cdcSGeorge Liu end = split[1].data() + split[1].size(); 3492647b3cdcSGeorge Liu auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue); 3493647b3cdcSGeorge Liu 3494dcf2ebc0SEd Tanous return ptrValue == end && ecValue != std::errc(); 3495647b3cdcSGeorge Liu } 3496647b3cdcSGeorge Liu 3497647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3498647b3cdcSGeorge Liu { 34990fda0f12SGeorge Liu BMCWEB_ROUTE( 35000fda0f12SGeorge Liu app, 35010fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/attachment/") 3502647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 3503647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 350445ca1b86SEd Tanous [&app](const crow::Request& req, 3505647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3506647b3cdcSGeorge Liu const std::string& postCodeID) { 350745ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 350845ca1b86SEd Tanous { 350945ca1b86SEd Tanous return; 351045ca1b86SEd Tanous } 3511647b3cdcSGeorge Liu if (!http_helpers::isOctetAccepted( 3512647b3cdcSGeorge Liu req.getHeaderValue("Accept"))) 3513647b3cdcSGeorge Liu { 3514647b3cdcSGeorge Liu asyncResp->res.result( 3515647b3cdcSGeorge Liu boost::beast::http::status::bad_request); 3516647b3cdcSGeorge Liu return; 3517647b3cdcSGeorge Liu } 3518647b3cdcSGeorge Liu 3519647b3cdcSGeorge Liu uint64_t currentValue = 0; 3520647b3cdcSGeorge Liu uint16_t index = 0; 3521647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 3522647b3cdcSGeorge Liu { 3523647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", 3524647b3cdcSGeorge Liu postCodeID); 3525647b3cdcSGeorge Liu return; 3526647b3cdcSGeorge Liu } 3527647b3cdcSGeorge Liu 3528647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 3529647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 3530647b3cdcSGeorge Liu const boost::system::error_code ec, 3531647b3cdcSGeorge Liu const std::vector<std::tuple< 3532647b3cdcSGeorge Liu uint64_t, std::vector<uint8_t>>>& postcodes) { 3533647b3cdcSGeorge Liu if (ec.value() == EBADR) 3534647b3cdcSGeorge Liu { 3535647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3536647b3cdcSGeorge Liu "LogEntry", postCodeID); 3537647b3cdcSGeorge Liu return; 3538647b3cdcSGeorge Liu } 3539647b3cdcSGeorge Liu if (ec) 3540647b3cdcSGeorge Liu { 3541647b3cdcSGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3542647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 3543647b3cdcSGeorge Liu return; 3544647b3cdcSGeorge Liu } 3545647b3cdcSGeorge Liu 3546647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 3547647b3cdcSGeorge Liu if (value == std::string::npos || 3548647b3cdcSGeorge Liu postcodes.size() < currentValue) 3549647b3cdcSGeorge Liu { 3550647b3cdcSGeorge Liu BMCWEB_LOG_ERROR << "Wrong currentValue value"; 3551647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3552647b3cdcSGeorge Liu "LogEntry", postCodeID); 3553647b3cdcSGeorge Liu return; 3554647b3cdcSGeorge Liu } 3555647b3cdcSGeorge Liu 35569eb808c1SEd Tanous const auto& [tID, c] = postcodes[value]; 355746ff87baSEd Tanous if (c.empty()) 3558647b3cdcSGeorge Liu { 3559647b3cdcSGeorge Liu BMCWEB_LOG_INFO << "No found post code data"; 3560647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3561647b3cdcSGeorge Liu "LogEntry", postCodeID); 3562647b3cdcSGeorge Liu return; 3563647b3cdcSGeorge Liu } 356446ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 356546ff87baSEd Tanous const char* d = reinterpret_cast<const char*>(c.data()); 356646ff87baSEd Tanous std::string_view strData(d, c.size()); 3567647b3cdcSGeorge Liu 3568647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Type", 3569647b3cdcSGeorge Liu "application/octet-stream"); 3570647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Transfer-Encoding", 3571647b3cdcSGeorge Liu "Base64"); 3572647b3cdcSGeorge Liu asyncResp->res.body() = 3573647b3cdcSGeorge Liu crow::utility::base64encode(strData); 3574647b3cdcSGeorge Liu }, 3575647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 3576647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 3577647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", 3578647b3cdcSGeorge Liu index); 3579647b3cdcSGeorge Liu }); 3580647b3cdcSGeorge Liu } 3581647b3cdcSGeorge Liu 35827e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 3583a3316fc6SZhikuiRen { 35847e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 35857e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/") 3586ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 35877e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 358845ca1b86SEd Tanous [&app](const crow::Request& req, 35897e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 35907e860f15SJohn Edward Broadbent const std::string& targetID) { 359145ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 359245ca1b86SEd Tanous { 359345ca1b86SEd Tanous return; 359445ca1b86SEd Tanous } 3595647b3cdcSGeorge Liu uint16_t bootIndex = 0; 3596647b3cdcSGeorge Liu uint64_t codeIndex = 0; 3597647b3cdcSGeorge Liu if (!parsePostCode(targetID, codeIndex, bootIndex)) 3598a3316fc6SZhikuiRen { 3599a3316fc6SZhikuiRen // Requested ID was not found 3600ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 3601a3316fc6SZhikuiRen return; 3602a3316fc6SZhikuiRen } 3603a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3604a3316fc6SZhikuiRen { 3605a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 36067e860f15SJohn Edward Broadbent << targetID; 3607a3316fc6SZhikuiRen } 3608a3316fc6SZhikuiRen 36097e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = 36107e860f15SJohn Edward Broadbent "#LogEntry.v1_4_0.LogEntry"; 3611a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 36120fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3613a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3614a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3615a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3616a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3617a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3618a3316fc6SZhikuiRen 3619a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 36207e860f15SJohn Edward Broadbent }); 3621a3316fc6SZhikuiRen } 3622a3316fc6SZhikuiRen 36231da66f75SEd Tanous } // namespace redfish 3624