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 183ccb3adbSEd Tanous #include "app.hpp" 197a1dbc48SGeorge Liu #include "dbus_utility.hpp" 203ccb3adbSEd Tanous #include "error_messages.hpp" 2168dd075aSAsmitha Karunanithi #include "generated/enums/log_entry.hpp" 22b7028ebfSSpencer Ku #include "gzfile.hpp" 23647b3cdcSGeorge Liu #include "http_utility.hpp" 24b7028ebfSSpencer Ku #include "human_sort.hpp" 253ccb3adbSEd Tanous #include "query.hpp" 264851d45dSJason M. Bills #include "registries.hpp" 274851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 284851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 293ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 3046229577SJames Feist #include "task.hpp" 313ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 323ccb3adbSEd Tanous #include "utils/time_utils.hpp" 331da66f75SEd Tanous 34e1f26343SJason M. Bills #include <systemd/sd-journal.h> 358e31778eSAsmitha Karunanithi #include <tinyxml2.h> 36400fd1fbSAdriana Kobylak #include <unistd.h> 37e1f26343SJason M. Bills 389896eaedSEd Tanous #include <boost/algorithm/string/case_conv.hpp> 3911ba3979SEd Tanous #include <boost/algorithm/string/classification.hpp> 40400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 414851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 4207c8c20dSEd Tanous #include <boost/beast/http/verb.hpp> 431da66f75SEd Tanous #include <boost/container/flat_map.hpp> 441ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 45ef4c65b7SEd Tanous #include <boost/url/format.hpp> 46d1bde9e5SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 47d1bde9e5SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 481214b7e7SGunnar Mills 497a1dbc48SGeorge Liu #include <array> 50647b3cdcSGeorge Liu #include <charconv> 514418c7f0SJames Feist #include <filesystem> 5275710de2SXiaochao Ma #include <optional> 533544d2a7SEd Tanous #include <ranges> 5426702d01SEd Tanous #include <span> 55cd225da8SJason M. Bills #include <string_view> 56abf2add6SEd Tanous #include <variant> 571da66f75SEd Tanous 581da66f75SEd Tanous namespace redfish 591da66f75SEd Tanous { 601da66f75SEd Tanous 6189492a15SPatrick Williams constexpr const char* crashdumpObject = "com.intel.crashdump"; 6289492a15SPatrick Williams constexpr const char* crashdumpPath = "/com/intel/crashdump"; 6389492a15SPatrick Williams constexpr const char* crashdumpInterface = "com.intel.crashdump"; 6489492a15SPatrick Williams constexpr const char* deleteAllInterface = 655b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 6689492a15SPatrick Williams constexpr const char* crashdumpOnDemandInterface = 67424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 6889492a15SPatrick Williams constexpr const char* crashdumpTelemetryInterface = 696eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 701da66f75SEd Tanous 718e31778eSAsmitha Karunanithi enum class DumpCreationProgress 728e31778eSAsmitha Karunanithi { 738e31778eSAsmitha Karunanithi DUMP_CREATE_SUCCESS, 748e31778eSAsmitha Karunanithi DUMP_CREATE_FAILED, 758e31778eSAsmitha Karunanithi DUMP_CREATE_INPROGRESS 768e31778eSAsmitha Karunanithi }; 778e31778eSAsmitha Karunanithi 78f6150403SJames Feist namespace fs = std::filesystem; 791da66f75SEd Tanous 80cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 81cb92c03bSAndrew Geissler { 82d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 83d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 84d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 85d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 86cb92c03bSAndrew Geissler { 87cb92c03bSAndrew Geissler return "Critical"; 88cb92c03bSAndrew Geissler } 893174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 90d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 91d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 92cb92c03bSAndrew Geissler { 93cb92c03bSAndrew Geissler return "OK"; 94cb92c03bSAndrew Geissler } 953174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 96cb92c03bSAndrew Geissler { 97cb92c03bSAndrew Geissler return "Warning"; 98cb92c03bSAndrew Geissler } 99cb92c03bSAndrew Geissler return ""; 100cb92c03bSAndrew Geissler } 101cb92c03bSAndrew Geissler 1029017faf2SAbhishek Patel inline std::optional<bool> getProviderNotifyAction(const std::string& notify) 1039017faf2SAbhishek Patel { 1049017faf2SAbhishek Patel std::optional<bool> notifyAction; 1059017faf2SAbhishek Patel if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify") 1069017faf2SAbhishek Patel { 1079017faf2SAbhishek Patel notifyAction = true; 1089017faf2SAbhishek Patel } 1099017faf2SAbhishek Patel else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit") 1109017faf2SAbhishek Patel { 1119017faf2SAbhishek Patel notifyAction = false; 1129017faf2SAbhishek Patel } 1139017faf2SAbhishek Patel 1149017faf2SAbhishek Patel return notifyAction; 1159017faf2SAbhishek Patel } 1169017faf2SAbhishek Patel 1177e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 11826ccae32SEd Tanous std::string_view field, 11939e77504SEd Tanous std::string_view& contents) 12016428a1aSJason M. Bills { 12116428a1aSJason M. Bills const char* data = nullptr; 12216428a1aSJason M. Bills size_t length = 0; 12316428a1aSJason M. Bills int ret = 0; 12416428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 12546ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 12646ff87baSEd Tanous const void** dataVoid = reinterpret_cast<const void**>(&data); 12746ff87baSEd Tanous 12846ff87baSEd Tanous ret = sd_journal_get_data(journal, field.data(), dataVoid, &length); 12916428a1aSJason M. Bills if (ret < 0) 13016428a1aSJason M. Bills { 13116428a1aSJason M. Bills return ret; 13216428a1aSJason M. Bills } 13339e77504SEd Tanous contents = std::string_view(data, length); 13416428a1aSJason M. Bills // Only use the content after the "=" character. 13581ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 13616428a1aSJason M. Bills return ret; 13716428a1aSJason M. Bills } 13816428a1aSJason M. Bills 1397e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 14026ccae32SEd Tanous std::string_view field, const int& base, 14126ccae32SEd Tanous long int& contents) 14216428a1aSJason M. Bills { 14316428a1aSJason M. Bills int ret = 0; 14439e77504SEd Tanous std::string_view metadata; 14516428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 14616428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 14716428a1aSJason M. Bills if (ret < 0) 14816428a1aSJason M. Bills { 14916428a1aSJason M. Bills return ret; 15016428a1aSJason M. Bills } 151b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 15216428a1aSJason M. Bills return ret; 15316428a1aSJason M. Bills } 15416428a1aSJason M. Bills 1557e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1567e860f15SJohn Edward Broadbent std::string& entryTimestamp) 157a3316fc6SZhikuiRen { 158a3316fc6SZhikuiRen int ret = 0; 159a3316fc6SZhikuiRen uint64_t timestamp = 0; 160a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 161a3316fc6SZhikuiRen if (ret < 0) 162a3316fc6SZhikuiRen { 16362598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to read entry timestamp: {}", strerror(-ret)); 164a3316fc6SZhikuiRen return false; 165a3316fc6SZhikuiRen } 166e645c5e6SKonstantin Aladyshev entryTimestamp = redfish::time_utils::getDateTimeUintUs(timestamp); 1679c620e21SAsmitha Karunanithi return true; 168a3316fc6SZhikuiRen } 16950b8a43aSEd Tanous 1707e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 171e85d6b16SJason M. Bills const bool firstEntry = true) 17216428a1aSJason M. Bills { 17316428a1aSJason M. Bills int ret = 0; 17416428a1aSJason M. Bills static uint64_t prevTs = 0; 17516428a1aSJason M. Bills static int index = 0; 176e85d6b16SJason M. Bills if (firstEntry) 177e85d6b16SJason M. Bills { 178e85d6b16SJason M. Bills prevTs = 0; 179e85d6b16SJason M. Bills } 180e85d6b16SJason M. Bills 18116428a1aSJason M. Bills // Get the entry timestamp 18216428a1aSJason M. Bills uint64_t curTs = 0; 18316428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 18416428a1aSJason M. Bills if (ret < 0) 18516428a1aSJason M. Bills { 18662598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to read entry timestamp: {}", strerror(-ret)); 18716428a1aSJason M. Bills return false; 18816428a1aSJason M. Bills } 18916428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 19016428a1aSJason M. Bills if (curTs == prevTs) 19116428a1aSJason M. Bills { 19216428a1aSJason M. Bills index++; 19316428a1aSJason M. Bills } 19416428a1aSJason M. Bills else 19516428a1aSJason M. Bills { 19616428a1aSJason M. Bills // Otherwise, reset it 19716428a1aSJason M. Bills index = 0; 19816428a1aSJason M. Bills } 19916428a1aSJason M. Bills // Save the timestamp 20016428a1aSJason M. Bills prevTs = curTs; 20116428a1aSJason M. Bills 20216428a1aSJason M. Bills entryID = std::to_string(curTs); 20316428a1aSJason M. Bills if (index > 0) 20416428a1aSJason M. Bills { 20516428a1aSJason M. Bills entryID += "_" + std::to_string(index); 20616428a1aSJason M. Bills } 20716428a1aSJason M. Bills return true; 20816428a1aSJason M. Bills } 20916428a1aSJason M. Bills 210e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 211e85d6b16SJason M. Bills const bool firstEntry = true) 21295820184SJason M. Bills { 213271584abSEd Tanous static time_t prevTs = 0; 21495820184SJason M. Bills static int index = 0; 215e85d6b16SJason M. Bills if (firstEntry) 216e85d6b16SJason M. Bills { 217e85d6b16SJason M. Bills prevTs = 0; 218e85d6b16SJason M. Bills } 219e85d6b16SJason M. Bills 22095820184SJason M. Bills // Get the entry timestamp 221271584abSEd Tanous std::time_t curTs = 0; 22295820184SJason M. Bills std::tm timeStruct = {}; 22395820184SJason M. Bills std::istringstream entryStream(logEntry); 22495820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 22595820184SJason M. Bills { 22695820184SJason M. Bills curTs = std::mktime(&timeStruct); 22795820184SJason M. Bills } 22895820184SJason M. Bills // If the timestamp isn't unique, increment the index 22995820184SJason M. Bills if (curTs == prevTs) 23095820184SJason M. Bills { 23195820184SJason M. Bills index++; 23295820184SJason M. Bills } 23395820184SJason M. Bills else 23495820184SJason M. Bills { 23595820184SJason M. Bills // Otherwise, reset it 23695820184SJason M. Bills index = 0; 23795820184SJason M. Bills } 23895820184SJason M. Bills // Save the timestamp 23995820184SJason M. Bills prevTs = curTs; 24095820184SJason M. Bills 24195820184SJason M. Bills entryID = std::to_string(curTs); 24295820184SJason M. Bills if (index > 0) 24395820184SJason M. Bills { 24495820184SJason M. Bills entryID += "_" + std::to_string(index); 24595820184SJason M. Bills } 24695820184SJason M. Bills return true; 24795820184SJason M. Bills } 24895820184SJason M. Bills 2497e860f15SJohn Edward Broadbent inline static bool 2508d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2518d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 2528d1b46d7Szhanghch05 uint64_t& index) 25316428a1aSJason M. Bills { 25416428a1aSJason M. Bills if (entryID.empty()) 25516428a1aSJason M. Bills { 25616428a1aSJason M. Bills return false; 25716428a1aSJason M. Bills } 25816428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 25939e77504SEd Tanous std::string_view tsStr(entryID); 26016428a1aSJason M. Bills 26181ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 26271d5d8dbSEd Tanous if (underscorePos != std::string_view::npos) 26316428a1aSJason M. Bills { 26416428a1aSJason M. Bills // Timestamp has an index 26516428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 26639e77504SEd Tanous std::string_view indexStr(entryID); 26716428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 26884396af9SPatrick Williams auto [ptr, ec] = std::from_chars(indexStr.begin(), indexStr.end(), 26984396af9SPatrick Williams index); 270c0bd5e4bSEd Tanous if (ec != std::errc()) 27116428a1aSJason M. Bills { 2729db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 27316428a1aSJason M. Bills return false; 27416428a1aSJason M. Bills } 27516428a1aSJason M. Bills } 27616428a1aSJason M. Bills // Timestamp has no index 27784396af9SPatrick Williams auto [ptr, ec] = std::from_chars(tsStr.begin(), tsStr.end(), timestamp); 278c0bd5e4bSEd Tanous if (ec != std::errc()) 27916428a1aSJason M. Bills { 2809db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 28116428a1aSJason M. Bills return false; 28216428a1aSJason M. Bills } 28316428a1aSJason M. Bills return true; 28416428a1aSJason M. Bills } 28516428a1aSJason M. Bills 28695820184SJason M. Bills static bool 28795820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 28895820184SJason M. Bills { 28995820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 29095820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 29195820184SJason M. Bills 29295820184SJason M. Bills // Loop through the directory looking for redfish log files 29395820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 29495820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 29595820184SJason M. Bills { 29695820184SJason M. Bills // If we find a redfish log file, save the path 29795820184SJason M. Bills std::string filename = dirEnt.path().filename(); 29811ba3979SEd Tanous if (filename.starts_with(redfishLogFilename)) 29995820184SJason M. Bills { 30095820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 30195820184SJason M. Bills } 30295820184SJason M. Bills } 30395820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 30495820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 30595820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 3063544d2a7SEd Tanous std::ranges::sort(redfishLogFiles); 30795820184SJason M. Bills 30895820184SJason M. Bills return !redfishLogFiles.empty(); 30995820184SJason M. Bills } 31095820184SJason M. Bills 31168dd075aSAsmitha Karunanithi inline log_entry::OriginatorTypes 31268dd075aSAsmitha Karunanithi mapDbusOriginatorTypeToRedfish(const std::string& originatorType) 31368dd075aSAsmitha Karunanithi { 31468dd075aSAsmitha Karunanithi if (originatorType == 31568dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client") 31668dd075aSAsmitha Karunanithi { 31768dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::Client; 31868dd075aSAsmitha Karunanithi } 31968dd075aSAsmitha Karunanithi if (originatorType == 32068dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal") 32168dd075aSAsmitha Karunanithi { 32268dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::Internal; 32368dd075aSAsmitha Karunanithi } 32468dd075aSAsmitha Karunanithi if (originatorType == 32568dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService") 32668dd075aSAsmitha Karunanithi { 32768dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::SupportingService; 32868dd075aSAsmitha Karunanithi } 32968dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::Invalid; 33068dd075aSAsmitha Karunanithi } 33168dd075aSAsmitha Karunanithi 332aefe3786SClaire Weinan inline void parseDumpEntryFromDbusObject( 3332d613eb6SJiaqing Zhao const dbus::utility::ManagedObjectType::value_type& object, 334c6fecdabSClaire Weinan std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs, 33568dd075aSAsmitha Karunanithi std::string& originatorId, log_entry::OriginatorTypes& originatorType, 336aefe3786SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 337aefe3786SClaire Weinan { 338aefe3786SClaire Weinan for (const auto& interfaceMap : object.second) 339aefe3786SClaire Weinan { 340aefe3786SClaire Weinan if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") 341aefe3786SClaire Weinan { 342aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 343aefe3786SClaire Weinan { 344aefe3786SClaire Weinan if (propertyMap.first == "Status") 345aefe3786SClaire Weinan { 346aefe3786SClaire Weinan const auto* status = 347aefe3786SClaire Weinan std::get_if<std::string>(&propertyMap.second); 348aefe3786SClaire Weinan if (status == nullptr) 349aefe3786SClaire Weinan { 350aefe3786SClaire Weinan messages::internalError(asyncResp->res); 351aefe3786SClaire Weinan break; 352aefe3786SClaire Weinan } 353aefe3786SClaire Weinan dumpStatus = *status; 354aefe3786SClaire Weinan } 355aefe3786SClaire Weinan } 356aefe3786SClaire Weinan } 357aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 358aefe3786SClaire Weinan { 359aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 360aefe3786SClaire Weinan { 361aefe3786SClaire Weinan if (propertyMap.first == "Size") 362aefe3786SClaire Weinan { 363aefe3786SClaire Weinan const auto* sizePtr = 364aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 365aefe3786SClaire Weinan if (sizePtr == nullptr) 366aefe3786SClaire Weinan { 367aefe3786SClaire Weinan messages::internalError(asyncResp->res); 368aefe3786SClaire Weinan break; 369aefe3786SClaire Weinan } 370aefe3786SClaire Weinan size = *sizePtr; 371aefe3786SClaire Weinan break; 372aefe3786SClaire Weinan } 373aefe3786SClaire Weinan } 374aefe3786SClaire Weinan } 375aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") 376aefe3786SClaire Weinan { 377aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 378aefe3786SClaire Weinan { 379aefe3786SClaire Weinan if (propertyMap.first == "Elapsed") 380aefe3786SClaire Weinan { 381aefe3786SClaire Weinan const uint64_t* usecsTimeStamp = 382aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 383aefe3786SClaire Weinan if (usecsTimeStamp == nullptr) 384aefe3786SClaire Weinan { 385aefe3786SClaire Weinan messages::internalError(asyncResp->res); 386aefe3786SClaire Weinan break; 387aefe3786SClaire Weinan } 388c6fecdabSClaire Weinan timestampUs = *usecsTimeStamp; 389aefe3786SClaire Weinan break; 390aefe3786SClaire Weinan } 391aefe3786SClaire Weinan } 392aefe3786SClaire Weinan } 39368dd075aSAsmitha Karunanithi else if (interfaceMap.first == 39468dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy") 39568dd075aSAsmitha Karunanithi { 39668dd075aSAsmitha Karunanithi for (const auto& propertyMap : interfaceMap.second) 39768dd075aSAsmitha Karunanithi { 39868dd075aSAsmitha Karunanithi if (propertyMap.first == "OriginatorId") 39968dd075aSAsmitha Karunanithi { 40068dd075aSAsmitha Karunanithi const std::string* id = 40168dd075aSAsmitha Karunanithi std::get_if<std::string>(&propertyMap.second); 40268dd075aSAsmitha Karunanithi if (id == nullptr) 40368dd075aSAsmitha Karunanithi { 40468dd075aSAsmitha Karunanithi messages::internalError(asyncResp->res); 40568dd075aSAsmitha Karunanithi break; 40668dd075aSAsmitha Karunanithi } 40768dd075aSAsmitha Karunanithi originatorId = *id; 40868dd075aSAsmitha Karunanithi } 40968dd075aSAsmitha Karunanithi 41068dd075aSAsmitha Karunanithi if (propertyMap.first == "OriginatorType") 41168dd075aSAsmitha Karunanithi { 41268dd075aSAsmitha Karunanithi const std::string* type = 41368dd075aSAsmitha Karunanithi std::get_if<std::string>(&propertyMap.second); 41468dd075aSAsmitha Karunanithi if (type == nullptr) 41568dd075aSAsmitha Karunanithi { 41668dd075aSAsmitha Karunanithi messages::internalError(asyncResp->res); 41768dd075aSAsmitha Karunanithi break; 41868dd075aSAsmitha Karunanithi } 41968dd075aSAsmitha Karunanithi 42068dd075aSAsmitha Karunanithi originatorType = mapDbusOriginatorTypeToRedfish(*type); 42168dd075aSAsmitha Karunanithi if (originatorType == log_entry::OriginatorTypes::Invalid) 42268dd075aSAsmitha Karunanithi { 42368dd075aSAsmitha Karunanithi messages::internalError(asyncResp->res); 42468dd075aSAsmitha Karunanithi break; 42568dd075aSAsmitha Karunanithi } 42668dd075aSAsmitha Karunanithi } 42768dd075aSAsmitha Karunanithi } 42868dd075aSAsmitha Karunanithi } 429aefe3786SClaire Weinan } 430aefe3786SClaire Weinan } 431aefe3786SClaire Weinan 43221ab404cSNan Zhou static std::string getDumpEntriesPath(const std::string& dumpType) 433fdd26906SClaire Weinan { 434fdd26906SClaire Weinan std::string entriesPath; 435fdd26906SClaire Weinan 436fdd26906SClaire Weinan if (dumpType == "BMC") 437fdd26906SClaire Weinan { 438fdd26906SClaire Weinan entriesPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 439fdd26906SClaire Weinan } 440fdd26906SClaire Weinan else if (dumpType == "FaultLog") 441fdd26906SClaire Weinan { 442fdd26906SClaire Weinan entriesPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/"; 443fdd26906SClaire Weinan } 444fdd26906SClaire Weinan else if (dumpType == "System") 445fdd26906SClaire Weinan { 446fdd26906SClaire Weinan entriesPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 447fdd26906SClaire Weinan } 448fdd26906SClaire Weinan else 449fdd26906SClaire Weinan { 45062598e31SEd Tanous BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}", 45162598e31SEd Tanous dumpType); 452fdd26906SClaire Weinan } 453fdd26906SClaire Weinan 454fdd26906SClaire Weinan // Returns empty string on error 455fdd26906SClaire Weinan return entriesPath; 456fdd26906SClaire Weinan } 457fdd26906SClaire Weinan 4588d1b46d7Szhanghch05 inline void 4598d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4605cb1dd27SAsmitha Karunanithi const std::string& dumpType) 4615cb1dd27SAsmitha Karunanithi { 462fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 463fdd26906SClaire Weinan if (entriesPath.empty()) 4645cb1dd27SAsmitha Karunanithi { 4655cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4665cb1dd27SAsmitha Karunanithi return; 4675cb1dd27SAsmitha Karunanithi } 4685cb1dd27SAsmitha Karunanithi 4695eb468daSGeorge Liu sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); 4705eb468daSGeorge Liu dbus::utility::getManagedObjects( 4715eb468daSGeorge Liu "xyz.openbmc_project.Dump.Manager", path, 472fdd26906SClaire Weinan [asyncResp, entriesPath, 4735e7e2dc5SEd Tanous dumpType](const boost::system::error_code& ec, 4745eb468daSGeorge Liu const dbus::utility::ManagedObjectType& objects) { 4755cb1dd27SAsmitha Karunanithi if (ec) 4765cb1dd27SAsmitha Karunanithi { 47762598e31SEd Tanous BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec); 4785cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4795cb1dd27SAsmitha Karunanithi return; 4805cb1dd27SAsmitha Karunanithi } 4815cb1dd27SAsmitha Karunanithi 482fdd26906SClaire Weinan // Remove ending slash 483fdd26906SClaire Weinan std::string odataIdStr = entriesPath; 484fdd26906SClaire Weinan if (!odataIdStr.empty()) 485fdd26906SClaire Weinan { 486fdd26906SClaire Weinan odataIdStr.pop_back(); 487fdd26906SClaire Weinan } 488fdd26906SClaire Weinan 489fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = 490fdd26906SClaire Weinan "#LogEntryCollection.LogEntryCollection"; 491fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr); 492fdd26906SClaire Weinan asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries"; 49389492a15SPatrick Williams asyncResp->res.jsonValue["Description"] = "Collection of " + dumpType + 49489492a15SPatrick Williams " Dump Entries"; 495fdd26906SClaire Weinan 4963544d2a7SEd Tanous nlohmann::json::array_t entriesArray; 497b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 498b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 499002d39b4SEd Tanous std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; 5005cb1dd27SAsmitha Karunanithi 5015eb468daSGeorge Liu dbus::utility::ManagedObjectType resp(objects); 5023544d2a7SEd Tanous std::ranges::sort(resp, [](const auto& l, const auto& r) { 503002d39b4SEd Tanous return AlphanumLess<std::string>()(l.first.filename(), 504002d39b4SEd Tanous r.first.filename()); 505565dfb6fSClaire Weinan }); 506565dfb6fSClaire Weinan 5075cb1dd27SAsmitha Karunanithi for (auto& object : resp) 5085cb1dd27SAsmitha Karunanithi { 509b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 5105cb1dd27SAsmitha Karunanithi { 5115cb1dd27SAsmitha Karunanithi continue; 5125cb1dd27SAsmitha Karunanithi } 513c6fecdabSClaire Weinan uint64_t timestampUs = 0; 5145cb1dd27SAsmitha Karunanithi uint64_t size = 0; 51535440d18SAsmitha Karunanithi std::string dumpStatus; 51668dd075aSAsmitha Karunanithi std::string originatorId; 51768dd075aSAsmitha Karunanithi log_entry::OriginatorTypes originatorType = 51868dd075aSAsmitha Karunanithi log_entry::OriginatorTypes::Internal; 519433b68b4SJason M. Bills nlohmann::json::object_t thisEntry; 5202dfd18efSEd Tanous 5212dfd18efSEd Tanous std::string entryID = object.first.filename(); 5222dfd18efSEd Tanous if (entryID.empty()) 5235cb1dd27SAsmitha Karunanithi { 5245cb1dd27SAsmitha Karunanithi continue; 5255cb1dd27SAsmitha Karunanithi } 5265cb1dd27SAsmitha Karunanithi 527c6fecdabSClaire Weinan parseDumpEntryFromDbusObject(object, dumpStatus, size, timestampUs, 52868dd075aSAsmitha Karunanithi originatorId, originatorType, 529aefe3786SClaire Weinan asyncResp); 5305cb1dd27SAsmitha Karunanithi 5310fda0f12SGeorge Liu if (dumpStatus != 5320fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 53335440d18SAsmitha Karunanithi !dumpStatus.empty()) 53435440d18SAsmitha Karunanithi { 53535440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 53635440d18SAsmitha Karunanithi continue; 53735440d18SAsmitha Karunanithi } 53835440d18SAsmitha Karunanithi 53968dd075aSAsmitha Karunanithi thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry"; 540fdd26906SClaire Weinan thisEntry["@odata.id"] = entriesPath + entryID; 5415cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 5425cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5435cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 544bbd80db8SClaire Weinan thisEntry["Created"] = 545bbd80db8SClaire Weinan redfish::time_utils::getDateTimeUintUs(timestampUs); 5465cb1dd27SAsmitha Karunanithi 54768dd075aSAsmitha Karunanithi if (!originatorId.empty()) 54868dd075aSAsmitha Karunanithi { 54968dd075aSAsmitha Karunanithi thisEntry["Originator"] = originatorId; 55068dd075aSAsmitha Karunanithi thisEntry["OriginatorType"] = originatorType; 55168dd075aSAsmitha Karunanithi } 55268dd075aSAsmitha Karunanithi 5535cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5545cb1dd27SAsmitha Karunanithi { 555d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 55689492a15SPatrick Williams thisEntry["AdditionalDataURI"] = entriesPath + entryID + 55789492a15SPatrick Williams "/attachment"; 558fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 5595cb1dd27SAsmitha Karunanithi } 5605cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5615cb1dd27SAsmitha Karunanithi { 562d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 563d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 56489492a15SPatrick Williams thisEntry["AdditionalDataURI"] = entriesPath + entryID + 56589492a15SPatrick Williams "/attachment"; 566fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 5675cb1dd27SAsmitha Karunanithi } 568b2ba3072SPatrick Williams entriesArray.emplace_back(std::move(thisEntry)); 5695cb1dd27SAsmitha Karunanithi } 570002d39b4SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size(); 5713544d2a7SEd Tanous asyncResp->res.jsonValue["Members"] = std::move(entriesArray); 5725eb468daSGeorge Liu }); 5735cb1dd27SAsmitha Karunanithi } 5745cb1dd27SAsmitha Karunanithi 5758d1b46d7Szhanghch05 inline void 576c7a6d660SClaire Weinan getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5778d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 5785cb1dd27SAsmitha Karunanithi { 579fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 580fdd26906SClaire Weinan if (entriesPath.empty()) 5815cb1dd27SAsmitha Karunanithi { 5825cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5835cb1dd27SAsmitha Karunanithi return; 5845cb1dd27SAsmitha Karunanithi } 5855cb1dd27SAsmitha Karunanithi 5865eb468daSGeorge Liu sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); 5875eb468daSGeorge Liu dbus::utility::getManagedObjects( 5885eb468daSGeorge Liu "xyz.openbmc_project.Dump.Manager", path, 589fdd26906SClaire Weinan [asyncResp, entryID, dumpType, 5905e7e2dc5SEd Tanous entriesPath](const boost::system::error_code& ec, 59102cad96eSEd Tanous const dbus::utility::ManagedObjectType& resp) { 5925cb1dd27SAsmitha Karunanithi if (ec) 5935cb1dd27SAsmitha Karunanithi { 59462598e31SEd Tanous BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec); 5955cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5965cb1dd27SAsmitha Karunanithi return; 5975cb1dd27SAsmitha Karunanithi } 5985cb1dd27SAsmitha Karunanithi 599b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 600b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 601b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 602002d39b4SEd Tanous std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; 603b47452b2SAsmitha Karunanithi 6049eb808c1SEd Tanous for (const auto& objectPath : resp) 6055cb1dd27SAsmitha Karunanithi { 606b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 6075cb1dd27SAsmitha Karunanithi { 6085cb1dd27SAsmitha Karunanithi continue; 6095cb1dd27SAsmitha Karunanithi } 6105cb1dd27SAsmitha Karunanithi 6115cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 612c6fecdabSClaire Weinan uint64_t timestampUs = 0; 6135cb1dd27SAsmitha Karunanithi uint64_t size = 0; 61435440d18SAsmitha Karunanithi std::string dumpStatus; 61568dd075aSAsmitha Karunanithi std::string originatorId; 61668dd075aSAsmitha Karunanithi log_entry::OriginatorTypes originatorType = 61768dd075aSAsmitha Karunanithi log_entry::OriginatorTypes::Internal; 6185cb1dd27SAsmitha Karunanithi 619aefe3786SClaire Weinan parseDumpEntryFromDbusObject(objectPath, dumpStatus, size, 62068dd075aSAsmitha Karunanithi timestampUs, originatorId, 62168dd075aSAsmitha Karunanithi originatorType, asyncResp); 6225cb1dd27SAsmitha Karunanithi 6230fda0f12SGeorge Liu if (dumpStatus != 6240fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 62535440d18SAsmitha Karunanithi !dumpStatus.empty()) 62635440d18SAsmitha Karunanithi { 62735440d18SAsmitha Karunanithi // Dump status is not Complete 62835440d18SAsmitha Karunanithi // return not found until status is changed to Completed 629d1bde9e5SKrzysztof Grobelny messages::resourceNotFound(asyncResp->res, dumpType + " dump", 630d1bde9e5SKrzysztof Grobelny entryID); 63135440d18SAsmitha Karunanithi return; 63235440d18SAsmitha Karunanithi } 63335440d18SAsmitha Karunanithi 6345cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 63568dd075aSAsmitha Karunanithi "#LogEntry.v1_11_0.LogEntry"; 636fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID; 6375cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6385cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6395cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 640bbd80db8SClaire Weinan asyncResp->res.jsonValue["Created"] = 641bbd80db8SClaire Weinan redfish::time_utils::getDateTimeUintUs(timestampUs); 6425cb1dd27SAsmitha Karunanithi 64368dd075aSAsmitha Karunanithi if (!originatorId.empty()) 64468dd075aSAsmitha Karunanithi { 64568dd075aSAsmitha Karunanithi asyncResp->res.jsonValue["Originator"] = originatorId; 64668dd075aSAsmitha Karunanithi asyncResp->res.jsonValue["OriginatorType"] = originatorType; 64768dd075aSAsmitha Karunanithi } 64868dd075aSAsmitha Karunanithi 6495cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6505cb1dd27SAsmitha Karunanithi { 651d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 652d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 653fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 654fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6555cb1dd27SAsmitha Karunanithi } 6565cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6575cb1dd27SAsmitha Karunanithi { 658d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 659002d39b4SEd Tanous asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System"; 660d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 661fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 662fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6635cb1dd27SAsmitha Karunanithi } 6645cb1dd27SAsmitha Karunanithi } 665e05aec50SEd Tanous if (!foundDumpEntry) 666b47452b2SAsmitha Karunanithi { 66762598e31SEd Tanous BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID); 668b90d14f2SMyung Bae messages::resourceNotFound(asyncResp->res, dumpType + " dump", 669b90d14f2SMyung Bae entryID); 670b47452b2SAsmitha Karunanithi return; 671b47452b2SAsmitha Karunanithi } 6725eb468daSGeorge Liu }); 6735cb1dd27SAsmitha Karunanithi } 6745cb1dd27SAsmitha Karunanithi 6758d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6769878256fSStanley Chu const std::string& entryID, 677b47452b2SAsmitha Karunanithi const std::string& dumpType) 6785cb1dd27SAsmitha Karunanithi { 6795a39f77aSPatrick Williams auto respHandler = [asyncResp, 6805a39f77aSPatrick Williams entryID](const boost::system::error_code& ec) { 68162598e31SEd Tanous BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done"); 6825cb1dd27SAsmitha Karunanithi if (ec) 6835cb1dd27SAsmitha Karunanithi { 6843de8d8baSGeorge Liu if (ec.value() == EBADR) 6853de8d8baSGeorge Liu { 6863de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 6873de8d8baSGeorge Liu return; 6883de8d8baSGeorge Liu } 68962598e31SEd Tanous BMCWEB_LOG_ERROR( 69062598e31SEd Tanous "Dump (DBus) doDelete respHandler got error {} entryID={}", ec, 69162598e31SEd Tanous entryID); 6925cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6935cb1dd27SAsmitha Karunanithi return; 6945cb1dd27SAsmitha Karunanithi } 6955cb1dd27SAsmitha Karunanithi }; 6965cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 6975cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 698b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 699b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 700b47452b2SAsmitha Karunanithi entryID, 7015cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 7025cb1dd27SAsmitha Karunanithi } 7035cb1dd27SAsmitha Karunanithi 704168d1b1aSCarson Labrado inline void 705168d1b1aSCarson Labrado downloadEntryCallback(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 706168d1b1aSCarson Labrado const std::string& entryID, 707168d1b1aSCarson Labrado const std::string& downloadEntryType, 708168d1b1aSCarson Labrado const boost::system::error_code& ec, 709168d1b1aSCarson Labrado const sdbusplus::message::unix_fd& unixfd) 710168d1b1aSCarson Labrado { 711168d1b1aSCarson Labrado if (ec.value() == EBADR) 712168d1b1aSCarson Labrado { 713168d1b1aSCarson Labrado messages::resourceNotFound(asyncResp->res, "EntryAttachment", entryID); 714168d1b1aSCarson Labrado return; 715168d1b1aSCarson Labrado } 716168d1b1aSCarson Labrado if (ec) 717168d1b1aSCarson Labrado { 718168d1b1aSCarson Labrado BMCWEB_LOG_ERROR("DBUS response error: {}", ec); 719168d1b1aSCarson Labrado messages::internalError(asyncResp->res); 720168d1b1aSCarson Labrado return; 721168d1b1aSCarson Labrado } 722168d1b1aSCarson Labrado 723168d1b1aSCarson Labrado // Make sure we know how to process the retrieved entry attachment 724168d1b1aSCarson Labrado if ((downloadEntryType != "BMC") && (downloadEntryType != "System")) 725168d1b1aSCarson Labrado { 726168d1b1aSCarson Labrado BMCWEB_LOG_ERROR("downloadEntryCallback() invalid entry type: {}", 727168d1b1aSCarson Labrado downloadEntryType); 728168d1b1aSCarson Labrado messages::internalError(asyncResp->res); 729168d1b1aSCarson Labrado } 730168d1b1aSCarson Labrado 731168d1b1aSCarson Labrado int fd = -1; 732168d1b1aSCarson Labrado fd = dup(unixfd); 733168d1b1aSCarson Labrado if (fd < 0) 734168d1b1aSCarson Labrado { 735168d1b1aSCarson Labrado BMCWEB_LOG_ERROR("Failed to open file"); 736168d1b1aSCarson Labrado messages::internalError(asyncResp->res); 737168d1b1aSCarson Labrado return; 738168d1b1aSCarson Labrado } 739168d1b1aSCarson Labrado 740168d1b1aSCarson Labrado long long int size = lseek(fd, 0, SEEK_END); 741168d1b1aSCarson Labrado if (size <= 0) 742168d1b1aSCarson Labrado { 743168d1b1aSCarson Labrado BMCWEB_LOG_ERROR("Failed to get size of file, lseek() returned {}", 744168d1b1aSCarson Labrado size); 745168d1b1aSCarson Labrado messages::internalError(asyncResp->res); 746168d1b1aSCarson Labrado close(fd); 747168d1b1aSCarson Labrado return; 748168d1b1aSCarson Labrado } 749168d1b1aSCarson Labrado 750168d1b1aSCarson Labrado // Arbitrary max size of 20MB to accommodate BMC dumps 751168d1b1aSCarson Labrado constexpr int maxFileSize = 20 * 1024 * 1024; 752168d1b1aSCarson Labrado if (size > maxFileSize) 753168d1b1aSCarson Labrado { 754168d1b1aSCarson Labrado BMCWEB_LOG_ERROR("File size {} exceeds maximum allowed size of {}", 755168d1b1aSCarson Labrado size, maxFileSize); 756168d1b1aSCarson Labrado messages::internalError(asyncResp->res); 757168d1b1aSCarson Labrado close(fd); 758168d1b1aSCarson Labrado return; 759168d1b1aSCarson Labrado } 760168d1b1aSCarson Labrado long long int rc = lseek(fd, 0, SEEK_SET); 761168d1b1aSCarson Labrado if (rc < 0) 762168d1b1aSCarson Labrado { 763168d1b1aSCarson Labrado BMCWEB_LOG_ERROR("Failed to reset file offset to 0"); 764168d1b1aSCarson Labrado messages::internalError(asyncResp->res); 765168d1b1aSCarson Labrado close(fd); 766168d1b1aSCarson Labrado return; 767168d1b1aSCarson Labrado } 768168d1b1aSCarson Labrado 769*27b0cf90SEd Tanous std::string body; 770*27b0cf90SEd Tanous body.resize(static_cast<size_t>(size), '\0'); 771*27b0cf90SEd Tanous rc = read(fd, body.data(), body.size()); 772168d1b1aSCarson Labrado if ((rc == -1) || (rc != size)) 773168d1b1aSCarson Labrado { 774168d1b1aSCarson Labrado BMCWEB_LOG_ERROR("Failed to read in file"); 775168d1b1aSCarson Labrado messages::internalError(asyncResp->res); 776168d1b1aSCarson Labrado close(fd); 777168d1b1aSCarson Labrado return; 778168d1b1aSCarson Labrado } 779168d1b1aSCarson Labrado close(fd); 780168d1b1aSCarson Labrado if (downloadEntryType == "System") 781168d1b1aSCarson Labrado { 782*27b0cf90SEd Tanous // Base64 encode response. 783*27b0cf90SEd Tanous asyncResp->res.write(crow::utility::base64encode(body)); 784168d1b1aSCarson Labrado asyncResp->res.addHeader( 785168d1b1aSCarson Labrado boost::beast::http::field::content_transfer_encoding, "Base64"); 786168d1b1aSCarson Labrado } 787*27b0cf90SEd Tanous else 788*27b0cf90SEd Tanous { 789*27b0cf90SEd Tanous asyncResp->res.write(std::move(body)); 790*27b0cf90SEd Tanous } 791168d1b1aSCarson Labrado 792168d1b1aSCarson Labrado asyncResp->res.addHeader(boost::beast::http::field::content_type, 793168d1b1aSCarson Labrado "application/octet-stream"); 794168d1b1aSCarson Labrado } 795168d1b1aSCarson Labrado 796168d1b1aSCarson Labrado inline void 797168d1b1aSCarson Labrado downloadDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 798168d1b1aSCarson Labrado const std::string& entryID, const std::string& dumpType) 799168d1b1aSCarson Labrado { 800168d1b1aSCarson Labrado if (dumpType != "BMC") 801168d1b1aSCarson Labrado { 802168d1b1aSCarson Labrado BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID); 803168d1b1aSCarson Labrado messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID); 804168d1b1aSCarson Labrado return; 805168d1b1aSCarson Labrado } 806168d1b1aSCarson Labrado 807168d1b1aSCarson Labrado std::string dumpEntryPath = 808168d1b1aSCarson Labrado sdbusplus::message::object_path("/xyz/openbmc_project/dump/") / 809168d1b1aSCarson Labrado std::string(boost::algorithm::to_lower_copy(dumpType)) / "entry" / 810168d1b1aSCarson Labrado entryID; 811168d1b1aSCarson Labrado 812168d1b1aSCarson Labrado auto downloadDumpEntryHandler = 813168d1b1aSCarson Labrado [asyncResp, entryID, 814168d1b1aSCarson Labrado dumpType](const boost::system::error_code& ec, 815168d1b1aSCarson Labrado const sdbusplus::message::unix_fd& unixfd) { 816168d1b1aSCarson Labrado downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd); 817168d1b1aSCarson Labrado }; 818168d1b1aSCarson Labrado 819168d1b1aSCarson Labrado crow::connections::systemBus->async_method_call( 820168d1b1aSCarson Labrado std::move(downloadDumpEntryHandler), "xyz.openbmc_project.Dump.Manager", 821168d1b1aSCarson Labrado dumpEntryPath, "xyz.openbmc_project.Dump.Entry", "GetFileHandle"); 822168d1b1aSCarson Labrado } 823168d1b1aSCarson Labrado 824168d1b1aSCarson Labrado inline void 825168d1b1aSCarson Labrado downloadEventLogEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 826168d1b1aSCarson Labrado const std::string& systemName, 827168d1b1aSCarson Labrado const std::string& entryID, 828168d1b1aSCarson Labrado const std::string& dumpType) 829168d1b1aSCarson Labrado { 830168d1b1aSCarson Labrado if constexpr (bmcwebEnableMultiHost) 831168d1b1aSCarson Labrado { 832168d1b1aSCarson Labrado // Option currently returns no systems. TBD 833168d1b1aSCarson Labrado messages::resourceNotFound(asyncResp->res, "ComputerSystem", 834168d1b1aSCarson Labrado systemName); 835168d1b1aSCarson Labrado return; 836168d1b1aSCarson Labrado } 837168d1b1aSCarson Labrado if (systemName != "system") 838168d1b1aSCarson Labrado { 839168d1b1aSCarson Labrado messages::resourceNotFound(asyncResp->res, "ComputerSystem", 840168d1b1aSCarson Labrado systemName); 841168d1b1aSCarson Labrado return; 842168d1b1aSCarson Labrado } 843168d1b1aSCarson Labrado 844168d1b1aSCarson Labrado std::string entryPath = 845168d1b1aSCarson Labrado sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") / 846168d1b1aSCarson Labrado entryID; 847168d1b1aSCarson Labrado 848168d1b1aSCarson Labrado auto downloadEventLogEntryHandler = 849168d1b1aSCarson Labrado [asyncResp, entryID, 850168d1b1aSCarson Labrado dumpType](const boost::system::error_code& ec, 851168d1b1aSCarson Labrado const sdbusplus::message::unix_fd& unixfd) { 852168d1b1aSCarson Labrado downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd); 853168d1b1aSCarson Labrado }; 854168d1b1aSCarson Labrado 855168d1b1aSCarson Labrado crow::connections::systemBus->async_method_call( 856168d1b1aSCarson Labrado std::move(downloadEventLogEntryHandler), "xyz.openbmc_project.Logging", 857168d1b1aSCarson Labrado entryPath, "xyz.openbmc_project.Logging.Entry", "GetEntry"); 858168d1b1aSCarson Labrado } 859168d1b1aSCarson Labrado 8608e31778eSAsmitha Karunanithi inline DumpCreationProgress 8618e31778eSAsmitha Karunanithi mapDbusStatusToDumpProgress(const std::string& status) 862a43be80fSAsmitha Karunanithi { 8638e31778eSAsmitha Karunanithi if (status == 8648e31778eSAsmitha Karunanithi "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" || 8658e31778eSAsmitha Karunanithi status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted") 8668e31778eSAsmitha Karunanithi { 8678e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_FAILED; 8688e31778eSAsmitha Karunanithi } 8698e31778eSAsmitha Karunanithi if (status == 8708e31778eSAsmitha Karunanithi "xyz.openbmc_project.Common.Progress.OperationStatus.Completed") 8718e31778eSAsmitha Karunanithi { 8728e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_SUCCESS; 8738e31778eSAsmitha Karunanithi } 8748e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_INPROGRESS; 8758e31778eSAsmitha Karunanithi } 8768e31778eSAsmitha Karunanithi 8778e31778eSAsmitha Karunanithi inline DumpCreationProgress 8788e31778eSAsmitha Karunanithi getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values) 8798e31778eSAsmitha Karunanithi { 8808e31778eSAsmitha Karunanithi for (const auto& [key, val] : values) 8818e31778eSAsmitha Karunanithi { 8828e31778eSAsmitha Karunanithi if (key == "Status") 8838e31778eSAsmitha Karunanithi { 8848e31778eSAsmitha Karunanithi const std::string* value = std::get_if<std::string>(&val); 8858e31778eSAsmitha Karunanithi if (value == nullptr) 8868e31778eSAsmitha Karunanithi { 88762598e31SEd Tanous BMCWEB_LOG_ERROR("Status property value is null"); 8888e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_FAILED; 8898e31778eSAsmitha Karunanithi } 8908e31778eSAsmitha Karunanithi return mapDbusStatusToDumpProgress(*value); 8918e31778eSAsmitha Karunanithi } 8928e31778eSAsmitha Karunanithi } 8938e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_INPROGRESS; 8948e31778eSAsmitha Karunanithi } 8958e31778eSAsmitha Karunanithi 8968e31778eSAsmitha Karunanithi inline std::string getDumpEntryPath(const std::string& dumpPath) 8978e31778eSAsmitha Karunanithi { 8988e31778eSAsmitha Karunanithi if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry") 8998e31778eSAsmitha Karunanithi { 9008e31778eSAsmitha Karunanithi return "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 9018e31778eSAsmitha Karunanithi } 9028e31778eSAsmitha Karunanithi if (dumpPath == "/xyz/openbmc_project/dump/system/entry") 9038e31778eSAsmitha Karunanithi { 9048e31778eSAsmitha Karunanithi return "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 9058e31778eSAsmitha Karunanithi } 9068e31778eSAsmitha Karunanithi return ""; 9078e31778eSAsmitha Karunanithi } 9088e31778eSAsmitha Karunanithi 9098e31778eSAsmitha Karunanithi inline void createDumpTaskCallback( 9108e31778eSAsmitha Karunanithi task::Payload&& payload, 9118e31778eSAsmitha Karunanithi const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 9128e31778eSAsmitha Karunanithi const sdbusplus::message::object_path& createdObjPath) 9138e31778eSAsmitha Karunanithi { 9148e31778eSAsmitha Karunanithi const std::string dumpPath = createdObjPath.parent_path().str; 9158e31778eSAsmitha Karunanithi const std::string dumpId = createdObjPath.filename(); 9168e31778eSAsmitha Karunanithi 9178e31778eSAsmitha Karunanithi std::string dumpEntryPath = getDumpEntryPath(dumpPath); 9188e31778eSAsmitha Karunanithi 9198e31778eSAsmitha Karunanithi if (dumpEntryPath.empty()) 9208e31778eSAsmitha Karunanithi { 92162598e31SEd Tanous BMCWEB_LOG_ERROR("Invalid dump type received"); 9228e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 9238e31778eSAsmitha Karunanithi return; 9248e31778eSAsmitha Karunanithi } 9258e31778eSAsmitha Karunanithi 9268e31778eSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 9278e31778eSAsmitha Karunanithi [asyncResp, payload, createdObjPath, 9288e31778eSAsmitha Karunanithi dumpEntryPath{std::move(dumpEntryPath)}, 9295e7e2dc5SEd Tanous dumpId](const boost::system::error_code& ec, 9308e31778eSAsmitha Karunanithi const std::string& introspectXml) { 9318e31778eSAsmitha Karunanithi if (ec) 9328e31778eSAsmitha Karunanithi { 93362598e31SEd Tanous BMCWEB_LOG_ERROR("Introspect call failed with error: {}", 93462598e31SEd Tanous ec.message()); 9358e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 9368e31778eSAsmitha Karunanithi return; 9378e31778eSAsmitha Karunanithi } 9388e31778eSAsmitha Karunanithi 9398e31778eSAsmitha Karunanithi // Check if the created dump object has implemented Progress 9408e31778eSAsmitha Karunanithi // interface to track dump completion. If yes, fetch the "Status" 9418e31778eSAsmitha Karunanithi // property of the interface, modify the task state accordingly. 9428e31778eSAsmitha Karunanithi // Else, return task completed. 9438e31778eSAsmitha Karunanithi tinyxml2::XMLDocument doc; 9448e31778eSAsmitha Karunanithi 9458e31778eSAsmitha Karunanithi doc.Parse(introspectXml.data(), introspectXml.size()); 9468e31778eSAsmitha Karunanithi tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node"); 9478e31778eSAsmitha Karunanithi if (pRoot == nullptr) 9488e31778eSAsmitha Karunanithi { 94962598e31SEd Tanous BMCWEB_LOG_ERROR("XML document failed to parse"); 9508e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 9518e31778eSAsmitha Karunanithi return; 9528e31778eSAsmitha Karunanithi } 9538e31778eSAsmitha Karunanithi tinyxml2::XMLElement* interfaceNode = 9548e31778eSAsmitha Karunanithi pRoot->FirstChildElement("interface"); 9558e31778eSAsmitha Karunanithi 9568e31778eSAsmitha Karunanithi bool isProgressIntfPresent = false; 9578e31778eSAsmitha Karunanithi while (interfaceNode != nullptr) 9588e31778eSAsmitha Karunanithi { 9598e31778eSAsmitha Karunanithi const char* thisInterfaceName = interfaceNode->Attribute("name"); 9608e31778eSAsmitha Karunanithi if (thisInterfaceName != nullptr) 9618e31778eSAsmitha Karunanithi { 9628e31778eSAsmitha Karunanithi if (thisInterfaceName == 9638e31778eSAsmitha Karunanithi std::string_view("xyz.openbmc_project.Common.Progress")) 9648e31778eSAsmitha Karunanithi { 9658e31778eSAsmitha Karunanithi interfaceNode = 9668e31778eSAsmitha Karunanithi interfaceNode->NextSiblingElement("interface"); 9678e31778eSAsmitha Karunanithi continue; 9688e31778eSAsmitha Karunanithi } 9698e31778eSAsmitha Karunanithi isProgressIntfPresent = true; 9708e31778eSAsmitha Karunanithi break; 9718e31778eSAsmitha Karunanithi } 9728e31778eSAsmitha Karunanithi interfaceNode = interfaceNode->NextSiblingElement("interface"); 9738e31778eSAsmitha Karunanithi } 9748e31778eSAsmitha Karunanithi 975a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 9768e31778eSAsmitha Karunanithi [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent]( 9778b24275dSEd Tanous const boost::system::error_code& ec2, sdbusplus::message_t& msg, 978a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 9798b24275dSEd Tanous if (ec2) 980cb13a392SEd Tanous { 98162598e31SEd Tanous BMCWEB_LOG_ERROR("{}: Error in creating dump", 98262598e31SEd Tanous createdObjPath.str); 9838e31778eSAsmitha Karunanithi taskData->messages.emplace_back(messages::internalError()); 9846145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 9856145ed6fSAsmitha Karunanithi return task::completed; 986cb13a392SEd Tanous } 987b9d36b47SEd Tanous 9888e31778eSAsmitha Karunanithi if (isProgressIntfPresent) 989a43be80fSAsmitha Karunanithi { 9908e31778eSAsmitha Karunanithi dbus::utility::DBusPropertiesMap values; 9918e31778eSAsmitha Karunanithi std::string prop; 9928e31778eSAsmitha Karunanithi msg.read(prop, values); 9938e31778eSAsmitha Karunanithi 9948e31778eSAsmitha Karunanithi DumpCreationProgress dumpStatus = 9958e31778eSAsmitha Karunanithi getDumpCompletionStatus(values); 9968e31778eSAsmitha Karunanithi if (dumpStatus == DumpCreationProgress::DUMP_CREATE_FAILED) 9978e31778eSAsmitha Karunanithi { 99862598e31SEd Tanous BMCWEB_LOG_ERROR("{}: Error in creating dump", 99962598e31SEd Tanous createdObjPath.str); 10008e31778eSAsmitha Karunanithi taskData->state = "Cancelled"; 10018e31778eSAsmitha Karunanithi return task::completed; 10028e31778eSAsmitha Karunanithi } 10038e31778eSAsmitha Karunanithi 10048e31778eSAsmitha Karunanithi if (dumpStatus == DumpCreationProgress::DUMP_CREATE_INPROGRESS) 10058e31778eSAsmitha Karunanithi { 100662598e31SEd Tanous BMCWEB_LOG_DEBUG("{}: Dump creation task is in progress", 100762598e31SEd Tanous createdObjPath.str); 10088e31778eSAsmitha Karunanithi return !task::completed; 10098e31778eSAsmitha Karunanithi } 10108e31778eSAsmitha Karunanithi } 10118e31778eSAsmitha Karunanithi 1012a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 1013a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 1014a43be80fSAsmitha Karunanithi 1015c51a58eeSEd Tanous boost::urls::url url = boost::urls::format( 1016c51a58eeSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/{}", dumpId); 1017c51a58eeSEd Tanous 1018c51a58eeSEd Tanous std::string headerLoc = "Location: "; 1019c51a58eeSEd Tanous headerLoc += url.buffer(); 1020c51a58eeSEd Tanous 1021002d39b4SEd Tanous taskData->payload->httpHeaders.emplace_back(std::move(headerLoc)); 1022a43be80fSAsmitha Karunanithi 102362598e31SEd Tanous BMCWEB_LOG_DEBUG("{}: Dump creation task completed", 102462598e31SEd Tanous createdObjPath.str); 1025a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 1026b47452b2SAsmitha Karunanithi return task::completed; 1027a43be80fSAsmitha Karunanithi }, 10288e31778eSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus.Properties'," 10298e31778eSAsmitha Karunanithi "member='PropertiesChanged',path='" + 10308e31778eSAsmitha Karunanithi createdObjPath.str + "'"); 1031a43be80fSAsmitha Karunanithi 10328e31778eSAsmitha Karunanithi // The task timer is set to max time limit within which the 10338e31778eSAsmitha Karunanithi // requested dump will be collected. 10348e31778eSAsmitha Karunanithi task->startTimer(std::chrono::minutes(6)); 1035a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 10368e31778eSAsmitha Karunanithi task->payload.emplace(payload); 10378e31778eSAsmitha Karunanithi }, 10388e31778eSAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", createdObjPath, 10398e31778eSAsmitha Karunanithi "org.freedesktop.DBus.Introspectable", "Introspect"); 1040a43be80fSAsmitha Karunanithi } 1041a43be80fSAsmitha Karunanithi 10428d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 10438d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 1044a43be80fSAsmitha Karunanithi { 1045fdd26906SClaire Weinan std::string dumpPath = getDumpEntriesPath(dumpType); 1046fdd26906SClaire Weinan if (dumpPath.empty()) 1047a43be80fSAsmitha Karunanithi { 1048a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 1049a43be80fSAsmitha Karunanithi return; 1050a43be80fSAsmitha Karunanithi } 1051a43be80fSAsmitha Karunanithi 1052a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 1053a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 1054a43be80fSAsmitha Karunanithi 105515ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 1056a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 1057a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 1058a43be80fSAsmitha Karunanithi { 1059a43be80fSAsmitha Karunanithi return; 1060a43be80fSAsmitha Karunanithi } 1061a43be80fSAsmitha Karunanithi 1062a43be80fSAsmitha Karunanithi if (dumpType == "System") 1063a43be80fSAsmitha Karunanithi { 1064a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 1065a43be80fSAsmitha Karunanithi { 106662598e31SEd Tanous BMCWEB_LOG_ERROR( 106762598e31SEd Tanous "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"); 1068a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 1069a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 1070a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 1071a43be80fSAsmitha Karunanithi return; 1072a43be80fSAsmitha Karunanithi } 10733174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 1074a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 1075a43be80fSAsmitha Karunanithi { 107662598e31SEd Tanous BMCWEB_LOG_ERROR("Wrong parameter values passed"); 1077ace85d60SEd Tanous messages::internalError(asyncResp->res); 1078a43be80fSAsmitha Karunanithi return; 1079a43be80fSAsmitha Karunanithi } 10805907571dSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/"; 1081a43be80fSAsmitha Karunanithi } 1082a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 1083a43be80fSAsmitha Karunanithi { 1084a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 1085a43be80fSAsmitha Karunanithi { 108662598e31SEd Tanous BMCWEB_LOG_ERROR( 108762598e31SEd Tanous "CreateDump action parameter 'DiagnosticDataType' not found!"); 1088a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 1089a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 1090a43be80fSAsmitha Karunanithi return; 1091a43be80fSAsmitha Karunanithi } 10923174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 1093a43be80fSAsmitha Karunanithi { 109462598e31SEd Tanous BMCWEB_LOG_ERROR( 109562598e31SEd Tanous "Wrong parameter value passed for 'DiagnosticDataType'"); 1096ace85d60SEd Tanous messages::internalError(asyncResp->res); 1097a43be80fSAsmitha Karunanithi return; 1098a43be80fSAsmitha Karunanithi } 10995907571dSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/"; 11005907571dSAsmitha Karunanithi } 11015907571dSAsmitha Karunanithi else 11025907571dSAsmitha Karunanithi { 110362598e31SEd Tanous BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type"); 11045907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 11055907571dSAsmitha Karunanithi return; 1106a43be80fSAsmitha Karunanithi } 1107a43be80fSAsmitha Karunanithi 11088e31778eSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>> 11098e31778eSAsmitha Karunanithi createDumpParamVec; 11108e31778eSAsmitha Karunanithi 1111f574a8e1SCarson Labrado if (req.session != nullptr) 1112f574a8e1SCarson Labrado { 111368dd075aSAsmitha Karunanithi createDumpParamVec.emplace_back( 111468dd075aSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId", 111568dd075aSAsmitha Karunanithi req.session->clientIp); 111668dd075aSAsmitha Karunanithi createDumpParamVec.emplace_back( 111768dd075aSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType", 111868dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client"); 1119f574a8e1SCarson Labrado } 112068dd075aSAsmitha Karunanithi 1121a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 11225e7e2dc5SEd Tanous [asyncResp, payload(task::Payload(req)), 11235e7e2dc5SEd Tanous dumpPath](const boost::system::error_code& ec, 11245e7e2dc5SEd Tanous const sdbusplus::message_t& msg, 11258e31778eSAsmitha Karunanithi const sdbusplus::message::object_path& objPath) mutable { 1126a43be80fSAsmitha Karunanithi if (ec) 1127a43be80fSAsmitha Karunanithi { 112862598e31SEd Tanous BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec); 11295907571dSAsmitha Karunanithi const sd_bus_error* dbusError = msg.get_error(); 11305907571dSAsmitha Karunanithi if (dbusError == nullptr) 11315907571dSAsmitha Karunanithi { 11325907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 11335907571dSAsmitha Karunanithi return; 11345907571dSAsmitha Karunanithi } 11355907571dSAsmitha Karunanithi 113662598e31SEd Tanous BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}", 113762598e31SEd Tanous dbusError->name, dbusError->message); 11385907571dSAsmitha Karunanithi if (std::string_view( 11395907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.NotAllowed") == 11405907571dSAsmitha Karunanithi dbusError->name) 11415907571dSAsmitha Karunanithi { 11425907571dSAsmitha Karunanithi messages::resourceInStandby(asyncResp->res); 11435907571dSAsmitha Karunanithi return; 11445907571dSAsmitha Karunanithi } 11455907571dSAsmitha Karunanithi if (std::string_view( 11465907571dSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.Error.Disabled") == 11475907571dSAsmitha Karunanithi dbusError->name) 11485907571dSAsmitha Karunanithi { 11495907571dSAsmitha Karunanithi messages::serviceDisabled(asyncResp->res, dumpPath); 11505907571dSAsmitha Karunanithi return; 11515907571dSAsmitha Karunanithi } 11525907571dSAsmitha Karunanithi if (std::string_view( 11535907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.Unavailable") == 11545907571dSAsmitha Karunanithi dbusError->name) 11555907571dSAsmitha Karunanithi { 11565907571dSAsmitha Karunanithi messages::resourceInUse(asyncResp->res); 11575907571dSAsmitha Karunanithi return; 11585907571dSAsmitha Karunanithi } 11595907571dSAsmitha Karunanithi // Other Dbus errors such as: 11605907571dSAsmitha Karunanithi // xyz.openbmc_project.Common.Error.InvalidArgument & 11615907571dSAsmitha Karunanithi // org.freedesktop.DBus.Error.InvalidArgs are all related to 11625907571dSAsmitha Karunanithi // the dbus call that is made here in the bmcweb 11635907571dSAsmitha Karunanithi // implementation and has nothing to do with the client's 11645907571dSAsmitha Karunanithi // input in the request. Hence, returning internal error 11655907571dSAsmitha Karunanithi // back to the client. 1166a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 1167a43be80fSAsmitha Karunanithi return; 1168a43be80fSAsmitha Karunanithi } 116962598e31SEd Tanous BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str); 11708e31778eSAsmitha Karunanithi createDumpTaskCallback(std::move(payload), asyncResp, objPath); 1171a43be80fSAsmitha Karunanithi }, 1172b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 1173b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 1174b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 11758e31778eSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec); 1176a43be80fSAsmitha Karunanithi } 1177a43be80fSAsmitha Karunanithi 11788d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 11798d1b46d7Szhanghch05 const std::string& dumpType) 118080319af1SAsmitha Karunanithi { 1181b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 1182b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 11838d1b46d7Szhanghch05 11840d946211SClaire Weinan crow::connections::systemBus->async_method_call( 11850d946211SClaire Weinan [asyncResp](const boost::system::error_code& ec) { 118680319af1SAsmitha Karunanithi if (ec) 118780319af1SAsmitha Karunanithi { 118862598e31SEd Tanous BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec); 118980319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 119080319af1SAsmitha Karunanithi return; 119180319af1SAsmitha Karunanithi } 11920d946211SClaire Weinan }, 11930d946211SClaire Weinan "xyz.openbmc_project.Dump.Manager", 11940d946211SClaire Weinan "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 11950d946211SClaire Weinan "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 119680319af1SAsmitha Karunanithi } 119780319af1SAsmitha Karunanithi 1198b9d36b47SEd Tanous inline static void 1199b9d36b47SEd Tanous parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params, 1200b9d36b47SEd Tanous std::string& filename, std::string& timestamp, 1201b9d36b47SEd Tanous std::string& logfile) 1202043a0536SJohnathan Mantey { 1203d1bde9e5SKrzysztof Grobelny const std::string* filenamePtr = nullptr; 1204d1bde9e5SKrzysztof Grobelny const std::string* timestampPtr = nullptr; 1205d1bde9e5SKrzysztof Grobelny const std::string* logfilePtr = nullptr; 1206d1bde9e5SKrzysztof Grobelny 1207d1bde9e5SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1208d1bde9e5SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr, 1209d1bde9e5SKrzysztof Grobelny "Filename", filenamePtr, "Log", logfilePtr); 1210d1bde9e5SKrzysztof Grobelny 1211d1bde9e5SKrzysztof Grobelny if (!success) 1212043a0536SJohnathan Mantey { 1213d1bde9e5SKrzysztof Grobelny return; 1214043a0536SJohnathan Mantey } 1215d1bde9e5SKrzysztof Grobelny 1216d1bde9e5SKrzysztof Grobelny if (filenamePtr != nullptr) 1217043a0536SJohnathan Mantey { 1218d1bde9e5SKrzysztof Grobelny filename = *filenamePtr; 1219d1bde9e5SKrzysztof Grobelny } 1220d1bde9e5SKrzysztof Grobelny 1221d1bde9e5SKrzysztof Grobelny if (timestampPtr != nullptr) 1222043a0536SJohnathan Mantey { 1223d1bde9e5SKrzysztof Grobelny timestamp = *timestampPtr; 1224043a0536SJohnathan Mantey } 1225d1bde9e5SKrzysztof Grobelny 1226d1bde9e5SKrzysztof Grobelny if (logfilePtr != nullptr) 1227043a0536SJohnathan Mantey { 1228d1bde9e5SKrzysztof Grobelny logfile = *logfilePtr; 1229043a0536SJohnathan Mantey } 1230043a0536SJohnathan Mantey } 1231043a0536SJohnathan Mantey 12327e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 12331da66f75SEd Tanous { 1234c4bf6374SJason M. Bills /** 1235c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 1236c4bf6374SJason M. Bills */ 123722d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/") 1238ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 1239002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1240002d39b4SEd Tanous [&app](const crow::Request& req, 124122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 124222d268cbSEd Tanous const std::string& systemName) { 12433ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1244c4bf6374SJason M. Bills { 124545ca1b86SEd Tanous return; 124645ca1b86SEd Tanous } 12477f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 12487f3e84a1SEd Tanous { 12497f3e84a1SEd Tanous // Option currently returns no systems. TBD 12507f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 12517f3e84a1SEd Tanous systemName); 12527f3e84a1SEd Tanous return; 12537f3e84a1SEd Tanous } 125422d268cbSEd Tanous if (systemName != "system") 125522d268cbSEd Tanous { 125622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 125722d268cbSEd Tanous systemName); 125822d268cbSEd Tanous return; 125922d268cbSEd Tanous } 126022d268cbSEd Tanous 12617e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 12627e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1263c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1264c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 1265c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1266029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 126745ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 1268c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1269c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 1270002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 1271c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 12721476687dSEd Tanous nlohmann::json::object_t eventLog; 12731476687dSEd Tanous eventLog["@odata.id"] = 12741476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1275b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(eventLog)); 12765cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 12771476687dSEd Tanous nlohmann::json::object_t dumpLog; 1278002d39b4SEd Tanous dumpLog["@odata.id"] = "/redfish/v1/Systems/system/LogServices/Dump"; 1279b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(dumpLog)); 1280c9bb6861Sraviteja-b #endif 1281c9bb6861Sraviteja-b 1282d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 12831476687dSEd Tanous nlohmann::json::object_t crashdump; 12841476687dSEd Tanous crashdump["@odata.id"] = 12851476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump"; 1286b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(crashdump)); 1287d53dd41fSJason M. Bills #endif 1288b7028ebfSSpencer Ku 1289b7028ebfSSpencer Ku #ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER 12901476687dSEd Tanous nlohmann::json::object_t hostlogger; 12911476687dSEd Tanous hostlogger["@odata.id"] = 12921476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger"; 1293b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(hostlogger)); 1294b7028ebfSSpencer Ku #endif 1295c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1296c4bf6374SJason M. Bills logServiceArray.size(); 1297a3316fc6SZhikuiRen 12987a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 12997a1dbc48SGeorge Liu "xyz.openbmc_project.State.Boot.PostCode"}; 13007a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 13017a1dbc48SGeorge Liu "/", 0, interfaces, 13027a1dbc48SGeorge Liu [asyncResp](const boost::system::error_code& ec, 1303b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& 1304b9d36b47SEd Tanous subtreePath) { 1305a3316fc6SZhikuiRen if (ec) 1306a3316fc6SZhikuiRen { 130762598e31SEd Tanous BMCWEB_LOG_ERROR("{}", ec); 1308a3316fc6SZhikuiRen return; 1309a3316fc6SZhikuiRen } 1310a3316fc6SZhikuiRen 131155f79e6fSEd Tanous for (const auto& pathStr : subtreePath) 1312a3316fc6SZhikuiRen { 1313a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 1314a3316fc6SZhikuiRen { 131523a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 1316a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 1317613dabeaSEd Tanous nlohmann::json::object_t member; 1318613dabeaSEd Tanous member["@odata.id"] = 1319613dabeaSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes"; 1320613dabeaSEd Tanous 1321b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 1322613dabeaSEd Tanous 132345ca1b86SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 132423a21a1cSEd Tanous logServiceArrayLocal.size(); 1325a3316fc6SZhikuiRen return; 1326a3316fc6SZhikuiRen } 1327a3316fc6SZhikuiRen } 13287a1dbc48SGeorge Liu }); 13297e860f15SJohn Edward Broadbent }); 1330c4bf6374SJason M. Bills } 1331c4bf6374SJason M. Bills 13327e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 1333c4bf6374SJason M. Bills { 133422d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/") 1335ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 1336002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1337002d39b4SEd Tanous [&app](const crow::Request& req, 133822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 133922d268cbSEd Tanous const std::string& systemName) { 13403ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 134145ca1b86SEd Tanous { 134245ca1b86SEd Tanous return; 134345ca1b86SEd Tanous } 134422d268cbSEd Tanous if (systemName != "system") 134522d268cbSEd Tanous { 134622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 134722d268cbSEd Tanous systemName); 134822d268cbSEd Tanous return; 134922d268cbSEd Tanous } 1350c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1351029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1352c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1353b25644a1SJanet Adkins "#LogService.v1_2_0.LogService"; 1354c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 1355002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 1356c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1357c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 13587c8c4058STejas Patil 13597c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 13602b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 13617c8c4058STejas Patil 13627c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 13637c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 13647c8c4058STejas Patil redfishDateTimeOffset.second; 13657c8c4058STejas Patil 13661476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 13671476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1368e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1369e7d6c8b2SGunnar Mills 13700fda0f12SGeorge Liu {"target", 13710fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog"}}; 13727e860f15SJohn Edward Broadbent }); 1373489640c6SJason M. Bills } 1374489640c6SJason M. Bills 13757e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1376489640c6SJason M. Bills { 13774978b63fSJason M. Bills BMCWEB_ROUTE( 13784978b63fSJason M. Bills app, 137922d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 1380432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 13817e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 138245ca1b86SEd Tanous [&app](const crow::Request& req, 138322d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 138422d268cbSEd Tanous const std::string& systemName) { 13853ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 138645ca1b86SEd Tanous { 138745ca1b86SEd Tanous return; 138845ca1b86SEd Tanous } 138922d268cbSEd Tanous if (systemName != "system") 139022d268cbSEd Tanous { 139122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 139222d268cbSEd Tanous systemName); 139322d268cbSEd Tanous return; 139422d268cbSEd Tanous } 1395489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1396489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1397489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1398489640c6SJason M. Bills { 1399489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1400489640c6SJason M. Bills { 1401489640c6SJason M. Bills std::error_code ec; 1402489640c6SJason M. Bills std::filesystem::remove(file, ec); 1403489640c6SJason M. Bills } 1404489640c6SJason M. Bills } 1405489640c6SJason M. Bills 1406489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1407489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 14085e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 1409489640c6SJason M. Bills if (ec) 1410489640c6SJason M. Bills { 141162598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec); 1412489640c6SJason M. Bills messages::internalError(asyncResp->res); 1413489640c6SJason M. Bills return; 1414489640c6SJason M. Bills } 1415489640c6SJason M. Bills 1416489640c6SJason M. Bills messages::success(asyncResp->res); 1417489640c6SJason M. Bills }, 1418489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1419002d39b4SEd Tanous "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1420002d39b4SEd Tanous "replace"); 14217e860f15SJohn Edward Broadbent }); 1422c4bf6374SJason M. Bills } 1423c4bf6374SJason M. Bills 1424ac992cdeSJason M. Bills enum class LogParseError 1425ac992cdeSJason M. Bills { 1426ac992cdeSJason M. Bills success, 1427ac992cdeSJason M. Bills parseFailed, 1428ac992cdeSJason M. Bills messageIdNotInRegistry, 1429ac992cdeSJason M. Bills }; 1430ac992cdeSJason M. Bills 1431ac992cdeSJason M. Bills static LogParseError 1432ac992cdeSJason M. Bills fillEventLogEntryJson(const std::string& logEntryID, 1433b5a76932SEd Tanous const std::string& logEntry, 1434de703c5dSJason M. Bills nlohmann::json::object_t& logEntryJson) 1435c4bf6374SJason M. Bills { 143695820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1437cd225da8SJason M. Bills // First get the Timestamp 1438f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1439cd225da8SJason M. Bills if (space == std::string::npos) 144095820184SJason M. Bills { 1441ac992cdeSJason M. Bills return LogParseError::parseFailed; 144295820184SJason M. Bills } 1443cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1444cd225da8SJason M. Bills // Then get the log contents 1445f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1446cd225da8SJason M. Bills if (entryStart == std::string::npos) 1447cd225da8SJason M. Bills { 1448ac992cdeSJason M. Bills return LogParseError::parseFailed; 1449cd225da8SJason M. Bills } 1450cd225da8SJason M. Bills std::string_view entry(logEntry); 1451cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1452cd225da8SJason M. Bills // Use split to separate the entry into its fields 1453cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 145450ebd4afSEd Tanous bmcweb::split(logEntryFields, entry, ','); 1455cd225da8SJason M. Bills // We need at least a MessageId to be valid 14561e6deaf6SEd Tanous auto logEntryIter = logEntryFields.begin(); 14571e6deaf6SEd Tanous if (logEntryIter == logEntryFields.end()) 1458cd225da8SJason M. Bills { 1459ac992cdeSJason M. Bills return LogParseError::parseFailed; 1460cd225da8SJason M. Bills } 14611e6deaf6SEd Tanous std::string& messageID = *logEntryIter; 14624851d45dSJason M. Bills // Get the Message from the MessageRegistry 1463fffb8c1fSEd Tanous const registries::Message* message = registries::getMessage(messageID); 1464c4bf6374SJason M. Bills 14651e6deaf6SEd Tanous logEntryIter++; 146654417b02SSui Chen if (message == nullptr) 1467c4bf6374SJason M. Bills { 146862598e31SEd Tanous BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry); 1469ac992cdeSJason M. Bills return LogParseError::messageIdNotInRegistry; 1470c4bf6374SJason M. Bills } 1471c4bf6374SJason M. Bills 14721e6deaf6SEd Tanous std::vector<std::string_view> messageArgs(logEntryIter, 14731e6deaf6SEd Tanous logEntryFields.end()); 1474c05bba45SEd Tanous messageArgs.resize(message->numberOfArgs); 1475c05bba45SEd Tanous 14761e6deaf6SEd Tanous std::string msg = redfish::registries::fillMessageArgs(messageArgs, 14771e6deaf6SEd Tanous message->message); 14781e6deaf6SEd Tanous if (msg.empty()) 147915a86ff6SJason M. Bills { 14801e6deaf6SEd Tanous return LogParseError::parseFailed; 148115a86ff6SJason M. Bills } 14824851d45dSJason M. Bills 148395820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 148495820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 148595820184SJason M. Bills // between the '.' and the '+', so just remove them. 1486f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1487f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 148895820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1489c4bf6374SJason M. Bills { 149095820184SJason M. Bills timestamp.erase(dot, plus - dot); 1491c4bf6374SJason M. Bills } 1492c4bf6374SJason M. Bills 1493c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 14949c11a172SVijay Lobo logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 1495ef4c65b7SEd Tanous logEntryJson["@odata.id"] = boost::urls::format( 1496ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/{}", 1497ef4c65b7SEd Tanous logEntryID); 149884afc48bSJason M. Bills logEntryJson["Name"] = "System Event Log Entry"; 149984afc48bSJason M. Bills logEntryJson["Id"] = logEntryID; 150084afc48bSJason M. Bills logEntryJson["Message"] = std::move(msg); 150184afc48bSJason M. Bills logEntryJson["MessageId"] = std::move(messageID); 150284afc48bSJason M. Bills logEntryJson["MessageArgs"] = messageArgs; 150384afc48bSJason M. Bills logEntryJson["EntryType"] = "Event"; 150484afc48bSJason M. Bills logEntryJson["Severity"] = message->messageSeverity; 150584afc48bSJason M. Bills logEntryJson["Created"] = std::move(timestamp); 1506ac992cdeSJason M. Bills return LogParseError::success; 1507c4bf6374SJason M. Bills } 1508c4bf6374SJason M. Bills 15097e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1510c4bf6374SJason M. Bills { 151122d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") 15128b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 1513002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1514002d39b4SEd Tanous [&app](const crow::Request& req, 151522d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 151622d268cbSEd Tanous const std::string& systemName) { 1517c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1518c937d2bfSEd Tanous .canDelegateTop = true, 1519c937d2bfSEd Tanous .canDelegateSkip = true, 1520c937d2bfSEd Tanous }; 1521c937d2bfSEd Tanous query_param::Query delegatedQuery; 1522c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 15233ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 1524c4bf6374SJason M. Bills { 1525c4bf6374SJason M. Bills return; 1526c4bf6374SJason M. Bills } 15277f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 15287f3e84a1SEd Tanous { 15297f3e84a1SEd Tanous // Option currently returns no systems. TBD 15307f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 15317f3e84a1SEd Tanous systemName); 15327f3e84a1SEd Tanous return; 15337f3e84a1SEd Tanous } 153422d268cbSEd Tanous if (systemName != "system") 153522d268cbSEd Tanous { 153622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 153722d268cbSEd Tanous systemName); 153822d268cbSEd Tanous return; 153922d268cbSEd Tanous } 154022d268cbSEd Tanous 15415143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 15423648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 15433648c8beSEd Tanous 15447e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 15457e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1546c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1547c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1548c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1549029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1550c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1551c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1552c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1553cb92c03bSAndrew Geissler 15544978b63fSJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1555c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 15567e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 15577e860f15SJohn Edward Broadbent // entry 155895820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 155995820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1560b01bf299SEd Tanous uint64_t entryCount = 0; 1561cd225da8SJason M. Bills std::string logEntry; 156295820184SJason M. Bills 15637e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 15647e860f15SJohn Edward Broadbent // backwards 1565002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1566002d39b4SEd Tanous it++) 1567c4bf6374SJason M. Bills { 1568cd225da8SJason M. Bills std::ifstream logStream(*it); 156995820184SJason M. Bills if (!logStream.is_open()) 1570c4bf6374SJason M. Bills { 1571c4bf6374SJason M. Bills continue; 1572c4bf6374SJason M. Bills } 1573c4bf6374SJason M. Bills 1574e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1575e85d6b16SJason M. Bills bool firstEntry = true; 157695820184SJason M. Bills while (std::getline(logStream, logEntry)) 157795820184SJason M. Bills { 1578c4bf6374SJason M. Bills std::string idStr; 1579e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1580c4bf6374SJason M. Bills { 1581c4bf6374SJason M. Bills continue; 1582c4bf6374SJason M. Bills } 1583e85d6b16SJason M. Bills firstEntry = false; 1584e85d6b16SJason M. Bills 1585de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 158689492a15SPatrick Williams LogParseError status = fillEventLogEntryJson(idStr, logEntry, 158789492a15SPatrick Williams bmcLogEntry); 1588ac992cdeSJason M. Bills if (status == LogParseError::messageIdNotInRegistry) 1589ac992cdeSJason M. Bills { 1590ac992cdeSJason M. Bills continue; 1591ac992cdeSJason M. Bills } 1592ac992cdeSJason M. Bills if (status != LogParseError::success) 1593c4bf6374SJason M. Bills { 1594c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1595c4bf6374SJason M. Bills return; 1596c4bf6374SJason M. Bills } 1597de703c5dSJason M. Bills 1598de703c5dSJason M. Bills entryCount++; 1599de703c5dSJason M. Bills // Handle paging using skip (number of entries to skip from the 1600de703c5dSJason M. Bills // start) and top (number of entries to display) 16013648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 1602de703c5dSJason M. Bills { 1603de703c5dSJason M. Bills continue; 1604de703c5dSJason M. Bills } 1605de703c5dSJason M. Bills 1606b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(bmcLogEntry)); 1607c4bf6374SJason M. Bills } 160895820184SJason M. Bills } 1609c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 16103648c8beSEd Tanous if (skip + top < entryCount) 1611c4bf6374SJason M. Bills { 1612c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 16134978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries?$skip=" + 16143648c8beSEd Tanous std::to_string(skip + top); 1615c4bf6374SJason M. Bills } 16167e860f15SJohn Edward Broadbent }); 1617897967deSJason M. Bills } 1618897967deSJason M. Bills 16197e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1620897967deSJason M. Bills { 16217e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 162222d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1623ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 16247e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 162545ca1b86SEd Tanous [&app](const crow::Request& req, 16267e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 162722d268cbSEd Tanous const std::string& systemName, const std::string& param) { 16283ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 162945ca1b86SEd Tanous { 163045ca1b86SEd Tanous return; 163145ca1b86SEd Tanous } 16327f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 16337f3e84a1SEd Tanous { 16347f3e84a1SEd Tanous // Option currently returns no systems. TBD 16357f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 16367f3e84a1SEd Tanous systemName); 16377f3e84a1SEd Tanous return; 16387f3e84a1SEd Tanous } 163922d268cbSEd Tanous 164022d268cbSEd Tanous if (systemName != "system") 164122d268cbSEd Tanous { 164222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 164322d268cbSEd Tanous systemName); 164422d268cbSEd Tanous return; 164522d268cbSEd Tanous } 164622d268cbSEd Tanous 16477e860f15SJohn Edward Broadbent const std::string& targetID = param; 16488d1b46d7Szhanghch05 16497e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 16507e860f15SJohn Edward Broadbent // entry to find the target entry 1651897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1652897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1653897967deSJason M. Bills std::string logEntry; 1654897967deSJason M. Bills 16557e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 16567e860f15SJohn Edward Broadbent // backwards 1657002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1658002d39b4SEd Tanous it++) 1659897967deSJason M. Bills { 1660897967deSJason M. Bills std::ifstream logStream(*it); 1661897967deSJason M. Bills if (!logStream.is_open()) 1662897967deSJason M. Bills { 1663897967deSJason M. Bills continue; 1664897967deSJason M. Bills } 1665897967deSJason M. Bills 1666897967deSJason M. Bills // Reset the unique ID on the first entry 1667897967deSJason M. Bills bool firstEntry = true; 1668897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1669897967deSJason M. Bills { 1670897967deSJason M. Bills std::string idStr; 1671897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1672897967deSJason M. Bills { 1673897967deSJason M. Bills continue; 1674897967deSJason M. Bills } 1675897967deSJason M. Bills firstEntry = false; 1676897967deSJason M. Bills 1677897967deSJason M. Bills if (idStr == targetID) 1678897967deSJason M. Bills { 1679de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 1680ac992cdeSJason M. Bills LogParseError status = 1681ac992cdeSJason M. Bills fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); 1682ac992cdeSJason M. Bills if (status != LogParseError::success) 1683897967deSJason M. Bills { 1684897967deSJason M. Bills messages::internalError(asyncResp->res); 1685897967deSJason M. Bills return; 1686897967deSJason M. Bills } 1687d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcLogEntry); 1688897967deSJason M. Bills return; 1689897967deSJason M. Bills } 1690897967deSJason M. Bills } 1691897967deSJason M. Bills } 1692897967deSJason M. Bills // Requested ID was not found 16939db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", targetID); 16947e860f15SJohn Edward Broadbent }); 169508a4e4b5SAnthony Wilson } 169608a4e4b5SAnthony Wilson 16977e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 169808a4e4b5SAnthony Wilson { 169922d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") 1700ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 1701002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1702002d39b4SEd Tanous [&app](const crow::Request& req, 170322d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 170422d268cbSEd Tanous const std::string& systemName) { 17053ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 170645ca1b86SEd Tanous { 170745ca1b86SEd Tanous return; 170845ca1b86SEd Tanous } 17097f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 17107f3e84a1SEd Tanous { 17117f3e84a1SEd Tanous // Option currently returns no systems. TBD 17127f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 17137f3e84a1SEd Tanous systemName); 17147f3e84a1SEd Tanous return; 17157f3e84a1SEd Tanous } 171622d268cbSEd Tanous if (systemName != "system") 171722d268cbSEd Tanous { 171822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 171922d268cbSEd Tanous systemName); 172022d268cbSEd Tanous return; 172122d268cbSEd Tanous } 172222d268cbSEd Tanous 17237e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 17247e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 172508a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 172608a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 172708a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 172808a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 172908a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 173008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 173108a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 173208a4e4b5SAnthony Wilson 1733cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1734cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 17355eb468daSGeorge Liu sdbusplus::message::object_path path("/xyz/openbmc_project/logging"); 17365eb468daSGeorge Liu dbus::utility::getManagedObjects( 17375eb468daSGeorge Liu "xyz.openbmc_project.Logging", path, 17385e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 1739914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& resp) { 1740cb92c03bSAndrew Geissler if (ec) 1741cb92c03bSAndrew Geissler { 1742cb92c03bSAndrew Geissler // TODO Handle for specific error code 174362598e31SEd Tanous BMCWEB_LOG_ERROR( 174462598e31SEd Tanous "getLogEntriesIfaceData resp_handler got error {}", ec); 1745cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1746cb92c03bSAndrew Geissler return; 1747cb92c03bSAndrew Geissler } 17483544d2a7SEd Tanous nlohmann::json::array_t entriesArray; 17499eb808c1SEd Tanous for (const auto& objectPath : resp) 1750cb92c03bSAndrew Geissler { 1751914e2d5dSEd Tanous const uint32_t* id = nullptr; 1752c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1753c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1754914e2d5dSEd Tanous const std::string* severity = nullptr; 1755914e2d5dSEd Tanous const std::string* message = nullptr; 1756914e2d5dSEd Tanous const std::string* filePath = nullptr; 17579c11a172SVijay Lobo const std::string* resolution = nullptr; 175875710de2SXiaochao Ma bool resolved = false; 17599017faf2SAbhishek Patel const std::string* notify = nullptr; 17609017faf2SAbhishek Patel 17619eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 1762f86bb901SAdriana Kobylak { 1763f86bb901SAdriana Kobylak if (interfaceMap.first == 1764f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1765f86bb901SAdriana Kobylak { 1766002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 1767cb92c03bSAndrew Geissler { 1768cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1769cb92c03bSAndrew Geissler { 1770002d39b4SEd Tanous id = std::get_if<uint32_t>(&propertyMap.second); 1771cb92c03bSAndrew Geissler } 1772cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1773cb92c03bSAndrew Geissler { 1774002d39b4SEd Tanous timestamp = 1775002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 17767e860f15SJohn Edward Broadbent } 1777002d39b4SEd Tanous else if (propertyMap.first == "UpdateTimestamp") 17787e860f15SJohn Edward Broadbent { 1779002d39b4SEd Tanous updateTimestamp = 1780002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 17817e860f15SJohn Edward Broadbent } 17827e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 17837e860f15SJohn Edward Broadbent { 17847e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 17857e860f15SJohn Edward Broadbent &propertyMap.second); 17867e860f15SJohn Edward Broadbent } 17879c11a172SVijay Lobo else if (propertyMap.first == "Resolution") 17889c11a172SVijay Lobo { 17899c11a172SVijay Lobo resolution = std::get_if<std::string>( 17909c11a172SVijay Lobo &propertyMap.second); 17919c11a172SVijay Lobo } 17927e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 17937e860f15SJohn Edward Broadbent { 17947e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 17957e860f15SJohn Edward Broadbent &propertyMap.second); 17967e860f15SJohn Edward Broadbent } 17977e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 17987e860f15SJohn Edward Broadbent { 1799914e2d5dSEd Tanous const bool* resolveptr = 1800002d39b4SEd Tanous std::get_if<bool>(&propertyMap.second); 18017e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 18027e860f15SJohn Edward Broadbent { 1803002d39b4SEd Tanous messages::internalError(asyncResp->res); 18047e860f15SJohn Edward Broadbent return; 18057e860f15SJohn Edward Broadbent } 18067e860f15SJohn Edward Broadbent resolved = *resolveptr; 18077e860f15SJohn Edward Broadbent } 18089017faf2SAbhishek Patel else if (propertyMap.first == 18099017faf2SAbhishek Patel "ServiceProviderNotify") 18109017faf2SAbhishek Patel { 18119017faf2SAbhishek Patel notify = std::get_if<std::string>( 18129017faf2SAbhishek Patel &propertyMap.second); 18139017faf2SAbhishek Patel if (notify == nullptr) 18149017faf2SAbhishek Patel { 18159017faf2SAbhishek Patel messages::internalError(asyncResp->res); 18169017faf2SAbhishek Patel return; 18179017faf2SAbhishek Patel } 18189017faf2SAbhishek Patel } 18197e860f15SJohn Edward Broadbent } 18207e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 18217e860f15SJohn Edward Broadbent severity == nullptr) 18227e860f15SJohn Edward Broadbent { 18237e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 18247e860f15SJohn Edward Broadbent return; 18257e860f15SJohn Edward Broadbent } 18267e860f15SJohn Edward Broadbent } 18277e860f15SJohn Edward Broadbent else if (interfaceMap.first == 18287e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 18297e860f15SJohn Edward Broadbent { 1830002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 18317e860f15SJohn Edward Broadbent { 18327e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 18337e860f15SJohn Edward Broadbent { 18347e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 18357e860f15SJohn Edward Broadbent &propertyMap.second); 18367e860f15SJohn Edward Broadbent } 18377e860f15SJohn Edward Broadbent } 18387e860f15SJohn Edward Broadbent } 18397e860f15SJohn Edward Broadbent } 18407e860f15SJohn Edward Broadbent // Object path without the 18417e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 18427e860f15SJohn Edward Broadbent // and continue. 18437e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 1844c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1845c419c759SEd Tanous updateTimestamp == nullptr) 18467e860f15SJohn Edward Broadbent { 18477e860f15SJohn Edward Broadbent continue; 18487e860f15SJohn Edward Broadbent } 18493544d2a7SEd Tanous nlohmann::json& thisEntry = entriesArray.emplace_back(); 18509c11a172SVijay Lobo thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 1851ef4c65b7SEd Tanous thisEntry["@odata.id"] = boost::urls::format( 1852ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/{}", 1853ef4c65b7SEd Tanous std::to_string(*id)); 18547e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 18557e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 18567e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 18577e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 18589c11a172SVijay Lobo if ((resolution != nullptr) && (!(*resolution).empty())) 18599c11a172SVijay Lobo { 18609c11a172SVijay Lobo thisEntry["Resolution"] = *resolution; 18619c11a172SVijay Lobo } 18629017faf2SAbhishek Patel std::optional<bool> notifyAction = 18639017faf2SAbhishek Patel getProviderNotifyAction(*notify); 18649017faf2SAbhishek Patel if (notifyAction) 18659017faf2SAbhishek Patel { 18669017faf2SAbhishek Patel thisEntry["ServiceProviderNotified"] = *notifyAction; 18679017faf2SAbhishek Patel } 18687e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 18697e860f15SJohn Edward Broadbent thisEntry["Severity"] = 18707e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 18717e860f15SJohn Edward Broadbent thisEntry["Created"] = 18722b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*timestamp); 18737e860f15SJohn Edward Broadbent thisEntry["Modified"] = 18742b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*updateTimestamp); 18757e860f15SJohn Edward Broadbent if (filePath != nullptr) 18767e860f15SJohn Edward Broadbent { 18777e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 18780fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 18797e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 18807e860f15SJohn Edward Broadbent } 18817e860f15SJohn Edward Broadbent } 18823544d2a7SEd Tanous std::ranges::sort(entriesArray, [](const nlohmann::json& left, 18833544d2a7SEd Tanous const nlohmann::json& right) { 18847e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 18857e860f15SJohn Edward Broadbent }); 18867e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 18877e860f15SJohn Edward Broadbent entriesArray.size(); 18883544d2a7SEd Tanous asyncResp->res.jsonValue["Members"] = std::move(entriesArray); 18895eb468daSGeorge Liu }); 18907e860f15SJohn Edward Broadbent }); 18917e860f15SJohn Edward Broadbent } 18927e860f15SJohn Edward Broadbent 18937e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 18947e860f15SJohn Edward Broadbent { 18957e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 189622d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1897ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 1898002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1899002d39b4SEd Tanous [&app](const crow::Request& req, 19007e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 190122d268cbSEd Tanous const std::string& systemName, const std::string& param) { 19023ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 19037e860f15SJohn Edward Broadbent { 190445ca1b86SEd Tanous return; 190545ca1b86SEd Tanous } 19067f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 19077f3e84a1SEd Tanous { 19087f3e84a1SEd Tanous // Option currently returns no systems. TBD 19097f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 19107f3e84a1SEd Tanous systemName); 19117f3e84a1SEd Tanous return; 19127f3e84a1SEd Tanous } 191322d268cbSEd Tanous if (systemName != "system") 191422d268cbSEd Tanous { 191522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 191622d268cbSEd Tanous systemName); 191722d268cbSEd Tanous return; 191822d268cbSEd Tanous } 191922d268cbSEd Tanous 19207e860f15SJohn Edward Broadbent std::string entryID = param; 19217e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 19227e860f15SJohn Edward Broadbent 19237e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 19247e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 1925d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1926d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, "xyz.openbmc_project.Logging", 1927d1bde9e5SKrzysztof Grobelny "/xyz/openbmc_project/logging/entry/" + entryID, "", 19285e7e2dc5SEd Tanous [asyncResp, entryID](const boost::system::error_code& ec, 1929b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 19307e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 19317e860f15SJohn Edward Broadbent { 1932d1bde9e5SKrzysztof Grobelny messages::resourceNotFound(asyncResp->res, "EventLogEntry", 1933d1bde9e5SKrzysztof Grobelny entryID); 19347e860f15SJohn Edward Broadbent return; 19357e860f15SJohn Edward Broadbent } 19367e860f15SJohn Edward Broadbent if (ec) 19377e860f15SJohn Edward Broadbent { 193862598e31SEd Tanous BMCWEB_LOG_ERROR( 193962598e31SEd Tanous "EventLogEntry (DBus) resp_handler got error {}", ec); 19407e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 19417e860f15SJohn Edward Broadbent return; 19427e860f15SJohn Edward Broadbent } 1943914e2d5dSEd Tanous const uint32_t* id = nullptr; 1944c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1945c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1946914e2d5dSEd Tanous const std::string* severity = nullptr; 1947914e2d5dSEd Tanous const std::string* message = nullptr; 1948914e2d5dSEd Tanous const std::string* filePath = nullptr; 19499c11a172SVijay Lobo const std::string* resolution = nullptr; 19507e860f15SJohn Edward Broadbent bool resolved = false; 19519017faf2SAbhishek Patel const std::string* notify = nullptr; 19527e860f15SJohn Edward Broadbent 1953d1bde9e5SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1954d1bde9e5SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), resp, "Id", id, "Timestamp", 1955d1bde9e5SKrzysztof Grobelny timestamp, "UpdateTimestamp", updateTimestamp, "Severity", 19569c11a172SVijay Lobo severity, "Message", message, "Resolved", resolved, 19579017faf2SAbhishek Patel "Resolution", resolution, "Path", filePath, 19589017faf2SAbhishek Patel "ServiceProviderNotify", notify); 1959d1bde9e5SKrzysztof Grobelny 1960d1bde9e5SKrzysztof Grobelny if (!success) 196175710de2SXiaochao Ma { 196275710de2SXiaochao Ma messages::internalError(asyncResp->res); 196375710de2SXiaochao Ma return; 196475710de2SXiaochao Ma } 1965d1bde9e5SKrzysztof Grobelny 1966002d39b4SEd Tanous if (id == nullptr || message == nullptr || severity == nullptr || 19679017faf2SAbhishek Patel timestamp == nullptr || updateTimestamp == nullptr || 19689017faf2SAbhishek Patel notify == nullptr) 1969f86bb901SAdriana Kobylak { 1970ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1971271584abSEd Tanous return; 1972271584abSEd Tanous } 19739017faf2SAbhishek Patel 1974f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 19759c11a172SVijay Lobo "#LogEntry.v1_9_0.LogEntry"; 1976ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 1977ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/{}", 1978ef4c65b7SEd Tanous std::to_string(*id)); 197945ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Event Log Entry"; 1980f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1981f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1982f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 19839017faf2SAbhishek Patel std::optional<bool> notifyAction = getProviderNotifyAction(*notify); 19849017faf2SAbhishek Patel if (notifyAction) 19859017faf2SAbhishek Patel { 19869017faf2SAbhishek Patel asyncResp->res.jsonValue["ServiceProviderNotified"] = 19879017faf2SAbhishek Patel *notifyAction; 19889017faf2SAbhishek Patel } 19899c11a172SVijay Lobo if ((resolution != nullptr) && (!(*resolution).empty())) 19909c11a172SVijay Lobo { 19919c11a172SVijay Lobo asyncResp->res.jsonValue["Resolution"] = *resolution; 19929c11a172SVijay Lobo } 1993f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1994f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1995f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1996f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 19972b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*timestamp); 1998f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 19992b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*updateTimestamp); 2000f86bb901SAdriana Kobylak if (filePath != nullptr) 2001f86bb901SAdriana Kobylak { 2002f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 2003e7dbd530SPotin Lai "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 2004e7dbd530SPotin Lai std::to_string(*id) + "/attachment"; 2005f86bb901SAdriana Kobylak } 2006d1bde9e5SKrzysztof Grobelny }); 20077e860f15SJohn Edward Broadbent }); 2008336e96c6SChicago Duan 20097e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 201022d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 2011ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 20127e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 201345ca1b86SEd Tanous [&app](const crow::Request& req, 20147e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 201522d268cbSEd Tanous const std::string& systemName, const std::string& entryId) { 20163ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 201745ca1b86SEd Tanous { 201845ca1b86SEd Tanous return; 201945ca1b86SEd Tanous } 20207f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 20217f3e84a1SEd Tanous { 20227f3e84a1SEd Tanous // Option currently returns no systems. TBD 20237f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 20247f3e84a1SEd Tanous systemName); 20257f3e84a1SEd Tanous return; 20267f3e84a1SEd Tanous } 202722d268cbSEd Tanous if (systemName != "system") 202822d268cbSEd Tanous { 202922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 203022d268cbSEd Tanous systemName); 203122d268cbSEd Tanous return; 203222d268cbSEd Tanous } 203375710de2SXiaochao Ma std::optional<bool> resolved; 203475710de2SXiaochao Ma 203515ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", 20367e860f15SJohn Edward Broadbent resolved)) 203775710de2SXiaochao Ma { 203875710de2SXiaochao Ma return; 203975710de2SXiaochao Ma } 204062598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Resolved"); 204175710de2SXiaochao Ma 20429ae226faSGeorge Liu sdbusplus::asio::setProperty( 20439ae226faSGeorge Liu *crow::connections::systemBus, "xyz.openbmc_project.Logging", 20449ae226faSGeorge Liu "/xyz/openbmc_project/logging/entry/" + entryId, 20459ae226faSGeorge Liu "xyz.openbmc_project.Logging.Entry", "Resolved", *resolved, 20465e7e2dc5SEd Tanous [asyncResp, entryId](const boost::system::error_code& ec) { 204775710de2SXiaochao Ma if (ec) 204875710de2SXiaochao Ma { 204962598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 205075710de2SXiaochao Ma messages::internalError(asyncResp->res); 205175710de2SXiaochao Ma return; 205275710de2SXiaochao Ma } 20539ae226faSGeorge Liu }); 20547e860f15SJohn Edward Broadbent }); 205575710de2SXiaochao Ma 20567e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 205722d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 2058ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 2059ed398213SEd Tanous 2060002d39b4SEd Tanous .methods(boost::beast::http::verb::delete_)( 2061002d39b4SEd Tanous [&app](const crow::Request& req, 2062002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 206322d268cbSEd Tanous const std::string& systemName, const std::string& param) { 20643ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2065336e96c6SChicago Duan { 206645ca1b86SEd Tanous return; 206745ca1b86SEd Tanous } 20687f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 20697f3e84a1SEd Tanous { 20707f3e84a1SEd Tanous // Option currently returns no systems. TBD 20717f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 20727f3e84a1SEd Tanous systemName); 20737f3e84a1SEd Tanous return; 20747f3e84a1SEd Tanous } 207522d268cbSEd Tanous if (systemName != "system") 207622d268cbSEd Tanous { 207722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 207822d268cbSEd Tanous systemName); 207922d268cbSEd Tanous return; 208022d268cbSEd Tanous } 208162598e31SEd Tanous BMCWEB_LOG_DEBUG("Do delete single event entries."); 2082336e96c6SChicago Duan 20837e860f15SJohn Edward Broadbent std::string entryID = param; 2084336e96c6SChicago Duan 2085336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 2086336e96c6SChicago Duan 2087336e96c6SChicago Duan // Process response from Logging service. 20885a39f77aSPatrick Williams auto respHandler = [asyncResp, 20895a39f77aSPatrick Williams entryID](const boost::system::error_code& ec) { 209062598e31SEd Tanous BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done"); 2091336e96c6SChicago Duan if (ec) 2092336e96c6SChicago Duan { 20933de8d8baSGeorge Liu if (ec.value() == EBADR) 20943de8d8baSGeorge Liu { 209545ca1b86SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 209645ca1b86SEd Tanous entryID); 20973de8d8baSGeorge Liu return; 20983de8d8baSGeorge Liu } 2099336e96c6SChicago Duan // TODO Handle for specific error code 210062598e31SEd Tanous BMCWEB_LOG_ERROR( 210162598e31SEd Tanous "EventLogEntry (DBus) doDelete respHandler got error {}", 210262598e31SEd Tanous ec); 2103336e96c6SChicago Duan asyncResp->res.result( 2104336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 2105336e96c6SChicago Duan return; 2106336e96c6SChicago Duan } 2107336e96c6SChicago Duan 2108336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 2109336e96c6SChicago Duan }; 2110336e96c6SChicago Duan 2111336e96c6SChicago Duan // Make call to Logging service to request Delete Log 2112336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 2113336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 2114336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 2115336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 21167e860f15SJohn Edward Broadbent }); 2117400fd1fbSAdriana Kobylak } 2118400fd1fbSAdriana Kobylak 2119b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 2120b7028ebfSSpencer Ku 2121b7028ebfSSpencer Ku inline bool 2122b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 2123b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 2124b7028ebfSSpencer Ku { 2125b7028ebfSSpencer Ku std::error_code ec; 2126b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 2127b7028ebfSSpencer Ku if (ec) 2128b7028ebfSSpencer Ku { 2129bf2ddedeSCarson Labrado BMCWEB_LOG_WARNING("{}", ec.message()); 2130b7028ebfSSpencer Ku return false; 2131b7028ebfSSpencer Ku } 2132b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 2133b7028ebfSSpencer Ku { 2134b7028ebfSSpencer Ku std::string filename = it.path().filename(); 2135b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 2136b7028ebfSSpencer Ku // path 213711ba3979SEd Tanous if (filename.starts_with("log")) 2138b7028ebfSSpencer Ku { 2139b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 2140b7028ebfSSpencer Ku } 2141b7028ebfSSpencer Ku } 2142b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 2143b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 2144b7028ebfSSpencer Ku // descending order. 2145b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 2146b7028ebfSSpencer Ku AlphanumLess<std::string>()); 2147b7028ebfSSpencer Ku 2148b7028ebfSSpencer Ku return true; 2149b7028ebfSSpencer Ku } 2150b7028ebfSSpencer Ku 215102cad96eSEd Tanous inline bool getHostLoggerEntries( 215202cad96eSEd Tanous const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip, 215302cad96eSEd Tanous uint64_t top, std::vector<std::string>& logEntries, size_t& logCount) 2154b7028ebfSSpencer Ku { 2155b7028ebfSSpencer Ku GzFileReader logFile; 2156b7028ebfSSpencer Ku 2157b7028ebfSSpencer Ku // Go though all log files and expose host logs. 2158b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 2159b7028ebfSSpencer Ku { 2160b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 2161b7028ebfSSpencer Ku { 216262598e31SEd Tanous BMCWEB_LOG_ERROR("fail to expose host logs"); 2163b7028ebfSSpencer Ku return false; 2164b7028ebfSSpencer Ku } 2165b7028ebfSSpencer Ku } 2166b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 2167b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 2168b7028ebfSSpencer Ku if (!lastMessage.empty()) 2169b7028ebfSSpencer Ku { 2170b7028ebfSSpencer Ku logCount++; 2171b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 2172b7028ebfSSpencer Ku { 2173b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 2174b7028ebfSSpencer Ku } 2175b7028ebfSSpencer Ku } 2176b7028ebfSSpencer Ku return true; 2177b7028ebfSSpencer Ku } 2178b7028ebfSSpencer Ku 2179b7028ebfSSpencer Ku inline void fillHostLoggerEntryJson(const std::string& logEntryID, 2180b7028ebfSSpencer Ku const std::string& msg, 21816d6574c9SJason M. Bills nlohmann::json::object_t& logEntryJson) 2182b7028ebfSSpencer Ku { 2183b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 21849c11a172SVijay Lobo logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 2185ef4c65b7SEd Tanous logEntryJson["@odata.id"] = boost::urls::format( 2186ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/{}", 2187ef4c65b7SEd Tanous logEntryID); 21886d6574c9SJason M. Bills logEntryJson["Name"] = "Host Logger Entry"; 21896d6574c9SJason M. Bills logEntryJson["Id"] = logEntryID; 21906d6574c9SJason M. Bills logEntryJson["Message"] = msg; 21916d6574c9SJason M. Bills logEntryJson["EntryType"] = "Oem"; 21926d6574c9SJason M. Bills logEntryJson["Severity"] = "OK"; 21936d6574c9SJason M. Bills logEntryJson["OemRecordFormat"] = "Host Logger Entry"; 2194b7028ebfSSpencer Ku } 2195b7028ebfSSpencer Ku 2196b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 2197b7028ebfSSpencer Ku { 219822d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/") 2199b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 22001476687dSEd Tanous .methods(boost::beast::http::verb::get)( 22011476687dSEd Tanous [&app](const crow::Request& req, 220222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 220322d268cbSEd Tanous const std::string& systemName) { 22043ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 220545ca1b86SEd Tanous { 220645ca1b86SEd Tanous return; 220745ca1b86SEd Tanous } 22087f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 22097f3e84a1SEd Tanous { 22107f3e84a1SEd Tanous // Option currently returns no systems. TBD 22117f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 22127f3e84a1SEd Tanous systemName); 22137f3e84a1SEd Tanous return; 22147f3e84a1SEd Tanous } 221522d268cbSEd Tanous if (systemName != "system") 221622d268cbSEd Tanous { 221722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 221822d268cbSEd Tanous systemName); 221922d268cbSEd Tanous return; 222022d268cbSEd Tanous } 2221b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 2222b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"; 2223b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 2224b25644a1SJanet Adkins "#LogService.v1_2_0.LogService"; 2225b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 2226b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 2227b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 22281476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 22291476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 2230b7028ebfSSpencer Ku }); 2231b7028ebfSSpencer Ku } 2232b7028ebfSSpencer Ku 2233b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 2234b7028ebfSSpencer Ku { 2235b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 223622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/") 2237b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2238002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2239002d39b4SEd Tanous [&app](const crow::Request& req, 224022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 224122d268cbSEd Tanous const std::string& systemName) { 2242c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2243c937d2bfSEd Tanous .canDelegateTop = true, 2244c937d2bfSEd Tanous .canDelegateSkip = true, 2245c937d2bfSEd Tanous }; 2246c937d2bfSEd Tanous query_param::Query delegatedQuery; 2247c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 22483ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 2249b7028ebfSSpencer Ku { 2250b7028ebfSSpencer Ku return; 2251b7028ebfSSpencer Ku } 22527f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 22537f3e84a1SEd Tanous { 22547f3e84a1SEd Tanous // Option currently returns no systems. TBD 22557f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 22567f3e84a1SEd Tanous systemName); 22577f3e84a1SEd Tanous return; 22587f3e84a1SEd Tanous } 225922d268cbSEd Tanous if (systemName != "system") 226022d268cbSEd Tanous { 226122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 226222d268cbSEd Tanous systemName); 226322d268cbSEd Tanous return; 226422d268cbSEd Tanous } 2265b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 2266b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 2267b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 2268b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 2269b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 2270b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 2271b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 22720fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2273b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 2274b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 2275b7028ebfSSpencer Ku 2276b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2277b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2278b7028ebfSSpencer Ku { 2279bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("Failed to get host log file path"); 2280b7028ebfSSpencer Ku return; 2281b7028ebfSSpencer Ku } 22823648c8beSEd Tanous // If we weren't provided top and skip limits, use the defaults. 22833648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 22845143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 2285b7028ebfSSpencer Ku size_t logCount = 0; 2286b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 2287b7028ebfSSpencer Ku // control by skip and top. 2288b7028ebfSSpencer Ku std::vector<std::string> logEntries; 22893648c8beSEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries, 22903648c8beSEd Tanous logCount)) 2291b7028ebfSSpencer Ku { 2292b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2293b7028ebfSSpencer Ku return; 2294b7028ebfSSpencer Ku } 2295b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 2296b7028ebfSSpencer Ku // log count 229726f6976fSEd Tanous if (logEntries.empty()) 2298b7028ebfSSpencer Ku { 2299b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 2300b7028ebfSSpencer Ku return; 2301b7028ebfSSpencer Ku } 230226f6976fSEd Tanous if (!logEntries.empty()) 2303b7028ebfSSpencer Ku { 2304b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 2305b7028ebfSSpencer Ku { 23066d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 23073648c8beSEd Tanous fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i], 23083648c8beSEd Tanous hostLogEntry); 2309b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(hostLogEntry)); 2310b7028ebfSSpencer Ku } 2311b7028ebfSSpencer Ku 2312b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 23133648c8beSEd Tanous if (skip + top < logCount) 2314b7028ebfSSpencer Ku { 2315b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 23160fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/HostLogger/Entries?$skip=" + 23173648c8beSEd Tanous std::to_string(skip + top); 2318b7028ebfSSpencer Ku } 2319b7028ebfSSpencer Ku } 2320b7028ebfSSpencer Ku }); 2321b7028ebfSSpencer Ku } 2322b7028ebfSSpencer Ku 2323b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 2324b7028ebfSSpencer Ku { 2325b7028ebfSSpencer Ku BMCWEB_ROUTE( 232622d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/") 2327b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2328b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 232945ca1b86SEd Tanous [&app](const crow::Request& req, 2330b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 233122d268cbSEd Tanous const std::string& systemName, const std::string& param) { 23323ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 233345ca1b86SEd Tanous { 233445ca1b86SEd Tanous return; 233545ca1b86SEd Tanous } 23367f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 23377f3e84a1SEd Tanous { 23387f3e84a1SEd Tanous // Option currently returns no systems. TBD 23397f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 23407f3e84a1SEd Tanous systemName); 23417f3e84a1SEd Tanous return; 23427f3e84a1SEd Tanous } 234322d268cbSEd Tanous if (systemName != "system") 234422d268cbSEd Tanous { 234522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 234622d268cbSEd Tanous systemName); 234722d268cbSEd Tanous return; 234822d268cbSEd Tanous } 2349b7028ebfSSpencer Ku const std::string& targetID = param; 2350b7028ebfSSpencer Ku 2351b7028ebfSSpencer Ku uint64_t idInt = 0; 2352ca45aa3cSEd Tanous 235384396af9SPatrick Williams auto [ptr, ec] = std::from_chars(&*targetID.begin(), &*targetID.end(), 235484396af9SPatrick Williams idInt); 23559db4ba25SJiaqing Zhao if (ec == std::errc::invalid_argument || 23569db4ba25SJiaqing Zhao ec == std::errc::result_out_of_range) 2357b7028ebfSSpencer Ku { 23589db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", param); 2359b7028ebfSSpencer Ku return; 2360b7028ebfSSpencer Ku } 2361b7028ebfSSpencer Ku 2362b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2363b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2364b7028ebfSSpencer Ku { 2365bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("Failed to get host log file path"); 2366b7028ebfSSpencer Ku return; 2367b7028ebfSSpencer Ku } 2368b7028ebfSSpencer Ku 2369b7028ebfSSpencer Ku size_t logCount = 0; 23703648c8beSEd Tanous size_t top = 1; 2371b7028ebfSSpencer Ku std::vector<std::string> logEntries; 2372b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 2373b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 2374b7028ebfSSpencer Ku // get that entry 2375002d39b4SEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries, 2376002d39b4SEd Tanous logCount)) 2377b7028ebfSSpencer Ku { 2378b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2379b7028ebfSSpencer Ku return; 2380b7028ebfSSpencer Ku } 2381b7028ebfSSpencer Ku 2382b7028ebfSSpencer Ku if (!logEntries.empty()) 2383b7028ebfSSpencer Ku { 23846d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 23856d6574c9SJason M. Bills fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry); 23866d6574c9SJason M. Bills asyncResp->res.jsonValue.update(hostLogEntry); 2387b7028ebfSSpencer Ku return; 2388b7028ebfSSpencer Ku } 2389b7028ebfSSpencer Ku 2390b7028ebfSSpencer Ku // Requested ID was not found 23919db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", param); 2392b7028ebfSSpencer Ku }); 2393b7028ebfSSpencer Ku } 2394b7028ebfSSpencer Ku 2395dd72e87bSClaire Weinan inline void handleBMCLogServicesCollectionGet( 2396fdd26906SClaire Weinan crow::App& app, const crow::Request& req, 2397fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 23981da66f75SEd Tanous { 23993ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 240045ca1b86SEd Tanous { 240145ca1b86SEd Tanous return; 240245ca1b86SEd Tanous } 24037e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 24047e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2405e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 24061da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2407e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 2408e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 2409002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 2410e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 24111da66f75SEd Tanous "Collection of LogServices for this Manager"; 2412002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 2413c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 2414fdd26906SClaire Weinan 2415c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 2416613dabeaSEd Tanous nlohmann::json::object_t journal; 2417613dabeaSEd Tanous journal["@odata.id"] = "/redfish/v1/Managers/bmc/LogServices/Journal"; 2418b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(journal)); 2419c4bf6374SJason M. Bills #endif 2420fdd26906SClaire Weinan 2421fdd26906SClaire Weinan asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); 2422fdd26906SClaire Weinan 2423fdd26906SClaire Weinan #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 242415912159SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 24257a1dbc48SGeorge Liu "xyz.openbmc_project.Collection.DeleteAll"}; 24267a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 24277a1dbc48SGeorge Liu "/xyz/openbmc_project/dump", 0, interfaces, 2428fdd26906SClaire Weinan [asyncResp]( 24297a1dbc48SGeorge Liu const boost::system::error_code& ec, 2430fdd26906SClaire Weinan const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 2431fdd26906SClaire Weinan if (ec) 2432fdd26906SClaire Weinan { 243362598e31SEd Tanous BMCWEB_LOG_ERROR( 243462598e31SEd Tanous "handleBMCLogServicesCollectionGet respHandler got error {}", 243562598e31SEd Tanous ec); 2436fdd26906SClaire Weinan // Assume that getting an error simply means there are no dump 2437fdd26906SClaire Weinan // LogServices. Return without adding any error response. 2438fdd26906SClaire Weinan return; 2439fdd26906SClaire Weinan } 2440fdd26906SClaire Weinan 2441fdd26906SClaire Weinan nlohmann::json& logServiceArrayLocal = 2442fdd26906SClaire Weinan asyncResp->res.jsonValue["Members"]; 2443fdd26906SClaire Weinan 2444fdd26906SClaire Weinan for (const std::string& path : subTreePaths) 2445fdd26906SClaire Weinan { 2446fdd26906SClaire Weinan if (path == "/xyz/openbmc_project/dump/bmc") 2447fdd26906SClaire Weinan { 2448613dabeaSEd Tanous nlohmann::json::object_t member; 2449613dabeaSEd Tanous member["@odata.id"] = 2450613dabeaSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump"; 2451b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 2452fdd26906SClaire Weinan } 2453fdd26906SClaire Weinan else if (path == "/xyz/openbmc_project/dump/faultlog") 2454fdd26906SClaire Weinan { 2455613dabeaSEd Tanous nlohmann::json::object_t member; 2456613dabeaSEd Tanous member["@odata.id"] = 2457613dabeaSEd Tanous "/redfish/v1/Managers/bmc/LogServices/FaultLog"; 2458b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 2459fdd26906SClaire Weinan } 2460fdd26906SClaire Weinan } 2461fdd26906SClaire Weinan 2462e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2463fdd26906SClaire Weinan logServiceArrayLocal.size(); 24647a1dbc48SGeorge Liu }); 2465fdd26906SClaire Weinan #endif 2466fdd26906SClaire Weinan } 2467fdd26906SClaire Weinan 2468fdd26906SClaire Weinan inline void requestRoutesBMCLogServiceCollection(App& app) 2469fdd26906SClaire Weinan { 2470fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 2471fdd26906SClaire Weinan .privileges(redfish::privileges::getLogServiceCollection) 2472fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2473dd72e87bSClaire Weinan std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app))); 2474e1f26343SJason M. Bills } 2475e1f26343SJason M. Bills 24767e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 2477e1f26343SJason M. Bills { 24787e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 2479ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 24807e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 248145ca1b86SEd Tanous [&app](const crow::Request& req, 248245ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24833ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 24847e860f15SJohn Edward Broadbent { 248545ca1b86SEd Tanous return; 248645ca1b86SEd Tanous } 2487e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2488b25644a1SJanet Adkins "#LogService.v1_2_0.LogService"; 24890f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 24900f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 2491002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 2492002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 2493ed34a4adSEd Tanous asyncResp->res.jsonValue["Id"] = "Journal"; 2494e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 24957c8c4058STejas Patil 24967c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 24972b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 2498002d39b4SEd Tanous asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 24997c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 25007c8c4058STejas Patil redfishDateTimeOffset.second; 25017c8c4058STejas Patil 25021476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 25031476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 25047e860f15SJohn Edward Broadbent }); 2505e1f26343SJason M. Bills } 2506e1f26343SJason M. Bills 25073a48b3a2SJason M. Bills static int 25083a48b3a2SJason M. Bills fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 2509e1f26343SJason M. Bills sd_journal* journal, 25103a48b3a2SJason M. Bills nlohmann::json::object_t& bmcJournalLogEntryJson) 2511e1f26343SJason M. Bills { 2512e1f26343SJason M. Bills // Get the Log Entry contents 2513e1f26343SJason M. Bills int ret = 0; 2514e1f26343SJason M. Bills 2515a8fe54f0SJason M. Bills std::string message; 2516a8fe54f0SJason M. Bills std::string_view syslogID; 2517a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 2518a8fe54f0SJason M. Bills if (ret < 0) 2519a8fe54f0SJason M. Bills { 2520bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("Failed to read SYSLOG_IDENTIFIER field: {}", 252162598e31SEd Tanous strerror(-ret)); 2522a8fe54f0SJason M. Bills } 2523a8fe54f0SJason M. Bills if (!syslogID.empty()) 2524a8fe54f0SJason M. Bills { 2525a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 2526a8fe54f0SJason M. Bills } 2527a8fe54f0SJason M. Bills 252839e77504SEd Tanous std::string_view msg; 252916428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 2530e1f26343SJason M. Bills if (ret < 0) 2531e1f26343SJason M. Bills { 253262598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to read MESSAGE field: {}", strerror(-ret)); 2533e1f26343SJason M. Bills return 1; 2534e1f26343SJason M. Bills } 2535a8fe54f0SJason M. Bills message += std::string(msg); 2536e1f26343SJason M. Bills 2537e1f26343SJason M. Bills // Get the severity from the PRIORITY field 2538271584abSEd Tanous long int severity = 8; // Default to an invalid priority 253916428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 2540e1f26343SJason M. Bills if (ret < 0) 2541e1f26343SJason M. Bills { 2542bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("Failed to read PRIORITY field: {}", strerror(-ret)); 2543e1f26343SJason M. Bills } 2544e1f26343SJason M. Bills 2545e1f26343SJason M. Bills // Get the Created time from the timestamp 254616428a1aSJason M. Bills std::string entryTimeStr; 254716428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 2548e1f26343SJason M. Bills { 254916428a1aSJason M. Bills return 1; 2550e1f26343SJason M. Bills } 2551e1f26343SJason M. Bills 2552e1f26343SJason M. Bills // Fill in the log entry with the gathered data 25539c11a172SVijay Lobo bmcJournalLogEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 2554ef4c65b7SEd Tanous bmcJournalLogEntryJson["@odata.id"] = boost::urls::format( 2555ef4c65b7SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/{}", 2556eddfc437SWilly Tu bmcJournalLogEntryID); 255784afc48bSJason M. Bills bmcJournalLogEntryJson["Name"] = "BMC Journal Entry"; 255884afc48bSJason M. Bills bmcJournalLogEntryJson["Id"] = bmcJournalLogEntryID; 255984afc48bSJason M. Bills bmcJournalLogEntryJson["Message"] = std::move(message); 256084afc48bSJason M. Bills bmcJournalLogEntryJson["EntryType"] = "Oem"; 256184afc48bSJason M. Bills bmcJournalLogEntryJson["Severity"] = severity <= 2 ? "Critical" 2562738c1e61SPatrick Williams : severity <= 4 ? "Warning" 256384afc48bSJason M. Bills : "OK"; 256484afc48bSJason M. Bills bmcJournalLogEntryJson["OemRecordFormat"] = "BMC Journal Entry"; 256584afc48bSJason M. Bills bmcJournalLogEntryJson["Created"] = std::move(entryTimeStr); 2566e1f26343SJason M. Bills return 0; 2567e1f26343SJason M. Bills } 2568e1f26343SJason M. Bills 25697e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 2570e1f26343SJason M. Bills { 25717e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 2572ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 2573002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2574002d39b4SEd Tanous [&app](const crow::Request& req, 2575002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2576c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2577c937d2bfSEd Tanous .canDelegateTop = true, 2578c937d2bfSEd Tanous .canDelegateSkip = true, 2579c937d2bfSEd Tanous }; 2580c937d2bfSEd Tanous query_param::Query delegatedQuery; 2581c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 25823ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 2583193ad2faSJason M. Bills { 2584193ad2faSJason M. Bills return; 2585193ad2faSJason M. Bills } 25863648c8beSEd Tanous 25873648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 25885143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 25893648c8beSEd Tanous 25907e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 25917e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2592e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2593e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 25940f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 25950f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 2596e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 2597e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2598e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 25990fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2600e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2601e1f26343SJason M. Bills 26027e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 26037e860f15SJohn Edward Broadbent // unique ID for each entry 2604e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2605e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2606e1f26343SJason M. Bills if (ret < 0) 2607e1f26343SJason M. Bills { 260862598e31SEd Tanous BMCWEB_LOG_ERROR("failed to open journal: {}", strerror(-ret)); 2609f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2610e1f26343SJason M. Bills return; 2611e1f26343SJason M. Bills } 26120fda0f12SGeorge Liu std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 26130fda0f12SGeorge Liu journalTmp, sd_journal_close); 2614e1f26343SJason M. Bills journalTmp = nullptr; 2615b01bf299SEd Tanous uint64_t entryCount = 0; 2616e85d6b16SJason M. Bills // Reset the unique ID on the first entry 2617e85d6b16SJason M. Bills bool firstEntry = true; 2618e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 2619e1f26343SJason M. Bills { 2620193ad2faSJason M. Bills entryCount++; 26217e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 26227e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 26233648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 2624193ad2faSJason M. Bills { 2625193ad2faSJason M. Bills continue; 2626193ad2faSJason M. Bills } 2627193ad2faSJason M. Bills 262816428a1aSJason M. Bills std::string idStr; 2629e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2630e1f26343SJason M. Bills { 2631e1f26343SJason M. Bills continue; 2632e1f26343SJason M. Bills } 2633e85d6b16SJason M. Bills firstEntry = false; 2634e85d6b16SJason M. Bills 26353a48b3a2SJason M. Bills nlohmann::json::object_t bmcJournalLogEntry; 2636c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 2637c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 2638e1f26343SJason M. Bills { 2639f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2640e1f26343SJason M. Bills return; 2641e1f26343SJason M. Bills } 2642b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(bmcJournalLogEntry)); 2643e1f26343SJason M. Bills } 2644193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 26453648c8beSEd Tanous if (skip + top < entryCount) 2646193ad2faSJason M. Bills { 2647193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 26480fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 26493648c8beSEd Tanous std::to_string(skip + top); 2650193ad2faSJason M. Bills } 26517e860f15SJohn Edward Broadbent }); 2652e1f26343SJason M. Bills } 2653e1f26343SJason M. Bills 26547e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 2655e1f26343SJason M. Bills { 26567e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 26577e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 2658ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 26597e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 266045ca1b86SEd Tanous [&app](const crow::Request& req, 26617e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26627e860f15SJohn Edward Broadbent const std::string& entryID) { 26633ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 266445ca1b86SEd Tanous { 266545ca1b86SEd Tanous return; 266645ca1b86SEd Tanous } 2667e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2668e1f26343SJason M. Bills uint64_t ts = 0; 2669271584abSEd Tanous uint64_t index = 0; 26708d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2671e1f26343SJason M. Bills { 267216428a1aSJason M. Bills return; 2673e1f26343SJason M. Bills } 2674e1f26343SJason M. Bills 2675e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2676e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2677e1f26343SJason M. Bills if (ret < 0) 2678e1f26343SJason M. Bills { 267962598e31SEd Tanous BMCWEB_LOG_ERROR("failed to open journal: {}", strerror(-ret)); 2680f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2681e1f26343SJason M. Bills return; 2682e1f26343SJason M. Bills } 2683002d39b4SEd Tanous std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 2684002d39b4SEd Tanous journalTmp, sd_journal_close); 2685e1f26343SJason M. Bills journalTmp = nullptr; 26867e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 26877e860f15SJohn Edward Broadbent // index tracking the unique ID 2688af07e3f5SJason M. Bills std::string idStr; 2689af07e3f5SJason M. Bills bool firstEntry = true; 2690e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 26912056b6d1SManojkiran Eda if (ret < 0) 26922056b6d1SManojkiran Eda { 269362598e31SEd Tanous BMCWEB_LOG_ERROR("failed to seek to an entry in journal{}", 269462598e31SEd Tanous strerror(-ret)); 26952056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 26962056b6d1SManojkiran Eda return; 26972056b6d1SManojkiran Eda } 2698271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2699e1f26343SJason M. Bills { 2700e1f26343SJason M. Bills sd_journal_next(journal.get()); 2701af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2702af07e3f5SJason M. Bills { 2703af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2704af07e3f5SJason M. Bills return; 2705af07e3f5SJason M. Bills } 2706af07e3f5SJason M. Bills firstEntry = false; 2707af07e3f5SJason M. Bills } 2708c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2709af07e3f5SJason M. Bills if (idStr != entryID) 2710c4bf6374SJason M. Bills { 27119db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 2712c4bf6374SJason M. Bills return; 2713c4bf6374SJason M. Bills } 2714c4bf6374SJason M. Bills 27153a48b3a2SJason M. Bills nlohmann::json::object_t bmcJournalLogEntry; 2716c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 27173a48b3a2SJason M. Bills bmcJournalLogEntry) != 0) 2718e1f26343SJason M. Bills { 2719f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2720e1f26343SJason M. Bills return; 2721e1f26343SJason M. Bills } 2722d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcJournalLogEntry); 27237e860f15SJohn Edward Broadbent }); 2724c9bb6861Sraviteja-b } 2725c9bb6861Sraviteja-b 2726fdd26906SClaire Weinan inline void 2727fdd26906SClaire Weinan getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2728fdd26906SClaire Weinan const std::string& dumpType) 2729c9bb6861Sraviteja-b { 2730fdd26906SClaire Weinan std::string dumpPath; 2731fdd26906SClaire Weinan std::string overWritePolicy; 2732fdd26906SClaire Weinan bool collectDiagnosticDataSupported = false; 2733fdd26906SClaire Weinan 2734fdd26906SClaire Weinan if (dumpType == "BMC") 273545ca1b86SEd Tanous { 2736fdd26906SClaire Weinan dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump"; 2737fdd26906SClaire Weinan overWritePolicy = "WrapsWhenFull"; 2738fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2739fdd26906SClaire Weinan } 2740fdd26906SClaire Weinan else if (dumpType == "FaultLog") 2741fdd26906SClaire Weinan { 2742fdd26906SClaire Weinan dumpPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog"; 2743fdd26906SClaire Weinan overWritePolicy = "Unknown"; 2744fdd26906SClaire Weinan collectDiagnosticDataSupported = false; 2745fdd26906SClaire Weinan } 2746fdd26906SClaire Weinan else if (dumpType == "System") 2747fdd26906SClaire Weinan { 2748fdd26906SClaire Weinan dumpPath = "/redfish/v1/Systems/system/LogServices/Dump"; 2749fdd26906SClaire Weinan overWritePolicy = "WrapsWhenFull"; 2750fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2751fdd26906SClaire Weinan } 2752fdd26906SClaire Weinan else 2753fdd26906SClaire Weinan { 275462598e31SEd Tanous BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}", 275562598e31SEd Tanous dumpType); 2756fdd26906SClaire Weinan messages::internalError(asyncResp->res); 275745ca1b86SEd Tanous return; 275845ca1b86SEd Tanous } 2759fdd26906SClaire Weinan 2760fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = dumpPath; 2761fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; 2762c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 2763fdd26906SClaire Weinan asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; 2764fdd26906SClaire Weinan asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); 2765fdd26906SClaire Weinan asyncResp->res.jsonValue["OverWritePolicy"] = std::move(overWritePolicy); 27667c8c4058STejas Patil 27677c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 27682b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 27690fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 27707c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 27717c8c4058STejas Patil redfishDateTimeOffset.second; 27727c8c4058STejas Patil 2773fdd26906SClaire Weinan asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; 2774fdd26906SClaire Weinan 2775fdd26906SClaire Weinan if (collectDiagnosticDataSupported) 2776fdd26906SClaire Weinan { 2777002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 27781476687dSEd Tanous ["target"] = 2779fdd26906SClaire Weinan dumpPath + "/Actions/LogService.CollectDiagnosticData"; 2780fdd26906SClaire Weinan } 27810d946211SClaire Weinan 27820d946211SClaire Weinan constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface}; 27830d946211SClaire Weinan dbus::utility::getSubTreePaths( 27840d946211SClaire Weinan "/xyz/openbmc_project/dump", 0, interfaces, 27850d946211SClaire Weinan [asyncResp, dumpType, dumpPath]( 27860d946211SClaire Weinan const boost::system::error_code& ec, 27870d946211SClaire Weinan const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 27880d946211SClaire Weinan if (ec) 27890d946211SClaire Weinan { 279062598e31SEd Tanous BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", ec); 27910d946211SClaire Weinan // Assume that getting an error simply means there are no dump 27920d946211SClaire Weinan // LogServices. Return without adding any error response. 27930d946211SClaire Weinan return; 27940d946211SClaire Weinan } 27950d946211SClaire Weinan 27960d946211SClaire Weinan const std::string dbusDumpPath = 27970d946211SClaire Weinan "/xyz/openbmc_project/dump/" + 27980d946211SClaire Weinan boost::algorithm::to_lower_copy(dumpType); 27990d946211SClaire Weinan 28000d946211SClaire Weinan for (const std::string& path : subTreePaths) 28010d946211SClaire Weinan { 28020d946211SClaire Weinan if (path == dbusDumpPath) 28030d946211SClaire Weinan { 28040d946211SClaire Weinan asyncResp->res 28050d946211SClaire Weinan .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 28060d946211SClaire Weinan dumpPath + "/Actions/LogService.ClearLog"; 28070d946211SClaire Weinan break; 28080d946211SClaire Weinan } 28090d946211SClaire Weinan } 28100d946211SClaire Weinan }); 2811c9bb6861Sraviteja-b } 2812c9bb6861Sraviteja-b 2813fdd26906SClaire Weinan inline void handleLogServicesDumpServiceGet( 2814fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2815fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 28167e860f15SJohn Edward Broadbent { 28173ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 281845ca1b86SEd Tanous { 281945ca1b86SEd Tanous return; 282045ca1b86SEd Tanous } 2821fdd26906SClaire Weinan getDumpServiceInfo(asyncResp, dumpType); 2822fdd26906SClaire Weinan } 2823c9bb6861Sraviteja-b 282422d268cbSEd Tanous inline void handleLogServicesDumpServiceComputerSystemGet( 282522d268cbSEd Tanous crow::App& app, const crow::Request& req, 282622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 282722d268cbSEd Tanous const std::string& chassisId) 282822d268cbSEd Tanous { 282922d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 283022d268cbSEd Tanous { 283122d268cbSEd Tanous return; 283222d268cbSEd Tanous } 283322d268cbSEd Tanous if (chassisId != "system") 283422d268cbSEd Tanous { 283522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 283622d268cbSEd Tanous return; 283722d268cbSEd Tanous } 283822d268cbSEd Tanous getDumpServiceInfo(asyncResp, "System"); 283922d268cbSEd Tanous } 284022d268cbSEd Tanous 2841fdd26906SClaire Weinan inline void handleLogServicesDumpEntriesCollectionGet( 2842fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2843fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2844fdd26906SClaire Weinan { 2845fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2846fdd26906SClaire Weinan { 2847fdd26906SClaire Weinan return; 2848fdd26906SClaire Weinan } 2849fdd26906SClaire Weinan getDumpEntryCollection(asyncResp, dumpType); 2850fdd26906SClaire Weinan } 2851fdd26906SClaire Weinan 285222d268cbSEd Tanous inline void handleLogServicesDumpEntriesCollectionComputerSystemGet( 285322d268cbSEd Tanous crow::App& app, const crow::Request& req, 285422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 285522d268cbSEd Tanous const std::string& chassisId) 285622d268cbSEd Tanous { 285722d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 285822d268cbSEd Tanous { 285922d268cbSEd Tanous return; 286022d268cbSEd Tanous } 286122d268cbSEd Tanous if (chassisId != "system") 286222d268cbSEd Tanous { 286322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 286422d268cbSEd Tanous return; 286522d268cbSEd Tanous } 286622d268cbSEd Tanous getDumpEntryCollection(asyncResp, "System"); 286722d268cbSEd Tanous } 286822d268cbSEd Tanous 2869fdd26906SClaire Weinan inline void handleLogServicesDumpEntryGet( 2870fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2871fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2872fdd26906SClaire Weinan const std::string& dumpId) 2873fdd26906SClaire Weinan { 2874fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2875fdd26906SClaire Weinan { 2876fdd26906SClaire Weinan return; 2877fdd26906SClaire Weinan } 2878fdd26906SClaire Weinan getDumpEntryById(asyncResp, dumpId, dumpType); 2879fdd26906SClaire Weinan } 2880168d1b1aSCarson Labrado 288122d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemGet( 288222d268cbSEd Tanous crow::App& app, const crow::Request& req, 288322d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 288422d268cbSEd Tanous const std::string& chassisId, const std::string& dumpId) 288522d268cbSEd Tanous { 288622d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 288722d268cbSEd Tanous { 288822d268cbSEd Tanous return; 288922d268cbSEd Tanous } 289022d268cbSEd Tanous if (chassisId != "system") 289122d268cbSEd Tanous { 289222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 289322d268cbSEd Tanous return; 289422d268cbSEd Tanous } 289522d268cbSEd Tanous getDumpEntryById(asyncResp, dumpId, "System"); 289622d268cbSEd Tanous } 2897fdd26906SClaire Weinan 2898fdd26906SClaire Weinan inline void handleLogServicesDumpEntryDelete( 2899fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2900fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2901fdd26906SClaire Weinan const std::string& dumpId) 2902fdd26906SClaire Weinan { 2903fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2904fdd26906SClaire Weinan { 2905fdd26906SClaire Weinan return; 2906fdd26906SClaire Weinan } 2907fdd26906SClaire Weinan deleteDumpEntry(asyncResp, dumpId, dumpType); 2908fdd26906SClaire Weinan } 2909fdd26906SClaire Weinan 291022d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemDelete( 291122d268cbSEd Tanous crow::App& app, const crow::Request& req, 291222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 291322d268cbSEd Tanous const std::string& chassisId, const std::string& dumpId) 291422d268cbSEd Tanous { 291522d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 291622d268cbSEd Tanous { 291722d268cbSEd Tanous return; 291822d268cbSEd Tanous } 291922d268cbSEd Tanous if (chassisId != "system") 292022d268cbSEd Tanous { 292122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 292222d268cbSEd Tanous return; 292322d268cbSEd Tanous } 292422d268cbSEd Tanous deleteDumpEntry(asyncResp, dumpId, "System"); 292522d268cbSEd Tanous } 292622d268cbSEd Tanous 2927168d1b1aSCarson Labrado inline void handleLogServicesDumpEntryDownloadGet( 2928168d1b1aSCarson Labrado crow::App& app, const std::string& dumpType, const crow::Request& req, 2929168d1b1aSCarson Labrado const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2930168d1b1aSCarson Labrado const std::string& dumpId) 2931168d1b1aSCarson Labrado { 2932168d1b1aSCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2933168d1b1aSCarson Labrado { 2934168d1b1aSCarson Labrado return; 2935168d1b1aSCarson Labrado } 2936168d1b1aSCarson Labrado downloadDumpEntry(asyncResp, dumpId, dumpType); 2937168d1b1aSCarson Labrado } 2938168d1b1aSCarson Labrado 2939168d1b1aSCarson Labrado inline void handleDBusEventLogEntryDownloadGet( 2940168d1b1aSCarson Labrado crow::App& app, const std::string& dumpType, const crow::Request& req, 2941168d1b1aSCarson Labrado const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2942168d1b1aSCarson Labrado const std::string& systemName, const std::string& entryID) 2943168d1b1aSCarson Labrado { 2944168d1b1aSCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2945168d1b1aSCarson Labrado { 2946168d1b1aSCarson Labrado return; 2947168d1b1aSCarson Labrado } 2948168d1b1aSCarson Labrado if (!http_helpers::isContentTypeAllowed( 2949168d1b1aSCarson Labrado req.getHeaderValue("Accept"), 2950168d1b1aSCarson Labrado http_helpers::ContentType::OctetStream, true)) 2951168d1b1aSCarson Labrado { 2952168d1b1aSCarson Labrado asyncResp->res.result(boost::beast::http::status::bad_request); 2953168d1b1aSCarson Labrado return; 2954168d1b1aSCarson Labrado } 2955168d1b1aSCarson Labrado downloadEventLogEntry(asyncResp, systemName, entryID, dumpType); 2956168d1b1aSCarson Labrado } 2957168d1b1aSCarson Labrado 2958fdd26906SClaire Weinan inline void handleLogServicesDumpCollectDiagnosticDataPost( 2959fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2960fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2961fdd26906SClaire Weinan { 2962fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2963fdd26906SClaire Weinan { 2964fdd26906SClaire Weinan return; 2965fdd26906SClaire Weinan } 2966fdd26906SClaire Weinan createDump(asyncResp, req, dumpType); 2967fdd26906SClaire Weinan } 2968fdd26906SClaire Weinan 296922d268cbSEd Tanous inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost( 297022d268cbSEd Tanous crow::App& app, const crow::Request& req, 297122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29727f3e84a1SEd Tanous const std::string& systemName) 297322d268cbSEd Tanous { 297422d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 297522d268cbSEd Tanous { 297622d268cbSEd Tanous return; 297722d268cbSEd Tanous } 29787f3e84a1SEd Tanous 29797f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 298022d268cbSEd Tanous { 29817f3e84a1SEd Tanous // Option currently returns no systems. TBD 29827f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 29837f3e84a1SEd Tanous systemName); 29847f3e84a1SEd Tanous return; 29857f3e84a1SEd Tanous } 29867f3e84a1SEd Tanous if (systemName != "system") 29877f3e84a1SEd Tanous { 29887f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 29897f3e84a1SEd Tanous systemName); 299022d268cbSEd Tanous return; 299122d268cbSEd Tanous } 299222d268cbSEd Tanous createDump(asyncResp, req, "System"); 299322d268cbSEd Tanous } 299422d268cbSEd Tanous 2995fdd26906SClaire Weinan inline void handleLogServicesDumpClearLogPost( 2996fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2997fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2998fdd26906SClaire Weinan { 2999fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3000fdd26906SClaire Weinan { 3001fdd26906SClaire Weinan return; 3002fdd26906SClaire Weinan } 3003fdd26906SClaire Weinan clearDump(asyncResp, dumpType); 3004fdd26906SClaire Weinan } 3005fdd26906SClaire Weinan 300622d268cbSEd Tanous inline void handleLogServicesDumpClearLogComputerSystemPost( 300722d268cbSEd Tanous crow::App& app, const crow::Request& req, 300822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 30097f3e84a1SEd Tanous const std::string& systemName) 301022d268cbSEd Tanous { 301122d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 301222d268cbSEd Tanous { 301322d268cbSEd Tanous return; 301422d268cbSEd Tanous } 30157f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 301622d268cbSEd Tanous { 30177f3e84a1SEd Tanous // Option currently returns no systems. TBD 30187f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 30197f3e84a1SEd Tanous systemName); 30207f3e84a1SEd Tanous return; 30217f3e84a1SEd Tanous } 30227f3e84a1SEd Tanous if (systemName != "system") 30237f3e84a1SEd Tanous { 30247f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 30257f3e84a1SEd Tanous systemName); 302622d268cbSEd Tanous return; 302722d268cbSEd Tanous } 302822d268cbSEd Tanous clearDump(asyncResp, "System"); 302922d268cbSEd Tanous } 303022d268cbSEd Tanous 3031fdd26906SClaire Weinan inline void requestRoutesBMCDumpService(App& app) 3032fdd26906SClaire Weinan { 3033fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 3034fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 3035fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 3036fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "BMC")); 3037fdd26906SClaire Weinan } 3038fdd26906SClaire Weinan 3039fdd26906SClaire Weinan inline void requestRoutesBMCDumpEntryCollection(App& app) 3040fdd26906SClaire Weinan { 3041fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 3042fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 3043fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 3044fdd26906SClaire Weinan handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); 3045c9bb6861Sraviteja-b } 3046c9bb6861Sraviteja-b 30477e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 3048c9bb6861Sraviteja-b { 30497e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 30507e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 3051ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 3052fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 3053fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "BMC")); 3054fdd26906SClaire Weinan 30557e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 30567e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 3057ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 3058fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 3059fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); 3060c9bb6861Sraviteja-b } 3061c9bb6861Sraviteja-b 3062168d1b1aSCarson Labrado inline void requestRoutesBMCDumpEntryDownload(App& app) 3063168d1b1aSCarson Labrado { 3064168d1b1aSCarson Labrado BMCWEB_ROUTE( 3065168d1b1aSCarson Labrado app, 3066168d1b1aSCarson Labrado "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/attachment") 3067168d1b1aSCarson Labrado .privileges(redfish::privileges::getLogEntry) 3068168d1b1aSCarson Labrado .methods(boost::beast::http::verb::get)(std::bind_front( 3069168d1b1aSCarson Labrado handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC")); 3070168d1b1aSCarson Labrado } 3071168d1b1aSCarson Labrado 30727e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 3073c9bb6861Sraviteja-b { 30740fda0f12SGeorge Liu BMCWEB_ROUTE( 30750fda0f12SGeorge Liu app, 30760fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 3077ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 30787e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 3079fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, 3080fdd26906SClaire Weinan std::ref(app), "BMC")); 3081a43be80fSAsmitha Karunanithi } 3082a43be80fSAsmitha Karunanithi 30837e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 308480319af1SAsmitha Karunanithi { 30850fda0f12SGeorge Liu BMCWEB_ROUTE( 30860fda0f12SGeorge Liu app, 30870fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog/") 3088ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 3089fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 3090fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); 309145ca1b86SEd Tanous } 3092fdd26906SClaire Weinan 3093168d1b1aSCarson Labrado inline void requestRoutesDBusEventLogEntryDownload(App& app) 3094168d1b1aSCarson Labrado { 3095168d1b1aSCarson Labrado BMCWEB_ROUTE( 3096168d1b1aSCarson Labrado app, 3097168d1b1aSCarson Labrado "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment") 3098168d1b1aSCarson Labrado .privileges(redfish::privileges::getLogEntry) 3099168d1b1aSCarson Labrado .methods(boost::beast::http::verb::get)(std::bind_front( 3100168d1b1aSCarson Labrado handleDBusEventLogEntryDownloadGet, std::ref(app), "System")); 3101168d1b1aSCarson Labrado } 3102168d1b1aSCarson Labrado 3103fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpService(App& app) 3104fdd26906SClaire Weinan { 3105fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/") 3106fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 3107fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 3108fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); 3109fdd26906SClaire Weinan } 3110fdd26906SClaire Weinan 3111fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntryCollection(App& app) 3112fdd26906SClaire Weinan { 3113fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/") 3114fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 3115fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 3116fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpEntriesCollectionGet, 3117fdd26906SClaire Weinan std::ref(app), "FaultLog")); 3118fdd26906SClaire Weinan } 3119fdd26906SClaire Weinan 3120fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntry(App& app) 3121fdd26906SClaire Weinan { 3122fdd26906SClaire Weinan BMCWEB_ROUTE(app, 3123fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/") 3124fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntry) 3125fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 3126fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); 3127fdd26906SClaire Weinan 3128fdd26906SClaire Weinan BMCWEB_ROUTE(app, 3129fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/") 3130fdd26906SClaire Weinan .privileges(redfish::privileges::deleteLogEntry) 3131fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 3132fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); 3133fdd26906SClaire Weinan } 3134fdd26906SClaire Weinan 3135fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpClear(App& app) 3136fdd26906SClaire Weinan { 3137fdd26906SClaire Weinan BMCWEB_ROUTE( 3138fdd26906SClaire Weinan app, 3139fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Actions/LogService.ClearLog/") 3140fdd26906SClaire Weinan .privileges(redfish::privileges::postLogService) 3141fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 3142fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); 31435cb1dd27SAsmitha Karunanithi } 31445cb1dd27SAsmitha Karunanithi 31457e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 31465cb1dd27SAsmitha Karunanithi { 314722d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/") 3148ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 31496ab9ad54SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 315022d268cbSEd Tanous handleLogServicesDumpServiceComputerSystemGet, std::ref(app))); 31515cb1dd27SAsmitha Karunanithi } 31525cb1dd27SAsmitha Karunanithi 31537e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 31547e860f15SJohn Edward Broadbent { 315522d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/") 3156ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 315722d268cbSEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 315822d268cbSEd Tanous handleLogServicesDumpEntriesCollectionComputerSystemGet, 315922d268cbSEd Tanous std::ref(app))); 31605cb1dd27SAsmitha Karunanithi } 31615cb1dd27SAsmitha Karunanithi 31627e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 31635cb1dd27SAsmitha Karunanithi { 31647e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 316522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") 3166ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 31676ab9ad54SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 316822d268cbSEd Tanous handleLogServicesDumpEntryComputerSystemGet, std::ref(app))); 31698d1b46d7Szhanghch05 31707e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 317122d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") 3172ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 31736ab9ad54SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 317422d268cbSEd Tanous handleLogServicesDumpEntryComputerSystemDelete, std::ref(app))); 31755cb1dd27SAsmitha Karunanithi } 3176c9bb6861Sraviteja-b 31777e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 3178c9bb6861Sraviteja-b { 31790fda0f12SGeorge Liu BMCWEB_ROUTE( 31800fda0f12SGeorge Liu app, 318122d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 3182ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 318322d268cbSEd Tanous .methods(boost::beast::http::verb::post)(std::bind_front( 318422d268cbSEd Tanous handleLogServicesDumpCollectDiagnosticDataComputerSystemPost, 318522d268cbSEd Tanous std::ref(app))); 3186a43be80fSAsmitha Karunanithi } 3187a43be80fSAsmitha Karunanithi 31887e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 3189a43be80fSAsmitha Karunanithi { 31900fda0f12SGeorge Liu BMCWEB_ROUTE( 31910fda0f12SGeorge Liu app, 319222d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/") 3193ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 31946ab9ad54SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 319522d268cbSEd Tanous handleLogServicesDumpClearLogComputerSystemPost, std::ref(app))); 3196013487e5Sraviteja-b } 3197013487e5Sraviteja-b 31987e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 31991da66f75SEd Tanous { 32003946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 32013946028dSAppaRao Puli // method for security reasons. 32021da66f75SEd Tanous /** 32031da66f75SEd Tanous * Functions triggers appropriate requests on DBus 32041da66f75SEd Tanous */ 320522d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/") 3206ed398213SEd Tanous // This is incorrect, should be: 3207ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 3208432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 3209002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3210002d39b4SEd Tanous [&app](const crow::Request& req, 321122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 321222d268cbSEd Tanous const std::string& systemName) { 32133ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 321445ca1b86SEd Tanous { 321545ca1b86SEd Tanous return; 321645ca1b86SEd Tanous } 32177f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 32187f3e84a1SEd Tanous { 32197f3e84a1SEd Tanous // Option currently returns no systems. TBD 32207f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 32217f3e84a1SEd Tanous systemName); 32227f3e84a1SEd Tanous return; 32237f3e84a1SEd Tanous } 322422d268cbSEd Tanous if (systemName != "system") 322522d268cbSEd Tanous { 322622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 322722d268cbSEd Tanous systemName); 322822d268cbSEd Tanous return; 322922d268cbSEd Tanous } 323022d268cbSEd Tanous 32317e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 32327e860f15SJohn Edward Broadbent // SubRoute 32330f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3234424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 3235e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 32368e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 32374f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 32384f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 323915b89725SV-Sanjana asyncResp->res.jsonValue["Id"] = "Crashdump"; 3240e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 3241e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 32427c8c4058STejas Patil 32437c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 32442b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 32457c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 32467c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 32477c8c4058STejas Patil redfishDateTimeOffset.second; 32487c8c4058STejas Patil 32491476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 3250ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 3251002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 32521476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog"; 3253002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 32541476687dSEd Tanous ["target"] = 32551476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData"; 32567e860f15SJohn Edward Broadbent }); 32571da66f75SEd Tanous } 32581da66f75SEd Tanous 32597e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 32605b61b5e8SJason M. Bills { 32610fda0f12SGeorge Liu BMCWEB_ROUTE( 32620fda0f12SGeorge Liu app, 326322d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/") 3264ed398213SEd Tanous // This is incorrect, should be: 3265ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3266432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 32677e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 326845ca1b86SEd Tanous [&app](const crow::Request& req, 326922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 327022d268cbSEd Tanous const std::string& systemName) { 32713ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 327245ca1b86SEd Tanous { 327345ca1b86SEd Tanous return; 327445ca1b86SEd Tanous } 32757f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 32767f3e84a1SEd Tanous { 32777f3e84a1SEd Tanous // Option currently returns no systems. TBD 32787f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 32797f3e84a1SEd Tanous systemName); 32807f3e84a1SEd Tanous return; 32817f3e84a1SEd Tanous } 328222d268cbSEd Tanous if (systemName != "system") 328322d268cbSEd Tanous { 328422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 328522d268cbSEd Tanous systemName); 328622d268cbSEd Tanous return; 328722d268cbSEd Tanous } 32885b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 32895e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 3290cb13a392SEd Tanous const std::string&) { 32915b61b5e8SJason M. Bills if (ec) 32925b61b5e8SJason M. Bills { 32935b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 32945b61b5e8SJason M. Bills return; 32955b61b5e8SJason M. Bills } 32965b61b5e8SJason M. Bills messages::success(asyncResp->res); 32975b61b5e8SJason M. Bills }, 3298002d39b4SEd Tanous crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 32997e860f15SJohn Edward Broadbent }); 33005b61b5e8SJason M. Bills } 33015b61b5e8SJason M. Bills 33028d1b46d7Szhanghch05 static void 33038d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 33048d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 3305e855dd28SJason M. Bills { 3306043a0536SJohnathan Mantey auto getStoredLogCallback = 3307b9d36b47SEd Tanous [asyncResp, logID, 33085e7e2dc5SEd Tanous &logEntryJson](const boost::system::error_code& ec, 3309b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& params) { 3310e855dd28SJason M. Bills if (ec) 3311e855dd28SJason M. Bills { 331262598e31SEd Tanous BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message()); 33131ddcf01aSJason M. Bills if (ec.value() == 33141ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 33151ddcf01aSJason M. Bills { 3316002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 33171ddcf01aSJason M. Bills } 33181ddcf01aSJason M. Bills else 33191ddcf01aSJason M. Bills { 3320e855dd28SJason M. Bills messages::internalError(asyncResp->res); 33211ddcf01aSJason M. Bills } 3322e855dd28SJason M. Bills return; 3323e855dd28SJason M. Bills } 3324043a0536SJohnathan Mantey 3325043a0536SJohnathan Mantey std::string timestamp{}; 3326043a0536SJohnathan Mantey std::string filename{}; 3327043a0536SJohnathan Mantey std::string logfile{}; 33282c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 3329043a0536SJohnathan Mantey 3330043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 3331e855dd28SJason M. Bills { 33329db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3333e855dd28SJason M. Bills return; 3334e855dd28SJason M. Bills } 3335e855dd28SJason M. Bills 3336043a0536SJohnathan Mantey std::string crashdumpURI = 3337e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 3338043a0536SJohnathan Mantey logID + "/" + filename; 333984afc48bSJason M. Bills nlohmann::json::object_t logEntry; 33409c11a172SVijay Lobo logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 3341ef4c65b7SEd Tanous logEntry["@odata.id"] = boost::urls::format( 3342ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/{}", 3343ef4c65b7SEd Tanous logID); 334484afc48bSJason M. Bills logEntry["Name"] = "CPU Crashdump"; 334584afc48bSJason M. Bills logEntry["Id"] = logID; 334684afc48bSJason M. Bills logEntry["EntryType"] = "Oem"; 334784afc48bSJason M. Bills logEntry["AdditionalDataURI"] = std::move(crashdumpURI); 334884afc48bSJason M. Bills logEntry["DiagnosticDataType"] = "OEM"; 334984afc48bSJason M. Bills logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; 335084afc48bSJason M. Bills logEntry["Created"] = std::move(timestamp); 33512b20ef6eSJason M. Bills 33522b20ef6eSJason M. Bills // If logEntryJson references an array of LogEntry resources 33532b20ef6eSJason M. Bills // ('Members' list), then push this as a new entry, otherwise set it 33542b20ef6eSJason M. Bills // directly 33552b20ef6eSJason M. Bills if (logEntryJson.is_array()) 33562b20ef6eSJason M. Bills { 33572b20ef6eSJason M. Bills logEntryJson.push_back(logEntry); 33582b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 33592b20ef6eSJason M. Bills logEntryJson.size(); 33602b20ef6eSJason M. Bills } 33612b20ef6eSJason M. Bills else 33622b20ef6eSJason M. Bills { 3363d405bb51SJason M. Bills logEntryJson.update(logEntry); 33642b20ef6eSJason M. Bills } 3365e855dd28SJason M. Bills }; 3366d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3367d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, crashdumpObject, 3368d1bde9e5SKrzysztof Grobelny crashdumpPath + std::string("/") + logID, crashdumpInterface, 3369d1bde9e5SKrzysztof Grobelny std::move(getStoredLogCallback)); 3370e855dd28SJason M. Bills } 3371e855dd28SJason M. Bills 33727e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 33731da66f75SEd Tanous { 33743946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 33753946028dSAppaRao Puli // method for security reasons. 33761da66f75SEd Tanous /** 33771da66f75SEd Tanous * Functions triggers appropriate requests on DBus 33781da66f75SEd Tanous */ 33797e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 338022d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/") 3381ed398213SEd Tanous // This is incorrect, should be. 3382ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 3383432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3384002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3385002d39b4SEd Tanous [&app](const crow::Request& req, 338622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 338722d268cbSEd Tanous const std::string& systemName) { 33883ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 338945ca1b86SEd Tanous { 339045ca1b86SEd Tanous return; 339145ca1b86SEd Tanous } 33927f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 33937f3e84a1SEd Tanous { 33947f3e84a1SEd Tanous // Option currently returns no systems. TBD 33957f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 33967f3e84a1SEd Tanous systemName); 33977f3e84a1SEd Tanous return; 33987f3e84a1SEd Tanous } 339922d268cbSEd Tanous if (systemName != "system") 340022d268cbSEd Tanous { 340122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 340222d268cbSEd Tanous systemName); 340322d268cbSEd Tanous return; 340422d268cbSEd Tanous } 340522d268cbSEd Tanous 34067a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 34077a1dbc48SGeorge Liu crashdumpInterface}; 34087a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 34097a1dbc48SGeorge Liu "/", 0, interfaces, 34107a1dbc48SGeorge Liu [asyncResp](const boost::system::error_code& ec, 34112b20ef6eSJason M. Bills const std::vector<std::string>& resp) { 34121da66f75SEd Tanous if (ec) 34131da66f75SEd Tanous { 34141da66f75SEd Tanous if (ec.value() != 34151da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 34161da66f75SEd Tanous { 341762598e31SEd Tanous BMCWEB_LOG_DEBUG("failed to get entries ec: {}", 341862598e31SEd Tanous ec.message()); 3419f12894f8SJason M. Bills messages::internalError(asyncResp->res); 34201da66f75SEd Tanous return; 34211da66f75SEd Tanous } 34221da66f75SEd Tanous } 3423e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 34241da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 34250f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3426424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 3427002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 3428e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 3429424c4176SJason M. Bills "Collection of Crashdump Entries"; 3430002d39b4SEd Tanous asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3431a2dd60a6SBrandon Kim asyncResp->res.jsonValue["Members@odata.count"] = 0; 34322b20ef6eSJason M. Bills 34332b20ef6eSJason M. Bills for (const std::string& path : resp) 34341da66f75SEd Tanous { 34352b20ef6eSJason M. Bills const sdbusplus::message::object_path objPath(path); 3436e855dd28SJason M. Bills // Get the log ID 34372b20ef6eSJason M. Bills std::string logID = objPath.filename(); 34382b20ef6eSJason M. Bills if (logID.empty()) 34391da66f75SEd Tanous { 3440e855dd28SJason M. Bills continue; 34411da66f75SEd Tanous } 3442e855dd28SJason M. Bills // Add the log entry to the array 34432b20ef6eSJason M. Bills logCrashdumpEntry(asyncResp, logID, 34442b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"]); 34451da66f75SEd Tanous } 34467a1dbc48SGeorge Liu }); 34477e860f15SJohn Edward Broadbent }); 34481da66f75SEd Tanous } 34491da66f75SEd Tanous 34507e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 34511da66f75SEd Tanous { 34523946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 34533946028dSAppaRao Puli // method for security reasons. 34541da66f75SEd Tanous 34557e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 345622d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/") 3457ed398213SEd Tanous // this is incorrect, should be 3458ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 3459432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 34607e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 346145ca1b86SEd Tanous [&app](const crow::Request& req, 34627e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 346322d268cbSEd Tanous const std::string& systemName, const std::string& param) { 34643ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 346545ca1b86SEd Tanous { 346645ca1b86SEd Tanous return; 346745ca1b86SEd Tanous } 34687f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 34697f3e84a1SEd Tanous { 34707f3e84a1SEd Tanous // Option currently returns no systems. TBD 34717f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 34727f3e84a1SEd Tanous systemName); 34737f3e84a1SEd Tanous return; 34747f3e84a1SEd Tanous } 347522d268cbSEd Tanous if (systemName != "system") 347622d268cbSEd Tanous { 347722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 347822d268cbSEd Tanous systemName); 347922d268cbSEd Tanous return; 348022d268cbSEd Tanous } 34817e860f15SJohn Edward Broadbent const std::string& logID = param; 3482e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 34837e860f15SJohn Edward Broadbent }); 3484e855dd28SJason M. Bills } 3485e855dd28SJason M. Bills 34867e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 3487e855dd28SJason M. Bills { 34883946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 34893946028dSAppaRao Puli // method for security reasons. 34907e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 34917e860f15SJohn Edward Broadbent app, 349222d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/") 3493ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 34947e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 3495a4ce114aSNan Zhou [](const crow::Request& req, 34967e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 349722d268cbSEd Tanous const std::string& systemName, const std::string& logID, 349822d268cbSEd Tanous const std::string& fileName) { 34992a9beeedSShounak Mitra // Do not call getRedfishRoute here since the crashdump file is not a 35002a9beeedSShounak Mitra // Redfish resource. 350122d268cbSEd Tanous 35027f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 35037f3e84a1SEd Tanous { 35047f3e84a1SEd Tanous // Option currently returns no systems. TBD 35057f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 35067f3e84a1SEd Tanous systemName); 35077f3e84a1SEd Tanous return; 35087f3e84a1SEd Tanous } 350922d268cbSEd Tanous if (systemName != "system") 351022d268cbSEd Tanous { 351122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 351222d268cbSEd Tanous systemName); 351322d268cbSEd Tanous return; 351422d268cbSEd Tanous } 351522d268cbSEd Tanous 3516043a0536SJohnathan Mantey auto getStoredLogCallback = 351739662a3bSEd Tanous [asyncResp, logID, fileName, url(boost::urls::url(req.url()))]( 35185e7e2dc5SEd Tanous const boost::system::error_code& ec, 3519002d39b4SEd Tanous const std::vector< 3520002d39b4SEd Tanous std::pair<std::string, dbus::utility::DbusVariantType>>& 35217e860f15SJohn Edward Broadbent resp) { 35221da66f75SEd Tanous if (ec) 35231da66f75SEd Tanous { 352462598e31SEd Tanous BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message()); 3525f12894f8SJason M. Bills messages::internalError(asyncResp->res); 35261da66f75SEd Tanous return; 35271da66f75SEd Tanous } 3528e855dd28SJason M. Bills 3529043a0536SJohnathan Mantey std::string dbusFilename{}; 3530043a0536SJohnathan Mantey std::string dbusTimestamp{}; 3531043a0536SJohnathan Mantey std::string dbusFilepath{}; 3532043a0536SJohnathan Mantey 3533002d39b4SEd Tanous parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 3534002d39b4SEd Tanous dbusFilepath); 3535043a0536SJohnathan Mantey 3536043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 3537043a0536SJohnathan Mantey dbusFilepath.empty()) 35381da66f75SEd Tanous { 35399db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 35401da66f75SEd Tanous return; 35411da66f75SEd Tanous } 3542e855dd28SJason M. Bills 3543043a0536SJohnathan Mantey // Verify the file name parameter is correct 3544043a0536SJohnathan Mantey if (fileName != dbusFilename) 3545043a0536SJohnathan Mantey { 35469db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3547043a0536SJohnathan Mantey return; 3548043a0536SJohnathan Mantey } 3549043a0536SJohnathan Mantey 3550*27b0cf90SEd Tanous if (!asyncResp->res.openFile(dbusFilepath)) 3551043a0536SJohnathan Mantey { 35529db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3553043a0536SJohnathan Mantey return; 3554043a0536SJohnathan Mantey } 3555043a0536SJohnathan Mantey 35567e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 35577e860f15SJohn Edward Broadbent // from a browser 3558d9f6c621SEd Tanous asyncResp->res.addHeader( 3559d9f6c621SEd Tanous boost::beast::http::field::content_disposition, "attachment"); 35601da66f75SEd Tanous }; 3561d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3562d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, crashdumpObject, 3563d1bde9e5SKrzysztof Grobelny crashdumpPath + std::string("/") + logID, crashdumpInterface, 3564d1bde9e5SKrzysztof Grobelny std::move(getStoredLogCallback)); 35657e860f15SJohn Edward Broadbent }); 35661da66f75SEd Tanous } 35671da66f75SEd Tanous 3568c5a4c82aSJason M. Bills enum class OEMDiagnosticType 3569c5a4c82aSJason M. Bills { 3570c5a4c82aSJason M. Bills onDemand, 3571c5a4c82aSJason M. Bills telemetry, 3572c5a4c82aSJason M. Bills invalid, 3573c5a4c82aSJason M. Bills }; 3574c5a4c82aSJason M. Bills 357526ccae32SEd Tanous inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr) 3576c5a4c82aSJason M. Bills { 3577c5a4c82aSJason M. Bills if (oemDiagStr == "OnDemand") 3578c5a4c82aSJason M. Bills { 3579c5a4c82aSJason M. Bills return OEMDiagnosticType::onDemand; 3580c5a4c82aSJason M. Bills } 3581c5a4c82aSJason M. Bills if (oemDiagStr == "Telemetry") 3582c5a4c82aSJason M. Bills { 3583c5a4c82aSJason M. Bills return OEMDiagnosticType::telemetry; 3584c5a4c82aSJason M. Bills } 3585c5a4c82aSJason M. Bills 3586c5a4c82aSJason M. Bills return OEMDiagnosticType::invalid; 3587c5a4c82aSJason M. Bills } 3588c5a4c82aSJason M. Bills 35897e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 35901da66f75SEd Tanous { 35913946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 35923946028dSAppaRao Puli // method for security reasons. 35930fda0f12SGeorge Liu BMCWEB_ROUTE( 35940fda0f12SGeorge Liu app, 359522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") 3596ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 3597ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3598432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3599002d39b4SEd Tanous .methods(boost::beast::http::verb::post)( 3600002d39b4SEd Tanous [&app](const crow::Request& req, 360122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 360222d268cbSEd Tanous const std::string& systemName) { 36033ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 360445ca1b86SEd Tanous { 360545ca1b86SEd Tanous return; 360645ca1b86SEd Tanous } 360722d268cbSEd Tanous 36087f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 36097f3e84a1SEd Tanous { 36107f3e84a1SEd Tanous // Option currently returns no systems. TBD 36117f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 36127f3e84a1SEd Tanous systemName); 36137f3e84a1SEd Tanous return; 36147f3e84a1SEd Tanous } 361522d268cbSEd Tanous if (systemName != "system") 361622d268cbSEd Tanous { 361722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 361822d268cbSEd Tanous systemName); 361922d268cbSEd Tanous return; 362022d268cbSEd Tanous } 362122d268cbSEd Tanous 36228e6c099aSJason M. Bills std::string diagnosticDataType; 36238e6c099aSJason M. Bills std::string oemDiagnosticDataType; 362415ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 3625002d39b4SEd Tanous req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 3626002d39b4SEd Tanous "OEMDiagnosticDataType", oemDiagnosticDataType)) 36278e6c099aSJason M. Bills { 36288e6c099aSJason M. Bills return; 36298e6c099aSJason M. Bills } 36308e6c099aSJason M. Bills 36318e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 36328e6c099aSJason M. Bills { 363362598e31SEd Tanous BMCWEB_LOG_ERROR( 363462598e31SEd Tanous "Only OEM DiagnosticDataType supported for Crashdump"); 36358e6c099aSJason M. Bills messages::actionParameterValueFormatError( 36368e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 36378e6c099aSJason M. Bills "CollectDiagnosticData"); 36388e6c099aSJason M. Bills return; 36398e6c099aSJason M. Bills } 36408e6c099aSJason M. Bills 3641c5a4c82aSJason M. Bills OEMDiagnosticType oemDiagType = 3642c5a4c82aSJason M. Bills getOEMDiagnosticType(oemDiagnosticDataType); 3643c5a4c82aSJason M. Bills 3644c5a4c82aSJason M. Bills std::string iface; 3645c5a4c82aSJason M. Bills std::string method; 3646c5a4c82aSJason M. Bills std::string taskMatchStr; 3647c5a4c82aSJason M. Bills if (oemDiagType == OEMDiagnosticType::onDemand) 3648c5a4c82aSJason M. Bills { 3649c5a4c82aSJason M. Bills iface = crashdumpOnDemandInterface; 3650c5a4c82aSJason M. Bills method = "GenerateOnDemandLog"; 3651c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3652c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3653c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3654c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3655c5a4c82aSJason M. Bills } 3656c5a4c82aSJason M. Bills else if (oemDiagType == OEMDiagnosticType::telemetry) 3657c5a4c82aSJason M. Bills { 3658c5a4c82aSJason M. Bills iface = crashdumpTelemetryInterface; 3659c5a4c82aSJason M. Bills method = "GenerateTelemetryLog"; 3660c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3661c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3662c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3663c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3664c5a4c82aSJason M. Bills } 3665c5a4c82aSJason M. Bills else 3666c5a4c82aSJason M. Bills { 366762598e31SEd Tanous BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}", 366862598e31SEd Tanous oemDiagnosticDataType); 3669c5a4c82aSJason M. Bills messages::actionParameterValueFormatError( 3670002d39b4SEd Tanous asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType", 3671002d39b4SEd Tanous "CollectDiagnosticData"); 3672c5a4c82aSJason M. Bills return; 3673c5a4c82aSJason M. Bills } 3674c5a4c82aSJason M. Bills 3675c5a4c82aSJason M. Bills auto collectCrashdumpCallback = 3676c5a4c82aSJason M. Bills [asyncResp, payload(task::Payload(req)), 36775e7e2dc5SEd Tanous taskMatchStr](const boost::system::error_code& ec, 367898be3e39SEd Tanous const std::string&) mutable { 36791da66f75SEd Tanous if (ec) 36801da66f75SEd Tanous { 3681002d39b4SEd Tanous if (ec.value() == boost::system::errc::operation_not_supported) 36821da66f75SEd Tanous { 3683f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 36841da66f75SEd Tanous } 36854363d3b2SJason M. Bills else if (ec.value() == 36864363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 36874363d3b2SJason M. Bills { 3688002d39b4SEd Tanous messages::serviceTemporarilyUnavailable(asyncResp->res, 3689002d39b4SEd Tanous "60"); 36904363d3b2SJason M. Bills } 36911da66f75SEd Tanous else 36921da66f75SEd Tanous { 3693f12894f8SJason M. Bills messages::internalError(asyncResp->res); 36941da66f75SEd Tanous } 36951da66f75SEd Tanous return; 36961da66f75SEd Tanous } 3697002d39b4SEd Tanous std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 36988b24275dSEd Tanous [](const boost::system::error_code& ec2, sdbusplus::message_t&, 3699002d39b4SEd Tanous const std::shared_ptr<task::TaskData>& taskData) { 37008b24275dSEd Tanous if (!ec2) 370166afe4faSJames Feist { 3702002d39b4SEd Tanous taskData->messages.emplace_back(messages::taskCompletedOK( 3703e5d5006bSJames Feist std::to_string(taskData->index))); 3704831d6b09SJames Feist taskData->state = "Completed"; 370566afe4faSJames Feist } 370632898ceaSJames Feist return task::completed; 370766afe4faSJames Feist }, 3708c5a4c82aSJason M. Bills taskMatchStr); 3709c5a4c82aSJason M. Bills 371046229577SJames Feist task->startTimer(std::chrono::minutes(5)); 371146229577SJames Feist task->populateResp(asyncResp->res); 371298be3e39SEd Tanous task->payload.emplace(std::move(payload)); 37131da66f75SEd Tanous }; 37148e6c099aSJason M. Bills 37151da66f75SEd Tanous crow::connections::systemBus->async_method_call( 3716002d39b4SEd Tanous std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath, 3717002d39b4SEd Tanous iface, method); 37187e860f15SJohn Edward Broadbent }); 37196eda7685SKenny L. Ku } 37206eda7685SKenny L. Ku 3721cb92c03bSAndrew Geissler /** 3722cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 3723cb92c03bSAndrew Geissler */ 37247e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 3725cb92c03bSAndrew Geissler { 3726cb92c03bSAndrew Geissler /** 3727cb92c03bSAndrew Geissler * Function handles POST method request. 3728cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3729cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3730cb92c03bSAndrew Geissler */ 37317e860f15SJohn Edward Broadbent 37320fda0f12SGeorge Liu BMCWEB_ROUTE( 37330fda0f12SGeorge Liu app, 373422d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 3735ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 37367e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 373745ca1b86SEd Tanous [&app](const crow::Request& req, 373822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 373922d268cbSEd Tanous const std::string& systemName) { 37403ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 374145ca1b86SEd Tanous { 374245ca1b86SEd Tanous return; 374345ca1b86SEd Tanous } 37447f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 37457f3e84a1SEd Tanous { 37467f3e84a1SEd Tanous // Option currently returns no systems. TBD 37477f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 37487f3e84a1SEd Tanous systemName); 37497f3e84a1SEd Tanous return; 37507f3e84a1SEd Tanous } 375122d268cbSEd Tanous if (systemName != "system") 375222d268cbSEd Tanous { 375322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 375422d268cbSEd Tanous systemName); 375522d268cbSEd Tanous return; 375622d268cbSEd Tanous } 375762598e31SEd Tanous BMCWEB_LOG_DEBUG("Do delete all entries."); 3758cb92c03bSAndrew Geissler 3759cb92c03bSAndrew Geissler // Process response from Logging service. 37605e7e2dc5SEd Tanous auto respHandler = [asyncResp](const boost::system::error_code& ec) { 376162598e31SEd Tanous BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done"); 3762cb92c03bSAndrew Geissler if (ec) 3763cb92c03bSAndrew Geissler { 3764cb92c03bSAndrew Geissler // TODO Handle for specific error code 376562598e31SEd Tanous BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec); 3766cb92c03bSAndrew Geissler asyncResp->res.result( 3767cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3768cb92c03bSAndrew Geissler return; 3769cb92c03bSAndrew Geissler } 3770cb92c03bSAndrew Geissler 3771002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content); 3772cb92c03bSAndrew Geissler }; 3773cb92c03bSAndrew Geissler 3774cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3775cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 37762c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 3777cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3778cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 37797e860f15SJohn Edward Broadbent }); 3780cb92c03bSAndrew Geissler } 3781a3316fc6SZhikuiRen 3782a3316fc6SZhikuiRen /**************************************************** 3783a3316fc6SZhikuiRen * Redfish PostCode interfaces 3784a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3785a3316fc6SZhikuiRen ******************************************************/ 37867e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 3787a3316fc6SZhikuiRen { 378822d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/") 3789ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 3790002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3791002d39b4SEd Tanous [&app](const crow::Request& req, 379222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 379322d268cbSEd Tanous const std::string& systemName) { 37943ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 379545ca1b86SEd Tanous { 379645ca1b86SEd Tanous return; 379745ca1b86SEd Tanous } 37987f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 37997f3e84a1SEd Tanous { 38007f3e84a1SEd Tanous // Option currently returns no systems. TBD 38017f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 38027f3e84a1SEd Tanous systemName); 38037f3e84a1SEd Tanous return; 38047f3e84a1SEd Tanous } 380522d268cbSEd Tanous if (systemName != "system") 380622d268cbSEd Tanous { 380722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 380822d268cbSEd Tanous systemName); 380922d268cbSEd Tanous return; 381022d268cbSEd Tanous } 38111476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 38121476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes"; 38131476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 3814b25644a1SJanet Adkins "#LogService.v1_2_0.LogService"; 38151476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "POST Code Log Service"; 38161476687dSEd Tanous asyncResp->res.jsonValue["Description"] = "POST Code Log Service"; 3817ed34a4adSEd Tanous asyncResp->res.jsonValue["Id"] = "PostCodes"; 38181476687dSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 38191476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 38201476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 38217c8c4058STejas Patil 38227c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 38232b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 38240fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 38257c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 38267c8c4058STejas Patil redfishDateTimeOffset.second; 38277c8c4058STejas Patil 3828a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 38297e860f15SJohn Edward Broadbent {"target", 38300fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog"}}; 38317e860f15SJohn Edward Broadbent }); 3832a3316fc6SZhikuiRen } 3833a3316fc6SZhikuiRen 38347e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3835a3316fc6SZhikuiRen { 38360fda0f12SGeorge Liu BMCWEB_ROUTE( 38370fda0f12SGeorge Liu app, 383822d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/") 3839ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3840ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3841432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 38427e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 384345ca1b86SEd Tanous [&app](const crow::Request& req, 384422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 384522d268cbSEd Tanous const std::string& systemName) { 38463ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 384745ca1b86SEd Tanous { 384845ca1b86SEd Tanous return; 384945ca1b86SEd Tanous } 38507f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 38517f3e84a1SEd Tanous { 38527f3e84a1SEd Tanous // Option currently returns no systems. TBD 38537f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 38547f3e84a1SEd Tanous systemName); 38557f3e84a1SEd Tanous return; 38567f3e84a1SEd Tanous } 385722d268cbSEd Tanous if (systemName != "system") 385822d268cbSEd Tanous { 385922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 386022d268cbSEd Tanous systemName); 386122d268cbSEd Tanous return; 386222d268cbSEd Tanous } 386362598e31SEd Tanous BMCWEB_LOG_DEBUG("Do delete all postcodes entries."); 3864a3316fc6SZhikuiRen 3865a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3866a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 38675e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 3868a3316fc6SZhikuiRen if (ec) 3869a3316fc6SZhikuiRen { 3870a3316fc6SZhikuiRen // TODO Handle for specific error code 387162598e31SEd Tanous BMCWEB_LOG_ERROR("doClearPostCodes resp_handler got error {}", 387262598e31SEd Tanous ec); 3873002d39b4SEd Tanous asyncResp->res.result( 3874002d39b4SEd Tanous boost::beast::http::status::internal_server_error); 3875a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3876a3316fc6SZhikuiRen return; 3877a3316fc6SZhikuiRen } 387818fc70c0STony Lee messages::success(asyncResp->res); 3879a3316fc6SZhikuiRen }, 388015124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 388115124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3882a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 38837e860f15SJohn Edward Broadbent }); 3884a3316fc6SZhikuiRen } 3885a3316fc6SZhikuiRen 38866f284d24SJiaqing Zhao /** 38876f284d24SJiaqing Zhao * @brief Parse post code ID and get the current value and index value 38886f284d24SJiaqing Zhao * eg: postCodeID=B1-2, currentValue=1, index=2 38896f284d24SJiaqing Zhao * 38906f284d24SJiaqing Zhao * @param[in] postCodeID Post Code ID 38916f284d24SJiaqing Zhao * @param[out] currentValue Current value 38926f284d24SJiaqing Zhao * @param[out] index Index value 38936f284d24SJiaqing Zhao * 38946f284d24SJiaqing Zhao * @return bool true if the parsing is successful, false the parsing fails 38956f284d24SJiaqing Zhao */ 38966f284d24SJiaqing Zhao inline static bool parsePostCode(const std::string& postCodeID, 38976f284d24SJiaqing Zhao uint64_t& currentValue, uint16_t& index) 38986f284d24SJiaqing Zhao { 38996f284d24SJiaqing Zhao std::vector<std::string> split; 390050ebd4afSEd Tanous bmcweb::split(split, postCodeID, '-'); 39016f284d24SJiaqing Zhao if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B') 39026f284d24SJiaqing Zhao { 39036f284d24SJiaqing Zhao return false; 39046f284d24SJiaqing Zhao } 39056f284d24SJiaqing Zhao 390684396af9SPatrick Williams auto start = std::next(split[0].begin()); 390784396af9SPatrick Williams auto end = split[0].end(); 390884396af9SPatrick Williams auto [ptrIndex, ecIndex] = std::from_chars(&*start, &*end, index); 39096f284d24SJiaqing Zhao 391084396af9SPatrick Williams if (ptrIndex != &*end || ecIndex != std::errc()) 39116f284d24SJiaqing Zhao { 39126f284d24SJiaqing Zhao return false; 39136f284d24SJiaqing Zhao } 39146f284d24SJiaqing Zhao 391584396af9SPatrick Williams start = split[1].begin(); 391684396af9SPatrick Williams end = split[1].end(); 39176f284d24SJiaqing Zhao 391884396af9SPatrick Williams auto [ptrValue, ecValue] = std::from_chars(&*start, &*end, currentValue); 39196f284d24SJiaqing Zhao 392084396af9SPatrick Williams return ptrValue == &*end && ecValue == std::errc(); 39216f284d24SJiaqing Zhao } 39226f284d24SJiaqing Zhao 39236f284d24SJiaqing Zhao static bool fillPostCodeEntry( 3924ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 39256c9a279eSManojkiran Eda const boost::container::flat_map< 39266c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3927a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3928a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3929a3316fc6SZhikuiRen { 3930a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3931fffb8c1fSEd Tanous const registries::Message* message = 3932fffb8c1fSEd Tanous registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3933a3316fc6SZhikuiRen 3934a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3935a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 39366c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 39376c9a279eSManojkiran Eda code : postcode) 3938a3316fc6SZhikuiRen { 3939a3316fc6SZhikuiRen currentCodeIndex++; 3940a3316fc6SZhikuiRen std::string postcodeEntryID = 3941a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3942a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3943a3316fc6SZhikuiRen 3944a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3945a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3946a3316fc6SZhikuiRen 3947a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3948a3316fc6SZhikuiRen { // already incremented 3949a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3950a3316fc6SZhikuiRen } 3951a3316fc6SZhikuiRen else 3952a3316fc6SZhikuiRen { 3953a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3954a3316fc6SZhikuiRen } 3955a3316fc6SZhikuiRen 3956a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3957a3316fc6SZhikuiRen // not fall between top and skip 3958a3316fc6SZhikuiRen if ((codeIndex == 0) && 3959a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3960a3316fc6SZhikuiRen { 3961a3316fc6SZhikuiRen continue; 3962a3316fc6SZhikuiRen } 3963a3316fc6SZhikuiRen 39644e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3965a3316fc6SZhikuiRen // currentIndex 3966a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3967a3316fc6SZhikuiRen { 3968a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3969a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3970a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3971a3316fc6SZhikuiRen continue; 3972a3316fc6SZhikuiRen } 3973a3316fc6SZhikuiRen 3974a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3975a3316fc6SZhikuiRen // index 3976a3316fc6SZhikuiRen 3977a3316fc6SZhikuiRen // Get the Created time from the timestamp 3978a3316fc6SZhikuiRen std::string entryTimeStr; 39792a025611SKonstantin Aladyshev entryTimeStr = redfish::time_utils::getDateTimeUintUs(usecSinceEpoch); 3980a3316fc6SZhikuiRen 3981a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3982a3316fc6SZhikuiRen std::ostringstream hexCode; 3983a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 39846c9a279eSManojkiran Eda << std::get<0>(code.second); 3985a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3986a3316fc6SZhikuiRen // Set Fixed -Point Notation 3987a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3988a3316fc6SZhikuiRen // Set precision to 4 digits 3989a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3990a3316fc6SZhikuiRen // Add double to stream 3991a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3992a3316fc6SZhikuiRen 39931e6deaf6SEd Tanous std::string bootIndexStr = std::to_string(bootIndex); 39941e6deaf6SEd Tanous std::string timeOffsetString = timeOffsetStr.str(); 39951e6deaf6SEd Tanous std::string hexCodeStr = hexCode.str(); 3996a3316fc6SZhikuiRen 39971e6deaf6SEd Tanous std::array<std::string_view, 3> messageArgs = { 39981e6deaf6SEd Tanous bootIndexStr, timeOffsetString, hexCodeStr}; 39991e6deaf6SEd Tanous 40001e6deaf6SEd Tanous std::string msg = 40011e6deaf6SEd Tanous redfish::registries::fillMessageArgs(messageArgs, message->message); 40021e6deaf6SEd Tanous if (msg.empty()) 4003a3316fc6SZhikuiRen { 40041e6deaf6SEd Tanous messages::internalError(asyncResp->res); 40051e6deaf6SEd Tanous return false; 4006a3316fc6SZhikuiRen } 4007a3316fc6SZhikuiRen 4008d4342a92STim Lee // Get Severity template from message registry 4009d4342a92STim Lee std::string severity; 4010d4342a92STim Lee if (message != nullptr) 4011d4342a92STim Lee { 40125f2b84eeSEd Tanous severity = message->messageSeverity; 4013d4342a92STim Lee } 4014d4342a92STim Lee 40156f284d24SJiaqing Zhao // Format entry 40166f284d24SJiaqing Zhao nlohmann::json::object_t bmcLogEntry; 40179c11a172SVijay Lobo bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 4018ef4c65b7SEd Tanous bmcLogEntry["@odata.id"] = boost::urls::format( 4019ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/{}", 4020ef4c65b7SEd Tanous postcodeEntryID); 402184afc48bSJason M. Bills bmcLogEntry["Name"] = "POST Code Log Entry"; 402284afc48bSJason M. Bills bmcLogEntry["Id"] = postcodeEntryID; 402384afc48bSJason M. Bills bmcLogEntry["Message"] = std::move(msg); 402484afc48bSJason M. Bills bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode"; 40251e6deaf6SEd Tanous bmcLogEntry["MessageArgs"] = messageArgs; 402684afc48bSJason M. Bills bmcLogEntry["EntryType"] = "Event"; 402784afc48bSJason M. Bills bmcLogEntry["Severity"] = std::move(severity); 402884afc48bSJason M. Bills bmcLogEntry["Created"] = entryTimeStr; 4029647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 4030647b3cdcSGeorge Liu { 4031647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 4032647b3cdcSGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 4033647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 4034647b3cdcSGeorge Liu } 40356f284d24SJiaqing Zhao 40366f284d24SJiaqing Zhao // codeIndex is only specified when querying single entry, return only 40376f284d24SJiaqing Zhao // that entry in this case 40386f284d24SJiaqing Zhao if (codeIndex != 0) 40396f284d24SJiaqing Zhao { 4040ac106bf6SEd Tanous asyncResp->res.jsonValue.update(bmcLogEntry); 40416f284d24SJiaqing Zhao return true; 4042a3316fc6SZhikuiRen } 40436f284d24SJiaqing Zhao 4044ac106bf6SEd Tanous nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 4045b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(bmcLogEntry)); 40466f284d24SJiaqing Zhao } 40476f284d24SJiaqing Zhao 40486f284d24SJiaqing Zhao // Return value is always false when querying multiple entries 40496f284d24SJiaqing Zhao return false; 4050a3316fc6SZhikuiRen } 4051a3316fc6SZhikuiRen 4052ac106bf6SEd Tanous static void 4053ac106bf6SEd Tanous getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 40546f284d24SJiaqing Zhao const std::string& entryId) 4055a3316fc6SZhikuiRen { 40566f284d24SJiaqing Zhao uint16_t bootIndex = 0; 40576f284d24SJiaqing Zhao uint64_t codeIndex = 0; 40586f284d24SJiaqing Zhao if (!parsePostCode(entryId, codeIndex, bootIndex)) 40596f284d24SJiaqing Zhao { 40606f284d24SJiaqing Zhao // Requested ID was not found 4061ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 40626f284d24SJiaqing Zhao return; 40636f284d24SJiaqing Zhao } 40646f284d24SJiaqing Zhao 40656f284d24SJiaqing Zhao if (bootIndex == 0 || codeIndex == 0) 40666f284d24SJiaqing Zhao { 40676f284d24SJiaqing Zhao // 0 is an invalid index 4068ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 40696f284d24SJiaqing Zhao return; 40706f284d24SJiaqing Zhao } 40716f284d24SJiaqing Zhao 4072a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 4073ac106bf6SEd Tanous [asyncResp, entryId, bootIndex, 40745e7e2dc5SEd Tanous codeIndex](const boost::system::error_code& ec, 40756c9a279eSManojkiran Eda const boost::container::flat_map< 40766c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 40776c9a279eSManojkiran Eda postcode) { 4078a3316fc6SZhikuiRen if (ec) 4079a3316fc6SZhikuiRen { 408062598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error"); 4081ac106bf6SEd Tanous messages::internalError(asyncResp->res); 4082a3316fc6SZhikuiRen return; 4083a3316fc6SZhikuiRen } 4084a3316fc6SZhikuiRen 4085a3316fc6SZhikuiRen if (postcode.empty()) 4086a3316fc6SZhikuiRen { 4087ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 4088a3316fc6SZhikuiRen return; 4089a3316fc6SZhikuiRen } 4090a3316fc6SZhikuiRen 4091ac106bf6SEd Tanous if (!fillPostCodeEntry(asyncResp, postcode, bootIndex, codeIndex)) 40926f284d24SJiaqing Zhao { 4093ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 40946f284d24SJiaqing Zhao return; 40956f284d24SJiaqing Zhao } 4096a3316fc6SZhikuiRen }, 409715124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 409815124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 4099a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 4100a3316fc6SZhikuiRen bootIndex); 4101a3316fc6SZhikuiRen } 4102a3316fc6SZhikuiRen 4103ac106bf6SEd Tanous static void 4104ac106bf6SEd Tanous getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4105ac106bf6SEd Tanous const uint16_t bootIndex, const uint16_t bootCount, 4106ac106bf6SEd Tanous const uint64_t entryCount, size_t skip, size_t top) 4107a3316fc6SZhikuiRen { 4108a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 4109ac106bf6SEd Tanous [asyncResp, bootIndex, bootCount, entryCount, skip, 41105e7e2dc5SEd Tanous top](const boost::system::error_code& ec, 41116c9a279eSManojkiran Eda const boost::container::flat_map< 41126c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 41136c9a279eSManojkiran Eda postcode) { 4114a3316fc6SZhikuiRen if (ec) 4115a3316fc6SZhikuiRen { 411662598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error"); 4117ac106bf6SEd Tanous messages::internalError(asyncResp->res); 4118a3316fc6SZhikuiRen return; 4119a3316fc6SZhikuiRen } 4120a3316fc6SZhikuiRen 4121a3316fc6SZhikuiRen uint64_t endCount = entryCount; 4122a3316fc6SZhikuiRen if (!postcode.empty()) 4123a3316fc6SZhikuiRen { 4124a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 41253648c8beSEd Tanous if (skip < endCount && (top + skip) > entryCount) 4126a3316fc6SZhikuiRen { 412789492a15SPatrick Williams uint64_t thisBootSkip = std::max(static_cast<uint64_t>(skip), 412889492a15SPatrick Williams entryCount) - 41293648c8beSEd Tanous entryCount; 4130a3316fc6SZhikuiRen uint64_t thisBootTop = 41313648c8beSEd Tanous std::min(static_cast<uint64_t>(top + skip), endCount) - 41323648c8beSEd Tanous entryCount; 4133a3316fc6SZhikuiRen 4134ac106bf6SEd Tanous fillPostCodeEntry(asyncResp, postcode, bootIndex, 0, 4135ac106bf6SEd Tanous thisBootSkip, thisBootTop); 4136a3316fc6SZhikuiRen } 4137ac106bf6SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = endCount; 4138a3316fc6SZhikuiRen } 4139a3316fc6SZhikuiRen 4140a3316fc6SZhikuiRen // continue to previous bootIndex 4141a3316fc6SZhikuiRen if (bootIndex < bootCount) 4142a3316fc6SZhikuiRen { 4143ac106bf6SEd Tanous getPostCodeForBoot(asyncResp, static_cast<uint16_t>(bootIndex + 1), 4144a3316fc6SZhikuiRen bootCount, endCount, skip, top); 4145a3316fc6SZhikuiRen } 414681584abeSJiaqing Zhao else if (skip + top < endCount) 4147a3316fc6SZhikuiRen { 4148ac106bf6SEd Tanous asyncResp->res.jsonValue["Members@odata.nextLink"] = 41490fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries?$skip=" + 4150a3316fc6SZhikuiRen std::to_string(skip + top); 4151a3316fc6SZhikuiRen } 4152a3316fc6SZhikuiRen }, 415315124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 415415124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 4155a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 4156a3316fc6SZhikuiRen bootIndex); 4157a3316fc6SZhikuiRen } 4158a3316fc6SZhikuiRen 41598d1b46d7Szhanghch05 static void 4160ac106bf6SEd Tanous getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 41613648c8beSEd Tanous size_t skip, size_t top) 4162a3316fc6SZhikuiRen { 4163a3316fc6SZhikuiRen uint64_t entryCount = 0; 41641e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint16_t>( 41651e1e598dSJonathan Doman *crow::connections::systemBus, 41661e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 41671e1e598dSJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 41681e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", 4169ac106bf6SEd Tanous [asyncResp, entryCount, skip, top](const boost::system::error_code& ec, 41701e1e598dSJonathan Doman const uint16_t bootCount) { 4171a3316fc6SZhikuiRen if (ec) 4172a3316fc6SZhikuiRen { 417362598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 4174ac106bf6SEd Tanous messages::internalError(asyncResp->res); 4175a3316fc6SZhikuiRen return; 4176a3316fc6SZhikuiRen } 4177ac106bf6SEd Tanous getPostCodeForBoot(asyncResp, 1, bootCount, entryCount, skip, top); 41781e1e598dSJonathan Doman }); 4179a3316fc6SZhikuiRen } 4180a3316fc6SZhikuiRen 41817e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 4182a3316fc6SZhikuiRen { 41837e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 418422d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/") 4185ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 41867e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 418745ca1b86SEd Tanous [&app](const crow::Request& req, 418822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 418922d268cbSEd Tanous const std::string& systemName) { 4190c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 4191c937d2bfSEd Tanous .canDelegateTop = true, 4192c937d2bfSEd Tanous .canDelegateSkip = true, 4193c937d2bfSEd Tanous }; 4194c937d2bfSEd Tanous query_param::Query delegatedQuery; 4195c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 41963ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 419745ca1b86SEd Tanous { 419845ca1b86SEd Tanous return; 419945ca1b86SEd Tanous } 42007f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 42017f3e84a1SEd Tanous { 42027f3e84a1SEd Tanous // Option currently returns no systems. TBD 42037f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 42047f3e84a1SEd Tanous systemName); 42057f3e84a1SEd Tanous return; 42067f3e84a1SEd Tanous } 420722d268cbSEd Tanous 420822d268cbSEd Tanous if (systemName != "system") 420922d268cbSEd Tanous { 421022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 421122d268cbSEd Tanous systemName); 421222d268cbSEd Tanous return; 421322d268cbSEd Tanous } 4214a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 4215a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 4216a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 4217a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 4218a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 4219a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 4220a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 4221a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 4222a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 42233648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 42245143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 42253648c8beSEd Tanous getCurrentBootNumber(asyncResp, skip, top); 42267e860f15SJohn Edward Broadbent }); 4227a3316fc6SZhikuiRen } 4228a3316fc6SZhikuiRen 4229647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 4230647b3cdcSGeorge Liu { 42310fda0f12SGeorge Liu BMCWEB_ROUTE( 42320fda0f12SGeorge Liu app, 423322d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/") 4234647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 4235647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 423645ca1b86SEd Tanous [&app](const crow::Request& req, 4237647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 423822d268cbSEd Tanous const std::string& systemName, 4239647b3cdcSGeorge Liu const std::string& postCodeID) { 42403ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 424145ca1b86SEd Tanous { 424245ca1b86SEd Tanous return; 424345ca1b86SEd Tanous } 424472e21377SMatt Spinler if (!http_helpers::isContentTypeAllowed( 424599351cd8SEd Tanous req.getHeaderValue("Accept"), 42464a0e1a0cSEd Tanous http_helpers::ContentType::OctetStream, true)) 4247647b3cdcSGeorge Liu { 4248002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 4249647b3cdcSGeorge Liu return; 4250647b3cdcSGeorge Liu } 42517f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 42527f3e84a1SEd Tanous { 42537f3e84a1SEd Tanous // Option currently returns no systems. TBD 42547f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 42557f3e84a1SEd Tanous systemName); 42567f3e84a1SEd Tanous return; 42577f3e84a1SEd Tanous } 425822d268cbSEd Tanous if (systemName != "system") 425922d268cbSEd Tanous { 426022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 426122d268cbSEd Tanous systemName); 426222d268cbSEd Tanous return; 426322d268cbSEd Tanous } 4264647b3cdcSGeorge Liu 4265647b3cdcSGeorge Liu uint64_t currentValue = 0; 4266647b3cdcSGeorge Liu uint16_t index = 0; 4267647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 4268647b3cdcSGeorge Liu { 4269002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID); 4270647b3cdcSGeorge Liu return; 4271647b3cdcSGeorge Liu } 4272647b3cdcSGeorge Liu 4273647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 4274647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 42755e7e2dc5SEd Tanous const boost::system::error_code& ec, 4276002d39b4SEd Tanous const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>& 4277002d39b4SEd Tanous postcodes) { 4278647b3cdcSGeorge Liu if (ec.value() == EBADR) 4279647b3cdcSGeorge Liu { 4280002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4281002d39b4SEd Tanous postCodeID); 4282647b3cdcSGeorge Liu return; 4283647b3cdcSGeorge Liu } 4284647b3cdcSGeorge Liu if (ec) 4285647b3cdcSGeorge Liu { 428662598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 4287647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 4288647b3cdcSGeorge Liu return; 4289647b3cdcSGeorge Liu } 4290647b3cdcSGeorge Liu 4291647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 4292002d39b4SEd Tanous if (value == std::string::npos || postcodes.size() < currentValue) 4293647b3cdcSGeorge Liu { 429462598e31SEd Tanous BMCWEB_LOG_WARNING("Wrong currentValue value"); 4295002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4296002d39b4SEd Tanous postCodeID); 4297647b3cdcSGeorge Liu return; 4298647b3cdcSGeorge Liu } 4299647b3cdcSGeorge Liu 43009eb808c1SEd Tanous const auto& [tID, c] = postcodes[value]; 430146ff87baSEd Tanous if (c.empty()) 4302647b3cdcSGeorge Liu { 430362598e31SEd Tanous BMCWEB_LOG_WARNING("No found post code data"); 4304002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4305002d39b4SEd Tanous postCodeID); 4306647b3cdcSGeorge Liu return; 4307647b3cdcSGeorge Liu } 430846ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 430946ff87baSEd Tanous const char* d = reinterpret_cast<const char*>(c.data()); 431046ff87baSEd Tanous std::string_view strData(d, c.size()); 4311647b3cdcSGeorge Liu 4312d9f6c621SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::content_type, 4313647b3cdcSGeorge Liu "application/octet-stream"); 4314d9f6c621SEd Tanous asyncResp->res.addHeader( 4315d9f6c621SEd Tanous boost::beast::http::field::content_transfer_encoding, "Base64"); 4316*27b0cf90SEd Tanous asyncResp->res.write(crow::utility::base64encode(strData)); 4317647b3cdcSGeorge Liu }, 4318647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 4319647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 4320002d39b4SEd Tanous "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index); 4321647b3cdcSGeorge Liu }); 4322647b3cdcSGeorge Liu } 4323647b3cdcSGeorge Liu 43247e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 4325a3316fc6SZhikuiRen { 43267e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 432722d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/") 4328ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 43297e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 433045ca1b86SEd Tanous [&app](const crow::Request& req, 43317e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 433222d268cbSEd Tanous const std::string& systemName, const std::string& targetID) { 43333ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 433445ca1b86SEd Tanous { 433545ca1b86SEd Tanous return; 433645ca1b86SEd Tanous } 43377f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 43387f3e84a1SEd Tanous { 43397f3e84a1SEd Tanous // Option currently returns no systems. TBD 43407f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 43417f3e84a1SEd Tanous systemName); 43427f3e84a1SEd Tanous return; 43437f3e84a1SEd Tanous } 434422d268cbSEd Tanous if (systemName != "system") 434522d268cbSEd Tanous { 434622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 434722d268cbSEd Tanous systemName); 434822d268cbSEd Tanous return; 434922d268cbSEd Tanous } 435022d268cbSEd Tanous 43516f284d24SJiaqing Zhao getPostCodeForEntry(asyncResp, targetID); 43527e860f15SJohn Edward Broadbent }); 4353a3316fc6SZhikuiRen } 4354a3316fc6SZhikuiRen 43551da66f75SEd Tanous } // namespace redfish 4356