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> 309896eaedSEd Tanous #include <boost/algorithm/string/case_conv.hpp> 3111ba3979SEd Tanous #include <boost/algorithm/string/classification.hpp> 32400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 334851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 3407c8c20dSEd Tanous #include <boost/beast/http/verb.hpp> 351da66f75SEd Tanous #include <boost/container/flat_map.hpp> 361ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 37168e20c1SEd Tanous #include <dbus_utility.hpp> 38cb92c03bSAndrew Geissler #include <error_messages.hpp> 3945ca1b86SEd Tanous #include <query.hpp> 40ed398213SEd Tanous #include <registries/privilege_registry.hpp> 41*2b82937eSEd Tanous #include <utils/time_utils.hpp> 421214b7e7SGunnar Mills 43647b3cdcSGeorge Liu #include <charconv> 444418c7f0SJames Feist #include <filesystem> 4575710de2SXiaochao Ma #include <optional> 4626702d01SEd Tanous #include <span> 47cd225da8SJason M. Bills #include <string_view> 48abf2add6SEd Tanous #include <variant> 491da66f75SEd Tanous 501da66f75SEd Tanous namespace redfish 511da66f75SEd Tanous { 521da66f75SEd Tanous 535b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 545b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 555b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 565b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 575b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 585b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 59424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 606eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 616eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 621da66f75SEd Tanous 63fffb8c1fSEd Tanous namespace registries 644851d45dSJason M. Bills { 6526702d01SEd Tanous static const Message* 6626702d01SEd Tanous getMessageFromRegistry(const std::string& messageKey, 6726702d01SEd Tanous const std::span<const MessageEntry> registry) 684851d45dSJason M. Bills { 69002d39b4SEd Tanous std::span<const MessageEntry>::iterator messageIt = 70002d39b4SEd Tanous std::find_if(registry.begin(), registry.end(), 714851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 72e662eae8SEd Tanous return std::strcmp(messageEntry.first, messageKey.c_str()) == 0; 734851d45dSJason M. Bills }); 7426702d01SEd Tanous if (messageIt != registry.end()) 754851d45dSJason M. Bills { 764851d45dSJason M. Bills return &messageIt->second; 774851d45dSJason M. Bills } 784851d45dSJason M. Bills 794851d45dSJason M. Bills return nullptr; 804851d45dSJason M. Bills } 814851d45dSJason M. Bills 824851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 834851d45dSJason M. Bills { 844851d45dSJason M. Bills // Redfish MessageIds are in the form 854851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 864851d45dSJason M. Bills // the right Message 874851d45dSJason M. Bills std::vector<std::string> fields; 884851d45dSJason M. Bills fields.reserve(4); 894851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 9002cad96eSEd Tanous const std::string& registryName = fields[0]; 9102cad96eSEd Tanous const std::string& messageKey = fields[3]; 924851d45dSJason M. Bills 934851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 944851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 954851d45dSJason M. Bills { 964851d45dSJason M. Bills return getMessageFromRegistry( 9726702d01SEd Tanous messageKey, std::span<const MessageEntry>(base::registry)); 984851d45dSJason M. Bills } 994851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 1004851d45dSJason M. Bills { 1014851d45dSJason M. Bills return getMessageFromRegistry( 10226702d01SEd Tanous messageKey, std::span<const MessageEntry>(openbmc::registry)); 1034851d45dSJason M. Bills } 1044851d45dSJason M. Bills return nullptr; 1054851d45dSJason M. Bills } 106fffb8c1fSEd Tanous } // namespace registries 1074851d45dSJason M. Bills 108f6150403SJames Feist namespace fs = std::filesystem; 1091da66f75SEd Tanous 110cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 111cb92c03bSAndrew Geissler { 112d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 113d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 114d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 115d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 116cb92c03bSAndrew Geissler { 117cb92c03bSAndrew Geissler return "Critical"; 118cb92c03bSAndrew Geissler } 1193174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 120d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 121d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 122cb92c03bSAndrew Geissler { 123cb92c03bSAndrew Geissler return "OK"; 124cb92c03bSAndrew Geissler } 1253174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 126cb92c03bSAndrew Geissler { 127cb92c03bSAndrew Geissler return "Warning"; 128cb92c03bSAndrew Geissler } 129cb92c03bSAndrew Geissler return ""; 130cb92c03bSAndrew Geissler } 131cb92c03bSAndrew Geissler 1327e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 13339e77504SEd Tanous const std::string_view& field, 13439e77504SEd Tanous std::string_view& contents) 13516428a1aSJason M. Bills { 13616428a1aSJason M. Bills const char* data = nullptr; 13716428a1aSJason M. Bills size_t length = 0; 13816428a1aSJason M. Bills int ret = 0; 13916428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 14046ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 14146ff87baSEd Tanous const void** dataVoid = reinterpret_cast<const void**>(&data); 14246ff87baSEd Tanous 14346ff87baSEd Tanous ret = sd_journal_get_data(journal, field.data(), dataVoid, &length); 14416428a1aSJason M. Bills if (ret < 0) 14516428a1aSJason M. Bills { 14616428a1aSJason M. Bills return ret; 14716428a1aSJason M. Bills } 14839e77504SEd Tanous contents = std::string_view(data, length); 14916428a1aSJason M. Bills // Only use the content after the "=" character. 15081ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 15116428a1aSJason M. Bills return ret; 15216428a1aSJason M. Bills } 15316428a1aSJason M. Bills 1547e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 1557e860f15SJohn Edward Broadbent const std::string_view& field, 1567e860f15SJohn Edward Broadbent const int& base, long int& contents) 15716428a1aSJason M. Bills { 15816428a1aSJason M. Bills int ret = 0; 15939e77504SEd Tanous std::string_view metadata; 16016428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 16116428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 16216428a1aSJason M. Bills if (ret < 0) 16316428a1aSJason M. Bills { 16416428a1aSJason M. Bills return ret; 16516428a1aSJason M. Bills } 166b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 16716428a1aSJason M. Bills return ret; 16816428a1aSJason M. Bills } 16916428a1aSJason M. Bills 1707e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1717e860f15SJohn Edward Broadbent std::string& entryTimestamp) 172a3316fc6SZhikuiRen { 173a3316fc6SZhikuiRen int ret = 0; 174a3316fc6SZhikuiRen uint64_t timestamp = 0; 175a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 176a3316fc6SZhikuiRen if (ret < 0) 177a3316fc6SZhikuiRen { 178a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 179a3316fc6SZhikuiRen << strerror(-ret); 180a3316fc6SZhikuiRen return false; 181a3316fc6SZhikuiRen } 182*2b82937eSEd Tanous entryTimestamp = 183*2b82937eSEd Tanous redfish::time_utils::getDateTimeUint(timestamp / 1000 / 1000); 1849c620e21SAsmitha Karunanithi return true; 185a3316fc6SZhikuiRen } 18650b8a43aSEd Tanous 1877e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 188e85d6b16SJason M. Bills const bool firstEntry = true) 18916428a1aSJason M. Bills { 19016428a1aSJason M. Bills int ret = 0; 19116428a1aSJason M. Bills static uint64_t prevTs = 0; 19216428a1aSJason M. Bills static int index = 0; 193e85d6b16SJason M. Bills if (firstEntry) 194e85d6b16SJason M. Bills { 195e85d6b16SJason M. Bills prevTs = 0; 196e85d6b16SJason M. Bills } 197e85d6b16SJason M. Bills 19816428a1aSJason M. Bills // Get the entry timestamp 19916428a1aSJason M. Bills uint64_t curTs = 0; 20016428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 20116428a1aSJason M. Bills if (ret < 0) 20216428a1aSJason M. Bills { 20316428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 20416428a1aSJason M. Bills << strerror(-ret); 20516428a1aSJason M. Bills return false; 20616428a1aSJason M. Bills } 20716428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 20816428a1aSJason M. Bills if (curTs == prevTs) 20916428a1aSJason M. Bills { 21016428a1aSJason M. Bills index++; 21116428a1aSJason M. Bills } 21216428a1aSJason M. Bills else 21316428a1aSJason M. Bills { 21416428a1aSJason M. Bills // Otherwise, reset it 21516428a1aSJason M. Bills index = 0; 21616428a1aSJason M. Bills } 21716428a1aSJason M. Bills // Save the timestamp 21816428a1aSJason M. Bills prevTs = curTs; 21916428a1aSJason M. Bills 22016428a1aSJason M. Bills entryID = std::to_string(curTs); 22116428a1aSJason M. Bills if (index > 0) 22216428a1aSJason M. Bills { 22316428a1aSJason M. Bills entryID += "_" + std::to_string(index); 22416428a1aSJason M. Bills } 22516428a1aSJason M. Bills return true; 22616428a1aSJason M. Bills } 22716428a1aSJason M. Bills 228e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 229e85d6b16SJason M. Bills const bool firstEntry = true) 23095820184SJason M. Bills { 231271584abSEd Tanous static time_t prevTs = 0; 23295820184SJason M. Bills static int index = 0; 233e85d6b16SJason M. Bills if (firstEntry) 234e85d6b16SJason M. Bills { 235e85d6b16SJason M. Bills prevTs = 0; 236e85d6b16SJason M. Bills } 237e85d6b16SJason M. Bills 23895820184SJason M. Bills // Get the entry timestamp 239271584abSEd Tanous std::time_t curTs = 0; 24095820184SJason M. Bills std::tm timeStruct = {}; 24195820184SJason M. Bills std::istringstream entryStream(logEntry); 24295820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 24395820184SJason M. Bills { 24495820184SJason M. Bills curTs = std::mktime(&timeStruct); 24595820184SJason M. Bills } 24695820184SJason M. Bills // If the timestamp isn't unique, increment the index 24795820184SJason M. Bills if (curTs == prevTs) 24895820184SJason M. Bills { 24995820184SJason M. Bills index++; 25095820184SJason M. Bills } 25195820184SJason M. Bills else 25295820184SJason M. Bills { 25395820184SJason M. Bills // Otherwise, reset it 25495820184SJason M. Bills index = 0; 25595820184SJason M. Bills } 25695820184SJason M. Bills // Save the timestamp 25795820184SJason M. Bills prevTs = curTs; 25895820184SJason M. Bills 25995820184SJason M. Bills entryID = std::to_string(curTs); 26095820184SJason M. Bills if (index > 0) 26195820184SJason M. Bills { 26295820184SJason M. Bills entryID += "_" + std::to_string(index); 26395820184SJason M. Bills } 26495820184SJason M. Bills return true; 26595820184SJason M. Bills } 26695820184SJason M. Bills 2677e860f15SJohn Edward Broadbent inline static bool 2688d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2698d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 2708d1b46d7Szhanghch05 uint64_t& index) 27116428a1aSJason M. Bills { 27216428a1aSJason M. Bills if (entryID.empty()) 27316428a1aSJason M. Bills { 27416428a1aSJason M. Bills return false; 27516428a1aSJason M. Bills } 27616428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 27739e77504SEd Tanous std::string_view tsStr(entryID); 27816428a1aSJason M. Bills 27981ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 28071d5d8dbSEd Tanous if (underscorePos != std::string_view::npos) 28116428a1aSJason M. Bills { 28216428a1aSJason M. Bills // Timestamp has an index 28316428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 28439e77504SEd Tanous std::string_view indexStr(entryID); 28516428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 286c0bd5e4bSEd Tanous auto [ptr, ec] = std::from_chars( 287c0bd5e4bSEd Tanous indexStr.data(), indexStr.data() + indexStr.size(), index); 288c0bd5e4bSEd Tanous if (ec != std::errc()) 28916428a1aSJason M. Bills { 290ace85d60SEd Tanous messages::resourceMissingAtURI( 291ace85d60SEd Tanous asyncResp->res, crow::utility::urlFromPieces(entryID)); 29216428a1aSJason M. Bills return false; 29316428a1aSJason M. Bills } 29416428a1aSJason M. Bills } 29516428a1aSJason M. Bills // Timestamp has no index 296c0bd5e4bSEd Tanous auto [ptr, ec] = 297c0bd5e4bSEd Tanous std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp); 298c0bd5e4bSEd Tanous if (ec != std::errc()) 29916428a1aSJason M. Bills { 300ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, 301ace85d60SEd Tanous crow::utility::urlFromPieces(entryID)); 30216428a1aSJason M. Bills return false; 30316428a1aSJason M. Bills } 30416428a1aSJason M. Bills return true; 30516428a1aSJason M. Bills } 30616428a1aSJason M. Bills 30795820184SJason M. Bills static bool 30895820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 30995820184SJason M. Bills { 31095820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 31195820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 31295820184SJason M. Bills 31395820184SJason M. Bills // Loop through the directory looking for redfish log files 31495820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 31595820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 31695820184SJason M. Bills { 31795820184SJason M. Bills // If we find a redfish log file, save the path 31895820184SJason M. Bills std::string filename = dirEnt.path().filename(); 31911ba3979SEd Tanous if (filename.starts_with(redfishLogFilename)) 32095820184SJason M. Bills { 32195820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 32295820184SJason M. Bills } 32395820184SJason M. Bills } 32495820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 32595820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 32695820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 32795820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 32895820184SJason M. Bills 32995820184SJason M. Bills return !redfishLogFiles.empty(); 33095820184SJason M. Bills } 33195820184SJason M. Bills 332aefe3786SClaire Weinan inline void parseDumpEntryFromDbusObject( 3332d613eb6SJiaqing Zhao const dbus::utility::ManagedObjectType::value_type& object, 3342d613eb6SJiaqing Zhao std::string& dumpStatus, uint64_t& size, uint64_t& timestamp, 335aefe3786SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 336aefe3786SClaire Weinan { 337aefe3786SClaire Weinan for (const auto& interfaceMap : object.second) 338aefe3786SClaire Weinan { 339aefe3786SClaire Weinan if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") 340aefe3786SClaire Weinan { 341aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 342aefe3786SClaire Weinan { 343aefe3786SClaire Weinan if (propertyMap.first == "Status") 344aefe3786SClaire Weinan { 345aefe3786SClaire Weinan const auto* status = 346aefe3786SClaire Weinan std::get_if<std::string>(&propertyMap.second); 347aefe3786SClaire Weinan if (status == nullptr) 348aefe3786SClaire Weinan { 349aefe3786SClaire Weinan messages::internalError(asyncResp->res); 350aefe3786SClaire Weinan break; 351aefe3786SClaire Weinan } 352aefe3786SClaire Weinan dumpStatus = *status; 353aefe3786SClaire Weinan } 354aefe3786SClaire Weinan } 355aefe3786SClaire Weinan } 356aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 357aefe3786SClaire Weinan { 358aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 359aefe3786SClaire Weinan { 360aefe3786SClaire Weinan if (propertyMap.first == "Size") 361aefe3786SClaire Weinan { 362aefe3786SClaire Weinan const auto* sizePtr = 363aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 364aefe3786SClaire Weinan if (sizePtr == nullptr) 365aefe3786SClaire Weinan { 366aefe3786SClaire Weinan messages::internalError(asyncResp->res); 367aefe3786SClaire Weinan break; 368aefe3786SClaire Weinan } 369aefe3786SClaire Weinan size = *sizePtr; 370aefe3786SClaire Weinan break; 371aefe3786SClaire Weinan } 372aefe3786SClaire Weinan } 373aefe3786SClaire Weinan } 374aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") 375aefe3786SClaire Weinan { 376aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 377aefe3786SClaire Weinan { 378aefe3786SClaire Weinan if (propertyMap.first == "Elapsed") 379aefe3786SClaire Weinan { 380aefe3786SClaire Weinan const uint64_t* usecsTimeStamp = 381aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 382aefe3786SClaire Weinan if (usecsTimeStamp == nullptr) 383aefe3786SClaire Weinan { 384aefe3786SClaire Weinan messages::internalError(asyncResp->res); 385aefe3786SClaire Weinan break; 386aefe3786SClaire Weinan } 387aefe3786SClaire Weinan timestamp = *usecsTimeStamp; 388aefe3786SClaire Weinan break; 389aefe3786SClaire Weinan } 390aefe3786SClaire Weinan } 391aefe3786SClaire Weinan } 392aefe3786SClaire Weinan } 393aefe3786SClaire Weinan } 394aefe3786SClaire Weinan 39521ab404cSNan Zhou static std::string getDumpEntriesPath(const std::string& dumpType) 396fdd26906SClaire Weinan { 397fdd26906SClaire Weinan std::string entriesPath; 398fdd26906SClaire Weinan 399fdd26906SClaire Weinan if (dumpType == "BMC") 400fdd26906SClaire Weinan { 401fdd26906SClaire Weinan entriesPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 402fdd26906SClaire Weinan } 403fdd26906SClaire Weinan else if (dumpType == "FaultLog") 404fdd26906SClaire Weinan { 405fdd26906SClaire Weinan entriesPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/"; 406fdd26906SClaire Weinan } 407fdd26906SClaire Weinan else if (dumpType == "System") 408fdd26906SClaire Weinan { 409fdd26906SClaire Weinan entriesPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 410fdd26906SClaire Weinan } 411fdd26906SClaire Weinan else 412fdd26906SClaire Weinan { 413fdd26906SClaire Weinan BMCWEB_LOG_ERROR << "getDumpEntriesPath() invalid dump type: " 414fdd26906SClaire Weinan << dumpType; 415fdd26906SClaire Weinan } 416fdd26906SClaire Weinan 417fdd26906SClaire Weinan // Returns empty string on error 418fdd26906SClaire Weinan return entriesPath; 419fdd26906SClaire Weinan } 420fdd26906SClaire Weinan 4218d1b46d7Szhanghch05 inline void 4228d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4235cb1dd27SAsmitha Karunanithi const std::string& dumpType) 4245cb1dd27SAsmitha Karunanithi { 425fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 426fdd26906SClaire Weinan if (entriesPath.empty()) 4275cb1dd27SAsmitha Karunanithi { 4285cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4295cb1dd27SAsmitha Karunanithi return; 4305cb1dd27SAsmitha Karunanithi } 4315cb1dd27SAsmitha Karunanithi 4325cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 433fdd26906SClaire Weinan [asyncResp, entriesPath, 434711ac7a9SEd Tanous dumpType](const boost::system::error_code ec, 435711ac7a9SEd Tanous dbus::utility::ManagedObjectType& resp) { 4365cb1dd27SAsmitha Karunanithi if (ec) 4375cb1dd27SAsmitha Karunanithi { 4385cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4395cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4405cb1dd27SAsmitha Karunanithi return; 4415cb1dd27SAsmitha Karunanithi } 4425cb1dd27SAsmitha Karunanithi 443fdd26906SClaire Weinan // Remove ending slash 444fdd26906SClaire Weinan std::string odataIdStr = entriesPath; 445fdd26906SClaire Weinan if (!odataIdStr.empty()) 446fdd26906SClaire Weinan { 447fdd26906SClaire Weinan odataIdStr.pop_back(); 448fdd26906SClaire Weinan } 449fdd26906SClaire Weinan 450fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = 451fdd26906SClaire Weinan "#LogEntryCollection.LogEntryCollection"; 452fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr); 453fdd26906SClaire Weinan asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries"; 454fdd26906SClaire Weinan asyncResp->res.jsonValue["Description"] = 455fdd26906SClaire Weinan "Collection of " + dumpType + " Dump Entries"; 456fdd26906SClaire Weinan 4575cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4585cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 459b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 460b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 461002d39b4SEd Tanous std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; 4625cb1dd27SAsmitha Karunanithi 463002d39b4SEd Tanous std::sort(resp.begin(), resp.end(), [](const auto& l, const auto& r) { 464002d39b4SEd Tanous return AlphanumLess<std::string>()(l.first.filename(), 465002d39b4SEd Tanous r.first.filename()); 466565dfb6fSClaire Weinan }); 467565dfb6fSClaire Weinan 4685cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4695cb1dd27SAsmitha Karunanithi { 470b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 4715cb1dd27SAsmitha Karunanithi { 4725cb1dd27SAsmitha Karunanithi continue; 4735cb1dd27SAsmitha Karunanithi } 4741d8782e7SNan Zhou uint64_t timestamp = 0; 4755cb1dd27SAsmitha Karunanithi uint64_t size = 0; 47635440d18SAsmitha Karunanithi std::string dumpStatus; 477433b68b4SJason M. Bills nlohmann::json::object_t thisEntry; 4782dfd18efSEd Tanous 4792dfd18efSEd Tanous std::string entryID = object.first.filename(); 4802dfd18efSEd Tanous if (entryID.empty()) 4815cb1dd27SAsmitha Karunanithi { 4825cb1dd27SAsmitha Karunanithi continue; 4835cb1dd27SAsmitha Karunanithi } 4845cb1dd27SAsmitha Karunanithi 485aefe3786SClaire Weinan parseDumpEntryFromDbusObject(object, dumpStatus, size, timestamp, 486aefe3786SClaire Weinan asyncResp); 4875cb1dd27SAsmitha Karunanithi 4880fda0f12SGeorge Liu if (dumpStatus != 4890fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 49035440d18SAsmitha Karunanithi !dumpStatus.empty()) 49135440d18SAsmitha Karunanithi { 49235440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 49335440d18SAsmitha Karunanithi continue; 49435440d18SAsmitha Karunanithi } 49535440d18SAsmitha Karunanithi 496647b3cdcSGeorge Liu thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 497fdd26906SClaire Weinan thisEntry["@odata.id"] = entriesPath + entryID; 4985cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 4995cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 500*2b82937eSEd Tanous thisEntry["Created"] = 501*2b82937eSEd Tanous redfish::time_utils::getDateTimeUint(timestamp); 5025cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 5035cb1dd27SAsmitha Karunanithi 5045cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5055cb1dd27SAsmitha Karunanithi { 506d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 507d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 508fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 509fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 5105cb1dd27SAsmitha Karunanithi } 5115cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5125cb1dd27SAsmitha Karunanithi { 513d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 514d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 515d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 516fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 517fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 5185cb1dd27SAsmitha Karunanithi } 51935440d18SAsmitha Karunanithi entriesArray.push_back(std::move(thisEntry)); 5205cb1dd27SAsmitha Karunanithi } 521002d39b4SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size(); 5225cb1dd27SAsmitha Karunanithi }, 5235cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5245cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5255cb1dd27SAsmitha Karunanithi } 5265cb1dd27SAsmitha Karunanithi 5278d1b46d7Szhanghch05 inline void 528c7a6d660SClaire Weinan getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5298d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 5305cb1dd27SAsmitha Karunanithi { 531fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 532fdd26906SClaire Weinan if (entriesPath.empty()) 5335cb1dd27SAsmitha Karunanithi { 5345cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5355cb1dd27SAsmitha Karunanithi return; 5365cb1dd27SAsmitha Karunanithi } 5375cb1dd27SAsmitha Karunanithi 5385cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 539fdd26906SClaire Weinan [asyncResp, entryID, dumpType, 540fdd26906SClaire Weinan entriesPath](const boost::system::error_code ec, 54102cad96eSEd Tanous const dbus::utility::ManagedObjectType& resp) { 5425cb1dd27SAsmitha Karunanithi if (ec) 5435cb1dd27SAsmitha Karunanithi { 5445cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5455cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5465cb1dd27SAsmitha Karunanithi return; 5475cb1dd27SAsmitha Karunanithi } 5485cb1dd27SAsmitha Karunanithi 549b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 550b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 551b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 552002d39b4SEd Tanous std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; 553b47452b2SAsmitha Karunanithi 5549eb808c1SEd Tanous for (const auto& objectPath : resp) 5555cb1dd27SAsmitha Karunanithi { 556b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5575cb1dd27SAsmitha Karunanithi { 5585cb1dd27SAsmitha Karunanithi continue; 5595cb1dd27SAsmitha Karunanithi } 5605cb1dd27SAsmitha Karunanithi 5615cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 5621d8782e7SNan Zhou uint64_t timestamp = 0; 5635cb1dd27SAsmitha Karunanithi uint64_t size = 0; 56435440d18SAsmitha Karunanithi std::string dumpStatus; 5655cb1dd27SAsmitha Karunanithi 566aefe3786SClaire Weinan parseDumpEntryFromDbusObject(objectPath, dumpStatus, size, 567aefe3786SClaire Weinan timestamp, asyncResp); 5685cb1dd27SAsmitha Karunanithi 5690fda0f12SGeorge Liu if (dumpStatus != 5700fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 57135440d18SAsmitha Karunanithi !dumpStatus.empty()) 57235440d18SAsmitha Karunanithi { 57335440d18SAsmitha Karunanithi // Dump status is not Complete 57435440d18SAsmitha Karunanithi // return not found until status is changed to Completed 575002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, dumpType + " dump", 576002d39b4SEd Tanous entryID); 57735440d18SAsmitha Karunanithi return; 57835440d18SAsmitha Karunanithi } 57935440d18SAsmitha Karunanithi 5805cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 581647b3cdcSGeorge Liu "#LogEntry.v1_8_0.LogEntry"; 582fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID; 5835cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 5845cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 5855cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 586*2b82937eSEd Tanous redfish::time_utils::getDateTimeUint(timestamp); 5875cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 5885cb1dd27SAsmitha Karunanithi 5895cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5905cb1dd27SAsmitha Karunanithi { 591d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 592d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 593fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 594fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 5955cb1dd27SAsmitha Karunanithi } 5965cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5975cb1dd27SAsmitha Karunanithi { 598d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 599002d39b4SEd Tanous asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System"; 600d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 601fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 602fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6035cb1dd27SAsmitha Karunanithi } 6045cb1dd27SAsmitha Karunanithi } 605e05aec50SEd Tanous if (!foundDumpEntry) 606b47452b2SAsmitha Karunanithi { 607b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 608b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 609b47452b2SAsmitha Karunanithi return; 610b47452b2SAsmitha Karunanithi } 6115cb1dd27SAsmitha Karunanithi }, 6125cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6135cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6145cb1dd27SAsmitha Karunanithi } 6155cb1dd27SAsmitha Karunanithi 6168d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6179878256fSStanley Chu const std::string& entryID, 618b47452b2SAsmitha Karunanithi const std::string& dumpType) 6195cb1dd27SAsmitha Karunanithi { 620002d39b4SEd Tanous auto respHandler = 621002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec) { 6225cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6235cb1dd27SAsmitha Karunanithi if (ec) 6245cb1dd27SAsmitha Karunanithi { 6253de8d8baSGeorge Liu if (ec.value() == EBADR) 6263de8d8baSGeorge Liu { 6273de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 6283de8d8baSGeorge Liu return; 6293de8d8baSGeorge Liu } 6305cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 631fdd26906SClaire Weinan << ec << " entryID=" << entryID; 6325cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6335cb1dd27SAsmitha Karunanithi return; 6345cb1dd27SAsmitha Karunanithi } 6355cb1dd27SAsmitha Karunanithi }; 6365cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 6375cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 638b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 639b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 640b47452b2SAsmitha Karunanithi entryID, 6415cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 6425cb1dd27SAsmitha Karunanithi } 6435cb1dd27SAsmitha Karunanithi 6448d1b46d7Szhanghch05 inline void 64598be3e39SEd Tanous createDumpTaskCallback(task::Payload&& payload, 6468d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6478d1b46d7Szhanghch05 const uint32_t& dumpId, const std::string& dumpPath, 648a43be80fSAsmitha Karunanithi const std::string& dumpType) 649a43be80fSAsmitha Karunanithi { 650a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 65159d494eeSPatrick Williams [dumpId, dumpPath, 65259d494eeSPatrick Williams dumpType](boost::system::error_code err, sdbusplus::message_t& m, 653a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 654cb13a392SEd Tanous if (err) 655cb13a392SEd Tanous { 6566145ed6fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Error in creating a dump"; 6576145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 6586145ed6fSAsmitha Karunanithi return task::completed; 659cb13a392SEd Tanous } 660b9d36b47SEd Tanous 661b9d36b47SEd Tanous dbus::utility::DBusInteracesMap interfacesList; 662a43be80fSAsmitha Karunanithi 663a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 664a43be80fSAsmitha Karunanithi 665a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 666a43be80fSAsmitha Karunanithi 667b47452b2SAsmitha Karunanithi if (objPath.str == 668b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 669b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 670b47452b2SAsmitha Karunanithi "/entry/" + std::to_string(dumpId)) 671a43be80fSAsmitha Karunanithi { 672a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 673a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 674a43be80fSAsmitha Karunanithi 675a43be80fSAsmitha Karunanithi std::string headerLoc = 676a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 677002d39b4SEd Tanous taskData->payload->httpHeaders.emplace_back(std::move(headerLoc)); 678a43be80fSAsmitha Karunanithi 679a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 680b47452b2SAsmitha Karunanithi return task::completed; 6816145ed6fSAsmitha Karunanithi } 682a43be80fSAsmitha Karunanithi return task::completed; 683a43be80fSAsmitha Karunanithi }, 6844978b63fSJason M. Bills "type='signal',interface='org.freedesktop.DBus.ObjectManager'," 685a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 686a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 687a43be80fSAsmitha Karunanithi 688a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 689a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 69098be3e39SEd Tanous task->payload.emplace(std::move(payload)); 691a43be80fSAsmitha Karunanithi } 692a43be80fSAsmitha Karunanithi 6938d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6948d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 695a43be80fSAsmitha Karunanithi { 696fdd26906SClaire Weinan std::string dumpPath = getDumpEntriesPath(dumpType); 697fdd26906SClaire Weinan if (dumpPath.empty()) 698a43be80fSAsmitha Karunanithi { 699a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 700a43be80fSAsmitha Karunanithi return; 701a43be80fSAsmitha Karunanithi } 702a43be80fSAsmitha Karunanithi 703a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 704a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 705a43be80fSAsmitha Karunanithi 70615ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 707a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 708a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 709a43be80fSAsmitha Karunanithi { 710a43be80fSAsmitha Karunanithi return; 711a43be80fSAsmitha Karunanithi } 712a43be80fSAsmitha Karunanithi 713a43be80fSAsmitha Karunanithi if (dumpType == "System") 714a43be80fSAsmitha Karunanithi { 715a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 716a43be80fSAsmitha Karunanithi { 7174978b63fSJason M. Bills BMCWEB_LOG_ERROR 7184978b63fSJason M. Bills << "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"; 719a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 720a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 721a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 722a43be80fSAsmitha Karunanithi return; 723a43be80fSAsmitha Karunanithi } 7243174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 725a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 726a43be80fSAsmitha Karunanithi { 727a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 728ace85d60SEd Tanous messages::internalError(asyncResp->res); 729a43be80fSAsmitha Karunanithi return; 730a43be80fSAsmitha Karunanithi } 7315907571dSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/"; 732a43be80fSAsmitha Karunanithi } 733a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 734a43be80fSAsmitha Karunanithi { 735a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 736a43be80fSAsmitha Karunanithi { 7370fda0f12SGeorge Liu BMCWEB_LOG_ERROR 7380fda0f12SGeorge Liu << "CreateDump action parameter 'DiagnosticDataType' not found!"; 739a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 740a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 741a43be80fSAsmitha Karunanithi return; 742a43be80fSAsmitha Karunanithi } 7433174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 744a43be80fSAsmitha Karunanithi { 745a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 746a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 747ace85d60SEd Tanous messages::internalError(asyncResp->res); 748a43be80fSAsmitha Karunanithi return; 749a43be80fSAsmitha Karunanithi } 7505907571dSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/"; 7515907571dSAsmitha Karunanithi } 7525907571dSAsmitha Karunanithi else 7535907571dSAsmitha Karunanithi { 7545907571dSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump failed. Unknown dump type"; 7555907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 7565907571dSAsmitha Karunanithi return; 757a43be80fSAsmitha Karunanithi } 758a43be80fSAsmitha Karunanithi 759a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 76098be3e39SEd Tanous [asyncResp, payload(task::Payload(req)), dumpPath, 76198be3e39SEd Tanous dumpType](const boost::system::error_code ec, 7625907571dSAsmitha Karunanithi const sdbusplus::message::message& msg, 76398be3e39SEd Tanous const uint32_t& dumpId) mutable { 764a43be80fSAsmitha Karunanithi if (ec) 765a43be80fSAsmitha Karunanithi { 766a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 7675907571dSAsmitha Karunanithi const sd_bus_error* dbusError = msg.get_error(); 7685907571dSAsmitha Karunanithi if (dbusError == nullptr) 7695907571dSAsmitha Karunanithi { 7705907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 7715907571dSAsmitha Karunanithi return; 7725907571dSAsmitha Karunanithi } 7735907571dSAsmitha Karunanithi 7745907571dSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump DBus error: " << dbusError->name 7755907571dSAsmitha Karunanithi << " and error msg: " << dbusError->message; 7765907571dSAsmitha Karunanithi if (std::string_view( 7775907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.NotAllowed") == 7785907571dSAsmitha Karunanithi dbusError->name) 7795907571dSAsmitha Karunanithi { 7805907571dSAsmitha Karunanithi messages::resourceInStandby(asyncResp->res); 7815907571dSAsmitha Karunanithi return; 7825907571dSAsmitha Karunanithi } 7835907571dSAsmitha Karunanithi if (std::string_view( 7845907571dSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.Error.Disabled") == 7855907571dSAsmitha Karunanithi dbusError->name) 7865907571dSAsmitha Karunanithi { 7875907571dSAsmitha Karunanithi messages::serviceDisabled(asyncResp->res, dumpPath); 7885907571dSAsmitha Karunanithi return; 7895907571dSAsmitha Karunanithi } 7905907571dSAsmitha Karunanithi if (std::string_view( 7915907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.Unavailable") == 7925907571dSAsmitha Karunanithi dbusError->name) 7935907571dSAsmitha Karunanithi { 7945907571dSAsmitha Karunanithi messages::resourceInUse(asyncResp->res); 7955907571dSAsmitha Karunanithi return; 7965907571dSAsmitha Karunanithi } 7975907571dSAsmitha Karunanithi // Other Dbus errors such as: 7985907571dSAsmitha Karunanithi // xyz.openbmc_project.Common.Error.InvalidArgument & 7995907571dSAsmitha Karunanithi // org.freedesktop.DBus.Error.InvalidArgs are all related to 8005907571dSAsmitha Karunanithi // the dbus call that is made here in the bmcweb 8015907571dSAsmitha Karunanithi // implementation and has nothing to do with the client's 8025907571dSAsmitha Karunanithi // input in the request. Hence, returning internal error 8035907571dSAsmitha Karunanithi // back to the client. 804a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 805a43be80fSAsmitha Karunanithi return; 806a43be80fSAsmitha Karunanithi } 807a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 808a43be80fSAsmitha Karunanithi 809002d39b4SEd Tanous createDumpTaskCallback(std::move(payload), asyncResp, dumpId, dumpPath, 810002d39b4SEd Tanous dumpType); 811a43be80fSAsmitha Karunanithi }, 812b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 813b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 814b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 815a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 816a43be80fSAsmitha Karunanithi } 817a43be80fSAsmitha Karunanithi 8188d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8198d1b46d7Szhanghch05 const std::string& dumpType) 82080319af1SAsmitha Karunanithi { 821b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 822b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 8238d1b46d7Szhanghch05 82480319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 825b9d36b47SEd Tanous [asyncResp, dumpType]( 826b9d36b47SEd Tanous const boost::system::error_code ec, 827b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 82880319af1SAsmitha Karunanithi if (ec) 82980319af1SAsmitha Karunanithi { 83080319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 83180319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 83280319af1SAsmitha Karunanithi return; 83380319af1SAsmitha Karunanithi } 83480319af1SAsmitha Karunanithi 83580319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 83680319af1SAsmitha Karunanithi { 8372dfd18efSEd Tanous sdbusplus::message::object_path objPath(path); 8382dfd18efSEd Tanous std::string logID = objPath.filename(); 8392dfd18efSEd Tanous if (logID.empty()) 84080319af1SAsmitha Karunanithi { 8412dfd18efSEd Tanous continue; 84280319af1SAsmitha Karunanithi } 8432dfd18efSEd Tanous deleteDumpEntry(asyncResp, logID, dumpType); 84480319af1SAsmitha Karunanithi } 84580319af1SAsmitha Karunanithi }, 84680319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 84780319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 84880319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 849b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, 850b47452b2SAsmitha Karunanithi std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." + 851b47452b2SAsmitha Karunanithi dumpType}); 85280319af1SAsmitha Karunanithi } 85380319af1SAsmitha Karunanithi 854b9d36b47SEd Tanous inline static void 855b9d36b47SEd Tanous parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params, 856b9d36b47SEd Tanous std::string& filename, std::string& timestamp, 857b9d36b47SEd Tanous std::string& logfile) 858043a0536SJohnathan Mantey { 859043a0536SJohnathan Mantey for (auto property : params) 860043a0536SJohnathan Mantey { 861043a0536SJohnathan Mantey if (property.first == "Timestamp") 862043a0536SJohnathan Mantey { 863043a0536SJohnathan Mantey const std::string* value = 8648d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 865043a0536SJohnathan Mantey if (value != nullptr) 866043a0536SJohnathan Mantey { 867043a0536SJohnathan Mantey timestamp = *value; 868043a0536SJohnathan Mantey } 869043a0536SJohnathan Mantey } 870043a0536SJohnathan Mantey else if (property.first == "Filename") 871043a0536SJohnathan Mantey { 872043a0536SJohnathan Mantey const std::string* value = 8738d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 874043a0536SJohnathan Mantey if (value != nullptr) 875043a0536SJohnathan Mantey { 876043a0536SJohnathan Mantey filename = *value; 877043a0536SJohnathan Mantey } 878043a0536SJohnathan Mantey } 879043a0536SJohnathan Mantey else if (property.first == "Log") 880043a0536SJohnathan Mantey { 881043a0536SJohnathan Mantey const std::string* value = 8828d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 883043a0536SJohnathan Mantey if (value != nullptr) 884043a0536SJohnathan Mantey { 885043a0536SJohnathan Mantey logfile = *value; 886043a0536SJohnathan Mantey } 887043a0536SJohnathan Mantey } 888043a0536SJohnathan Mantey } 889043a0536SJohnathan Mantey } 890043a0536SJohnathan Mantey 891a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 8927e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 8931da66f75SEd Tanous { 894c4bf6374SJason M. Bills /** 895c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 896c4bf6374SJason M. Bills */ 8977e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/") 898ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 899002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 900002d39b4SEd Tanous [&app](const crow::Request& req, 901002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 9023ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 903c4bf6374SJason M. Bills { 90445ca1b86SEd Tanous return; 90545ca1b86SEd Tanous } 9067e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 9077e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 908c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 909c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 910c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 911029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 91245ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 913c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 914c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 915002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 916c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 9171476687dSEd Tanous nlohmann::json::object_t eventLog; 9181476687dSEd Tanous eventLog["@odata.id"] = 9191476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 9201476687dSEd Tanous logServiceArray.push_back(std::move(eventLog)); 9215cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 9221476687dSEd Tanous nlohmann::json::object_t dumpLog; 923002d39b4SEd Tanous dumpLog["@odata.id"] = "/redfish/v1/Systems/system/LogServices/Dump"; 9241476687dSEd Tanous logServiceArray.push_back(std::move(dumpLog)); 925c9bb6861Sraviteja-b #endif 926c9bb6861Sraviteja-b 927d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 9281476687dSEd Tanous nlohmann::json::object_t crashdump; 9291476687dSEd Tanous crashdump["@odata.id"] = 9301476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump"; 9311476687dSEd Tanous logServiceArray.push_back(std::move(crashdump)); 932d53dd41fSJason M. Bills #endif 933b7028ebfSSpencer Ku 934b7028ebfSSpencer Ku #ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER 9351476687dSEd Tanous nlohmann::json::object_t hostlogger; 9361476687dSEd Tanous hostlogger["@odata.id"] = 9371476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger"; 9381476687dSEd Tanous logServiceArray.push_back(std::move(hostlogger)); 939b7028ebfSSpencer Ku #endif 940c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 941c4bf6374SJason M. Bills logServiceArray.size(); 942a3316fc6SZhikuiRen 943a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 94445ca1b86SEd Tanous [asyncResp](const boost::system::error_code ec, 945b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& 946b9d36b47SEd Tanous subtreePath) { 947a3316fc6SZhikuiRen if (ec) 948a3316fc6SZhikuiRen { 949a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 950a3316fc6SZhikuiRen return; 951a3316fc6SZhikuiRen } 952a3316fc6SZhikuiRen 95355f79e6fSEd Tanous for (const auto& pathStr : subtreePath) 954a3316fc6SZhikuiRen { 955a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 956a3316fc6SZhikuiRen { 95723a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 958a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 95923a21a1cSEd Tanous logServiceArrayLocal.push_back( 9600fda0f12SGeorge Liu {{"@odata.id", 9610fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes"}}); 96245ca1b86SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 96323a21a1cSEd Tanous logServiceArrayLocal.size(); 964a3316fc6SZhikuiRen return; 965a3316fc6SZhikuiRen } 966a3316fc6SZhikuiRen } 967a3316fc6SZhikuiRen }, 968a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 969a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 97045ca1b86SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 97145ca1b86SEd Tanous std::array<const char*, 1>{postCodeIface}); 9727e860f15SJohn Edward Broadbent }); 973c4bf6374SJason M. Bills } 974c4bf6374SJason M. Bills 9757e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 976c4bf6374SJason M. Bills { 9777e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 978ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 979002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 980002d39b4SEd Tanous [&app](const crow::Request& req, 981002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 9823ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 98345ca1b86SEd Tanous { 98445ca1b86SEd Tanous return; 98545ca1b86SEd Tanous } 986c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 987029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 988c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 989c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 990c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 991002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 992c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 993c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 9947c8c4058STejas Patil 9957c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 996*2b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 9977c8c4058STejas Patil 9987c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 9997c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 10007c8c4058STejas Patil redfishDateTimeOffset.second; 10017c8c4058STejas Patil 10021476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 10031476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1004e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1005e7d6c8b2SGunnar Mills 10060fda0f12SGeorge Liu {"target", 10070fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog"}}; 10087e860f15SJohn Edward Broadbent }); 1009489640c6SJason M. Bills } 1010489640c6SJason M. Bills 10117e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1012489640c6SJason M. Bills { 10134978b63fSJason M. Bills BMCWEB_ROUTE( 10144978b63fSJason M. Bills app, 10154978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/") 1016432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 10177e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 101845ca1b86SEd Tanous [&app](const crow::Request& req, 10197e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 10203ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 102145ca1b86SEd Tanous { 102245ca1b86SEd Tanous return; 102345ca1b86SEd Tanous } 1024489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1025489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1026489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1027489640c6SJason M. Bills { 1028489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1029489640c6SJason M. Bills { 1030489640c6SJason M. Bills std::error_code ec; 1031489640c6SJason M. Bills std::filesystem::remove(file, ec); 1032489640c6SJason M. Bills } 1033489640c6SJason M. Bills } 1034489640c6SJason M. Bills 1035489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1036489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1037489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1038489640c6SJason M. Bills if (ec) 1039489640c6SJason M. Bills { 1040002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 1041489640c6SJason M. Bills messages::internalError(asyncResp->res); 1042489640c6SJason M. Bills return; 1043489640c6SJason M. Bills } 1044489640c6SJason M. Bills 1045489640c6SJason M. Bills messages::success(asyncResp->res); 1046489640c6SJason M. Bills }, 1047489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1048002d39b4SEd Tanous "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1049002d39b4SEd Tanous "replace"); 10507e860f15SJohn Edward Broadbent }); 1051c4bf6374SJason M. Bills } 1052c4bf6374SJason M. Bills 1053ac992cdeSJason M. Bills enum class LogParseError 1054ac992cdeSJason M. Bills { 1055ac992cdeSJason M. Bills success, 1056ac992cdeSJason M. Bills parseFailed, 1057ac992cdeSJason M. Bills messageIdNotInRegistry, 1058ac992cdeSJason M. Bills }; 1059ac992cdeSJason M. Bills 1060ac992cdeSJason M. Bills static LogParseError 1061ac992cdeSJason M. Bills fillEventLogEntryJson(const std::string& logEntryID, 1062b5a76932SEd Tanous const std::string& logEntry, 1063de703c5dSJason M. Bills nlohmann::json::object_t& logEntryJson) 1064c4bf6374SJason M. Bills { 106595820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1066cd225da8SJason M. Bills // First get the Timestamp 1067f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1068cd225da8SJason M. Bills if (space == std::string::npos) 106995820184SJason M. Bills { 1070ac992cdeSJason M. Bills return LogParseError::parseFailed; 107195820184SJason M. Bills } 1072cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1073cd225da8SJason M. Bills // Then get the log contents 1074f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1075cd225da8SJason M. Bills if (entryStart == std::string::npos) 1076cd225da8SJason M. Bills { 1077ac992cdeSJason M. Bills return LogParseError::parseFailed; 1078cd225da8SJason M. Bills } 1079cd225da8SJason M. Bills std::string_view entry(logEntry); 1080cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1081cd225da8SJason M. Bills // Use split to separate the entry into its fields 1082cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1083cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1084cd225da8SJason M. Bills boost::token_compress_on); 1085cd225da8SJason M. Bills // We need at least a MessageId to be valid 108626f6976fSEd Tanous if (logEntryFields.empty()) 1087cd225da8SJason M. Bills { 1088ac992cdeSJason M. Bills return LogParseError::parseFailed; 1089cd225da8SJason M. Bills } 1090cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 109195820184SJason M. Bills 10924851d45dSJason M. Bills // Get the Message from the MessageRegistry 1093fffb8c1fSEd Tanous const registries::Message* message = registries::getMessage(messageID); 1094c4bf6374SJason M. Bills 109554417b02SSui Chen if (message == nullptr) 1096c4bf6374SJason M. Bills { 109754417b02SSui Chen BMCWEB_LOG_WARNING << "Log entry not found in registry: " << logEntry; 1098ac992cdeSJason M. Bills return LogParseError::messageIdNotInRegistry; 1099c4bf6374SJason M. Bills } 1100c4bf6374SJason M. Bills 110154417b02SSui Chen std::string msg = message->message; 110254417b02SSui Chen 110315a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 110426702d01SEd Tanous std::span<std::string> messageArgs; 110515a86ff6SJason M. Bills if (logEntryFields.size() > 1) 110615a86ff6SJason M. Bills { 110715a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 110815a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 110915a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 111015a86ff6SJason M. Bills if (!messageArgsStart.empty()) 111115a86ff6SJason M. Bills { 111215a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 111315a86ff6SJason M. Bills } 111415a86ff6SJason M. Bills 111523a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1116c4bf6374SJason M. Bills 11174851d45dSJason M. Bills // Fill the MessageArgs into the Message 111895820184SJason M. Bills int i = 0; 111995820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11204851d45dSJason M. Bills { 112195820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11224851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11234851d45dSJason M. Bills if (argPos != std::string::npos) 11244851d45dSJason M. Bills { 112595820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11264851d45dSJason M. Bills } 11274851d45dSJason M. Bills } 112815a86ff6SJason M. Bills } 11294851d45dSJason M. Bills 113095820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 113195820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 113295820184SJason M. Bills // between the '.' and the '+', so just remove them. 1133f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1134f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 113595820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1136c4bf6374SJason M. Bills { 113795820184SJason M. Bills timestamp.erase(dot, plus - dot); 1138c4bf6374SJason M. Bills } 1139c4bf6374SJason M. Bills 1140c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 114184afc48bSJason M. Bills logEntryJson["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 114284afc48bSJason M. Bills logEntryJson["@odata.id"] = 114384afc48bSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + logEntryID; 114484afc48bSJason M. Bills logEntryJson["Name"] = "System Event Log Entry"; 114584afc48bSJason M. Bills logEntryJson["Id"] = logEntryID; 114684afc48bSJason M. Bills logEntryJson["Message"] = std::move(msg); 114784afc48bSJason M. Bills logEntryJson["MessageId"] = std::move(messageID); 114884afc48bSJason M. Bills logEntryJson["MessageArgs"] = messageArgs; 114984afc48bSJason M. Bills logEntryJson["EntryType"] = "Event"; 115084afc48bSJason M. Bills logEntryJson["Severity"] = message->messageSeverity; 115184afc48bSJason M. Bills logEntryJson["Created"] = std::move(timestamp); 1152ac992cdeSJason M. Bills return LogParseError::success; 1153c4bf6374SJason M. Bills } 1154c4bf6374SJason M. Bills 11557e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1156c4bf6374SJason M. Bills { 11577e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 11587e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 11598b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 1160002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1161002d39b4SEd Tanous [&app](const crow::Request& req, 1162002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1163c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1164c937d2bfSEd Tanous .canDelegateTop = true, 1165c937d2bfSEd Tanous .canDelegateSkip = true, 1166c937d2bfSEd Tanous }; 1167c937d2bfSEd Tanous query_param::Query delegatedQuery; 1168c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 11693ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 1170c4bf6374SJason M. Bills { 1171c4bf6374SJason M. Bills return; 1172c4bf6374SJason M. Bills } 11733648c8beSEd Tanous size_t top = 11743648c8beSEd Tanous delegatedQuery.top.value_or(query_param::maxEntriesPerPage); 11753648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 11763648c8beSEd Tanous 11777e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 11787e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1179c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1180c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1181c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1182029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1183c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1184c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1185c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1186cb92c03bSAndrew Geissler 11874978b63fSJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1188c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 11897e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 11907e860f15SJohn Edward Broadbent // entry 119195820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 119295820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1193b01bf299SEd Tanous uint64_t entryCount = 0; 1194cd225da8SJason M. Bills std::string logEntry; 119595820184SJason M. Bills 11967e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 11977e860f15SJohn Edward Broadbent // backwards 1198002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1199002d39b4SEd Tanous it++) 1200c4bf6374SJason M. Bills { 1201cd225da8SJason M. Bills std::ifstream logStream(*it); 120295820184SJason M. Bills if (!logStream.is_open()) 1203c4bf6374SJason M. Bills { 1204c4bf6374SJason M. Bills continue; 1205c4bf6374SJason M. Bills } 1206c4bf6374SJason M. Bills 1207e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1208e85d6b16SJason M. Bills bool firstEntry = true; 120995820184SJason M. Bills while (std::getline(logStream, logEntry)) 121095820184SJason M. Bills { 1211c4bf6374SJason M. Bills std::string idStr; 1212e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1213c4bf6374SJason M. Bills { 1214c4bf6374SJason M. Bills continue; 1215c4bf6374SJason M. Bills } 1216e85d6b16SJason M. Bills firstEntry = false; 1217e85d6b16SJason M. Bills 1218de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 1219ac992cdeSJason M. Bills LogParseError status = 1220ac992cdeSJason M. Bills fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); 1221ac992cdeSJason M. Bills if (status == LogParseError::messageIdNotInRegistry) 1222ac992cdeSJason M. Bills { 1223ac992cdeSJason M. Bills continue; 1224ac992cdeSJason M. Bills } 1225ac992cdeSJason M. Bills if (status != LogParseError::success) 1226c4bf6374SJason M. Bills { 1227c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1228c4bf6374SJason M. Bills return; 1229c4bf6374SJason M. Bills } 1230de703c5dSJason M. Bills 1231de703c5dSJason M. Bills entryCount++; 1232de703c5dSJason M. Bills // Handle paging using skip (number of entries to skip from the 1233de703c5dSJason M. Bills // start) and top (number of entries to display) 12343648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 1235de703c5dSJason M. Bills { 1236de703c5dSJason M. Bills continue; 1237de703c5dSJason M. Bills } 1238de703c5dSJason M. Bills 1239de703c5dSJason M. Bills logEntryArray.push_back(std::move(bmcLogEntry)); 1240c4bf6374SJason M. Bills } 124195820184SJason M. Bills } 1242c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 12433648c8beSEd Tanous if (skip + top < entryCount) 1244c4bf6374SJason M. Bills { 1245c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 12464978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries?$skip=" + 12473648c8beSEd Tanous std::to_string(skip + top); 1248c4bf6374SJason M. Bills } 12497e860f15SJohn Edward Broadbent }); 1250897967deSJason M. Bills } 1251897967deSJason M. Bills 12527e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1253897967deSJason M. Bills { 12547e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 12557e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1256ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 12577e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 125845ca1b86SEd Tanous [&app](const crow::Request& req, 12597e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12607e860f15SJohn Edward Broadbent const std::string& param) { 12613ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 126245ca1b86SEd Tanous { 126345ca1b86SEd Tanous return; 126445ca1b86SEd Tanous } 12657e860f15SJohn Edward Broadbent const std::string& targetID = param; 12668d1b46d7Szhanghch05 12677e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 12687e860f15SJohn Edward Broadbent // entry to find the target entry 1269897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1270897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1271897967deSJason M. Bills std::string logEntry; 1272897967deSJason M. Bills 12737e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12747e860f15SJohn Edward Broadbent // backwards 1275002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1276002d39b4SEd Tanous it++) 1277897967deSJason M. Bills { 1278897967deSJason M. Bills std::ifstream logStream(*it); 1279897967deSJason M. Bills if (!logStream.is_open()) 1280897967deSJason M. Bills { 1281897967deSJason M. Bills continue; 1282897967deSJason M. Bills } 1283897967deSJason M. Bills 1284897967deSJason M. Bills // Reset the unique ID on the first entry 1285897967deSJason M. Bills bool firstEntry = true; 1286897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1287897967deSJason M. Bills { 1288897967deSJason M. Bills std::string idStr; 1289897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1290897967deSJason M. Bills { 1291897967deSJason M. Bills continue; 1292897967deSJason M. Bills } 1293897967deSJason M. Bills firstEntry = false; 1294897967deSJason M. Bills 1295897967deSJason M. Bills if (idStr == targetID) 1296897967deSJason M. Bills { 1297de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 1298ac992cdeSJason M. Bills LogParseError status = 1299ac992cdeSJason M. Bills fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); 1300ac992cdeSJason M. Bills if (status != LogParseError::success) 1301897967deSJason M. Bills { 1302897967deSJason M. Bills messages::internalError(asyncResp->res); 1303897967deSJason M. Bills return; 1304897967deSJason M. Bills } 1305d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcLogEntry); 1306897967deSJason M. Bills return; 1307897967deSJason M. Bills } 1308897967deSJason M. Bills } 1309897967deSJason M. Bills } 1310897967deSJason M. Bills // Requested ID was not found 1311002d39b4SEd Tanous messages::resourceMissingAtURI(asyncResp->res, 1312002d39b4SEd Tanous crow::utility::urlFromPieces(targetID)); 13137e860f15SJohn Edward Broadbent }); 131408a4e4b5SAnthony Wilson } 131508a4e4b5SAnthony Wilson 13167e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 131708a4e4b5SAnthony Wilson { 13187e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 13197e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1320ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 1321002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1322002d39b4SEd Tanous [&app](const crow::Request& req, 1323002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 13243ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 132545ca1b86SEd Tanous { 132645ca1b86SEd Tanous return; 132745ca1b86SEd Tanous } 13287e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 13297e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 133008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 133108a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 133208a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 133308a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 133408a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 133508a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 133608a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 133708a4e4b5SAnthony Wilson 1338cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1339cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1340cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1341cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1342914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& resp) { 1343cb92c03bSAndrew Geissler if (ec) 1344cb92c03bSAndrew Geissler { 1345cb92c03bSAndrew Geissler // TODO Handle for specific error code 1346cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1347002d39b4SEd Tanous << "getLogEntriesIfaceData resp_handler got error " << ec; 1348cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1349cb92c03bSAndrew Geissler return; 1350cb92c03bSAndrew Geissler } 1351002d39b4SEd Tanous nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 1352cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 13539eb808c1SEd Tanous for (const auto& objectPath : resp) 1354cb92c03bSAndrew Geissler { 1355914e2d5dSEd Tanous const uint32_t* id = nullptr; 1356c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1357c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1358914e2d5dSEd Tanous const std::string* severity = nullptr; 1359914e2d5dSEd Tanous const std::string* message = nullptr; 1360914e2d5dSEd Tanous const std::string* filePath = nullptr; 136175710de2SXiaochao Ma bool resolved = false; 13629eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 1363f86bb901SAdriana Kobylak { 1364f86bb901SAdriana Kobylak if (interfaceMap.first == 1365f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1366f86bb901SAdriana Kobylak { 1367002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 1368cb92c03bSAndrew Geissler { 1369cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1370cb92c03bSAndrew Geissler { 1371002d39b4SEd Tanous id = std::get_if<uint32_t>(&propertyMap.second); 1372cb92c03bSAndrew Geissler } 1373cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1374cb92c03bSAndrew Geissler { 1375002d39b4SEd Tanous timestamp = 1376002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 13777e860f15SJohn Edward Broadbent } 1378002d39b4SEd Tanous else if (propertyMap.first == "UpdateTimestamp") 13797e860f15SJohn Edward Broadbent { 1380002d39b4SEd Tanous updateTimestamp = 1381002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 13827e860f15SJohn Edward Broadbent } 13837e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 13847e860f15SJohn Edward Broadbent { 13857e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 13867e860f15SJohn Edward Broadbent &propertyMap.second); 13877e860f15SJohn Edward Broadbent } 13887e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 13897e860f15SJohn Edward Broadbent { 13907e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 13917e860f15SJohn Edward Broadbent &propertyMap.second); 13927e860f15SJohn Edward Broadbent } 13937e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 13947e860f15SJohn Edward Broadbent { 1395914e2d5dSEd Tanous const bool* resolveptr = 1396002d39b4SEd Tanous std::get_if<bool>(&propertyMap.second); 13977e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 13987e860f15SJohn Edward Broadbent { 1399002d39b4SEd Tanous messages::internalError(asyncResp->res); 14007e860f15SJohn Edward Broadbent return; 14017e860f15SJohn Edward Broadbent } 14027e860f15SJohn Edward Broadbent resolved = *resolveptr; 14037e860f15SJohn Edward Broadbent } 14047e860f15SJohn Edward Broadbent } 14057e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14067e860f15SJohn Edward Broadbent severity == nullptr) 14077e860f15SJohn Edward Broadbent { 14087e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 14097e860f15SJohn Edward Broadbent return; 14107e860f15SJohn Edward Broadbent } 14117e860f15SJohn Edward Broadbent } 14127e860f15SJohn Edward Broadbent else if (interfaceMap.first == 14137e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 14147e860f15SJohn Edward Broadbent { 1415002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 14167e860f15SJohn Edward Broadbent { 14177e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 14187e860f15SJohn Edward Broadbent { 14197e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 14207e860f15SJohn Edward Broadbent &propertyMap.second); 14217e860f15SJohn Edward Broadbent } 14227e860f15SJohn Edward Broadbent } 14237e860f15SJohn Edward Broadbent } 14247e860f15SJohn Edward Broadbent } 14257e860f15SJohn Edward Broadbent // Object path without the 14267e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 14277e860f15SJohn Edward Broadbent // and continue. 14287e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 1429c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1430c419c759SEd Tanous updateTimestamp == nullptr) 14317e860f15SJohn Edward Broadbent { 14327e860f15SJohn Edward Broadbent continue; 14337e860f15SJohn Edward Broadbent } 14347e860f15SJohn Edward Broadbent entriesArray.push_back({}); 14357e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 14367e860f15SJohn Edward Broadbent thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 14377e860f15SJohn Edward Broadbent thisEntry["@odata.id"] = 14380fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 14397e860f15SJohn Edward Broadbent std::to_string(*id); 14407e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 14417e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 14427e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 14437e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 14447e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 14457e860f15SJohn Edward Broadbent thisEntry["Severity"] = 14467e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 14477e860f15SJohn Edward Broadbent thisEntry["Created"] = 1448*2b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*timestamp); 14497e860f15SJohn Edward Broadbent thisEntry["Modified"] = 1450*2b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*updateTimestamp); 14517e860f15SJohn Edward Broadbent if (filePath != nullptr) 14527e860f15SJohn Edward Broadbent { 14537e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 14540fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 14557e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 14567e860f15SJohn Edward Broadbent } 14577e860f15SJohn Edward Broadbent } 1458002d39b4SEd Tanous std::sort( 1459002d39b4SEd Tanous entriesArray.begin(), entriesArray.end(), 1460002d39b4SEd Tanous [](const nlohmann::json& left, const nlohmann::json& right) { 14617e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 14627e860f15SJohn Edward Broadbent }); 14637e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 14647e860f15SJohn Edward Broadbent entriesArray.size(); 14657e860f15SJohn Edward Broadbent }, 14667e860f15SJohn Edward Broadbent "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 14677e860f15SJohn Edward Broadbent "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 14687e860f15SJohn Edward Broadbent }); 14697e860f15SJohn Edward Broadbent } 14707e860f15SJohn Edward Broadbent 14717e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 14727e860f15SJohn Edward Broadbent { 14737e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 14747e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1475ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 1476002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1477002d39b4SEd Tanous [&app](const crow::Request& req, 14787e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 147945ca1b86SEd Tanous const std::string& param) { 14803ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 14817e860f15SJohn Edward Broadbent { 148245ca1b86SEd Tanous return; 148345ca1b86SEd Tanous } 14847e860f15SJohn Edward Broadbent std::string entryID = param; 14857e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 14867e860f15SJohn Edward Broadbent 14877e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 14887e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 14897e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 1490002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec, 1491b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 14927e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 14937e860f15SJohn Edward Broadbent { 1494002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "EventLogEntry", 1495002d39b4SEd Tanous entryID); 14967e860f15SJohn Edward Broadbent return; 14977e860f15SJohn Edward Broadbent } 14987e860f15SJohn Edward Broadbent if (ec) 14997e860f15SJohn Edward Broadbent { 15000fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1501002d39b4SEd Tanous << "EventLogEntry (DBus) resp_handler got error " << ec; 15027e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 15037e860f15SJohn Edward Broadbent return; 15047e860f15SJohn Edward Broadbent } 1505914e2d5dSEd Tanous const uint32_t* id = nullptr; 1506c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1507c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1508914e2d5dSEd Tanous const std::string* severity = nullptr; 1509914e2d5dSEd Tanous const std::string* message = nullptr; 1510914e2d5dSEd Tanous const std::string* filePath = nullptr; 15117e860f15SJohn Edward Broadbent bool resolved = false; 15127e860f15SJohn Edward Broadbent 15139eb808c1SEd Tanous for (const auto& propertyMap : resp) 15147e860f15SJohn Edward Broadbent { 15157e860f15SJohn Edward Broadbent if (propertyMap.first == "Id") 15167e860f15SJohn Edward Broadbent { 15177e860f15SJohn Edward Broadbent id = std::get_if<uint32_t>(&propertyMap.second); 15187e860f15SJohn Edward Broadbent } 15197e860f15SJohn Edward Broadbent else if (propertyMap.first == "Timestamp") 15207e860f15SJohn Edward Broadbent { 1521002d39b4SEd Tanous timestamp = std::get_if<uint64_t>(&propertyMap.second); 1522ebd45906SGeorge Liu } 1523d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1524d139c236SGeorge Liu { 1525ebd45906SGeorge Liu updateTimestamp = 1526c419c759SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 1527ebd45906SGeorge Liu } 1528cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1529cb92c03bSAndrew Geissler { 1530002d39b4SEd Tanous severity = std::get_if<std::string>(&propertyMap.second); 1531cb92c03bSAndrew Geissler } 1532cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1533cb92c03bSAndrew Geissler { 1534002d39b4SEd Tanous message = std::get_if<std::string>(&propertyMap.second); 1535ae34c8e8SAdriana Kobylak } 153675710de2SXiaochao Ma else if (propertyMap.first == "Resolved") 153775710de2SXiaochao Ma { 1538914e2d5dSEd Tanous const bool* resolveptr = 153975710de2SXiaochao Ma std::get_if<bool>(&propertyMap.second); 154075710de2SXiaochao Ma if (resolveptr == nullptr) 154175710de2SXiaochao Ma { 154275710de2SXiaochao Ma messages::internalError(asyncResp->res); 154375710de2SXiaochao Ma return; 154475710de2SXiaochao Ma } 154575710de2SXiaochao Ma resolved = *resolveptr; 154675710de2SXiaochao Ma } 15477e860f15SJohn Edward Broadbent else if (propertyMap.first == "Path") 1548f86bb901SAdriana Kobylak { 1549002d39b4SEd Tanous filePath = std::get_if<std::string>(&propertyMap.second); 1550f86bb901SAdriana Kobylak } 1551f86bb901SAdriana Kobylak } 1552002d39b4SEd Tanous if (id == nullptr || message == nullptr || severity == nullptr || 1553002d39b4SEd Tanous timestamp == nullptr || updateTimestamp == nullptr) 1554f86bb901SAdriana Kobylak { 1555ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1556271584abSEd Tanous return; 1557271584abSEd Tanous } 1558f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 1559f86bb901SAdriana Kobylak "#LogEntry.v1_8_0.LogEntry"; 1560f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.id"] = 15610fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 1562f86bb901SAdriana Kobylak std::to_string(*id); 156345ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Event Log Entry"; 1564f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1565f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1566f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 1567f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1568f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1569f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1570f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 1571*2b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*timestamp); 1572f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 1573*2b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*updateTimestamp); 1574f86bb901SAdriana Kobylak if (filePath != nullptr) 1575f86bb901SAdriana Kobylak { 1576f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 1577e7dbd530SPotin Lai "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 1578e7dbd530SPotin Lai std::to_string(*id) + "/attachment"; 1579f86bb901SAdriana Kobylak } 1580cb92c03bSAndrew Geissler }, 1581cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1582cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1583f86bb901SAdriana Kobylak "org.freedesktop.DBus.Properties", "GetAll", ""); 15847e860f15SJohn Edward Broadbent }); 1585336e96c6SChicago Duan 15867e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 15877e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1588ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 15897e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 159045ca1b86SEd Tanous [&app](const crow::Request& req, 15917e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 15927e860f15SJohn Edward Broadbent const std::string& entryId) { 15933ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 159445ca1b86SEd Tanous { 159545ca1b86SEd Tanous return; 159645ca1b86SEd Tanous } 159775710de2SXiaochao Ma std::optional<bool> resolved; 159875710de2SXiaochao Ma 159915ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", 16007e860f15SJohn Edward Broadbent resolved)) 160175710de2SXiaochao Ma { 160275710de2SXiaochao Ma return; 160375710de2SXiaochao Ma } 160475710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 160575710de2SXiaochao Ma 160675710de2SXiaochao Ma crow::connections::systemBus->async_method_call( 16074f48d5f6SEd Tanous [asyncResp, entryId](const boost::system::error_code ec) { 160875710de2SXiaochao Ma if (ec) 160975710de2SXiaochao Ma { 161075710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 161175710de2SXiaochao Ma messages::internalError(asyncResp->res); 161275710de2SXiaochao Ma return; 161375710de2SXiaochao Ma } 161475710de2SXiaochao Ma }, 161575710de2SXiaochao Ma "xyz.openbmc_project.Logging", 161675710de2SXiaochao Ma "/xyz/openbmc_project/logging/entry/" + entryId, 161775710de2SXiaochao Ma "org.freedesktop.DBus.Properties", "Set", 161875710de2SXiaochao Ma "xyz.openbmc_project.Logging.Entry", "Resolved", 1619168e20c1SEd Tanous dbus::utility::DbusVariantType(*resolved)); 16207e860f15SJohn Edward Broadbent }); 162175710de2SXiaochao Ma 16227e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16237e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1624ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1625ed398213SEd Tanous 1626002d39b4SEd Tanous .methods(boost::beast::http::verb::delete_)( 1627002d39b4SEd Tanous [&app](const crow::Request& req, 1628002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 162945ca1b86SEd Tanous const std::string& param) { 16303ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1631336e96c6SChicago Duan { 163245ca1b86SEd Tanous return; 163345ca1b86SEd Tanous } 1634336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1635336e96c6SChicago Duan 16367e860f15SJohn Edward Broadbent std::string entryID = param; 1637336e96c6SChicago Duan 1638336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1639336e96c6SChicago Duan 1640336e96c6SChicago Duan // Process response from Logging service. 1641002d39b4SEd Tanous auto respHandler = 1642002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec) { 1643002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1644336e96c6SChicago Duan if (ec) 1645336e96c6SChicago Duan { 16463de8d8baSGeorge Liu if (ec.value() == EBADR) 16473de8d8baSGeorge Liu { 164845ca1b86SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 164945ca1b86SEd Tanous entryID); 16503de8d8baSGeorge Liu return; 16513de8d8baSGeorge Liu } 1652336e96c6SChicago Duan // TODO Handle for specific error code 16530fda0f12SGeorge Liu BMCWEB_LOG_ERROR 16540fda0f12SGeorge Liu << "EventLogEntry (DBus) doDelete respHandler got error " 1655336e96c6SChicago Duan << ec; 1656336e96c6SChicago Duan asyncResp->res.result( 1657336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1658336e96c6SChicago Duan return; 1659336e96c6SChicago Duan } 1660336e96c6SChicago Duan 1661336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1662336e96c6SChicago Duan }; 1663336e96c6SChicago Duan 1664336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1665336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1666336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1667336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1668336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 16697e860f15SJohn Edward Broadbent }); 1670400fd1fbSAdriana Kobylak } 1671400fd1fbSAdriana Kobylak 16727e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1673400fd1fbSAdriana Kobylak { 16740fda0f12SGeorge Liu BMCWEB_ROUTE( 16750fda0f12SGeorge Liu app, 16760fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/attachment") 1677ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 16787e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 167945ca1b86SEd Tanous [&app](const crow::Request& req, 16807e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 168145ca1b86SEd Tanous const std::string& param) { 16823ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 16837e860f15SJohn Edward Broadbent { 168445ca1b86SEd Tanous return; 168545ca1b86SEd Tanous } 1686002d39b4SEd Tanous if (!http_helpers::isOctetAccepted(req.getHeaderValue("Accept"))) 1687400fd1fbSAdriana Kobylak { 1688002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 1689400fd1fbSAdriana Kobylak return; 1690400fd1fbSAdriana Kobylak } 1691400fd1fbSAdriana Kobylak 16927e860f15SJohn Edward Broadbent std::string entryID = param; 1693400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1694400fd1fbSAdriana Kobylak 1695400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 1696002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec, 1697400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 1698400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 1699400fd1fbSAdriana Kobylak { 1700002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "EventLogAttachment", 1701002d39b4SEd Tanous entryID); 1702400fd1fbSAdriana Kobylak return; 1703400fd1fbSAdriana Kobylak } 1704400fd1fbSAdriana Kobylak if (ec) 1705400fd1fbSAdriana Kobylak { 1706400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1707400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1708400fd1fbSAdriana Kobylak return; 1709400fd1fbSAdriana Kobylak } 1710400fd1fbSAdriana Kobylak 1711400fd1fbSAdriana Kobylak int fd = -1; 1712400fd1fbSAdriana Kobylak fd = dup(unixfd); 1713400fd1fbSAdriana Kobylak if (fd == -1) 1714400fd1fbSAdriana Kobylak { 1715400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1716400fd1fbSAdriana Kobylak return; 1717400fd1fbSAdriana Kobylak } 1718400fd1fbSAdriana Kobylak 1719400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 1720400fd1fbSAdriana Kobylak if (size == -1) 1721400fd1fbSAdriana Kobylak { 1722400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1723400fd1fbSAdriana Kobylak return; 1724400fd1fbSAdriana Kobylak } 1725400fd1fbSAdriana Kobylak 1726400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 1727400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 1728400fd1fbSAdriana Kobylak if (size > maxFileSize) 1729400fd1fbSAdriana Kobylak { 1730002d39b4SEd Tanous BMCWEB_LOG_ERROR << "File size exceeds maximum allowed size of " 1731400fd1fbSAdriana Kobylak << maxFileSize; 1732400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1733400fd1fbSAdriana Kobylak return; 1734400fd1fbSAdriana Kobylak } 1735400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 1736400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 1737400fd1fbSAdriana Kobylak if (rc == -1) 1738400fd1fbSAdriana Kobylak { 1739400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1740400fd1fbSAdriana Kobylak return; 1741400fd1fbSAdriana Kobylak } 1742400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 1743400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 1744400fd1fbSAdriana Kobylak { 1745400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1746400fd1fbSAdriana Kobylak return; 1747400fd1fbSAdriana Kobylak } 1748400fd1fbSAdriana Kobylak close(fd); 1749400fd1fbSAdriana Kobylak 1750400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 1751002d39b4SEd Tanous std::string output = crow::utility::base64encode(strData); 1752400fd1fbSAdriana Kobylak 1753d9f6c621SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::content_type, 1754400fd1fbSAdriana Kobylak "application/octet-stream"); 1755d9f6c621SEd Tanous asyncResp->res.addHeader( 1756d9f6c621SEd Tanous boost::beast::http::field::content_transfer_encoding, "Base64"); 1757400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 1758400fd1fbSAdriana Kobylak }, 1759400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 1760400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 1761400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 17627e860f15SJohn Edward Broadbent }); 17631da66f75SEd Tanous } 17641da66f75SEd Tanous 1765b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 1766b7028ebfSSpencer Ku 1767b7028ebfSSpencer Ku inline bool 1768b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 1769b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 1770b7028ebfSSpencer Ku { 1771b7028ebfSSpencer Ku std::error_code ec; 1772b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 1773b7028ebfSSpencer Ku if (ec) 1774b7028ebfSSpencer Ku { 1775b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << ec.message(); 1776b7028ebfSSpencer Ku return false; 1777b7028ebfSSpencer Ku } 1778b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 1779b7028ebfSSpencer Ku { 1780b7028ebfSSpencer Ku std::string filename = it.path().filename(); 1781b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 1782b7028ebfSSpencer Ku // path 178311ba3979SEd Tanous if (filename.starts_with("log")) 1784b7028ebfSSpencer Ku { 1785b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 1786b7028ebfSSpencer Ku } 1787b7028ebfSSpencer Ku } 1788b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 1789b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 1790b7028ebfSSpencer Ku // descending order. 1791b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 1792b7028ebfSSpencer Ku AlphanumLess<std::string>()); 1793b7028ebfSSpencer Ku 1794b7028ebfSSpencer Ku return true; 1795b7028ebfSSpencer Ku } 1796b7028ebfSSpencer Ku 179702cad96eSEd Tanous inline bool getHostLoggerEntries( 179802cad96eSEd Tanous const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip, 179902cad96eSEd Tanous uint64_t top, std::vector<std::string>& logEntries, size_t& logCount) 1800b7028ebfSSpencer Ku { 1801b7028ebfSSpencer Ku GzFileReader logFile; 1802b7028ebfSSpencer Ku 1803b7028ebfSSpencer Ku // Go though all log files and expose host logs. 1804b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 1805b7028ebfSSpencer Ku { 1806b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 1807b7028ebfSSpencer Ku { 1808b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to expose host logs"; 1809b7028ebfSSpencer Ku return false; 1810b7028ebfSSpencer Ku } 1811b7028ebfSSpencer Ku } 1812b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 1813b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 1814b7028ebfSSpencer Ku if (!lastMessage.empty()) 1815b7028ebfSSpencer Ku { 1816b7028ebfSSpencer Ku logCount++; 1817b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 1818b7028ebfSSpencer Ku { 1819b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 1820b7028ebfSSpencer Ku } 1821b7028ebfSSpencer Ku } 1822b7028ebfSSpencer Ku return true; 1823b7028ebfSSpencer Ku } 1824b7028ebfSSpencer Ku 1825b7028ebfSSpencer Ku inline void fillHostLoggerEntryJson(const std::string& logEntryID, 1826b7028ebfSSpencer Ku const std::string& msg, 18276d6574c9SJason M. Bills nlohmann::json::object_t& logEntryJson) 1828b7028ebfSSpencer Ku { 1829b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 18306d6574c9SJason M. Bills logEntryJson["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 18316d6574c9SJason M. Bills logEntryJson["@odata.id"] = 1832b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/" + 18336d6574c9SJason M. Bills logEntryID; 18346d6574c9SJason M. Bills logEntryJson["Name"] = "Host Logger Entry"; 18356d6574c9SJason M. Bills logEntryJson["Id"] = logEntryID; 18366d6574c9SJason M. Bills logEntryJson["Message"] = msg; 18376d6574c9SJason M. Bills logEntryJson["EntryType"] = "Oem"; 18386d6574c9SJason M. Bills logEntryJson["Severity"] = "OK"; 18396d6574c9SJason M. Bills logEntryJson["OemRecordFormat"] = "Host Logger Entry"; 1840b7028ebfSSpencer Ku } 1841b7028ebfSSpencer Ku 1842b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 1843b7028ebfSSpencer Ku { 1844b7028ebfSSpencer Ku BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/HostLogger/") 1845b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 18461476687dSEd Tanous .methods(boost::beast::http::verb::get)( 18471476687dSEd Tanous [&app](const crow::Request& req, 18481476687dSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 18493ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 185045ca1b86SEd Tanous { 185145ca1b86SEd Tanous return; 185245ca1b86SEd Tanous } 1853b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1854b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"; 1855b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1856b7028ebfSSpencer Ku "#LogService.v1_1_0.LogService"; 1857b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 1858b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 1859b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 18601476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 18611476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 1862b7028ebfSSpencer Ku }); 1863b7028ebfSSpencer Ku } 1864b7028ebfSSpencer Ku 1865b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 1866b7028ebfSSpencer Ku { 1867b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 1868b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/") 1869b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 1870002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1871002d39b4SEd Tanous [&app](const crow::Request& req, 1872002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1873c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1874c937d2bfSEd Tanous .canDelegateTop = true, 1875c937d2bfSEd Tanous .canDelegateSkip = true, 1876c937d2bfSEd Tanous }; 1877c937d2bfSEd Tanous query_param::Query delegatedQuery; 1878c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 18793ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 1880b7028ebfSSpencer Ku { 1881b7028ebfSSpencer Ku return; 1882b7028ebfSSpencer Ku } 1883b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1884b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 1885b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1886b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 1887b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 1888b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 1889b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 18900fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1891b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 1892b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 1893b7028ebfSSpencer Ku 1894b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 1895b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 1896b7028ebfSSpencer Ku { 1897b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 1898b7028ebfSSpencer Ku return; 1899b7028ebfSSpencer Ku } 19003648c8beSEd Tanous // If we weren't provided top and skip limits, use the defaults. 19013648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 19023648c8beSEd Tanous size_t top = 19033648c8beSEd Tanous delegatedQuery.top.value_or(query_param::maxEntriesPerPage); 1904b7028ebfSSpencer Ku size_t logCount = 0; 1905b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 1906b7028ebfSSpencer Ku // control by skip and top. 1907b7028ebfSSpencer Ku std::vector<std::string> logEntries; 19083648c8beSEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries, 19093648c8beSEd Tanous logCount)) 1910b7028ebfSSpencer Ku { 1911b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 1912b7028ebfSSpencer Ku return; 1913b7028ebfSSpencer Ku } 1914b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 1915b7028ebfSSpencer Ku // log count 191626f6976fSEd Tanous if (logEntries.empty()) 1917b7028ebfSSpencer Ku { 1918b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 1919b7028ebfSSpencer Ku return; 1920b7028ebfSSpencer Ku } 192126f6976fSEd Tanous if (!logEntries.empty()) 1922b7028ebfSSpencer Ku { 1923b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 1924b7028ebfSSpencer Ku { 19256d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 19263648c8beSEd Tanous fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i], 19273648c8beSEd Tanous hostLogEntry); 19286d6574c9SJason M. Bills logEntryArray.push_back(std::move(hostLogEntry)); 1929b7028ebfSSpencer Ku } 1930b7028ebfSSpencer Ku 1931b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 19323648c8beSEd Tanous if (skip + top < logCount) 1933b7028ebfSSpencer Ku { 1934b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 19350fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/HostLogger/Entries?$skip=" + 19363648c8beSEd Tanous std::to_string(skip + top); 1937b7028ebfSSpencer Ku } 1938b7028ebfSSpencer Ku } 1939b7028ebfSSpencer Ku }); 1940b7028ebfSSpencer Ku } 1941b7028ebfSSpencer Ku 1942b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 1943b7028ebfSSpencer Ku { 1944b7028ebfSSpencer Ku BMCWEB_ROUTE( 1945b7028ebfSSpencer Ku app, "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/<str>/") 1946b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 1947b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 194845ca1b86SEd Tanous [&app](const crow::Request& req, 1949b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1950b7028ebfSSpencer Ku const std::string& param) { 19513ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 195245ca1b86SEd Tanous { 195345ca1b86SEd Tanous return; 195445ca1b86SEd Tanous } 1955b7028ebfSSpencer Ku const std::string& targetID = param; 1956b7028ebfSSpencer Ku 1957b7028ebfSSpencer Ku uint64_t idInt = 0; 1958ca45aa3cSEd Tanous 1959ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 1960ca45aa3cSEd Tanous const char* end = targetID.data() + targetID.size(); 1961ca45aa3cSEd Tanous 1962ca45aa3cSEd Tanous auto [ptr, ec] = std::from_chars(targetID.data(), end, idInt); 1963b7028ebfSSpencer Ku if (ec == std::errc::invalid_argument) 1964b7028ebfSSpencer Ku { 1965ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 1966b7028ebfSSpencer Ku return; 1967b7028ebfSSpencer Ku } 1968b7028ebfSSpencer Ku if (ec == std::errc::result_out_of_range) 1969b7028ebfSSpencer Ku { 1970ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 1971b7028ebfSSpencer Ku return; 1972b7028ebfSSpencer Ku } 1973b7028ebfSSpencer Ku 1974b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 1975b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 1976b7028ebfSSpencer Ku { 1977b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 1978b7028ebfSSpencer Ku return; 1979b7028ebfSSpencer Ku } 1980b7028ebfSSpencer Ku 1981b7028ebfSSpencer Ku size_t logCount = 0; 19823648c8beSEd Tanous size_t top = 1; 1983b7028ebfSSpencer Ku std::vector<std::string> logEntries; 1984b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 1985b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 1986b7028ebfSSpencer Ku // get that entry 1987002d39b4SEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries, 1988002d39b4SEd Tanous logCount)) 1989b7028ebfSSpencer Ku { 1990b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 1991b7028ebfSSpencer Ku return; 1992b7028ebfSSpencer Ku } 1993b7028ebfSSpencer Ku 1994b7028ebfSSpencer Ku if (!logEntries.empty()) 1995b7028ebfSSpencer Ku { 19966d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 19976d6574c9SJason M. Bills fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry); 19986d6574c9SJason M. Bills asyncResp->res.jsonValue.update(hostLogEntry); 1999b7028ebfSSpencer Ku return; 2000b7028ebfSSpencer Ku } 2001b7028ebfSSpencer Ku 2002b7028ebfSSpencer Ku // Requested ID was not found 2003ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2004b7028ebfSSpencer Ku }); 2005b7028ebfSSpencer Ku } 2006b7028ebfSSpencer Ku 2007fdd26906SClaire Weinan constexpr char const* dumpManagerIface = 2008fdd26906SClaire Weinan "xyz.openbmc_project.Collection.DeleteAll"; 2009fdd26906SClaire Weinan inline void handleLogServicesCollectionGet( 2010fdd26906SClaire Weinan crow::App& app, const crow::Request& req, 2011fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 20121da66f75SEd Tanous { 20133ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 201445ca1b86SEd Tanous { 201545ca1b86SEd Tanous return; 201645ca1b86SEd Tanous } 20177e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 20187e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2019e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 20201da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2021e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 2022e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 2023002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 2024e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 20251da66f75SEd Tanous "Collection of LogServices for this Manager"; 2026002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 2027c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 2028fdd26906SClaire Weinan 2029c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 2030c4bf6374SJason M. Bills logServiceArray.push_back( 2031002d39b4SEd Tanous {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 2032c4bf6374SJason M. Bills #endif 2033fdd26906SClaire Weinan 2034fdd26906SClaire Weinan asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); 2035fdd26906SClaire Weinan 2036fdd26906SClaire Weinan #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 2037fdd26906SClaire Weinan auto respHandler = 2038fdd26906SClaire Weinan [asyncResp]( 2039fdd26906SClaire Weinan const boost::system::error_code ec, 2040fdd26906SClaire Weinan const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 2041fdd26906SClaire Weinan if (ec) 2042fdd26906SClaire Weinan { 2043fdd26906SClaire Weinan BMCWEB_LOG_ERROR 2044fdd26906SClaire Weinan << "handleLogServicesCollectionGet respHandler got error " 2045fdd26906SClaire Weinan << ec; 2046fdd26906SClaire Weinan // Assume that getting an error simply means there are no dump 2047fdd26906SClaire Weinan // LogServices. Return without adding any error response. 2048fdd26906SClaire Weinan return; 2049fdd26906SClaire Weinan } 2050fdd26906SClaire Weinan 2051fdd26906SClaire Weinan nlohmann::json& logServiceArrayLocal = 2052fdd26906SClaire Weinan asyncResp->res.jsonValue["Members"]; 2053fdd26906SClaire Weinan 2054fdd26906SClaire Weinan for (const std::string& path : subTreePaths) 2055fdd26906SClaire Weinan { 2056fdd26906SClaire Weinan if (path == "/xyz/openbmc_project/dump/bmc") 2057fdd26906SClaire Weinan { 2058fdd26906SClaire Weinan logServiceArrayLocal.push_back( 2059fdd26906SClaire Weinan {{"@odata.id", 2060fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 2061fdd26906SClaire Weinan } 2062fdd26906SClaire Weinan else if (path == "/xyz/openbmc_project/dump/faultlog") 2063fdd26906SClaire Weinan { 2064fdd26906SClaire Weinan logServiceArrayLocal.push_back( 2065fdd26906SClaire Weinan {{"@odata.id", 2066fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog"}}); 2067fdd26906SClaire Weinan } 2068fdd26906SClaire Weinan } 2069fdd26906SClaire Weinan 2070e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2071fdd26906SClaire Weinan logServiceArrayLocal.size(); 2072fdd26906SClaire Weinan }; 2073fdd26906SClaire Weinan 2074fdd26906SClaire Weinan crow::connections::systemBus->async_method_call( 2075fdd26906SClaire Weinan respHandler, "xyz.openbmc_project.ObjectMapper", 2076fdd26906SClaire Weinan "/xyz/openbmc_project/object_mapper", 2077fdd26906SClaire Weinan "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 2078fdd26906SClaire Weinan "/xyz/openbmc_project/dump", 0, 2079fdd26906SClaire Weinan std::array<const char*, 1>{dumpManagerIface}); 2080fdd26906SClaire Weinan #endif 2081fdd26906SClaire Weinan } 2082fdd26906SClaire Weinan 2083fdd26906SClaire Weinan inline void requestRoutesBMCLogServiceCollection(App& app) 2084fdd26906SClaire Weinan { 2085fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 2086fdd26906SClaire Weinan .privileges(redfish::privileges::getLogServiceCollection) 2087fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2088fdd26906SClaire Weinan std::bind_front(handleLogServicesCollectionGet, std::ref(app))); 2089e1f26343SJason M. Bills } 2090e1f26343SJason M. Bills 20917e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 2092e1f26343SJason M. Bills { 20937e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 2094ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 20957e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 209645ca1b86SEd Tanous [&app](const crow::Request& req, 209745ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 20983ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 20997e860f15SJohn Edward Broadbent { 210045ca1b86SEd Tanous return; 210145ca1b86SEd Tanous } 2102e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2103e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 21040f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 21050f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 2106002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 2107002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 2108c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 2109e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 21107c8c4058STejas Patil 21117c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 2112*2b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 2113002d39b4SEd Tanous asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 21147c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 21157c8c4058STejas Patil redfishDateTimeOffset.second; 21167c8c4058STejas Patil 21171476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 21181476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 21197e860f15SJohn Edward Broadbent }); 2120e1f26343SJason M. Bills } 2121e1f26343SJason M. Bills 21223a48b3a2SJason M. Bills static int 21233a48b3a2SJason M. Bills fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 2124e1f26343SJason M. Bills sd_journal* journal, 21253a48b3a2SJason M. Bills nlohmann::json::object_t& bmcJournalLogEntryJson) 2126e1f26343SJason M. Bills { 2127e1f26343SJason M. Bills // Get the Log Entry contents 2128e1f26343SJason M. Bills int ret = 0; 2129e1f26343SJason M. Bills 2130a8fe54f0SJason M. Bills std::string message; 2131a8fe54f0SJason M. Bills std::string_view syslogID; 2132a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 2133a8fe54f0SJason M. Bills if (ret < 0) 2134a8fe54f0SJason M. Bills { 2135a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 2136a8fe54f0SJason M. Bills << strerror(-ret); 2137a8fe54f0SJason M. Bills } 2138a8fe54f0SJason M. Bills if (!syslogID.empty()) 2139a8fe54f0SJason M. Bills { 2140a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 2141a8fe54f0SJason M. Bills } 2142a8fe54f0SJason M. Bills 214339e77504SEd Tanous std::string_view msg; 214416428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 2145e1f26343SJason M. Bills if (ret < 0) 2146e1f26343SJason M. Bills { 2147e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 2148e1f26343SJason M. Bills return 1; 2149e1f26343SJason M. Bills } 2150a8fe54f0SJason M. Bills message += std::string(msg); 2151e1f26343SJason M. Bills 2152e1f26343SJason M. Bills // Get the severity from the PRIORITY field 2153271584abSEd Tanous long int severity = 8; // Default to an invalid priority 215416428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 2155e1f26343SJason M. Bills if (ret < 0) 2156e1f26343SJason M. Bills { 2157e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 2158e1f26343SJason M. Bills } 2159e1f26343SJason M. Bills 2160e1f26343SJason M. Bills // Get the Created time from the timestamp 216116428a1aSJason M. Bills std::string entryTimeStr; 216216428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 2163e1f26343SJason M. Bills { 216416428a1aSJason M. Bills return 1; 2165e1f26343SJason M. Bills } 2166e1f26343SJason M. Bills 2167e1f26343SJason M. Bills // Fill in the log entry with the gathered data 216884afc48bSJason M. Bills bmcJournalLogEntryJson["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 216984afc48bSJason M. Bills bmcJournalLogEntryJson["@odata.id"] = 217084afc48bSJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 217184afc48bSJason M. Bills bmcJournalLogEntryID; 217284afc48bSJason M. Bills bmcJournalLogEntryJson["Name"] = "BMC Journal Entry"; 217384afc48bSJason M. Bills bmcJournalLogEntryJson["Id"] = bmcJournalLogEntryID; 217484afc48bSJason M. Bills bmcJournalLogEntryJson["Message"] = std::move(message); 217584afc48bSJason M. Bills bmcJournalLogEntryJson["EntryType"] = "Oem"; 217684afc48bSJason M. Bills bmcJournalLogEntryJson["Severity"] = severity <= 2 ? "Critical" 2177738c1e61SPatrick Williams : severity <= 4 ? "Warning" 217884afc48bSJason M. Bills : "OK"; 217984afc48bSJason M. Bills bmcJournalLogEntryJson["OemRecordFormat"] = "BMC Journal Entry"; 218084afc48bSJason M. Bills bmcJournalLogEntryJson["Created"] = std::move(entryTimeStr); 2181e1f26343SJason M. Bills return 0; 2182e1f26343SJason M. Bills } 2183e1f26343SJason M. Bills 21847e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 2185e1f26343SJason M. Bills { 21867e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 2187ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 2188002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2189002d39b4SEd Tanous [&app](const crow::Request& req, 2190002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2191c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2192c937d2bfSEd Tanous .canDelegateTop = true, 2193c937d2bfSEd Tanous .canDelegateSkip = true, 2194c937d2bfSEd Tanous }; 2195c937d2bfSEd Tanous query_param::Query delegatedQuery; 2196c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 21973ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 2198193ad2faSJason M. Bills { 2199193ad2faSJason M. Bills return; 2200193ad2faSJason M. Bills } 22013648c8beSEd Tanous 22023648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 22033648c8beSEd Tanous size_t top = 22043648c8beSEd Tanous delegatedQuery.top.value_or(query_param::maxEntriesPerPage); 22053648c8beSEd Tanous 22067e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 22077e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2208e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2209e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 22100f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 22110f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 2212e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 2213e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2214e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 22150fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2216e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2217e1f26343SJason M. Bills 22187e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 22197e860f15SJohn Edward Broadbent // unique ID for each entry 2220e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2221e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2222e1f26343SJason M. Bills if (ret < 0) 2223e1f26343SJason M. Bills { 2224002d39b4SEd Tanous BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 2225f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2226e1f26343SJason M. Bills return; 2227e1f26343SJason M. Bills } 22280fda0f12SGeorge Liu std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 22290fda0f12SGeorge Liu journalTmp, sd_journal_close); 2230e1f26343SJason M. Bills journalTmp = nullptr; 2231b01bf299SEd Tanous uint64_t entryCount = 0; 2232e85d6b16SJason M. Bills // Reset the unique ID on the first entry 2233e85d6b16SJason M. Bills bool firstEntry = true; 2234e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 2235e1f26343SJason M. Bills { 2236193ad2faSJason M. Bills entryCount++; 22377e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 22387e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 22393648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 2240193ad2faSJason M. Bills { 2241193ad2faSJason M. Bills continue; 2242193ad2faSJason M. Bills } 2243193ad2faSJason M. Bills 224416428a1aSJason M. Bills std::string idStr; 2245e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2246e1f26343SJason M. Bills { 2247e1f26343SJason M. Bills continue; 2248e1f26343SJason M. Bills } 2249e85d6b16SJason M. Bills firstEntry = false; 2250e85d6b16SJason M. Bills 22513a48b3a2SJason M. Bills nlohmann::json::object_t bmcJournalLogEntry; 2252c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 2253c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 2254e1f26343SJason M. Bills { 2255f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2256e1f26343SJason M. Bills return; 2257e1f26343SJason M. Bills } 22583a48b3a2SJason M. Bills logEntryArray.push_back(std::move(bmcJournalLogEntry)); 2259e1f26343SJason M. Bills } 2260193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 22613648c8beSEd Tanous if (skip + top < entryCount) 2262193ad2faSJason M. Bills { 2263193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 22640fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 22653648c8beSEd Tanous std::to_string(skip + top); 2266193ad2faSJason M. Bills } 22677e860f15SJohn Edward Broadbent }); 2268e1f26343SJason M. Bills } 2269e1f26343SJason M. Bills 22707e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 2271e1f26343SJason M. Bills { 22727e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 22737e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 2274ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 22757e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 227645ca1b86SEd Tanous [&app](const crow::Request& req, 22777e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22787e860f15SJohn Edward Broadbent const std::string& entryID) { 22793ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 228045ca1b86SEd Tanous { 228145ca1b86SEd Tanous return; 228245ca1b86SEd Tanous } 2283e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2284e1f26343SJason M. Bills uint64_t ts = 0; 2285271584abSEd Tanous uint64_t index = 0; 22868d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2287e1f26343SJason M. Bills { 228816428a1aSJason M. Bills return; 2289e1f26343SJason M. Bills } 2290e1f26343SJason M. Bills 2291e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2292e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2293e1f26343SJason M. Bills if (ret < 0) 2294e1f26343SJason M. Bills { 2295002d39b4SEd Tanous BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 2296f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2297e1f26343SJason M. Bills return; 2298e1f26343SJason M. Bills } 2299002d39b4SEd Tanous std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 2300002d39b4SEd Tanous journalTmp, sd_journal_close); 2301e1f26343SJason M. Bills journalTmp = nullptr; 23027e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 23037e860f15SJohn Edward Broadbent // index tracking the unique ID 2304af07e3f5SJason M. Bills std::string idStr; 2305af07e3f5SJason M. Bills bool firstEntry = true; 2306e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 23072056b6d1SManojkiran Eda if (ret < 0) 23082056b6d1SManojkiran Eda { 23092056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 23102056b6d1SManojkiran Eda << strerror(-ret); 23112056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 23122056b6d1SManojkiran Eda return; 23132056b6d1SManojkiran Eda } 2314271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2315e1f26343SJason M. Bills { 2316e1f26343SJason M. Bills sd_journal_next(journal.get()); 2317af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2318af07e3f5SJason M. Bills { 2319af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2320af07e3f5SJason M. Bills return; 2321af07e3f5SJason M. Bills } 2322af07e3f5SJason M. Bills firstEntry = false; 2323af07e3f5SJason M. Bills } 2324c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2325af07e3f5SJason M. Bills if (idStr != entryID) 2326c4bf6374SJason M. Bills { 2327ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2328c4bf6374SJason M. Bills return; 2329c4bf6374SJason M. Bills } 2330c4bf6374SJason M. Bills 23313a48b3a2SJason M. Bills nlohmann::json::object_t bmcJournalLogEntry; 2332c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 23333a48b3a2SJason M. Bills bmcJournalLogEntry) != 0) 2334e1f26343SJason M. Bills { 2335f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2336e1f26343SJason M. Bills return; 2337e1f26343SJason M. Bills } 2338d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcJournalLogEntry); 23397e860f15SJohn Edward Broadbent }); 2340c9bb6861Sraviteja-b } 2341c9bb6861Sraviteja-b 2342fdd26906SClaire Weinan inline void 2343fdd26906SClaire Weinan getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2344fdd26906SClaire Weinan const std::string& dumpType) 2345c9bb6861Sraviteja-b { 2346fdd26906SClaire Weinan std::string dumpPath; 2347fdd26906SClaire Weinan std::string overWritePolicy; 2348fdd26906SClaire Weinan bool collectDiagnosticDataSupported = false; 2349fdd26906SClaire Weinan 2350fdd26906SClaire Weinan if (dumpType == "BMC") 235145ca1b86SEd Tanous { 2352fdd26906SClaire Weinan dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump"; 2353fdd26906SClaire Weinan overWritePolicy = "WrapsWhenFull"; 2354fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2355fdd26906SClaire Weinan } 2356fdd26906SClaire Weinan else if (dumpType == "FaultLog") 2357fdd26906SClaire Weinan { 2358fdd26906SClaire Weinan dumpPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog"; 2359fdd26906SClaire Weinan overWritePolicy = "Unknown"; 2360fdd26906SClaire Weinan collectDiagnosticDataSupported = false; 2361fdd26906SClaire Weinan } 2362fdd26906SClaire Weinan else if (dumpType == "System") 2363fdd26906SClaire Weinan { 2364fdd26906SClaire Weinan dumpPath = "/redfish/v1/Systems/system/LogServices/Dump"; 2365fdd26906SClaire Weinan overWritePolicy = "WrapsWhenFull"; 2366fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2367fdd26906SClaire Weinan } 2368fdd26906SClaire Weinan else 2369fdd26906SClaire Weinan { 2370fdd26906SClaire Weinan BMCWEB_LOG_ERROR << "getDumpServiceInfo() invalid dump type: " 2371fdd26906SClaire Weinan << dumpType; 2372fdd26906SClaire Weinan messages::internalError(asyncResp->res); 237345ca1b86SEd Tanous return; 237445ca1b86SEd Tanous } 2375fdd26906SClaire Weinan 2376fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = dumpPath; 2377fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; 2378c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 2379fdd26906SClaire Weinan asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; 2380fdd26906SClaire Weinan asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); 2381fdd26906SClaire Weinan asyncResp->res.jsonValue["OverWritePolicy"] = std::move(overWritePolicy); 23827c8c4058STejas Patil 23837c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 2384*2b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 23850fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 23867c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 23877c8c4058STejas Patil redfishDateTimeOffset.second; 23887c8c4058STejas Patil 2389fdd26906SClaire Weinan asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; 2390002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 2391fdd26906SClaire Weinan dumpPath + "/Actions/LogService.ClearLog"; 2392fdd26906SClaire Weinan 2393fdd26906SClaire Weinan if (collectDiagnosticDataSupported) 2394fdd26906SClaire Weinan { 2395002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 23961476687dSEd Tanous ["target"] = 2397fdd26906SClaire Weinan dumpPath + "/Actions/LogService.CollectDiagnosticData"; 2398fdd26906SClaire Weinan } 2399c9bb6861Sraviteja-b } 2400c9bb6861Sraviteja-b 2401fdd26906SClaire Weinan inline void handleLogServicesDumpServiceGet( 2402fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2403fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 24047e860f15SJohn Edward Broadbent { 24053ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 240645ca1b86SEd Tanous { 240745ca1b86SEd Tanous return; 240845ca1b86SEd Tanous } 2409fdd26906SClaire Weinan getDumpServiceInfo(asyncResp, dumpType); 2410fdd26906SClaire Weinan } 2411c9bb6861Sraviteja-b 2412fdd26906SClaire Weinan inline void handleLogServicesDumpEntriesCollectionGet( 2413fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2414fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2415fdd26906SClaire Weinan { 2416fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2417fdd26906SClaire Weinan { 2418fdd26906SClaire Weinan return; 2419fdd26906SClaire Weinan } 2420fdd26906SClaire Weinan getDumpEntryCollection(asyncResp, dumpType); 2421fdd26906SClaire Weinan } 2422fdd26906SClaire Weinan 2423fdd26906SClaire Weinan inline void handleLogServicesDumpEntryGet( 2424fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2425fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2426fdd26906SClaire Weinan const std::string& dumpId) 2427fdd26906SClaire Weinan { 2428fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2429fdd26906SClaire Weinan { 2430fdd26906SClaire Weinan return; 2431fdd26906SClaire Weinan } 2432fdd26906SClaire Weinan getDumpEntryById(asyncResp, dumpId, dumpType); 2433fdd26906SClaire Weinan } 2434fdd26906SClaire Weinan 2435fdd26906SClaire Weinan inline void handleLogServicesDumpEntryDelete( 2436fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2437fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2438fdd26906SClaire Weinan const std::string& dumpId) 2439fdd26906SClaire Weinan { 2440fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2441fdd26906SClaire Weinan { 2442fdd26906SClaire Weinan return; 2443fdd26906SClaire Weinan } 2444fdd26906SClaire Weinan deleteDumpEntry(asyncResp, dumpId, dumpType); 2445fdd26906SClaire Weinan } 2446fdd26906SClaire Weinan 2447fdd26906SClaire Weinan inline void handleLogServicesDumpCollectDiagnosticDataPost( 2448fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2449fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2450fdd26906SClaire Weinan { 2451fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2452fdd26906SClaire Weinan { 2453fdd26906SClaire Weinan return; 2454fdd26906SClaire Weinan } 2455fdd26906SClaire Weinan createDump(asyncResp, req, dumpType); 2456fdd26906SClaire Weinan } 2457fdd26906SClaire Weinan 2458fdd26906SClaire Weinan inline void handleLogServicesDumpClearLogPost( 2459fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2460fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2461fdd26906SClaire Weinan { 2462fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2463fdd26906SClaire Weinan { 2464fdd26906SClaire Weinan return; 2465fdd26906SClaire Weinan } 2466fdd26906SClaire Weinan clearDump(asyncResp, dumpType); 2467fdd26906SClaire Weinan } 2468fdd26906SClaire Weinan 2469fdd26906SClaire Weinan inline void requestRoutesBMCDumpService(App& app) 2470fdd26906SClaire Weinan { 2471fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2472fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2473fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2474fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "BMC")); 2475fdd26906SClaire Weinan } 2476fdd26906SClaire Weinan 2477fdd26906SClaire Weinan inline void requestRoutesBMCDumpEntryCollection(App& app) 2478fdd26906SClaire Weinan { 2479fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2480fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2481fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2482fdd26906SClaire Weinan handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); 2483c9bb6861Sraviteja-b } 2484c9bb6861Sraviteja-b 24857e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2486c9bb6861Sraviteja-b { 24877e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24887e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2489ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2490fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2491fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "BMC")); 2492fdd26906SClaire Weinan 24937e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24947e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2495ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 2496fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2497fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); 2498c9bb6861Sraviteja-b } 2499c9bb6861Sraviteja-b 25007e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2501c9bb6861Sraviteja-b { 25020fda0f12SGeorge Liu BMCWEB_ROUTE( 25030fda0f12SGeorge Liu app, 25040fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2505ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 25067e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 2507fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, 2508fdd26906SClaire Weinan std::ref(app), "BMC")); 2509a43be80fSAsmitha Karunanithi } 2510a43be80fSAsmitha Karunanithi 25117e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 251280319af1SAsmitha Karunanithi { 25130fda0f12SGeorge Liu BMCWEB_ROUTE( 25140fda0f12SGeorge Liu app, 25150fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog/") 2516ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 2517fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 2518fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); 251945ca1b86SEd Tanous } 2520fdd26906SClaire Weinan 2521fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpService(App& app) 2522fdd26906SClaire Weinan { 2523fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/") 2524fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2525fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2526fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); 2527fdd26906SClaire Weinan } 2528fdd26906SClaire Weinan 2529fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntryCollection(App& app) 2530fdd26906SClaire Weinan { 2531fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/") 2532fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2533fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2534fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpEntriesCollectionGet, 2535fdd26906SClaire Weinan std::ref(app), "FaultLog")); 2536fdd26906SClaire Weinan } 2537fdd26906SClaire Weinan 2538fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntry(App& app) 2539fdd26906SClaire Weinan { 2540fdd26906SClaire Weinan BMCWEB_ROUTE(app, 2541fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/") 2542fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntry) 2543fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2544fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); 2545fdd26906SClaire Weinan 2546fdd26906SClaire Weinan BMCWEB_ROUTE(app, 2547fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/") 2548fdd26906SClaire Weinan .privileges(redfish::privileges::deleteLogEntry) 2549fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2550fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); 2551fdd26906SClaire Weinan } 2552fdd26906SClaire Weinan 2553fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpClear(App& app) 2554fdd26906SClaire Weinan { 2555fdd26906SClaire Weinan BMCWEB_ROUTE( 2556fdd26906SClaire Weinan app, 2557fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Actions/LogService.ClearLog/") 2558fdd26906SClaire Weinan .privileges(redfish::privileges::postLogService) 2559fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 2560fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); 25615cb1dd27SAsmitha Karunanithi } 25625cb1dd27SAsmitha Karunanithi 25637e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 25645cb1dd27SAsmitha Karunanithi { 25657e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/") 2566ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 2567002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2568002d39b4SEd Tanous [&app](const crow::Request& req, 2569002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 25703ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 25717e860f15SJohn Edward Broadbent { 257245ca1b86SEd Tanous return; 257345ca1b86SEd Tanous } 25745cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 25755cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 25765cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2577d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 25785cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 257945ca1b86SEd Tanous asyncResp->res.jsonValue["Description"] = "System Dump LogService"; 25805cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 25815cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 25827c8c4058STejas Patil 25837c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 2584*2b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 258545ca1b86SEd Tanous asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 25867c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 25877c8c4058STejas Patil redfishDateTimeOffset.second; 25887c8c4058STejas Patil 25891476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 25901476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 2591002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 25921476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog"; 25931476687dSEd Tanous 2594002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 25951476687dSEd Tanous ["target"] = 25961476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData"; 25977e860f15SJohn Edward Broadbent }); 25985cb1dd27SAsmitha Karunanithi } 25995cb1dd27SAsmitha Karunanithi 26007e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 26017e860f15SJohn Edward Broadbent { 26027e860f15SJohn Edward Broadbent 26035cb1dd27SAsmitha Karunanithi /** 26045cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 26055cb1dd27SAsmitha Karunanithi */ 2606b2a3289dSAsmitha Karunanithi BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 2607ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 26087e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 260945ca1b86SEd Tanous [&app](const crow::Request& req, 2610864d6a17SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26113ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 261245ca1b86SEd Tanous { 261345ca1b86SEd Tanous return; 261445ca1b86SEd Tanous } 26155cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 26167e860f15SJohn Edward Broadbent }); 26175cb1dd27SAsmitha Karunanithi } 26185cb1dd27SAsmitha Karunanithi 26197e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 26205cb1dd27SAsmitha Karunanithi { 26217e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2622864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2623ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2624ed398213SEd Tanous 26257e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 262645ca1b86SEd Tanous [&app](const crow::Request& req, 26277e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26287e860f15SJohn Edward Broadbent const std::string& param) { 26293ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2630c7a6d660SClaire Weinan { 2631c7a6d660SClaire Weinan return; 2632c7a6d660SClaire Weinan } 2633c7a6d660SClaire Weinan getDumpEntryById(asyncResp, param, "System"); 26347e860f15SJohn Edward Broadbent }); 26358d1b46d7Szhanghch05 26367e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2637864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2638ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 26397e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 264045ca1b86SEd Tanous [&app](const crow::Request& req, 26417e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26427e860f15SJohn Edward Broadbent const std::string& param) { 26433ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 264445ca1b86SEd Tanous { 264545ca1b86SEd Tanous return; 264645ca1b86SEd Tanous } 26477e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "system"); 26487e860f15SJohn Edward Broadbent }); 26495cb1dd27SAsmitha Karunanithi } 2650c9bb6861Sraviteja-b 26517e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2652c9bb6861Sraviteja-b { 26530fda0f12SGeorge Liu BMCWEB_ROUTE( 26540fda0f12SGeorge Liu app, 26550fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2656ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 26577e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 265845ca1b86SEd Tanous [&app](const crow::Request& req, 265945ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26603ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 266145ca1b86SEd Tanous { 266245ca1b86SEd Tanous return; 266345ca1b86SEd Tanous } 266445ca1b86SEd Tanous createDump(asyncResp, req, "System"); 266545ca1b86SEd Tanous }); 2666a43be80fSAsmitha Karunanithi } 2667a43be80fSAsmitha Karunanithi 26687e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2669a43be80fSAsmitha Karunanithi { 26700fda0f12SGeorge Liu BMCWEB_ROUTE( 26710fda0f12SGeorge Liu app, 26720fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog/") 2673ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 26747e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 267545ca1b86SEd Tanous [&app](const crow::Request& req, 26767e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 26777e860f15SJohn Edward Broadbent 267845ca1b86SEd Tanous { 26793ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 268045ca1b86SEd Tanous { 268145ca1b86SEd Tanous return; 268245ca1b86SEd Tanous } 268345ca1b86SEd Tanous clearDump(asyncResp, "System"); 268445ca1b86SEd Tanous }); 2685013487e5Sraviteja-b } 2686013487e5Sraviteja-b 26877e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 26881da66f75SEd Tanous { 26893946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 26903946028dSAppaRao Puli // method for security reasons. 26911da66f75SEd Tanous /** 26921da66f75SEd Tanous * Functions triggers appropriate requests on DBus 26931da66f75SEd Tanous */ 26947e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 2695ed398213SEd Tanous // This is incorrect, should be: 2696ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2697432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 2698002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2699002d39b4SEd Tanous [&app](const crow::Request& req, 2700002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 27013ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 270245ca1b86SEd Tanous { 270345ca1b86SEd Tanous return; 270445ca1b86SEd Tanous } 27057e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 27067e860f15SJohn Edward Broadbent // SubRoute 27070f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2708424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2709e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 27108e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 27114f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 27124f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 27134f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2714e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2715e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 27167c8c4058STejas Patil 27177c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 2718*2b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 27197c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 27207c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 27217c8c4058STejas Patil redfishDateTimeOffset.second; 27227c8c4058STejas Patil 27231476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 27241476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2725002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 27261476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog"; 2727002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 27281476687dSEd Tanous ["target"] = 27291476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData"; 27307e860f15SJohn Edward Broadbent }); 27311da66f75SEd Tanous } 27321da66f75SEd Tanous 27337e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 27345b61b5e8SJason M. Bills { 27350fda0f12SGeorge Liu BMCWEB_ROUTE( 27360fda0f12SGeorge Liu app, 27370fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog/") 2738ed398213SEd Tanous // This is incorrect, should be: 2739ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2740432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 27417e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 274245ca1b86SEd Tanous [&app](const crow::Request& req, 27437e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 27443ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 274545ca1b86SEd Tanous { 274645ca1b86SEd Tanous return; 274745ca1b86SEd Tanous } 27485b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 27495b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2750cb13a392SEd Tanous const std::string&) { 27515b61b5e8SJason M. Bills if (ec) 27525b61b5e8SJason M. Bills { 27535b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 27545b61b5e8SJason M. Bills return; 27555b61b5e8SJason M. Bills } 27565b61b5e8SJason M. Bills messages::success(asyncResp->res); 27575b61b5e8SJason M. Bills }, 2758002d39b4SEd Tanous crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 27597e860f15SJohn Edward Broadbent }); 27605b61b5e8SJason M. Bills } 27615b61b5e8SJason M. Bills 27628d1b46d7Szhanghch05 static void 27638d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 27648d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 2765e855dd28SJason M. Bills { 2766043a0536SJohnathan Mantey auto getStoredLogCallback = 2767b9d36b47SEd Tanous [asyncResp, logID, 2768b9d36b47SEd Tanous &logEntryJson](const boost::system::error_code ec, 2769b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& params) { 2770e855dd28SJason M. Bills if (ec) 2771e855dd28SJason M. Bills { 2772e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 27731ddcf01aSJason M. Bills if (ec.value() == 27741ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 27751ddcf01aSJason M. Bills { 2776002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 27771ddcf01aSJason M. Bills } 27781ddcf01aSJason M. Bills else 27791ddcf01aSJason M. Bills { 2780e855dd28SJason M. Bills messages::internalError(asyncResp->res); 27811ddcf01aSJason M. Bills } 2782e855dd28SJason M. Bills return; 2783e855dd28SJason M. Bills } 2784043a0536SJohnathan Mantey 2785043a0536SJohnathan Mantey std::string timestamp{}; 2786043a0536SJohnathan Mantey std::string filename{}; 2787043a0536SJohnathan Mantey std::string logfile{}; 27882c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2789043a0536SJohnathan Mantey 2790043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2791e855dd28SJason M. Bills { 2792002d39b4SEd Tanous messages::resourceMissingAtURI(asyncResp->res, 2793002d39b4SEd Tanous crow::utility::urlFromPieces(logID)); 2794e855dd28SJason M. Bills return; 2795e855dd28SJason M. Bills } 2796e855dd28SJason M. Bills 2797043a0536SJohnathan Mantey std::string crashdumpURI = 2798e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2799043a0536SJohnathan Mantey logID + "/" + filename; 280084afc48bSJason M. Bills nlohmann::json::object_t logEntry; 280184afc48bSJason M. Bills logEntry["@odata.type"] = "#LogEntry.v1_7_0.LogEntry"; 280284afc48bSJason M. Bills logEntry["@odata.id"] = 280384afc48bSJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + logID; 280484afc48bSJason M. Bills logEntry["Name"] = "CPU Crashdump"; 280584afc48bSJason M. Bills logEntry["Id"] = logID; 280684afc48bSJason M. Bills logEntry["EntryType"] = "Oem"; 280784afc48bSJason M. Bills logEntry["AdditionalDataURI"] = std::move(crashdumpURI); 280884afc48bSJason M. Bills logEntry["DiagnosticDataType"] = "OEM"; 280984afc48bSJason M. Bills logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; 281084afc48bSJason M. Bills logEntry["Created"] = std::move(timestamp); 28112b20ef6eSJason M. Bills 28122b20ef6eSJason M. Bills // If logEntryJson references an array of LogEntry resources 28132b20ef6eSJason M. Bills // ('Members' list), then push this as a new entry, otherwise set it 28142b20ef6eSJason M. Bills // directly 28152b20ef6eSJason M. Bills if (logEntryJson.is_array()) 28162b20ef6eSJason M. Bills { 28172b20ef6eSJason M. Bills logEntryJson.push_back(logEntry); 28182b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 28192b20ef6eSJason M. Bills logEntryJson.size(); 28202b20ef6eSJason M. Bills } 28212b20ef6eSJason M. Bills else 28222b20ef6eSJason M. Bills { 2823d405bb51SJason M. Bills logEntryJson.update(logEntry); 28242b20ef6eSJason M. Bills } 2825e855dd28SJason M. Bills }; 2826e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 28275b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 28285b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2829043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2830e855dd28SJason M. Bills } 2831e855dd28SJason M. Bills 28327e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 28331da66f75SEd Tanous { 28343946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28353946028dSAppaRao Puli // method for security reasons. 28361da66f75SEd Tanous /** 28371da66f75SEd Tanous * Functions triggers appropriate requests on DBus 28381da66f75SEd Tanous */ 28397e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 28407e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 2841ed398213SEd Tanous // This is incorrect, should be. 2842ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 2843432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 2844002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2845002d39b4SEd Tanous [&app](const crow::Request& req, 2846002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 28473ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 284845ca1b86SEd Tanous { 284945ca1b86SEd Tanous return; 285045ca1b86SEd Tanous } 28512b20ef6eSJason M. Bills crow::connections::systemBus->async_method_call( 28522b20ef6eSJason M. Bills [asyncResp](const boost::system::error_code ec, 28532b20ef6eSJason M. Bills const std::vector<std::string>& resp) { 28541da66f75SEd Tanous if (ec) 28551da66f75SEd Tanous { 28561da66f75SEd Tanous if (ec.value() != 28571da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 28581da66f75SEd Tanous { 28591da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 28601da66f75SEd Tanous << ec.message(); 2861f12894f8SJason M. Bills messages::internalError(asyncResp->res); 28621da66f75SEd Tanous return; 28631da66f75SEd Tanous } 28641da66f75SEd Tanous } 2865e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 28661da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 28670f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2868424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2869002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2870e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2871424c4176SJason M. Bills "Collection of Crashdump Entries"; 2872002d39b4SEd Tanous asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 2873a2dd60a6SBrandon Kim asyncResp->res.jsonValue["Members@odata.count"] = 0; 28742b20ef6eSJason M. Bills 28752b20ef6eSJason M. Bills for (const std::string& path : resp) 28761da66f75SEd Tanous { 28772b20ef6eSJason M. Bills const sdbusplus::message::object_path objPath(path); 2878e855dd28SJason M. Bills // Get the log ID 28792b20ef6eSJason M. Bills std::string logID = objPath.filename(); 28802b20ef6eSJason M. Bills if (logID.empty()) 28811da66f75SEd Tanous { 2882e855dd28SJason M. Bills continue; 28831da66f75SEd Tanous } 2884e855dd28SJason M. Bills // Add the log entry to the array 28852b20ef6eSJason M. Bills logCrashdumpEntry(asyncResp, logID, 28862b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"]); 28871da66f75SEd Tanous } 28882b20ef6eSJason M. Bills }, 28891da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 28901da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 28911da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 28925b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 28937e860f15SJohn Edward Broadbent }); 28941da66f75SEd Tanous } 28951da66f75SEd Tanous 28967e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 28971da66f75SEd Tanous { 28983946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28993946028dSAppaRao Puli // method for security reasons. 29001da66f75SEd Tanous 29017e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 29027e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/") 2903ed398213SEd Tanous // this is incorrect, should be 2904ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 2905432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 29067e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 290745ca1b86SEd Tanous [&app](const crow::Request& req, 29087e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29097e860f15SJohn Edward Broadbent const std::string& param) { 29103ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 291145ca1b86SEd Tanous { 291245ca1b86SEd Tanous return; 291345ca1b86SEd Tanous } 29147e860f15SJohn Edward Broadbent const std::string& logID = param; 2915e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 29167e860f15SJohn Edward Broadbent }); 2917e855dd28SJason M. Bills } 2918e855dd28SJason M. Bills 29197e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 2920e855dd28SJason M. Bills { 29213946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 29223946028dSAppaRao Puli // method for security reasons. 29237e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 29247e860f15SJohn Edward Broadbent app, 29257e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/") 2926ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 29277e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 2928a4ce114aSNan Zhou [](const crow::Request& req, 29297e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29307e860f15SJohn Edward Broadbent const std::string& logID, const std::string& fileName) { 29312a9beeedSShounak Mitra // Do not call getRedfishRoute here since the crashdump file is not a 29322a9beeedSShounak Mitra // Redfish resource. 2933043a0536SJohnathan Mantey auto getStoredLogCallback = 2934002d39b4SEd Tanous [asyncResp, logID, fileName, url(boost::urls::url(req.urlView))]( 2935abf2add6SEd Tanous const boost::system::error_code ec, 2936002d39b4SEd Tanous const std::vector< 2937002d39b4SEd Tanous std::pair<std::string, dbus::utility::DbusVariantType>>& 29387e860f15SJohn Edward Broadbent resp) { 29391da66f75SEd Tanous if (ec) 29401da66f75SEd Tanous { 2941002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 2942f12894f8SJason M. Bills messages::internalError(asyncResp->res); 29431da66f75SEd Tanous return; 29441da66f75SEd Tanous } 2945e855dd28SJason M. Bills 2946043a0536SJohnathan Mantey std::string dbusFilename{}; 2947043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2948043a0536SJohnathan Mantey std::string dbusFilepath{}; 2949043a0536SJohnathan Mantey 2950002d39b4SEd Tanous parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 2951002d39b4SEd Tanous dbusFilepath); 2952043a0536SJohnathan Mantey 2953043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2954043a0536SJohnathan Mantey dbusFilepath.empty()) 29551da66f75SEd Tanous { 2956ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 29571da66f75SEd Tanous return; 29581da66f75SEd Tanous } 2959e855dd28SJason M. Bills 2960043a0536SJohnathan Mantey // Verify the file name parameter is correct 2961043a0536SJohnathan Mantey if (fileName != dbusFilename) 2962043a0536SJohnathan Mantey { 2963ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 2964043a0536SJohnathan Mantey return; 2965043a0536SJohnathan Mantey } 2966043a0536SJohnathan Mantey 2967043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2968043a0536SJohnathan Mantey { 2969ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 2970043a0536SJohnathan Mantey return; 2971043a0536SJohnathan Mantey } 2972002d39b4SEd Tanous std::ifstream ifs(dbusFilepath, std::ios::in | std::ios::binary); 2973002d39b4SEd Tanous asyncResp->res.body() = 2974002d39b4SEd Tanous std::string(std::istreambuf_iterator<char>{ifs}, {}); 2975043a0536SJohnathan Mantey 29767e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 29777e860f15SJohn Edward Broadbent // from a browser 2978d9f6c621SEd Tanous asyncResp->res.addHeader( 2979d9f6c621SEd Tanous boost::beast::http::field::content_disposition, "attachment"); 29801da66f75SEd Tanous }; 29811da66f75SEd Tanous crow::connections::systemBus->async_method_call( 29825b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 29835b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2984002d39b4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 29857e860f15SJohn Edward Broadbent }); 29861da66f75SEd Tanous } 29871da66f75SEd Tanous 2988c5a4c82aSJason M. Bills enum class OEMDiagnosticType 2989c5a4c82aSJason M. Bills { 2990c5a4c82aSJason M. Bills onDemand, 2991c5a4c82aSJason M. Bills telemetry, 2992c5a4c82aSJason M. Bills invalid, 2993c5a4c82aSJason M. Bills }; 2994c5a4c82aSJason M. Bills 2995f7725d79SEd Tanous inline OEMDiagnosticType 2996f7725d79SEd Tanous getOEMDiagnosticType(const std::string_view& oemDiagStr) 2997c5a4c82aSJason M. Bills { 2998c5a4c82aSJason M. Bills if (oemDiagStr == "OnDemand") 2999c5a4c82aSJason M. Bills { 3000c5a4c82aSJason M. Bills return OEMDiagnosticType::onDemand; 3001c5a4c82aSJason M. Bills } 3002c5a4c82aSJason M. Bills if (oemDiagStr == "Telemetry") 3003c5a4c82aSJason M. Bills { 3004c5a4c82aSJason M. Bills return OEMDiagnosticType::telemetry; 3005c5a4c82aSJason M. Bills } 3006c5a4c82aSJason M. Bills 3007c5a4c82aSJason M. Bills return OEMDiagnosticType::invalid; 3008c5a4c82aSJason M. Bills } 3009c5a4c82aSJason M. Bills 30107e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 30111da66f75SEd Tanous { 30123946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 30133946028dSAppaRao Puli // method for security reasons. 30140fda0f12SGeorge Liu BMCWEB_ROUTE( 30150fda0f12SGeorge Liu app, 30160fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") 3017ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 3018ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3019432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3020002d39b4SEd Tanous .methods(boost::beast::http::verb::post)( 3021002d39b4SEd Tanous [&app](const crow::Request& req, 30227e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 30233ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 302445ca1b86SEd Tanous { 302545ca1b86SEd Tanous return; 302645ca1b86SEd Tanous } 30278e6c099aSJason M. Bills std::string diagnosticDataType; 30288e6c099aSJason M. Bills std::string oemDiagnosticDataType; 302915ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 3030002d39b4SEd Tanous req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 3031002d39b4SEd Tanous "OEMDiagnosticDataType", oemDiagnosticDataType)) 30328e6c099aSJason M. Bills { 30338e6c099aSJason M. Bills return; 30348e6c099aSJason M. Bills } 30358e6c099aSJason M. Bills 30368e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 30378e6c099aSJason M. Bills { 30388e6c099aSJason M. Bills BMCWEB_LOG_ERROR 30398e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 30408e6c099aSJason M. Bills messages::actionParameterValueFormatError( 30418e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 30428e6c099aSJason M. Bills "CollectDiagnosticData"); 30438e6c099aSJason M. Bills return; 30448e6c099aSJason M. Bills } 30458e6c099aSJason M. Bills 3046c5a4c82aSJason M. Bills OEMDiagnosticType oemDiagType = 3047c5a4c82aSJason M. Bills getOEMDiagnosticType(oemDiagnosticDataType); 3048c5a4c82aSJason M. Bills 3049c5a4c82aSJason M. Bills std::string iface; 3050c5a4c82aSJason M. Bills std::string method; 3051c5a4c82aSJason M. Bills std::string taskMatchStr; 3052c5a4c82aSJason M. Bills if (oemDiagType == OEMDiagnosticType::onDemand) 3053c5a4c82aSJason M. Bills { 3054c5a4c82aSJason M. Bills iface = crashdumpOnDemandInterface; 3055c5a4c82aSJason M. Bills method = "GenerateOnDemandLog"; 3056c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3057c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3058c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3059c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3060c5a4c82aSJason M. Bills } 3061c5a4c82aSJason M. Bills else if (oemDiagType == OEMDiagnosticType::telemetry) 3062c5a4c82aSJason M. Bills { 3063c5a4c82aSJason M. Bills iface = crashdumpTelemetryInterface; 3064c5a4c82aSJason M. Bills method = "GenerateTelemetryLog"; 3065c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3066c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3067c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3068c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3069c5a4c82aSJason M. Bills } 3070c5a4c82aSJason M. Bills else 3071c5a4c82aSJason M. Bills { 3072c5a4c82aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 3073c5a4c82aSJason M. Bills << oemDiagnosticDataType; 3074c5a4c82aSJason M. Bills messages::actionParameterValueFormatError( 3075002d39b4SEd Tanous asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType", 3076002d39b4SEd Tanous "CollectDiagnosticData"); 3077c5a4c82aSJason M. Bills return; 3078c5a4c82aSJason M. Bills } 3079c5a4c82aSJason M. Bills 3080c5a4c82aSJason M. Bills auto collectCrashdumpCallback = 3081c5a4c82aSJason M. Bills [asyncResp, payload(task::Payload(req)), 3082c5a4c82aSJason M. Bills taskMatchStr](const boost::system::error_code ec, 308398be3e39SEd Tanous const std::string&) mutable { 30841da66f75SEd Tanous if (ec) 30851da66f75SEd Tanous { 3086002d39b4SEd Tanous if (ec.value() == boost::system::errc::operation_not_supported) 30871da66f75SEd Tanous { 3088f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 30891da66f75SEd Tanous } 30904363d3b2SJason M. Bills else if (ec.value() == 30914363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 30924363d3b2SJason M. Bills { 3093002d39b4SEd Tanous messages::serviceTemporarilyUnavailable(asyncResp->res, 3094002d39b4SEd Tanous "60"); 30954363d3b2SJason M. Bills } 30961da66f75SEd Tanous else 30971da66f75SEd Tanous { 3098f12894f8SJason M. Bills messages::internalError(asyncResp->res); 30991da66f75SEd Tanous } 31001da66f75SEd Tanous return; 31011da66f75SEd Tanous } 3102002d39b4SEd Tanous std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 310359d494eeSPatrick Williams [](boost::system::error_code err, sdbusplus::message_t&, 3104002d39b4SEd Tanous const std::shared_ptr<task::TaskData>& taskData) { 310566afe4faSJames Feist if (!err) 310666afe4faSJames Feist { 3107002d39b4SEd Tanous taskData->messages.emplace_back(messages::taskCompletedOK( 3108e5d5006bSJames Feist std::to_string(taskData->index))); 3109831d6b09SJames Feist taskData->state = "Completed"; 311066afe4faSJames Feist } 311132898ceaSJames Feist return task::completed; 311266afe4faSJames Feist }, 3113c5a4c82aSJason M. Bills taskMatchStr); 3114c5a4c82aSJason M. Bills 311546229577SJames Feist task->startTimer(std::chrono::minutes(5)); 311646229577SJames Feist task->populateResp(asyncResp->res); 311798be3e39SEd Tanous task->payload.emplace(std::move(payload)); 31181da66f75SEd Tanous }; 31198e6c099aSJason M. Bills 31201da66f75SEd Tanous crow::connections::systemBus->async_method_call( 3121002d39b4SEd Tanous std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath, 3122002d39b4SEd Tanous iface, method); 31237e860f15SJohn Edward Broadbent }); 31246eda7685SKenny L. Ku } 31256eda7685SKenny L. Ku 3126cb92c03bSAndrew Geissler /** 3127cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 3128cb92c03bSAndrew Geissler */ 31297e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 3130cb92c03bSAndrew Geissler { 3131cb92c03bSAndrew Geissler /** 3132cb92c03bSAndrew Geissler * Function handles POST method request. 3133cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3134cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3135cb92c03bSAndrew Geissler */ 31367e860f15SJohn Edward Broadbent 31370fda0f12SGeorge Liu BMCWEB_ROUTE( 31380fda0f12SGeorge Liu app, 31390fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/") 3140ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 31417e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 314245ca1b86SEd Tanous [&app](const crow::Request& req, 31437e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 31443ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 314545ca1b86SEd Tanous { 314645ca1b86SEd Tanous return; 314745ca1b86SEd Tanous } 3148cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 3149cb92c03bSAndrew Geissler 3150cb92c03bSAndrew Geissler // Process response from Logging service. 3151002d39b4SEd Tanous auto respHandler = [asyncResp](const boost::system::error_code ec) { 3152002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 3153cb92c03bSAndrew Geissler if (ec) 3154cb92c03bSAndrew Geissler { 3155cb92c03bSAndrew Geissler // TODO Handle for specific error code 3156002d39b4SEd Tanous BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 3157cb92c03bSAndrew Geissler asyncResp->res.result( 3158cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3159cb92c03bSAndrew Geissler return; 3160cb92c03bSAndrew Geissler } 3161cb92c03bSAndrew Geissler 3162002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content); 3163cb92c03bSAndrew Geissler }; 3164cb92c03bSAndrew Geissler 3165cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3166cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 31672c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 3168cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3169cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 31707e860f15SJohn Edward Broadbent }); 3171cb92c03bSAndrew Geissler } 3172a3316fc6SZhikuiRen 3173a3316fc6SZhikuiRen /**************************************************** 3174a3316fc6SZhikuiRen * Redfish PostCode interfaces 3175a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3176a3316fc6SZhikuiRen ******************************************************/ 31777e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 3178a3316fc6SZhikuiRen { 31797e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 3180ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 3181002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3182002d39b4SEd Tanous [&app](const crow::Request& req, 3183002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 31843ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 318545ca1b86SEd Tanous { 318645ca1b86SEd Tanous return; 318745ca1b86SEd Tanous } 31881476687dSEd Tanous 31891476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 31901476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes"; 31911476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 31921476687dSEd Tanous "#LogService.v1_1_0.LogService"; 31931476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "POST Code Log Service"; 31941476687dSEd Tanous asyncResp->res.jsonValue["Description"] = "POST Code Log Service"; 31951476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "BIOS POST Code Log"; 31961476687dSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 31971476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 31981476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 31997c8c4058STejas Patil 32007c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 3201*2b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 32020fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 32037c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 32047c8c4058STejas Patil redfishDateTimeOffset.second; 32057c8c4058STejas Patil 3206a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 32077e860f15SJohn Edward Broadbent {"target", 32080fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog"}}; 32097e860f15SJohn Edward Broadbent }); 3210a3316fc6SZhikuiRen } 3211a3316fc6SZhikuiRen 32127e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3213a3316fc6SZhikuiRen { 32140fda0f12SGeorge Liu BMCWEB_ROUTE( 32150fda0f12SGeorge Liu app, 32160fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog/") 3217ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3218ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3219432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 32207e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 322145ca1b86SEd Tanous [&app](const crow::Request& req, 32227e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 32233ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 322445ca1b86SEd Tanous { 322545ca1b86SEd Tanous return; 322645ca1b86SEd Tanous } 3227a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3228a3316fc6SZhikuiRen 3229a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3230a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3231a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3232a3316fc6SZhikuiRen if (ec) 3233a3316fc6SZhikuiRen { 3234a3316fc6SZhikuiRen // TODO Handle for specific error code 3235002d39b4SEd Tanous BMCWEB_LOG_ERROR << "doClearPostCodes resp_handler got error " 32367e860f15SJohn Edward Broadbent << ec; 3237002d39b4SEd Tanous asyncResp->res.result( 3238002d39b4SEd Tanous boost::beast::http::status::internal_server_error); 3239a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3240a3316fc6SZhikuiRen return; 3241a3316fc6SZhikuiRen } 3242a3316fc6SZhikuiRen }, 324315124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 324415124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3245a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 32467e860f15SJohn Edward Broadbent }); 3247a3316fc6SZhikuiRen } 3248a3316fc6SZhikuiRen 3249a3316fc6SZhikuiRen static void fillPostCodeEntry( 32508d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 32516c9a279eSManojkiran Eda const boost::container::flat_map< 32526c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3253a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3254a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3255a3316fc6SZhikuiRen { 3256a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3257fffb8c1fSEd Tanous const registries::Message* message = 3258fffb8c1fSEd Tanous registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3259a3316fc6SZhikuiRen 3260a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3261a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 3262a3316fc6SZhikuiRen 3263a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 32646c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 32656c9a279eSManojkiran Eda code : postcode) 3266a3316fc6SZhikuiRen { 3267a3316fc6SZhikuiRen currentCodeIndex++; 3268a3316fc6SZhikuiRen std::string postcodeEntryID = 3269a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3270a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3271a3316fc6SZhikuiRen 3272a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3273a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3274a3316fc6SZhikuiRen 3275a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3276a3316fc6SZhikuiRen { // already incremented 3277a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3278a3316fc6SZhikuiRen } 3279a3316fc6SZhikuiRen else 3280a3316fc6SZhikuiRen { 3281a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3282a3316fc6SZhikuiRen } 3283a3316fc6SZhikuiRen 3284a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3285a3316fc6SZhikuiRen // not fall between top and skip 3286a3316fc6SZhikuiRen if ((codeIndex == 0) && 3287a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3288a3316fc6SZhikuiRen { 3289a3316fc6SZhikuiRen continue; 3290a3316fc6SZhikuiRen } 3291a3316fc6SZhikuiRen 32924e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3293a3316fc6SZhikuiRen // currentIndex 3294a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3295a3316fc6SZhikuiRen { 3296a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3297a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3298a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3299a3316fc6SZhikuiRen continue; 3300a3316fc6SZhikuiRen } 3301a3316fc6SZhikuiRen 3302a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3303a3316fc6SZhikuiRen // index 3304a3316fc6SZhikuiRen 3305a3316fc6SZhikuiRen // Get the Created time from the timestamp 3306a3316fc6SZhikuiRen std::string entryTimeStr; 33071d8782e7SNan Zhou entryTimeStr = 3308*2b82937eSEd Tanous redfish::time_utils::getDateTimeUint(usecSinceEpoch / 1000 / 1000); 3309a3316fc6SZhikuiRen 3310a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3311a3316fc6SZhikuiRen std::ostringstream hexCode; 3312a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 33136c9a279eSManojkiran Eda << std::get<0>(code.second); 3314a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3315a3316fc6SZhikuiRen // Set Fixed -Point Notation 3316a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3317a3316fc6SZhikuiRen // Set precision to 4 digits 3318a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3319a3316fc6SZhikuiRen // Add double to stream 3320a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3321a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3322a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3323a3316fc6SZhikuiRen 3324a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3325a3316fc6SZhikuiRen std::string msg; 3326a3316fc6SZhikuiRen if (message != nullptr) 3327a3316fc6SZhikuiRen { 3328a3316fc6SZhikuiRen msg = message->message; 3329a3316fc6SZhikuiRen 3330a3316fc6SZhikuiRen // fill in this post code value 3331a3316fc6SZhikuiRen int i = 0; 3332a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3333a3316fc6SZhikuiRen { 3334a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3335a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3336a3316fc6SZhikuiRen if (argPos != std::string::npos) 3337a3316fc6SZhikuiRen { 3338a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3339a3316fc6SZhikuiRen } 3340a3316fc6SZhikuiRen } 3341a3316fc6SZhikuiRen } 3342a3316fc6SZhikuiRen 3343d4342a92STim Lee // Get Severity template from message registry 3344d4342a92STim Lee std::string severity; 3345d4342a92STim Lee if (message != nullptr) 3346d4342a92STim Lee { 33475f2b84eeSEd Tanous severity = message->messageSeverity; 3348d4342a92STim Lee } 3349d4342a92STim Lee 3350a3316fc6SZhikuiRen // add to AsyncResp 3351a3316fc6SZhikuiRen logEntryArray.push_back({}); 3352a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 335384afc48bSJason M. Bills bmcLogEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 335484afc48bSJason M. Bills bmcLogEntry["@odata.id"] = 33550fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 335684afc48bSJason M. Bills postcodeEntryID; 335784afc48bSJason M. Bills bmcLogEntry["Name"] = "POST Code Log Entry"; 335884afc48bSJason M. Bills bmcLogEntry["Id"] = postcodeEntryID; 335984afc48bSJason M. Bills bmcLogEntry["Message"] = std::move(msg); 336084afc48bSJason M. Bills bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode"; 336184afc48bSJason M. Bills bmcLogEntry["MessageArgs"] = std::move(messageArgs); 336284afc48bSJason M. Bills bmcLogEntry["EntryType"] = "Event"; 336384afc48bSJason M. Bills bmcLogEntry["Severity"] = std::move(severity); 336484afc48bSJason M. Bills bmcLogEntry["Created"] = entryTimeStr; 3365647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 3366647b3cdcSGeorge Liu { 3367647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 3368647b3cdcSGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3369647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 3370647b3cdcSGeorge Liu } 3371a3316fc6SZhikuiRen } 3372a3316fc6SZhikuiRen } 3373a3316fc6SZhikuiRen 33748d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3375a3316fc6SZhikuiRen const uint16_t bootIndex, 3376a3316fc6SZhikuiRen const uint64_t codeIndex) 3377a3316fc6SZhikuiRen { 3378a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 33796c9a279eSManojkiran Eda [aResp, bootIndex, 33806c9a279eSManojkiran Eda codeIndex](const boost::system::error_code ec, 33816c9a279eSManojkiran Eda const boost::container::flat_map< 33826c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 33836c9a279eSManojkiran Eda postcode) { 3384a3316fc6SZhikuiRen if (ec) 3385a3316fc6SZhikuiRen { 3386a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3387a3316fc6SZhikuiRen messages::internalError(aResp->res); 3388a3316fc6SZhikuiRen return; 3389a3316fc6SZhikuiRen } 3390a3316fc6SZhikuiRen 3391a3316fc6SZhikuiRen // skip the empty postcode boots 3392a3316fc6SZhikuiRen if (postcode.empty()) 3393a3316fc6SZhikuiRen { 3394a3316fc6SZhikuiRen return; 3395a3316fc6SZhikuiRen } 3396a3316fc6SZhikuiRen 3397a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3398a3316fc6SZhikuiRen 3399a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3400a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3401a3316fc6SZhikuiRen }, 340215124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 340315124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3404a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3405a3316fc6SZhikuiRen bootIndex); 3406a3316fc6SZhikuiRen } 3407a3316fc6SZhikuiRen 34088d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3409a3316fc6SZhikuiRen const uint16_t bootIndex, 3410a3316fc6SZhikuiRen const uint16_t bootCount, 34113648c8beSEd Tanous const uint64_t entryCount, size_t skip, 34123648c8beSEd Tanous size_t top) 3413a3316fc6SZhikuiRen { 3414a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3415a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3416a3316fc6SZhikuiRen top](const boost::system::error_code ec, 34176c9a279eSManojkiran Eda const boost::container::flat_map< 34186c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 34196c9a279eSManojkiran Eda postcode) { 3420a3316fc6SZhikuiRen if (ec) 3421a3316fc6SZhikuiRen { 3422a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3423a3316fc6SZhikuiRen messages::internalError(aResp->res); 3424a3316fc6SZhikuiRen return; 3425a3316fc6SZhikuiRen } 3426a3316fc6SZhikuiRen 3427a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3428a3316fc6SZhikuiRen if (!postcode.empty()) 3429a3316fc6SZhikuiRen { 3430a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 34313648c8beSEd Tanous if (skip < endCount && (top + skip) > entryCount) 3432a3316fc6SZhikuiRen { 34333648c8beSEd Tanous uint64_t thisBootSkip = 34343648c8beSEd Tanous std::max(static_cast<uint64_t>(skip), entryCount) - 34353648c8beSEd Tanous entryCount; 3436a3316fc6SZhikuiRen uint64_t thisBootTop = 34373648c8beSEd Tanous std::min(static_cast<uint64_t>(top + skip), endCount) - 34383648c8beSEd Tanous entryCount; 3439a3316fc6SZhikuiRen 3440002d39b4SEd Tanous fillPostCodeEntry(aResp, postcode, bootIndex, 0, thisBootSkip, 3441002d39b4SEd Tanous thisBootTop); 3442a3316fc6SZhikuiRen } 3443a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3444a3316fc6SZhikuiRen } 3445a3316fc6SZhikuiRen 3446a3316fc6SZhikuiRen // continue to previous bootIndex 3447a3316fc6SZhikuiRen if (bootIndex < bootCount) 3448a3316fc6SZhikuiRen { 3449a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3450a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3451a3316fc6SZhikuiRen } 345281584abeSJiaqing Zhao else if (skip + top < endCount) 3453a3316fc6SZhikuiRen { 3454a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 34550fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries?$skip=" + 3456a3316fc6SZhikuiRen std::to_string(skip + top); 3457a3316fc6SZhikuiRen } 3458a3316fc6SZhikuiRen }, 345915124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 346015124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3461a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3462a3316fc6SZhikuiRen bootIndex); 3463a3316fc6SZhikuiRen } 3464a3316fc6SZhikuiRen 34658d1b46d7Szhanghch05 static void 34668d1b46d7Szhanghch05 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 34673648c8beSEd Tanous size_t skip, size_t top) 3468a3316fc6SZhikuiRen { 3469a3316fc6SZhikuiRen uint64_t entryCount = 0; 34701e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint16_t>( 34711e1e598dSJonathan Doman *crow::connections::systemBus, 34721e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 34731e1e598dSJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 34741e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", 34751e1e598dSJonathan Doman [aResp, entryCount, skip, top](const boost::system::error_code ec, 34761e1e598dSJonathan Doman const uint16_t bootCount) { 3477a3316fc6SZhikuiRen if (ec) 3478a3316fc6SZhikuiRen { 3479a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3480a3316fc6SZhikuiRen messages::internalError(aResp->res); 3481a3316fc6SZhikuiRen return; 3482a3316fc6SZhikuiRen } 34831e1e598dSJonathan Doman getPostCodeForBoot(aResp, 1, bootCount, entryCount, skip, top); 34841e1e598dSJonathan Doman }); 3485a3316fc6SZhikuiRen } 3486a3316fc6SZhikuiRen 34877e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3488a3316fc6SZhikuiRen { 34897e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 34907e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3491ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 34927e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 349345ca1b86SEd Tanous [&app](const crow::Request& req, 34947e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3495c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 3496c937d2bfSEd Tanous .canDelegateTop = true, 3497c937d2bfSEd Tanous .canDelegateSkip = true, 3498c937d2bfSEd Tanous }; 3499c937d2bfSEd Tanous query_param::Query delegatedQuery; 3500c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 35013ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 350245ca1b86SEd Tanous { 350345ca1b86SEd Tanous return; 350445ca1b86SEd Tanous } 3505a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3506a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3507a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3508a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3509a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3510a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3511a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3512a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3513a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 35143648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 35153648c8beSEd Tanous size_t top = 35163648c8beSEd Tanous delegatedQuery.top.value_or(query_param::maxEntriesPerPage); 35173648c8beSEd Tanous getCurrentBootNumber(asyncResp, skip, top); 35187e860f15SJohn Edward Broadbent }); 3519a3316fc6SZhikuiRen } 3520a3316fc6SZhikuiRen 3521647b3cdcSGeorge Liu /** 3522647b3cdcSGeorge Liu * @brief Parse post code ID and get the current value and index value 3523647b3cdcSGeorge Liu * eg: postCodeID=B1-2, currentValue=1, index=2 3524647b3cdcSGeorge Liu * 3525647b3cdcSGeorge Liu * @param[in] postCodeID Post Code ID 3526647b3cdcSGeorge Liu * @param[out] currentValue Current value 3527647b3cdcSGeorge Liu * @param[out] index Index value 3528647b3cdcSGeorge Liu * 3529647b3cdcSGeorge Liu * @return bool true if the parsing is successful, false the parsing fails 3530647b3cdcSGeorge Liu */ 3531647b3cdcSGeorge Liu inline static bool parsePostCode(const std::string& postCodeID, 3532647b3cdcSGeorge Liu uint64_t& currentValue, uint16_t& index) 3533647b3cdcSGeorge Liu { 3534647b3cdcSGeorge Liu std::vector<std::string> split; 3535647b3cdcSGeorge Liu boost::algorithm::split(split, postCodeID, boost::is_any_of("-")); 3536647b3cdcSGeorge Liu if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B') 3537647b3cdcSGeorge Liu { 3538647b3cdcSGeorge Liu return false; 3539647b3cdcSGeorge Liu } 3540647b3cdcSGeorge Liu 3541ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3542647b3cdcSGeorge Liu const char* start = split[0].data() + 1; 3543ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3544647b3cdcSGeorge Liu const char* end = split[0].data() + split[0].size(); 3545647b3cdcSGeorge Liu auto [ptrIndex, ecIndex] = std::from_chars(start, end, index); 3546647b3cdcSGeorge Liu 3547647b3cdcSGeorge Liu if (ptrIndex != end || ecIndex != std::errc()) 3548647b3cdcSGeorge Liu { 3549647b3cdcSGeorge Liu return false; 3550647b3cdcSGeorge Liu } 3551647b3cdcSGeorge Liu 3552647b3cdcSGeorge Liu start = split[1].data(); 3553ca45aa3cSEd Tanous 3554ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3555647b3cdcSGeorge Liu end = split[1].data() + split[1].size(); 3556647b3cdcSGeorge Liu auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue); 3557647b3cdcSGeorge Liu 3558517d9a58STony Lee return ptrValue == end && ecValue == std::errc(); 3559647b3cdcSGeorge Liu } 3560647b3cdcSGeorge Liu 3561647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3562647b3cdcSGeorge Liu { 35630fda0f12SGeorge Liu BMCWEB_ROUTE( 35640fda0f12SGeorge Liu app, 35650fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/attachment/") 3566647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 3567647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 356845ca1b86SEd Tanous [&app](const crow::Request& req, 3569647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3570647b3cdcSGeorge Liu const std::string& postCodeID) { 35713ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 357245ca1b86SEd Tanous { 357345ca1b86SEd Tanous return; 357445ca1b86SEd Tanous } 3575002d39b4SEd Tanous if (!http_helpers::isOctetAccepted(req.getHeaderValue("Accept"))) 3576647b3cdcSGeorge Liu { 3577002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 3578647b3cdcSGeorge Liu return; 3579647b3cdcSGeorge Liu } 3580647b3cdcSGeorge Liu 3581647b3cdcSGeorge Liu uint64_t currentValue = 0; 3582647b3cdcSGeorge Liu uint16_t index = 0; 3583647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 3584647b3cdcSGeorge Liu { 3585002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID); 3586647b3cdcSGeorge Liu return; 3587647b3cdcSGeorge Liu } 3588647b3cdcSGeorge Liu 3589647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 3590647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 3591647b3cdcSGeorge Liu const boost::system::error_code ec, 3592002d39b4SEd Tanous const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>& 3593002d39b4SEd Tanous postcodes) { 3594647b3cdcSGeorge Liu if (ec.value() == EBADR) 3595647b3cdcSGeorge Liu { 3596002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 3597002d39b4SEd Tanous postCodeID); 3598647b3cdcSGeorge Liu return; 3599647b3cdcSGeorge Liu } 3600647b3cdcSGeorge Liu if (ec) 3601647b3cdcSGeorge Liu { 3602647b3cdcSGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3603647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 3604647b3cdcSGeorge Liu return; 3605647b3cdcSGeorge Liu } 3606647b3cdcSGeorge Liu 3607647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 3608002d39b4SEd Tanous if (value == std::string::npos || postcodes.size() < currentValue) 3609647b3cdcSGeorge Liu { 3610647b3cdcSGeorge Liu BMCWEB_LOG_ERROR << "Wrong currentValue value"; 3611002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 3612002d39b4SEd Tanous postCodeID); 3613647b3cdcSGeorge Liu return; 3614647b3cdcSGeorge Liu } 3615647b3cdcSGeorge Liu 36169eb808c1SEd Tanous const auto& [tID, c] = postcodes[value]; 361746ff87baSEd Tanous if (c.empty()) 3618647b3cdcSGeorge Liu { 3619647b3cdcSGeorge Liu BMCWEB_LOG_INFO << "No found post code data"; 3620002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 3621002d39b4SEd Tanous postCodeID); 3622647b3cdcSGeorge Liu return; 3623647b3cdcSGeorge Liu } 362446ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 362546ff87baSEd Tanous const char* d = reinterpret_cast<const char*>(c.data()); 362646ff87baSEd Tanous std::string_view strData(d, c.size()); 3627647b3cdcSGeorge Liu 3628d9f6c621SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::content_type, 3629647b3cdcSGeorge Liu "application/octet-stream"); 3630d9f6c621SEd Tanous asyncResp->res.addHeader( 3631d9f6c621SEd Tanous boost::beast::http::field::content_transfer_encoding, "Base64"); 3632002d39b4SEd Tanous asyncResp->res.body() = crow::utility::base64encode(strData); 3633647b3cdcSGeorge Liu }, 3634647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 3635647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 3636002d39b4SEd Tanous "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index); 3637647b3cdcSGeorge Liu }); 3638647b3cdcSGeorge Liu } 3639647b3cdcSGeorge Liu 36407e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 3641a3316fc6SZhikuiRen { 36427e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 36437e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/") 3644ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 36457e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 364645ca1b86SEd Tanous [&app](const crow::Request& req, 36477e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 36487e860f15SJohn Edward Broadbent const std::string& targetID) { 36493ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 365045ca1b86SEd Tanous { 365145ca1b86SEd Tanous return; 365245ca1b86SEd Tanous } 3653647b3cdcSGeorge Liu uint16_t bootIndex = 0; 3654647b3cdcSGeorge Liu uint64_t codeIndex = 0; 3655647b3cdcSGeorge Liu if (!parsePostCode(targetID, codeIndex, bootIndex)) 3656a3316fc6SZhikuiRen { 3657a3316fc6SZhikuiRen // Requested ID was not found 3658ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 3659a3316fc6SZhikuiRen return; 3660a3316fc6SZhikuiRen } 3661a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3662a3316fc6SZhikuiRen { 3663a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 36647e860f15SJohn Edward Broadbent << targetID; 3665a3316fc6SZhikuiRen } 3666a3316fc6SZhikuiRen 3667002d39b4SEd Tanous asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 3668a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 36690fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3670a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3671a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3672a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3673a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3674a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3675a3316fc6SZhikuiRen 3676a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 36777e860f15SJohn Edward Broadbent }); 3678a3316fc6SZhikuiRen } 3679a3316fc6SZhikuiRen 36801da66f75SEd Tanous } // namespace redfish 3681