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" 22*539d8c6bSEd 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"; 1245*539d8c6bSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = 1246*539d8c6bSEd 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 12667e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1267489640c6SJason M. Bills { 12684978b63fSJason M. Bills BMCWEB_ROUTE( 12694978b63fSJason M. Bills app, 127022d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 1271432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 12727e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 127345ca1b86SEd Tanous [&app](const crow::Request& req, 127422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 127522d268cbSEd Tanous const std::string& systemName) { 12763ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 127745ca1b86SEd Tanous { 127845ca1b86SEd Tanous return; 127945ca1b86SEd Tanous } 1280253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 128122d268cbSEd Tanous { 128222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 128322d268cbSEd Tanous systemName); 128422d268cbSEd Tanous return; 128522d268cbSEd Tanous } 1286489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1287489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1288489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1289489640c6SJason M. Bills { 1290489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1291489640c6SJason M. Bills { 1292489640c6SJason M. Bills std::error_code ec; 1293489640c6SJason M. Bills std::filesystem::remove(file, ec); 1294489640c6SJason M. Bills } 1295489640c6SJason M. Bills } 1296489640c6SJason M. Bills 1297489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1298489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 12995e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 1300489640c6SJason M. Bills if (ec) 1301489640c6SJason M. Bills { 130262598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to reload rsyslog: {}", ec); 1303489640c6SJason M. Bills messages::internalError(asyncResp->res); 1304489640c6SJason M. Bills return; 1305489640c6SJason M. Bills } 1306489640c6SJason M. Bills 1307489640c6SJason M. Bills messages::success(asyncResp->res); 1308489640c6SJason M. Bills }, 1309489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1310002d39b4SEd Tanous "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1311002d39b4SEd Tanous "replace"); 13127e860f15SJohn Edward Broadbent }); 1313c4bf6374SJason M. Bills } 1314c4bf6374SJason M. Bills 1315ac992cdeSJason M. Bills enum class LogParseError 1316ac992cdeSJason M. Bills { 1317ac992cdeSJason M. Bills success, 1318ac992cdeSJason M. Bills parseFailed, 1319ac992cdeSJason M. Bills messageIdNotInRegistry, 1320ac992cdeSJason M. Bills }; 1321ac992cdeSJason M. Bills 1322ac992cdeSJason M. Bills static LogParseError 1323ac992cdeSJason M. Bills fillEventLogEntryJson(const std::string& logEntryID, 1324b5a76932SEd Tanous const std::string& logEntry, 1325de703c5dSJason M. Bills nlohmann::json::object_t& logEntryJson) 1326c4bf6374SJason M. Bills { 132795820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1328cd225da8SJason M. Bills // First get the Timestamp 1329f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1330cd225da8SJason M. Bills if (space == std::string::npos) 133195820184SJason M. Bills { 1332ac992cdeSJason M. Bills return LogParseError::parseFailed; 133395820184SJason M. Bills } 1334cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1335cd225da8SJason M. Bills // Then get the log contents 1336f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1337cd225da8SJason M. Bills if (entryStart == std::string::npos) 1338cd225da8SJason M. Bills { 1339ac992cdeSJason M. Bills return LogParseError::parseFailed; 1340cd225da8SJason M. Bills } 1341cd225da8SJason M. Bills std::string_view entry(logEntry); 1342cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1343cd225da8SJason M. Bills // Use split to separate the entry into its fields 1344cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 134550ebd4afSEd Tanous bmcweb::split(logEntryFields, entry, ','); 1346cd225da8SJason M. Bills // We need at least a MessageId to be valid 13471e6deaf6SEd Tanous auto logEntryIter = logEntryFields.begin(); 13481e6deaf6SEd Tanous if (logEntryIter == logEntryFields.end()) 1349cd225da8SJason M. Bills { 1350ac992cdeSJason M. Bills return LogParseError::parseFailed; 1351cd225da8SJason M. Bills } 13521e6deaf6SEd Tanous std::string& messageID = *logEntryIter; 13534851d45dSJason M. Bills // Get the Message from the MessageRegistry 1354fffb8c1fSEd Tanous const registries::Message* message = registries::getMessage(messageID); 1355c4bf6374SJason M. Bills 13561e6deaf6SEd Tanous logEntryIter++; 135754417b02SSui Chen if (message == nullptr) 1358c4bf6374SJason M. Bills { 135962598e31SEd Tanous BMCWEB_LOG_WARNING("Log entry not found in registry: {}", logEntry); 1360ac992cdeSJason M. Bills return LogParseError::messageIdNotInRegistry; 1361c4bf6374SJason M. Bills } 1362c4bf6374SJason M. Bills 13631e6deaf6SEd Tanous std::vector<std::string_view> messageArgs(logEntryIter, 13641e6deaf6SEd Tanous logEntryFields.end()); 1365c05bba45SEd Tanous messageArgs.resize(message->numberOfArgs); 1366c05bba45SEd Tanous 13671e6deaf6SEd Tanous std::string msg = redfish::registries::fillMessageArgs(messageArgs, 13681e6deaf6SEd Tanous message->message); 13691e6deaf6SEd Tanous if (msg.empty()) 137015a86ff6SJason M. Bills { 13711e6deaf6SEd Tanous return LogParseError::parseFailed; 137215a86ff6SJason M. Bills } 13734851d45dSJason M. Bills 137495820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 137595820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 137695820184SJason M. Bills // between the '.' and the '+', so just remove them. 1377f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1378f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 137995820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1380c4bf6374SJason M. Bills { 138195820184SJason M. Bills timestamp.erase(dot, plus - dot); 1382c4bf6374SJason M. Bills } 1383c4bf6374SJason M. Bills 1384c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 13859c11a172SVijay Lobo logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 1386ef4c65b7SEd Tanous logEntryJson["@odata.id"] = boost::urls::format( 1387253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}", 1388253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID); 138984afc48bSJason M. Bills logEntryJson["Name"] = "System Event Log Entry"; 139084afc48bSJason M. Bills logEntryJson["Id"] = logEntryID; 139184afc48bSJason M. Bills logEntryJson["Message"] = std::move(msg); 139284afc48bSJason M. Bills logEntryJson["MessageId"] = std::move(messageID); 139384afc48bSJason M. Bills logEntryJson["MessageArgs"] = messageArgs; 139484afc48bSJason M. Bills logEntryJson["EntryType"] = "Event"; 139584afc48bSJason M. Bills logEntryJson["Severity"] = message->messageSeverity; 139684afc48bSJason M. Bills logEntryJson["Created"] = std::move(timestamp); 1397ac992cdeSJason M. Bills return LogParseError::success; 1398c4bf6374SJason M. Bills } 1399c4bf6374SJason M. Bills 14007e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1401c4bf6374SJason M. Bills { 140222d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") 14038b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 1404002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1405002d39b4SEd Tanous [&app](const crow::Request& req, 140622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 140722d268cbSEd Tanous const std::string& systemName) { 1408c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1409c937d2bfSEd Tanous .canDelegateTop = true, 1410c937d2bfSEd Tanous .canDelegateSkip = true, 1411c937d2bfSEd Tanous }; 1412c937d2bfSEd Tanous query_param::Query delegatedQuery; 1413c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 14143ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 1415c4bf6374SJason M. Bills { 1416c4bf6374SJason M. Bills return; 1417c4bf6374SJason M. Bills } 141825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 14197f3e84a1SEd Tanous { 14207f3e84a1SEd Tanous // Option currently returns no systems. TBD 14217f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 14227f3e84a1SEd Tanous systemName); 14237f3e84a1SEd Tanous return; 14247f3e84a1SEd Tanous } 1425253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 142622d268cbSEd Tanous { 142722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 142822d268cbSEd Tanous systemName); 142922d268cbSEd Tanous return; 143022d268cbSEd Tanous } 143122d268cbSEd Tanous 14325143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 14333648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 14343648c8beSEd Tanous 14357e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 14367e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1437c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1438c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1439c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1440253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries", 1441253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 1442c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1443c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1444c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1445cb92c03bSAndrew Geissler 14464978b63fSJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1447c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 14487e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 14497e860f15SJohn Edward Broadbent // entry 145095820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 145195820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1452b01bf299SEd Tanous uint64_t entryCount = 0; 1453cd225da8SJason M. Bills std::string logEntry; 145495820184SJason M. Bills 14557e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 14567e860f15SJohn Edward Broadbent // backwards 1457002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1458002d39b4SEd Tanous it++) 1459c4bf6374SJason M. Bills { 1460cd225da8SJason M. Bills std::ifstream logStream(*it); 146195820184SJason M. Bills if (!logStream.is_open()) 1462c4bf6374SJason M. Bills { 1463c4bf6374SJason M. Bills continue; 1464c4bf6374SJason M. Bills } 1465c4bf6374SJason M. Bills 1466e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1467e85d6b16SJason M. Bills bool firstEntry = true; 146895820184SJason M. Bills while (std::getline(logStream, logEntry)) 146995820184SJason M. Bills { 1470c4bf6374SJason M. Bills std::string idStr; 1471e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1472c4bf6374SJason M. Bills { 1473c4bf6374SJason M. Bills continue; 1474c4bf6374SJason M. Bills } 1475e85d6b16SJason M. Bills firstEntry = false; 1476e85d6b16SJason M. Bills 1477de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 147889492a15SPatrick Williams LogParseError status = fillEventLogEntryJson(idStr, logEntry, 147989492a15SPatrick Williams bmcLogEntry); 1480ac992cdeSJason M. Bills if (status == LogParseError::messageIdNotInRegistry) 1481ac992cdeSJason M. Bills { 1482ac992cdeSJason M. Bills continue; 1483ac992cdeSJason M. Bills } 1484ac992cdeSJason M. Bills if (status != LogParseError::success) 1485c4bf6374SJason M. Bills { 1486c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1487c4bf6374SJason M. Bills return; 1488c4bf6374SJason M. Bills } 1489de703c5dSJason M. Bills 1490de703c5dSJason M. Bills entryCount++; 1491de703c5dSJason M. Bills // Handle paging using skip (number of entries to skip from the 1492de703c5dSJason M. Bills // start) and top (number of entries to display) 14933648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 1494de703c5dSJason M. Bills { 1495de703c5dSJason M. Bills continue; 1496de703c5dSJason M. Bills } 1497de703c5dSJason M. Bills 1498b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(bmcLogEntry)); 1499c4bf6374SJason M. Bills } 150095820184SJason M. Bills } 1501c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 15023648c8beSEd Tanous if (skip + top < entryCount) 1503c4bf6374SJason M. Bills { 1504253f11b8SEd Tanous asyncResp->res 1505253f11b8SEd Tanous .jsonValue["Members@odata.nextLink"] = boost::urls::format( 1506253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Entries?$skip={}", 1507253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(skip + top)); 1508c4bf6374SJason M. Bills } 15097e860f15SJohn Edward Broadbent }); 1510897967deSJason M. Bills } 1511897967deSJason M. Bills 15127e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1513897967deSJason M. Bills { 15147e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 151522d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1516ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 15177e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 151845ca1b86SEd Tanous [&app](const crow::Request& req, 15197e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 152022d268cbSEd Tanous const std::string& systemName, const std::string& param) { 15213ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 152245ca1b86SEd Tanous { 152345ca1b86SEd Tanous return; 152445ca1b86SEd Tanous } 152525b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 15267f3e84a1SEd Tanous { 15277f3e84a1SEd Tanous // Option currently returns no systems. TBD 15287f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 15297f3e84a1SEd Tanous systemName); 15307f3e84a1SEd Tanous return; 15317f3e84a1SEd Tanous } 153222d268cbSEd Tanous 1533253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 153422d268cbSEd Tanous { 153522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 153622d268cbSEd Tanous systemName); 153722d268cbSEd Tanous return; 153822d268cbSEd Tanous } 153922d268cbSEd Tanous 15407e860f15SJohn Edward Broadbent const std::string& targetID = param; 15418d1b46d7Szhanghch05 15427e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 15437e860f15SJohn Edward Broadbent // entry to find the target entry 1544897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1545897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1546897967deSJason M. Bills std::string logEntry; 1547897967deSJason M. Bills 15487e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 15497e860f15SJohn Edward Broadbent // backwards 1550002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1551002d39b4SEd Tanous it++) 1552897967deSJason M. Bills { 1553897967deSJason M. Bills std::ifstream logStream(*it); 1554897967deSJason M. Bills if (!logStream.is_open()) 1555897967deSJason M. Bills { 1556897967deSJason M. Bills continue; 1557897967deSJason M. Bills } 1558897967deSJason M. Bills 1559897967deSJason M. Bills // Reset the unique ID on the first entry 1560897967deSJason M. Bills bool firstEntry = true; 1561897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1562897967deSJason M. Bills { 1563897967deSJason M. Bills std::string idStr; 1564897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1565897967deSJason M. Bills { 1566897967deSJason M. Bills continue; 1567897967deSJason M. Bills } 1568897967deSJason M. Bills firstEntry = false; 1569897967deSJason M. Bills 1570897967deSJason M. Bills if (idStr == targetID) 1571897967deSJason M. Bills { 1572de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 1573ac992cdeSJason M. Bills LogParseError status = 1574ac992cdeSJason M. Bills fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); 1575ac992cdeSJason M. Bills if (status != LogParseError::success) 1576897967deSJason M. Bills { 1577897967deSJason M. Bills messages::internalError(asyncResp->res); 1578897967deSJason M. Bills return; 1579897967deSJason M. Bills } 1580d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcLogEntry); 1581897967deSJason M. Bills return; 1582897967deSJason M. Bills } 1583897967deSJason M. Bills } 1584897967deSJason M. Bills } 1585897967deSJason M. Bills // Requested ID was not found 15869db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", targetID); 15877e860f15SJohn Edward Broadbent }); 158808a4e4b5SAnthony Wilson } 158908a4e4b5SAnthony Wilson 15907e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 159108a4e4b5SAnthony Wilson { 159222d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") 1593ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 1594002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1595002d39b4SEd Tanous [&app](const crow::Request& req, 159622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 159722d268cbSEd Tanous const std::string& systemName) { 15983ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 159945ca1b86SEd Tanous { 160045ca1b86SEd Tanous return; 160145ca1b86SEd Tanous } 160225b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 16037f3e84a1SEd Tanous { 16047f3e84a1SEd Tanous // Option currently returns no systems. TBD 16057f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 16067f3e84a1SEd Tanous systemName); 16077f3e84a1SEd Tanous return; 16087f3e84a1SEd Tanous } 1609253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 161022d268cbSEd Tanous { 161122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 161222d268cbSEd Tanous systemName); 161322d268cbSEd Tanous return; 161422d268cbSEd Tanous } 161522d268cbSEd Tanous 16167e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 16177e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 161808a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 161908a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 162008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 1621253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries", 1622253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 162308a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 162408a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 162508a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 162608a4e4b5SAnthony Wilson 1627cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1628cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 16295eb468daSGeorge Liu sdbusplus::message::object_path path("/xyz/openbmc_project/logging"); 16305eb468daSGeorge Liu dbus::utility::getManagedObjects( 16315eb468daSGeorge Liu "xyz.openbmc_project.Logging", path, 16325e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 1633914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& resp) { 1634cb92c03bSAndrew Geissler if (ec) 1635cb92c03bSAndrew Geissler { 1636cb92c03bSAndrew Geissler // TODO Handle for specific error code 163762598e31SEd Tanous BMCWEB_LOG_ERROR( 163862598e31SEd Tanous "getLogEntriesIfaceData resp_handler got error {}", ec); 1639cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1640cb92c03bSAndrew Geissler return; 1641cb92c03bSAndrew Geissler } 16423544d2a7SEd Tanous nlohmann::json::array_t entriesArray; 16439eb808c1SEd Tanous for (const auto& objectPath : resp) 1644cb92c03bSAndrew Geissler { 1645914e2d5dSEd Tanous const uint32_t* id = nullptr; 1646c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1647c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1648914e2d5dSEd Tanous const std::string* severity = nullptr; 1649914e2d5dSEd Tanous const std::string* message = nullptr; 1650914e2d5dSEd Tanous const std::string* filePath = nullptr; 16519c11a172SVijay Lobo const std::string* resolution = nullptr; 165275710de2SXiaochao Ma bool resolved = false; 16539017faf2SAbhishek Patel const std::string* notify = nullptr; 16549017faf2SAbhishek Patel 16559eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 1656f86bb901SAdriana Kobylak { 1657f86bb901SAdriana Kobylak if (interfaceMap.first == 1658f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1659f86bb901SAdriana Kobylak { 1660002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 1661cb92c03bSAndrew Geissler { 1662cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1663cb92c03bSAndrew Geissler { 1664002d39b4SEd Tanous id = std::get_if<uint32_t>(&propertyMap.second); 1665cb92c03bSAndrew Geissler } 1666cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1667cb92c03bSAndrew Geissler { 1668002d39b4SEd Tanous timestamp = 1669002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 16707e860f15SJohn Edward Broadbent } 1671002d39b4SEd Tanous else if (propertyMap.first == "UpdateTimestamp") 16727e860f15SJohn Edward Broadbent { 1673002d39b4SEd Tanous updateTimestamp = 1674002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 16757e860f15SJohn Edward Broadbent } 16767e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 16777e860f15SJohn Edward Broadbent { 16787e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 16797e860f15SJohn Edward Broadbent &propertyMap.second); 16807e860f15SJohn Edward Broadbent } 16819c11a172SVijay Lobo else if (propertyMap.first == "Resolution") 16829c11a172SVijay Lobo { 16839c11a172SVijay Lobo resolution = std::get_if<std::string>( 16849c11a172SVijay Lobo &propertyMap.second); 16859c11a172SVijay Lobo } 16867e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 16877e860f15SJohn Edward Broadbent { 16887e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 16897e860f15SJohn Edward Broadbent &propertyMap.second); 16907e860f15SJohn Edward Broadbent } 16917e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 16927e860f15SJohn Edward Broadbent { 1693914e2d5dSEd Tanous const bool* resolveptr = 1694002d39b4SEd Tanous std::get_if<bool>(&propertyMap.second); 16957e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 16967e860f15SJohn Edward Broadbent { 1697002d39b4SEd Tanous messages::internalError(asyncResp->res); 16987e860f15SJohn Edward Broadbent return; 16997e860f15SJohn Edward Broadbent } 17007e860f15SJohn Edward Broadbent resolved = *resolveptr; 17017e860f15SJohn Edward Broadbent } 17029017faf2SAbhishek Patel else if (propertyMap.first == 17039017faf2SAbhishek Patel "ServiceProviderNotify") 17049017faf2SAbhishek Patel { 17059017faf2SAbhishek Patel notify = std::get_if<std::string>( 17069017faf2SAbhishek Patel &propertyMap.second); 17079017faf2SAbhishek Patel if (notify == nullptr) 17089017faf2SAbhishek Patel { 17099017faf2SAbhishek Patel messages::internalError(asyncResp->res); 17109017faf2SAbhishek Patel return; 17119017faf2SAbhishek Patel } 17129017faf2SAbhishek Patel } 17137e860f15SJohn Edward Broadbent } 17147e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 17157e860f15SJohn Edward Broadbent severity == nullptr) 17167e860f15SJohn Edward Broadbent { 17177e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 17187e860f15SJohn Edward Broadbent return; 17197e860f15SJohn Edward Broadbent } 17207e860f15SJohn Edward Broadbent } 17217e860f15SJohn Edward Broadbent else if (interfaceMap.first == 17227e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 17237e860f15SJohn Edward Broadbent { 1724002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 17257e860f15SJohn Edward Broadbent { 17267e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 17277e860f15SJohn Edward Broadbent { 17287e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 17297e860f15SJohn Edward Broadbent &propertyMap.second); 17307e860f15SJohn Edward Broadbent } 17317e860f15SJohn Edward Broadbent } 17327e860f15SJohn Edward Broadbent } 17337e860f15SJohn Edward Broadbent } 17347e860f15SJohn Edward Broadbent // Object path without the 17357e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 17367e860f15SJohn Edward Broadbent // and continue. 17377e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 1738c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1739c419c759SEd Tanous updateTimestamp == nullptr) 17407e860f15SJohn Edward Broadbent { 17417e860f15SJohn Edward Broadbent continue; 17427e860f15SJohn Edward Broadbent } 17433544d2a7SEd Tanous nlohmann::json& thisEntry = entriesArray.emplace_back(); 17449c11a172SVijay Lobo thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 1745ef4c65b7SEd Tanous thisEntry["@odata.id"] = boost::urls::format( 1746253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}", 1747253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(*id)); 17487e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 17497e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 17507e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 17517e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 17529c11a172SVijay Lobo if ((resolution != nullptr) && (!(*resolution).empty())) 17539c11a172SVijay Lobo { 17549c11a172SVijay Lobo thisEntry["Resolution"] = *resolution; 17559c11a172SVijay Lobo } 17569017faf2SAbhishek Patel std::optional<bool> notifyAction = 17579017faf2SAbhishek Patel getProviderNotifyAction(*notify); 17589017faf2SAbhishek Patel if (notifyAction) 17599017faf2SAbhishek Patel { 17609017faf2SAbhishek Patel thisEntry["ServiceProviderNotified"] = *notifyAction; 17619017faf2SAbhishek Patel } 17627e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 17637e860f15SJohn Edward Broadbent thisEntry["Severity"] = 17647e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 17657e860f15SJohn Edward Broadbent thisEntry["Created"] = 17662b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*timestamp); 17677e860f15SJohn Edward Broadbent thisEntry["Modified"] = 17682b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*updateTimestamp); 17697e860f15SJohn Edward Broadbent if (filePath != nullptr) 17707e860f15SJohn Edward Broadbent { 17717e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 1772253f11b8SEd Tanous std::format( 1773253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/", 1774253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME) + 17757e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 17767e860f15SJohn Edward Broadbent } 17777e860f15SJohn Edward Broadbent } 17783544d2a7SEd Tanous std::ranges::sort(entriesArray, [](const nlohmann::json& left, 17793544d2a7SEd Tanous const nlohmann::json& right) { 17807e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 17817e860f15SJohn Edward Broadbent }); 17827e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 17837e860f15SJohn Edward Broadbent entriesArray.size(); 17843544d2a7SEd Tanous asyncResp->res.jsonValue["Members"] = std::move(entriesArray); 17855eb468daSGeorge Liu }); 17867e860f15SJohn Edward Broadbent }); 17877e860f15SJohn Edward Broadbent } 17887e860f15SJohn Edward Broadbent 17897e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 17907e860f15SJohn Edward Broadbent { 17917e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 179222d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1793ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 1794002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1795002d39b4SEd Tanous [&app](const crow::Request& req, 17967e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 179722d268cbSEd Tanous const std::string& systemName, const std::string& param) { 17983ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 17997e860f15SJohn Edward Broadbent { 180045ca1b86SEd Tanous return; 180145ca1b86SEd Tanous } 180225b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 18037f3e84a1SEd Tanous { 18047f3e84a1SEd Tanous // Option currently returns no systems. TBD 18057f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 18067f3e84a1SEd Tanous systemName); 18077f3e84a1SEd Tanous return; 18087f3e84a1SEd Tanous } 1809253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 181022d268cbSEd Tanous { 181122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 181222d268cbSEd Tanous systemName); 181322d268cbSEd Tanous return; 181422d268cbSEd Tanous } 181522d268cbSEd Tanous 18167e860f15SJohn Edward Broadbent std::string entryID = param; 18177e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 18187e860f15SJohn Edward Broadbent 18197e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 18207e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 1821d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1822d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, "xyz.openbmc_project.Logging", 1823d1bde9e5SKrzysztof Grobelny "/xyz/openbmc_project/logging/entry/" + entryID, "", 18245e7e2dc5SEd Tanous [asyncResp, entryID](const boost::system::error_code& ec, 1825b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 18267e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 18277e860f15SJohn Edward Broadbent { 1828d1bde9e5SKrzysztof Grobelny messages::resourceNotFound(asyncResp->res, "EventLogEntry", 1829d1bde9e5SKrzysztof Grobelny entryID); 18307e860f15SJohn Edward Broadbent return; 18317e860f15SJohn Edward Broadbent } 18327e860f15SJohn Edward Broadbent if (ec) 18337e860f15SJohn Edward Broadbent { 183462598e31SEd Tanous BMCWEB_LOG_ERROR( 183562598e31SEd Tanous "EventLogEntry (DBus) resp_handler got error {}", ec); 18367e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 18377e860f15SJohn Edward Broadbent return; 18387e860f15SJohn Edward Broadbent } 1839914e2d5dSEd Tanous const uint32_t* id = nullptr; 1840c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1841c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1842914e2d5dSEd Tanous const std::string* severity = nullptr; 1843914e2d5dSEd Tanous const std::string* message = nullptr; 1844914e2d5dSEd Tanous const std::string* filePath = nullptr; 18459c11a172SVijay Lobo const std::string* resolution = nullptr; 18467e860f15SJohn Edward Broadbent bool resolved = false; 18479017faf2SAbhishek Patel const std::string* notify = nullptr; 18487e860f15SJohn Edward Broadbent 1849d1bde9e5SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1850d1bde9e5SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), resp, "Id", id, "Timestamp", 1851d1bde9e5SKrzysztof Grobelny timestamp, "UpdateTimestamp", updateTimestamp, "Severity", 18529c11a172SVijay Lobo severity, "Message", message, "Resolved", resolved, 18539017faf2SAbhishek Patel "Resolution", resolution, "Path", filePath, 18549017faf2SAbhishek Patel "ServiceProviderNotify", notify); 1855d1bde9e5SKrzysztof Grobelny 1856d1bde9e5SKrzysztof Grobelny if (!success) 185775710de2SXiaochao Ma { 185875710de2SXiaochao Ma messages::internalError(asyncResp->res); 185975710de2SXiaochao Ma return; 186075710de2SXiaochao Ma } 1861d1bde9e5SKrzysztof Grobelny 1862002d39b4SEd Tanous if (id == nullptr || message == nullptr || severity == nullptr || 18639017faf2SAbhishek Patel timestamp == nullptr || updateTimestamp == nullptr || 18649017faf2SAbhishek Patel notify == nullptr) 1865f86bb901SAdriana Kobylak { 1866ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1867271584abSEd Tanous return; 1868271584abSEd Tanous } 18699017faf2SAbhishek Patel 1870f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 18719c11a172SVijay Lobo "#LogEntry.v1_9_0.LogEntry"; 1872ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 1873253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}", 1874253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(*id)); 187545ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Event Log Entry"; 1876f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1877f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1878f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 18799017faf2SAbhishek Patel std::optional<bool> notifyAction = getProviderNotifyAction(*notify); 18809017faf2SAbhishek Patel if (notifyAction) 18819017faf2SAbhishek Patel { 18829017faf2SAbhishek Patel asyncResp->res.jsonValue["ServiceProviderNotified"] = 18839017faf2SAbhishek Patel *notifyAction; 18849017faf2SAbhishek Patel } 18859c11a172SVijay Lobo if ((resolution != nullptr) && (!(*resolution).empty())) 18869c11a172SVijay Lobo { 18879c11a172SVijay Lobo asyncResp->res.jsonValue["Resolution"] = *resolution; 18889c11a172SVijay Lobo } 1889f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1890f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1891f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1892f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 18932b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*timestamp); 1894f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 18952b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*updateTimestamp); 1896f86bb901SAdriana Kobylak if (filePath != nullptr) 1897f86bb901SAdriana Kobylak { 1898f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 1899253f11b8SEd Tanous std::format( 1900253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/EventLog/Entries/", 1901253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME) + 1902e7dbd530SPotin Lai std::to_string(*id) + "/attachment"; 1903f86bb901SAdriana Kobylak } 1904d1bde9e5SKrzysztof Grobelny }); 19057e860f15SJohn Edward Broadbent }); 1906336e96c6SChicago Duan 19077e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 190822d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1909ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 19107e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 191145ca1b86SEd Tanous [&app](const crow::Request& req, 19127e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 191322d268cbSEd Tanous const std::string& systemName, const std::string& entryId) { 19143ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 191545ca1b86SEd Tanous { 191645ca1b86SEd Tanous return; 191745ca1b86SEd Tanous } 191825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 19197f3e84a1SEd Tanous { 19207f3e84a1SEd Tanous // Option currently returns no systems. TBD 19217f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 19227f3e84a1SEd Tanous systemName); 19237f3e84a1SEd Tanous return; 19247f3e84a1SEd Tanous } 1925253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 192622d268cbSEd Tanous { 192722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 192822d268cbSEd Tanous systemName); 192922d268cbSEd Tanous return; 193022d268cbSEd Tanous } 193175710de2SXiaochao Ma std::optional<bool> resolved; 193275710de2SXiaochao Ma 193315ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", 19347e860f15SJohn Edward Broadbent resolved)) 193575710de2SXiaochao Ma { 193675710de2SXiaochao Ma return; 193775710de2SXiaochao Ma } 193862598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Resolved"); 193975710de2SXiaochao Ma 1940e93abac6SGinu George setDbusProperty(asyncResp, "Resolved", "xyz.openbmc_project.Logging", 19419ae226faSGeorge Liu "/xyz/openbmc_project/logging/entry/" + entryId, 19423eb66652SAsmitha Karunanithi "xyz.openbmc_project.Logging.Entry", "Resolved", 1943e93abac6SGinu George *resolved); 19447e860f15SJohn Edward Broadbent }); 194575710de2SXiaochao Ma 19467e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 194722d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1948ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1949ed398213SEd Tanous 1950002d39b4SEd Tanous .methods(boost::beast::http::verb::delete_)( 1951002d39b4SEd Tanous [&app](const crow::Request& req, 1952002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 195322d268cbSEd Tanous const std::string& systemName, const std::string& param) { 19543ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1955336e96c6SChicago Duan { 195645ca1b86SEd Tanous return; 195745ca1b86SEd Tanous } 195825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 19597f3e84a1SEd Tanous { 19607f3e84a1SEd Tanous // Option currently returns no systems. TBD 19617f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 19627f3e84a1SEd Tanous systemName); 19637f3e84a1SEd Tanous return; 19647f3e84a1SEd Tanous } 1965253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 196622d268cbSEd Tanous { 196722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 196822d268cbSEd Tanous systemName); 196922d268cbSEd Tanous return; 197022d268cbSEd Tanous } 197162598e31SEd Tanous BMCWEB_LOG_DEBUG("Do delete single event entries."); 1972336e96c6SChicago Duan 19737e860f15SJohn Edward Broadbent std::string entryID = param; 1974336e96c6SChicago Duan 1975336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1976336e96c6SChicago Duan 1977336e96c6SChicago Duan // Process response from Logging service. 19785a39f77aSPatrick Williams auto respHandler = [asyncResp, 19795a39f77aSPatrick Williams entryID](const boost::system::error_code& ec) { 198062598e31SEd Tanous BMCWEB_LOG_DEBUG("EventLogEntry (DBus) doDelete callback: Done"); 1981336e96c6SChicago Duan if (ec) 1982336e96c6SChicago Duan { 19833de8d8baSGeorge Liu if (ec.value() == EBADR) 19843de8d8baSGeorge Liu { 198545ca1b86SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 198645ca1b86SEd Tanous entryID); 19873de8d8baSGeorge Liu return; 19883de8d8baSGeorge Liu } 1989336e96c6SChicago Duan // TODO Handle for specific error code 199062598e31SEd Tanous BMCWEB_LOG_ERROR( 199162598e31SEd Tanous "EventLogEntry (DBus) doDelete respHandler got error {}", 199262598e31SEd Tanous ec); 1993336e96c6SChicago Duan asyncResp->res.result( 1994336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1995336e96c6SChicago Duan return; 1996336e96c6SChicago Duan } 1997336e96c6SChicago Duan 1998336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1999336e96c6SChicago Duan }; 2000336e96c6SChicago Duan 2001336e96c6SChicago Duan // Make call to Logging service to request Delete Log 2002336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 2003336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 2004336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 2005336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 20067e860f15SJohn Edward Broadbent }); 2007400fd1fbSAdriana Kobylak } 2008400fd1fbSAdriana Kobylak 2009b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 2010b7028ebfSSpencer Ku 2011b7028ebfSSpencer Ku inline bool 2012b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 2013b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 2014b7028ebfSSpencer Ku { 2015b7028ebfSSpencer Ku std::error_code ec; 2016b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 2017b7028ebfSSpencer Ku if (ec) 2018b7028ebfSSpencer Ku { 2019bf2ddedeSCarson Labrado BMCWEB_LOG_WARNING("{}", ec.message()); 2020b7028ebfSSpencer Ku return false; 2021b7028ebfSSpencer Ku } 2022b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 2023b7028ebfSSpencer Ku { 2024b7028ebfSSpencer Ku std::string filename = it.path().filename(); 2025b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 2026b7028ebfSSpencer Ku // path 202711ba3979SEd Tanous if (filename.starts_with("log")) 2028b7028ebfSSpencer Ku { 2029b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 2030b7028ebfSSpencer Ku } 2031b7028ebfSSpencer Ku } 2032b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 2033b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 2034b7028ebfSSpencer Ku // descending order. 2035b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 2036b7028ebfSSpencer Ku AlphanumLess<std::string>()); 2037b7028ebfSSpencer Ku 2038b7028ebfSSpencer Ku return true; 2039b7028ebfSSpencer Ku } 2040b7028ebfSSpencer Ku 204102cad96eSEd Tanous inline bool getHostLoggerEntries( 204202cad96eSEd Tanous const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip, 204302cad96eSEd Tanous uint64_t top, std::vector<std::string>& logEntries, size_t& logCount) 2044b7028ebfSSpencer Ku { 2045b7028ebfSSpencer Ku GzFileReader logFile; 2046b7028ebfSSpencer Ku 2047b7028ebfSSpencer Ku // Go though all log files and expose host logs. 2048b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 2049b7028ebfSSpencer Ku { 2050b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 2051b7028ebfSSpencer Ku { 205262598e31SEd Tanous BMCWEB_LOG_ERROR("fail to expose host logs"); 2053b7028ebfSSpencer Ku return false; 2054b7028ebfSSpencer Ku } 2055b7028ebfSSpencer Ku } 2056b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 2057b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 2058b7028ebfSSpencer Ku if (!lastMessage.empty()) 2059b7028ebfSSpencer Ku { 2060b7028ebfSSpencer Ku logCount++; 2061b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 2062b7028ebfSSpencer Ku { 2063b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 2064b7028ebfSSpencer Ku } 2065b7028ebfSSpencer Ku } 2066b7028ebfSSpencer Ku return true; 2067b7028ebfSSpencer Ku } 2068b7028ebfSSpencer Ku 20696f056f24SEd Tanous inline void fillHostLoggerEntryJson(std::string_view logEntryID, 20706f056f24SEd Tanous std::string_view msg, 20716d6574c9SJason M. Bills nlohmann::json::object_t& logEntryJson) 2072b7028ebfSSpencer Ku { 2073b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 20749c11a172SVijay Lobo logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 2075ef4c65b7SEd Tanous logEntryJson["@odata.id"] = boost::urls::format( 2076253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries/{}", 2077253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, logEntryID); 20786d6574c9SJason M. Bills logEntryJson["Name"] = "Host Logger Entry"; 20796d6574c9SJason M. Bills logEntryJson["Id"] = logEntryID; 20806d6574c9SJason M. Bills logEntryJson["Message"] = msg; 2081*539d8c6bSEd Tanous logEntryJson["EntryType"] = log_entry::LogEntryType::Oem; 2082*539d8c6bSEd Tanous logEntryJson["Severity"] = log_entry::EventSeverity::OK; 20836d6574c9SJason M. Bills logEntryJson["OemRecordFormat"] = "Host Logger Entry"; 2084b7028ebfSSpencer Ku } 2085b7028ebfSSpencer Ku 2086b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 2087b7028ebfSSpencer Ku { 208822d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/") 2089b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 20901476687dSEd Tanous .methods(boost::beast::http::verb::get)( 20911476687dSEd Tanous [&app](const crow::Request& req, 209222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 209322d268cbSEd Tanous const std::string& systemName) { 20943ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 209545ca1b86SEd Tanous { 209645ca1b86SEd Tanous return; 209745ca1b86SEd Tanous } 209825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 20997f3e84a1SEd Tanous { 21007f3e84a1SEd Tanous // Option currently returns no systems. TBD 21017f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 21027f3e84a1SEd Tanous systemName); 21037f3e84a1SEd Tanous return; 21047f3e84a1SEd Tanous } 2105253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 210622d268cbSEd Tanous { 210722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 210822d268cbSEd Tanous systemName); 210922d268cbSEd Tanous return; 211022d268cbSEd Tanous } 2111b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 2112253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/HostLogger", 2113253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2114b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 2115b25644a1SJanet Adkins "#LogService.v1_2_0.LogService"; 2116b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 2117b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 2118b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 21191476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 2120253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries", 2121253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2122b7028ebfSSpencer Ku }); 2123b7028ebfSSpencer Ku } 2124b7028ebfSSpencer Ku 2125b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 2126b7028ebfSSpencer Ku { 2127b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 212822d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/") 2129b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2130002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2131002d39b4SEd Tanous [&app](const crow::Request& req, 213222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 213322d268cbSEd Tanous const std::string& systemName) { 2134c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2135c937d2bfSEd Tanous .canDelegateTop = true, 2136c937d2bfSEd Tanous .canDelegateSkip = true, 2137c937d2bfSEd Tanous }; 2138c937d2bfSEd Tanous query_param::Query delegatedQuery; 2139c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 21403ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 2141b7028ebfSSpencer Ku { 2142b7028ebfSSpencer Ku return; 2143b7028ebfSSpencer Ku } 214425b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 21457f3e84a1SEd Tanous { 21467f3e84a1SEd Tanous // Option currently returns no systems. TBD 21477f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 21487f3e84a1SEd Tanous systemName); 21497f3e84a1SEd Tanous return; 21507f3e84a1SEd Tanous } 2151253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 215222d268cbSEd Tanous { 215322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 215422d268cbSEd Tanous systemName); 215522d268cbSEd Tanous return; 215622d268cbSEd Tanous } 2157b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 2158253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries", 2159253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2160b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 2161b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 2162b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 2163b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 2164b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 21650fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2166b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 2167b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 2168b7028ebfSSpencer Ku 2169b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2170b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2171b7028ebfSSpencer Ku { 2172bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("Failed to get host log file path"); 2173b7028ebfSSpencer Ku return; 2174b7028ebfSSpencer Ku } 21753648c8beSEd Tanous // If we weren't provided top and skip limits, use the defaults. 21763648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 21775143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 2178b7028ebfSSpencer Ku size_t logCount = 0; 2179b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 2180b7028ebfSSpencer Ku // control by skip and top. 2181b7028ebfSSpencer Ku std::vector<std::string> logEntries; 21823648c8beSEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries, 21833648c8beSEd Tanous logCount)) 2184b7028ebfSSpencer Ku { 2185b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2186b7028ebfSSpencer Ku return; 2187b7028ebfSSpencer Ku } 2188b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 2189b7028ebfSSpencer Ku // log count 219026f6976fSEd Tanous if (logEntries.empty()) 2191b7028ebfSSpencer Ku { 2192b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 2193b7028ebfSSpencer Ku return; 2194b7028ebfSSpencer Ku } 219526f6976fSEd Tanous if (!logEntries.empty()) 2196b7028ebfSSpencer Ku { 2197b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 2198b7028ebfSSpencer Ku { 21996d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 22003648c8beSEd Tanous fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i], 22013648c8beSEd Tanous hostLogEntry); 2202b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(hostLogEntry)); 2203b7028ebfSSpencer Ku } 2204b7028ebfSSpencer Ku 2205b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 22063648c8beSEd Tanous if (skip + top < logCount) 2207b7028ebfSSpencer Ku { 2208b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 2209253f11b8SEd Tanous std::format( 2210253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries?$skip=", 2211253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME) + 22123648c8beSEd Tanous std::to_string(skip + top); 2213b7028ebfSSpencer Ku } 2214b7028ebfSSpencer Ku } 2215b7028ebfSSpencer Ku }); 2216b7028ebfSSpencer Ku } 2217b7028ebfSSpencer Ku 2218b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 2219b7028ebfSSpencer Ku { 2220b7028ebfSSpencer Ku BMCWEB_ROUTE( 222122d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/") 2222b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2223b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 222445ca1b86SEd Tanous [&app](const crow::Request& req, 2225b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 222622d268cbSEd Tanous const std::string& systemName, const std::string& param) { 22273ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 222845ca1b86SEd Tanous { 222945ca1b86SEd Tanous return; 223045ca1b86SEd Tanous } 223125b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 22327f3e84a1SEd Tanous { 22337f3e84a1SEd Tanous // Option currently returns no systems. TBD 22347f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 22357f3e84a1SEd Tanous systemName); 22367f3e84a1SEd Tanous return; 22377f3e84a1SEd Tanous } 2238253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 223922d268cbSEd Tanous { 224022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 224122d268cbSEd Tanous systemName); 224222d268cbSEd Tanous return; 224322d268cbSEd Tanous } 22446f056f24SEd Tanous std::string_view targetID = param; 2245b7028ebfSSpencer Ku 2246b7028ebfSSpencer Ku uint64_t idInt = 0; 2247ca45aa3cSEd Tanous 22486f056f24SEd Tanous auto [ptr, ec] = std::from_chars(targetID.begin(), targetID.end(), 224984396af9SPatrick Williams idInt); 22506f056f24SEd Tanous if (ec != std::errc{} || ptr != targetID.end()) 2251b7028ebfSSpencer Ku { 22529db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", param); 2253b7028ebfSSpencer Ku return; 2254b7028ebfSSpencer Ku } 2255b7028ebfSSpencer Ku 2256b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2257b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2258b7028ebfSSpencer Ku { 2259bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("Failed to get host log file path"); 2260b7028ebfSSpencer Ku return; 2261b7028ebfSSpencer Ku } 2262b7028ebfSSpencer Ku 2263b7028ebfSSpencer Ku size_t logCount = 0; 22643648c8beSEd Tanous size_t top = 1; 2265b7028ebfSSpencer Ku std::vector<std::string> logEntries; 2266b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 2267b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 2268b7028ebfSSpencer Ku // get that entry 2269002d39b4SEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries, 2270002d39b4SEd Tanous logCount)) 2271b7028ebfSSpencer Ku { 2272b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2273b7028ebfSSpencer Ku return; 2274b7028ebfSSpencer Ku } 2275b7028ebfSSpencer Ku 2276b7028ebfSSpencer Ku if (!logEntries.empty()) 2277b7028ebfSSpencer Ku { 22786d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 22796d6574c9SJason M. Bills fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry); 22806d6574c9SJason M. Bills asyncResp->res.jsonValue.update(hostLogEntry); 2281b7028ebfSSpencer Ku return; 2282b7028ebfSSpencer Ku } 2283b7028ebfSSpencer Ku 2284b7028ebfSSpencer Ku // Requested ID was not found 22859db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", param); 2286b7028ebfSSpencer Ku }); 2287b7028ebfSSpencer Ku } 2288b7028ebfSSpencer Ku 2289dd72e87bSClaire Weinan inline void handleBMCLogServicesCollectionGet( 2290fdd26906SClaire Weinan crow::App& app, const crow::Request& req, 2291253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2292253f11b8SEd Tanous const std::string& managerId) 22931da66f75SEd Tanous { 22943ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 229545ca1b86SEd Tanous { 229645ca1b86SEd Tanous return; 229745ca1b86SEd Tanous } 2298253f11b8SEd Tanous 2299253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2300253f11b8SEd Tanous { 2301253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2302253f11b8SEd Tanous return; 2303253f11b8SEd Tanous } 2304253f11b8SEd Tanous 23057e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 23067e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2307e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 23081da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2309253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 2310253f11b8SEd Tanous "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME); 2311002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 2312e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 23131da66f75SEd Tanous "Collection of LogServices for this Manager"; 2314002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 2315c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 2316fdd26906SClaire Weinan 231725b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_BMC_JOURNAL) 231825b54dbaSEd Tanous { 2319613dabeaSEd Tanous nlohmann::json::object_t journal; 2320253f11b8SEd Tanous journal["@odata.id"] = 2321253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/LogServices/Journal", 2322253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2323b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(journal)); 232425b54dbaSEd Tanous } 2325fdd26906SClaire Weinan 2326fdd26906SClaire Weinan asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); 2327fdd26906SClaire Weinan 232825b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_DUMP_LOG) 232925b54dbaSEd Tanous { 233015912159SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 23317a1dbc48SGeorge Liu "xyz.openbmc_project.Collection.DeleteAll"}; 23327a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 23337a1dbc48SGeorge Liu "/xyz/openbmc_project/dump", 0, interfaces, 233425b54dbaSEd Tanous [asyncResp](const boost::system::error_code& ec, 233525b54dbaSEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& 233625b54dbaSEd Tanous subTreePaths) { 2337fdd26906SClaire Weinan if (ec) 2338fdd26906SClaire Weinan { 233962598e31SEd Tanous BMCWEB_LOG_ERROR( 234062598e31SEd Tanous "handleBMCLogServicesCollectionGet respHandler got error {}", 234162598e31SEd Tanous ec); 2342fdd26906SClaire Weinan // Assume that getting an error simply means there are no dump 2343fdd26906SClaire Weinan // LogServices. Return without adding any error response. 2344fdd26906SClaire Weinan return; 2345fdd26906SClaire Weinan } 2346fdd26906SClaire Weinan 2347fdd26906SClaire Weinan nlohmann::json& logServiceArrayLocal = 2348fdd26906SClaire Weinan asyncResp->res.jsonValue["Members"]; 2349fdd26906SClaire Weinan 2350fdd26906SClaire Weinan for (const std::string& path : subTreePaths) 2351fdd26906SClaire Weinan { 2352fdd26906SClaire Weinan if (path == "/xyz/openbmc_project/dump/bmc") 2353fdd26906SClaire Weinan { 2354613dabeaSEd Tanous nlohmann::json::object_t member; 2355253f11b8SEd Tanous member["@odata.id"] = boost::urls::format( 2356253f11b8SEd Tanous "/redfish/v1/Managers/{}/LogServices/Dump", 2357253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2358b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 2359fdd26906SClaire Weinan } 2360fdd26906SClaire Weinan else if (path == "/xyz/openbmc_project/dump/faultlog") 2361fdd26906SClaire Weinan { 2362613dabeaSEd Tanous nlohmann::json::object_t member; 2363253f11b8SEd Tanous member["@odata.id"] = boost::urls::format( 2364253f11b8SEd Tanous "/redfish/v1/Managers/{}/LogServices/FaultLog", 2365253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2366b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 2367fdd26906SClaire Weinan } 2368fdd26906SClaire Weinan } 2369fdd26906SClaire Weinan 2370e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2371fdd26906SClaire Weinan logServiceArrayLocal.size(); 23727a1dbc48SGeorge Liu }); 237325b54dbaSEd Tanous } 2374fdd26906SClaire Weinan } 2375fdd26906SClaire Weinan 2376fdd26906SClaire Weinan inline void requestRoutesBMCLogServiceCollection(App& app) 2377fdd26906SClaire Weinan { 2378253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/") 2379fdd26906SClaire Weinan .privileges(redfish::privileges::getLogServiceCollection) 2380fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2381dd72e87bSClaire Weinan std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app))); 2382e1f26343SJason M. Bills } 2383e1f26343SJason M. Bills 2384fdd26906SClaire Weinan inline void 2385fdd26906SClaire Weinan getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2386fdd26906SClaire Weinan const std::string& dumpType) 2387c9bb6861Sraviteja-b { 2388fdd26906SClaire Weinan std::string dumpPath; 2389*539d8c6bSEd Tanous log_service::OverWritePolicy overWritePolicy = 2390*539d8c6bSEd Tanous log_service::OverWritePolicy::Invalid; 2391fdd26906SClaire Weinan bool collectDiagnosticDataSupported = false; 2392fdd26906SClaire Weinan 2393fdd26906SClaire Weinan if (dumpType == "BMC") 239445ca1b86SEd Tanous { 2395253f11b8SEd Tanous dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/Dump", 2396253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2397*539d8c6bSEd Tanous overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; 2398fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2399fdd26906SClaire Weinan } 2400fdd26906SClaire Weinan else if (dumpType == "FaultLog") 2401fdd26906SClaire Weinan { 2402253f11b8SEd Tanous dumpPath = std::format("/redfish/v1/Managers/{}/LogServices/FaultLog", 2403253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2404*539d8c6bSEd Tanous overWritePolicy = log_service::OverWritePolicy::Unknown; 2405fdd26906SClaire Weinan collectDiagnosticDataSupported = false; 2406fdd26906SClaire Weinan } 2407fdd26906SClaire Weinan else if (dumpType == "System") 2408fdd26906SClaire Weinan { 2409253f11b8SEd Tanous dumpPath = std::format("/redfish/v1/Systems/{}/LogServices/Dump", 2410253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2411*539d8c6bSEd Tanous overWritePolicy = log_service::OverWritePolicy::WrapsWhenFull; 2412fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2413fdd26906SClaire Weinan } 2414fdd26906SClaire Weinan else 2415fdd26906SClaire Weinan { 241662598e31SEd Tanous BMCWEB_LOG_ERROR("getDumpServiceInfo() invalid dump type: {}", 241762598e31SEd Tanous dumpType); 2418fdd26906SClaire Weinan messages::internalError(asyncResp->res); 241945ca1b86SEd Tanous return; 242045ca1b86SEd Tanous } 2421fdd26906SClaire Weinan 2422fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = dumpPath; 2423fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; 2424c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 2425fdd26906SClaire Weinan asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; 2426fdd26906SClaire Weinan asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); 2427*539d8c6bSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = overWritePolicy; 24287c8c4058STejas Patil 24297c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 24302b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 24310fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 24327c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 24337c8c4058STejas Patil redfishDateTimeOffset.second; 24347c8c4058STejas Patil 2435fdd26906SClaire Weinan asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; 2436fdd26906SClaire Weinan 2437fdd26906SClaire Weinan if (collectDiagnosticDataSupported) 2438fdd26906SClaire Weinan { 2439002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 24401476687dSEd Tanous ["target"] = 2441fdd26906SClaire Weinan dumpPath + "/Actions/LogService.CollectDiagnosticData"; 2442fdd26906SClaire Weinan } 24430d946211SClaire Weinan 24440d946211SClaire Weinan constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface}; 24450d946211SClaire Weinan dbus::utility::getSubTreePaths( 24460d946211SClaire Weinan "/xyz/openbmc_project/dump", 0, interfaces, 24470d946211SClaire Weinan [asyncResp, dumpType, dumpPath]( 24480d946211SClaire Weinan const boost::system::error_code& ec, 24490d946211SClaire Weinan const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 24500d946211SClaire Weinan if (ec) 24510d946211SClaire Weinan { 245262598e31SEd Tanous BMCWEB_LOG_ERROR("getDumpServiceInfo respHandler got error {}", ec); 24530d946211SClaire Weinan // Assume that getting an error simply means there are no dump 24540d946211SClaire Weinan // LogServices. Return without adding any error response. 24550d946211SClaire Weinan return; 24560d946211SClaire Weinan } 245718f8f608SEd Tanous std::string dbusDumpPath = getDumpPath(dumpType); 24580d946211SClaire Weinan for (const std::string& path : subTreePaths) 24590d946211SClaire Weinan { 24600d946211SClaire Weinan if (path == dbusDumpPath) 24610d946211SClaire Weinan { 24620d946211SClaire Weinan asyncResp->res 24630d946211SClaire Weinan .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 24640d946211SClaire Weinan dumpPath + "/Actions/LogService.ClearLog"; 24650d946211SClaire Weinan break; 24660d946211SClaire Weinan } 24670d946211SClaire Weinan } 24680d946211SClaire Weinan }); 2469c9bb6861Sraviteja-b } 2470c9bb6861Sraviteja-b 2471fdd26906SClaire Weinan inline void handleLogServicesDumpServiceGet( 2472fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2473253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2474253f11b8SEd Tanous const std::string& managerId) 24757e860f15SJohn Edward Broadbent { 24763ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 247745ca1b86SEd Tanous { 247845ca1b86SEd Tanous return; 247945ca1b86SEd Tanous } 2480253f11b8SEd Tanous 2481253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2482253f11b8SEd Tanous { 2483253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2484253f11b8SEd Tanous return; 2485253f11b8SEd Tanous } 2486253f11b8SEd Tanous 2487fdd26906SClaire Weinan getDumpServiceInfo(asyncResp, dumpType); 2488fdd26906SClaire Weinan } 2489c9bb6861Sraviteja-b 249022d268cbSEd Tanous inline void handleLogServicesDumpServiceComputerSystemGet( 249122d268cbSEd Tanous crow::App& app, const crow::Request& req, 249222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 249322d268cbSEd Tanous const std::string& chassisId) 249422d268cbSEd Tanous { 249522d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 249622d268cbSEd Tanous { 249722d268cbSEd Tanous return; 249822d268cbSEd Tanous } 2499253f11b8SEd Tanous if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) 250022d268cbSEd Tanous { 250122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 250222d268cbSEd Tanous return; 250322d268cbSEd Tanous } 250422d268cbSEd Tanous getDumpServiceInfo(asyncResp, "System"); 250522d268cbSEd Tanous } 250622d268cbSEd Tanous 2507fdd26906SClaire Weinan inline void handleLogServicesDumpEntriesCollectionGet( 2508fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2509253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2510253f11b8SEd Tanous const std::string& managerId) 2511fdd26906SClaire Weinan { 2512fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2513fdd26906SClaire Weinan { 2514fdd26906SClaire Weinan return; 2515fdd26906SClaire Weinan } 2516253f11b8SEd Tanous 2517253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2518253f11b8SEd Tanous { 2519253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2520253f11b8SEd Tanous return; 2521253f11b8SEd Tanous } 2522fdd26906SClaire Weinan getDumpEntryCollection(asyncResp, dumpType); 2523fdd26906SClaire Weinan } 2524fdd26906SClaire Weinan 252522d268cbSEd Tanous inline void handleLogServicesDumpEntriesCollectionComputerSystemGet( 252622d268cbSEd Tanous crow::App& app, const crow::Request& req, 252722d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 252822d268cbSEd Tanous const std::string& chassisId) 252922d268cbSEd Tanous { 253022d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 253122d268cbSEd Tanous { 253222d268cbSEd Tanous return; 253322d268cbSEd Tanous } 2534253f11b8SEd Tanous if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) 253522d268cbSEd Tanous { 253622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 253722d268cbSEd Tanous return; 253822d268cbSEd Tanous } 253922d268cbSEd Tanous getDumpEntryCollection(asyncResp, "System"); 254022d268cbSEd Tanous } 254122d268cbSEd Tanous 2542fdd26906SClaire Weinan inline void handleLogServicesDumpEntryGet( 2543fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2544fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2545253f11b8SEd Tanous const std::string& managerId, const std::string& dumpId) 2546fdd26906SClaire Weinan { 2547fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2548fdd26906SClaire Weinan { 2549fdd26906SClaire Weinan return; 2550fdd26906SClaire Weinan } 2551253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2552253f11b8SEd Tanous { 2553253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2554253f11b8SEd Tanous return; 2555253f11b8SEd Tanous } 2556fdd26906SClaire Weinan getDumpEntryById(asyncResp, dumpId, dumpType); 2557fdd26906SClaire Weinan } 2558168d1b1aSCarson Labrado 255922d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemGet( 256022d268cbSEd Tanous crow::App& app, const crow::Request& req, 256122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 256222d268cbSEd Tanous const std::string& chassisId, const std::string& dumpId) 256322d268cbSEd Tanous { 256422d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 256522d268cbSEd Tanous { 256622d268cbSEd Tanous return; 256722d268cbSEd Tanous } 2568253f11b8SEd Tanous if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) 256922d268cbSEd Tanous { 257022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 257122d268cbSEd Tanous return; 257222d268cbSEd Tanous } 257322d268cbSEd Tanous getDumpEntryById(asyncResp, dumpId, "System"); 257422d268cbSEd Tanous } 2575fdd26906SClaire Weinan 2576fdd26906SClaire Weinan inline void handleLogServicesDumpEntryDelete( 2577fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2578fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2579253f11b8SEd Tanous const std::string& managerId, const std::string& dumpId) 2580fdd26906SClaire Weinan { 2581fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2582fdd26906SClaire Weinan { 2583fdd26906SClaire Weinan return; 2584fdd26906SClaire Weinan } 2585253f11b8SEd Tanous 2586253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2587253f11b8SEd Tanous { 2588253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2589253f11b8SEd Tanous return; 2590253f11b8SEd Tanous } 2591fdd26906SClaire Weinan deleteDumpEntry(asyncResp, dumpId, dumpType); 2592fdd26906SClaire Weinan } 2593fdd26906SClaire Weinan 259422d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemDelete( 259522d268cbSEd Tanous crow::App& app, const crow::Request& req, 259622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 259722d268cbSEd Tanous const std::string& chassisId, const std::string& dumpId) 259822d268cbSEd Tanous { 259922d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 260022d268cbSEd Tanous { 260122d268cbSEd Tanous return; 260222d268cbSEd Tanous } 2603253f11b8SEd Tanous if (chassisId != BMCWEB_REDFISH_SYSTEM_URI_NAME) 260422d268cbSEd Tanous { 260522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 260622d268cbSEd Tanous return; 260722d268cbSEd Tanous } 260822d268cbSEd Tanous deleteDumpEntry(asyncResp, dumpId, "System"); 260922d268cbSEd Tanous } 261022d268cbSEd Tanous 2611168d1b1aSCarson Labrado inline void handleLogServicesDumpEntryDownloadGet( 2612168d1b1aSCarson Labrado crow::App& app, const std::string& dumpType, const crow::Request& req, 2613168d1b1aSCarson Labrado const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2614253f11b8SEd Tanous const std::string& managerId, const std::string& dumpId) 2615168d1b1aSCarson Labrado { 2616168d1b1aSCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2617168d1b1aSCarson Labrado { 2618168d1b1aSCarson Labrado return; 2619168d1b1aSCarson Labrado } 2620253f11b8SEd Tanous 2621253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2622253f11b8SEd Tanous { 2623253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2624253f11b8SEd Tanous return; 2625253f11b8SEd Tanous } 2626168d1b1aSCarson Labrado downloadDumpEntry(asyncResp, dumpId, dumpType); 2627168d1b1aSCarson Labrado } 2628168d1b1aSCarson Labrado 2629168d1b1aSCarson Labrado inline void handleDBusEventLogEntryDownloadGet( 2630168d1b1aSCarson Labrado crow::App& app, const std::string& dumpType, const crow::Request& req, 2631168d1b1aSCarson Labrado const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2632168d1b1aSCarson Labrado const std::string& systemName, const std::string& entryID) 2633168d1b1aSCarson Labrado { 2634168d1b1aSCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2635168d1b1aSCarson Labrado { 2636168d1b1aSCarson Labrado return; 2637168d1b1aSCarson Labrado } 2638168d1b1aSCarson Labrado if (!http_helpers::isContentTypeAllowed( 2639168d1b1aSCarson Labrado req.getHeaderValue("Accept"), 2640168d1b1aSCarson Labrado http_helpers::ContentType::OctetStream, true)) 2641168d1b1aSCarson Labrado { 2642168d1b1aSCarson Labrado asyncResp->res.result(boost::beast::http::status::bad_request); 2643168d1b1aSCarson Labrado return; 2644168d1b1aSCarson Labrado } 2645168d1b1aSCarson Labrado downloadEventLogEntry(asyncResp, systemName, entryID, dumpType); 2646168d1b1aSCarson Labrado } 2647168d1b1aSCarson Labrado 2648fdd26906SClaire Weinan inline void handleLogServicesDumpCollectDiagnosticDataPost( 2649fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2650253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2651253f11b8SEd Tanous const std::string& managerId) 2652fdd26906SClaire Weinan { 2653fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2654fdd26906SClaire Weinan { 2655fdd26906SClaire Weinan return; 2656fdd26906SClaire Weinan } 2657253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2658253f11b8SEd Tanous { 2659253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2660253f11b8SEd Tanous return; 2661253f11b8SEd Tanous } 2662253f11b8SEd Tanous 2663fdd26906SClaire Weinan createDump(asyncResp, req, dumpType); 2664fdd26906SClaire Weinan } 2665fdd26906SClaire Weinan 266622d268cbSEd Tanous inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost( 266722d268cbSEd Tanous crow::App& app, const crow::Request& req, 266822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26697f3e84a1SEd Tanous const std::string& systemName) 267022d268cbSEd Tanous { 267122d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 267222d268cbSEd Tanous { 267322d268cbSEd Tanous return; 267422d268cbSEd Tanous } 26757f3e84a1SEd Tanous 267625b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 267722d268cbSEd Tanous { 26787f3e84a1SEd Tanous // Option currently returns no systems. TBD 26797f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 26807f3e84a1SEd Tanous systemName); 26817f3e84a1SEd Tanous return; 26827f3e84a1SEd Tanous } 2683253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 26847f3e84a1SEd Tanous { 26857f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 26867f3e84a1SEd Tanous systemName); 268722d268cbSEd Tanous return; 268822d268cbSEd Tanous } 268922d268cbSEd Tanous createDump(asyncResp, req, "System"); 269022d268cbSEd Tanous } 269122d268cbSEd Tanous 2692fdd26906SClaire Weinan inline void handleLogServicesDumpClearLogPost( 2693fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2694253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2695253f11b8SEd Tanous const std::string& managerId) 2696fdd26906SClaire Weinan { 2697fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2698fdd26906SClaire Weinan { 2699fdd26906SClaire Weinan return; 2700fdd26906SClaire Weinan } 2701253f11b8SEd Tanous 2702253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2703253f11b8SEd Tanous { 2704253f11b8SEd Tanous messages::resourceNotFound(asyncResp->res, "Manager", managerId); 2705253f11b8SEd Tanous return; 2706253f11b8SEd Tanous } 2707fdd26906SClaire Weinan clearDump(asyncResp, dumpType); 2708fdd26906SClaire Weinan } 2709fdd26906SClaire Weinan 271022d268cbSEd Tanous inline void handleLogServicesDumpClearLogComputerSystemPost( 271122d268cbSEd Tanous crow::App& app, const crow::Request& req, 271222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 27137f3e84a1SEd Tanous const std::string& systemName) 271422d268cbSEd Tanous { 271522d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 271622d268cbSEd Tanous { 271722d268cbSEd Tanous return; 271822d268cbSEd Tanous } 271925b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 272022d268cbSEd Tanous { 27217f3e84a1SEd Tanous // Option currently returns no systems. TBD 27227f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 27237f3e84a1SEd Tanous systemName); 27247f3e84a1SEd Tanous return; 27257f3e84a1SEd Tanous } 2726253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 27277f3e84a1SEd Tanous { 27287f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 27297f3e84a1SEd Tanous systemName); 273022d268cbSEd Tanous return; 273122d268cbSEd Tanous } 273222d268cbSEd Tanous clearDump(asyncResp, "System"); 273322d268cbSEd Tanous } 273422d268cbSEd Tanous 2735fdd26906SClaire Weinan inline void requestRoutesBMCDumpService(App& app) 2736fdd26906SClaire Weinan { 2737253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/") 2738fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2739fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2740fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "BMC")); 2741fdd26906SClaire Weinan } 2742fdd26906SClaire Weinan 2743fdd26906SClaire Weinan inline void requestRoutesBMCDumpEntryCollection(App& app) 2744fdd26906SClaire Weinan { 2745253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/") 2746fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2747fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2748fdd26906SClaire Weinan handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); 2749c9bb6861Sraviteja-b } 2750c9bb6861Sraviteja-b 27517e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2752c9bb6861Sraviteja-b { 27537e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2754253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") 2755ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2756fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2757fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "BMC")); 2758fdd26906SClaire Weinan 27597e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2760253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/") 2761ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 2762fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2763fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); 2764c9bb6861Sraviteja-b } 2765c9bb6861Sraviteja-b 2766168d1b1aSCarson Labrado inline void requestRoutesBMCDumpEntryDownload(App& app) 2767168d1b1aSCarson Labrado { 2768168d1b1aSCarson Labrado BMCWEB_ROUTE( 2769168d1b1aSCarson Labrado app, 2770253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/Dump/Entries/<str>/attachment/") 2771168d1b1aSCarson Labrado .privileges(redfish::privileges::getLogEntry) 2772168d1b1aSCarson Labrado .methods(boost::beast::http::verb::get)(std::bind_front( 2773168d1b1aSCarson Labrado handleLogServicesDumpEntryDownloadGet, std::ref(app), "BMC")); 2774168d1b1aSCarson Labrado } 2775168d1b1aSCarson Labrado 27767e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2777c9bb6861Sraviteja-b { 27780fda0f12SGeorge Liu BMCWEB_ROUTE( 27790fda0f12SGeorge Liu app, 2780253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2781ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 27827e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 2783fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, 2784fdd26906SClaire Weinan std::ref(app), "BMC")); 2785a43be80fSAsmitha Karunanithi } 2786a43be80fSAsmitha Karunanithi 27877e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 278880319af1SAsmitha Karunanithi { 27890fda0f12SGeorge Liu BMCWEB_ROUTE( 27900fda0f12SGeorge Liu app, 2791253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/Dump/Actions/LogService.ClearLog/") 2792ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 2793fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 2794fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); 279545ca1b86SEd Tanous } 2796fdd26906SClaire Weinan 2797168d1b1aSCarson Labrado inline void requestRoutesDBusEventLogEntryDownload(App& app) 2798168d1b1aSCarson Labrado { 2799168d1b1aSCarson Labrado BMCWEB_ROUTE( 2800168d1b1aSCarson Labrado app, 28019e9d99daSRavi Teja "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/") 2802168d1b1aSCarson Labrado .privileges(redfish::privileges::getLogEntry) 2803168d1b1aSCarson Labrado .methods(boost::beast::http::verb::get)(std::bind_front( 2804168d1b1aSCarson Labrado handleDBusEventLogEntryDownloadGet, std::ref(app), "System")); 2805168d1b1aSCarson Labrado } 2806168d1b1aSCarson Labrado 2807fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpService(App& app) 2808fdd26906SClaire Weinan { 2809253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/") 2810fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2811fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2812fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); 2813fdd26906SClaire Weinan } 2814fdd26906SClaire Weinan 2815fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntryCollection(App& app) 2816fdd26906SClaire Weinan { 2817253f11b8SEd Tanous BMCWEB_ROUTE(app, 2818253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/") 2819fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2820fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2821fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpEntriesCollectionGet, 2822fdd26906SClaire Weinan std::ref(app), "FaultLog")); 2823fdd26906SClaire Weinan } 2824fdd26906SClaire Weinan 2825fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntry(App& app) 2826fdd26906SClaire Weinan { 2827253f11b8SEd Tanous BMCWEB_ROUTE( 2828253f11b8SEd Tanous app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") 2829fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntry) 2830fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2831fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); 2832fdd26906SClaire Weinan 2833253f11b8SEd Tanous BMCWEB_ROUTE( 2834253f11b8SEd Tanous app, "/redfish/v1/Managers/<str>/LogServices/FaultLog/Entries/<str>/") 2835fdd26906SClaire Weinan .privileges(redfish::privileges::deleteLogEntry) 2836fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2837fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); 2838fdd26906SClaire Weinan } 2839fdd26906SClaire Weinan 2840fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpClear(App& app) 2841fdd26906SClaire Weinan { 2842fdd26906SClaire Weinan BMCWEB_ROUTE( 2843fdd26906SClaire Weinan app, 2844253f11b8SEd Tanous "/redfish/v1/Managers/<str>/LogServices/FaultLog/Actions/LogService.ClearLog/") 2845fdd26906SClaire Weinan .privileges(redfish::privileges::postLogService) 2846fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 2847fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); 28485cb1dd27SAsmitha Karunanithi } 28495cb1dd27SAsmitha Karunanithi 28507e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 28515cb1dd27SAsmitha Karunanithi { 285222d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/") 2853ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 28546ab9ad54SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 285522d268cbSEd Tanous handleLogServicesDumpServiceComputerSystemGet, std::ref(app))); 28565cb1dd27SAsmitha Karunanithi } 28575cb1dd27SAsmitha Karunanithi 28587e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 28597e860f15SJohn Edward Broadbent { 286022d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/") 2861ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 286222d268cbSEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 286322d268cbSEd Tanous handleLogServicesDumpEntriesCollectionComputerSystemGet, 286422d268cbSEd Tanous std::ref(app))); 28655cb1dd27SAsmitha Karunanithi } 28665cb1dd27SAsmitha Karunanithi 28677e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 28685cb1dd27SAsmitha Karunanithi { 28697e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 287022d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") 2871ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 28726ab9ad54SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 287322d268cbSEd Tanous handleLogServicesDumpEntryComputerSystemGet, std::ref(app))); 28748d1b46d7Szhanghch05 28757e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 287622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") 2877ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 28786ab9ad54SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 287922d268cbSEd Tanous handleLogServicesDumpEntryComputerSystemDelete, std::ref(app))); 28805cb1dd27SAsmitha Karunanithi } 2881c9bb6861Sraviteja-b 28827e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2883c9bb6861Sraviteja-b { 28840fda0f12SGeorge Liu BMCWEB_ROUTE( 28850fda0f12SGeorge Liu app, 288622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2887ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 288822d268cbSEd Tanous .methods(boost::beast::http::verb::post)(std::bind_front( 288922d268cbSEd Tanous handleLogServicesDumpCollectDiagnosticDataComputerSystemPost, 289022d268cbSEd Tanous std::ref(app))); 2891a43be80fSAsmitha Karunanithi } 2892a43be80fSAsmitha Karunanithi 28937e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2894a43be80fSAsmitha Karunanithi { 28950fda0f12SGeorge Liu BMCWEB_ROUTE( 28960fda0f12SGeorge Liu app, 289722d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/") 2898ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 28996ab9ad54SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 290022d268cbSEd Tanous handleLogServicesDumpClearLogComputerSystemPost, std::ref(app))); 2901013487e5Sraviteja-b } 2902013487e5Sraviteja-b 29037e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 29041da66f75SEd Tanous { 29053946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 29063946028dSAppaRao Puli // method for security reasons. 29071da66f75SEd Tanous /** 29081da66f75SEd Tanous * Functions triggers appropriate requests on DBus 29091da66f75SEd Tanous */ 291022d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/") 2911ed398213SEd Tanous // This is incorrect, should be: 2912ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2913432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 2914002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2915002d39b4SEd Tanous [&app](const crow::Request& req, 291622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 291722d268cbSEd Tanous const std::string& systemName) { 29183ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 291945ca1b86SEd Tanous { 292045ca1b86SEd Tanous return; 292145ca1b86SEd Tanous } 292225b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 29237f3e84a1SEd Tanous { 29247f3e84a1SEd Tanous // Option currently returns no systems. TBD 29257f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 29267f3e84a1SEd Tanous systemName); 29277f3e84a1SEd Tanous return; 29287f3e84a1SEd Tanous } 2929253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 293022d268cbSEd Tanous { 293122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 293222d268cbSEd Tanous systemName); 293322d268cbSEd Tanous return; 293422d268cbSEd Tanous } 293522d268cbSEd Tanous 29367e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 29377e860f15SJohn Edward Broadbent // SubRoute 29380f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2939253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/Crashdump", 2940253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2941e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 29428e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 29434f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 29444f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 294515b89725SV-Sanjana asyncResp->res.jsonValue["Id"] = "Crashdump"; 2946*539d8c6bSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = 2947*539d8c6bSEd Tanous log_service::OverWritePolicy::WrapsWhenFull; 2948e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 29497c8c4058STejas Patil 29507c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 29512b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 29527c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 29537c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 29547c8c4058STejas Patil redfishDateTimeOffset.second; 29557c8c4058STejas Patil 29561476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 2957253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", 2958253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2959253f11b8SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] 2960253f11b8SEd Tanous ["target"] = std::format( 2961253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.ClearLog", 2962253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 2963002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 2964253f11b8SEd Tanous ["target"] = std::format( 2965253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData", 2966253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 29677e860f15SJohn Edward Broadbent }); 29681da66f75SEd Tanous } 29691da66f75SEd Tanous 29707e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 29715b61b5e8SJason M. Bills { 29720fda0f12SGeorge Liu BMCWEB_ROUTE( 29730fda0f12SGeorge Liu app, 297422d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/") 2975ed398213SEd Tanous // This is incorrect, should be: 2976ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2977432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 29787e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 297945ca1b86SEd Tanous [&app](const crow::Request& req, 298022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 298122d268cbSEd Tanous const std::string& systemName) { 29823ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 298345ca1b86SEd Tanous { 298445ca1b86SEd Tanous return; 298545ca1b86SEd Tanous } 298625b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 29877f3e84a1SEd Tanous { 29887f3e84a1SEd Tanous // Option currently returns no systems. TBD 29897f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 29907f3e84a1SEd Tanous systemName); 29917f3e84a1SEd Tanous return; 29927f3e84a1SEd Tanous } 2993253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 299422d268cbSEd Tanous { 299522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 299622d268cbSEd Tanous systemName); 299722d268cbSEd Tanous return; 299822d268cbSEd Tanous } 29995b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 30005e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 3001cb13a392SEd Tanous const std::string&) { 30025b61b5e8SJason M. Bills if (ec) 30035b61b5e8SJason M. Bills { 30045b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 30055b61b5e8SJason M. Bills return; 30065b61b5e8SJason M. Bills } 30075b61b5e8SJason M. Bills messages::success(asyncResp->res); 30085b61b5e8SJason M. Bills }, 3009002d39b4SEd Tanous crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 30107e860f15SJohn Edward Broadbent }); 30115b61b5e8SJason M. Bills } 30125b61b5e8SJason M. Bills 30138d1b46d7Szhanghch05 static void 30148d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 30158d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 3016e855dd28SJason M. Bills { 3017043a0536SJohnathan Mantey auto getStoredLogCallback = 3018b9d36b47SEd Tanous [asyncResp, logID, 30195e7e2dc5SEd Tanous &logEntryJson](const boost::system::error_code& ec, 3020b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& params) { 3021e855dd28SJason M. Bills if (ec) 3022e855dd28SJason M. Bills { 302362598e31SEd Tanous BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message()); 30241ddcf01aSJason M. Bills if (ec.value() == 30251ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 30261ddcf01aSJason M. Bills { 3027002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 30281ddcf01aSJason M. Bills } 30291ddcf01aSJason M. Bills else 30301ddcf01aSJason M. Bills { 3031e855dd28SJason M. Bills messages::internalError(asyncResp->res); 30321ddcf01aSJason M. Bills } 3033e855dd28SJason M. Bills return; 3034e855dd28SJason M. Bills } 3035043a0536SJohnathan Mantey 3036043a0536SJohnathan Mantey std::string timestamp{}; 3037043a0536SJohnathan Mantey std::string filename{}; 3038043a0536SJohnathan Mantey std::string logfile{}; 30392c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 3040043a0536SJohnathan Mantey 3041043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 3042e855dd28SJason M. Bills { 30439db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3044e855dd28SJason M. Bills return; 3045e855dd28SJason M. Bills } 3046e855dd28SJason M. Bills 3047043a0536SJohnathan Mantey std::string crashdumpURI = 3048253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/", 3049253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME) + 3050043a0536SJohnathan Mantey logID + "/" + filename; 305184afc48bSJason M. Bills nlohmann::json::object_t logEntry; 30529c11a172SVijay Lobo logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 3053ef4c65b7SEd Tanous logEntry["@odata.id"] = boost::urls::format( 3054253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries/{}", 3055253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, logID); 305684afc48bSJason M. Bills logEntry["Name"] = "CPU Crashdump"; 305784afc48bSJason M. Bills logEntry["Id"] = logID; 3058*539d8c6bSEd Tanous logEntry["EntryType"] = log_entry::LogEntryType::Oem; 305984afc48bSJason M. Bills logEntry["AdditionalDataURI"] = std::move(crashdumpURI); 306084afc48bSJason M. Bills logEntry["DiagnosticDataType"] = "OEM"; 306184afc48bSJason M. Bills logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; 306284afc48bSJason M. Bills logEntry["Created"] = std::move(timestamp); 30632b20ef6eSJason M. Bills 30642b20ef6eSJason M. Bills // If logEntryJson references an array of LogEntry resources 30652b20ef6eSJason M. Bills // ('Members' list), then push this as a new entry, otherwise set it 30662b20ef6eSJason M. Bills // directly 30672b20ef6eSJason M. Bills if (logEntryJson.is_array()) 30682b20ef6eSJason M. Bills { 30692b20ef6eSJason M. Bills logEntryJson.push_back(logEntry); 30702b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 30712b20ef6eSJason M. Bills logEntryJson.size(); 30722b20ef6eSJason M. Bills } 30732b20ef6eSJason M. Bills else 30742b20ef6eSJason M. Bills { 3075d405bb51SJason M. Bills logEntryJson.update(logEntry); 30762b20ef6eSJason M. Bills } 3077e855dd28SJason M. Bills }; 3078d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3079d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, crashdumpObject, 3080d1bde9e5SKrzysztof Grobelny crashdumpPath + std::string("/") + logID, crashdumpInterface, 3081d1bde9e5SKrzysztof Grobelny std::move(getStoredLogCallback)); 3082e855dd28SJason M. Bills } 3083e855dd28SJason M. Bills 30847e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 30851da66f75SEd Tanous { 30863946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 30873946028dSAppaRao Puli // method for security reasons. 30881da66f75SEd Tanous /** 30891da66f75SEd Tanous * Functions triggers appropriate requests on DBus 30901da66f75SEd Tanous */ 30917e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 309222d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/") 3093ed398213SEd Tanous // This is incorrect, should be. 3094ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 3095432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3096002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3097002d39b4SEd Tanous [&app](const crow::Request& req, 309822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 309922d268cbSEd Tanous const std::string& systemName) { 31003ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 310145ca1b86SEd Tanous { 310245ca1b86SEd Tanous return; 310345ca1b86SEd Tanous } 310425b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 31057f3e84a1SEd Tanous { 31067f3e84a1SEd Tanous // Option currently returns no systems. TBD 31077f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 31087f3e84a1SEd Tanous systemName); 31097f3e84a1SEd Tanous return; 31107f3e84a1SEd Tanous } 3111253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 311222d268cbSEd Tanous { 311322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 311422d268cbSEd Tanous systemName); 311522d268cbSEd Tanous return; 311622d268cbSEd Tanous } 311722d268cbSEd Tanous 31187a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 31197a1dbc48SGeorge Liu crashdumpInterface}; 31207a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 31217a1dbc48SGeorge Liu "/", 0, interfaces, 31227a1dbc48SGeorge Liu [asyncResp](const boost::system::error_code& ec, 31232b20ef6eSJason M. Bills const std::vector<std::string>& resp) { 31241da66f75SEd Tanous if (ec) 31251da66f75SEd Tanous { 31261da66f75SEd Tanous if (ec.value() != 31271da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 31281da66f75SEd Tanous { 312962598e31SEd Tanous BMCWEB_LOG_DEBUG("failed to get entries ec: {}", 313062598e31SEd Tanous ec.message()); 3131f12894f8SJason M. Bills messages::internalError(asyncResp->res); 31321da66f75SEd Tanous return; 31331da66f75SEd Tanous } 31341da66f75SEd Tanous } 3135e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 31361da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 3137253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = std::format( 3138253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/Crashdump/Entries", 3139253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3140002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 3141e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 3142424c4176SJason M. Bills "Collection of Crashdump Entries"; 3143002d39b4SEd Tanous asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3144a2dd60a6SBrandon Kim asyncResp->res.jsonValue["Members@odata.count"] = 0; 31452b20ef6eSJason M. Bills 31462b20ef6eSJason M. Bills for (const std::string& path : resp) 31471da66f75SEd Tanous { 31482b20ef6eSJason M. Bills const sdbusplus::message::object_path objPath(path); 3149e855dd28SJason M. Bills // Get the log ID 31502b20ef6eSJason M. Bills std::string logID = objPath.filename(); 31512b20ef6eSJason M. Bills if (logID.empty()) 31521da66f75SEd Tanous { 3153e855dd28SJason M. Bills continue; 31541da66f75SEd Tanous } 3155e855dd28SJason M. Bills // Add the log entry to the array 31562b20ef6eSJason M. Bills logCrashdumpEntry(asyncResp, logID, 31572b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"]); 31581da66f75SEd Tanous } 31597a1dbc48SGeorge Liu }); 31607e860f15SJohn Edward Broadbent }); 31611da66f75SEd Tanous } 31621da66f75SEd Tanous 31637e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 31641da66f75SEd Tanous { 31653946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 31663946028dSAppaRao Puli // method for security reasons. 31671da66f75SEd Tanous 31687e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 316922d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/") 3170ed398213SEd Tanous // this is incorrect, should be 3171ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 3172432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 31737e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 317445ca1b86SEd Tanous [&app](const crow::Request& req, 31757e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 317622d268cbSEd Tanous const std::string& systemName, const std::string& param) { 31773ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 317845ca1b86SEd Tanous { 317945ca1b86SEd Tanous return; 318045ca1b86SEd Tanous } 318125b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 31827f3e84a1SEd Tanous { 31837f3e84a1SEd Tanous // Option currently returns no systems. TBD 31847f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 31857f3e84a1SEd Tanous systemName); 31867f3e84a1SEd Tanous return; 31877f3e84a1SEd Tanous } 3188253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 318922d268cbSEd Tanous { 319022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 319122d268cbSEd Tanous systemName); 319222d268cbSEd Tanous return; 319322d268cbSEd Tanous } 31947e860f15SJohn Edward Broadbent const std::string& logID = param; 3195e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 31967e860f15SJohn Edward Broadbent }); 3197e855dd28SJason M. Bills } 3198e855dd28SJason M. Bills 31997e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 3200e855dd28SJason M. Bills { 32013946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 32023946028dSAppaRao Puli // method for security reasons. 32037e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 32047e860f15SJohn Edward Broadbent app, 320522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/") 3206ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 32077e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 3208a4ce114aSNan Zhou [](const crow::Request& req, 32097e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 321022d268cbSEd Tanous const std::string& systemName, const std::string& logID, 321122d268cbSEd Tanous const std::string& fileName) { 32122a9beeedSShounak Mitra // Do not call getRedfishRoute here since the crashdump file is not a 32132a9beeedSShounak Mitra // Redfish resource. 321422d268cbSEd Tanous 321525b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 32167f3e84a1SEd Tanous { 32177f3e84a1SEd Tanous // Option currently returns no systems. TBD 32187f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 32197f3e84a1SEd Tanous systemName); 32207f3e84a1SEd Tanous return; 32217f3e84a1SEd Tanous } 3222253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 322322d268cbSEd Tanous { 322422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 322522d268cbSEd Tanous systemName); 322622d268cbSEd Tanous return; 322722d268cbSEd Tanous } 322822d268cbSEd Tanous 3229043a0536SJohnathan Mantey auto getStoredLogCallback = 323039662a3bSEd Tanous [asyncResp, logID, fileName, url(boost::urls::url(req.url()))]( 32315e7e2dc5SEd Tanous const boost::system::error_code& ec, 3232002d39b4SEd Tanous const std::vector< 3233002d39b4SEd Tanous std::pair<std::string, dbus::utility::DbusVariantType>>& 32347e860f15SJohn Edward Broadbent resp) { 32351da66f75SEd Tanous if (ec) 32361da66f75SEd Tanous { 323762598e31SEd Tanous BMCWEB_LOG_DEBUG("failed to get log ec: {}", ec.message()); 3238f12894f8SJason M. Bills messages::internalError(asyncResp->res); 32391da66f75SEd Tanous return; 32401da66f75SEd Tanous } 3241e855dd28SJason M. Bills 3242043a0536SJohnathan Mantey std::string dbusFilename{}; 3243043a0536SJohnathan Mantey std::string dbusTimestamp{}; 3244043a0536SJohnathan Mantey std::string dbusFilepath{}; 3245043a0536SJohnathan Mantey 3246002d39b4SEd Tanous parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 3247002d39b4SEd Tanous dbusFilepath); 3248043a0536SJohnathan Mantey 3249043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 3250043a0536SJohnathan Mantey dbusFilepath.empty()) 32511da66f75SEd Tanous { 32529db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 32531da66f75SEd Tanous return; 32541da66f75SEd Tanous } 3255e855dd28SJason M. Bills 3256043a0536SJohnathan Mantey // Verify the file name parameter is correct 3257043a0536SJohnathan Mantey if (fileName != dbusFilename) 3258043a0536SJohnathan Mantey { 32599db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3260043a0536SJohnathan Mantey return; 3261043a0536SJohnathan Mantey } 3262043a0536SJohnathan Mantey 326327b0cf90SEd Tanous if (!asyncResp->res.openFile(dbusFilepath)) 3264043a0536SJohnathan Mantey { 32659db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3266043a0536SJohnathan Mantey return; 3267043a0536SJohnathan Mantey } 3268043a0536SJohnathan Mantey 32697e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 32707e860f15SJohn Edward Broadbent // from a browser 3271d9f6c621SEd Tanous asyncResp->res.addHeader( 3272d9f6c621SEd Tanous boost::beast::http::field::content_disposition, "attachment"); 32731da66f75SEd Tanous }; 3274d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3275d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, crashdumpObject, 3276d1bde9e5SKrzysztof Grobelny crashdumpPath + std::string("/") + logID, crashdumpInterface, 3277d1bde9e5SKrzysztof Grobelny std::move(getStoredLogCallback)); 32787e860f15SJohn Edward Broadbent }); 32791da66f75SEd Tanous } 32801da66f75SEd Tanous 3281c5a4c82aSJason M. Bills enum class OEMDiagnosticType 3282c5a4c82aSJason M. Bills { 3283c5a4c82aSJason M. Bills onDemand, 3284c5a4c82aSJason M. Bills telemetry, 3285c5a4c82aSJason M. Bills invalid, 3286c5a4c82aSJason M. Bills }; 3287c5a4c82aSJason M. Bills 328826ccae32SEd Tanous inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr) 3289c5a4c82aSJason M. Bills { 3290c5a4c82aSJason M. Bills if (oemDiagStr == "OnDemand") 3291c5a4c82aSJason M. Bills { 3292c5a4c82aSJason M. Bills return OEMDiagnosticType::onDemand; 3293c5a4c82aSJason M. Bills } 3294c5a4c82aSJason M. Bills if (oemDiagStr == "Telemetry") 3295c5a4c82aSJason M. Bills { 3296c5a4c82aSJason M. Bills return OEMDiagnosticType::telemetry; 3297c5a4c82aSJason M. Bills } 3298c5a4c82aSJason M. Bills 3299c5a4c82aSJason M. Bills return OEMDiagnosticType::invalid; 3300c5a4c82aSJason M. Bills } 3301c5a4c82aSJason M. Bills 33027e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 33031da66f75SEd Tanous { 33043946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 33053946028dSAppaRao Puli // method for security reasons. 33060fda0f12SGeorge Liu BMCWEB_ROUTE( 33070fda0f12SGeorge Liu app, 330822d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") 3309ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 3310ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3311432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3312002d39b4SEd Tanous .methods(boost::beast::http::verb::post)( 3313002d39b4SEd Tanous [&app](const crow::Request& req, 331422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 331522d268cbSEd Tanous const std::string& systemName) { 33163ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 331745ca1b86SEd Tanous { 331845ca1b86SEd Tanous return; 331945ca1b86SEd Tanous } 332022d268cbSEd Tanous 332125b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 33227f3e84a1SEd Tanous { 33237f3e84a1SEd Tanous // Option currently returns no systems. TBD 33247f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 33257f3e84a1SEd Tanous systemName); 33267f3e84a1SEd Tanous return; 33277f3e84a1SEd Tanous } 3328253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 332922d268cbSEd Tanous { 333022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 333122d268cbSEd Tanous systemName); 333222d268cbSEd Tanous return; 333322d268cbSEd Tanous } 333422d268cbSEd Tanous 33358e6c099aSJason M. Bills std::string diagnosticDataType; 33368e6c099aSJason M. Bills std::string oemDiagnosticDataType; 333715ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 3338002d39b4SEd Tanous req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 3339002d39b4SEd Tanous "OEMDiagnosticDataType", oemDiagnosticDataType)) 33408e6c099aSJason M. Bills { 33418e6c099aSJason M. Bills return; 33428e6c099aSJason M. Bills } 33438e6c099aSJason M. Bills 33448e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 33458e6c099aSJason M. Bills { 334662598e31SEd Tanous BMCWEB_LOG_ERROR( 334762598e31SEd Tanous "Only OEM DiagnosticDataType supported for Crashdump"); 33488e6c099aSJason M. Bills messages::actionParameterValueFormatError( 33498e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 33508e6c099aSJason M. Bills "CollectDiagnosticData"); 33518e6c099aSJason M. Bills return; 33528e6c099aSJason M. Bills } 33538e6c099aSJason M. Bills 3354c5a4c82aSJason M. Bills OEMDiagnosticType oemDiagType = 3355c5a4c82aSJason M. Bills getOEMDiagnosticType(oemDiagnosticDataType); 3356c5a4c82aSJason M. Bills 3357c5a4c82aSJason M. Bills std::string iface; 3358c5a4c82aSJason M. Bills std::string method; 3359c5a4c82aSJason M. Bills std::string taskMatchStr; 3360c5a4c82aSJason M. Bills if (oemDiagType == OEMDiagnosticType::onDemand) 3361c5a4c82aSJason M. Bills { 3362c5a4c82aSJason M. Bills iface = crashdumpOnDemandInterface; 3363c5a4c82aSJason M. Bills method = "GenerateOnDemandLog"; 3364c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3365c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3366c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3367c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3368c5a4c82aSJason M. Bills } 3369c5a4c82aSJason M. Bills else if (oemDiagType == OEMDiagnosticType::telemetry) 3370c5a4c82aSJason M. Bills { 3371c5a4c82aSJason M. Bills iface = crashdumpTelemetryInterface; 3372c5a4c82aSJason M. Bills method = "GenerateTelemetryLog"; 3373c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3374c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3375c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3376c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3377c5a4c82aSJason M. Bills } 3378c5a4c82aSJason M. Bills else 3379c5a4c82aSJason M. Bills { 338062598e31SEd Tanous BMCWEB_LOG_ERROR("Unsupported OEMDiagnosticDataType: {}", 338162598e31SEd Tanous oemDiagnosticDataType); 3382c5a4c82aSJason M. Bills messages::actionParameterValueFormatError( 3383002d39b4SEd Tanous asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType", 3384002d39b4SEd Tanous "CollectDiagnosticData"); 3385c5a4c82aSJason M. Bills return; 3386c5a4c82aSJason M. Bills } 3387c5a4c82aSJason M. Bills 3388c5a4c82aSJason M. Bills auto collectCrashdumpCallback = 3389c5a4c82aSJason M. Bills [asyncResp, payload(task::Payload(req)), 33905e7e2dc5SEd Tanous taskMatchStr](const boost::system::error_code& ec, 339198be3e39SEd Tanous const std::string&) mutable { 33921da66f75SEd Tanous if (ec) 33931da66f75SEd Tanous { 3394002d39b4SEd Tanous if (ec.value() == boost::system::errc::operation_not_supported) 33951da66f75SEd Tanous { 3396f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 33971da66f75SEd Tanous } 33984363d3b2SJason M. Bills else if (ec.value() == 33994363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 34004363d3b2SJason M. Bills { 3401002d39b4SEd Tanous messages::serviceTemporarilyUnavailable(asyncResp->res, 3402002d39b4SEd Tanous "60"); 34034363d3b2SJason M. Bills } 34041da66f75SEd Tanous else 34051da66f75SEd Tanous { 3406f12894f8SJason M. Bills messages::internalError(asyncResp->res); 34071da66f75SEd Tanous } 34081da66f75SEd Tanous return; 34091da66f75SEd Tanous } 3410002d39b4SEd Tanous std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 34118b24275dSEd Tanous [](const boost::system::error_code& ec2, sdbusplus::message_t&, 3412002d39b4SEd Tanous const std::shared_ptr<task::TaskData>& taskData) { 34138b24275dSEd Tanous if (!ec2) 341466afe4faSJames Feist { 3415002d39b4SEd Tanous taskData->messages.emplace_back(messages::taskCompletedOK( 3416e5d5006bSJames Feist std::to_string(taskData->index))); 3417831d6b09SJames Feist taskData->state = "Completed"; 341866afe4faSJames Feist } 341932898ceaSJames Feist return task::completed; 342066afe4faSJames Feist }, 3421c5a4c82aSJason M. Bills taskMatchStr); 3422c5a4c82aSJason M. Bills 342346229577SJames Feist task->startTimer(std::chrono::minutes(5)); 342446229577SJames Feist task->populateResp(asyncResp->res); 342598be3e39SEd Tanous task->payload.emplace(std::move(payload)); 34261da66f75SEd Tanous }; 34278e6c099aSJason M. Bills 34281da66f75SEd Tanous crow::connections::systemBus->async_method_call( 3429002d39b4SEd Tanous std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath, 3430002d39b4SEd Tanous iface, method); 34317e860f15SJohn Edward Broadbent }); 34326eda7685SKenny L. Ku } 34336eda7685SKenny L. Ku 3434cb92c03bSAndrew Geissler /** 3435cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 3436cb92c03bSAndrew Geissler */ 34377e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 3438cb92c03bSAndrew Geissler { 3439cb92c03bSAndrew Geissler /** 3440cb92c03bSAndrew Geissler * Function handles POST method request. 3441cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3442cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3443cb92c03bSAndrew Geissler */ 34447e860f15SJohn Edward Broadbent 34450fda0f12SGeorge Liu BMCWEB_ROUTE( 34460fda0f12SGeorge Liu app, 344722d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 3448ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 34497e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 345045ca1b86SEd Tanous [&app](const crow::Request& req, 345122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 345222d268cbSEd Tanous const std::string& systemName) { 34533ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 345445ca1b86SEd Tanous { 345545ca1b86SEd Tanous return; 345645ca1b86SEd Tanous } 345725b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 34587f3e84a1SEd Tanous { 34597f3e84a1SEd Tanous // Option currently returns no systems. TBD 34607f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 34617f3e84a1SEd Tanous systemName); 34627f3e84a1SEd Tanous return; 34637f3e84a1SEd Tanous } 3464253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 346522d268cbSEd Tanous { 346622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 346722d268cbSEd Tanous systemName); 346822d268cbSEd Tanous return; 346922d268cbSEd Tanous } 347062598e31SEd Tanous BMCWEB_LOG_DEBUG("Do delete all entries."); 3471cb92c03bSAndrew Geissler 3472cb92c03bSAndrew Geissler // Process response from Logging service. 34735e7e2dc5SEd Tanous auto respHandler = [asyncResp](const boost::system::error_code& ec) { 347462598e31SEd Tanous BMCWEB_LOG_DEBUG("doClearLog resp_handler callback: Done"); 3475cb92c03bSAndrew Geissler if (ec) 3476cb92c03bSAndrew Geissler { 3477cb92c03bSAndrew Geissler // TODO Handle for specific error code 347862598e31SEd Tanous BMCWEB_LOG_ERROR("doClearLog resp_handler got error {}", ec); 3479cb92c03bSAndrew Geissler asyncResp->res.result( 3480cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3481cb92c03bSAndrew Geissler return; 3482cb92c03bSAndrew Geissler } 3483cb92c03bSAndrew Geissler 3484002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content); 3485cb92c03bSAndrew Geissler }; 3486cb92c03bSAndrew Geissler 3487cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3488cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 34892c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 3490cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3491cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 34927e860f15SJohn Edward Broadbent }); 3493cb92c03bSAndrew Geissler } 3494a3316fc6SZhikuiRen 3495a3316fc6SZhikuiRen /**************************************************** 3496a3316fc6SZhikuiRen * Redfish PostCode interfaces 3497a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3498a3316fc6SZhikuiRen ******************************************************/ 34997e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 3500a3316fc6SZhikuiRen { 350122d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/") 3502ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 3503002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3504002d39b4SEd Tanous [&app](const crow::Request& req, 350522d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 350622d268cbSEd Tanous const std::string& systemName) { 35073ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 350845ca1b86SEd Tanous { 350945ca1b86SEd Tanous return; 351045ca1b86SEd Tanous } 351125b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 35127f3e84a1SEd Tanous { 35137f3e84a1SEd Tanous // Option currently returns no systems. TBD 35147f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 35157f3e84a1SEd Tanous systemName); 35167f3e84a1SEd Tanous return; 35177f3e84a1SEd Tanous } 3518253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 351922d268cbSEd Tanous { 352022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 352122d268cbSEd Tanous systemName); 352222d268cbSEd Tanous return; 352322d268cbSEd Tanous } 35241476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3525253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/PostCodes", 3526253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 35271476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 3528b25644a1SJanet Adkins "#LogService.v1_2_0.LogService"; 35291476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "POST Code Log Service"; 35301476687dSEd Tanous asyncResp->res.jsonValue["Description"] = "POST Code Log Service"; 3531ed34a4adSEd Tanous asyncResp->res.jsonValue["Id"] = "PostCodes"; 3532*539d8c6bSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = 3533*539d8c6bSEd Tanous log_service::OverWritePolicy::WrapsWhenFull; 35341476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 3535253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries", 3536253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 35377c8c4058STejas Patil 35387c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 35392b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 35400fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 35417c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 35427c8c4058STejas Patil redfishDateTimeOffset.second; 35437c8c4058STejas Patil 354420fa6a2cSEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] 354520fa6a2cSEd Tanous ["target"] = std::format( 3546253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/PostCodes/Actions/LogService.ClearLog", 354720fa6a2cSEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 35487e860f15SJohn Edward Broadbent }); 3549a3316fc6SZhikuiRen } 3550a3316fc6SZhikuiRen 35517e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3552a3316fc6SZhikuiRen { 35530fda0f12SGeorge Liu BMCWEB_ROUTE( 35540fda0f12SGeorge Liu app, 355522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/") 3556ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3557ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3558432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 35597e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 356045ca1b86SEd Tanous [&app](const crow::Request& req, 356122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 356222d268cbSEd Tanous const std::string& systemName) { 35633ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 356445ca1b86SEd Tanous { 356545ca1b86SEd Tanous return; 356645ca1b86SEd Tanous } 356725b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 35687f3e84a1SEd Tanous { 35697f3e84a1SEd Tanous // Option currently returns no systems. TBD 35707f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 35717f3e84a1SEd Tanous systemName); 35727f3e84a1SEd Tanous return; 35737f3e84a1SEd Tanous } 3574253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 357522d268cbSEd Tanous { 357622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 357722d268cbSEd Tanous systemName); 357822d268cbSEd Tanous return; 357922d268cbSEd Tanous } 358062598e31SEd Tanous BMCWEB_LOG_DEBUG("Do delete all postcodes entries."); 3581a3316fc6SZhikuiRen 3582a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3583a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 35845e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 3585a3316fc6SZhikuiRen if (ec) 3586a3316fc6SZhikuiRen { 3587a3316fc6SZhikuiRen // TODO Handle for specific error code 358862598e31SEd Tanous BMCWEB_LOG_ERROR("doClearPostCodes resp_handler got error {}", 358962598e31SEd Tanous ec); 3590002d39b4SEd Tanous asyncResp->res.result( 3591002d39b4SEd Tanous boost::beast::http::status::internal_server_error); 3592a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3593a3316fc6SZhikuiRen return; 3594a3316fc6SZhikuiRen } 359518fc70c0STony Lee messages::success(asyncResp->res); 3596a3316fc6SZhikuiRen }, 359715124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 359815124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3599a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 36007e860f15SJohn Edward Broadbent }); 3601a3316fc6SZhikuiRen } 3602a3316fc6SZhikuiRen 36036f284d24SJiaqing Zhao /** 36046f284d24SJiaqing Zhao * @brief Parse post code ID and get the current value and index value 36056f284d24SJiaqing Zhao * eg: postCodeID=B1-2, currentValue=1, index=2 36066f284d24SJiaqing Zhao * 36076f284d24SJiaqing Zhao * @param[in] postCodeID Post Code ID 36086f284d24SJiaqing Zhao * @param[out] currentValue Current value 36096f284d24SJiaqing Zhao * @param[out] index Index value 36106f284d24SJiaqing Zhao * 36116f284d24SJiaqing Zhao * @return bool true if the parsing is successful, false the parsing fails 36126f284d24SJiaqing Zhao */ 36136f056f24SEd Tanous inline bool parsePostCode(std::string_view postCodeID, uint64_t& currentValue, 3614df254f2cSEd Tanous uint16_t& index) 36156f284d24SJiaqing Zhao { 36166f284d24SJiaqing Zhao std::vector<std::string> split; 361750ebd4afSEd Tanous bmcweb::split(split, postCodeID, '-'); 36186f056f24SEd Tanous if (split.size() != 2) 36196f056f24SEd Tanous { 36206f056f24SEd Tanous return false; 36216f056f24SEd Tanous } 36226f056f24SEd Tanous std::string_view postCodeNumber = split[0]; 36236f056f24SEd Tanous if (postCodeNumber.size() < 2) 36246f056f24SEd Tanous { 36256f056f24SEd Tanous return false; 36266f056f24SEd Tanous } 36276f056f24SEd Tanous if (postCodeNumber[0] != 'B') 36286f056f24SEd Tanous { 36296f056f24SEd Tanous return false; 36306f056f24SEd Tanous } 36316f056f24SEd Tanous postCodeNumber.remove_prefix(1); 36326f056f24SEd Tanous auto [ptrIndex, ecIndex] = std::from_chars(postCodeNumber.begin(), 36336f056f24SEd Tanous postCodeNumber.end(), index); 36346f056f24SEd Tanous if (ptrIndex != postCodeNumber.end() || ecIndex != std::errc()) 36356f284d24SJiaqing Zhao { 36366f284d24SJiaqing Zhao return false; 36376f284d24SJiaqing Zhao } 36386f284d24SJiaqing Zhao 36396f056f24SEd Tanous std::string_view postCodeIndex = split[1]; 36406f284d24SJiaqing Zhao 36416f056f24SEd Tanous auto [ptrValue, ecValue] = std::from_chars( 36426f056f24SEd Tanous postCodeIndex.begin(), postCodeIndex.end(), currentValue); 36436f284d24SJiaqing Zhao 36446f056f24SEd Tanous return ptrValue == postCodeIndex.end() && ecValue == std::errc(); 36456f284d24SJiaqing Zhao } 36466f284d24SJiaqing Zhao 36476f284d24SJiaqing Zhao static bool fillPostCodeEntry( 3648ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 36496c9a279eSManojkiran Eda const boost::container::flat_map< 36506c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3651a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3652a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3653a3316fc6SZhikuiRen { 3654a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3655fffb8c1fSEd Tanous const registries::Message* message = 3656fffb8c1fSEd Tanous registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3657dc8cfa66SEd Tanous if (message == nullptr) 3658dc8cfa66SEd Tanous { 3659dc8cfa66SEd Tanous BMCWEB_LOG_ERROR("Couldn't find known message?"); 3660dc8cfa66SEd Tanous return false; 3661dc8cfa66SEd Tanous } 3662a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3663a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 36646c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 36656c9a279eSManojkiran Eda code : postcode) 3666a3316fc6SZhikuiRen { 3667a3316fc6SZhikuiRen currentCodeIndex++; 3668a3316fc6SZhikuiRen std::string postcodeEntryID = 3669a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3670a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3671a3316fc6SZhikuiRen 3672a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3673a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3674a3316fc6SZhikuiRen 3675a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3676a3316fc6SZhikuiRen { // already incremented 3677a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3678a3316fc6SZhikuiRen } 3679a3316fc6SZhikuiRen else 3680a3316fc6SZhikuiRen { 3681a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3682a3316fc6SZhikuiRen } 3683a3316fc6SZhikuiRen 3684a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3685a3316fc6SZhikuiRen // not fall between top and skip 3686a3316fc6SZhikuiRen if ((codeIndex == 0) && 3687a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3688a3316fc6SZhikuiRen { 3689a3316fc6SZhikuiRen continue; 3690a3316fc6SZhikuiRen } 3691a3316fc6SZhikuiRen 36924e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3693a3316fc6SZhikuiRen // currentIndex 3694a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3695a3316fc6SZhikuiRen { 3696a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3697a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3698a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3699a3316fc6SZhikuiRen continue; 3700a3316fc6SZhikuiRen } 3701a3316fc6SZhikuiRen 3702a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3703a3316fc6SZhikuiRen // index 3704a3316fc6SZhikuiRen 3705a3316fc6SZhikuiRen // Get the Created time from the timestamp 3706a3316fc6SZhikuiRen std::string entryTimeStr; 37072a025611SKonstantin Aladyshev entryTimeStr = redfish::time_utils::getDateTimeUintUs(usecSinceEpoch); 3708a3316fc6SZhikuiRen 3709a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3710a3316fc6SZhikuiRen std::ostringstream hexCode; 3711a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 37126c9a279eSManojkiran Eda << std::get<0>(code.second); 3713a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3714a3316fc6SZhikuiRen // Set Fixed -Point Notation 3715a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3716a3316fc6SZhikuiRen // Set precision to 4 digits 3717a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3718a3316fc6SZhikuiRen // Add double to stream 3719a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3720a3316fc6SZhikuiRen 37211e6deaf6SEd Tanous std::string bootIndexStr = std::to_string(bootIndex); 37221e6deaf6SEd Tanous std::string timeOffsetString = timeOffsetStr.str(); 37231e6deaf6SEd Tanous std::string hexCodeStr = hexCode.str(); 3724a3316fc6SZhikuiRen 37251e6deaf6SEd Tanous std::array<std::string_view, 3> messageArgs = { 37261e6deaf6SEd Tanous bootIndexStr, timeOffsetString, hexCodeStr}; 37271e6deaf6SEd Tanous 37281e6deaf6SEd Tanous std::string msg = 37291e6deaf6SEd Tanous redfish::registries::fillMessageArgs(messageArgs, message->message); 37301e6deaf6SEd Tanous if (msg.empty()) 3731a3316fc6SZhikuiRen { 37321e6deaf6SEd Tanous messages::internalError(asyncResp->res); 37331e6deaf6SEd Tanous return false; 3734a3316fc6SZhikuiRen } 3735a3316fc6SZhikuiRen 3736d4342a92STim Lee // Get Severity template from message registry 3737d4342a92STim Lee std::string severity; 3738d4342a92STim Lee if (message != nullptr) 3739d4342a92STim Lee { 37405f2b84eeSEd Tanous severity = message->messageSeverity; 3741d4342a92STim Lee } 3742d4342a92STim Lee 37436f284d24SJiaqing Zhao // Format entry 37446f284d24SJiaqing Zhao nlohmann::json::object_t bmcLogEntry; 37459c11a172SVijay Lobo bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 3746ef4c65b7SEd Tanous bmcLogEntry["@odata.id"] = boost::urls::format( 3747253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/{}", 3748253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, postcodeEntryID); 374984afc48bSJason M. Bills bmcLogEntry["Name"] = "POST Code Log Entry"; 375084afc48bSJason M. Bills bmcLogEntry["Id"] = postcodeEntryID; 375184afc48bSJason M. Bills bmcLogEntry["Message"] = std::move(msg); 375284afc48bSJason M. Bills bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode"; 37531e6deaf6SEd Tanous bmcLogEntry["MessageArgs"] = messageArgs; 375484afc48bSJason M. Bills bmcLogEntry["EntryType"] = "Event"; 375584afc48bSJason M. Bills bmcLogEntry["Severity"] = std::move(severity); 375684afc48bSJason M. Bills bmcLogEntry["Created"] = entryTimeStr; 3757647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 3758647b3cdcSGeorge Liu { 3759647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 3760253f11b8SEd Tanous std::format( 3761253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries/", 3762253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME) + 3763647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 3764647b3cdcSGeorge Liu } 37656f284d24SJiaqing Zhao 37666f284d24SJiaqing Zhao // codeIndex is only specified when querying single entry, return only 37676f284d24SJiaqing Zhao // that entry in this case 37686f284d24SJiaqing Zhao if (codeIndex != 0) 37696f284d24SJiaqing Zhao { 3770ac106bf6SEd Tanous asyncResp->res.jsonValue.update(bmcLogEntry); 37716f284d24SJiaqing Zhao return true; 3772a3316fc6SZhikuiRen } 37736f284d24SJiaqing Zhao 3774ac106bf6SEd Tanous nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 3775b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(bmcLogEntry)); 37766f284d24SJiaqing Zhao } 37776f284d24SJiaqing Zhao 37786f284d24SJiaqing Zhao // Return value is always false when querying multiple entries 37796f284d24SJiaqing Zhao return false; 3780a3316fc6SZhikuiRen } 3781a3316fc6SZhikuiRen 3782ac106bf6SEd Tanous static void 3783ac106bf6SEd Tanous getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 37846f284d24SJiaqing Zhao const std::string& entryId) 3785a3316fc6SZhikuiRen { 37866f284d24SJiaqing Zhao uint16_t bootIndex = 0; 37876f284d24SJiaqing Zhao uint64_t codeIndex = 0; 37886f284d24SJiaqing Zhao if (!parsePostCode(entryId, codeIndex, bootIndex)) 37896f284d24SJiaqing Zhao { 37906f284d24SJiaqing Zhao // Requested ID was not found 3791ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 37926f284d24SJiaqing Zhao return; 37936f284d24SJiaqing Zhao } 37946f284d24SJiaqing Zhao 37956f284d24SJiaqing Zhao if (bootIndex == 0 || codeIndex == 0) 37966f284d24SJiaqing Zhao { 37976f284d24SJiaqing Zhao // 0 is an invalid index 3798ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 37996f284d24SJiaqing Zhao return; 38006f284d24SJiaqing Zhao } 38016f284d24SJiaqing Zhao 3802a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3803ac106bf6SEd Tanous [asyncResp, entryId, bootIndex, 38045e7e2dc5SEd Tanous codeIndex](const boost::system::error_code& ec, 38056c9a279eSManojkiran Eda const boost::container::flat_map< 38066c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 38076c9a279eSManojkiran Eda postcode) { 3808a3316fc6SZhikuiRen if (ec) 3809a3316fc6SZhikuiRen { 381062598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error"); 3811ac106bf6SEd Tanous messages::internalError(asyncResp->res); 3812a3316fc6SZhikuiRen return; 3813a3316fc6SZhikuiRen } 3814a3316fc6SZhikuiRen 3815a3316fc6SZhikuiRen if (postcode.empty()) 3816a3316fc6SZhikuiRen { 3817ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 3818a3316fc6SZhikuiRen return; 3819a3316fc6SZhikuiRen } 3820a3316fc6SZhikuiRen 3821ac106bf6SEd Tanous if (!fillPostCodeEntry(asyncResp, postcode, bootIndex, codeIndex)) 38226f284d24SJiaqing Zhao { 3823ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 38246f284d24SJiaqing Zhao return; 38256f284d24SJiaqing Zhao } 3826a3316fc6SZhikuiRen }, 382715124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 382815124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3829a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3830a3316fc6SZhikuiRen bootIndex); 3831a3316fc6SZhikuiRen } 3832a3316fc6SZhikuiRen 3833ac106bf6SEd Tanous static void 3834ac106bf6SEd Tanous getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3835ac106bf6SEd Tanous const uint16_t bootIndex, const uint16_t bootCount, 3836ac106bf6SEd Tanous const uint64_t entryCount, size_t skip, size_t top) 3837a3316fc6SZhikuiRen { 3838a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3839ac106bf6SEd Tanous [asyncResp, bootIndex, bootCount, entryCount, skip, 38405e7e2dc5SEd Tanous top](const boost::system::error_code& ec, 38416c9a279eSManojkiran Eda const boost::container::flat_map< 38426c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 38436c9a279eSManojkiran Eda postcode) { 3844a3316fc6SZhikuiRen if (ec) 3845a3316fc6SZhikuiRen { 384662598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS POST CODE PostCode response error"); 3847ac106bf6SEd Tanous messages::internalError(asyncResp->res); 3848a3316fc6SZhikuiRen return; 3849a3316fc6SZhikuiRen } 3850a3316fc6SZhikuiRen 3851a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3852a3316fc6SZhikuiRen if (!postcode.empty()) 3853a3316fc6SZhikuiRen { 3854a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 38553648c8beSEd Tanous if (skip < endCount && (top + skip) > entryCount) 3856a3316fc6SZhikuiRen { 385789492a15SPatrick Williams uint64_t thisBootSkip = std::max(static_cast<uint64_t>(skip), 385889492a15SPatrick Williams entryCount) - 38593648c8beSEd Tanous entryCount; 3860a3316fc6SZhikuiRen uint64_t thisBootTop = 38613648c8beSEd Tanous std::min(static_cast<uint64_t>(top + skip), endCount) - 38623648c8beSEd Tanous entryCount; 3863a3316fc6SZhikuiRen 3864ac106bf6SEd Tanous fillPostCodeEntry(asyncResp, postcode, bootIndex, 0, 3865ac106bf6SEd Tanous thisBootSkip, thisBootTop); 3866a3316fc6SZhikuiRen } 3867ac106bf6SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = endCount; 3868a3316fc6SZhikuiRen } 3869a3316fc6SZhikuiRen 3870a3316fc6SZhikuiRen // continue to previous bootIndex 3871a3316fc6SZhikuiRen if (bootIndex < bootCount) 3872a3316fc6SZhikuiRen { 3873ac106bf6SEd Tanous getPostCodeForBoot(asyncResp, static_cast<uint16_t>(bootIndex + 1), 3874a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3875a3316fc6SZhikuiRen } 387681584abeSJiaqing Zhao else if (skip + top < endCount) 3877a3316fc6SZhikuiRen { 3878ac106bf6SEd Tanous asyncResp->res.jsonValue["Members@odata.nextLink"] = 3879253f11b8SEd Tanous std::format( 3880253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices/PostCodes/Entries?$skip=", 3881253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME) + 3882a3316fc6SZhikuiRen std::to_string(skip + top); 3883a3316fc6SZhikuiRen } 3884a3316fc6SZhikuiRen }, 388515124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 388615124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3887a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3888a3316fc6SZhikuiRen bootIndex); 3889a3316fc6SZhikuiRen } 3890a3316fc6SZhikuiRen 38918d1b46d7Szhanghch05 static void 3892ac106bf6SEd Tanous getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 38933648c8beSEd Tanous size_t skip, size_t top) 3894a3316fc6SZhikuiRen { 3895a3316fc6SZhikuiRen uint64_t entryCount = 0; 38961e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint16_t>( 38971e1e598dSJonathan Doman *crow::connections::systemBus, 38981e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 38991e1e598dSJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 39001e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", 3901ac106bf6SEd Tanous [asyncResp, entryCount, skip, top](const boost::system::error_code& ec, 39021e1e598dSJonathan Doman const uint16_t bootCount) { 3903a3316fc6SZhikuiRen if (ec) 3904a3316fc6SZhikuiRen { 390562598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 3906ac106bf6SEd Tanous messages::internalError(asyncResp->res); 3907a3316fc6SZhikuiRen return; 3908a3316fc6SZhikuiRen } 3909ac106bf6SEd Tanous getPostCodeForBoot(asyncResp, 1, bootCount, entryCount, skip, top); 39101e1e598dSJonathan Doman }); 3911a3316fc6SZhikuiRen } 3912a3316fc6SZhikuiRen 39137e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3914a3316fc6SZhikuiRen { 39157e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 391622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/") 3917ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 39187e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 391945ca1b86SEd Tanous [&app](const crow::Request& req, 392022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 392122d268cbSEd Tanous const std::string& systemName) { 3922c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 3923c937d2bfSEd Tanous .canDelegateTop = true, 3924c937d2bfSEd Tanous .canDelegateSkip = true, 3925c937d2bfSEd Tanous }; 3926c937d2bfSEd Tanous query_param::Query delegatedQuery; 3927c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 39283ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 392945ca1b86SEd Tanous { 393045ca1b86SEd Tanous return; 393145ca1b86SEd Tanous } 393225b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 39337f3e84a1SEd Tanous { 39347f3e84a1SEd Tanous // Option currently returns no systems. TBD 39357f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 39367f3e84a1SEd Tanous systemName); 39377f3e84a1SEd Tanous return; 39387f3e84a1SEd Tanous } 393922d268cbSEd Tanous 3940253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 394122d268cbSEd Tanous { 394222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 394322d268cbSEd Tanous systemName); 394422d268cbSEd Tanous return; 394522d268cbSEd Tanous } 3946a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3947a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3948a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3949253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/LogServices/PostCodes/Entries", 3950253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3951a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3952a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3953a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3954a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3955a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 39563648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 39575143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 39583648c8beSEd Tanous getCurrentBootNumber(asyncResp, skip, top); 39597e860f15SJohn Edward Broadbent }); 3960a3316fc6SZhikuiRen } 3961a3316fc6SZhikuiRen 3962647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3963647b3cdcSGeorge Liu { 39640fda0f12SGeorge Liu BMCWEB_ROUTE( 39650fda0f12SGeorge Liu app, 396622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/") 3967647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 3968647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 396945ca1b86SEd Tanous [&app](const crow::Request& req, 3970647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 397122d268cbSEd Tanous const std::string& systemName, 3972647b3cdcSGeorge Liu const std::string& postCodeID) { 39733ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 397445ca1b86SEd Tanous { 397545ca1b86SEd Tanous return; 397645ca1b86SEd Tanous } 397772e21377SMatt Spinler if (!http_helpers::isContentTypeAllowed( 397899351cd8SEd Tanous req.getHeaderValue("Accept"), 39794a0e1a0cSEd Tanous http_helpers::ContentType::OctetStream, true)) 3980647b3cdcSGeorge Liu { 3981002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 3982647b3cdcSGeorge Liu return; 3983647b3cdcSGeorge Liu } 398425b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 39857f3e84a1SEd Tanous { 39867f3e84a1SEd Tanous // Option currently returns no systems. TBD 39877f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 39887f3e84a1SEd Tanous systemName); 39897f3e84a1SEd Tanous return; 39907f3e84a1SEd Tanous } 3991253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 399222d268cbSEd Tanous { 399322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 399422d268cbSEd Tanous systemName); 399522d268cbSEd Tanous return; 399622d268cbSEd Tanous } 3997647b3cdcSGeorge Liu 3998647b3cdcSGeorge Liu uint64_t currentValue = 0; 3999647b3cdcSGeorge Liu uint16_t index = 0; 4000647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 4001647b3cdcSGeorge Liu { 4002002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID); 4003647b3cdcSGeorge Liu return; 4004647b3cdcSGeorge Liu } 4005647b3cdcSGeorge Liu 4006647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 4007647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 40085e7e2dc5SEd Tanous const boost::system::error_code& ec, 4009002d39b4SEd Tanous const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>& 4010002d39b4SEd Tanous postcodes) { 4011647b3cdcSGeorge Liu if (ec.value() == EBADR) 4012647b3cdcSGeorge Liu { 4013002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4014002d39b4SEd Tanous postCodeID); 4015647b3cdcSGeorge Liu return; 4016647b3cdcSGeorge Liu } 4017647b3cdcSGeorge Liu if (ec) 4018647b3cdcSGeorge Liu { 401962598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 4020647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 4021647b3cdcSGeorge Liu return; 4022647b3cdcSGeorge Liu } 4023647b3cdcSGeorge Liu 4024647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 4025002d39b4SEd Tanous if (value == std::string::npos || postcodes.size() < currentValue) 4026647b3cdcSGeorge Liu { 402762598e31SEd Tanous BMCWEB_LOG_WARNING("Wrong currentValue value"); 4028002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4029002d39b4SEd Tanous postCodeID); 4030647b3cdcSGeorge Liu return; 4031647b3cdcSGeorge Liu } 4032647b3cdcSGeorge Liu 40339eb808c1SEd Tanous const auto& [tID, c] = postcodes[value]; 403446ff87baSEd Tanous if (c.empty()) 4035647b3cdcSGeorge Liu { 403662598e31SEd Tanous BMCWEB_LOG_WARNING("No found post code data"); 4037002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4038002d39b4SEd Tanous postCodeID); 4039647b3cdcSGeorge Liu return; 4040647b3cdcSGeorge Liu } 404146ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 404246ff87baSEd Tanous const char* d = reinterpret_cast<const char*>(c.data()); 404346ff87baSEd Tanous std::string_view strData(d, c.size()); 4044647b3cdcSGeorge Liu 4045d9f6c621SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::content_type, 4046647b3cdcSGeorge Liu "application/octet-stream"); 4047d9f6c621SEd Tanous asyncResp->res.addHeader( 4048d9f6c621SEd Tanous boost::beast::http::field::content_transfer_encoding, "Base64"); 404927b0cf90SEd Tanous asyncResp->res.write(crow::utility::base64encode(strData)); 4050647b3cdcSGeorge Liu }, 4051647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 4052647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 4053002d39b4SEd Tanous "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index); 4054647b3cdcSGeorge Liu }); 4055647b3cdcSGeorge Liu } 4056647b3cdcSGeorge Liu 40577e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 4058a3316fc6SZhikuiRen { 40597e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 406022d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/") 4061ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 40627e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 406345ca1b86SEd Tanous [&app](const crow::Request& req, 40647e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 406522d268cbSEd Tanous const std::string& systemName, const std::string& targetID) { 40663ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 406745ca1b86SEd Tanous { 406845ca1b86SEd Tanous return; 406945ca1b86SEd Tanous } 407025b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 40717f3e84a1SEd Tanous { 40727f3e84a1SEd Tanous // Option currently returns no systems. TBD 40737f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 40747f3e84a1SEd Tanous systemName); 40757f3e84a1SEd Tanous return; 40767f3e84a1SEd Tanous } 4077253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 407822d268cbSEd Tanous { 407922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 408022d268cbSEd Tanous systemName); 408122d268cbSEd Tanous return; 408222d268cbSEd Tanous } 408322d268cbSEd Tanous 40846f284d24SJiaqing Zhao getPostCodeForEntry(asyncResp, targetID); 40857e860f15SJohn Edward Broadbent }); 4086a3316fc6SZhikuiRen } 4087a3316fc6SZhikuiRen 40881da66f75SEd Tanous } // namespace redfish 4089