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" 22539d8c6bSEd Tanous #include "generated/enums/log_service.hpp" 23b7028ebfSSpencer Ku #include "gzfile.hpp" 24647b3cdcSGeorge Liu #include "http_utility.hpp" 25b7028ebfSSpencer Ku #include "human_sort.hpp" 263ccb3adbSEd Tanous #include "query.hpp" 274851d45dSJason M. Bills #include "registries.hpp" 284851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 294851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 303ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 3146229577SJames Feist #include "task.hpp" 325b90429aSEd Tanous #include "task_messages.hpp" 333ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 345b90429aSEd Tanous #include "utils/json_utils.hpp" 353ccb3adbSEd Tanous #include "utils/time_utils.hpp" 361da66f75SEd Tanous 3775e8e218SMyung Bae #include <systemd/sd-id128.h> 388e31778eSAsmitha Karunanithi #include <tinyxml2.h> 39400fd1fbSAdriana Kobylak #include <unistd.h> 40e1f26343SJason M. Bills 4107c8c20dSEd Tanous #include <boost/beast/http/verb.hpp> 421da66f75SEd Tanous #include <boost/container/flat_map.hpp> 431ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 44ef4c65b7SEd Tanous #include <boost/url/format.hpp> 45d1bde9e5SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 46d1bde9e5SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 471214b7e7SGunnar Mills 487a1dbc48SGeorge Liu #include <array> 49647b3cdcSGeorge Liu #include <charconv> 50b5f288d2SAbhilash Raju #include <cstddef> 514418c7f0SJames Feist #include <filesystem> 5218f8f608SEd Tanous #include <iterator> 5375710de2SXiaochao Ma #include <optional> 543544d2a7SEd Tanous #include <ranges> 5526702d01SEd Tanous #include <span> 5618f8f608SEd Tanous #include <string> 57cd225da8SJason M. Bills #include <string_view> 58abf2add6SEd Tanous #include <variant> 591da66f75SEd Tanous 601da66f75SEd Tanous namespace redfish 611da66f75SEd Tanous { 621da66f75SEd Tanous 6389492a15SPatrick Williams constexpr const char* crashdumpObject = "com.intel.crashdump"; 6489492a15SPatrick Williams constexpr const char* crashdumpPath = "/com/intel/crashdump"; 6589492a15SPatrick Williams constexpr const char* crashdumpInterface = "com.intel.crashdump"; 6689492a15SPatrick Williams constexpr const char* deleteAllInterface = 675b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 6889492a15SPatrick Williams constexpr const char* crashdumpOnDemandInterface = 69424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 7089492a15SPatrick Williams constexpr const char* crashdumpTelemetryInterface = 716eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 721da66f75SEd Tanous 738e31778eSAsmitha Karunanithi enum class DumpCreationProgress 748e31778eSAsmitha Karunanithi { 758e31778eSAsmitha Karunanithi DUMP_CREATE_SUCCESS, 768e31778eSAsmitha Karunanithi DUMP_CREATE_FAILED, 778e31778eSAsmitha Karunanithi DUMP_CREATE_INPROGRESS 788e31778eSAsmitha Karunanithi }; 798e31778eSAsmitha Karunanithi 80f6150403SJames Feist namespace fs = std::filesystem; 811da66f75SEd Tanous 82cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 83cb92c03bSAndrew Geissler { 84d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 85d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 86d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 87d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 88cb92c03bSAndrew Geissler { 89cb92c03bSAndrew Geissler return "Critical"; 90cb92c03bSAndrew Geissler } 913174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 92d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 93d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 94cb92c03bSAndrew Geissler { 95cb92c03bSAndrew Geissler return "OK"; 96cb92c03bSAndrew Geissler } 973174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 98cb92c03bSAndrew Geissler { 99cb92c03bSAndrew Geissler return "Warning"; 100cb92c03bSAndrew Geissler } 101cb92c03bSAndrew Geissler return ""; 102cb92c03bSAndrew Geissler } 103cb92c03bSAndrew Geissler 1049017faf2SAbhishek Patel inline std::optional<bool> getProviderNotifyAction(const std::string& notify) 1059017faf2SAbhishek Patel { 1069017faf2SAbhishek Patel std::optional<bool> notifyAction; 1079017faf2SAbhishek Patel if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify") 1089017faf2SAbhishek Patel { 1099017faf2SAbhishek Patel notifyAction = true; 1109017faf2SAbhishek Patel } 1119017faf2SAbhishek Patel else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit") 1129017faf2SAbhishek Patel { 1139017faf2SAbhishek Patel notifyAction = false; 1149017faf2SAbhishek Patel } 1159017faf2SAbhishek Patel 1169017faf2SAbhishek Patel return notifyAction; 1179017faf2SAbhishek Patel } 1189017faf2SAbhishek Patel 11918f8f608SEd Tanous inline std::string getDumpPath(std::string_view dumpType) 12018f8f608SEd Tanous { 12118f8f608SEd Tanous std::string dbusDumpPath = "/xyz/openbmc_project/dump/"; 12218f8f608SEd Tanous std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath), 12318f8f608SEd Tanous bmcweb::asciiToLower); 12418f8f608SEd Tanous 12518f8f608SEd Tanous return dbusDumpPath; 12618f8f608SEd Tanous } 12718f8f608SEd Tanous 128055713e4SEd Tanous inline bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 129e85d6b16SJason M. Bills const bool firstEntry = true) 13095820184SJason M. Bills { 131271584abSEd Tanous static time_t prevTs = 0; 13295820184SJason M. Bills static int index = 0; 133e85d6b16SJason M. Bills if (firstEntry) 134e85d6b16SJason M. Bills { 135e85d6b16SJason M. Bills prevTs = 0; 136e85d6b16SJason M. Bills } 137e85d6b16SJason M. Bills 13895820184SJason M. Bills // Get the entry timestamp 139271584abSEd Tanous std::time_t curTs = 0; 14095820184SJason M. Bills std::tm timeStruct = {}; 14195820184SJason M. Bills std::istringstream entryStream(logEntry); 14295820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 14395820184SJason M. Bills { 14495820184SJason M. Bills curTs = std::mktime(&timeStruct); 14595820184SJason M. Bills } 14695820184SJason M. Bills // If the timestamp isn't unique, increment the index 14795820184SJason M. Bills if (curTs == prevTs) 14895820184SJason M. Bills { 14995820184SJason M. Bills index++; 15095820184SJason M. Bills } 15195820184SJason M. Bills else 15295820184SJason M. Bills { 15395820184SJason M. Bills // Otherwise, reset it 15495820184SJason M. Bills index = 0; 15595820184SJason M. Bills } 15695820184SJason M. Bills // Save the timestamp 15795820184SJason M. Bills prevTs = curTs; 15895820184SJason M. Bills 15995820184SJason M. Bills entryID = std::to_string(curTs); 16095820184SJason M. Bills if (index > 0) 16195820184SJason M. Bills { 16295820184SJason M. Bills entryID += "_" + std::to_string(index); 16395820184SJason M. Bills } 16495820184SJason M. Bills return true; 16595820184SJason M. Bills } 16695820184SJason M. Bills 16795820184SJason M. Bills static bool 16895820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 16995820184SJason M. Bills { 17095820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 17195820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 17295820184SJason M. Bills 17395820184SJason M. Bills // Loop through the directory looking for redfish log files 17495820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 17595820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 17695820184SJason M. Bills { 17795820184SJason M. Bills // If we find a redfish log file, save the path 17895820184SJason M. Bills std::string filename = dirEnt.path().filename(); 17911ba3979SEd Tanous if (filename.starts_with(redfishLogFilename)) 18095820184SJason M. Bills { 18195820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 18295820184SJason M. Bills } 18395820184SJason M. Bills } 18495820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 18595820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 18695820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 1873544d2a7SEd Tanous std::ranges::sort(redfishLogFiles); 18895820184SJason M. Bills 18995820184SJason M. Bills return !redfishLogFiles.empty(); 19095820184SJason M. Bills } 19195820184SJason M. Bills 19268dd075aSAsmitha Karunanithi inline log_entry::OriginatorTypes 19368dd075aSAsmitha Karunanithi mapDbusOriginatorTypeToRedfish(const std::string& originatorType) 19468dd075aSAsmitha Karunanithi { 19568dd075aSAsmitha Karunanithi if (originatorType == 19668dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client") 19768dd075aSAsmitha Karunanithi { 19868dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::Client; 19968dd075aSAsmitha Karunanithi } 20068dd075aSAsmitha Karunanithi if (originatorType == 20168dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal") 20268dd075aSAsmitha Karunanithi { 20368dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::Internal; 20468dd075aSAsmitha Karunanithi } 20568dd075aSAsmitha Karunanithi if (originatorType == 20668dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService") 20768dd075aSAsmitha Karunanithi { 20868dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::SupportingService; 20968dd075aSAsmitha Karunanithi } 21068dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::Invalid; 21168dd075aSAsmitha Karunanithi } 21268dd075aSAsmitha Karunanithi 213aefe3786SClaire Weinan inline void parseDumpEntryFromDbusObject( 2142d613eb6SJiaqing Zhao const dbus::utility::ManagedObjectType::value_type& object, 215c6fecdabSClaire Weinan std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs, 21668dd075aSAsmitha Karunanithi std::string& originatorId, log_entry::OriginatorTypes& originatorType, 217aefe3786SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 218aefe3786SClaire Weinan { 219aefe3786SClaire Weinan for (const auto& interfaceMap : object.second) 220aefe3786SClaire Weinan { 221aefe3786SClaire Weinan if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") 222aefe3786SClaire Weinan { 223aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 224aefe3786SClaire Weinan { 225aefe3786SClaire Weinan if (propertyMap.first == "Status") 226aefe3786SClaire Weinan { 227aefe3786SClaire Weinan const auto* status = 228aefe3786SClaire Weinan std::get_if<std::string>(&propertyMap.second); 229aefe3786SClaire Weinan if (status == nullptr) 230aefe3786SClaire Weinan { 231aefe3786SClaire Weinan messages::internalError(asyncResp->res); 232aefe3786SClaire Weinan break; 233aefe3786SClaire Weinan } 234aefe3786SClaire Weinan dumpStatus = *status; 235aefe3786SClaire Weinan } 236aefe3786SClaire Weinan } 237aefe3786SClaire Weinan } 238aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 239aefe3786SClaire Weinan { 240aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 241aefe3786SClaire Weinan { 242aefe3786SClaire Weinan if (propertyMap.first == "Size") 243aefe3786SClaire Weinan { 244aefe3786SClaire Weinan const auto* sizePtr = 245aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 246aefe3786SClaire Weinan if (sizePtr == nullptr) 247aefe3786SClaire Weinan { 248aefe3786SClaire Weinan messages::internalError(asyncResp->res); 249aefe3786SClaire Weinan break; 250aefe3786SClaire Weinan } 251aefe3786SClaire Weinan size = *sizePtr; 252aefe3786SClaire Weinan break; 253aefe3786SClaire Weinan } 254aefe3786SClaire Weinan } 255aefe3786SClaire Weinan } 256aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") 257aefe3786SClaire Weinan { 258aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 259aefe3786SClaire Weinan { 260aefe3786SClaire Weinan if (propertyMap.first == "Elapsed") 261aefe3786SClaire Weinan { 262aefe3786SClaire Weinan const uint64_t* usecsTimeStamp = 263aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 264aefe3786SClaire Weinan if (usecsTimeStamp == nullptr) 265aefe3786SClaire Weinan { 266aefe3786SClaire Weinan messages::internalError(asyncResp->res); 267aefe3786SClaire Weinan break; 268aefe3786SClaire Weinan } 269c6fecdabSClaire Weinan timestampUs = *usecsTimeStamp; 270aefe3786SClaire Weinan break; 271aefe3786SClaire Weinan } 272aefe3786SClaire Weinan } 273aefe3786SClaire Weinan } 27468dd075aSAsmitha Karunanithi else if (interfaceMap.first == 27568dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy") 27668dd075aSAsmitha Karunanithi { 27768dd075aSAsmitha Karunanithi for (const auto& propertyMap : interfaceMap.second) 27868dd075aSAsmitha Karunanithi { 27968dd075aSAsmitha Karunanithi if (propertyMap.first == "OriginatorId") 28068dd075aSAsmitha Karunanithi { 28168dd075aSAsmitha Karunanithi const std::string* id = 28268dd075aSAsmitha Karunanithi std::get_if<std::string>(&propertyMap.second); 28368dd075aSAsmitha Karunanithi if (id == nullptr) 28468dd075aSAsmitha Karunanithi { 28568dd075aSAsmitha Karunanithi messages::internalError(asyncResp->res); 28668dd075aSAsmitha Karunanithi break; 28768dd075aSAsmitha Karunanithi } 28868dd075aSAsmitha Karunanithi originatorId = *id; 28968dd075aSAsmitha Karunanithi } 29068dd075aSAsmitha Karunanithi 29168dd075aSAsmitha Karunanithi if (propertyMap.first == "OriginatorType") 29268dd075aSAsmitha Karunanithi { 29368dd075aSAsmitha Karunanithi const std::string* type = 29468dd075aSAsmitha Karunanithi std::get_if<std::string>(&propertyMap.second); 29568dd075aSAsmitha Karunanithi if (type == nullptr) 29668dd075aSAsmitha Karunanithi { 29768dd075aSAsmitha Karunanithi messages::internalError(asyncResp->res); 29868dd075aSAsmitha Karunanithi break; 29968dd075aSAsmitha Karunanithi } 30068dd075aSAsmitha Karunanithi 30168dd075aSAsmitha Karunanithi originatorType = mapDbusOriginatorTypeToRedfish(*type); 30268dd075aSAsmitha Karunanithi if (originatorType == log_entry::OriginatorTypes::Invalid) 30368dd075aSAsmitha Karunanithi { 30468dd075aSAsmitha Karunanithi messages::internalError(asyncResp->res); 30568dd075aSAsmitha Karunanithi break; 30668dd075aSAsmitha Karunanithi } 30768dd075aSAsmitha Karunanithi } 30868dd075aSAsmitha Karunanithi } 30968dd075aSAsmitha Karunanithi } 310aefe3786SClaire Weinan } 311aefe3786SClaire Weinan } 312aefe3786SClaire Weinan 31321ab404cSNan Zhou static std::string getDumpEntriesPath(const std::string& dumpType) 314fdd26906SClaire Weinan { 315fdd26906SClaire Weinan std::string entriesPath; 316fdd26906SClaire Weinan 317fdd26906SClaire Weinan if (dumpType == "BMC") 318fdd26906SClaire Weinan { 319253f11b8SEd Tanous entriesPath = 320253f11b8SEd Tanous std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/", 321253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 322fdd26906SClaire Weinan } 323fdd26906SClaire Weinan else if (dumpType == "FaultLog") 324fdd26906SClaire Weinan { 325253f11b8SEd Tanous entriesPath = 326253f11b8SEd Tanous std::format("/redfish/v1/Managers/{}/LogServices/FaultLog/Entries/", 327253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 328fdd26906SClaire Weinan } 329fdd26906SClaire Weinan else if (dumpType == "System") 330fdd26906SClaire Weinan { 331253f11b8SEd Tanous entriesPath = 332253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/", 333253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 334fdd26906SClaire Weinan } 335fdd26906SClaire Weinan else 336fdd26906SClaire Weinan { 33762598e31SEd Tanous BMCWEB_LOG_ERROR("getDumpEntriesPath() invalid dump type: {}", 33862598e31SEd Tanous dumpType); 339fdd26906SClaire Weinan } 340fdd26906SClaire Weinan 341fdd26906SClaire Weinan // Returns empty string on error 342fdd26906SClaire Weinan return entriesPath; 343fdd26906SClaire Weinan } 344fdd26906SClaire Weinan 3458d1b46d7Szhanghch05 inline void 3468d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3475cb1dd27SAsmitha Karunanithi const std::string& dumpType) 3485cb1dd27SAsmitha Karunanithi { 349fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 350fdd26906SClaire Weinan if (entriesPath.empty()) 3515cb1dd27SAsmitha Karunanithi { 3525cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 3535cb1dd27SAsmitha Karunanithi return; 3545cb1dd27SAsmitha Karunanithi } 3555cb1dd27SAsmitha Karunanithi 3565eb468daSGeorge Liu sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); 3575eb468daSGeorge Liu dbus::utility::getManagedObjects( 3585eb468daSGeorge Liu "xyz.openbmc_project.Dump.Manager", path, 359fdd26906SClaire Weinan [asyncResp, entriesPath, 3605e7e2dc5SEd Tanous dumpType](const boost::system::error_code& ec, 3615eb468daSGeorge Liu const dbus::utility::ManagedObjectType& objects) { 3625cb1dd27SAsmitha Karunanithi if (ec) 3635cb1dd27SAsmitha Karunanithi { 36462598e31SEd Tanous BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec); 3655cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 3665cb1dd27SAsmitha Karunanithi return; 3675cb1dd27SAsmitha Karunanithi } 3685cb1dd27SAsmitha Karunanithi 369fdd26906SClaire Weinan // Remove ending slash 370fdd26906SClaire Weinan std::string odataIdStr = entriesPath; 371fdd26906SClaire Weinan if (!odataIdStr.empty()) 372fdd26906SClaire Weinan { 373fdd26906SClaire Weinan odataIdStr.pop_back(); 374fdd26906SClaire Weinan } 375fdd26906SClaire Weinan 376fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = 377fdd26906SClaire Weinan "#LogEntryCollection.LogEntryCollection"; 378fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr); 379fdd26906SClaire Weinan asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries"; 38089492a15SPatrick Williams asyncResp->res.jsonValue["Description"] = "Collection of " + dumpType + 38189492a15SPatrick Williams " Dump Entries"; 382fdd26906SClaire Weinan 3833544d2a7SEd Tanous nlohmann::json::array_t entriesArray; 38418f8f608SEd Tanous std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/"; 3855cb1dd27SAsmitha Karunanithi 3865eb468daSGeorge Liu dbus::utility::ManagedObjectType resp(objects); 3873544d2a7SEd Tanous std::ranges::sort(resp, [](const auto& l, const auto& r) { 388002d39b4SEd Tanous return AlphanumLess<std::string>()(l.first.filename(), 389002d39b4SEd Tanous r.first.filename()); 390565dfb6fSClaire Weinan }); 391565dfb6fSClaire Weinan 3925cb1dd27SAsmitha Karunanithi for (auto& object : resp) 3935cb1dd27SAsmitha Karunanithi { 394b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 3955cb1dd27SAsmitha Karunanithi { 3965cb1dd27SAsmitha Karunanithi continue; 3975cb1dd27SAsmitha Karunanithi } 398c6fecdabSClaire Weinan uint64_t timestampUs = 0; 3995cb1dd27SAsmitha Karunanithi uint64_t size = 0; 40035440d18SAsmitha Karunanithi std::string dumpStatus; 40168dd075aSAsmitha Karunanithi std::string originatorId; 40268dd075aSAsmitha Karunanithi log_entry::OriginatorTypes originatorType = 40368dd075aSAsmitha Karunanithi log_entry::OriginatorTypes::Internal; 404433b68b4SJason M. Bills nlohmann::json::object_t thisEntry; 4052dfd18efSEd Tanous 4062dfd18efSEd Tanous std::string entryID = object.first.filename(); 4072dfd18efSEd Tanous if (entryID.empty()) 4085cb1dd27SAsmitha Karunanithi { 4095cb1dd27SAsmitha Karunanithi continue; 4105cb1dd27SAsmitha Karunanithi } 4115cb1dd27SAsmitha Karunanithi 412c6fecdabSClaire Weinan parseDumpEntryFromDbusObject(object, dumpStatus, size, timestampUs, 41368dd075aSAsmitha Karunanithi originatorId, originatorType, 414aefe3786SClaire Weinan asyncResp); 4155cb1dd27SAsmitha Karunanithi 4160fda0f12SGeorge Liu if (dumpStatus != 4170fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 41835440d18SAsmitha Karunanithi !dumpStatus.empty()) 41935440d18SAsmitha Karunanithi { 42035440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 42135440d18SAsmitha Karunanithi continue; 42235440d18SAsmitha Karunanithi } 42335440d18SAsmitha Karunanithi 42468dd075aSAsmitha Karunanithi thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry"; 425fdd26906SClaire Weinan thisEntry["@odata.id"] = entriesPath + entryID; 4265cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 4275cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 4285cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 429bbd80db8SClaire Weinan thisEntry["Created"] = 430bbd80db8SClaire Weinan redfish::time_utils::getDateTimeUintUs(timestampUs); 4315cb1dd27SAsmitha Karunanithi 43268dd075aSAsmitha Karunanithi if (!originatorId.empty()) 43368dd075aSAsmitha Karunanithi { 43468dd075aSAsmitha Karunanithi thisEntry["Originator"] = originatorId; 43568dd075aSAsmitha Karunanithi thisEntry["OriginatorType"] = originatorType; 43668dd075aSAsmitha Karunanithi } 43768dd075aSAsmitha Karunanithi 4385cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 4395cb1dd27SAsmitha Karunanithi { 440d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 44189492a15SPatrick Williams thisEntry["AdditionalDataURI"] = entriesPath + entryID + 44289492a15SPatrick Williams "/attachment"; 443fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 4445cb1dd27SAsmitha Karunanithi } 4455cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 4465cb1dd27SAsmitha Karunanithi { 447d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 448d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 44989492a15SPatrick Williams thisEntry["AdditionalDataURI"] = entriesPath + entryID + 45089492a15SPatrick Williams "/attachment"; 451fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 4525cb1dd27SAsmitha Karunanithi } 453b2ba3072SPatrick Williams entriesArray.emplace_back(std::move(thisEntry)); 4545cb1dd27SAsmitha Karunanithi } 455002d39b4SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size(); 4563544d2a7SEd Tanous asyncResp->res.jsonValue["Members"] = std::move(entriesArray); 4575eb468daSGeorge Liu }); 4585cb1dd27SAsmitha Karunanithi } 4595cb1dd27SAsmitha Karunanithi 4608d1b46d7Szhanghch05 inline void 461c7a6d660SClaire Weinan getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4628d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 4635cb1dd27SAsmitha Karunanithi { 464fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 465fdd26906SClaire Weinan if (entriesPath.empty()) 4665cb1dd27SAsmitha Karunanithi { 4675cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4685cb1dd27SAsmitha Karunanithi return; 4695cb1dd27SAsmitha Karunanithi } 4705cb1dd27SAsmitha Karunanithi 4715eb468daSGeorge Liu sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); 4725eb468daSGeorge Liu dbus::utility::getManagedObjects( 4735eb468daSGeorge Liu "xyz.openbmc_project.Dump.Manager", path, 474fdd26906SClaire Weinan [asyncResp, entryID, dumpType, 4755e7e2dc5SEd Tanous entriesPath](const boost::system::error_code& ec, 47602cad96eSEd Tanous const dbus::utility::ManagedObjectType& resp) { 4775cb1dd27SAsmitha Karunanithi if (ec) 4785cb1dd27SAsmitha Karunanithi { 47962598e31SEd Tanous BMCWEB_LOG_ERROR("DumpEntry resp_handler got error {}", ec); 4805cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4815cb1dd27SAsmitha Karunanithi return; 4825cb1dd27SAsmitha Karunanithi } 4835cb1dd27SAsmitha Karunanithi 484b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 48518f8f608SEd Tanous std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/"; 486b47452b2SAsmitha Karunanithi 4879eb808c1SEd Tanous for (const auto& objectPath : resp) 4885cb1dd27SAsmitha Karunanithi { 489b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 4905cb1dd27SAsmitha Karunanithi { 4915cb1dd27SAsmitha Karunanithi continue; 4925cb1dd27SAsmitha Karunanithi } 4935cb1dd27SAsmitha Karunanithi 4945cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 495c6fecdabSClaire Weinan uint64_t timestampUs = 0; 4965cb1dd27SAsmitha Karunanithi uint64_t size = 0; 49735440d18SAsmitha Karunanithi std::string dumpStatus; 49868dd075aSAsmitha Karunanithi std::string originatorId; 49968dd075aSAsmitha Karunanithi log_entry::OriginatorTypes originatorType = 50068dd075aSAsmitha Karunanithi log_entry::OriginatorTypes::Internal; 5015cb1dd27SAsmitha Karunanithi 502aefe3786SClaire Weinan parseDumpEntryFromDbusObject(objectPath, dumpStatus, size, 50368dd075aSAsmitha Karunanithi timestampUs, originatorId, 50468dd075aSAsmitha Karunanithi originatorType, asyncResp); 5055cb1dd27SAsmitha Karunanithi 5060fda0f12SGeorge Liu if (dumpStatus != 5070fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 50835440d18SAsmitha Karunanithi !dumpStatus.empty()) 50935440d18SAsmitha Karunanithi { 51035440d18SAsmitha Karunanithi // Dump status is not Complete 51135440d18SAsmitha Karunanithi // return not found until status is changed to Completed 512d1bde9e5SKrzysztof Grobelny messages::resourceNotFound(asyncResp->res, dumpType + " dump", 513d1bde9e5SKrzysztof Grobelny entryID); 51435440d18SAsmitha Karunanithi return; 51535440d18SAsmitha Karunanithi } 51635440d18SAsmitha Karunanithi 5175cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 51868dd075aSAsmitha Karunanithi "#LogEntry.v1_11_0.LogEntry"; 519fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID; 5205cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 5215cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 5225cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 523bbd80db8SClaire Weinan asyncResp->res.jsonValue["Created"] = 524bbd80db8SClaire Weinan redfish::time_utils::getDateTimeUintUs(timestampUs); 5255cb1dd27SAsmitha Karunanithi 52668dd075aSAsmitha Karunanithi if (!originatorId.empty()) 52768dd075aSAsmitha Karunanithi { 52868dd075aSAsmitha Karunanithi asyncResp->res.jsonValue["Originator"] = originatorId; 52968dd075aSAsmitha Karunanithi asyncResp->res.jsonValue["OriginatorType"] = originatorType; 53068dd075aSAsmitha Karunanithi } 53168dd075aSAsmitha Karunanithi 5325cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5335cb1dd27SAsmitha Karunanithi { 534d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 535d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 536fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 537fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 5385cb1dd27SAsmitha Karunanithi } 5395cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5405cb1dd27SAsmitha Karunanithi { 541d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 542002d39b4SEd Tanous asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System"; 543d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 544fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 545fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 5465cb1dd27SAsmitha Karunanithi } 5475cb1dd27SAsmitha Karunanithi } 548e05aec50SEd Tanous if (!foundDumpEntry) 549b47452b2SAsmitha Karunanithi { 55062598e31SEd Tanous BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID); 551b90d14f2SMyung Bae messages::resourceNotFound(asyncResp->res, dumpType + " dump", 552b90d14f2SMyung Bae entryID); 553b47452b2SAsmitha Karunanithi return; 554b47452b2SAsmitha Karunanithi } 5555eb468daSGeorge Liu }); 5565cb1dd27SAsmitha Karunanithi } 5575cb1dd27SAsmitha Karunanithi 5588d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5599878256fSStanley Chu const std::string& entryID, 560b47452b2SAsmitha Karunanithi const std::string& dumpType) 5615cb1dd27SAsmitha Karunanithi { 5625a39f77aSPatrick Williams auto respHandler = [asyncResp, 5635a39f77aSPatrick Williams entryID](const boost::system::error_code& ec) { 56462598e31SEd Tanous BMCWEB_LOG_DEBUG("Dump Entry doDelete callback: Done"); 5655cb1dd27SAsmitha Karunanithi if (ec) 5665cb1dd27SAsmitha Karunanithi { 5673de8d8baSGeorge Liu if (ec.value() == EBADR) 5683de8d8baSGeorge Liu { 5693de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 5703de8d8baSGeorge Liu return; 5713de8d8baSGeorge Liu } 57262598e31SEd Tanous BMCWEB_LOG_ERROR( 57362598e31SEd Tanous "Dump (DBus) doDelete respHandler got error {} entryID={}", ec, 57462598e31SEd Tanous entryID); 5755cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5765cb1dd27SAsmitha Karunanithi return; 5775cb1dd27SAsmitha Karunanithi } 5785cb1dd27SAsmitha Karunanithi }; 57918f8f608SEd Tanous 5805cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 5815cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 58218f8f608SEd Tanous std::format("{}/entry/{}", getDumpPath(dumpType), entryID), 5835cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 5845cb1dd27SAsmitha Karunanithi } 585b5f288d2SAbhilash Raju inline bool checkSizeLimit(int fd, crow::Response& res) 586b5f288d2SAbhilash Raju { 587b5f288d2SAbhilash Raju long long int size = lseek(fd, 0, SEEK_END); 588b5f288d2SAbhilash Raju if (size <= 0) 589b5f288d2SAbhilash Raju { 590b5f288d2SAbhilash Raju BMCWEB_LOG_ERROR("Failed to get size of file, lseek() returned {}", 591b5f288d2SAbhilash Raju size); 592b5f288d2SAbhilash Raju messages::internalError(res); 593b5f288d2SAbhilash Raju return false; 594b5f288d2SAbhilash Raju } 5955cb1dd27SAsmitha Karunanithi 596b5f288d2SAbhilash Raju // Arbitrary max size of 20MB to accommodate BMC dumps 597b5f288d2SAbhilash Raju constexpr long long int maxFileSize = 20LL * 1024LL * 1024LL; 598b5f288d2SAbhilash Raju if (size > maxFileSize) 599b5f288d2SAbhilash Raju { 600b5f288d2SAbhilash Raju BMCWEB_LOG_ERROR("File size {} exceeds maximum allowed size of {}", 601b5f288d2SAbhilash Raju size, maxFileSize); 602b5f288d2SAbhilash Raju messages::internalError(res); 603b5f288d2SAbhilash Raju return false; 604b5f288d2SAbhilash Raju } 605b5f288d2SAbhilash Raju off_t rc = lseek(fd, 0, SEEK_SET); 606b5f288d2SAbhilash Raju if (rc < 0) 607b5f288d2SAbhilash Raju { 608b5f288d2SAbhilash Raju BMCWEB_LOG_ERROR("Failed to reset file offset to 0"); 609b5f288d2SAbhilash Raju messages::internalError(res); 610b5f288d2SAbhilash Raju return false; 611b5f288d2SAbhilash Raju } 612b5f288d2SAbhilash Raju return true; 613b5f288d2SAbhilash Raju } 614168d1b1aSCarson Labrado inline void 615168d1b1aSCarson Labrado downloadEntryCallback(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 616168d1b1aSCarson Labrado const std::string& entryID, 617168d1b1aSCarson Labrado const std::string& downloadEntryType, 618168d1b1aSCarson Labrado const boost::system::error_code& ec, 619168d1b1aSCarson Labrado const sdbusplus::message::unix_fd& unixfd) 620168d1b1aSCarson Labrado { 621168d1b1aSCarson Labrado if (ec.value() == EBADR) 622168d1b1aSCarson Labrado { 623168d1b1aSCarson Labrado messages::resourceNotFound(asyncResp->res, "EntryAttachment", entryID); 624168d1b1aSCarson Labrado return; 625168d1b1aSCarson Labrado } 626168d1b1aSCarson Labrado if (ec) 627168d1b1aSCarson Labrado { 628168d1b1aSCarson Labrado BMCWEB_LOG_ERROR("DBUS response error: {}", ec); 629168d1b1aSCarson Labrado messages::internalError(asyncResp->res); 630168d1b1aSCarson Labrado return; 631168d1b1aSCarson Labrado } 632168d1b1aSCarson Labrado 633168d1b1aSCarson Labrado // Make sure we know how to process the retrieved entry attachment 634168d1b1aSCarson Labrado if ((downloadEntryType != "BMC") && (downloadEntryType != "System")) 635168d1b1aSCarson Labrado { 636168d1b1aSCarson Labrado BMCWEB_LOG_ERROR("downloadEntryCallback() invalid entry type: {}", 637168d1b1aSCarson Labrado downloadEntryType); 638168d1b1aSCarson Labrado messages::internalError(asyncResp->res); 639168d1b1aSCarson Labrado } 640168d1b1aSCarson Labrado 641168d1b1aSCarson Labrado int fd = -1; 642168d1b1aSCarson Labrado fd = dup(unixfd); 643168d1b1aSCarson Labrado if (fd < 0) 644168d1b1aSCarson Labrado { 645168d1b1aSCarson Labrado BMCWEB_LOG_ERROR("Failed to open file"); 646168d1b1aSCarson Labrado messages::internalError(asyncResp->res); 647168d1b1aSCarson Labrado return; 648168d1b1aSCarson Labrado } 649b5f288d2SAbhilash Raju if (!checkSizeLimit(fd, asyncResp->res)) 650168d1b1aSCarson Labrado { 651168d1b1aSCarson Labrado close(fd); 652168d1b1aSCarson Labrado return; 653168d1b1aSCarson Labrado } 654168d1b1aSCarson Labrado if (downloadEntryType == "System") 655168d1b1aSCarson Labrado { 656b5f288d2SAbhilash Raju if (!asyncResp->res.openFd(fd, bmcweb::EncodingType::Base64)) 657b5f288d2SAbhilash Raju { 658b5f288d2SAbhilash Raju messages::internalError(asyncResp->res); 659b5f288d2SAbhilash Raju close(fd); 660b5f288d2SAbhilash Raju return; 661b5f288d2SAbhilash Raju } 662168d1b1aSCarson Labrado asyncResp->res.addHeader( 663168d1b1aSCarson Labrado boost::beast::http::field::content_transfer_encoding, "Base64"); 664b5f288d2SAbhilash Raju return; 665168d1b1aSCarson Labrado } 666b5f288d2SAbhilash Raju if (!asyncResp->res.openFd(fd)) 66727b0cf90SEd Tanous { 668b5f288d2SAbhilash Raju messages::internalError(asyncResp->res); 669b5f288d2SAbhilash Raju close(fd); 670b5f288d2SAbhilash Raju return; 67127b0cf90SEd Tanous } 672168d1b1aSCarson Labrado asyncResp->res.addHeader(boost::beast::http::field::content_type, 673168d1b1aSCarson Labrado "application/octet-stream"); 674168d1b1aSCarson Labrado } 675168d1b1aSCarson Labrado 676168d1b1aSCarson Labrado inline void 677168d1b1aSCarson Labrado downloadDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 678168d1b1aSCarson Labrado const std::string& entryID, const std::string& dumpType) 679168d1b1aSCarson Labrado { 680168d1b1aSCarson Labrado if (dumpType != "BMC") 681168d1b1aSCarson Labrado { 682168d1b1aSCarson Labrado BMCWEB_LOG_WARNING("Can't find Dump Entry {}", entryID); 683168d1b1aSCarson Labrado messages::resourceNotFound(asyncResp->res, dumpType + " dump", entryID); 684168d1b1aSCarson Labrado return; 685168d1b1aSCarson Labrado } 686168d1b1aSCarson Labrado 68718f8f608SEd Tanous std::string dumpEntryPath = std::format("{}/entry/{}", 68818f8f608SEd Tanous getDumpPath(dumpType), entryID); 689168d1b1aSCarson Labrado 690168d1b1aSCarson Labrado auto downloadDumpEntryHandler = 691168d1b1aSCarson Labrado [asyncResp, entryID, 692168d1b1aSCarson Labrado dumpType](const boost::system::error_code& ec, 693168d1b1aSCarson Labrado const sdbusplus::message::unix_fd& unixfd) { 694168d1b1aSCarson Labrado downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd); 695168d1b1aSCarson Labrado }; 696168d1b1aSCarson Labrado 697168d1b1aSCarson Labrado crow::connections::systemBus->async_method_call( 698168d1b1aSCarson Labrado std::move(downloadDumpEntryHandler), "xyz.openbmc_project.Dump.Manager", 699168d1b1aSCarson Labrado dumpEntryPath, "xyz.openbmc_project.Dump.Entry", "GetFileHandle"); 700168d1b1aSCarson Labrado } 701168d1b1aSCarson Labrado 702168d1b1aSCarson Labrado inline void 703168d1b1aSCarson Labrado downloadEventLogEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 704168d1b1aSCarson Labrado const std::string& systemName, 705168d1b1aSCarson Labrado const std::string& entryID, 706168d1b1aSCarson Labrado const std::string& dumpType) 707168d1b1aSCarson Labrado { 70825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 709168d1b1aSCarson Labrado { 710168d1b1aSCarson Labrado // Option currently returns no systems. TBD 711168d1b1aSCarson Labrado messages::resourceNotFound(asyncResp->res, "ComputerSystem", 712168d1b1aSCarson Labrado systemName); 713168d1b1aSCarson Labrado return; 714168d1b1aSCarson Labrado } 715253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 716168d1b1aSCarson Labrado { 717168d1b1aSCarson Labrado messages::resourceNotFound(asyncResp->res, "ComputerSystem", 718168d1b1aSCarson Labrado systemName); 719168d1b1aSCarson Labrado return; 720168d1b1aSCarson Labrado } 721168d1b1aSCarson Labrado 722168d1b1aSCarson Labrado std::string entryPath = 723168d1b1aSCarson Labrado sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") / 724168d1b1aSCarson Labrado entryID; 725168d1b1aSCarson Labrado 726168d1b1aSCarson Labrado auto downloadEventLogEntryHandler = 727168d1b1aSCarson Labrado [asyncResp, entryID, 728168d1b1aSCarson Labrado dumpType](const boost::system::error_code& ec, 729168d1b1aSCarson Labrado const sdbusplus::message::unix_fd& unixfd) { 730168d1b1aSCarson Labrado downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd); 731168d1b1aSCarson Labrado }; 732168d1b1aSCarson Labrado 733168d1b1aSCarson Labrado crow::connections::systemBus->async_method_call( 734168d1b1aSCarson Labrado std::move(downloadEventLogEntryHandler), "xyz.openbmc_project.Logging", 735168d1b1aSCarson Labrado entryPath, "xyz.openbmc_project.Logging.Entry", "GetEntry"); 736168d1b1aSCarson Labrado } 737168d1b1aSCarson Labrado 7388e31778eSAsmitha Karunanithi inline DumpCreationProgress 7398e31778eSAsmitha Karunanithi mapDbusStatusToDumpProgress(const std::string& status) 740a43be80fSAsmitha Karunanithi { 7418e31778eSAsmitha Karunanithi if (status == 7428e31778eSAsmitha Karunanithi "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" || 7438e31778eSAsmitha Karunanithi status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted") 7448e31778eSAsmitha Karunanithi { 7458e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_FAILED; 7468e31778eSAsmitha Karunanithi } 7478e31778eSAsmitha Karunanithi if (status == 7488e31778eSAsmitha Karunanithi "xyz.openbmc_project.Common.Progress.OperationStatus.Completed") 7498e31778eSAsmitha Karunanithi { 7508e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_SUCCESS; 7518e31778eSAsmitha Karunanithi } 7528e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_INPROGRESS; 7538e31778eSAsmitha Karunanithi } 7548e31778eSAsmitha Karunanithi 7558e31778eSAsmitha Karunanithi inline DumpCreationProgress 7568e31778eSAsmitha Karunanithi getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values) 7578e31778eSAsmitha Karunanithi { 7588e31778eSAsmitha Karunanithi for (const auto& [key, val] : values) 7598e31778eSAsmitha Karunanithi { 7608e31778eSAsmitha Karunanithi if (key == "Status") 7618e31778eSAsmitha Karunanithi { 7628e31778eSAsmitha Karunanithi const std::string* value = std::get_if<std::string>(&val); 7638e31778eSAsmitha Karunanithi if (value == nullptr) 7648e31778eSAsmitha Karunanithi { 76562598e31SEd Tanous BMCWEB_LOG_ERROR("Status property value is null"); 7668e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_FAILED; 7678e31778eSAsmitha Karunanithi } 7688e31778eSAsmitha Karunanithi return mapDbusStatusToDumpProgress(*value); 7698e31778eSAsmitha Karunanithi } 7708e31778eSAsmitha Karunanithi } 7718e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_INPROGRESS; 7728e31778eSAsmitha Karunanithi } 7738e31778eSAsmitha Karunanithi 7748e31778eSAsmitha Karunanithi inline std::string getDumpEntryPath(const std::string& dumpPath) 7758e31778eSAsmitha Karunanithi { 7768e31778eSAsmitha Karunanithi if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry") 7778e31778eSAsmitha Karunanithi { 778253f11b8SEd Tanous return std::format("/redfish/v1/Managers/{}/LogServices/Dump/Entries/", 7799f565090SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 7808e31778eSAsmitha Karunanithi } 7818e31778eSAsmitha Karunanithi if (dumpPath == "/xyz/openbmc_project/dump/system/entry") 7828e31778eSAsmitha Karunanithi { 783253f11b8SEd Tanous return std::format("/redfish/v1/Systems/{}/LogServices/Dump/Entries/", 784253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 7858e31778eSAsmitha Karunanithi } 7868e31778eSAsmitha Karunanithi return ""; 7878e31778eSAsmitha Karunanithi } 7888e31778eSAsmitha Karunanithi 7898e31778eSAsmitha Karunanithi inline void createDumpTaskCallback( 7908e31778eSAsmitha Karunanithi task::Payload&& payload, 7918e31778eSAsmitha Karunanithi const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7928e31778eSAsmitha Karunanithi const sdbusplus::message::object_path& createdObjPath) 7938e31778eSAsmitha Karunanithi { 7948e31778eSAsmitha Karunanithi const std::string dumpPath = createdObjPath.parent_path().str; 7958e31778eSAsmitha Karunanithi const std::string dumpId = createdObjPath.filename(); 7968e31778eSAsmitha Karunanithi 7978e31778eSAsmitha Karunanithi std::string dumpEntryPath = getDumpEntryPath(dumpPath); 7988e31778eSAsmitha Karunanithi 7998e31778eSAsmitha Karunanithi if (dumpEntryPath.empty()) 8008e31778eSAsmitha Karunanithi { 80162598e31SEd Tanous BMCWEB_LOG_ERROR("Invalid dump type received"); 8028e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 8038e31778eSAsmitha Karunanithi return; 8048e31778eSAsmitha Karunanithi } 8058e31778eSAsmitha Karunanithi 8068e31778eSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 8078cb2c024SEd Tanous [asyncResp, payload = std::move(payload), createdObjPath, 8088e31778eSAsmitha Karunanithi dumpEntryPath{std::move(dumpEntryPath)}, 8095e7e2dc5SEd Tanous dumpId](const boost::system::error_code& ec, 8108e31778eSAsmitha Karunanithi const std::string& introspectXml) { 8118e31778eSAsmitha Karunanithi if (ec) 8128e31778eSAsmitha Karunanithi { 81362598e31SEd Tanous BMCWEB_LOG_ERROR("Introspect call failed with error: {}", 81462598e31SEd Tanous ec.message()); 8158e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 8168e31778eSAsmitha Karunanithi return; 8178e31778eSAsmitha Karunanithi } 8188e31778eSAsmitha Karunanithi 8198e31778eSAsmitha Karunanithi // Check if the created dump object has implemented Progress 8208e31778eSAsmitha Karunanithi // interface to track dump completion. If yes, fetch the "Status" 8218e31778eSAsmitha Karunanithi // property of the interface, modify the task state accordingly. 8228e31778eSAsmitha Karunanithi // Else, return task completed. 8238e31778eSAsmitha Karunanithi tinyxml2::XMLDocument doc; 8248e31778eSAsmitha Karunanithi 8258e31778eSAsmitha Karunanithi doc.Parse(introspectXml.data(), introspectXml.size()); 8268e31778eSAsmitha Karunanithi tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node"); 8278e31778eSAsmitha Karunanithi if (pRoot == nullptr) 8288e31778eSAsmitha Karunanithi { 82962598e31SEd Tanous BMCWEB_LOG_ERROR("XML document failed to parse"); 8308e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 8318e31778eSAsmitha Karunanithi return; 8328e31778eSAsmitha Karunanithi } 8338e31778eSAsmitha Karunanithi tinyxml2::XMLElement* interfaceNode = 8348e31778eSAsmitha Karunanithi pRoot->FirstChildElement("interface"); 8358e31778eSAsmitha Karunanithi 8368e31778eSAsmitha Karunanithi bool isProgressIntfPresent = false; 8378e31778eSAsmitha Karunanithi while (interfaceNode != nullptr) 8388e31778eSAsmitha Karunanithi { 8398e31778eSAsmitha Karunanithi const char* thisInterfaceName = interfaceNode->Attribute("name"); 8408e31778eSAsmitha Karunanithi if (thisInterfaceName != nullptr) 8418e31778eSAsmitha Karunanithi { 8428e31778eSAsmitha Karunanithi if (thisInterfaceName == 8438e31778eSAsmitha Karunanithi std::string_view("xyz.openbmc_project.Common.Progress")) 8448e31778eSAsmitha Karunanithi { 8458e31778eSAsmitha Karunanithi interfaceNode = 8468e31778eSAsmitha Karunanithi interfaceNode->NextSiblingElement("interface"); 8478e31778eSAsmitha Karunanithi continue; 8488e31778eSAsmitha Karunanithi } 8498e31778eSAsmitha Karunanithi isProgressIntfPresent = true; 8508e31778eSAsmitha Karunanithi break; 8518e31778eSAsmitha Karunanithi } 8528e31778eSAsmitha Karunanithi interfaceNode = interfaceNode->NextSiblingElement("interface"); 8538e31778eSAsmitha Karunanithi } 8548e31778eSAsmitha Karunanithi 855a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 8568e31778eSAsmitha Karunanithi [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent]( 8578b24275dSEd Tanous const boost::system::error_code& ec2, sdbusplus::message_t& msg, 858a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 8598b24275dSEd Tanous if (ec2) 860cb13a392SEd Tanous { 86162598e31SEd Tanous BMCWEB_LOG_ERROR("{}: Error in creating dump", 86262598e31SEd Tanous createdObjPath.str); 8638e31778eSAsmitha Karunanithi taskData->messages.emplace_back(messages::internalError()); 8646145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 8656145ed6fSAsmitha Karunanithi return task::completed; 866cb13a392SEd Tanous } 867b9d36b47SEd Tanous 8688e31778eSAsmitha Karunanithi if (isProgressIntfPresent) 869a43be80fSAsmitha Karunanithi { 8708e31778eSAsmitha Karunanithi dbus::utility::DBusPropertiesMap values; 8718e31778eSAsmitha Karunanithi std::string prop; 8728e31778eSAsmitha Karunanithi msg.read(prop, values); 8738e31778eSAsmitha Karunanithi 8748e31778eSAsmitha Karunanithi DumpCreationProgress dumpStatus = 8758e31778eSAsmitha Karunanithi getDumpCompletionStatus(values); 8768e31778eSAsmitha Karunanithi if (dumpStatus == DumpCreationProgress::DUMP_CREATE_FAILED) 8778e31778eSAsmitha Karunanithi { 87862598e31SEd Tanous BMCWEB_LOG_ERROR("{}: Error in creating dump", 87962598e31SEd Tanous createdObjPath.str); 8808e31778eSAsmitha Karunanithi taskData->state = "Cancelled"; 8818e31778eSAsmitha Karunanithi return task::completed; 8828e31778eSAsmitha Karunanithi } 8838e31778eSAsmitha Karunanithi 8848e31778eSAsmitha Karunanithi if (dumpStatus == DumpCreationProgress::DUMP_CREATE_INPROGRESS) 8858e31778eSAsmitha Karunanithi { 88662598e31SEd Tanous BMCWEB_LOG_DEBUG("{}: Dump creation task is in progress", 88762598e31SEd Tanous createdObjPath.str); 8888e31778eSAsmitha Karunanithi return !task::completed; 8898e31778eSAsmitha Karunanithi } 8908e31778eSAsmitha Karunanithi } 8918e31778eSAsmitha Karunanithi 892a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 893a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 894a43be80fSAsmitha Karunanithi 895c51a58eeSEd Tanous boost::urls::url url = boost::urls::format( 896253f11b8SEd Tanous "/redfish/v1/Managers/{}/LogServices/Dump/Entries/{}", 897253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME, dumpId); 898c51a58eeSEd Tanous 899c51a58eeSEd Tanous std::string headerLoc = "Location: "; 900c51a58eeSEd Tanous headerLoc += url.buffer(); 901c51a58eeSEd Tanous 902002d39b4SEd Tanous taskData->payload->httpHeaders.emplace_back(std::move(headerLoc)); 903a43be80fSAsmitha Karunanithi 90462598e31SEd Tanous BMCWEB_LOG_DEBUG("{}: Dump creation task completed", 90562598e31SEd Tanous createdObjPath.str); 906a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 907b47452b2SAsmitha Karunanithi return task::completed; 908a43be80fSAsmitha Karunanithi }, 9098e31778eSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus.Properties'," 9108e31778eSAsmitha Karunanithi "member='PropertiesChanged',path='" + 9118e31778eSAsmitha Karunanithi createdObjPath.str + "'"); 912a43be80fSAsmitha Karunanithi 9138e31778eSAsmitha Karunanithi // The task timer is set to max time limit within which the 9148e31778eSAsmitha Karunanithi // requested dump will be collected. 9158e31778eSAsmitha Karunanithi task->startTimer(std::chrono::minutes(6)); 916a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 9178e31778eSAsmitha Karunanithi task->payload.emplace(payload); 9188e31778eSAsmitha Karunanithi }, 9198e31778eSAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", createdObjPath, 9208e31778eSAsmitha Karunanithi "org.freedesktop.DBus.Introspectable", "Introspect"); 921a43be80fSAsmitha Karunanithi } 922a43be80fSAsmitha Karunanithi 9238d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 9248d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 925a43be80fSAsmitha Karunanithi { 926fdd26906SClaire Weinan std::string dumpPath = getDumpEntriesPath(dumpType); 927fdd26906SClaire Weinan if (dumpPath.empty()) 928a43be80fSAsmitha Karunanithi { 929a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 930a43be80fSAsmitha Karunanithi return; 931a43be80fSAsmitha Karunanithi } 932a43be80fSAsmitha Karunanithi 933a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 934a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 935a43be80fSAsmitha Karunanithi 93615ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 937a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 938a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 939a43be80fSAsmitha Karunanithi { 940a43be80fSAsmitha Karunanithi return; 941a43be80fSAsmitha Karunanithi } 942a43be80fSAsmitha Karunanithi 943a43be80fSAsmitha Karunanithi if (dumpType == "System") 944a43be80fSAsmitha Karunanithi { 945a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 946a43be80fSAsmitha Karunanithi { 94762598e31SEd Tanous BMCWEB_LOG_ERROR( 94862598e31SEd Tanous "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"); 949a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 950a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 951a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 952a43be80fSAsmitha Karunanithi return; 953a43be80fSAsmitha Karunanithi } 9543174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 955a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 956a43be80fSAsmitha Karunanithi { 95762598e31SEd Tanous BMCWEB_LOG_ERROR("Wrong parameter values passed"); 958ace85d60SEd Tanous messages::internalError(asyncResp->res); 959a43be80fSAsmitha Karunanithi return; 960a43be80fSAsmitha Karunanithi } 961253f11b8SEd Tanous dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump/", 962253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 963a43be80fSAsmitha Karunanithi } 964a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 965a43be80fSAsmitha Karunanithi { 966a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 967a43be80fSAsmitha Karunanithi { 96862598e31SEd Tanous BMCWEB_LOG_ERROR( 96962598e31SEd Tanous "CreateDump action parameter 'DiagnosticDataType' not found!"); 970a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 971a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 972a43be80fSAsmitha Karunanithi return; 973a43be80fSAsmitha Karunanithi } 9743174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 975a43be80fSAsmitha Karunanithi { 97662598e31SEd Tanous BMCWEB_LOG_ERROR( 97762598e31SEd Tanous "Wrong parameter value passed for 'DiagnosticDataType'"); 978ace85d60SEd Tanous messages::internalError(asyncResp->res); 979a43be80fSAsmitha Karunanithi return; 980a43be80fSAsmitha Karunanithi } 981253f11b8SEd Tanous dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump/", 982253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 9835907571dSAsmitha Karunanithi } 9845907571dSAsmitha Karunanithi else 9855907571dSAsmitha Karunanithi { 98662598e31SEd Tanous BMCWEB_LOG_ERROR("CreateDump failed. Unknown dump type"); 9875907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 9885907571dSAsmitha Karunanithi return; 989a43be80fSAsmitha Karunanithi } 990a43be80fSAsmitha Karunanithi 9918e31778eSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>> 9928e31778eSAsmitha Karunanithi createDumpParamVec; 9938e31778eSAsmitha Karunanithi 994f574a8e1SCarson Labrado if (req.session != nullptr) 995f574a8e1SCarson Labrado { 99668dd075aSAsmitha Karunanithi createDumpParamVec.emplace_back( 99768dd075aSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId", 99868dd075aSAsmitha Karunanithi req.session->clientIp); 99968dd075aSAsmitha Karunanithi createDumpParamVec.emplace_back( 100068dd075aSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType", 100168dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client"); 1002f574a8e1SCarson Labrado } 100368dd075aSAsmitha Karunanithi 1004a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 10055e7e2dc5SEd Tanous [asyncResp, payload(task::Payload(req)), 10065e7e2dc5SEd Tanous dumpPath](const boost::system::error_code& ec, 10075e7e2dc5SEd Tanous const sdbusplus::message_t& msg, 10088e31778eSAsmitha Karunanithi const sdbusplus::message::object_path& objPath) mutable { 1009a43be80fSAsmitha Karunanithi if (ec) 1010a43be80fSAsmitha Karunanithi { 101162598e31SEd Tanous BMCWEB_LOG_ERROR("CreateDump resp_handler got error {}", ec); 10125907571dSAsmitha Karunanithi const sd_bus_error* dbusError = msg.get_error(); 10135907571dSAsmitha Karunanithi if (dbusError == nullptr) 10145907571dSAsmitha Karunanithi { 10155907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 10165907571dSAsmitha Karunanithi return; 10175907571dSAsmitha Karunanithi } 10185907571dSAsmitha Karunanithi 101962598e31SEd Tanous BMCWEB_LOG_ERROR("CreateDump DBus error: {} and error msg: {}", 102062598e31SEd Tanous dbusError->name, dbusError->message); 10215907571dSAsmitha Karunanithi if (std::string_view( 10225907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.NotAllowed") == 10235907571dSAsmitha Karunanithi dbusError->name) 10245907571dSAsmitha Karunanithi { 10255907571dSAsmitha Karunanithi messages::resourceInStandby(asyncResp->res); 10265907571dSAsmitha Karunanithi return; 10275907571dSAsmitha Karunanithi } 10285907571dSAsmitha Karunanithi if (std::string_view( 10295907571dSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.Error.Disabled") == 10305907571dSAsmitha Karunanithi dbusError->name) 10315907571dSAsmitha Karunanithi { 10325907571dSAsmitha Karunanithi messages::serviceDisabled(asyncResp->res, dumpPath); 10335907571dSAsmitha Karunanithi return; 10345907571dSAsmitha Karunanithi } 10355907571dSAsmitha Karunanithi if (std::string_view( 10365907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.Unavailable") == 10375907571dSAsmitha Karunanithi dbusError->name) 10385907571dSAsmitha Karunanithi { 10395907571dSAsmitha Karunanithi messages::resourceInUse(asyncResp->res); 10405907571dSAsmitha Karunanithi return; 10415907571dSAsmitha Karunanithi } 10425907571dSAsmitha Karunanithi // Other Dbus errors such as: 10435907571dSAsmitha Karunanithi // xyz.openbmc_project.Common.Error.InvalidArgument & 10445907571dSAsmitha Karunanithi // org.freedesktop.DBus.Error.InvalidArgs are all related to 10455907571dSAsmitha Karunanithi // the dbus call that is made here in the bmcweb 10465907571dSAsmitha Karunanithi // implementation and has nothing to do with the client's 10475907571dSAsmitha Karunanithi // input in the request. Hence, returning internal error 10485907571dSAsmitha Karunanithi // back to the client. 1049a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 1050a43be80fSAsmitha Karunanithi return; 1051a43be80fSAsmitha Karunanithi } 105262598e31SEd Tanous BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str); 10538e31778eSAsmitha Karunanithi createDumpTaskCallback(std::move(payload), asyncResp, objPath); 1054a43be80fSAsmitha Karunanithi }, 105518f8f608SEd Tanous "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType), 10568e31778eSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec); 1057a43be80fSAsmitha Karunanithi } 1058a43be80fSAsmitha Karunanithi 10598d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 10608d1b46d7Szhanghch05 const std::string& dumpType) 106180319af1SAsmitha Karunanithi { 10620d946211SClaire Weinan crow::connections::systemBus->async_method_call( 10630d946211SClaire Weinan [asyncResp](const boost::system::error_code& ec) { 106480319af1SAsmitha Karunanithi if (ec) 106580319af1SAsmitha Karunanithi { 106662598e31SEd Tanous BMCWEB_LOG_ERROR("clearDump resp_handler got error {}", ec); 106780319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 106880319af1SAsmitha Karunanithi return; 106980319af1SAsmitha Karunanithi } 10700d946211SClaire Weinan }, 107118f8f608SEd Tanous "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType), 10720d946211SClaire Weinan "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 107380319af1SAsmitha Karunanithi } 107480319af1SAsmitha Karunanithi 1075df254f2cSEd Tanous inline void 1076b9d36b47SEd Tanous parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params, 1077b9d36b47SEd Tanous std::string& filename, std::string& timestamp, 1078b9d36b47SEd Tanous std::string& logfile) 1079043a0536SJohnathan Mantey { 1080d1bde9e5SKrzysztof Grobelny const std::string* filenamePtr = nullptr; 1081d1bde9e5SKrzysztof Grobelny const std::string* timestampPtr = nullptr; 1082d1bde9e5SKrzysztof Grobelny const std::string* logfilePtr = nullptr; 1083d1bde9e5SKrzysztof Grobelny 1084d1bde9e5SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1085d1bde9e5SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr, 1086d1bde9e5SKrzysztof Grobelny "Filename", filenamePtr, "Log", logfilePtr); 1087d1bde9e5SKrzysztof Grobelny 1088d1bde9e5SKrzysztof Grobelny if (!success) 1089043a0536SJohnathan Mantey { 1090d1bde9e5SKrzysztof Grobelny return; 1091043a0536SJohnathan Mantey } 1092d1bde9e5SKrzysztof Grobelny 1093d1bde9e5SKrzysztof Grobelny if (filenamePtr != nullptr) 1094043a0536SJohnathan Mantey { 1095d1bde9e5SKrzysztof Grobelny filename = *filenamePtr; 1096d1bde9e5SKrzysztof Grobelny } 1097d1bde9e5SKrzysztof Grobelny 1098d1bde9e5SKrzysztof Grobelny if (timestampPtr != nullptr) 1099043a0536SJohnathan Mantey { 1100d1bde9e5SKrzysztof Grobelny timestamp = *timestampPtr; 1101043a0536SJohnathan Mantey } 1102d1bde9e5SKrzysztof Grobelny 1103d1bde9e5SKrzysztof Grobelny if (logfilePtr != nullptr) 1104043a0536SJohnathan Mantey { 1105d1bde9e5SKrzysztof Grobelny logfile = *logfilePtr; 1106043a0536SJohnathan Mantey } 1107043a0536SJohnathan Mantey } 1108043a0536SJohnathan Mantey 11097e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 11101da66f75SEd Tanous { 1111c4bf6374SJason M. Bills /** 1112c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 1113c4bf6374SJason M. Bills */ 111422d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/") 1115ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 1116002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1117002d39b4SEd Tanous [&app](const crow::Request& req, 111822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 111922d268cbSEd Tanous const std::string& systemName) { 11203ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1121c4bf6374SJason M. Bills { 112245ca1b86SEd Tanous return; 112345ca1b86SEd Tanous } 112425b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 11257f3e84a1SEd Tanous { 11267f3e84a1SEd Tanous // Option currently returns no systems. TBD 11277f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 11287f3e84a1SEd Tanous systemName); 11297f3e84a1SEd Tanous return; 11307f3e84a1SEd Tanous } 1131253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 113222d268cbSEd Tanous { 113322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 113422d268cbSEd Tanous systemName); 113522d268cbSEd Tanous return; 113622d268cbSEd Tanous } 113722d268cbSEd Tanous 11387e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 11397e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1140c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1141c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 1142c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1143253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices", 1144253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 114545ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 1146c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1147c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 1148002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 1149c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 11501476687dSEd Tanous nlohmann::json::object_t eventLog; 11511476687dSEd Tanous eventLog["@odata.id"] = 1152253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/EventLog", 1153253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 1154b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(eventLog)); 115525b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_DUMP_LOG) 115625b54dbaSEd Tanous { 11571476687dSEd Tanous nlohmann::json::object_t dumpLog; 115825b54dbaSEd Tanous dumpLog["@odata.id"] = 1159253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/Dump", 1160253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 1161b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(dumpLog)); 116225b54dbaSEd Tanous } 1163c9bb6861Sraviteja-b 11645ffd11f2SGunnar Mills if constexpr (BMCWEB_REDFISH_CPU_LOG) 116525b54dbaSEd Tanous { 11661476687dSEd Tanous nlohmann::json::object_t crashdump; 11671476687dSEd Tanous crashdump["@odata.id"] = 1168253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", 1169253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 1170b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(crashdump)); 117125b54dbaSEd Tanous } 1172b7028ebfSSpencer Ku 117325b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_HOST_LOGGER) 117425b54dbaSEd Tanous { 11751476687dSEd Tanous nlohmann::json::object_t hostlogger; 11761476687dSEd Tanous hostlogger["@odata.id"] = 1177253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/HostLogger", 1178253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 1179b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(hostlogger)); 118025b54dbaSEd Tanous } 1181c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1182c4bf6374SJason M. Bills logServiceArray.size(); 1183a3316fc6SZhikuiRen 11847a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 11857a1dbc48SGeorge Liu "xyz.openbmc_project.State.Boot.PostCode"}; 11867a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 11877a1dbc48SGeorge Liu "/", 0, interfaces, 11887a1dbc48SGeorge Liu [asyncResp](const boost::system::error_code& ec, 1189b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& 1190b9d36b47SEd Tanous subtreePath) { 1191a3316fc6SZhikuiRen if (ec) 1192a3316fc6SZhikuiRen { 119362598e31SEd Tanous BMCWEB_LOG_ERROR("{}", ec); 1194a3316fc6SZhikuiRen return; 1195a3316fc6SZhikuiRen } 1196a3316fc6SZhikuiRen 119755f79e6fSEd Tanous for (const auto& pathStr : subtreePath) 1198a3316fc6SZhikuiRen { 1199a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 1200a3316fc6SZhikuiRen { 120123a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 1202a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 1203613dabeaSEd Tanous nlohmann::json::object_t member; 1204253f11b8SEd Tanous member["@odata.id"] = std::format( 1205253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/PostCodes", 1206253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 1207613dabeaSEd Tanous 1208b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 1209613dabeaSEd Tanous 121045ca1b86SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 121123a21a1cSEd Tanous logServiceArrayLocal.size(); 1212a3316fc6SZhikuiRen return; 1213a3316fc6SZhikuiRen } 1214a3316fc6SZhikuiRen } 12157a1dbc48SGeorge Liu }); 12167e860f15SJohn Edward Broadbent }); 1217c4bf6374SJason M. Bills } 1218c4bf6374SJason M. Bills 12197e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 1220c4bf6374SJason M. Bills { 122122d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/") 1222ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 1223002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1224002d39b4SEd Tanous [&app](const crow::Request& req, 122522d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 122622d268cbSEd Tanous const std::string& systemName) { 12273ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 122845ca1b86SEd Tanous { 122945ca1b86SEd Tanous return; 123045ca1b86SEd Tanous } 1231253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 123222d268cbSEd Tanous { 123322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 123422d268cbSEd Tanous systemName); 123522d268cbSEd Tanous return; 123622d268cbSEd Tanous } 1237c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1238253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/EventLog", 1239253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 1240c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1241b25644a1SJanet Adkins "#LogService.v1_2_0.LogService"; 1242c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 1243002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 1244c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1245539d8c6bSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = 1246539d8c6bSEd Tanous log_service::OverWritePolicy::WrapsWhenFull; 12477c8c4058STejas Patil 12487c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 12492b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 12507c8c4058STejas Patil 12517c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 12527c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 12537c8c4058STejas Patil redfishDateTimeOffset.second; 12547c8c4058STejas Patil 12551476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 1256253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries", 1257253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 125820fa6a2cSEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] 1259e7d6c8b2SGunnar Mills 126020fa6a2cSEd Tanous = std::format( 1261253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog", 126220fa6a2cSEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 12637e860f15SJohn Edward Broadbent }); 1264489640c6SJason M. Bills } 1265489640c6SJason M. Bills 1266599b9af3SAlexander Hansen inline void handleSystemsLogServicesEventLogActionsClearPost( 1267599b9af3SAlexander Hansen App& app, const crow::Request& req, 126822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1269599b9af3SAlexander Hansen const std::string& systemName) 1270599b9af3SAlexander Hansen { 12713ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 127245ca1b86SEd Tanous { 127345ca1b86SEd Tanous return; 127445ca1b86SEd Tanous } 1275253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 127622d268cbSEd Tanous { 127722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 127822d268cbSEd Tanous systemName); 127922d268cbSEd Tanous return; 128022d268cbSEd Tanous } 1281599b9af3SAlexander Hansen 1282489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1283489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1284489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1285489640c6SJason M. Bills { 1286489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1287489640c6SJason M. Bills { 1288489640c6SJason M. Bills std::error_code ec; 1289489640c6SJason M. Bills std::filesystem::remove(file, ec); 1290489640c6SJason M. Bills } 1291489640c6SJason M. Bills } 1292489640c6SJason M. Bills 1293489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1294489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 12955e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 1296489640c6SJason M. Bills if (ec) 1297489640c6SJason M. Bills { 129862598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec); 1299489640c6SJason M. Bills messages::internalError(asyncResp->res); 1300489640c6SJason M. Bills return; 1301489640c6SJason M. Bills } 1302489640c6SJason M. Bills 1303489640c6SJason M. Bills messages::success(asyncResp->res); 1304489640c6SJason M. Bills }, 1305489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1306002d39b4SEd Tanous "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1307002d39b4SEd Tanous "replace"); 1308599b9af3SAlexander Hansen } 1309599b9af3SAlexander Hansen 1310599b9af3SAlexander Hansen inline void requestRoutesJournalEventLogClear(App& app) 1311599b9af3SAlexander Hansen { 1312599b9af3SAlexander Hansen BMCWEB_ROUTE( 1313599b9af3SAlexander Hansen app, 1314599b9af3SAlexander Hansen "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 1315599b9af3SAlexander Hansen .privileges({{"ConfigureComponents"}}) 1316599b9af3SAlexander Hansen .methods(boost::beast::http::verb::post)(std::bind_front( 1317599b9af3SAlexander Hansen handleSystemsLogServicesEventLogActionsClearPost, std::ref(app))); 1318c4bf6374SJason M. Bills } 1319c4bf6374SJason M. Bills 1320ac992cdeSJason M. Bills enum class LogParseError 1321ac992cdeSJason M. Bills { 1322ac992cdeSJason M. Bills success, 1323ac992cdeSJason M. Bills parseFailed, 1324ac992cdeSJason M. Bills messageIdNotInRegistry, 1325ac992cdeSJason M. Bills }; 1326ac992cdeSJason M. Bills 1327ac992cdeSJason M. Bills static LogParseError 1328ac992cdeSJason M. Bills fillEventLogEntryJson(const std::string& logEntryID, 1329b5a76932SEd Tanous const std::string& logEntry, 1330de703c5dSJason M. Bills nlohmann::json::object_t& logEntryJson) 1331c4bf6374SJason M. Bills { 133295820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1333cd225da8SJason M. Bills // First get the Timestamp 1334f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1335cd225da8SJason M. Bills if (space == std::string::npos) 133695820184SJason M. Bills { 1337ac992cdeSJason M. Bills return LogParseError::parseFailed; 133895820184SJason M. Bills } 1339cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1340cd225da8SJason M. Bills // Then get the log contents 1341f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1342cd225da8SJason M. Bills if (entryStart == std::string::npos) 1343cd225da8SJason M. Bills { 1344ac992cdeSJason M. Bills return LogParseError::parseFailed; 1345cd225da8SJason M. Bills } 1346cd225da8SJason M. Bills std::string_view entry(logEntry); 1347cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1348cd225da8SJason M. Bills // Use split to separate the entry into its fields 1349cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 135050ebd4afSEd Tanous bmcweb::split(logEntryFields, entry, ','); 1351cd225da8SJason M. Bills // We need at least a MessageId to be valid 13521e6deaf6SEd Tanous auto logEntryIter = logEntryFields.begin(); 13531e6deaf6SEd Tanous if (logEntryIter == logEntryFields.end()) 1354cd225da8SJason M. Bills { 1355ac992cdeSJason M. Bills return LogParseError::parseFailed; 1356cd225da8SJason M. Bills } 13571e6deaf6SEd Tanous std::string& messageID = *logEntryIter; 13584851d45dSJason M. Bills // Get the Message from the MessageRegistry 1359fffb8c1fSEd Tanous const registries::Message* message = registries::getMessage(messageID); 1360c4bf6374SJason M. Bills 13611e6deaf6SEd Tanous logEntryIter++; 136254417b02SSui Chen if (message == nullptr) 1363c4bf6374SJason M. Bills { 136462598e31SEd Tanous BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry); 1365ac992cdeSJason M. Bills return LogParseError::messageIdNotInRegistry; 1366c4bf6374SJason M. Bills } 1367c4bf6374SJason M. Bills 13681e6deaf6SEd Tanous std::vector<std::string_view> messageArgs(logEntryIter, 13691e6deaf6SEd Tanous logEntryFields.end()); 1370c05bba45SEd Tanous messageArgs.resize(message->numberOfArgs); 1371c05bba45SEd Tanous 13721e6deaf6SEd Tanous std::string msg = redfish::registries::fillMessageArgs(messageArgs, 13731e6deaf6SEd Tanous message->message); 13741e6deaf6SEd Tanous if (msg.empty()) 137515a86ff6SJason M. Bills { 13761e6deaf6SEd Tanous return LogParseError::parseFailed; 137715a86ff6SJason M. Bills } 13784851d45dSJason M. Bills 137995820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 138095820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 138195820184SJason M. Bills // between the '.' and the '+', so just remove them. 1382f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1383f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 138495820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1385c4bf6374SJason M. Bills { 138695820184SJason M. Bills timestamp.erase(dot, plus - dot); 1387c4bf6374SJason M. Bills } 1388c4bf6374SJason M. Bills 1389c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 13909c11a172SVijay Lobo logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 1391ef4c65b7SEd Tanous logEntryJson["@odata.id"] = boost::urls::format( 1392253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}", 1393253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID); 139484afc48bSJason M. Bills logEntryJson["Name"] = "System Event Log Entry"; 139584afc48bSJason M. Bills logEntryJson["Id"] = logEntryID; 139684afc48bSJason M. Bills logEntryJson["Message"] = std::move(msg); 139784afc48bSJason M. Bills logEntryJson["MessageId"] = std::move(messageID); 139884afc48bSJason M. Bills logEntryJson["MessageArgs"] = messageArgs; 139984afc48bSJason M. Bills logEntryJson["EntryType"] = "Event"; 140084afc48bSJason M. Bills logEntryJson["Severity"] = message->messageSeverity; 140184afc48bSJason M. Bills logEntryJson["Created"] = std::move(timestamp); 1402ac992cdeSJason M. Bills return LogParseError::success; 1403c4bf6374SJason M. Bills } 1404c4bf6374SJason M. Bills 1405*898f2aa2SEd Tanous inline void fillEventLogLogEntryFromPropertyMap( 1406*898f2aa2SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1407*898f2aa2SEd Tanous const dbus::utility::DBusPropertiesMap& resp, 1408*898f2aa2SEd Tanous nlohmann::json& objectToFillOut) 1409*898f2aa2SEd Tanous { 1410*898f2aa2SEd Tanous uint32_t id = 0; 1411*898f2aa2SEd Tanous uint64_t timestamp = 0; 1412*898f2aa2SEd Tanous uint64_t updateTimestamp = 0; 1413*898f2aa2SEd Tanous std::string severity; 1414*898f2aa2SEd Tanous std::string message; 1415*898f2aa2SEd Tanous const std::string* filePath = nullptr; 1416*898f2aa2SEd Tanous const std::string* resolution = nullptr; 1417*898f2aa2SEd Tanous bool resolved = false; 1418*898f2aa2SEd Tanous std::string notify; 1419*898f2aa2SEd Tanous // clang-format off 1420*898f2aa2SEd Tanous bool success = sdbusplus::unpackPropertiesNoThrow( 1421*898f2aa2SEd Tanous dbus_utils::UnpackErrorPrinter(), resp, 1422*898f2aa2SEd Tanous "Id", id, 1423*898f2aa2SEd Tanous "Message", message, 1424*898f2aa2SEd Tanous "Path", filePath, 1425*898f2aa2SEd Tanous "Resolution", resolution, 1426*898f2aa2SEd Tanous "Resolved", resolved, 1427*898f2aa2SEd Tanous "ServiceProviderNotify", notify, 1428*898f2aa2SEd Tanous "Severity", severity, 1429*898f2aa2SEd Tanous "Timestamp", timestamp, 1430*898f2aa2SEd Tanous "UpdateTimestamp", updateTimestamp 1431*898f2aa2SEd Tanous ); 1432*898f2aa2SEd Tanous // clang-format on 1433*898f2aa2SEd Tanous 1434*898f2aa2SEd Tanous if (!success) 1435*898f2aa2SEd Tanous { 1436*898f2aa2SEd Tanous messages::internalError(asyncResp->res); 1437*898f2aa2SEd Tanous return; 1438*898f2aa2SEd Tanous } 1439*898f2aa2SEd Tanous 1440*898f2aa2SEd Tanous objectToFillOut["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 1441*898f2aa2SEd Tanous objectToFillOut["@odata.id"] = boost::urls::format( 1442*898f2aa2SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}", 1443*898f2aa2SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(id)); 1444*898f2aa2SEd Tanous objectToFillOut["Name"] = "System Event Log Entry"; 1445*898f2aa2SEd Tanous objectToFillOut["Id"] = std::to_string(id); 1446*898f2aa2SEd Tanous objectToFillOut["Message"] = message; 1447*898f2aa2SEd Tanous objectToFillOut["Resolved"] = resolved; 1448*898f2aa2SEd Tanous std::optional<bool> notifyAction = getProviderNotifyAction(notify); 1449*898f2aa2SEd Tanous if (notifyAction) 1450*898f2aa2SEd Tanous { 1451*898f2aa2SEd Tanous objectToFillOut["ServiceProviderNotified"] = *notifyAction; 1452*898f2aa2SEd Tanous } 1453*898f2aa2SEd Tanous if ((resolution != nullptr) && !resolution->empty()) 1454*898f2aa2SEd Tanous { 1455*898f2aa2SEd Tanous objectToFillOut["Resolution"] = *resolution; 1456*898f2aa2SEd Tanous } 1457*898f2aa2SEd Tanous objectToFillOut["EntryType"] = "Event"; 1458*898f2aa2SEd Tanous objectToFillOut["Severity"] = translateSeverityDbusToRedfish(severity); 1459*898f2aa2SEd Tanous objectToFillOut["Created"] = 1460*898f2aa2SEd Tanous redfish::time_utils::getDateTimeUintMs(timestamp); 1461*898f2aa2SEd Tanous objectToFillOut["Modified"] = 1462*898f2aa2SEd Tanous redfish::time_utils::getDateTimeUintMs(updateTimestamp); 1463*898f2aa2SEd Tanous if (filePath != nullptr) 1464*898f2aa2SEd Tanous { 1465*898f2aa2SEd Tanous objectToFillOut["AdditionalDataURI"] = boost::urls::format( 1466*898f2aa2SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment", 1467*898f2aa2SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(id)); 1468*898f2aa2SEd Tanous } 1469*898f2aa2SEd Tanous } 1470*898f2aa2SEd Tanous 1471b729096dSEd Tanous inline void afterLogEntriesGetManagedObjects( 1472b729096dSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1473b729096dSEd Tanous const boost::system::error_code& ec, 1474b729096dSEd Tanous const dbus::utility::ManagedObjectType& resp) 1475b729096dSEd Tanous { 1476b729096dSEd Tanous if (ec) 1477b729096dSEd Tanous { 1478b729096dSEd Tanous // TODO Handle for specific error code 1479b729096dSEd Tanous BMCWEB_LOG_ERROR("getLogEntriesIfaceData resp_handler got error {}", 1480b729096dSEd Tanous ec); 1481b729096dSEd Tanous messages::internalError(asyncResp->res); 1482b729096dSEd Tanous return; 1483b729096dSEd Tanous } 1484b729096dSEd Tanous nlohmann::json::array_t entriesArray; 1485b729096dSEd Tanous for (const auto& objectPath : resp) 1486b729096dSEd Tanous { 1487*898f2aa2SEd Tanous dbus::utility::DBusPropertiesMap propsFlattened; 1488*898f2aa2SEd Tanous auto isEntry = std::ranges::find_if(objectPath.second, 1489*898f2aa2SEd Tanous [](const auto& object) { 1490*898f2aa2SEd Tanous return object.first == "xyz.openbmc_project.Logging.Entry"; 1491*898f2aa2SEd Tanous }); 1492*898f2aa2SEd Tanous if (isEntry == objectPath.second.end()) 1493b729096dSEd Tanous { 1494b729096dSEd Tanous continue; 1495b729096dSEd Tanous } 1496*898f2aa2SEd Tanous for (const auto& interfaceMap : objectPath.second) 1497b729096dSEd Tanous { 1498*898f2aa2SEd Tanous for (const auto& propertyMap : interfaceMap.second) 1499b729096dSEd Tanous { 1500*898f2aa2SEd Tanous propsFlattened.emplace_back(propertyMap.first, 1501*898f2aa2SEd Tanous propertyMap.second); 1502b729096dSEd Tanous } 1503b729096dSEd Tanous } 1504*898f2aa2SEd Tanous fillEventLogLogEntryFromPropertyMap(asyncResp, propsFlattened, 1505*898f2aa2SEd Tanous entriesArray.emplace_back()); 1506b729096dSEd Tanous } 1507*898f2aa2SEd Tanous 1508b729096dSEd Tanous std::ranges::sort(entriesArray, [](const nlohmann::json& left, 1509b729096dSEd Tanous const nlohmann::json& right) { 1510b729096dSEd Tanous return (left["Id"] <= right["Id"]); 1511b729096dSEd Tanous }); 1512b729096dSEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size(); 1513b729096dSEd Tanous asyncResp->res.jsonValue["Members"] = std::move(entriesArray); 1514b729096dSEd Tanous } 1515b729096dSEd Tanous 1516599b9af3SAlexander Hansen inline void handleSystemsLogServiceEventLogLogEntryCollection( 1517599b9af3SAlexander Hansen App& app, const crow::Request& req, 151822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1519599b9af3SAlexander Hansen const std::string& systemName) 1520599b9af3SAlexander Hansen { 1521c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1522c937d2bfSEd Tanous .canDelegateTop = true, 1523c937d2bfSEd Tanous .canDelegateSkip = true, 1524c937d2bfSEd Tanous }; 1525c937d2bfSEd Tanous query_param::Query delegatedQuery; 1526599b9af3SAlexander Hansen if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp, 1527599b9af3SAlexander Hansen delegatedQuery, capabilities)) 1528c4bf6374SJason M. Bills { 1529c4bf6374SJason M. Bills return; 1530c4bf6374SJason M. Bills } 153125b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 15327f3e84a1SEd Tanous { 15337f3e84a1SEd Tanous // Option currently returns no systems. TBD 15347f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 15357f3e84a1SEd Tanous systemName); 15367f3e84a1SEd Tanous return; 15377f3e84a1SEd Tanous } 1538253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 153922d268cbSEd Tanous { 154022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 154122d268cbSEd Tanous systemName); 154222d268cbSEd Tanous return; 154322d268cbSEd Tanous } 154422d268cbSEd Tanous 15455143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 15463648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 15473648c8beSEd Tanous 15487e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 15497e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1550c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1551c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1552c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1553253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries", 1554253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 1555c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1556c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1557c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1558cb92c03bSAndrew Geissler 15594978b63fSJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1560c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 15617e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 15627e860f15SJohn Edward Broadbent // entry 156395820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 156495820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1565b01bf299SEd Tanous uint64_t entryCount = 0; 1566cd225da8SJason M. Bills std::string logEntry; 156795820184SJason M. Bills 15687e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 15697e860f15SJohn Edward Broadbent // backwards 1570599b9af3SAlexander Hansen for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++) 1571c4bf6374SJason M. Bills { 1572cd225da8SJason M. Bills std::ifstream logStream(*it); 157395820184SJason M. Bills if (!logStream.is_open()) 1574c4bf6374SJason M. Bills { 1575c4bf6374SJason M. Bills continue; 1576c4bf6374SJason M. Bills } 1577c4bf6374SJason M. Bills 1578e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1579e85d6b16SJason M. Bills bool firstEntry = true; 158095820184SJason M. Bills while (std::getline(logStream, logEntry)) 158195820184SJason M. Bills { 1582c4bf6374SJason M. Bills std::string idStr; 1583e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1584c4bf6374SJason M. Bills { 1585c4bf6374SJason M. Bills continue; 1586c4bf6374SJason M. Bills } 1587e85d6b16SJason M. Bills firstEntry = false; 1588e85d6b16SJason M. Bills 1589de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 159089492a15SPatrick Williams LogParseError status = fillEventLogEntryJson(idStr, logEntry, 159189492a15SPatrick Williams bmcLogEntry); 1592ac992cdeSJason M. Bills if (status == LogParseError::messageIdNotInRegistry) 1593ac992cdeSJason M. Bills { 1594ac992cdeSJason M. Bills continue; 1595ac992cdeSJason M. Bills } 1596ac992cdeSJason M. Bills if (status != LogParseError::success) 1597c4bf6374SJason M. Bills { 1598c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1599c4bf6374SJason M. Bills return; 1600c4bf6374SJason M. Bills } 1601de703c5dSJason M. Bills 1602de703c5dSJason M. Bills entryCount++; 1603de703c5dSJason M. Bills // Handle paging using skip (number of entries to skip from the 1604de703c5dSJason M. Bills // start) and top (number of entries to display) 16053648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 1606de703c5dSJason M. Bills { 1607de703c5dSJason M. Bills continue; 1608de703c5dSJason M. Bills } 1609de703c5dSJason M. Bills 1610b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(bmcLogEntry)); 1611c4bf6374SJason M. Bills } 161295820184SJason M. Bills } 1613c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 16143648c8beSEd Tanous if (skip + top < entryCount) 1615c4bf6374SJason M. Bills { 1616599b9af3SAlexander Hansen asyncResp->res.jsonValue["Members@odata.nextLink"] = 1617599b9af3SAlexander Hansen boost::urls::format( 1618253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}", 1619253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top)); 1620c4bf6374SJason M. Bills } 1621897967deSJason M. Bills } 1622897967deSJason M. Bills 1623599b9af3SAlexander Hansen inline void requestRoutesJournalEventLogEntryCollection(App& app) 1624897967deSJason M. Bills { 1625599b9af3SAlexander Hansen BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") 1626599b9af3SAlexander Hansen .privileges(redfish::privileges::getLogEntryCollection) 1627599b9af3SAlexander Hansen .methods(boost::beast::http::verb::get)(std::bind_front( 1628599b9af3SAlexander Hansen handleSystemsLogServiceEventLogLogEntryCollection, std::ref(app))); 1629599b9af3SAlexander Hansen } 1630599b9af3SAlexander Hansen 1631599b9af3SAlexander Hansen inline void handleSystemsLogServiceEventLogEntriesGet( 1632599b9af3SAlexander Hansen App& app, const crow::Request& req, 16337e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1634599b9af3SAlexander Hansen const std::string& systemName, const std::string& param) 1635599b9af3SAlexander Hansen { 16363ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 163745ca1b86SEd Tanous { 163845ca1b86SEd Tanous return; 163945ca1b86SEd Tanous } 164025b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 16417f3e84a1SEd Tanous { 16427f3e84a1SEd Tanous // Option currently returns no systems. TBD 16437f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 16447f3e84a1SEd Tanous systemName); 16457f3e84a1SEd Tanous return; 16467f3e84a1SEd Tanous } 164722d268cbSEd Tanous 1648253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 164922d268cbSEd Tanous { 165022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 165122d268cbSEd Tanous systemName); 165222d268cbSEd Tanous return; 165322d268cbSEd Tanous } 165422d268cbSEd Tanous 16557e860f15SJohn Edward Broadbent const std::string& targetID = param; 16568d1b46d7Szhanghch05 16577e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 16587e860f15SJohn Edward Broadbent // entry to find the target entry 1659897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1660897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1661897967deSJason M. Bills std::string logEntry; 1662897967deSJason M. Bills 16637e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 16647e860f15SJohn Edward Broadbent // backwards 1665599b9af3SAlexander Hansen for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); it++) 1666897967deSJason M. Bills { 1667897967deSJason M. Bills std::ifstream logStream(*it); 1668897967deSJason M. Bills if (!logStream.is_open()) 1669897967deSJason M. Bills { 1670897967deSJason M. Bills continue; 1671897967deSJason M. Bills } 1672897967deSJason M. Bills 1673897967deSJason M. Bills // Reset the unique ID on the first entry 1674897967deSJason M. Bills bool firstEntry = true; 1675897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1676897967deSJason M. Bills { 1677897967deSJason M. Bills std::string idStr; 1678897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1679897967deSJason M. Bills { 1680897967deSJason M. Bills continue; 1681897967deSJason M. Bills } 1682897967deSJason M. Bills firstEntry = false; 1683897967deSJason M. Bills 1684897967deSJason M. Bills if (idStr == targetID) 1685897967deSJason M. Bills { 1686de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 1687599b9af3SAlexander Hansen LogParseError status = fillEventLogEntryJson(idStr, logEntry, 1688599b9af3SAlexander Hansen bmcLogEntry); 1689ac992cdeSJason M. Bills if (status != LogParseError::success) 1690897967deSJason M. Bills { 1691897967deSJason M. Bills messages::internalError(asyncResp->res); 1692897967deSJason M. Bills return; 1693897967deSJason M. Bills } 1694d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcLogEntry); 1695897967deSJason M. Bills return; 1696897967deSJason M. Bills } 1697897967deSJason M. Bills } 1698897967deSJason M. Bills } 1699897967deSJason M. Bills // Requested ID was not found 17009db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", targetID); 1701599b9af3SAlexander Hansen } 1702599b9af3SAlexander Hansen 1703599b9af3SAlexander Hansen inline void requestRoutesJournalEventLogEntry(App& app) 1704599b9af3SAlexander Hansen { 1705599b9af3SAlexander Hansen BMCWEB_ROUTE( 1706599b9af3SAlexander Hansen app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1707599b9af3SAlexander Hansen .privileges(redfish::privileges::getLogEntry) 1708599b9af3SAlexander Hansen .methods(boost::beast::http::verb::get)(std::bind_front( 1709599b9af3SAlexander Hansen handleSystemsLogServiceEventLogEntriesGet, std::ref(app))); 1710599b9af3SAlexander Hansen } 1711599b9af3SAlexander Hansen 1712599b9af3SAlexander Hansen inline void dBusEventLogEntryCollection( 1713599b9af3SAlexander Hansen const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1714599b9af3SAlexander Hansen { 1715599b9af3SAlexander Hansen // Collections don't include the static data added by SubRoute 1716599b9af3SAlexander Hansen // because it has a duplicate entry for members 1717599b9af3SAlexander Hansen asyncResp->res.jsonValue["@odata.type"] = 1718599b9af3SAlexander Hansen "#LogEntryCollection.LogEntryCollection"; 1719599b9af3SAlexander Hansen asyncResp->res.jsonValue["@odata.id"] = 1720599b9af3SAlexander Hansen std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries", 1721599b9af3SAlexander Hansen BMCWEB_REDFISH_SYSTEM_URI_NAME); 1722599b9af3SAlexander Hansen asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1723599b9af3SAlexander Hansen asyncResp->res.jsonValue["Description"] = 1724599b9af3SAlexander Hansen "Collection of System Event Log Entries"; 1725599b9af3SAlexander Hansen 1726599b9af3SAlexander Hansen // DBus implementation of EventLog/Entries 1727599b9af3SAlexander Hansen // Make call to Logging Service to find all log entry objects 1728599b9af3SAlexander Hansen sdbusplus::message::object_path path("/xyz/openbmc_project/logging"); 1729599b9af3SAlexander Hansen dbus::utility::getManagedObjects( 1730599b9af3SAlexander Hansen "xyz.openbmc_project.Logging", path, 1731599b9af3SAlexander Hansen [asyncResp](const boost::system::error_code& ec, 1732599b9af3SAlexander Hansen const dbus::utility::ManagedObjectType& resp) { 1733b729096dSEd Tanous afterLogEntriesGetManagedObjects(asyncResp, ec, resp); 17347e860f15SJohn Edward Broadbent }); 173508a4e4b5SAnthony Wilson } 173608a4e4b5SAnthony Wilson 17377e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 173808a4e4b5SAnthony Wilson { 173922d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") 1740ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 1741002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1742002d39b4SEd Tanous [&app](const crow::Request& req, 174322d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 174422d268cbSEd Tanous const std::string& systemName) { 17453ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 174645ca1b86SEd Tanous { 174745ca1b86SEd Tanous return; 174845ca1b86SEd Tanous } 174925b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 17507f3e84a1SEd Tanous { 17517f3e84a1SEd Tanous // Option currently returns no systems. TBD 17527f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 17537f3e84a1SEd Tanous systemName); 17547f3e84a1SEd Tanous return; 17557f3e84a1SEd Tanous } 1756253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 175722d268cbSEd Tanous { 175822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 175922d268cbSEd Tanous systemName); 176022d268cbSEd Tanous return; 176122d268cbSEd Tanous } 1762599b9af3SAlexander Hansen dBusEventLogEntryCollection(asyncResp); 1763599b9af3SAlexander Hansen }); 1764599b9af3SAlexander Hansen } 176522d268cbSEd Tanous 1766599b9af3SAlexander Hansen inline void 1767599b9af3SAlexander Hansen dBusEventLogEntryGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1768*898f2aa2SEd Tanous std::string entryID) 1769599b9af3SAlexander Hansen { 1770599b9af3SAlexander Hansen dbus::utility::escapePathForDbus(entryID); 177108a4e4b5SAnthony Wilson 1772cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1773cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1774599b9af3SAlexander Hansen sdbusplus::asio::getAllProperties( 1775599b9af3SAlexander Hansen *crow::connections::systemBus, "xyz.openbmc_project.Logging", 1776599b9af3SAlexander Hansen "/xyz/openbmc_project/logging/entry/" + entryID, "", 1777599b9af3SAlexander Hansen [asyncResp, entryID](const boost::system::error_code& ec, 1778599b9af3SAlexander Hansen const dbus::utility::DBusPropertiesMap& resp) { 1779599b9af3SAlexander Hansen if (ec.value() == EBADR) 1780599b9af3SAlexander Hansen { 1781599b9af3SAlexander Hansen messages::resourceNotFound(asyncResp->res, "EventLogEntry", 1782599b9af3SAlexander Hansen entryID); 1783599b9af3SAlexander Hansen return; 1784599b9af3SAlexander Hansen } 1785cb92c03bSAndrew Geissler if (ec) 1786cb92c03bSAndrew Geissler { 1787599b9af3SAlexander Hansen BMCWEB_LOG_ERROR("EventLogEntry (DBus) resp_handler got error {}", 1788599b9af3SAlexander Hansen ec); 1789cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1790cb92c03bSAndrew Geissler return; 1791cb92c03bSAndrew Geissler } 17929017faf2SAbhishek Patel 1793*898f2aa2SEd Tanous fillEventLogLogEntryFromPropertyMap(asyncResp, resp, 1794*898f2aa2SEd Tanous asyncResp->res.jsonValue); 1795599b9af3SAlexander Hansen }); 17967e860f15SJohn Edward Broadbent } 1797599b9af3SAlexander Hansen 1798599b9af3SAlexander Hansen inline void 1799599b9af3SAlexander Hansen dBusEventLogEntryPatch(const crow::Request& req, 1800599b9af3SAlexander Hansen const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1801599b9af3SAlexander Hansen const std::string& entryId) 1802599b9af3SAlexander Hansen { 1803599b9af3SAlexander Hansen std::optional<bool> resolved; 1804599b9af3SAlexander Hansen 1805599b9af3SAlexander Hansen if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", resolved)) 1806599b9af3SAlexander Hansen { 1807599b9af3SAlexander Hansen return; 1808599b9af3SAlexander Hansen } 1809599b9af3SAlexander Hansen BMCWEB_LOG_DEBUG("Set Resolved"); 1810599b9af3SAlexander Hansen 1811599b9af3SAlexander Hansen setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging", 1812599b9af3SAlexander Hansen "/xyz/openbmc_project/logging/entry/" + entryId, 1813599b9af3SAlexander Hansen "xyz.openbmc_project.Logging.Entry", "Resolved", 1814599b9af3SAlexander Hansen resolved.value_or(false)); 1815599b9af3SAlexander Hansen } 1816599b9af3SAlexander Hansen 1817599b9af3SAlexander Hansen inline void 1818599b9af3SAlexander Hansen dBusEventLogEntryDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1819599b9af3SAlexander Hansen std::string entryID) 1820599b9af3SAlexander Hansen { 1821599b9af3SAlexander Hansen BMCWEB_LOG_DEBUG("Do delete single event entries."); 1822599b9af3SAlexander Hansen 1823599b9af3SAlexander Hansen dbus::utility::escapePathForDbus(entryID); 1824599b9af3SAlexander Hansen 1825599b9af3SAlexander Hansen // Process response from Logging service. 1826599b9af3SAlexander Hansen auto respHandler = [asyncResp, 1827599b9af3SAlexander Hansen entryID](const boost::system::error_code& ec) { 1828599b9af3SAlexander Hansen BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done"); 1829599b9af3SAlexander Hansen if (ec) 1830599b9af3SAlexander Hansen { 1831599b9af3SAlexander Hansen if (ec.value() == EBADR) 1832599b9af3SAlexander Hansen { 1833599b9af3SAlexander Hansen messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 1834599b9af3SAlexander Hansen return; 1835599b9af3SAlexander Hansen } 1836599b9af3SAlexander Hansen // TODO Handle for specific error code 1837599b9af3SAlexander Hansen BMCWEB_LOG_ERROR( 1838599b9af3SAlexander Hansen "EventLogEntry (DBus) doDelete respHandler got error {}", ec); 1839599b9af3SAlexander Hansen asyncResp->res.result( 1840599b9af3SAlexander Hansen boost::beast::http::status::internal_server_error); 1841599b9af3SAlexander Hansen return; 1842599b9af3SAlexander Hansen } 1843599b9af3SAlexander Hansen 1844599b9af3SAlexander Hansen asyncResp->res.result(boost::beast::http::status::ok); 1845599b9af3SAlexander Hansen }; 1846599b9af3SAlexander Hansen 1847599b9af3SAlexander Hansen // Make call to Logging service to request Delete Log 1848599b9af3SAlexander Hansen crow::connections::systemBus->async_method_call( 1849599b9af3SAlexander Hansen respHandler, "xyz.openbmc_project.Logging", 1850599b9af3SAlexander Hansen "/xyz/openbmc_project/logging/entry/" + entryID, 1851599b9af3SAlexander Hansen "xyz.openbmc_project.Object.Delete", "Delete"); 18527e860f15SJohn Edward Broadbent } 18537e860f15SJohn Edward Broadbent 18547e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 18557e860f15SJohn Edward Broadbent { 18567e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 185722d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1858ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 1859002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1860002d39b4SEd Tanous [&app](const crow::Request& req, 18617e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1862*898f2aa2SEd Tanous const std::string& systemName, const std::string& entryId) { 18633ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 18647e860f15SJohn Edward Broadbent { 186545ca1b86SEd Tanous return; 186645ca1b86SEd Tanous } 186725b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 18687f3e84a1SEd Tanous { 18697f3e84a1SEd Tanous // Option currently returns no systems. TBD 18707f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 18717f3e84a1SEd Tanous systemName); 18727f3e84a1SEd Tanous return; 18737f3e84a1SEd Tanous } 1874253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 187522d268cbSEd Tanous { 187622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 187722d268cbSEd Tanous systemName); 187822d268cbSEd Tanous return; 187922d268cbSEd Tanous } 188022d268cbSEd Tanous 1881*898f2aa2SEd Tanous dBusEventLogEntryGet(asyncResp, entryId); 18827e860f15SJohn Edward Broadbent }); 1883336e96c6SChicago Duan 18847e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 188522d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1886ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 18877e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 188845ca1b86SEd Tanous [&app](const crow::Request& req, 18897e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 189022d268cbSEd Tanous const std::string& systemName, const std::string& entryId) { 18913ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 189245ca1b86SEd Tanous { 189345ca1b86SEd Tanous return; 189445ca1b86SEd Tanous } 189525b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 18967f3e84a1SEd Tanous { 18977f3e84a1SEd Tanous // Option currently returns no systems. TBD 18987f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 18997f3e84a1SEd Tanous systemName); 19007f3e84a1SEd Tanous return; 19017f3e84a1SEd Tanous } 1902253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 190322d268cbSEd Tanous { 190422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 190522d268cbSEd Tanous systemName); 190622d268cbSEd Tanous return; 190722d268cbSEd Tanous } 190875710de2SXiaochao Ma 1909599b9af3SAlexander Hansen dBusEventLogEntryPatch(req, asyncResp, entryId); 19107e860f15SJohn Edward Broadbent }); 191175710de2SXiaochao Ma 19127e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 191322d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1914ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1915ed398213SEd Tanous 1916002d39b4SEd Tanous .methods(boost::beast::http::verb::delete_)( 1917002d39b4SEd Tanous [&app](const crow::Request& req, 1918002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 191922d268cbSEd Tanous const std::string& systemName, const std::string& param) { 19203ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1921336e96c6SChicago Duan { 192245ca1b86SEd Tanous return; 192345ca1b86SEd Tanous } 192425b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 19257f3e84a1SEd Tanous { 19267f3e84a1SEd Tanous // Option currently returns no systems. TBD 19277f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 19287f3e84a1SEd Tanous systemName); 19297f3e84a1SEd Tanous return; 19307f3e84a1SEd Tanous } 1931253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 193222d268cbSEd Tanous { 193322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 193422d268cbSEd Tanous systemName); 193522d268cbSEd Tanous return; 193622d268cbSEd Tanous } 1937599b9af3SAlexander Hansen dBusEventLogEntryDelete(asyncResp, param); 19387e860f15SJohn Edward Broadbent }); 1939400fd1fbSAdriana Kobylak } 1940400fd1fbSAdriana Kobylak 1941b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 1942b7028ebfSSpencer Ku 1943b7028ebfSSpencer Ku inline bool 1944b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 1945b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 1946b7028ebfSSpencer Ku { 1947b7028ebfSSpencer Ku std::error_code ec; 1948b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 1949b7028ebfSSpencer Ku if (ec) 1950b7028ebfSSpencer Ku { 1951bf2ddedeSCarson Labrado BMCWEB_LOG_WARNING("{}", ec.message()); 1952b7028ebfSSpencer Ku return false; 1953b7028ebfSSpencer Ku } 1954b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 1955b7028ebfSSpencer Ku { 1956b7028ebfSSpencer Ku std::string filename = it.path().filename(); 1957b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 1958b7028ebfSSpencer Ku // path 195911ba3979SEd Tanous if (filename.starts_with("log")) 1960b7028ebfSSpencer Ku { 1961b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 1962b7028ebfSSpencer Ku } 1963b7028ebfSSpencer Ku } 1964b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 1965b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 1966b7028ebfSSpencer Ku // descending order. 1967b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 1968b7028ebfSSpencer Ku AlphanumLess<std::string>()); 1969b7028ebfSSpencer Ku 1970b7028ebfSSpencer Ku return true; 1971b7028ebfSSpencer Ku } 1972b7028ebfSSpencer Ku 197302cad96eSEd Tanous inline bool getHostLoggerEntries( 197402cad96eSEd Tanous const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip, 197502cad96eSEd Tanous uint64_t top, std::vector<std::string>& logEntries, size_t& logCount) 1976b7028ebfSSpencer Ku { 1977b7028ebfSSpencer Ku GzFileReader logFile; 1978b7028ebfSSpencer Ku 1979b7028ebfSSpencer Ku // Go though all log files and expose host logs. 1980b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 1981b7028ebfSSpencer Ku { 1982b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 1983b7028ebfSSpencer Ku { 198462598e31SEd Tanous BMCWEB_LOG_ERROR("fail to expose host logs"); 1985b7028ebfSSpencer Ku return false; 1986b7028ebfSSpencer Ku } 1987b7028ebfSSpencer Ku } 1988b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 1989b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 1990b7028ebfSSpencer Ku if (!lastMessage.empty()) 1991b7028ebfSSpencer Ku { 1992b7028ebfSSpencer Ku logCount++; 1993b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 1994b7028ebfSSpencer Ku { 1995b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 1996b7028ebfSSpencer Ku } 1997b7028ebfSSpencer Ku } 1998b7028ebfSSpencer Ku return true; 1999b7028ebfSSpencer Ku } 2000b7028ebfSSpencer Ku 20016f056f24SEd Tanous inline void fillHostLoggerEntryJson(std::string_view logEntryID, 20026f056f24SEd Tanous std::string_view msg, 20036d6574c9SJason M. Bills nlohmann::json::object_t& logEntryJson) 2004b7028ebfSSpencer Ku { 2005b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 20069c11a172SVijay Lobo logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 2007ef4c65b7SEd Tanous logEntryJson["@odata.id"] = boost::urls::format( 2008253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries/{}", 2009253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID); 20106d6574c9SJason M. Bills logEntryJson["Name"] = "Host Logger Entry"; 20116d6574c9SJason M. Bills logEntryJson["Id"] = logEntryID; 20126d6574c9SJason M. Bills logEntryJson["Message"] = msg; 2013539d8c6bSEd Tanous logEntryJson["EntryType"] = log_entry::LogEntryType::Oem; 2014539d8c6bSEd Tanous logEntryJson["Severity"] = log_entry::EventSeverity::OK; 20156d6574c9SJason M. Bills logEntryJson["OemRecordFormat"] = "Host Logger Entry"; 2016b7028ebfSSpencer Ku } 2017b7028ebfSSpencer Ku 2018b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 2019b7028ebfSSpencer Ku { 202022d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/") 2021b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 20221476687dSEd Tanous .methods(boost::beast::http::verb::get)( 20231476687dSEd Tanous [&app](const crow::Request& req, 202422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 202522d268cbSEd Tanous const std::string& systemName) { 20263ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 202745ca1b86SEd Tanous { 202845ca1b86SEd Tanous return; 202945ca1b86SEd Tanous } 203025b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 20317f3e84a1SEd Tanous { 20327f3e84a1SEd Tanous // Option currently returns no systems. TBD 20337f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 20347f3e84a1SEd Tanous systemName); 20357f3e84a1SEd Tanous return; 20367f3e84a1SEd Tanous } 2037253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 203822d268cbSEd Tanous { 203922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 204022d268cbSEd Tanous systemName); 204122d268cbSEd Tanous return; 204222d268cbSEd Tanous } 2043b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 2044253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/HostLogger", 2045253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2046b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 2047b25644a1SJanet Adkins "#LogService.v1_2_0.LogService"; 2048b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 2049b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 2050b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 20511476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 2052253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries", 2053253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2054b7028ebfSSpencer Ku }); 2055b7028ebfSSpencer Ku } 2056b7028ebfSSpencer Ku 2057b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 2058b7028ebfSSpencer Ku { 2059b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 206022d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/") 2061b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2062002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2063002d39b4SEd Tanous [&app](const crow::Request& req, 206422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 206522d268cbSEd Tanous const std::string& systemName) { 2066c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2067c937d2bfSEd Tanous .canDelegateTop = true, 2068c937d2bfSEd Tanous .canDelegateSkip = true, 2069c937d2bfSEd Tanous }; 2070c937d2bfSEd Tanous query_param::Query delegatedQuery; 2071c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 20723ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 2073b7028ebfSSpencer Ku { 2074b7028ebfSSpencer Ku return; 2075b7028ebfSSpencer Ku } 207625b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 20777f3e84a1SEd Tanous { 20787f3e84a1SEd Tanous // Option currently returns no systems. TBD 20797f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 20807f3e84a1SEd Tanous systemName); 20817f3e84a1SEd Tanous return; 20827f3e84a1SEd Tanous } 2083253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 208422d268cbSEd Tanous { 208522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 208622d268cbSEd Tanous systemName); 208722d268cbSEd Tanous return; 208822d268cbSEd Tanous } 2089b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 2090253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries", 2091253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2092b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 2093b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 2094b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 2095b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 2096b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 20970fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2098b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 2099b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 2100b7028ebfSSpencer Ku 2101b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2102b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2103b7028ebfSSpencer Ku { 2104bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("Failed to get host log file path"); 2105b7028ebfSSpencer Ku return; 2106b7028ebfSSpencer Ku } 21073648c8beSEd Tanous // If we weren't provided top and skip limits, use the defaults. 21083648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 21095143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 2110b7028ebfSSpencer Ku size_t logCount = 0; 2111b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 2112b7028ebfSSpencer Ku // control by skip and top. 2113b7028ebfSSpencer Ku std::vector<std::string> logEntries; 21143648c8beSEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries, 21153648c8beSEd Tanous logCount)) 2116b7028ebfSSpencer Ku { 2117b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2118b7028ebfSSpencer Ku return; 2119b7028ebfSSpencer Ku } 2120b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 2121b7028ebfSSpencer Ku // log count 212226f6976fSEd Tanous if (logEntries.empty()) 2123b7028ebfSSpencer Ku { 2124b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 2125b7028ebfSSpencer Ku return; 2126b7028ebfSSpencer Ku } 212726f6976fSEd Tanous if (!logEntries.empty()) 2128b7028ebfSSpencer Ku { 2129b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 2130b7028ebfSSpencer Ku { 21316d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 21323648c8beSEd Tanous fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i], 21333648c8beSEd Tanous hostLogEntry); 2134b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(hostLogEntry)); 2135b7028ebfSSpencer Ku } 2136b7028ebfSSpencer Ku 2137b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 21383648c8beSEd Tanous if (skip + top < logCount) 2139b7028ebfSSpencer Ku { 2140b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 2141253f11b8SEd Tanous std::format( 2142253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries?$skip=", 2143253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME) + 21443648c8beSEd Tanous std::to_string(skip + top); 2145b7028ebfSSpencer Ku } 2146b7028ebfSSpencer Ku } 2147b7028ebfSSpencer Ku }); 2148b7028ebfSSpencer Ku } 2149b7028ebfSSpencer Ku 2150b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 2151b7028ebfSSpencer Ku { 2152b7028ebfSSpencer Ku BMCWEB_ROUTE( 215322d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/") 2154b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2155b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 215645ca1b86SEd Tanous [&app](const crow::Request& req, 2157b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 215822d268cbSEd Tanous const std::string& systemName, const std::string& param) { 21593ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 216045ca1b86SEd Tanous { 216145ca1b86SEd Tanous return; 216245ca1b86SEd Tanous } 216325b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 21647f3e84a1SEd Tanous { 21657f3e84a1SEd Tanous // Option currently returns no systems. TBD 21667f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 21677f3e84a1SEd Tanous systemName); 21687f3e84a1SEd Tanous return; 21697f3e84a1SEd Tanous } 2170253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 217122d268cbSEd Tanous { 217222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 217322d268cbSEd Tanous systemName); 217422d268cbSEd Tanous return; 217522d268cbSEd Tanous } 21766f056f24SEd Tanous std::string_view targetID = param; 2177b7028ebfSSpencer Ku 2178b7028ebfSSpencer Ku uint64_t idInt = 0; 2179ca45aa3cSEd Tanous 21806f056f24SEd Tanous auto [ptr, ec] = std::from_chars(targetID.begin(), targetID.end(), 218184396af9SPatrick Williams idInt); 21826f056f24SEd Tanous if (ec != std::errc{} || ptr != targetID.end()) 2183b7028ebfSSpencer Ku { 21849db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", param); 2185b7028ebfSSpencer Ku return; 2186b7028ebfSSpencer Ku } 2187b7028ebfSSpencer Ku 2188b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2189b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2190b7028ebfSSpencer Ku { 2191bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("Failed to get host log file path"); 2192b7028ebfSSpencer Ku return; 2193b7028ebfSSpencer Ku } 2194b7028ebfSSpencer Ku 2195b7028ebfSSpencer Ku size_t logCount = 0; 21963648c8beSEd Tanous size_t top = 1; 2197b7028ebfSSpencer Ku std::vector<std::string> logEntries; 2198b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 2199b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 2200b7028ebfSSpencer Ku // get that entry 2201002d39b4SEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries, 2202002d39b4SEd Tanous logCount)) 2203b7028ebfSSpencer Ku { 2204b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2205b7028ebfSSpencer Ku return; 2206b7028ebfSSpencer Ku } 2207b7028ebfSSpencer Ku 2208b7028ebfSSpencer Ku if (!logEntries.empty()) 2209b7028ebfSSpencer Ku { 22106d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 22116d6574c9SJason M. Bills fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry); 22126d6574c9SJason M. Bills asyncResp->res.jsonValue.update(hostLogEntry); 2213b7028ebfSSpencer Ku return; 2214b7028ebfSSpencer Ku } 2215b7028ebfSSpencer Ku 2216b7028ebfSSpencer Ku // Requested ID was not found 22179db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", param); 2218b7028ebfSSpencer Ku }); 2219b7028ebfSSpencer Ku } 2220b7028ebfSSpencer Ku 2221dd72e87bSClaire Weinan inline void handleBMCLogServicesCollectionGet( 2222fdd26906SClaire Weinan crow::App& app, const crow::Request& req, 2223253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2224253f11b8SEd Tanous const std::string& managerId) 22251da66f75SEd Tanous { 22263ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 222745ca1b86SEd Tanous { 222845ca1b86SEd Tanous return; 222945ca1b86SEd Tanous } 2230253f11b8SEd Tanous 2231253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2232253f11b8SEd Tanous { 2233253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2234253f11b8SEd Tanous return; 2235253f11b8SEd Tanous } 2236253f11b8SEd Tanous 22377e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 22387e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2239e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 22401da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2241253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 2242253f11b8SEd Tanous "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME); 2243002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 2244e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 22451da66f75SEd Tanous "Collection of LogServices for this Manager"; 2246002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 2247c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 2248fdd26906SClaire Weinan 224925b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_BMC_JOURNAL) 225025b54dbaSEd Tanous { 2251613dabeaSEd Tanous nlohmann::json::object_t journal; 2252253f11b8SEd Tanous journal["@odata.id"] = 2253253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal", 2254253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2255b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(journal)); 225625b54dbaSEd Tanous } 2257fdd26906SClaire Weinan 2258fdd26906SClaire Weinan asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); 2259fdd26906SClaire Weinan 226025b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_DUMP_LOG) 226125b54dbaSEd Tanous { 226215912159SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 22637a1dbc48SGeorge Liu "xyz.openbmc_project.Collection.DeleteAll"}; 22647a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 22657a1dbc48SGeorge Liu "/xyz/openbmc_project/dump", 0, interfaces, 226625b54dbaSEd Tanous [asyncResp](const boost::system::error_code& ec, 226725b54dbaSEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& 226825b54dbaSEd Tanous subTreePaths) { 2269fdd26906SClaire Weinan if (ec) 2270fdd26906SClaire Weinan { 227162598e31SEd Tanous BMCWEB_LOG_ERROR( 227262598e31SEd Tanous "handleBMCLogServicesCollectionGet respHandler got error {}", 227362598e31SEd Tanous ec); 2274fdd26906SClaire Weinan // Assume that getting an error simply means there are no dump 2275fdd26906SClaire Weinan // LogServices. Return without adding any error response. 2276fdd26906SClaire Weinan return; 2277fdd26906SClaire Weinan } 2278fdd26906SClaire Weinan 2279fdd26906SClaire Weinan nlohmann::json& logServiceArrayLocal = 2280fdd26906SClaire Weinan asyncResp->res.jsonValue["Members"]; 2281fdd26906SClaire Weinan 2282fdd26906SClaire Weinan for (const std::string& path : subTreePaths) 2283fdd26906SClaire Weinan { 2284fdd26906SClaire Weinan if (path == "/xyz/openbmc_project/dump/bmc") 2285fdd26906SClaire Weinan { 2286613dabeaSEd Tanous nlohmann::json::object_t member; 2287253f11b8SEd Tanous member["@odata.id"] = boost::urls::format( 2288253f11b8SEd Tanous "/redfish/v1/Managers/{}/LogServices/Dump", 2289253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2290b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 2291fdd26906SClaire Weinan } 2292fdd26906SClaire Weinan else if (path == "/xyz/openbmc_project/dump/faultlog") 2293fdd26906SClaire Weinan { 2294613dabeaSEd Tanous nlohmann::json::object_t member; 2295253f11b8SEd Tanous member["@odata.id"] = boost::urls::format( 2296253f11b8SEd Tanous "/redfish/v1/Managers/{}/LogServices/FaultLog", 2297253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2298b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 2299fdd26906SClaire Weinan } 2300fdd26906SClaire Weinan } 2301fdd26906SClaire Weinan 2302e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2303fdd26906SClaire Weinan logServiceArrayLocal.size(); 23047a1dbc48SGeorge Liu }); 230525b54dbaSEd Tanous } 2306fdd26906SClaire Weinan } 2307fdd26906SClaire Weinan 2308fdd26906SClaire Weinan inline void requestRoutesBMCLogServiceCollection(App& app) 2309fdd26906SClaire Weinan { 2310253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/") 2311fdd26906SClaire Weinan .privileges(redfish::privileges::getLogServiceCollection) 2312fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2313dd72e87bSClaire Weinan std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app))); 2314e1f26343SJason M. Bills } 2315e1f26343SJason M. Bills 2316fdd26906SClaire Weinan inline void 2317fdd26906SClaire Weinan getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2318fdd26906SClaire Weinan const std::string& dumpType) 2319c9bb6861Sraviteja-b { 2320fdd26906SClaire Weinan std::string dumpPath; 2321539d8c6bSEd Tanous log_service::OverWritePolicy overWritePolicy = 2322539d8c6bSEd Tanous log_service::OverWritePolicy::Invalid; 2323fdd26906SClaire Weinan bool collectDiagnosticDataSupported = false; 2324fdd26906SClaire Weinan 2325fdd26906SClaire Weinan if (dumpType == "BMC") 232645ca1b86SEd Tanous { 2327253f11b8SEd Tanous dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump", 2328253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2329539d8c6bSEd Tanous overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; 2330fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2331fdd26906SClaire Weinan } 2332fdd26906SClaire Weinan else if (dumpType == "FaultLog") 2333fdd26906SClaire Weinan { 2334253f11b8SEd Tanous dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog", 2335253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2336539d8c6bSEd Tanous overWritePolicy = log_service::OverWritePolicy::Unknown; 2337fdd26906SClaire Weinan collectDiagnosticDataSupported = false; 2338fdd26906SClaire Weinan } 2339fdd26906SClaire Weinan else if (dumpType == "System") 2340fdd26906SClaire Weinan { 2341253f11b8SEd Tanous dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump", 2342253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2343539d8c6bSEd Tanous overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; 2344fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2345fdd26906SClaire Weinan } 2346fdd26906SClaire Weinan else 2347fdd26906SClaire Weinan { 234862598e31SEd Tanous BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}", 234962598e31SEd Tanous dumpType); 2350fdd26906SClaire Weinan messages::internalError(asyncResp->res); 235145ca1b86SEd Tanous return; 235245ca1b86SEd Tanous } 2353fdd26906SClaire Weinan 2354fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = dumpPath; 2355fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; 2356c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 2357fdd26906SClaire Weinan asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; 2358fdd26906SClaire Weinan asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); 2359539d8c6bSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy; 23607c8c4058STejas Patil 23617c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 23622b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 23630fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 23647c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 23657c8c4058STejas Patil redfishDateTimeOffset.second; 23667c8c4058STejas Patil 2367fdd26906SClaire Weinan asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; 2368fdd26906SClaire Weinan 2369fdd26906SClaire Weinan if (collectDiagnosticDataSupported) 2370fdd26906SClaire Weinan { 2371002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 23721476687dSEd Tanous ["target"] = 2373fdd26906SClaire Weinan dumpPath + "/Actions/LogService.CollectDiagnosticData"; 2374fdd26906SClaire Weinan } 23750d946211SClaire Weinan 23760d946211SClaire Weinan constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface}; 23770d946211SClaire Weinan dbus::utility::getSubTreePaths( 23780d946211SClaire Weinan "/xyz/openbmc_project/dump", 0, interfaces, 23790d946211SClaire Weinan [asyncResp, dumpType, dumpPath]( 23800d946211SClaire Weinan const boost::system::error_code& ec, 23810d946211SClaire Weinan const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 23820d946211SClaire Weinan if (ec) 23830d946211SClaire Weinan { 238462598e31SEd Tanous BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", ec); 23850d946211SClaire Weinan // Assume that getting an error simply means there are no dump 23860d946211SClaire Weinan // LogServices. Return without adding any error response. 23870d946211SClaire Weinan return; 23880d946211SClaire Weinan } 238918f8f608SEd Tanous std::string dbusDumpPath = getDumpPath(dumpType); 23900d946211SClaire Weinan for (const std::string& path : subTreePaths) 23910d946211SClaire Weinan { 23920d946211SClaire Weinan if (path == dbusDumpPath) 23930d946211SClaire Weinan { 23940d946211SClaire Weinan asyncResp->res 23950d946211SClaire Weinan .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 23960d946211SClaire Weinan dumpPath + "/Actions/LogService.ClearLog"; 23970d946211SClaire Weinan break; 23980d946211SClaire Weinan } 23990d946211SClaire Weinan } 24000d946211SClaire Weinan }); 2401c9bb6861Sraviteja-b } 2402c9bb6861Sraviteja-b 2403fdd26906SClaire Weinan inline void handleLogServicesDumpServiceGet( 2404fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2405253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2406253f11b8SEd Tanous const std::string& managerId) 24077e860f15SJohn Edward Broadbent { 24083ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 240945ca1b86SEd Tanous { 241045ca1b86SEd Tanous return; 241145ca1b86SEd Tanous } 2412253f11b8SEd Tanous 2413253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2414253f11b8SEd Tanous { 2415253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2416253f11b8SEd Tanous return; 2417253f11b8SEd Tanous } 2418253f11b8SEd Tanous 2419fdd26906SClaire Weinan getDumpServiceInfo(asyncResp, dumpType); 2420fdd26906SClaire Weinan } 2421c9bb6861Sraviteja-b 242222d268cbSEd Tanous inline void handleLogServicesDumpServiceComputerSystemGet( 242322d268cbSEd Tanous crow::App& app, const crow::Request& req, 242422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 242522d268cbSEd Tanous const std::string& chassisId) 242622d268cbSEd Tanous { 242722d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 242822d268cbSEd Tanous { 242922d268cbSEd Tanous return; 243022d268cbSEd Tanous } 2431253f11b8SEd Tanous if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) 243222d268cbSEd Tanous { 243322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 243422d268cbSEd Tanous return; 243522d268cbSEd Tanous } 243622d268cbSEd Tanous getDumpServiceInfo(asyncResp, "System"); 243722d268cbSEd Tanous } 243822d268cbSEd Tanous 2439fdd26906SClaire Weinan inline void handleLogServicesDumpEntriesCollectionGet( 2440fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2441253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2442253f11b8SEd Tanous const std::string& managerId) 2443fdd26906SClaire Weinan { 2444fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2445fdd26906SClaire Weinan { 2446fdd26906SClaire Weinan return; 2447fdd26906SClaire Weinan } 2448253f11b8SEd Tanous 2449253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2450253f11b8SEd Tanous { 2451253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2452253f11b8SEd Tanous return; 2453253f11b8SEd Tanous } 2454fdd26906SClaire Weinan getDumpEntryCollection(asyncResp, dumpType); 2455fdd26906SClaire Weinan } 2456fdd26906SClaire Weinan 245722d268cbSEd Tanous inline void handleLogServicesDumpEntriesCollectionComputerSystemGet( 245822d268cbSEd Tanous crow::App& app, const crow::Request& req, 245922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 246022d268cbSEd Tanous const std::string& chassisId) 246122d268cbSEd Tanous { 246222d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 246322d268cbSEd Tanous { 246422d268cbSEd Tanous return; 246522d268cbSEd Tanous } 2466253f11b8SEd Tanous if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) 246722d268cbSEd Tanous { 246822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 246922d268cbSEd Tanous return; 247022d268cbSEd Tanous } 247122d268cbSEd Tanous getDumpEntryCollection(asyncResp, "System"); 247222d268cbSEd Tanous } 247322d268cbSEd Tanous 2474fdd26906SClaire Weinan inline void handleLogServicesDumpEntryGet( 2475fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2476fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2477253f11b8SEd Tanous const std::string& managerId, const std::string& dumpId) 2478fdd26906SClaire Weinan { 2479fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2480fdd26906SClaire Weinan { 2481fdd26906SClaire Weinan return; 2482fdd26906SClaire Weinan } 2483253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2484253f11b8SEd Tanous { 2485253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2486253f11b8SEd Tanous return; 2487253f11b8SEd Tanous } 2488fdd26906SClaire Weinan getDumpEntryById(asyncResp, dumpId, dumpType); 2489fdd26906SClaire Weinan } 2490168d1b1aSCarson Labrado 249122d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemGet( 249222d268cbSEd Tanous crow::App& app, const crow::Request& req, 249322d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 249422d268cbSEd Tanous const std::string& chassisId, const std::string& dumpId) 249522d268cbSEd Tanous { 249622d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 249722d268cbSEd Tanous { 249822d268cbSEd Tanous return; 249922d268cbSEd Tanous } 2500253f11b8SEd Tanous if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) 250122d268cbSEd Tanous { 250222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 250322d268cbSEd Tanous return; 250422d268cbSEd Tanous } 250522d268cbSEd Tanous getDumpEntryById(asyncResp, dumpId, "System"); 250622d268cbSEd Tanous } 2507fdd26906SClaire Weinan 2508fdd26906SClaire Weinan inline void handleLogServicesDumpEntryDelete( 2509fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2510fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2511253f11b8SEd Tanous const std::string& managerId, const std::string& dumpId) 2512fdd26906SClaire Weinan { 2513fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2514fdd26906SClaire Weinan { 2515fdd26906SClaire Weinan return; 2516fdd26906SClaire Weinan } 2517253f11b8SEd Tanous 2518253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2519253f11b8SEd Tanous { 2520253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2521253f11b8SEd Tanous return; 2522253f11b8SEd Tanous } 2523fdd26906SClaire Weinan deleteDumpEntry(asyncResp, dumpId, dumpType); 2524fdd26906SClaire Weinan } 2525fdd26906SClaire Weinan 252622d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemDelete( 252722d268cbSEd Tanous crow::App& app, const crow::Request& req, 252822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 252922d268cbSEd Tanous const std::string& chassisId, const std::string& dumpId) 253022d268cbSEd Tanous { 253122d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 253222d268cbSEd Tanous { 253322d268cbSEd Tanous return; 253422d268cbSEd Tanous } 2535253f11b8SEd Tanous if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) 253622d268cbSEd Tanous { 253722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 253822d268cbSEd Tanous return; 253922d268cbSEd Tanous } 254022d268cbSEd Tanous deleteDumpEntry(asyncResp, dumpId, "System"); 254122d268cbSEd Tanous } 254222d268cbSEd Tanous 2543168d1b1aSCarson Labrado inline void handleLogServicesDumpEntryDownloadGet( 2544168d1b1aSCarson Labrado crow::App& app, const std::string& dumpType, const crow::Request& req, 2545168d1b1aSCarson Labrado const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2546253f11b8SEd Tanous const std::string& managerId, const std::string& dumpId) 2547168d1b1aSCarson Labrado { 2548168d1b1aSCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2549168d1b1aSCarson Labrado { 2550168d1b1aSCarson Labrado return; 2551168d1b1aSCarson Labrado } 2552253f11b8SEd Tanous 2553253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2554253f11b8SEd Tanous { 2555253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2556253f11b8SEd Tanous return; 2557253f11b8SEd Tanous } 2558168d1b1aSCarson Labrado downloadDumpEntry(asyncResp, dumpId, dumpType); 2559168d1b1aSCarson Labrado } 2560168d1b1aSCarson Labrado 2561168d1b1aSCarson Labrado inline void handleDBusEventLogEntryDownloadGet( 2562168d1b1aSCarson Labrado crow::App& app, const std::string& dumpType, const crow::Request& req, 2563168d1b1aSCarson Labrado const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2564168d1b1aSCarson Labrado const std::string& systemName, const std::string& entryID) 2565168d1b1aSCarson Labrado { 2566168d1b1aSCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2567168d1b1aSCarson Labrado { 2568168d1b1aSCarson Labrado return; 2569168d1b1aSCarson Labrado } 2570168d1b1aSCarson Labrado if (!http_helpers::isContentTypeAllowed( 2571168d1b1aSCarson Labrado req.getHeaderValue("Accept"), 2572168d1b1aSCarson Labrado http_helpers::ContentType::OctetStream, true)) 2573168d1b1aSCarson Labrado { 2574168d1b1aSCarson Labrado asyncResp->res.result(boost::beast::http::status::bad_request); 2575168d1b1aSCarson Labrado return; 2576168d1b1aSCarson Labrado } 2577168d1b1aSCarson Labrado downloadEventLogEntry(asyncResp, systemName, entryID, dumpType); 2578168d1b1aSCarson Labrado } 2579168d1b1aSCarson Labrado 2580fdd26906SClaire Weinan inline void handleLogServicesDumpCollectDiagnosticDataPost( 2581fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2582253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2583253f11b8SEd Tanous const std::string& managerId) 2584fdd26906SClaire Weinan { 2585fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2586fdd26906SClaire Weinan { 2587fdd26906SClaire Weinan return; 2588fdd26906SClaire Weinan } 2589253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2590253f11b8SEd Tanous { 2591253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2592253f11b8SEd Tanous return; 2593253f11b8SEd Tanous } 2594253f11b8SEd Tanous 2595fdd26906SClaire Weinan createDump(asyncResp, req, dumpType); 2596fdd26906SClaire Weinan } 2597fdd26906SClaire Weinan 259822d268cbSEd Tanous inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost( 259922d268cbSEd Tanous crow::App& app, const crow::Request& req, 260022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26017f3e84a1SEd Tanous const std::string& systemName) 260222d268cbSEd Tanous { 260322d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 260422d268cbSEd Tanous { 260522d268cbSEd Tanous return; 260622d268cbSEd Tanous } 26077f3e84a1SEd Tanous 260825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 260922d268cbSEd Tanous { 26107f3e84a1SEd Tanous // Option currently returns no systems. TBD 26117f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 26127f3e84a1SEd Tanous systemName); 26137f3e84a1SEd Tanous return; 26147f3e84a1SEd Tanous } 2615253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 26167f3e84a1SEd Tanous { 26177f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 26187f3e84a1SEd Tanous systemName); 261922d268cbSEd Tanous return; 262022d268cbSEd Tanous } 262122d268cbSEd Tanous createDump(asyncResp, req, "System"); 262222d268cbSEd Tanous } 262322d268cbSEd Tanous 2624fdd26906SClaire Weinan inline void handleLogServicesDumpClearLogPost( 2625fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2626253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2627253f11b8SEd Tanous const std::string& managerId) 2628fdd26906SClaire Weinan { 2629fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2630fdd26906SClaire Weinan { 2631fdd26906SClaire Weinan return; 2632fdd26906SClaire Weinan } 2633253f11b8SEd Tanous 2634253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2635253f11b8SEd Tanous { 2636253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2637253f11b8SEd Tanous return; 2638253f11b8SEd Tanous } 2639fdd26906SClaire Weinan clearDump(asyncResp, dumpType); 2640fdd26906SClaire Weinan } 2641fdd26906SClaire Weinan 264222d268cbSEd Tanous inline void handleLogServicesDumpClearLogComputerSystemPost( 264322d268cbSEd Tanous crow::App& app, const crow::Request& req, 264422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26457f3e84a1SEd Tanous const std::string& systemName) 264622d268cbSEd Tanous { 264722d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 264822d268cbSEd Tanous { 264922d268cbSEd Tanous return; 265022d268cbSEd Tanous } 265125b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 265222d268cbSEd Tanous { 26537f3e84a1SEd Tanous // Option currently returns no systems. TBD 26547f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 26557f3e84a1SEd Tanous systemName); 26567f3e84a1SEd Tanous return; 26577f3e84a1SEd Tanous } 2658253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 26597f3e84a1SEd Tanous { 26607f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 26617f3e84a1SEd Tanous systemName); 266222d268cbSEd Tanous return; 266322d268cbSEd Tanous } 266422d268cbSEd Tanous clearDump(asyncResp, "System"); 266522d268cbSEd Tanous } 266622d268cbSEd Tanous 2667fdd26906SClaire Weinan inline void requestRoutesBMCDumpService(App& app) 2668fdd26906SClaire Weinan { 2669253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/") 2670fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2671fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2672fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "BMC")); 2673fdd26906SClaire Weinan } 2674fdd26906SClaire Weinan 2675fdd26906SClaire Weinan inline void requestRoutesBMCDumpEntryCollection(App& app) 2676fdd26906SClaire Weinan { 2677253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/") 2678fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2679fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2680fdd26906SClaire Weinan handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); 2681c9bb6861Sraviteja-b } 2682c9bb6861Sraviteja-b 26837e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2684c9bb6861Sraviteja-b { 26857e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2686253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") 2687ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2688fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2689fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "BMC")); 2690fdd26906SClaire Weinan 26917e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2692253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") 2693ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 2694fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2695fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); 2696c9bb6861Sraviteja-b } 2697c9bb6861Sraviteja-b 2698168d1b1aSCarson Labrado inline void requestRoutesBMCDumpEntryDownload(App& app) 2699168d1b1aSCarson Labrado { 2700168d1b1aSCarson Labrado BMCWEB_ROUTE( 2701168d1b1aSCarson Labrado app, 2702253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/") 2703168d1b1aSCarson Labrado .privileges(redfish::privileges::getLogEntry) 2704168d1b1aSCarson Labrado .methods(boost::beast::http::verb::get)(std::bind_front( 2705168d1b1aSCarson Labrado handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC")); 2706168d1b1aSCarson Labrado } 2707168d1b1aSCarson Labrado 27087e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2709c9bb6861Sraviteja-b { 27100fda0f12SGeorge Liu BMCWEB_ROUTE( 27110fda0f12SGeorge Liu app, 2712253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2713ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 27147e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 2715fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, 2716fdd26906SClaire Weinan std::ref(app), "BMC")); 2717a43be80fSAsmitha Karunanithi } 2718a43be80fSAsmitha Karunanithi 27197e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 272080319af1SAsmitha Karunanithi { 27210fda0f12SGeorge Liu BMCWEB_ROUTE( 27220fda0f12SGeorge Liu app, 2723253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/") 2724ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 2725fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 2726fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); 272745ca1b86SEd Tanous } 2728fdd26906SClaire Weinan 2729168d1b1aSCarson Labrado inline void requestRoutesDBusEventLogEntryDownload(App& app) 2730168d1b1aSCarson Labrado { 2731168d1b1aSCarson Labrado BMCWEB_ROUTE( 2732168d1b1aSCarson Labrado app, 27339e9d99daSRavi Teja "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/") 2734168d1b1aSCarson Labrado .privileges(redfish::privileges::getLogEntry) 2735168d1b1aSCarson Labrado .methods(boost::beast::http::verb::get)(std::bind_front( 2736168d1b1aSCarson Labrado handleDBusEventLogEntryDownloadGet, std::ref(app), "System")); 2737168d1b1aSCarson Labrado } 2738168d1b1aSCarson Labrado 2739fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpService(App& app) 2740fdd26906SClaire Weinan { 2741253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/") 2742fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2743fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2744fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); 2745fdd26906SClaire Weinan } 2746fdd26906SClaire Weinan 2747fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntryCollection(App& app) 2748fdd26906SClaire Weinan { 2749253f11b8SEd Tanous BMCWEB_ROUTE(app, 2750253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/") 2751fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2752fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2753fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpEntriesCollectionGet, 2754fdd26906SClaire Weinan std::ref(app), "FaultLog")); 2755fdd26906SClaire Weinan } 2756fdd26906SClaire Weinan 2757fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntry(App& app) 2758fdd26906SClaire Weinan { 2759253f11b8SEd Tanous BMCWEB_ROUTE( 2760253f11b8SEd Tanous app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") 2761fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntry) 2762fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2763fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); 2764fdd26906SClaire Weinan 2765253f11b8SEd Tanous BMCWEB_ROUTE( 2766253f11b8SEd Tanous app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") 2767fdd26906SClaire Weinan .privileges(redfish::privileges::deleteLogEntry) 2768fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2769fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); 2770fdd26906SClaire Weinan } 2771fdd26906SClaire Weinan 2772fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpClear(App& app) 2773fdd26906SClaire Weinan { 2774fdd26906SClaire Weinan BMCWEB_ROUTE( 2775fdd26906SClaire Weinan app, 2776253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/") 2777fdd26906SClaire Weinan .privileges(redfish::privileges::postLogService) 2778fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 2779fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); 27805cb1dd27SAsmitha Karunanithi } 27815cb1dd27SAsmitha Karunanithi 27827e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 27835cb1dd27SAsmitha Karunanithi { 278422d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/") 2785ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 27866ab9ad54SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 278722d268cbSEd Tanous handleLogServicesDumpServiceComputerSystemGet, std::ref(app))); 27885cb1dd27SAsmitha Karunanithi } 27895cb1dd27SAsmitha Karunanithi 27907e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 27917e860f15SJohn Edward Broadbent { 279222d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/") 2793ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 279422d268cbSEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 279522d268cbSEd Tanous handleLogServicesDumpEntriesCollectionComputerSystemGet, 279622d268cbSEd Tanous std::ref(app))); 27975cb1dd27SAsmitha Karunanithi } 27985cb1dd27SAsmitha Karunanithi 27997e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 28005cb1dd27SAsmitha Karunanithi { 28017e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 280222d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") 2803ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 28046ab9ad54SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 280522d268cbSEd Tanous handleLogServicesDumpEntryComputerSystemGet, std::ref(app))); 28068d1b46d7Szhanghch05 28077e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 280822d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") 2809ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 28106ab9ad54SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 281122d268cbSEd Tanous handleLogServicesDumpEntryComputerSystemDelete, std::ref(app))); 28125cb1dd27SAsmitha Karunanithi } 2813c9bb6861Sraviteja-b 28147e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2815c9bb6861Sraviteja-b { 28160fda0f12SGeorge Liu BMCWEB_ROUTE( 28170fda0f12SGeorge Liu app, 281822d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2819ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 282022d268cbSEd Tanous .methods(boost::beast::http::verb::post)(std::bind_front( 282122d268cbSEd Tanous handleLogServicesDumpCollectDiagnosticDataComputerSystemPost, 282222d268cbSEd Tanous std::ref(app))); 2823a43be80fSAsmitha Karunanithi } 2824a43be80fSAsmitha Karunanithi 28257e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2826a43be80fSAsmitha Karunanithi { 28270fda0f12SGeorge Liu BMCWEB_ROUTE( 28280fda0f12SGeorge Liu app, 282922d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/") 2830ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 28316ab9ad54SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 283222d268cbSEd Tanous handleLogServicesDumpClearLogComputerSystemPost, std::ref(app))); 2833013487e5Sraviteja-b } 2834013487e5Sraviteja-b 28357e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 28361da66f75SEd Tanous { 28373946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28383946028dSAppaRao Puli // method for security reasons. 28391da66f75SEd Tanous /** 28401da66f75SEd Tanous * Functions triggers appropriate requests on DBus 28411da66f75SEd Tanous */ 284222d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/") 2843ed398213SEd Tanous // This is incorrect, should be: 2844ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2845432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 2846002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2847002d39b4SEd Tanous [&app](const crow::Request& req, 284822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 284922d268cbSEd Tanous const std::string& systemName) { 28503ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 285145ca1b86SEd Tanous { 285245ca1b86SEd Tanous return; 285345ca1b86SEd Tanous } 285425b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 28557f3e84a1SEd Tanous { 28567f3e84a1SEd Tanous // Option currently returns no systems. TBD 28577f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 28587f3e84a1SEd Tanous systemName); 28597f3e84a1SEd Tanous return; 28607f3e84a1SEd Tanous } 2861253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 286222d268cbSEd Tanous { 286322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 286422d268cbSEd Tanous systemName); 286522d268cbSEd Tanous return; 286622d268cbSEd Tanous } 286722d268cbSEd Tanous 28687e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 28697e860f15SJohn Edward Broadbent // SubRoute 28700f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2871253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", 2872253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2873e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 28748e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 28754f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 28764f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 287715b89725SV-Sanjana asyncResp->res.jsonValue["Id"] = "Crashdump"; 2878539d8c6bSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = 2879539d8c6bSEd Tanous log_service::OverWritePolicy::WrapsWhenFull; 2880e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 28817c8c4058STejas Patil 28827c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 28832b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 28847c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 28857c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 28867c8c4058STejas Patil redfishDateTimeOffset.second; 28877c8c4058STejas Patil 28881476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 2889253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", 2890253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2891253f11b8SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] 2892253f11b8SEd Tanous ["target"] = std::format( 2893253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog", 2894253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2895002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 2896253f11b8SEd Tanous ["target"] = std::format( 2897253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData", 2898253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 28997e860f15SJohn Edward Broadbent }); 29001da66f75SEd Tanous } 29011da66f75SEd Tanous 29027e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 29035b61b5e8SJason M. Bills { 29040fda0f12SGeorge Liu BMCWEB_ROUTE( 29050fda0f12SGeorge Liu app, 290622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/") 2907ed398213SEd Tanous // This is incorrect, should be: 2908ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2909432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 29107e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 291145ca1b86SEd Tanous [&app](const crow::Request& req, 291222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 291322d268cbSEd Tanous const std::string& systemName) { 29143ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 291545ca1b86SEd Tanous { 291645ca1b86SEd Tanous return; 291745ca1b86SEd Tanous } 291825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 29197f3e84a1SEd Tanous { 29207f3e84a1SEd Tanous // Option currently returns no systems. TBD 29217f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 29227f3e84a1SEd Tanous systemName); 29237f3e84a1SEd Tanous return; 29247f3e84a1SEd Tanous } 2925253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 292622d268cbSEd Tanous { 292722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 292822d268cbSEd Tanous systemName); 292922d268cbSEd Tanous return; 293022d268cbSEd Tanous } 29315b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 29325e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 2933cb13a392SEd Tanous const std::string&) { 29345b61b5e8SJason M. Bills if (ec) 29355b61b5e8SJason M. Bills { 29365b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 29375b61b5e8SJason M. Bills return; 29385b61b5e8SJason M. Bills } 29395b61b5e8SJason M. Bills messages::success(asyncResp->res); 29405b61b5e8SJason M. Bills }, 2941002d39b4SEd Tanous crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 29427e860f15SJohn Edward Broadbent }); 29435b61b5e8SJason M. Bills } 29445b61b5e8SJason M. Bills 29458d1b46d7Szhanghch05 static void 29468d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29478d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 2948e855dd28SJason M. Bills { 2949043a0536SJohnathan Mantey auto getStoredLogCallback = 2950b9d36b47SEd Tanous [asyncResp, logID, 29515e7e2dc5SEd Tanous &logEntryJson](const boost::system::error_code& ec, 2952b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& params) { 2953e855dd28SJason M. Bills if (ec) 2954e855dd28SJason M. Bills { 295562598e31SEd Tanous BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message()); 29561ddcf01aSJason M. Bills if (ec.value() == 29571ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 29581ddcf01aSJason M. Bills { 2959002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 29601ddcf01aSJason M. Bills } 29611ddcf01aSJason M. Bills else 29621ddcf01aSJason M. Bills { 2963e855dd28SJason M. Bills messages::internalError(asyncResp->res); 29641ddcf01aSJason M. Bills } 2965e855dd28SJason M. Bills return; 2966e855dd28SJason M. Bills } 2967043a0536SJohnathan Mantey 2968043a0536SJohnathan Mantey std::string timestamp{}; 2969043a0536SJohnathan Mantey std::string filename{}; 2970043a0536SJohnathan Mantey std::string logfile{}; 29712c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2972043a0536SJohnathan Mantey 2973043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2974e855dd28SJason M. Bills { 29759db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 2976e855dd28SJason M. Bills return; 2977e855dd28SJason M. Bills } 2978e855dd28SJason M. Bills 2979043a0536SJohnathan Mantey std::string crashdumpURI = 2980253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/", 2981253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME) + 2982043a0536SJohnathan Mantey logID + "/" + filename; 298384afc48bSJason M. Bills nlohmann::json::object_t logEntry; 29849c11a172SVijay Lobo logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 2985ef4c65b7SEd Tanous logEntry["@odata.id"] = boost::urls::format( 2986253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}", 2987253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, logID); 298884afc48bSJason M. Bills logEntry["Name"] = "CPU Crashdump"; 298984afc48bSJason M. Bills logEntry["Id"] = logID; 2990539d8c6bSEd Tanous logEntry["EntryType"] = log_entry::LogEntryType::Oem; 299184afc48bSJason M. Bills logEntry["AdditionalDataURI"] = std::move(crashdumpURI); 299284afc48bSJason M. Bills logEntry["DiagnosticDataType"] = "OEM"; 299384afc48bSJason M. Bills logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; 299484afc48bSJason M. Bills logEntry["Created"] = std::move(timestamp); 29952b20ef6eSJason M. Bills 29962b20ef6eSJason M. Bills // If logEntryJson references an array of LogEntry resources 29972b20ef6eSJason M. Bills // ('Members' list), then push this as a new entry, otherwise set it 29982b20ef6eSJason M. Bills // directly 29992b20ef6eSJason M. Bills if (logEntryJson.is_array()) 30002b20ef6eSJason M. Bills { 30012b20ef6eSJason M. Bills logEntryJson.push_back(logEntry); 30022b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 30032b20ef6eSJason M. Bills logEntryJson.size(); 30042b20ef6eSJason M. Bills } 30052b20ef6eSJason M. Bills else 30062b20ef6eSJason M. Bills { 3007d405bb51SJason M. Bills logEntryJson.update(logEntry); 30082b20ef6eSJason M. Bills } 3009e855dd28SJason M. Bills }; 3010d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3011d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, crashdumpObject, 3012d1bde9e5SKrzysztof Grobelny crashdumpPath + std::string("/") + logID, crashdumpInterface, 3013d1bde9e5SKrzysztof Grobelny std::move(getStoredLogCallback)); 3014e855dd28SJason M. Bills } 3015e855dd28SJason M. Bills 30167e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 30171da66f75SEd Tanous { 30183946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 30193946028dSAppaRao Puli // method for security reasons. 30201da66f75SEd Tanous /** 30211da66f75SEd Tanous * Functions triggers appropriate requests on DBus 30221da66f75SEd Tanous */ 30237e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 302422d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/") 3025ed398213SEd Tanous // This is incorrect, should be. 3026ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 3027432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3028002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3029002d39b4SEd Tanous [&app](const crow::Request& req, 303022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 303122d268cbSEd Tanous const std::string& systemName) { 30323ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 303345ca1b86SEd Tanous { 303445ca1b86SEd Tanous return; 303545ca1b86SEd Tanous } 303625b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 30377f3e84a1SEd Tanous { 30387f3e84a1SEd Tanous // Option currently returns no systems. TBD 30397f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 30407f3e84a1SEd Tanous systemName); 30417f3e84a1SEd Tanous return; 30427f3e84a1SEd Tanous } 3043253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 304422d268cbSEd Tanous { 304522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 304622d268cbSEd Tanous systemName); 304722d268cbSEd Tanous return; 304822d268cbSEd Tanous } 304922d268cbSEd Tanous 30507a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 30517a1dbc48SGeorge Liu crashdumpInterface}; 30527a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 30537a1dbc48SGeorge Liu "/", 0, interfaces, 30547a1dbc48SGeorge Liu [asyncResp](const boost::system::error_code& ec, 30552b20ef6eSJason M. Bills const std::vector<std::string>& resp) { 30561da66f75SEd Tanous if (ec) 30571da66f75SEd Tanous { 30581da66f75SEd Tanous if (ec.value() != 30591da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 30601da66f75SEd Tanous { 306162598e31SEd Tanous BMCWEB_LOG_DEBUG("failed to get entries ec: {}", 306262598e31SEd Tanous ec.message()); 3063f12894f8SJason M. Bills messages::internalError(asyncResp->res); 30641da66f75SEd Tanous return; 30651da66f75SEd Tanous } 30661da66f75SEd Tanous } 3067e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 30681da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 3069253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = std::format( 3070253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", 3071253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3072002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 3073e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 3074424c4176SJason M. Bills "Collection of Crashdump Entries"; 3075002d39b4SEd Tanous asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3076a2dd60a6SBrandon Kim asyncResp->res.jsonValue["Members@odata.count"] = 0; 30772b20ef6eSJason M. Bills 30782b20ef6eSJason M. Bills for (const std::string& path : resp) 30791da66f75SEd Tanous { 30802b20ef6eSJason M. Bills const sdbusplus::message::object_path objPath(path); 3081e855dd28SJason M. Bills // Get the log ID 30822b20ef6eSJason M. Bills std::string logID = objPath.filename(); 30832b20ef6eSJason M. Bills if (logID.empty()) 30841da66f75SEd Tanous { 3085e855dd28SJason M. Bills continue; 30861da66f75SEd Tanous } 3087e855dd28SJason M. Bills // Add the log entry to the array 30882b20ef6eSJason M. Bills logCrashdumpEntry(asyncResp, logID, 30892b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"]); 30901da66f75SEd Tanous } 30917a1dbc48SGeorge Liu }); 30927e860f15SJohn Edward Broadbent }); 30931da66f75SEd Tanous } 30941da66f75SEd Tanous 30957e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 30961da66f75SEd Tanous { 30973946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 30983946028dSAppaRao Puli // method for security reasons. 30991da66f75SEd Tanous 31007e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 310122d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/") 3102ed398213SEd Tanous // this is incorrect, should be 3103ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 3104432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 31057e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 310645ca1b86SEd Tanous [&app](const crow::Request& req, 31077e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 310822d268cbSEd Tanous const std::string& systemName, const std::string& param) { 31093ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 311045ca1b86SEd Tanous { 311145ca1b86SEd Tanous return; 311245ca1b86SEd Tanous } 311325b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 31147f3e84a1SEd Tanous { 31157f3e84a1SEd Tanous // Option currently returns no systems. TBD 31167f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 31177f3e84a1SEd Tanous systemName); 31187f3e84a1SEd Tanous return; 31197f3e84a1SEd Tanous } 3120253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 312122d268cbSEd Tanous { 312222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 312322d268cbSEd Tanous systemName); 312422d268cbSEd Tanous return; 312522d268cbSEd Tanous } 31267e860f15SJohn Edward Broadbent const std::string& logID = param; 3127e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 31287e860f15SJohn Edward Broadbent }); 3129e855dd28SJason M. Bills } 3130e855dd28SJason M. Bills 31317e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 3132e855dd28SJason M. Bills { 31333946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 31343946028dSAppaRao Puli // method for security reasons. 31357e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 31367e860f15SJohn Edward Broadbent app, 313722d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/") 3138ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 31397e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 3140a4ce114aSNan Zhou [](const crow::Request& req, 31417e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 314222d268cbSEd Tanous const std::string& systemName, const std::string& logID, 314322d268cbSEd Tanous const std::string& fileName) { 31442a9beeedSShounak Mitra // Do not call getRedfishRoute here since the crashdump file is not a 31452a9beeedSShounak Mitra // Redfish resource. 314622d268cbSEd Tanous 314725b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 31487f3e84a1SEd Tanous { 31497f3e84a1SEd Tanous // Option currently returns no systems. TBD 31507f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 31517f3e84a1SEd Tanous systemName); 31527f3e84a1SEd Tanous return; 31537f3e84a1SEd Tanous } 3154253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 315522d268cbSEd Tanous { 315622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 315722d268cbSEd Tanous systemName); 315822d268cbSEd Tanous return; 315922d268cbSEd Tanous } 316022d268cbSEd Tanous 3161043a0536SJohnathan Mantey auto getStoredLogCallback = 316239662a3bSEd Tanous [asyncResp, logID, fileName, url(boost::urls::url(req.url()))]( 31635e7e2dc5SEd Tanous const boost::system::error_code& ec, 3164002d39b4SEd Tanous const std::vector< 3165002d39b4SEd Tanous std::pair<std::string, dbus::utility::DbusVariantType>>& 31667e860f15SJohn Edward Broadbent resp) { 31671da66f75SEd Tanous if (ec) 31681da66f75SEd Tanous { 316962598e31SEd Tanous BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message()); 3170f12894f8SJason M. Bills messages::internalError(asyncResp->res); 31711da66f75SEd Tanous return; 31721da66f75SEd Tanous } 3173e855dd28SJason M. Bills 3174043a0536SJohnathan Mantey std::string dbusFilename{}; 3175043a0536SJohnathan Mantey std::string dbusTimestamp{}; 3176043a0536SJohnathan Mantey std::string dbusFilepath{}; 3177043a0536SJohnathan Mantey 3178002d39b4SEd Tanous parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 3179002d39b4SEd Tanous dbusFilepath); 3180043a0536SJohnathan Mantey 3181043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 3182043a0536SJohnathan Mantey dbusFilepath.empty()) 31831da66f75SEd Tanous { 31849db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 31851da66f75SEd Tanous return; 31861da66f75SEd Tanous } 3187e855dd28SJason M. Bills 3188043a0536SJohnathan Mantey // Verify the file name parameter is correct 3189043a0536SJohnathan Mantey if (fileName != dbusFilename) 3190043a0536SJohnathan Mantey { 31919db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3192043a0536SJohnathan Mantey return; 3193043a0536SJohnathan Mantey } 3194043a0536SJohnathan Mantey 319527b0cf90SEd Tanous if (!asyncResp->res.openFile(dbusFilepath)) 3196043a0536SJohnathan Mantey { 31979db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3198043a0536SJohnathan Mantey return; 3199043a0536SJohnathan Mantey } 3200043a0536SJohnathan Mantey 32017e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 32027e860f15SJohn Edward Broadbent // from a browser 3203d9f6c621SEd Tanous asyncResp->res.addHeader( 3204d9f6c621SEd Tanous boost::beast::http::field::content_disposition, "attachment"); 32051da66f75SEd Tanous }; 3206d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3207d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, crashdumpObject, 3208d1bde9e5SKrzysztof Grobelny crashdumpPath + std::string("/") + logID, crashdumpInterface, 3209d1bde9e5SKrzysztof Grobelny std::move(getStoredLogCallback)); 32107e860f15SJohn Edward Broadbent }); 32111da66f75SEd Tanous } 32121da66f75SEd Tanous 3213c5a4c82aSJason M. Bills enum class OEMDiagnosticType 3214c5a4c82aSJason M. Bills { 3215c5a4c82aSJason M. Bills onDemand, 3216c5a4c82aSJason M. Bills telemetry, 3217c5a4c82aSJason M. Bills invalid, 3218c5a4c82aSJason M. Bills }; 3219c5a4c82aSJason M. Bills 322026ccae32SEd Tanous inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr) 3221c5a4c82aSJason M. Bills { 3222c5a4c82aSJason M. Bills if (oemDiagStr == "OnDemand") 3223c5a4c82aSJason M. Bills { 3224c5a4c82aSJason M. Bills return OEMDiagnosticType::onDemand; 3225c5a4c82aSJason M. Bills } 3226c5a4c82aSJason M. Bills if (oemDiagStr == "Telemetry") 3227c5a4c82aSJason M. Bills { 3228c5a4c82aSJason M. Bills return OEMDiagnosticType::telemetry; 3229c5a4c82aSJason M. Bills } 3230c5a4c82aSJason M. Bills 3231c5a4c82aSJason M. Bills return OEMDiagnosticType::invalid; 3232c5a4c82aSJason M. Bills } 3233c5a4c82aSJason M. Bills 32347e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 32351da66f75SEd Tanous { 32363946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 32373946028dSAppaRao Puli // method for security reasons. 32380fda0f12SGeorge Liu BMCWEB_ROUTE( 32390fda0f12SGeorge Liu app, 324022d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") 3241ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 3242ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3243432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3244002d39b4SEd Tanous .methods(boost::beast::http::verb::post)( 3245002d39b4SEd Tanous [&app](const crow::Request& req, 324622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 324722d268cbSEd Tanous const std::string& systemName) { 32483ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 324945ca1b86SEd Tanous { 325045ca1b86SEd Tanous return; 325145ca1b86SEd Tanous } 325222d268cbSEd Tanous 325325b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 32547f3e84a1SEd Tanous { 32557f3e84a1SEd Tanous // Option currently returns no systems. TBD 32567f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 32577f3e84a1SEd Tanous systemName); 32587f3e84a1SEd Tanous return; 32597f3e84a1SEd Tanous } 3260253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 326122d268cbSEd Tanous { 326222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 326322d268cbSEd Tanous systemName); 326422d268cbSEd Tanous return; 326522d268cbSEd Tanous } 326622d268cbSEd Tanous 32678e6c099aSJason M. Bills std::string diagnosticDataType; 32688e6c099aSJason M. Bills std::string oemDiagnosticDataType; 326915ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 3270002d39b4SEd Tanous req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 3271002d39b4SEd Tanous "OEMDiagnosticDataType", oemDiagnosticDataType)) 32728e6c099aSJason M. Bills { 32738e6c099aSJason M. Bills return; 32748e6c099aSJason M. Bills } 32758e6c099aSJason M. Bills 32768e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 32778e6c099aSJason M. Bills { 327862598e31SEd Tanous BMCWEB_LOG_ERROR( 327962598e31SEd Tanous "Only OEM DiagnosticDataType supported for Crashdump"); 32808e6c099aSJason M. Bills messages::actionParameterValueFormatError( 32818e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 32828e6c099aSJason M. Bills "CollectDiagnosticData"); 32838e6c099aSJason M. Bills return; 32848e6c099aSJason M. Bills } 32858e6c099aSJason M. Bills 3286c5a4c82aSJason M. Bills OEMDiagnosticType oemDiagType = 3287c5a4c82aSJason M. Bills getOEMDiagnosticType(oemDiagnosticDataType); 3288c5a4c82aSJason M. Bills 3289c5a4c82aSJason M. Bills std::string iface; 3290c5a4c82aSJason M. Bills std::string method; 3291c5a4c82aSJason M. Bills std::string taskMatchStr; 3292c5a4c82aSJason M. Bills if (oemDiagType == OEMDiagnosticType::onDemand) 3293c5a4c82aSJason M. Bills { 3294c5a4c82aSJason M. Bills iface = crashdumpOnDemandInterface; 3295c5a4c82aSJason M. Bills method = "GenerateOnDemandLog"; 3296c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3297c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3298c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3299c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3300c5a4c82aSJason M. Bills } 3301c5a4c82aSJason M. Bills else if (oemDiagType == OEMDiagnosticType::telemetry) 3302c5a4c82aSJason M. Bills { 3303c5a4c82aSJason M. Bills iface = crashdumpTelemetryInterface; 3304c5a4c82aSJason M. Bills method = "GenerateTelemetryLog"; 3305c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3306c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3307c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3308c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3309c5a4c82aSJason M. Bills } 3310c5a4c82aSJason M. Bills else 3311c5a4c82aSJason M. Bills { 331262598e31SEd Tanous BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}", 331362598e31SEd Tanous oemDiagnosticDataType); 3314c5a4c82aSJason M. Bills messages::actionParameterValueFormatError( 3315002d39b4SEd Tanous asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType", 3316002d39b4SEd Tanous "CollectDiagnosticData"); 3317c5a4c82aSJason M. Bills return; 3318c5a4c82aSJason M. Bills } 3319c5a4c82aSJason M. Bills 3320c5a4c82aSJason M. Bills auto collectCrashdumpCallback = 3321c5a4c82aSJason M. Bills [asyncResp, payload(task::Payload(req)), 33225e7e2dc5SEd Tanous taskMatchStr](const boost::system::error_code& ec, 332398be3e39SEd Tanous const std::string&) mutable { 33241da66f75SEd Tanous if (ec) 33251da66f75SEd Tanous { 3326002d39b4SEd Tanous if (ec.value() == boost::system::errc::operation_not_supported) 33271da66f75SEd Tanous { 3328f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 33291da66f75SEd Tanous } 33304363d3b2SJason M. Bills else if (ec.value() == 33314363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 33324363d3b2SJason M. Bills { 3333002d39b4SEd Tanous messages::serviceTemporarilyUnavailable(asyncResp->res, 3334002d39b4SEd Tanous "60"); 33354363d3b2SJason M. Bills } 33361da66f75SEd Tanous else 33371da66f75SEd Tanous { 3338f12894f8SJason M. Bills messages::internalError(asyncResp->res); 33391da66f75SEd Tanous } 33401da66f75SEd Tanous return; 33411da66f75SEd Tanous } 3342002d39b4SEd Tanous std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 33438b24275dSEd Tanous [](const boost::system::error_code& ec2, sdbusplus::message_t&, 3344002d39b4SEd Tanous const std::shared_ptr<task::TaskData>& taskData) { 33458b24275dSEd Tanous if (!ec2) 334666afe4faSJames Feist { 3347002d39b4SEd Tanous taskData->messages.emplace_back(messages::taskCompletedOK( 3348e5d5006bSJames Feist std::to_string(taskData->index))); 3349831d6b09SJames Feist taskData->state = "Completed"; 335066afe4faSJames Feist } 335132898ceaSJames Feist return task::completed; 335266afe4faSJames Feist }, 3353c5a4c82aSJason M. Bills taskMatchStr); 3354c5a4c82aSJason M. Bills 335546229577SJames Feist task->startTimer(std::chrono::minutes(5)); 335646229577SJames Feist task->populateResp(asyncResp->res); 335798be3e39SEd Tanous task->payload.emplace(std::move(payload)); 33581da66f75SEd Tanous }; 33598e6c099aSJason M. Bills 33601da66f75SEd Tanous crow::connections::systemBus->async_method_call( 3361002d39b4SEd Tanous std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath, 3362002d39b4SEd Tanous iface, method); 33637e860f15SJohn Edward Broadbent }); 33646eda7685SKenny L. Ku } 33656eda7685SKenny L. Ku 3366599b9af3SAlexander Hansen inline void dBusLogServiceActionsClear( 3367599b9af3SAlexander Hansen const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 3368599b9af3SAlexander Hansen { 3369599b9af3SAlexander Hansen BMCWEB_LOG_DEBUG("Do delete all entries."); 3370599b9af3SAlexander Hansen 3371599b9af3SAlexander Hansen // Process response from Logging service. 3372599b9af3SAlexander Hansen auto respHandler = [asyncResp](const boost::system::error_code& ec) { 3373599b9af3SAlexander Hansen BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done"); 3374599b9af3SAlexander Hansen if (ec) 3375599b9af3SAlexander Hansen { 3376599b9af3SAlexander Hansen // TODO Handle for specific error code 3377599b9af3SAlexander Hansen BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec); 3378599b9af3SAlexander Hansen asyncResp->res.result( 3379599b9af3SAlexander Hansen boost::beast::http::status::internal_server_error); 3380599b9af3SAlexander Hansen return; 3381599b9af3SAlexander Hansen } 3382599b9af3SAlexander Hansen 3383599b9af3SAlexander Hansen asyncResp->res.result(boost::beast::http::status::no_content); 3384599b9af3SAlexander Hansen }; 3385599b9af3SAlexander Hansen 3386599b9af3SAlexander Hansen // Make call to Logging service to request Clear Log 3387599b9af3SAlexander Hansen crow::connections::systemBus->async_method_call( 3388599b9af3SAlexander Hansen respHandler, "xyz.openbmc_project.Logging", 3389599b9af3SAlexander Hansen "/xyz/openbmc_project/logging", 3390599b9af3SAlexander Hansen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 3391599b9af3SAlexander Hansen } 3392599b9af3SAlexander Hansen 3393cb92c03bSAndrew Geissler /** 3394cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 3395cb92c03bSAndrew Geissler */ 33967e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 3397cb92c03bSAndrew Geissler { 3398cb92c03bSAndrew Geissler /** 3399cb92c03bSAndrew Geissler * Function handles POST method request. 3400cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3401cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3402cb92c03bSAndrew Geissler */ 34037e860f15SJohn Edward Broadbent 34040fda0f12SGeorge Liu BMCWEB_ROUTE( 34050fda0f12SGeorge Liu app, 340622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 3407ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 34087e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 340945ca1b86SEd Tanous [&app](const crow::Request& req, 341022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 341122d268cbSEd Tanous const std::string& systemName) { 34123ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 341345ca1b86SEd Tanous { 341445ca1b86SEd Tanous return; 341545ca1b86SEd Tanous } 341625b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 34177f3e84a1SEd Tanous { 34187f3e84a1SEd Tanous // Option currently returns no systems. TBD 34197f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 34207f3e84a1SEd Tanous systemName); 34217f3e84a1SEd Tanous return; 34227f3e84a1SEd Tanous } 3423253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 342422d268cbSEd Tanous { 342522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 342622d268cbSEd Tanous systemName); 342722d268cbSEd Tanous return; 342822d268cbSEd Tanous } 3429599b9af3SAlexander Hansen dBusLogServiceActionsClear(asyncResp); 34307e860f15SJohn Edward Broadbent }); 3431cb92c03bSAndrew Geissler } 3432a3316fc6SZhikuiRen 3433a3316fc6SZhikuiRen /**************************************************** 3434a3316fc6SZhikuiRen * Redfish PostCode interfaces 3435a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3436a3316fc6SZhikuiRen ******************************************************/ 34377e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 3438a3316fc6SZhikuiRen { 343922d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/") 3440ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 3441002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3442002d39b4SEd Tanous [&app](const crow::Request& req, 344322d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 344422d268cbSEd Tanous const std::string& systemName) { 34453ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 344645ca1b86SEd Tanous { 344745ca1b86SEd Tanous return; 344845ca1b86SEd Tanous } 344925b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 34507f3e84a1SEd Tanous { 34517f3e84a1SEd Tanous // Option currently returns no systems. TBD 34527f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 34537f3e84a1SEd Tanous systemName); 34547f3e84a1SEd Tanous return; 34557f3e84a1SEd Tanous } 3456253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 345722d268cbSEd Tanous { 345822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 345922d268cbSEd Tanous systemName); 346022d268cbSEd Tanous return; 346122d268cbSEd Tanous } 34621476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3463253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/PostCodes", 3464253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 34651476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 3466b25644a1SJanet Adkins "#LogService.v1_2_0.LogService"; 34671476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "POST Code Log Service"; 34681476687dSEd Tanous asyncResp->res.jsonValue["Description"] = "POST Code Log Service"; 3469ed34a4adSEd Tanous asyncResp->res.jsonValue["Id"] = "PostCodes"; 3470539d8c6bSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = 3471539d8c6bSEd Tanous log_service::OverWritePolicy::WrapsWhenFull; 34721476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 3473253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries", 3474253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 34757c8c4058STejas Patil 34767c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 34772b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 34780fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 34797c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 34807c8c4058STejas Patil redfishDateTimeOffset.second; 34817c8c4058STejas Patil 348220fa6a2cSEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] 348320fa6a2cSEd Tanous ["target"] = std::format( 3484253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/PostCodes/Actions/LogService.ClearLog", 348520fa6a2cSEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 34867e860f15SJohn Edward Broadbent }); 3487a3316fc6SZhikuiRen } 3488a3316fc6SZhikuiRen 34897e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3490a3316fc6SZhikuiRen { 34910fda0f12SGeorge Liu BMCWEB_ROUTE( 34920fda0f12SGeorge Liu app, 349322d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/") 3494ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3495ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3496432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 34977e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 349845ca1b86SEd Tanous [&app](const crow::Request& req, 349922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 350022d268cbSEd Tanous const std::string& systemName) { 35013ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 350245ca1b86SEd Tanous { 350345ca1b86SEd Tanous return; 350445ca1b86SEd Tanous } 350525b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 35067f3e84a1SEd Tanous { 35077f3e84a1SEd Tanous // Option currently returns no systems. TBD 35087f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 35097f3e84a1SEd Tanous systemName); 35107f3e84a1SEd Tanous return; 35117f3e84a1SEd Tanous } 3512253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 351322d268cbSEd Tanous { 351422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 351522d268cbSEd Tanous systemName); 351622d268cbSEd Tanous return; 351722d268cbSEd Tanous } 351862598e31SEd Tanous BMCWEB_LOG_DEBUG("Do delete all postcodes entries."); 3519a3316fc6SZhikuiRen 3520a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3521a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 35225e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 3523a3316fc6SZhikuiRen if (ec) 3524a3316fc6SZhikuiRen { 3525a3316fc6SZhikuiRen // TODO Handle for specific error code 352662598e31SEd Tanous BMCWEB_LOG_ERROR("doClearPostCodes resp_handler got error {}", 352762598e31SEd Tanous ec); 3528002d39b4SEd Tanous asyncResp->res.result( 3529002d39b4SEd Tanous boost::beast::http::status::internal_server_error); 3530a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3531a3316fc6SZhikuiRen return; 3532a3316fc6SZhikuiRen } 353318fc70c0STony Lee messages::success(asyncResp->res); 3534a3316fc6SZhikuiRen }, 353515124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 353615124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3537a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 35387e860f15SJohn Edward Broadbent }); 3539a3316fc6SZhikuiRen } 3540a3316fc6SZhikuiRen 35416f284d24SJiaqing Zhao /** 35426f284d24SJiaqing Zhao * @brief Parse post code ID and get the current value and index value 35436f284d24SJiaqing Zhao * eg: postCodeID=B1-2, currentValue=1, index=2 35446f284d24SJiaqing Zhao * 35456f284d24SJiaqing Zhao * @param[in] postCodeID Post Code ID 35466f284d24SJiaqing Zhao * @param[out] currentValue Current value 35476f284d24SJiaqing Zhao * @param[out] index Index value 35486f284d24SJiaqing Zhao * 35496f284d24SJiaqing Zhao * @return bool true if the parsing is successful, false the parsing fails 35506f284d24SJiaqing Zhao */ 35516f056f24SEd Tanous inline bool parsePostCode(std::string_view postCodeID, uint64_t& currentValue, 3552df254f2cSEd Tanous uint16_t& index) 35536f284d24SJiaqing Zhao { 35546f284d24SJiaqing Zhao std::vector<std::string> split; 355550ebd4afSEd Tanous bmcweb::split(split, postCodeID, '-'); 35566f056f24SEd Tanous if (split.size() != 2) 35576f056f24SEd Tanous { 35586f056f24SEd Tanous return false; 35596f056f24SEd Tanous } 35606f056f24SEd Tanous std::string_view postCodeNumber = split[0]; 35616f056f24SEd Tanous if (postCodeNumber.size() < 2) 35626f056f24SEd Tanous { 35636f056f24SEd Tanous return false; 35646f056f24SEd Tanous } 35656f056f24SEd Tanous if (postCodeNumber[0] != 'B') 35666f056f24SEd Tanous { 35676f056f24SEd Tanous return false; 35686f056f24SEd Tanous } 35696f056f24SEd Tanous postCodeNumber.remove_prefix(1); 35706f056f24SEd Tanous auto [ptrIndex, ecIndex] = std::from_chars(postCodeNumber.begin(), 35716f056f24SEd Tanous postCodeNumber.end(), index); 35726f056f24SEd Tanous if (ptrIndex != postCodeNumber.end() || ecIndex != std::errc()) 35736f284d24SJiaqing Zhao { 35746f284d24SJiaqing Zhao return false; 35756f284d24SJiaqing Zhao } 35766f284d24SJiaqing Zhao 35776f056f24SEd Tanous std::string_view postCodeIndex = split[1]; 35786f284d24SJiaqing Zhao 35796f056f24SEd Tanous auto [ptrValue, ecValue] = std::from_chars( 35806f056f24SEd Tanous postCodeIndex.begin(), postCodeIndex.end(), currentValue); 35816f284d24SJiaqing Zhao 35826f056f24SEd Tanous return ptrValue == postCodeIndex.end() && ecValue == std::errc(); 35836f284d24SJiaqing Zhao } 35846f284d24SJiaqing Zhao 35856f284d24SJiaqing Zhao static bool fillPostCodeEntry( 3586ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 35876c9a279eSManojkiran Eda const boost::container::flat_map< 35886c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3589a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3590a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3591a3316fc6SZhikuiRen { 3592a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3593fffb8c1fSEd Tanous const registries::Message* message = 3594fffb8c1fSEd Tanous registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3595dc8cfa66SEd Tanous if (message == nullptr) 3596dc8cfa66SEd Tanous { 3597dc8cfa66SEd Tanous BMCWEB_LOG_ERROR("Couldn't find known message?"); 3598dc8cfa66SEd Tanous return false; 3599dc8cfa66SEd Tanous } 3600a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3601a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 36026c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 36036c9a279eSManojkiran Eda code : postcode) 3604a3316fc6SZhikuiRen { 3605a3316fc6SZhikuiRen currentCodeIndex++; 3606a3316fc6SZhikuiRen std::string postcodeEntryID = 3607a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3608a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3609a3316fc6SZhikuiRen 3610a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3611a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3612a3316fc6SZhikuiRen 3613a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3614a3316fc6SZhikuiRen { // already incremented 3615a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3616a3316fc6SZhikuiRen } 3617a3316fc6SZhikuiRen else 3618a3316fc6SZhikuiRen { 3619a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3620a3316fc6SZhikuiRen } 3621a3316fc6SZhikuiRen 3622a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3623a3316fc6SZhikuiRen // not fall between top and skip 3624a3316fc6SZhikuiRen if ((codeIndex == 0) && 3625a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3626a3316fc6SZhikuiRen { 3627a3316fc6SZhikuiRen continue; 3628a3316fc6SZhikuiRen } 3629a3316fc6SZhikuiRen 36304e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3631a3316fc6SZhikuiRen // currentIndex 3632a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3633a3316fc6SZhikuiRen { 3634a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3635a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3636a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3637a3316fc6SZhikuiRen continue; 3638a3316fc6SZhikuiRen } 3639a3316fc6SZhikuiRen 3640a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3641a3316fc6SZhikuiRen // index 3642a3316fc6SZhikuiRen 3643a3316fc6SZhikuiRen // Get the Created time from the timestamp 3644a3316fc6SZhikuiRen std::string entryTimeStr; 36452a025611SKonstantin Aladyshev entryTimeStr = redfish::time_utils::getDateTimeUintUs(usecSinceEpoch); 3646a3316fc6SZhikuiRen 3647a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3648a3316fc6SZhikuiRen std::ostringstream hexCode; 3649a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 36506c9a279eSManojkiran Eda << std::get<0>(code.second); 3651a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3652a3316fc6SZhikuiRen // Set Fixed -Point Notation 3653a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3654a3316fc6SZhikuiRen // Set precision to 4 digits 3655a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3656a3316fc6SZhikuiRen // Add double to stream 3657a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3658a3316fc6SZhikuiRen 36591e6deaf6SEd Tanous std::string bootIndexStr = std::to_string(bootIndex); 36601e6deaf6SEd Tanous std::string timeOffsetString = timeOffsetStr.str(); 36611e6deaf6SEd Tanous std::string hexCodeStr = hexCode.str(); 3662a3316fc6SZhikuiRen 36631e6deaf6SEd Tanous std::array<std::string_view, 3> messageArgs = { 36641e6deaf6SEd Tanous bootIndexStr, timeOffsetString, hexCodeStr}; 36651e6deaf6SEd Tanous 36661e6deaf6SEd Tanous std::string msg = 36671e6deaf6SEd Tanous redfish::registries::fillMessageArgs(messageArgs, message->message); 36681e6deaf6SEd Tanous if (msg.empty()) 3669a3316fc6SZhikuiRen { 36701e6deaf6SEd Tanous messages::internalError(asyncResp->res); 36711e6deaf6SEd Tanous return false; 3672a3316fc6SZhikuiRen } 3673a3316fc6SZhikuiRen 3674d4342a92STim Lee // Get Severity template from message registry 3675d4342a92STim Lee std::string severity; 3676d4342a92STim Lee if (message != nullptr) 3677d4342a92STim Lee { 36785f2b84eeSEd Tanous severity = message->messageSeverity; 3679d4342a92STim Lee } 3680d4342a92STim Lee 36816f284d24SJiaqing Zhao // Format entry 36826f284d24SJiaqing Zhao nlohmann::json::object_t bmcLogEntry; 36839c11a172SVijay Lobo bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 3684ef4c65b7SEd Tanous bmcLogEntry["@odata.id"] = boost::urls::format( 3685253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/{}", 3686253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, postcodeEntryID); 368784afc48bSJason M. Bills bmcLogEntry["Name"] = "POST Code Log Entry"; 368884afc48bSJason M. Bills bmcLogEntry["Id"] = postcodeEntryID; 368984afc48bSJason M. Bills bmcLogEntry["Message"] = std::move(msg); 369084afc48bSJason M. Bills bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode"; 36911e6deaf6SEd Tanous bmcLogEntry["MessageArgs"] = messageArgs; 369284afc48bSJason M. Bills bmcLogEntry["EntryType"] = "Event"; 369384afc48bSJason M. Bills bmcLogEntry["Severity"] = std::move(severity); 369484afc48bSJason M. Bills bmcLogEntry["Created"] = entryTimeStr; 3695647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 3696647b3cdcSGeorge Liu { 3697647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 3698253f11b8SEd Tanous std::format( 3699253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/", 3700253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME) + 3701647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 3702647b3cdcSGeorge Liu } 37036f284d24SJiaqing Zhao 37046f284d24SJiaqing Zhao // codeIndex is only specified when querying single entry, return only 37056f284d24SJiaqing Zhao // that entry in this case 37066f284d24SJiaqing Zhao if (codeIndex != 0) 37076f284d24SJiaqing Zhao { 3708ac106bf6SEd Tanous asyncResp->res.jsonValue.update(bmcLogEntry); 37096f284d24SJiaqing Zhao return true; 3710a3316fc6SZhikuiRen } 37116f284d24SJiaqing Zhao 3712ac106bf6SEd Tanous nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 3713b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(bmcLogEntry)); 37146f284d24SJiaqing Zhao } 37156f284d24SJiaqing Zhao 37166f284d24SJiaqing Zhao // Return value is always false when querying multiple entries 37176f284d24SJiaqing Zhao return false; 3718a3316fc6SZhikuiRen } 3719a3316fc6SZhikuiRen 3720ac106bf6SEd Tanous static void 3721ac106bf6SEd Tanous getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 37226f284d24SJiaqing Zhao const std::string& entryId) 3723a3316fc6SZhikuiRen { 37246f284d24SJiaqing Zhao uint16_t bootIndex = 0; 37256f284d24SJiaqing Zhao uint64_t codeIndex = 0; 37266f284d24SJiaqing Zhao if (!parsePostCode(entryId, codeIndex, bootIndex)) 37276f284d24SJiaqing Zhao { 37286f284d24SJiaqing Zhao // Requested ID was not found 3729ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 37306f284d24SJiaqing Zhao return; 37316f284d24SJiaqing Zhao } 37326f284d24SJiaqing Zhao 37336f284d24SJiaqing Zhao if (bootIndex == 0 || codeIndex == 0) 37346f284d24SJiaqing Zhao { 37356f284d24SJiaqing Zhao // 0 is an invalid index 3736ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 37376f284d24SJiaqing Zhao return; 37386f284d24SJiaqing Zhao } 37396f284d24SJiaqing Zhao 3740a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3741ac106bf6SEd Tanous [asyncResp, entryId, bootIndex, 37425e7e2dc5SEd Tanous codeIndex](const boost::system::error_code& ec, 37436c9a279eSManojkiran Eda const boost::container::flat_map< 37446c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 37456c9a279eSManojkiran Eda postcode) { 3746a3316fc6SZhikuiRen if (ec) 3747a3316fc6SZhikuiRen { 374862598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error"); 3749ac106bf6SEd Tanous messages::internalError(asyncResp->res); 3750a3316fc6SZhikuiRen return; 3751a3316fc6SZhikuiRen } 3752a3316fc6SZhikuiRen 3753a3316fc6SZhikuiRen if (postcode.empty()) 3754a3316fc6SZhikuiRen { 3755ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 3756a3316fc6SZhikuiRen return; 3757a3316fc6SZhikuiRen } 3758a3316fc6SZhikuiRen 3759ac106bf6SEd Tanous if (!fillPostCodeEntry(asyncResp, postcode, bootIndex, codeIndex)) 37606f284d24SJiaqing Zhao { 3761ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 37626f284d24SJiaqing Zhao return; 37636f284d24SJiaqing Zhao } 3764a3316fc6SZhikuiRen }, 376515124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 376615124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3767a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3768a3316fc6SZhikuiRen bootIndex); 3769a3316fc6SZhikuiRen } 3770a3316fc6SZhikuiRen 3771ac106bf6SEd Tanous static void 3772ac106bf6SEd Tanous getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3773ac106bf6SEd Tanous const uint16_t bootIndex, const uint16_t bootCount, 3774ac106bf6SEd Tanous const uint64_t entryCount, size_t skip, size_t top) 3775a3316fc6SZhikuiRen { 3776a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3777ac106bf6SEd Tanous [asyncResp, bootIndex, bootCount, entryCount, skip, 37785e7e2dc5SEd Tanous top](const boost::system::error_code& ec, 37796c9a279eSManojkiran Eda const boost::container::flat_map< 37806c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 37816c9a279eSManojkiran Eda postcode) { 3782a3316fc6SZhikuiRen if (ec) 3783a3316fc6SZhikuiRen { 378462598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error"); 3785ac106bf6SEd Tanous messages::internalError(asyncResp->res); 3786a3316fc6SZhikuiRen return; 3787a3316fc6SZhikuiRen } 3788a3316fc6SZhikuiRen 3789a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3790a3316fc6SZhikuiRen if (!postcode.empty()) 3791a3316fc6SZhikuiRen { 3792a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 37933648c8beSEd Tanous if (skip < endCount && (top + skip) > entryCount) 3794a3316fc6SZhikuiRen { 379589492a15SPatrick Williams uint64_t thisBootSkip = std::max(static_cast<uint64_t>(skip), 379689492a15SPatrick Williams entryCount) - 37973648c8beSEd Tanous entryCount; 3798a3316fc6SZhikuiRen uint64_t thisBootTop = 37993648c8beSEd Tanous std::min(static_cast<uint64_t>(top + skip), endCount) - 38003648c8beSEd Tanous entryCount; 3801a3316fc6SZhikuiRen 3802ac106bf6SEd Tanous fillPostCodeEntry(asyncResp, postcode, bootIndex, 0, 3803ac106bf6SEd Tanous thisBootSkip, thisBootTop); 3804a3316fc6SZhikuiRen } 3805ac106bf6SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = endCount; 3806a3316fc6SZhikuiRen } 3807a3316fc6SZhikuiRen 3808a3316fc6SZhikuiRen // continue to previous bootIndex 3809a3316fc6SZhikuiRen if (bootIndex < bootCount) 3810a3316fc6SZhikuiRen { 3811ac106bf6SEd Tanous getPostCodeForBoot(asyncResp, static_cast<uint16_t>(bootIndex + 1), 3812a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3813a3316fc6SZhikuiRen } 381481584abeSJiaqing Zhao else if (skip + top < endCount) 3815a3316fc6SZhikuiRen { 3816ac106bf6SEd Tanous asyncResp->res.jsonValue["Members@odata.nextLink"] = 3817253f11b8SEd Tanous std::format( 3818253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries?$skip=", 3819253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME) + 3820a3316fc6SZhikuiRen std::to_string(skip + top); 3821a3316fc6SZhikuiRen } 3822a3316fc6SZhikuiRen }, 382315124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 382415124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3825a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3826a3316fc6SZhikuiRen bootIndex); 3827a3316fc6SZhikuiRen } 3828a3316fc6SZhikuiRen 38298d1b46d7Szhanghch05 static void 3830ac106bf6SEd Tanous getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 38313648c8beSEd Tanous size_t skip, size_t top) 3832a3316fc6SZhikuiRen { 3833a3316fc6SZhikuiRen uint64_t entryCount = 0; 38341e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint16_t>( 38351e1e598dSJonathan Doman *crow::connections::systemBus, 38361e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 38371e1e598dSJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 38381e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", 3839ac106bf6SEd Tanous [asyncResp, entryCount, skip, top](const boost::system::error_code& ec, 38401e1e598dSJonathan Doman const uint16_t bootCount) { 3841a3316fc6SZhikuiRen if (ec) 3842a3316fc6SZhikuiRen { 384362598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 3844ac106bf6SEd Tanous messages::internalError(asyncResp->res); 3845a3316fc6SZhikuiRen return; 3846a3316fc6SZhikuiRen } 3847ac106bf6SEd Tanous getPostCodeForBoot(asyncResp, 1, bootCount, entryCount, skip, top); 38481e1e598dSJonathan Doman }); 3849a3316fc6SZhikuiRen } 3850a3316fc6SZhikuiRen 38517e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3852a3316fc6SZhikuiRen { 38537e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 385422d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/") 3855ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 38567e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 385745ca1b86SEd Tanous [&app](const crow::Request& req, 385822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 385922d268cbSEd Tanous const std::string& systemName) { 3860c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 3861c937d2bfSEd Tanous .canDelegateTop = true, 3862c937d2bfSEd Tanous .canDelegateSkip = true, 3863c937d2bfSEd Tanous }; 3864c937d2bfSEd Tanous query_param::Query delegatedQuery; 3865c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 38663ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 386745ca1b86SEd Tanous { 386845ca1b86SEd Tanous return; 386945ca1b86SEd Tanous } 387025b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 38717f3e84a1SEd Tanous { 38727f3e84a1SEd Tanous // Option currently returns no systems. TBD 38737f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 38747f3e84a1SEd Tanous systemName); 38757f3e84a1SEd Tanous return; 38767f3e84a1SEd Tanous } 387722d268cbSEd Tanous 3878253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 387922d268cbSEd Tanous { 388022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 388122d268cbSEd Tanous systemName); 388222d268cbSEd Tanous return; 388322d268cbSEd Tanous } 3884a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3885a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3886a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3887253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries", 3888253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3889a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3890a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3891a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3892a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3893a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 38943648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 38955143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 38963648c8beSEd Tanous getCurrentBootNumber(asyncResp, skip, top); 38977e860f15SJohn Edward Broadbent }); 3898a3316fc6SZhikuiRen } 3899a3316fc6SZhikuiRen 3900647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3901647b3cdcSGeorge Liu { 39020fda0f12SGeorge Liu BMCWEB_ROUTE( 39030fda0f12SGeorge Liu app, 390422d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/") 3905647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 3906647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 390745ca1b86SEd Tanous [&app](const crow::Request& req, 3908647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 390922d268cbSEd Tanous const std::string& systemName, 3910647b3cdcSGeorge Liu const std::string& postCodeID) { 39113ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 391245ca1b86SEd Tanous { 391345ca1b86SEd Tanous return; 391445ca1b86SEd Tanous } 391572e21377SMatt Spinler if (!http_helpers::isContentTypeAllowed( 391699351cd8SEd Tanous req.getHeaderValue("Accept"), 39174a0e1a0cSEd Tanous http_helpers::ContentType::OctetStream, true)) 3918647b3cdcSGeorge Liu { 3919002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 3920647b3cdcSGeorge Liu return; 3921647b3cdcSGeorge Liu } 392225b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 39237f3e84a1SEd Tanous { 39247f3e84a1SEd Tanous // Option currently returns no systems. TBD 39257f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 39267f3e84a1SEd Tanous systemName); 39277f3e84a1SEd Tanous return; 39287f3e84a1SEd Tanous } 3929253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 393022d268cbSEd Tanous { 393122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 393222d268cbSEd Tanous systemName); 393322d268cbSEd Tanous return; 393422d268cbSEd Tanous } 3935647b3cdcSGeorge Liu 3936647b3cdcSGeorge Liu uint64_t currentValue = 0; 3937647b3cdcSGeorge Liu uint16_t index = 0; 3938647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 3939647b3cdcSGeorge Liu { 3940002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID); 3941647b3cdcSGeorge Liu return; 3942647b3cdcSGeorge Liu } 3943647b3cdcSGeorge Liu 3944647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 3945647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 39465e7e2dc5SEd Tanous const boost::system::error_code& ec, 3947002d39b4SEd Tanous const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>& 3948002d39b4SEd Tanous postcodes) { 3949647b3cdcSGeorge Liu if (ec.value() == EBADR) 3950647b3cdcSGeorge Liu { 3951002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 3952002d39b4SEd Tanous postCodeID); 3953647b3cdcSGeorge Liu return; 3954647b3cdcSGeorge Liu } 3955647b3cdcSGeorge Liu if (ec) 3956647b3cdcSGeorge Liu { 395762598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 3958647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 3959647b3cdcSGeorge Liu return; 3960647b3cdcSGeorge Liu } 3961647b3cdcSGeorge Liu 3962647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 3963002d39b4SEd Tanous if (value == std::string::npos || postcodes.size() < currentValue) 3964647b3cdcSGeorge Liu { 396562598e31SEd Tanous BMCWEB_LOG_WARNING("Wrong currentValue value"); 3966002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 3967002d39b4SEd Tanous postCodeID); 3968647b3cdcSGeorge Liu return; 3969647b3cdcSGeorge Liu } 3970647b3cdcSGeorge Liu 39719eb808c1SEd Tanous const auto& [tID, c] = postcodes[value]; 397246ff87baSEd Tanous if (c.empty()) 3973647b3cdcSGeorge Liu { 397462598e31SEd Tanous BMCWEB_LOG_WARNING("No found post code data"); 3975002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 3976002d39b4SEd Tanous postCodeID); 3977647b3cdcSGeorge Liu return; 3978647b3cdcSGeorge Liu } 397946ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 398046ff87baSEd Tanous const char* d = reinterpret_cast<const char*>(c.data()); 398146ff87baSEd Tanous std::string_view strData(d, c.size()); 3982647b3cdcSGeorge Liu 3983d9f6c621SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::content_type, 3984647b3cdcSGeorge Liu "application/octet-stream"); 3985d9f6c621SEd Tanous asyncResp->res.addHeader( 3986d9f6c621SEd Tanous boost::beast::http::field::content_transfer_encoding, "Base64"); 398727b0cf90SEd Tanous asyncResp->res.write(crow::utility::base64encode(strData)); 3988647b3cdcSGeorge Liu }, 3989647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 3990647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 3991002d39b4SEd Tanous "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index); 3992647b3cdcSGeorge Liu }); 3993647b3cdcSGeorge Liu } 3994647b3cdcSGeorge Liu 39957e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 3996a3316fc6SZhikuiRen { 39977e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 399822d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/") 3999ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 40007e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 400145ca1b86SEd Tanous [&app](const crow::Request& req, 40027e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 400322d268cbSEd Tanous const std::string& systemName, const std::string& targetID) { 40043ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 400545ca1b86SEd Tanous { 400645ca1b86SEd Tanous return; 400745ca1b86SEd Tanous } 400825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 40097f3e84a1SEd Tanous { 40107f3e84a1SEd Tanous // Option currently returns no systems. TBD 40117f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 40127f3e84a1SEd Tanous systemName); 40137f3e84a1SEd Tanous return; 40147f3e84a1SEd Tanous } 4015253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 401622d268cbSEd Tanous { 401722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 401822d268cbSEd Tanous systemName); 401922d268cbSEd Tanous return; 402022d268cbSEd Tanous } 402122d268cbSEd Tanous 40226f284d24SJiaqing Zhao getPostCodeForEntry(asyncResp, targetID); 40237e860f15SJohn Edward Broadbent }); 4024a3316fc6SZhikuiRen } 4025a3316fc6SZhikuiRen 40261da66f75SEd Tanous } // namespace redfish 4027