11da66f75SEd Tanous /* 21da66f75SEd Tanous // Copyright (c) 2018 Intel Corporation 31da66f75SEd Tanous // 41da66f75SEd Tanous // Licensed under the Apache License, Version 2.0 (the "License"); 51da66f75SEd Tanous // you may not use this file except in compliance with the License. 61da66f75SEd Tanous // You may obtain a copy of the License at 71da66f75SEd Tanous // 81da66f75SEd Tanous // http://www.apache.org/licenses/LICENSE-2.0 91da66f75SEd Tanous // 101da66f75SEd Tanous // Unless required by applicable law or agreed to in writing, software 111da66f75SEd Tanous // distributed under the License is distributed on an "AS IS" BASIS, 121da66f75SEd Tanous // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131da66f75SEd Tanous // See the License for the specific language governing permissions and 141da66f75SEd Tanous // limitations under the License. 151da66f75SEd Tanous */ 161da66f75SEd Tanous #pragma once 171da66f75SEd Tanous 183ccb3adbSEd Tanous #include "app.hpp" 197a1dbc48SGeorge Liu #include "dbus_utility.hpp" 203ccb3adbSEd Tanous #include "error_messages.hpp" 2168dd075aSAsmitha Karunanithi #include "generated/enums/log_entry.hpp" 22b7028ebfSSpencer Ku #include "gzfile.hpp" 23647b3cdcSGeorge Liu #include "http_utility.hpp" 24b7028ebfSSpencer Ku #include "human_sort.hpp" 253ccb3adbSEd Tanous #include "query.hpp" 264851d45dSJason M. Bills #include "registries.hpp" 274851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 284851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 293ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 3046229577SJames Feist #include "task.hpp" 313ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 323ccb3adbSEd Tanous #include "utils/time_utils.hpp" 331da66f75SEd Tanous 34e1f26343SJason M. Bills #include <systemd/sd-journal.h> 358e31778eSAsmitha Karunanithi #include <tinyxml2.h> 36400fd1fbSAdriana Kobylak #include <unistd.h> 37e1f26343SJason M. Bills 389896eaedSEd Tanous #include <boost/algorithm/string/case_conv.hpp> 3911ba3979SEd Tanous #include <boost/algorithm/string/classification.hpp> 40400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 414851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 4207c8c20dSEd Tanous #include <boost/beast/http/verb.hpp> 431da66f75SEd Tanous #include <boost/container/flat_map.hpp> 441ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 45ef4c65b7SEd Tanous #include <boost/url/format.hpp> 46d1bde9e5SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 47d1bde9e5SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 481214b7e7SGunnar Mills 497a1dbc48SGeorge Liu #include <array> 50647b3cdcSGeorge Liu #include <charconv> 514418c7f0SJames Feist #include <filesystem> 5275710de2SXiaochao Ma #include <optional> 5326702d01SEd Tanous #include <span> 54cd225da8SJason M. Bills #include <string_view> 55abf2add6SEd Tanous #include <variant> 561da66f75SEd Tanous 571da66f75SEd Tanous namespace redfish 581da66f75SEd Tanous { 591da66f75SEd Tanous 6089492a15SPatrick Williams constexpr const char* crashdumpObject = "com.intel.crashdump"; 6189492a15SPatrick Williams constexpr const char* crashdumpPath = "/com/intel/crashdump"; 6289492a15SPatrick Williams constexpr const char* crashdumpInterface = "com.intel.crashdump"; 6389492a15SPatrick Williams constexpr const char* deleteAllInterface = 645b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 6589492a15SPatrick Williams constexpr const char* crashdumpOnDemandInterface = 66424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 6789492a15SPatrick Williams constexpr const char* crashdumpTelemetryInterface = 686eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 691da66f75SEd Tanous 708e31778eSAsmitha Karunanithi enum class DumpCreationProgress 718e31778eSAsmitha Karunanithi { 728e31778eSAsmitha Karunanithi DUMP_CREATE_SUCCESS, 738e31778eSAsmitha Karunanithi DUMP_CREATE_FAILED, 748e31778eSAsmitha Karunanithi DUMP_CREATE_INPROGRESS 758e31778eSAsmitha Karunanithi }; 768e31778eSAsmitha Karunanithi 77f6150403SJames Feist namespace fs = std::filesystem; 781da66f75SEd Tanous 79cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 80cb92c03bSAndrew Geissler { 81d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 82d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 83d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 84d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 85cb92c03bSAndrew Geissler { 86cb92c03bSAndrew Geissler return "Critical"; 87cb92c03bSAndrew Geissler } 883174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 89d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 90d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 91cb92c03bSAndrew Geissler { 92cb92c03bSAndrew Geissler return "OK"; 93cb92c03bSAndrew Geissler } 943174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 95cb92c03bSAndrew Geissler { 96cb92c03bSAndrew Geissler return "Warning"; 97cb92c03bSAndrew Geissler } 98cb92c03bSAndrew Geissler return ""; 99cb92c03bSAndrew Geissler } 100cb92c03bSAndrew Geissler 1019017faf2SAbhishek Patel inline std::optional<bool> getProviderNotifyAction(const std::string& notify) 1029017faf2SAbhishek Patel { 1039017faf2SAbhishek Patel std::optional<bool> notifyAction; 1049017faf2SAbhishek Patel if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify") 1059017faf2SAbhishek Patel { 1069017faf2SAbhishek Patel notifyAction = true; 1079017faf2SAbhishek Patel } 1089017faf2SAbhishek Patel else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit") 1099017faf2SAbhishek Patel { 1109017faf2SAbhishek Patel notifyAction = false; 1119017faf2SAbhishek Patel } 1129017faf2SAbhishek Patel 1139017faf2SAbhishek Patel return notifyAction; 1149017faf2SAbhishek Patel } 1159017faf2SAbhishek Patel 1167e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 11726ccae32SEd Tanous std::string_view field, 11839e77504SEd Tanous std::string_view& contents) 11916428a1aSJason M. Bills { 12016428a1aSJason M. Bills const char* data = nullptr; 12116428a1aSJason M. Bills size_t length = 0; 12216428a1aSJason M. Bills int ret = 0; 12316428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 12446ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 12546ff87baSEd Tanous const void** dataVoid = reinterpret_cast<const void**>(&data); 12646ff87baSEd Tanous 12746ff87baSEd Tanous ret = sd_journal_get_data(journal, field.data(), dataVoid, &length); 12816428a1aSJason M. Bills if (ret < 0) 12916428a1aSJason M. Bills { 13016428a1aSJason M. Bills return ret; 13116428a1aSJason M. Bills } 13239e77504SEd Tanous contents = std::string_view(data, length); 13316428a1aSJason M. Bills // Only use the content after the "=" character. 13481ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 13516428a1aSJason M. Bills return ret; 13616428a1aSJason M. Bills } 13716428a1aSJason M. Bills 1387e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 13926ccae32SEd Tanous std::string_view field, const int& base, 14026ccae32SEd Tanous long int& contents) 14116428a1aSJason M. Bills { 14216428a1aSJason M. Bills int ret = 0; 14339e77504SEd Tanous std::string_view metadata; 14416428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 14516428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 14616428a1aSJason M. Bills if (ret < 0) 14716428a1aSJason M. Bills { 14816428a1aSJason M. Bills return ret; 14916428a1aSJason M. Bills } 150b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 15116428a1aSJason M. Bills return ret; 15216428a1aSJason M. Bills } 15316428a1aSJason M. Bills 1547e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1557e860f15SJohn Edward Broadbent std::string& entryTimestamp) 156a3316fc6SZhikuiRen { 157a3316fc6SZhikuiRen int ret = 0; 158a3316fc6SZhikuiRen uint64_t timestamp = 0; 159a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 160a3316fc6SZhikuiRen if (ret < 0) 161a3316fc6SZhikuiRen { 162a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 163a3316fc6SZhikuiRen << strerror(-ret); 164a3316fc6SZhikuiRen return false; 165a3316fc6SZhikuiRen } 166e645c5e6SKonstantin Aladyshev entryTimestamp = redfish::time_utils::getDateTimeUintUs(timestamp); 1679c620e21SAsmitha Karunanithi return true; 168a3316fc6SZhikuiRen } 16950b8a43aSEd Tanous 1707e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 171e85d6b16SJason M. Bills const bool firstEntry = true) 17216428a1aSJason M. Bills { 17316428a1aSJason M. Bills int ret = 0; 17416428a1aSJason M. Bills static uint64_t prevTs = 0; 17516428a1aSJason M. Bills static int index = 0; 176e85d6b16SJason M. Bills if (firstEntry) 177e85d6b16SJason M. Bills { 178e85d6b16SJason M. Bills prevTs = 0; 179e85d6b16SJason M. Bills } 180e85d6b16SJason M. Bills 18116428a1aSJason M. Bills // Get the entry timestamp 18216428a1aSJason M. Bills uint64_t curTs = 0; 18316428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 18416428a1aSJason M. Bills if (ret < 0) 18516428a1aSJason M. Bills { 18616428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 18716428a1aSJason M. Bills << strerror(-ret); 18816428a1aSJason M. Bills return false; 18916428a1aSJason M. Bills } 19016428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 19116428a1aSJason M. Bills if (curTs == prevTs) 19216428a1aSJason M. Bills { 19316428a1aSJason M. Bills index++; 19416428a1aSJason M. Bills } 19516428a1aSJason M. Bills else 19616428a1aSJason M. Bills { 19716428a1aSJason M. Bills // Otherwise, reset it 19816428a1aSJason M. Bills index = 0; 19916428a1aSJason M. Bills } 20016428a1aSJason M. Bills // Save the timestamp 20116428a1aSJason M. Bills prevTs = curTs; 20216428a1aSJason M. Bills 20316428a1aSJason M. Bills entryID = std::to_string(curTs); 20416428a1aSJason M. Bills if (index > 0) 20516428a1aSJason M. Bills { 20616428a1aSJason M. Bills entryID += "_" + std::to_string(index); 20716428a1aSJason M. Bills } 20816428a1aSJason M. Bills return true; 20916428a1aSJason M. Bills } 21016428a1aSJason M. Bills 211e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 212e85d6b16SJason M. Bills const bool firstEntry = true) 21395820184SJason M. Bills { 214271584abSEd Tanous static time_t prevTs = 0; 21595820184SJason M. Bills static int index = 0; 216e85d6b16SJason M. Bills if (firstEntry) 217e85d6b16SJason M. Bills { 218e85d6b16SJason M. Bills prevTs = 0; 219e85d6b16SJason M. Bills } 220e85d6b16SJason M. Bills 22195820184SJason M. Bills // Get the entry timestamp 222271584abSEd Tanous std::time_t curTs = 0; 22395820184SJason M. Bills std::tm timeStruct = {}; 22495820184SJason M. Bills std::istringstream entryStream(logEntry); 22595820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 22695820184SJason M. Bills { 22795820184SJason M. Bills curTs = std::mktime(&timeStruct); 22895820184SJason M. Bills } 22995820184SJason M. Bills // If the timestamp isn't unique, increment the index 23095820184SJason M. Bills if (curTs == prevTs) 23195820184SJason M. Bills { 23295820184SJason M. Bills index++; 23395820184SJason M. Bills } 23495820184SJason M. Bills else 23595820184SJason M. Bills { 23695820184SJason M. Bills // Otherwise, reset it 23795820184SJason M. Bills index = 0; 23895820184SJason M. Bills } 23995820184SJason M. Bills // Save the timestamp 24095820184SJason M. Bills prevTs = curTs; 24195820184SJason M. Bills 24295820184SJason M. Bills entryID = std::to_string(curTs); 24395820184SJason M. Bills if (index > 0) 24495820184SJason M. Bills { 24595820184SJason M. Bills entryID += "_" + std::to_string(index); 24695820184SJason M. Bills } 24795820184SJason M. Bills return true; 24895820184SJason M. Bills } 24995820184SJason M. Bills 2507e860f15SJohn Edward Broadbent inline static bool 2518d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2528d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 2538d1b46d7Szhanghch05 uint64_t& index) 25416428a1aSJason M. Bills { 25516428a1aSJason M. Bills if (entryID.empty()) 25616428a1aSJason M. Bills { 25716428a1aSJason M. Bills return false; 25816428a1aSJason M. Bills } 25916428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 26039e77504SEd Tanous std::string_view tsStr(entryID); 26116428a1aSJason M. Bills 26281ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 26371d5d8dbSEd Tanous if (underscorePos != std::string_view::npos) 26416428a1aSJason M. Bills { 26516428a1aSJason M. Bills // Timestamp has an index 26616428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 26739e77504SEd Tanous std::string_view indexStr(entryID); 26816428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 26984396af9SPatrick Williams auto [ptr, ec] = std::from_chars(indexStr.begin(), indexStr.end(), 27084396af9SPatrick Williams index); 271c0bd5e4bSEd Tanous if (ec != std::errc()) 27216428a1aSJason M. Bills { 2739db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 27416428a1aSJason M. Bills return false; 27516428a1aSJason M. Bills } 27616428a1aSJason M. Bills } 27716428a1aSJason M. Bills // Timestamp has no index 27884396af9SPatrick Williams auto [ptr, ec] = std::from_chars(tsStr.begin(), tsStr.end(), timestamp); 279c0bd5e4bSEd Tanous if (ec != std::errc()) 28016428a1aSJason M. Bills { 2819db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 28216428a1aSJason M. Bills return false; 28316428a1aSJason M. Bills } 28416428a1aSJason M. Bills return true; 28516428a1aSJason M. Bills } 28616428a1aSJason M. Bills 28795820184SJason M. Bills static bool 28895820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 28995820184SJason M. Bills { 29095820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 29195820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 29295820184SJason M. Bills 29395820184SJason M. Bills // Loop through the directory looking for redfish log files 29495820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 29595820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 29695820184SJason M. Bills { 29795820184SJason M. Bills // If we find a redfish log file, save the path 29895820184SJason M. Bills std::string filename = dirEnt.path().filename(); 29911ba3979SEd Tanous if (filename.starts_with(redfishLogFilename)) 30095820184SJason M. Bills { 30195820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 30295820184SJason M. Bills } 30395820184SJason M. Bills } 30495820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 30595820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 30695820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 30795820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 30895820184SJason M. Bills 30995820184SJason M. Bills return !redfishLogFiles.empty(); 31095820184SJason M. Bills } 31195820184SJason M. Bills 31268dd075aSAsmitha Karunanithi inline log_entry::OriginatorTypes 31368dd075aSAsmitha Karunanithi mapDbusOriginatorTypeToRedfish(const std::string& originatorType) 31468dd075aSAsmitha Karunanithi { 31568dd075aSAsmitha Karunanithi if (originatorType == 31668dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client") 31768dd075aSAsmitha Karunanithi { 31868dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::Client; 31968dd075aSAsmitha Karunanithi } 32068dd075aSAsmitha Karunanithi if (originatorType == 32168dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal") 32268dd075aSAsmitha Karunanithi { 32368dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::Internal; 32468dd075aSAsmitha Karunanithi } 32568dd075aSAsmitha Karunanithi if (originatorType == 32668dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService") 32768dd075aSAsmitha Karunanithi { 32868dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::SupportingService; 32968dd075aSAsmitha Karunanithi } 33068dd075aSAsmitha Karunanithi return log_entry::OriginatorTypes::Invalid; 33168dd075aSAsmitha Karunanithi } 33268dd075aSAsmitha Karunanithi 333aefe3786SClaire Weinan inline void parseDumpEntryFromDbusObject( 3342d613eb6SJiaqing Zhao const dbus::utility::ManagedObjectType::value_type& object, 335c6fecdabSClaire Weinan std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs, 33668dd075aSAsmitha Karunanithi std::string& originatorId, log_entry::OriginatorTypes& originatorType, 337aefe3786SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 338aefe3786SClaire Weinan { 339aefe3786SClaire Weinan for (const auto& interfaceMap : object.second) 340aefe3786SClaire Weinan { 341aefe3786SClaire Weinan if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") 342aefe3786SClaire Weinan { 343aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 344aefe3786SClaire Weinan { 345aefe3786SClaire Weinan if (propertyMap.first == "Status") 346aefe3786SClaire Weinan { 347aefe3786SClaire Weinan const auto* status = 348aefe3786SClaire Weinan std::get_if<std::string>(&propertyMap.second); 349aefe3786SClaire Weinan if (status == nullptr) 350aefe3786SClaire Weinan { 351aefe3786SClaire Weinan messages::internalError(asyncResp->res); 352aefe3786SClaire Weinan break; 353aefe3786SClaire Weinan } 354aefe3786SClaire Weinan dumpStatus = *status; 355aefe3786SClaire Weinan } 356aefe3786SClaire Weinan } 357aefe3786SClaire Weinan } 358aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 359aefe3786SClaire Weinan { 360aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 361aefe3786SClaire Weinan { 362aefe3786SClaire Weinan if (propertyMap.first == "Size") 363aefe3786SClaire Weinan { 364aefe3786SClaire Weinan const auto* sizePtr = 365aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 366aefe3786SClaire Weinan if (sizePtr == nullptr) 367aefe3786SClaire Weinan { 368aefe3786SClaire Weinan messages::internalError(asyncResp->res); 369aefe3786SClaire Weinan break; 370aefe3786SClaire Weinan } 371aefe3786SClaire Weinan size = *sizePtr; 372aefe3786SClaire Weinan break; 373aefe3786SClaire Weinan } 374aefe3786SClaire Weinan } 375aefe3786SClaire Weinan } 376aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") 377aefe3786SClaire Weinan { 378aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 379aefe3786SClaire Weinan { 380aefe3786SClaire Weinan if (propertyMap.first == "Elapsed") 381aefe3786SClaire Weinan { 382aefe3786SClaire Weinan const uint64_t* usecsTimeStamp = 383aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 384aefe3786SClaire Weinan if (usecsTimeStamp == nullptr) 385aefe3786SClaire Weinan { 386aefe3786SClaire Weinan messages::internalError(asyncResp->res); 387aefe3786SClaire Weinan break; 388aefe3786SClaire Weinan } 389c6fecdabSClaire Weinan timestampUs = *usecsTimeStamp; 390aefe3786SClaire Weinan break; 391aefe3786SClaire Weinan } 392aefe3786SClaire Weinan } 393aefe3786SClaire Weinan } 39468dd075aSAsmitha Karunanithi else if (interfaceMap.first == 39568dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy") 39668dd075aSAsmitha Karunanithi { 39768dd075aSAsmitha Karunanithi for (const auto& propertyMap : interfaceMap.second) 39868dd075aSAsmitha Karunanithi { 39968dd075aSAsmitha Karunanithi if (propertyMap.first == "OriginatorId") 40068dd075aSAsmitha Karunanithi { 40168dd075aSAsmitha Karunanithi const std::string* id = 40268dd075aSAsmitha Karunanithi std::get_if<std::string>(&propertyMap.second); 40368dd075aSAsmitha Karunanithi if (id == nullptr) 40468dd075aSAsmitha Karunanithi { 40568dd075aSAsmitha Karunanithi messages::internalError(asyncResp->res); 40668dd075aSAsmitha Karunanithi break; 40768dd075aSAsmitha Karunanithi } 40868dd075aSAsmitha Karunanithi originatorId = *id; 40968dd075aSAsmitha Karunanithi } 41068dd075aSAsmitha Karunanithi 41168dd075aSAsmitha Karunanithi if (propertyMap.first == "OriginatorType") 41268dd075aSAsmitha Karunanithi { 41368dd075aSAsmitha Karunanithi const std::string* type = 41468dd075aSAsmitha Karunanithi std::get_if<std::string>(&propertyMap.second); 41568dd075aSAsmitha Karunanithi if (type == nullptr) 41668dd075aSAsmitha Karunanithi { 41768dd075aSAsmitha Karunanithi messages::internalError(asyncResp->res); 41868dd075aSAsmitha Karunanithi break; 41968dd075aSAsmitha Karunanithi } 42068dd075aSAsmitha Karunanithi 42168dd075aSAsmitha Karunanithi originatorType = mapDbusOriginatorTypeToRedfish(*type); 42268dd075aSAsmitha Karunanithi if (originatorType == log_entry::OriginatorTypes::Invalid) 42368dd075aSAsmitha Karunanithi { 42468dd075aSAsmitha Karunanithi messages::internalError(asyncResp->res); 42568dd075aSAsmitha Karunanithi break; 42668dd075aSAsmitha Karunanithi } 42768dd075aSAsmitha Karunanithi } 42868dd075aSAsmitha Karunanithi } 42968dd075aSAsmitha Karunanithi } 430aefe3786SClaire Weinan } 431aefe3786SClaire Weinan } 432aefe3786SClaire Weinan 43321ab404cSNan Zhou static std::string getDumpEntriesPath(const std::string& dumpType) 434fdd26906SClaire Weinan { 435fdd26906SClaire Weinan std::string entriesPath; 436fdd26906SClaire Weinan 437fdd26906SClaire Weinan if (dumpType == "BMC") 438fdd26906SClaire Weinan { 439fdd26906SClaire Weinan entriesPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 440fdd26906SClaire Weinan } 441fdd26906SClaire Weinan else if (dumpType == "FaultLog") 442fdd26906SClaire Weinan { 443fdd26906SClaire Weinan entriesPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/"; 444fdd26906SClaire Weinan } 445fdd26906SClaire Weinan else if (dumpType == "System") 446fdd26906SClaire Weinan { 447fdd26906SClaire Weinan entriesPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 448fdd26906SClaire Weinan } 449fdd26906SClaire Weinan else 450fdd26906SClaire Weinan { 451fdd26906SClaire Weinan BMCWEB_LOG_ERROR << "getDumpEntriesPath() invalid dump type: " 452fdd26906SClaire Weinan << dumpType; 453fdd26906SClaire Weinan } 454fdd26906SClaire Weinan 455fdd26906SClaire Weinan // Returns empty string on error 456fdd26906SClaire Weinan return entriesPath; 457fdd26906SClaire Weinan } 458fdd26906SClaire Weinan 4598d1b46d7Szhanghch05 inline void 4608d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4615cb1dd27SAsmitha Karunanithi const std::string& dumpType) 4625cb1dd27SAsmitha Karunanithi { 463fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 464fdd26906SClaire Weinan if (entriesPath.empty()) 4655cb1dd27SAsmitha Karunanithi { 4665cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4675cb1dd27SAsmitha Karunanithi return; 4685cb1dd27SAsmitha Karunanithi } 4695cb1dd27SAsmitha Karunanithi 4705eb468daSGeorge Liu sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); 4715eb468daSGeorge Liu dbus::utility::getManagedObjects( 4725eb468daSGeorge Liu "xyz.openbmc_project.Dump.Manager", path, 473fdd26906SClaire Weinan [asyncResp, entriesPath, 4745e7e2dc5SEd Tanous dumpType](const boost::system::error_code& ec, 4755eb468daSGeorge Liu const dbus::utility::ManagedObjectType& objects) { 4765cb1dd27SAsmitha Karunanithi if (ec) 4775cb1dd27SAsmitha Karunanithi { 4785cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4795cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4805cb1dd27SAsmitha Karunanithi return; 4815cb1dd27SAsmitha Karunanithi } 4825cb1dd27SAsmitha Karunanithi 483fdd26906SClaire Weinan // Remove ending slash 484fdd26906SClaire Weinan std::string odataIdStr = entriesPath; 485fdd26906SClaire Weinan if (!odataIdStr.empty()) 486fdd26906SClaire Weinan { 487fdd26906SClaire Weinan odataIdStr.pop_back(); 488fdd26906SClaire Weinan } 489fdd26906SClaire Weinan 490fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = 491fdd26906SClaire Weinan "#LogEntryCollection.LogEntryCollection"; 492fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr); 493fdd26906SClaire Weinan asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries"; 49489492a15SPatrick Williams asyncResp->res.jsonValue["Description"] = "Collection of " + dumpType + 49589492a15SPatrick Williams " Dump Entries"; 496fdd26906SClaire Weinan 4975cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4985cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 499b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 500b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 501002d39b4SEd Tanous std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; 5025cb1dd27SAsmitha Karunanithi 5035eb468daSGeorge Liu dbus::utility::ManagedObjectType resp(objects); 504002d39b4SEd Tanous std::sort(resp.begin(), resp.end(), [](const auto& l, const auto& r) { 505002d39b4SEd Tanous return AlphanumLess<std::string>()(l.first.filename(), 506002d39b4SEd Tanous r.first.filename()); 507565dfb6fSClaire Weinan }); 508565dfb6fSClaire Weinan 5095cb1dd27SAsmitha Karunanithi for (auto& object : resp) 5105cb1dd27SAsmitha Karunanithi { 511b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 5125cb1dd27SAsmitha Karunanithi { 5135cb1dd27SAsmitha Karunanithi continue; 5145cb1dd27SAsmitha Karunanithi } 515c6fecdabSClaire Weinan uint64_t timestampUs = 0; 5165cb1dd27SAsmitha Karunanithi uint64_t size = 0; 51735440d18SAsmitha Karunanithi std::string dumpStatus; 51868dd075aSAsmitha Karunanithi std::string originatorId; 51968dd075aSAsmitha Karunanithi log_entry::OriginatorTypes originatorType = 52068dd075aSAsmitha Karunanithi log_entry::OriginatorTypes::Internal; 521433b68b4SJason M. Bills nlohmann::json::object_t thisEntry; 5222dfd18efSEd Tanous 5232dfd18efSEd Tanous std::string entryID = object.first.filename(); 5242dfd18efSEd Tanous if (entryID.empty()) 5255cb1dd27SAsmitha Karunanithi { 5265cb1dd27SAsmitha Karunanithi continue; 5275cb1dd27SAsmitha Karunanithi } 5285cb1dd27SAsmitha Karunanithi 529c6fecdabSClaire Weinan parseDumpEntryFromDbusObject(object, dumpStatus, size, timestampUs, 53068dd075aSAsmitha Karunanithi originatorId, originatorType, 531aefe3786SClaire Weinan asyncResp); 5325cb1dd27SAsmitha Karunanithi 5330fda0f12SGeorge Liu if (dumpStatus != 5340fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 53535440d18SAsmitha Karunanithi !dumpStatus.empty()) 53635440d18SAsmitha Karunanithi { 53735440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 53835440d18SAsmitha Karunanithi continue; 53935440d18SAsmitha Karunanithi } 54035440d18SAsmitha Karunanithi 54168dd075aSAsmitha Karunanithi thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry"; 542fdd26906SClaire Weinan thisEntry["@odata.id"] = entriesPath + entryID; 5435cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 5445cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5455cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 546bbd80db8SClaire Weinan thisEntry["Created"] = 547bbd80db8SClaire Weinan redfish::time_utils::getDateTimeUintUs(timestampUs); 5485cb1dd27SAsmitha Karunanithi 54968dd075aSAsmitha Karunanithi if (!originatorId.empty()) 55068dd075aSAsmitha Karunanithi { 55168dd075aSAsmitha Karunanithi thisEntry["Originator"] = originatorId; 55268dd075aSAsmitha Karunanithi thisEntry["OriginatorType"] = originatorType; 55368dd075aSAsmitha Karunanithi } 55468dd075aSAsmitha Karunanithi 5555cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5565cb1dd27SAsmitha Karunanithi { 557d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 55889492a15SPatrick Williams thisEntry["AdditionalDataURI"] = entriesPath + entryID + 55989492a15SPatrick Williams "/attachment"; 560fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 5615cb1dd27SAsmitha Karunanithi } 5625cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5635cb1dd27SAsmitha Karunanithi { 564d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 565d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 56689492a15SPatrick Williams thisEntry["AdditionalDataURI"] = entriesPath + entryID + 56789492a15SPatrick Williams "/attachment"; 568fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 5695cb1dd27SAsmitha Karunanithi } 570b2ba3072SPatrick Williams entriesArray.emplace_back(std::move(thisEntry)); 5715cb1dd27SAsmitha Karunanithi } 572002d39b4SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size(); 5735eb468daSGeorge Liu }); 5745cb1dd27SAsmitha Karunanithi } 5755cb1dd27SAsmitha Karunanithi 5768d1b46d7Szhanghch05 inline void 577c7a6d660SClaire Weinan getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5788d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 5795cb1dd27SAsmitha Karunanithi { 580fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 581fdd26906SClaire Weinan if (entriesPath.empty()) 5825cb1dd27SAsmitha Karunanithi { 5835cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5845cb1dd27SAsmitha Karunanithi return; 5855cb1dd27SAsmitha Karunanithi } 5865cb1dd27SAsmitha Karunanithi 5875eb468daSGeorge Liu sdbusplus::message::object_path path("/xyz/openbmc_project/dump"); 5885eb468daSGeorge Liu dbus::utility::getManagedObjects( 5895eb468daSGeorge Liu "xyz.openbmc_project.Dump.Manager", path, 590fdd26906SClaire Weinan [asyncResp, entryID, dumpType, 5915e7e2dc5SEd Tanous entriesPath](const boost::system::error_code& ec, 59202cad96eSEd Tanous const dbus::utility::ManagedObjectType& resp) { 5935cb1dd27SAsmitha Karunanithi if (ec) 5945cb1dd27SAsmitha Karunanithi { 5955cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5965cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5975cb1dd27SAsmitha Karunanithi return; 5985cb1dd27SAsmitha Karunanithi } 5995cb1dd27SAsmitha Karunanithi 600b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 601b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 602b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 603002d39b4SEd Tanous std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; 604b47452b2SAsmitha Karunanithi 6059eb808c1SEd Tanous for (const auto& objectPath : resp) 6065cb1dd27SAsmitha Karunanithi { 607b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 6085cb1dd27SAsmitha Karunanithi { 6095cb1dd27SAsmitha Karunanithi continue; 6105cb1dd27SAsmitha Karunanithi } 6115cb1dd27SAsmitha Karunanithi 6125cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 613c6fecdabSClaire Weinan uint64_t timestampUs = 0; 6145cb1dd27SAsmitha Karunanithi uint64_t size = 0; 61535440d18SAsmitha Karunanithi std::string dumpStatus; 61668dd075aSAsmitha Karunanithi std::string originatorId; 61768dd075aSAsmitha Karunanithi log_entry::OriginatorTypes originatorType = 61868dd075aSAsmitha Karunanithi log_entry::OriginatorTypes::Internal; 6195cb1dd27SAsmitha Karunanithi 620aefe3786SClaire Weinan parseDumpEntryFromDbusObject(objectPath, dumpStatus, size, 62168dd075aSAsmitha Karunanithi timestampUs, originatorId, 62268dd075aSAsmitha Karunanithi originatorType, asyncResp); 6235cb1dd27SAsmitha Karunanithi 6240fda0f12SGeorge Liu if (dumpStatus != 6250fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 62635440d18SAsmitha Karunanithi !dumpStatus.empty()) 62735440d18SAsmitha Karunanithi { 62835440d18SAsmitha Karunanithi // Dump status is not Complete 62935440d18SAsmitha Karunanithi // return not found until status is changed to Completed 630d1bde9e5SKrzysztof Grobelny messages::resourceNotFound(asyncResp->res, dumpType + " dump", 631d1bde9e5SKrzysztof Grobelny entryID); 63235440d18SAsmitha Karunanithi return; 63335440d18SAsmitha Karunanithi } 63435440d18SAsmitha Karunanithi 6355cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 63668dd075aSAsmitha Karunanithi "#LogEntry.v1_11_0.LogEntry"; 637fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID; 6385cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6395cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6405cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 641bbd80db8SClaire Weinan asyncResp->res.jsonValue["Created"] = 642bbd80db8SClaire Weinan redfish::time_utils::getDateTimeUintUs(timestampUs); 6435cb1dd27SAsmitha Karunanithi 64468dd075aSAsmitha Karunanithi if (!originatorId.empty()) 64568dd075aSAsmitha Karunanithi { 64668dd075aSAsmitha Karunanithi asyncResp->res.jsonValue["Originator"] = originatorId; 64768dd075aSAsmitha Karunanithi asyncResp->res.jsonValue["OriginatorType"] = originatorType; 64868dd075aSAsmitha Karunanithi } 64968dd075aSAsmitha Karunanithi 6505cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6515cb1dd27SAsmitha Karunanithi { 652d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 653d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 654fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 655fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6565cb1dd27SAsmitha Karunanithi } 6575cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6585cb1dd27SAsmitha Karunanithi { 659d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 660002d39b4SEd Tanous asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System"; 661d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 662fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 663fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6645cb1dd27SAsmitha Karunanithi } 6655cb1dd27SAsmitha Karunanithi } 666e05aec50SEd Tanous if (!foundDumpEntry) 667b47452b2SAsmitha Karunanithi { 668b90d14f2SMyung Bae BMCWEB_LOG_WARNING << "Can't find Dump Entry " << entryID; 669b90d14f2SMyung Bae messages::resourceNotFound(asyncResp->res, dumpType + " dump", 670b90d14f2SMyung Bae entryID); 671b47452b2SAsmitha Karunanithi return; 672b47452b2SAsmitha Karunanithi } 6735eb468daSGeorge Liu }); 6745cb1dd27SAsmitha Karunanithi } 6755cb1dd27SAsmitha Karunanithi 6768d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6779878256fSStanley Chu const std::string& entryID, 678b47452b2SAsmitha Karunanithi const std::string& dumpType) 6795cb1dd27SAsmitha Karunanithi { 680002d39b4SEd Tanous auto respHandler = 6815e7e2dc5SEd Tanous [asyncResp, entryID](const boost::system::error_code& ec) { 6825cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6835cb1dd27SAsmitha Karunanithi if (ec) 6845cb1dd27SAsmitha Karunanithi { 6853de8d8baSGeorge Liu if (ec.value() == EBADR) 6863de8d8baSGeorge Liu { 6873de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 6883de8d8baSGeorge Liu return; 6893de8d8baSGeorge Liu } 6905cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 691fdd26906SClaire Weinan << ec << " entryID=" << entryID; 6925cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6935cb1dd27SAsmitha Karunanithi return; 6945cb1dd27SAsmitha Karunanithi } 6955cb1dd27SAsmitha Karunanithi }; 6965cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 6975cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 698b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 699b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 700b47452b2SAsmitha Karunanithi entryID, 7015cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 7025cb1dd27SAsmitha Karunanithi } 7035cb1dd27SAsmitha Karunanithi 7048e31778eSAsmitha Karunanithi inline DumpCreationProgress 7058e31778eSAsmitha Karunanithi mapDbusStatusToDumpProgress(const std::string& status) 706a43be80fSAsmitha Karunanithi { 7078e31778eSAsmitha Karunanithi if (status == 7088e31778eSAsmitha Karunanithi "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" || 7098e31778eSAsmitha Karunanithi status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted") 7108e31778eSAsmitha Karunanithi { 7118e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_FAILED; 7128e31778eSAsmitha Karunanithi } 7138e31778eSAsmitha Karunanithi if (status == 7148e31778eSAsmitha Karunanithi "xyz.openbmc_project.Common.Progress.OperationStatus.Completed") 7158e31778eSAsmitha Karunanithi { 7168e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_SUCCESS; 7178e31778eSAsmitha Karunanithi } 7188e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_INPROGRESS; 7198e31778eSAsmitha Karunanithi } 7208e31778eSAsmitha Karunanithi 7218e31778eSAsmitha Karunanithi inline DumpCreationProgress 7228e31778eSAsmitha Karunanithi getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values) 7238e31778eSAsmitha Karunanithi { 7248e31778eSAsmitha Karunanithi for (const auto& [key, val] : values) 7258e31778eSAsmitha Karunanithi { 7268e31778eSAsmitha Karunanithi if (key == "Status") 7278e31778eSAsmitha Karunanithi { 7288e31778eSAsmitha Karunanithi const std::string* value = std::get_if<std::string>(&val); 7298e31778eSAsmitha Karunanithi if (value == nullptr) 7308e31778eSAsmitha Karunanithi { 7318e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Status property value is null"; 7328e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_FAILED; 7338e31778eSAsmitha Karunanithi } 7348e31778eSAsmitha Karunanithi return mapDbusStatusToDumpProgress(*value); 7358e31778eSAsmitha Karunanithi } 7368e31778eSAsmitha Karunanithi } 7378e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_INPROGRESS; 7388e31778eSAsmitha Karunanithi } 7398e31778eSAsmitha Karunanithi 7408e31778eSAsmitha Karunanithi inline std::string getDumpEntryPath(const std::string& dumpPath) 7418e31778eSAsmitha Karunanithi { 7428e31778eSAsmitha Karunanithi if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry") 7438e31778eSAsmitha Karunanithi { 7448e31778eSAsmitha Karunanithi return "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 7458e31778eSAsmitha Karunanithi } 7468e31778eSAsmitha Karunanithi if (dumpPath == "/xyz/openbmc_project/dump/system/entry") 7478e31778eSAsmitha Karunanithi { 7488e31778eSAsmitha Karunanithi return "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 7498e31778eSAsmitha Karunanithi } 7508e31778eSAsmitha Karunanithi return ""; 7518e31778eSAsmitha Karunanithi } 7528e31778eSAsmitha Karunanithi 7538e31778eSAsmitha Karunanithi inline void createDumpTaskCallback( 7548e31778eSAsmitha Karunanithi task::Payload&& payload, 7558e31778eSAsmitha Karunanithi const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7568e31778eSAsmitha Karunanithi const sdbusplus::message::object_path& createdObjPath) 7578e31778eSAsmitha Karunanithi { 7588e31778eSAsmitha Karunanithi const std::string dumpPath = createdObjPath.parent_path().str; 7598e31778eSAsmitha Karunanithi const std::string dumpId = createdObjPath.filename(); 7608e31778eSAsmitha Karunanithi 7618e31778eSAsmitha Karunanithi std::string dumpEntryPath = getDumpEntryPath(dumpPath); 7628e31778eSAsmitha Karunanithi 7638e31778eSAsmitha Karunanithi if (dumpEntryPath.empty()) 7648e31778eSAsmitha Karunanithi { 7658e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type received"; 7668e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 7678e31778eSAsmitha Karunanithi return; 7688e31778eSAsmitha Karunanithi } 7698e31778eSAsmitha Karunanithi 7708e31778eSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 7718e31778eSAsmitha Karunanithi [asyncResp, payload, createdObjPath, 7728e31778eSAsmitha Karunanithi dumpEntryPath{std::move(dumpEntryPath)}, 7735e7e2dc5SEd Tanous dumpId](const boost::system::error_code& ec, 7748e31778eSAsmitha Karunanithi const std::string& introspectXml) { 7758e31778eSAsmitha Karunanithi if (ec) 7768e31778eSAsmitha Karunanithi { 7778e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Introspect call failed with error: " 7788e31778eSAsmitha Karunanithi << ec.message(); 7798e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 7808e31778eSAsmitha Karunanithi return; 7818e31778eSAsmitha Karunanithi } 7828e31778eSAsmitha Karunanithi 7838e31778eSAsmitha Karunanithi // Check if the created dump object has implemented Progress 7848e31778eSAsmitha Karunanithi // interface to track dump completion. If yes, fetch the "Status" 7858e31778eSAsmitha Karunanithi // property of the interface, modify the task state accordingly. 7868e31778eSAsmitha Karunanithi // Else, return task completed. 7878e31778eSAsmitha Karunanithi tinyxml2::XMLDocument doc; 7888e31778eSAsmitha Karunanithi 7898e31778eSAsmitha Karunanithi doc.Parse(introspectXml.data(), introspectXml.size()); 7908e31778eSAsmitha Karunanithi tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node"); 7918e31778eSAsmitha Karunanithi if (pRoot == nullptr) 7928e31778eSAsmitha Karunanithi { 7938e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << "XML document failed to parse"; 7948e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 7958e31778eSAsmitha Karunanithi return; 7968e31778eSAsmitha Karunanithi } 7978e31778eSAsmitha Karunanithi tinyxml2::XMLElement* interfaceNode = 7988e31778eSAsmitha Karunanithi pRoot->FirstChildElement("interface"); 7998e31778eSAsmitha Karunanithi 8008e31778eSAsmitha Karunanithi bool isProgressIntfPresent = false; 8018e31778eSAsmitha Karunanithi while (interfaceNode != nullptr) 8028e31778eSAsmitha Karunanithi { 8038e31778eSAsmitha Karunanithi const char* thisInterfaceName = interfaceNode->Attribute("name"); 8048e31778eSAsmitha Karunanithi if (thisInterfaceName != nullptr) 8058e31778eSAsmitha Karunanithi { 8068e31778eSAsmitha Karunanithi if (thisInterfaceName == 8078e31778eSAsmitha Karunanithi std::string_view("xyz.openbmc_project.Common.Progress")) 8088e31778eSAsmitha Karunanithi { 8098e31778eSAsmitha Karunanithi interfaceNode = 8108e31778eSAsmitha Karunanithi interfaceNode->NextSiblingElement("interface"); 8118e31778eSAsmitha Karunanithi continue; 8128e31778eSAsmitha Karunanithi } 8138e31778eSAsmitha Karunanithi isProgressIntfPresent = true; 8148e31778eSAsmitha Karunanithi break; 8158e31778eSAsmitha Karunanithi } 8168e31778eSAsmitha Karunanithi interfaceNode = interfaceNode->NextSiblingElement("interface"); 8178e31778eSAsmitha Karunanithi } 8188e31778eSAsmitha Karunanithi 819a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 8208e31778eSAsmitha Karunanithi [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent]( 8218b24275dSEd Tanous const boost::system::error_code& ec2, sdbusplus::message_t& msg, 822a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 8238b24275dSEd Tanous if (ec2) 824cb13a392SEd Tanous { 8258e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << createdObjPath.str 8268e31778eSAsmitha Karunanithi << ": Error in creating dump"; 8278e31778eSAsmitha Karunanithi taskData->messages.emplace_back(messages::internalError()); 8286145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 8296145ed6fSAsmitha Karunanithi return task::completed; 830cb13a392SEd Tanous } 831b9d36b47SEd Tanous 8328e31778eSAsmitha Karunanithi if (isProgressIntfPresent) 833a43be80fSAsmitha Karunanithi { 8348e31778eSAsmitha Karunanithi dbus::utility::DBusPropertiesMap values; 8358e31778eSAsmitha Karunanithi std::string prop; 8368e31778eSAsmitha Karunanithi msg.read(prop, values); 8378e31778eSAsmitha Karunanithi 8388e31778eSAsmitha Karunanithi DumpCreationProgress dumpStatus = 8398e31778eSAsmitha Karunanithi getDumpCompletionStatus(values); 8408e31778eSAsmitha Karunanithi if (dumpStatus == DumpCreationProgress::DUMP_CREATE_FAILED) 8418e31778eSAsmitha Karunanithi { 8428e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << createdObjPath.str 8438e31778eSAsmitha Karunanithi << ": Error in creating dump"; 8448e31778eSAsmitha Karunanithi taskData->state = "Cancelled"; 8458e31778eSAsmitha Karunanithi return task::completed; 8468e31778eSAsmitha Karunanithi } 8478e31778eSAsmitha Karunanithi 8488e31778eSAsmitha Karunanithi if (dumpStatus == DumpCreationProgress::DUMP_CREATE_INPROGRESS) 8498e31778eSAsmitha Karunanithi { 8508e31778eSAsmitha Karunanithi BMCWEB_LOG_DEBUG << createdObjPath.str 8518e31778eSAsmitha Karunanithi << ": Dump creation task is in progress"; 8528e31778eSAsmitha Karunanithi return !task::completed; 8538e31778eSAsmitha Karunanithi } 8548e31778eSAsmitha Karunanithi } 8558e31778eSAsmitha Karunanithi 856a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 857a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 858a43be80fSAsmitha Karunanithi 859c51a58eeSEd Tanous boost::urls::url url = boost::urls::format( 860c51a58eeSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/{}", dumpId); 861c51a58eeSEd Tanous 862c51a58eeSEd Tanous std::string headerLoc = "Location: "; 863c51a58eeSEd Tanous headerLoc += url.buffer(); 864c51a58eeSEd Tanous 865002d39b4SEd Tanous taskData->payload->httpHeaders.emplace_back(std::move(headerLoc)); 866a43be80fSAsmitha Karunanithi 8678e31778eSAsmitha Karunanithi BMCWEB_LOG_DEBUG << createdObjPath.str 8688e31778eSAsmitha Karunanithi << ": Dump creation task completed"; 869a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 870b47452b2SAsmitha Karunanithi return task::completed; 871a43be80fSAsmitha Karunanithi }, 8728e31778eSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus.Properties'," 8738e31778eSAsmitha Karunanithi "member='PropertiesChanged',path='" + 8748e31778eSAsmitha Karunanithi createdObjPath.str + "'"); 875a43be80fSAsmitha Karunanithi 8768e31778eSAsmitha Karunanithi // The task timer is set to max time limit within which the 8778e31778eSAsmitha Karunanithi // requested dump will be collected. 8788e31778eSAsmitha Karunanithi task->startTimer(std::chrono::minutes(6)); 879a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 8808e31778eSAsmitha Karunanithi task->payload.emplace(payload); 8818e31778eSAsmitha Karunanithi }, 8828e31778eSAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", createdObjPath, 8838e31778eSAsmitha Karunanithi "org.freedesktop.DBus.Introspectable", "Introspect"); 884a43be80fSAsmitha Karunanithi } 885a43be80fSAsmitha Karunanithi 8868d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8878d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 888a43be80fSAsmitha Karunanithi { 889fdd26906SClaire Weinan std::string dumpPath = getDumpEntriesPath(dumpType); 890fdd26906SClaire Weinan if (dumpPath.empty()) 891a43be80fSAsmitha Karunanithi { 892a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 893a43be80fSAsmitha Karunanithi return; 894a43be80fSAsmitha Karunanithi } 895a43be80fSAsmitha Karunanithi 896a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 897a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 898a43be80fSAsmitha Karunanithi 89915ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 900a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 901a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 902a43be80fSAsmitha Karunanithi { 903a43be80fSAsmitha Karunanithi return; 904a43be80fSAsmitha Karunanithi } 905a43be80fSAsmitha Karunanithi 906a43be80fSAsmitha Karunanithi if (dumpType == "System") 907a43be80fSAsmitha Karunanithi { 908a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 909a43be80fSAsmitha Karunanithi { 9104978b63fSJason M. Bills BMCWEB_LOG_ERROR 9114978b63fSJason M. Bills << "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"; 912a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 913a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 914a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 915a43be80fSAsmitha Karunanithi return; 916a43be80fSAsmitha Karunanithi } 9173174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 918a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 919a43be80fSAsmitha Karunanithi { 920a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 921ace85d60SEd Tanous messages::internalError(asyncResp->res); 922a43be80fSAsmitha Karunanithi return; 923a43be80fSAsmitha Karunanithi } 9245907571dSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/"; 925a43be80fSAsmitha Karunanithi } 926a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 927a43be80fSAsmitha Karunanithi { 928a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 929a43be80fSAsmitha Karunanithi { 9300fda0f12SGeorge Liu BMCWEB_LOG_ERROR 9310fda0f12SGeorge Liu << "CreateDump action parameter 'DiagnosticDataType' not found!"; 932a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 933a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 934a43be80fSAsmitha Karunanithi return; 935a43be80fSAsmitha Karunanithi } 9363174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 937a43be80fSAsmitha Karunanithi { 938a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 939a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 940ace85d60SEd Tanous messages::internalError(asyncResp->res); 941a43be80fSAsmitha Karunanithi return; 942a43be80fSAsmitha Karunanithi } 9435907571dSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/"; 9445907571dSAsmitha Karunanithi } 9455907571dSAsmitha Karunanithi else 9465907571dSAsmitha Karunanithi { 9475907571dSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump failed. Unknown dump type"; 9485907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 9495907571dSAsmitha Karunanithi return; 950a43be80fSAsmitha Karunanithi } 951a43be80fSAsmitha Karunanithi 9528e31778eSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>> 9538e31778eSAsmitha Karunanithi createDumpParamVec; 9548e31778eSAsmitha Karunanithi 955f574a8e1SCarson Labrado if (req.session != nullptr) 956f574a8e1SCarson Labrado { 95768dd075aSAsmitha Karunanithi createDumpParamVec.emplace_back( 95868dd075aSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId", 95968dd075aSAsmitha Karunanithi req.session->clientIp); 96068dd075aSAsmitha Karunanithi createDumpParamVec.emplace_back( 96168dd075aSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType", 96268dd075aSAsmitha Karunanithi "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client"); 963f574a8e1SCarson Labrado } 96468dd075aSAsmitha Karunanithi 965a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 9665e7e2dc5SEd Tanous [asyncResp, payload(task::Payload(req)), 9675e7e2dc5SEd Tanous dumpPath](const boost::system::error_code& ec, 9685e7e2dc5SEd Tanous const sdbusplus::message_t& msg, 9698e31778eSAsmitha Karunanithi const sdbusplus::message::object_path& objPath) mutable { 970a43be80fSAsmitha Karunanithi if (ec) 971a43be80fSAsmitha Karunanithi { 972a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 9735907571dSAsmitha Karunanithi const sd_bus_error* dbusError = msg.get_error(); 9745907571dSAsmitha Karunanithi if (dbusError == nullptr) 9755907571dSAsmitha Karunanithi { 9765907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 9775907571dSAsmitha Karunanithi return; 9785907571dSAsmitha Karunanithi } 9795907571dSAsmitha Karunanithi 9805907571dSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump DBus error: " << dbusError->name 9815907571dSAsmitha Karunanithi << " and error msg: " << dbusError->message; 9825907571dSAsmitha Karunanithi if (std::string_view( 9835907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.NotAllowed") == 9845907571dSAsmitha Karunanithi dbusError->name) 9855907571dSAsmitha Karunanithi { 9865907571dSAsmitha Karunanithi messages::resourceInStandby(asyncResp->res); 9875907571dSAsmitha Karunanithi return; 9885907571dSAsmitha Karunanithi } 9895907571dSAsmitha Karunanithi if (std::string_view( 9905907571dSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.Error.Disabled") == 9915907571dSAsmitha Karunanithi dbusError->name) 9925907571dSAsmitha Karunanithi { 9935907571dSAsmitha Karunanithi messages::serviceDisabled(asyncResp->res, dumpPath); 9945907571dSAsmitha Karunanithi return; 9955907571dSAsmitha Karunanithi } 9965907571dSAsmitha Karunanithi if (std::string_view( 9975907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.Unavailable") == 9985907571dSAsmitha Karunanithi dbusError->name) 9995907571dSAsmitha Karunanithi { 10005907571dSAsmitha Karunanithi messages::resourceInUse(asyncResp->res); 10015907571dSAsmitha Karunanithi return; 10025907571dSAsmitha Karunanithi } 10035907571dSAsmitha Karunanithi // Other Dbus errors such as: 10045907571dSAsmitha Karunanithi // xyz.openbmc_project.Common.Error.InvalidArgument & 10055907571dSAsmitha Karunanithi // org.freedesktop.DBus.Error.InvalidArgs are all related to 10065907571dSAsmitha Karunanithi // the dbus call that is made here in the bmcweb 10075907571dSAsmitha Karunanithi // implementation and has nothing to do with the client's 10085907571dSAsmitha Karunanithi // input in the request. Hence, returning internal error 10095907571dSAsmitha Karunanithi // back to the client. 1010a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 1011a43be80fSAsmitha Karunanithi return; 1012a43be80fSAsmitha Karunanithi } 10138e31778eSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Path: " << objPath.str; 10148e31778eSAsmitha Karunanithi createDumpTaskCallback(std::move(payload), asyncResp, objPath); 1015a43be80fSAsmitha Karunanithi }, 1016b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 1017b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 1018b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 10198e31778eSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec); 1020a43be80fSAsmitha Karunanithi } 1021a43be80fSAsmitha Karunanithi 10228d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 10238d1b46d7Szhanghch05 const std::string& dumpType) 102480319af1SAsmitha Karunanithi { 1025b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 1026b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 10278d1b46d7Szhanghch05 10280d946211SClaire Weinan crow::connections::systemBus->async_method_call( 10290d946211SClaire Weinan [asyncResp](const boost::system::error_code& ec) { 103080319af1SAsmitha Karunanithi if (ec) 103180319af1SAsmitha Karunanithi { 10320d946211SClaire Weinan BMCWEB_LOG_ERROR << "clearDump resp_handler got error " << ec; 103380319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 103480319af1SAsmitha Karunanithi return; 103580319af1SAsmitha Karunanithi } 10360d946211SClaire Weinan }, 10370d946211SClaire Weinan "xyz.openbmc_project.Dump.Manager", 10380d946211SClaire Weinan "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 10390d946211SClaire Weinan "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 104080319af1SAsmitha Karunanithi } 104180319af1SAsmitha Karunanithi 1042b9d36b47SEd Tanous inline static void 1043b9d36b47SEd Tanous parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params, 1044b9d36b47SEd Tanous std::string& filename, std::string& timestamp, 1045b9d36b47SEd Tanous std::string& logfile) 1046043a0536SJohnathan Mantey { 1047d1bde9e5SKrzysztof Grobelny const std::string* filenamePtr = nullptr; 1048d1bde9e5SKrzysztof Grobelny const std::string* timestampPtr = nullptr; 1049d1bde9e5SKrzysztof Grobelny const std::string* logfilePtr = nullptr; 1050d1bde9e5SKrzysztof Grobelny 1051d1bde9e5SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1052d1bde9e5SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr, 1053d1bde9e5SKrzysztof Grobelny "Filename", filenamePtr, "Log", logfilePtr); 1054d1bde9e5SKrzysztof Grobelny 1055d1bde9e5SKrzysztof Grobelny if (!success) 1056043a0536SJohnathan Mantey { 1057d1bde9e5SKrzysztof Grobelny return; 1058043a0536SJohnathan Mantey } 1059d1bde9e5SKrzysztof Grobelny 1060d1bde9e5SKrzysztof Grobelny if (filenamePtr != nullptr) 1061043a0536SJohnathan Mantey { 1062d1bde9e5SKrzysztof Grobelny filename = *filenamePtr; 1063d1bde9e5SKrzysztof Grobelny } 1064d1bde9e5SKrzysztof Grobelny 1065d1bde9e5SKrzysztof Grobelny if (timestampPtr != nullptr) 1066043a0536SJohnathan Mantey { 1067d1bde9e5SKrzysztof Grobelny timestamp = *timestampPtr; 1068043a0536SJohnathan Mantey } 1069d1bde9e5SKrzysztof Grobelny 1070d1bde9e5SKrzysztof Grobelny if (logfilePtr != nullptr) 1071043a0536SJohnathan Mantey { 1072d1bde9e5SKrzysztof Grobelny logfile = *logfilePtr; 1073043a0536SJohnathan Mantey } 1074043a0536SJohnathan Mantey } 1075043a0536SJohnathan Mantey 10767e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 10771da66f75SEd Tanous { 1078c4bf6374SJason M. Bills /** 1079c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 1080c4bf6374SJason M. Bills */ 108122d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/") 1082ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 1083002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1084002d39b4SEd Tanous [&app](const crow::Request& req, 108522d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 108622d268cbSEd Tanous const std::string& systemName) { 10873ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1088c4bf6374SJason M. Bills { 108945ca1b86SEd Tanous return; 109045ca1b86SEd Tanous } 10917f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 10927f3e84a1SEd Tanous { 10937f3e84a1SEd Tanous // Option currently returns no systems. TBD 10947f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 10957f3e84a1SEd Tanous systemName); 10967f3e84a1SEd Tanous return; 10977f3e84a1SEd Tanous } 109822d268cbSEd Tanous if (systemName != "system") 109922d268cbSEd Tanous { 110022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 110122d268cbSEd Tanous systemName); 110222d268cbSEd Tanous return; 110322d268cbSEd Tanous } 110422d268cbSEd Tanous 11057e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 11067e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1107c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1108c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 1109c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1110029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 111145ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 1112c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1113c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 1114002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 1115c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 11161476687dSEd Tanous nlohmann::json::object_t eventLog; 11171476687dSEd Tanous eventLog["@odata.id"] = 11181476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1119b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(eventLog)); 11205cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 11211476687dSEd Tanous nlohmann::json::object_t dumpLog; 1122002d39b4SEd Tanous dumpLog["@odata.id"] = "/redfish/v1/Systems/system/LogServices/Dump"; 1123b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(dumpLog)); 1124c9bb6861Sraviteja-b #endif 1125c9bb6861Sraviteja-b 1126d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 11271476687dSEd Tanous nlohmann::json::object_t crashdump; 11281476687dSEd Tanous crashdump["@odata.id"] = 11291476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump"; 1130b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(crashdump)); 1131d53dd41fSJason M. Bills #endif 1132b7028ebfSSpencer Ku 1133b7028ebfSSpencer Ku #ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER 11341476687dSEd Tanous nlohmann::json::object_t hostlogger; 11351476687dSEd Tanous hostlogger["@odata.id"] = 11361476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger"; 1137b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(hostlogger)); 1138b7028ebfSSpencer Ku #endif 1139c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1140c4bf6374SJason M. Bills logServiceArray.size(); 1141a3316fc6SZhikuiRen 11427a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 11437a1dbc48SGeorge Liu "xyz.openbmc_project.State.Boot.PostCode"}; 11447a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 11457a1dbc48SGeorge Liu "/", 0, interfaces, 11467a1dbc48SGeorge Liu [asyncResp](const boost::system::error_code& ec, 1147b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& 1148b9d36b47SEd Tanous subtreePath) { 1149a3316fc6SZhikuiRen if (ec) 1150a3316fc6SZhikuiRen { 1151a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 1152a3316fc6SZhikuiRen return; 1153a3316fc6SZhikuiRen } 1154a3316fc6SZhikuiRen 115555f79e6fSEd Tanous for (const auto& pathStr : subtreePath) 1156a3316fc6SZhikuiRen { 1157a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 1158a3316fc6SZhikuiRen { 115923a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 1160a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 1161613dabeaSEd Tanous nlohmann::json::object_t member; 1162613dabeaSEd Tanous member["@odata.id"] = 1163613dabeaSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes"; 1164613dabeaSEd Tanous 1165b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 1166613dabeaSEd Tanous 116745ca1b86SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 116823a21a1cSEd Tanous logServiceArrayLocal.size(); 1169a3316fc6SZhikuiRen return; 1170a3316fc6SZhikuiRen } 1171a3316fc6SZhikuiRen } 11727a1dbc48SGeorge Liu }); 11737e860f15SJohn Edward Broadbent }); 1174c4bf6374SJason M. Bills } 1175c4bf6374SJason M. Bills 11767e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 1177c4bf6374SJason M. Bills { 117822d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/") 1179ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 1180002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1181002d39b4SEd Tanous [&app](const crow::Request& req, 118222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 118322d268cbSEd Tanous const std::string& systemName) { 11843ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 118545ca1b86SEd Tanous { 118645ca1b86SEd Tanous return; 118745ca1b86SEd Tanous } 118822d268cbSEd Tanous if (systemName != "system") 118922d268cbSEd Tanous { 119022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 119122d268cbSEd Tanous systemName); 119222d268cbSEd Tanous return; 119322d268cbSEd Tanous } 1194c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1195029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1196c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1197c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 1198c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 1199002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 1200c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1201c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 12027c8c4058STejas Patil 12037c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 12042b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 12057c8c4058STejas Patil 12067c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 12077c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 12087c8c4058STejas Patil redfishDateTimeOffset.second; 12097c8c4058STejas Patil 12101476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 12111476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1212e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1213e7d6c8b2SGunnar Mills 12140fda0f12SGeorge Liu {"target", 12150fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog"}}; 12167e860f15SJohn Edward Broadbent }); 1217489640c6SJason M. Bills } 1218489640c6SJason M. Bills 12197e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1220489640c6SJason M. Bills { 12214978b63fSJason M. Bills BMCWEB_ROUTE( 12224978b63fSJason M. Bills app, 122322d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 1224432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 12257e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 122645ca1b86SEd Tanous [&app](const crow::Request& req, 122722d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 122822d268cbSEd Tanous const std::string& systemName) { 12293ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 123045ca1b86SEd Tanous { 123145ca1b86SEd Tanous return; 123245ca1b86SEd Tanous } 123322d268cbSEd Tanous if (systemName != "system") 123422d268cbSEd Tanous { 123522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 123622d268cbSEd Tanous systemName); 123722d268cbSEd Tanous return; 123822d268cbSEd Tanous } 1239489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1240489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1241489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1242489640c6SJason M. Bills { 1243489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1244489640c6SJason M. Bills { 1245489640c6SJason M. Bills std::error_code ec; 1246489640c6SJason M. Bills std::filesystem::remove(file, ec); 1247489640c6SJason M. Bills } 1248489640c6SJason M. Bills } 1249489640c6SJason M. Bills 1250489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1251489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 12525e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 1253489640c6SJason M. Bills if (ec) 1254489640c6SJason M. Bills { 1255002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 1256489640c6SJason M. Bills messages::internalError(asyncResp->res); 1257489640c6SJason M. Bills return; 1258489640c6SJason M. Bills } 1259489640c6SJason M. Bills 1260489640c6SJason M. Bills messages::success(asyncResp->res); 1261489640c6SJason M. Bills }, 1262489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1263002d39b4SEd Tanous "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1264002d39b4SEd Tanous "replace"); 12657e860f15SJohn Edward Broadbent }); 1266c4bf6374SJason M. Bills } 1267c4bf6374SJason M. Bills 1268ac992cdeSJason M. Bills enum class LogParseError 1269ac992cdeSJason M. Bills { 1270ac992cdeSJason M. Bills success, 1271ac992cdeSJason M. Bills parseFailed, 1272ac992cdeSJason M. Bills messageIdNotInRegistry, 1273ac992cdeSJason M. Bills }; 1274ac992cdeSJason M. Bills 1275ac992cdeSJason M. Bills static LogParseError 1276ac992cdeSJason M. Bills fillEventLogEntryJson(const std::string& logEntryID, 1277b5a76932SEd Tanous const std::string& logEntry, 1278de703c5dSJason M. Bills nlohmann::json::object_t& logEntryJson) 1279c4bf6374SJason M. Bills { 128095820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1281cd225da8SJason M. Bills // First get the Timestamp 1282f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1283cd225da8SJason M. Bills if (space == std::string::npos) 128495820184SJason M. Bills { 1285ac992cdeSJason M. Bills return LogParseError::parseFailed; 128695820184SJason M. Bills } 1287cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1288cd225da8SJason M. Bills // Then get the log contents 1289f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1290cd225da8SJason M. Bills if (entryStart == std::string::npos) 1291cd225da8SJason M. Bills { 1292ac992cdeSJason M. Bills return LogParseError::parseFailed; 1293cd225da8SJason M. Bills } 1294cd225da8SJason M. Bills std::string_view entry(logEntry); 1295cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1296cd225da8SJason M. Bills // Use split to separate the entry into its fields 1297cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 129850ebd4afSEd Tanous bmcweb::split(logEntryFields, entry, ','); 1299cd225da8SJason M. Bills // We need at least a MessageId to be valid 13001e6deaf6SEd Tanous auto logEntryIter = logEntryFields.begin(); 13011e6deaf6SEd Tanous if (logEntryIter == logEntryFields.end()) 1302cd225da8SJason M. Bills { 1303ac992cdeSJason M. Bills return LogParseError::parseFailed; 1304cd225da8SJason M. Bills } 13051e6deaf6SEd Tanous std::string& messageID = *logEntryIter; 13064851d45dSJason M. Bills // Get the Message from the MessageRegistry 1307fffb8c1fSEd Tanous const registries::Message* message = registries::getMessage(messageID); 1308c4bf6374SJason M. Bills 13091e6deaf6SEd Tanous logEntryIter++; 131054417b02SSui Chen if (message == nullptr) 1311c4bf6374SJason M. Bills { 131254417b02SSui Chen BMCWEB_LOG_WARNING << "Log entry not found in registry: " << logEntry; 1313ac992cdeSJason M. Bills return LogParseError::messageIdNotInRegistry; 1314c4bf6374SJason M. Bills } 1315c4bf6374SJason M. Bills 13161e6deaf6SEd Tanous std::vector<std::string_view> messageArgs(logEntryIter, 13171e6deaf6SEd Tanous logEntryFields.end()); 1318*c05bba45SEd Tanous messageArgs.resize(message->numberOfArgs); 1319*c05bba45SEd Tanous 13201e6deaf6SEd Tanous std::string msg = redfish::registries::fillMessageArgs(messageArgs, 13211e6deaf6SEd Tanous message->message); 13221e6deaf6SEd Tanous if (msg.empty()) 132315a86ff6SJason M. Bills { 13241e6deaf6SEd Tanous return LogParseError::parseFailed; 132515a86ff6SJason M. Bills } 13264851d45dSJason M. Bills 132795820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 132895820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 132995820184SJason M. Bills // between the '.' and the '+', so just remove them. 1330f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1331f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 133295820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1333c4bf6374SJason M. Bills { 133495820184SJason M. Bills timestamp.erase(dot, plus - dot); 1335c4bf6374SJason M. Bills } 1336c4bf6374SJason M. Bills 1337c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 13389c11a172SVijay Lobo logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 1339ef4c65b7SEd Tanous logEntryJson["@odata.id"] = boost::urls::format( 1340ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/{}", 1341ef4c65b7SEd Tanous logEntryID); 134284afc48bSJason M. Bills logEntryJson["Name"] = "System Event Log Entry"; 134384afc48bSJason M. Bills logEntryJson["Id"] = logEntryID; 134484afc48bSJason M. Bills logEntryJson["Message"] = std::move(msg); 134584afc48bSJason M. Bills logEntryJson["MessageId"] = std::move(messageID); 134684afc48bSJason M. Bills logEntryJson["MessageArgs"] = messageArgs; 134784afc48bSJason M. Bills logEntryJson["EntryType"] = "Event"; 134884afc48bSJason M. Bills logEntryJson["Severity"] = message->messageSeverity; 134984afc48bSJason M. Bills logEntryJson["Created"] = std::move(timestamp); 1350ac992cdeSJason M. Bills return LogParseError::success; 1351c4bf6374SJason M. Bills } 1352c4bf6374SJason M. Bills 13537e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1354c4bf6374SJason M. Bills { 135522d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") 13568b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 1357002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1358002d39b4SEd Tanous [&app](const crow::Request& req, 135922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 136022d268cbSEd Tanous const std::string& systemName) { 1361c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1362c937d2bfSEd Tanous .canDelegateTop = true, 1363c937d2bfSEd Tanous .canDelegateSkip = true, 1364c937d2bfSEd Tanous }; 1365c937d2bfSEd Tanous query_param::Query delegatedQuery; 1366c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 13673ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 1368c4bf6374SJason M. Bills { 1369c4bf6374SJason M. Bills return; 1370c4bf6374SJason M. Bills } 13717f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 13727f3e84a1SEd Tanous { 13737f3e84a1SEd Tanous // Option currently returns no systems. TBD 13747f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 13757f3e84a1SEd Tanous systemName); 13767f3e84a1SEd Tanous return; 13777f3e84a1SEd Tanous } 137822d268cbSEd Tanous if (systemName != "system") 137922d268cbSEd Tanous { 138022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 138122d268cbSEd Tanous systemName); 138222d268cbSEd Tanous return; 138322d268cbSEd Tanous } 138422d268cbSEd Tanous 13855143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 13863648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 13873648c8beSEd Tanous 13887e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 13897e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1390c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1391c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1392c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1393029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1394c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1395c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1396c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1397cb92c03bSAndrew Geissler 13984978b63fSJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1399c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 14007e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 14017e860f15SJohn Edward Broadbent // entry 140295820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 140395820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1404b01bf299SEd Tanous uint64_t entryCount = 0; 1405cd225da8SJason M. Bills std::string logEntry; 140695820184SJason M. Bills 14077e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 14087e860f15SJohn Edward Broadbent // backwards 1409002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1410002d39b4SEd Tanous it++) 1411c4bf6374SJason M. Bills { 1412cd225da8SJason M. Bills std::ifstream logStream(*it); 141395820184SJason M. Bills if (!logStream.is_open()) 1414c4bf6374SJason M. Bills { 1415c4bf6374SJason M. Bills continue; 1416c4bf6374SJason M. Bills } 1417c4bf6374SJason M. Bills 1418e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1419e85d6b16SJason M. Bills bool firstEntry = true; 142095820184SJason M. Bills while (std::getline(logStream, logEntry)) 142195820184SJason M. Bills { 1422c4bf6374SJason M. Bills std::string idStr; 1423e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1424c4bf6374SJason M. Bills { 1425c4bf6374SJason M. Bills continue; 1426c4bf6374SJason M. Bills } 1427e85d6b16SJason M. Bills firstEntry = false; 1428e85d6b16SJason M. Bills 1429de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 143089492a15SPatrick Williams LogParseError status = fillEventLogEntryJson(idStr, logEntry, 143189492a15SPatrick Williams bmcLogEntry); 1432ac992cdeSJason M. Bills if (status == LogParseError::messageIdNotInRegistry) 1433ac992cdeSJason M. Bills { 1434ac992cdeSJason M. Bills continue; 1435ac992cdeSJason M. Bills } 1436ac992cdeSJason M. Bills if (status != LogParseError::success) 1437c4bf6374SJason M. Bills { 1438c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1439c4bf6374SJason M. Bills return; 1440c4bf6374SJason M. Bills } 1441de703c5dSJason M. Bills 1442de703c5dSJason M. Bills entryCount++; 1443de703c5dSJason M. Bills // Handle paging using skip (number of entries to skip from the 1444de703c5dSJason M. Bills // start) and top (number of entries to display) 14453648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 1446de703c5dSJason M. Bills { 1447de703c5dSJason M. Bills continue; 1448de703c5dSJason M. Bills } 1449de703c5dSJason M. Bills 1450b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(bmcLogEntry)); 1451c4bf6374SJason M. Bills } 145295820184SJason M. Bills } 1453c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 14543648c8beSEd Tanous if (skip + top < entryCount) 1455c4bf6374SJason M. Bills { 1456c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 14574978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries?$skip=" + 14583648c8beSEd Tanous std::to_string(skip + top); 1459c4bf6374SJason M. Bills } 14607e860f15SJohn Edward Broadbent }); 1461897967deSJason M. Bills } 1462897967deSJason M. Bills 14637e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1464897967deSJason M. Bills { 14657e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 146622d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1467ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 14687e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 146945ca1b86SEd Tanous [&app](const crow::Request& req, 14707e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 147122d268cbSEd Tanous const std::string& systemName, const std::string& param) { 14723ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 147345ca1b86SEd Tanous { 147445ca1b86SEd Tanous return; 147545ca1b86SEd Tanous } 14767f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 14777f3e84a1SEd Tanous { 14787f3e84a1SEd Tanous // Option currently returns no systems. TBD 14797f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 14807f3e84a1SEd Tanous systemName); 14817f3e84a1SEd Tanous return; 14827f3e84a1SEd Tanous } 148322d268cbSEd Tanous 148422d268cbSEd Tanous if (systemName != "system") 148522d268cbSEd Tanous { 148622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 148722d268cbSEd Tanous systemName); 148822d268cbSEd Tanous return; 148922d268cbSEd Tanous } 149022d268cbSEd Tanous 14917e860f15SJohn Edward Broadbent const std::string& targetID = param; 14928d1b46d7Szhanghch05 14937e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 14947e860f15SJohn Edward Broadbent // entry to find the target entry 1495897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1496897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1497897967deSJason M. Bills std::string logEntry; 1498897967deSJason M. Bills 14997e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 15007e860f15SJohn Edward Broadbent // backwards 1501002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1502002d39b4SEd Tanous it++) 1503897967deSJason M. Bills { 1504897967deSJason M. Bills std::ifstream logStream(*it); 1505897967deSJason M. Bills if (!logStream.is_open()) 1506897967deSJason M. Bills { 1507897967deSJason M. Bills continue; 1508897967deSJason M. Bills } 1509897967deSJason M. Bills 1510897967deSJason M. Bills // Reset the unique ID on the first entry 1511897967deSJason M. Bills bool firstEntry = true; 1512897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1513897967deSJason M. Bills { 1514897967deSJason M. Bills std::string idStr; 1515897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1516897967deSJason M. Bills { 1517897967deSJason M. Bills continue; 1518897967deSJason M. Bills } 1519897967deSJason M. Bills firstEntry = false; 1520897967deSJason M. Bills 1521897967deSJason M. Bills if (idStr == targetID) 1522897967deSJason M. Bills { 1523de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 1524ac992cdeSJason M. Bills LogParseError status = 1525ac992cdeSJason M. Bills fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); 1526ac992cdeSJason M. Bills if (status != LogParseError::success) 1527897967deSJason M. Bills { 1528897967deSJason M. Bills messages::internalError(asyncResp->res); 1529897967deSJason M. Bills return; 1530897967deSJason M. Bills } 1531d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcLogEntry); 1532897967deSJason M. Bills return; 1533897967deSJason M. Bills } 1534897967deSJason M. Bills } 1535897967deSJason M. Bills } 1536897967deSJason M. Bills // Requested ID was not found 15379db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", targetID); 15387e860f15SJohn Edward Broadbent }); 153908a4e4b5SAnthony Wilson } 154008a4e4b5SAnthony Wilson 15417e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 154208a4e4b5SAnthony Wilson { 154322d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") 1544ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 1545002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1546002d39b4SEd Tanous [&app](const crow::Request& req, 154722d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 154822d268cbSEd Tanous const std::string& systemName) { 15493ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 155045ca1b86SEd Tanous { 155145ca1b86SEd Tanous return; 155245ca1b86SEd Tanous } 15537f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 15547f3e84a1SEd Tanous { 15557f3e84a1SEd Tanous // Option currently returns no systems. TBD 15567f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 15577f3e84a1SEd Tanous systemName); 15587f3e84a1SEd Tanous return; 15597f3e84a1SEd Tanous } 156022d268cbSEd Tanous if (systemName != "system") 156122d268cbSEd Tanous { 156222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 156322d268cbSEd Tanous systemName); 156422d268cbSEd Tanous return; 156522d268cbSEd Tanous } 156622d268cbSEd Tanous 15677e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 15687e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 156908a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 157008a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 157108a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 157208a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 157308a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 157408a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 157508a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 157608a4e4b5SAnthony Wilson 1577cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1578cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 15795eb468daSGeorge Liu sdbusplus::message::object_path path("/xyz/openbmc_project/logging"); 15805eb468daSGeorge Liu dbus::utility::getManagedObjects( 15815eb468daSGeorge Liu "xyz.openbmc_project.Logging", path, 15825e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 1583914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& resp) { 1584cb92c03bSAndrew Geissler if (ec) 1585cb92c03bSAndrew Geissler { 1586cb92c03bSAndrew Geissler // TODO Handle for specific error code 1587cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1588002d39b4SEd Tanous << "getLogEntriesIfaceData resp_handler got error " << ec; 1589cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1590cb92c03bSAndrew Geissler return; 1591cb92c03bSAndrew Geissler } 1592002d39b4SEd Tanous nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 1593cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 15949eb808c1SEd Tanous for (const auto& objectPath : resp) 1595cb92c03bSAndrew Geissler { 1596914e2d5dSEd Tanous const uint32_t* id = nullptr; 1597c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1598c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1599914e2d5dSEd Tanous const std::string* severity = nullptr; 1600914e2d5dSEd Tanous const std::string* message = nullptr; 1601914e2d5dSEd Tanous const std::string* filePath = nullptr; 16029c11a172SVijay Lobo const std::string* resolution = nullptr; 160375710de2SXiaochao Ma bool resolved = false; 16049017faf2SAbhishek Patel const std::string* notify = nullptr; 16059017faf2SAbhishek Patel 16069eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 1607f86bb901SAdriana Kobylak { 1608f86bb901SAdriana Kobylak if (interfaceMap.first == 1609f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1610f86bb901SAdriana Kobylak { 1611002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 1612cb92c03bSAndrew Geissler { 1613cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1614cb92c03bSAndrew Geissler { 1615002d39b4SEd Tanous id = std::get_if<uint32_t>(&propertyMap.second); 1616cb92c03bSAndrew Geissler } 1617cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1618cb92c03bSAndrew Geissler { 1619002d39b4SEd Tanous timestamp = 1620002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 16217e860f15SJohn Edward Broadbent } 1622002d39b4SEd Tanous else if (propertyMap.first == "UpdateTimestamp") 16237e860f15SJohn Edward Broadbent { 1624002d39b4SEd Tanous updateTimestamp = 1625002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 16267e860f15SJohn Edward Broadbent } 16277e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 16287e860f15SJohn Edward Broadbent { 16297e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 16307e860f15SJohn Edward Broadbent &propertyMap.second); 16317e860f15SJohn Edward Broadbent } 16329c11a172SVijay Lobo else if (propertyMap.first == "Resolution") 16339c11a172SVijay Lobo { 16349c11a172SVijay Lobo resolution = std::get_if<std::string>( 16359c11a172SVijay Lobo &propertyMap.second); 16369c11a172SVijay Lobo } 16377e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 16387e860f15SJohn Edward Broadbent { 16397e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 16407e860f15SJohn Edward Broadbent &propertyMap.second); 16417e860f15SJohn Edward Broadbent } 16427e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 16437e860f15SJohn Edward Broadbent { 1644914e2d5dSEd Tanous const bool* resolveptr = 1645002d39b4SEd Tanous std::get_if<bool>(&propertyMap.second); 16467e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 16477e860f15SJohn Edward Broadbent { 1648002d39b4SEd Tanous messages::internalError(asyncResp->res); 16497e860f15SJohn Edward Broadbent return; 16507e860f15SJohn Edward Broadbent } 16517e860f15SJohn Edward Broadbent resolved = *resolveptr; 16527e860f15SJohn Edward Broadbent } 16539017faf2SAbhishek Patel else if (propertyMap.first == 16549017faf2SAbhishek Patel "ServiceProviderNotify") 16559017faf2SAbhishek Patel { 16569017faf2SAbhishek Patel notify = std::get_if<std::string>( 16579017faf2SAbhishek Patel &propertyMap.second); 16589017faf2SAbhishek Patel if (notify == nullptr) 16599017faf2SAbhishek Patel { 16609017faf2SAbhishek Patel messages::internalError(asyncResp->res); 16619017faf2SAbhishek Patel return; 16629017faf2SAbhishek Patel } 16639017faf2SAbhishek Patel } 16647e860f15SJohn Edward Broadbent } 16657e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 16667e860f15SJohn Edward Broadbent severity == nullptr) 16677e860f15SJohn Edward Broadbent { 16687e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 16697e860f15SJohn Edward Broadbent return; 16707e860f15SJohn Edward Broadbent } 16717e860f15SJohn Edward Broadbent } 16727e860f15SJohn Edward Broadbent else if (interfaceMap.first == 16737e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 16747e860f15SJohn Edward Broadbent { 1675002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 16767e860f15SJohn Edward Broadbent { 16777e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 16787e860f15SJohn Edward Broadbent { 16797e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 16807e860f15SJohn Edward Broadbent &propertyMap.second); 16817e860f15SJohn Edward Broadbent } 16827e860f15SJohn Edward Broadbent } 16837e860f15SJohn Edward Broadbent } 16847e860f15SJohn Edward Broadbent } 16857e860f15SJohn Edward Broadbent // Object path without the 16867e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 16877e860f15SJohn Edward Broadbent // and continue. 16887e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 1689c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1690c419c759SEd Tanous updateTimestamp == nullptr) 16917e860f15SJohn Edward Broadbent { 16927e860f15SJohn Edward Broadbent continue; 16937e860f15SJohn Edward Broadbent } 16947e860f15SJohn Edward Broadbent entriesArray.push_back({}); 16957e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 16969c11a172SVijay Lobo thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 1697ef4c65b7SEd Tanous thisEntry["@odata.id"] = boost::urls::format( 1698ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/{}", 1699ef4c65b7SEd Tanous std::to_string(*id)); 17007e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 17017e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 17027e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 17037e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 17049c11a172SVijay Lobo if ((resolution != nullptr) && (!(*resolution).empty())) 17059c11a172SVijay Lobo { 17069c11a172SVijay Lobo thisEntry["Resolution"] = *resolution; 17079c11a172SVijay Lobo } 17089017faf2SAbhishek Patel std::optional<bool> notifyAction = 17099017faf2SAbhishek Patel getProviderNotifyAction(*notify); 17109017faf2SAbhishek Patel if (notifyAction) 17119017faf2SAbhishek Patel { 17129017faf2SAbhishek Patel thisEntry["ServiceProviderNotified"] = *notifyAction; 17139017faf2SAbhishek Patel } 17147e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 17157e860f15SJohn Edward Broadbent thisEntry["Severity"] = 17167e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 17177e860f15SJohn Edward Broadbent thisEntry["Created"] = 17182b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*timestamp); 17197e860f15SJohn Edward Broadbent thisEntry["Modified"] = 17202b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*updateTimestamp); 17217e860f15SJohn Edward Broadbent if (filePath != nullptr) 17227e860f15SJohn Edward Broadbent { 17237e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 17240fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 17257e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 17267e860f15SJohn Edward Broadbent } 17277e860f15SJohn Edward Broadbent } 1728002d39b4SEd Tanous std::sort( 1729002d39b4SEd Tanous entriesArray.begin(), entriesArray.end(), 1730002d39b4SEd Tanous [](const nlohmann::json& left, const nlohmann::json& right) { 17317e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 17327e860f15SJohn Edward Broadbent }); 17337e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 17347e860f15SJohn Edward Broadbent entriesArray.size(); 17355eb468daSGeorge Liu }); 17367e860f15SJohn Edward Broadbent }); 17377e860f15SJohn Edward Broadbent } 17387e860f15SJohn Edward Broadbent 17397e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 17407e860f15SJohn Edward Broadbent { 17417e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 174222d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1743ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 1744002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1745002d39b4SEd Tanous [&app](const crow::Request& req, 17467e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 174722d268cbSEd Tanous const std::string& systemName, const std::string& param) { 17483ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 17497e860f15SJohn Edward Broadbent { 175045ca1b86SEd Tanous return; 175145ca1b86SEd Tanous } 17527f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 17537f3e84a1SEd Tanous { 17547f3e84a1SEd Tanous // Option currently returns no systems. TBD 17557f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 17567f3e84a1SEd Tanous systemName); 17577f3e84a1SEd Tanous return; 17587f3e84a1SEd Tanous } 175922d268cbSEd Tanous if (systemName != "system") 176022d268cbSEd Tanous { 176122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 176222d268cbSEd Tanous systemName); 176322d268cbSEd Tanous return; 176422d268cbSEd Tanous } 176522d268cbSEd Tanous 17667e860f15SJohn Edward Broadbent std::string entryID = param; 17677e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 17687e860f15SJohn Edward Broadbent 17697e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 17707e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 1771d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1772d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, "xyz.openbmc_project.Logging", 1773d1bde9e5SKrzysztof Grobelny "/xyz/openbmc_project/logging/entry/" + entryID, "", 17745e7e2dc5SEd Tanous [asyncResp, entryID](const boost::system::error_code& ec, 1775b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 17767e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 17777e860f15SJohn Edward Broadbent { 1778d1bde9e5SKrzysztof Grobelny messages::resourceNotFound(asyncResp->res, "EventLogEntry", 1779d1bde9e5SKrzysztof Grobelny entryID); 17807e860f15SJohn Edward Broadbent return; 17817e860f15SJohn Edward Broadbent } 17827e860f15SJohn Edward Broadbent if (ec) 17837e860f15SJohn Edward Broadbent { 17840fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1785002d39b4SEd Tanous << "EventLogEntry (DBus) resp_handler got error " << ec; 17867e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 17877e860f15SJohn Edward Broadbent return; 17887e860f15SJohn Edward Broadbent } 1789914e2d5dSEd Tanous const uint32_t* id = nullptr; 1790c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1791c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1792914e2d5dSEd Tanous const std::string* severity = nullptr; 1793914e2d5dSEd Tanous const std::string* message = nullptr; 1794914e2d5dSEd Tanous const std::string* filePath = nullptr; 17959c11a172SVijay Lobo const std::string* resolution = nullptr; 17967e860f15SJohn Edward Broadbent bool resolved = false; 17979017faf2SAbhishek Patel const std::string* notify = nullptr; 17987e860f15SJohn Edward Broadbent 1799d1bde9e5SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1800d1bde9e5SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), resp, "Id", id, "Timestamp", 1801d1bde9e5SKrzysztof Grobelny timestamp, "UpdateTimestamp", updateTimestamp, "Severity", 18029c11a172SVijay Lobo severity, "Message", message, "Resolved", resolved, 18039017faf2SAbhishek Patel "Resolution", resolution, "Path", filePath, 18049017faf2SAbhishek Patel "ServiceProviderNotify", notify); 1805d1bde9e5SKrzysztof Grobelny 1806d1bde9e5SKrzysztof Grobelny if (!success) 180775710de2SXiaochao Ma { 180875710de2SXiaochao Ma messages::internalError(asyncResp->res); 180975710de2SXiaochao Ma return; 181075710de2SXiaochao Ma } 1811d1bde9e5SKrzysztof Grobelny 1812002d39b4SEd Tanous if (id == nullptr || message == nullptr || severity == nullptr || 18139017faf2SAbhishek Patel timestamp == nullptr || updateTimestamp == nullptr || 18149017faf2SAbhishek Patel notify == nullptr) 1815f86bb901SAdriana Kobylak { 1816ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1817271584abSEd Tanous return; 1818271584abSEd Tanous } 18199017faf2SAbhishek Patel 1820f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 18219c11a172SVijay Lobo "#LogEntry.v1_9_0.LogEntry"; 1822ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 1823ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/{}", 1824ef4c65b7SEd Tanous std::to_string(*id)); 182545ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Event Log Entry"; 1826f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1827f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1828f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 18299017faf2SAbhishek Patel std::optional<bool> notifyAction = getProviderNotifyAction(*notify); 18309017faf2SAbhishek Patel if (notifyAction) 18319017faf2SAbhishek Patel { 18329017faf2SAbhishek Patel asyncResp->res.jsonValue["ServiceProviderNotified"] = 18339017faf2SAbhishek Patel *notifyAction; 18349017faf2SAbhishek Patel } 18359c11a172SVijay Lobo if ((resolution != nullptr) && (!(*resolution).empty())) 18369c11a172SVijay Lobo { 18379c11a172SVijay Lobo asyncResp->res.jsonValue["Resolution"] = *resolution; 18389c11a172SVijay Lobo } 1839f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1840f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1841f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1842f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 18432b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*timestamp); 1844f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 18452b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*updateTimestamp); 1846f86bb901SAdriana Kobylak if (filePath != nullptr) 1847f86bb901SAdriana Kobylak { 1848f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 1849e7dbd530SPotin Lai "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 1850e7dbd530SPotin Lai std::to_string(*id) + "/attachment"; 1851f86bb901SAdriana Kobylak } 1852d1bde9e5SKrzysztof Grobelny }); 18537e860f15SJohn Edward Broadbent }); 1854336e96c6SChicago Duan 18557e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 185622d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1857ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 18587e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 185945ca1b86SEd Tanous [&app](const crow::Request& req, 18607e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 186122d268cbSEd Tanous const std::string& systemName, const std::string& entryId) { 18623ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 186345ca1b86SEd Tanous { 186445ca1b86SEd Tanous return; 186545ca1b86SEd Tanous } 18667f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 18677f3e84a1SEd Tanous { 18687f3e84a1SEd Tanous // Option currently returns no systems. TBD 18697f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 18707f3e84a1SEd Tanous systemName); 18717f3e84a1SEd Tanous return; 18727f3e84a1SEd Tanous } 187322d268cbSEd Tanous if (systemName != "system") 187422d268cbSEd Tanous { 187522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 187622d268cbSEd Tanous systemName); 187722d268cbSEd Tanous return; 187822d268cbSEd Tanous } 187975710de2SXiaochao Ma std::optional<bool> resolved; 188075710de2SXiaochao Ma 188115ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", 18827e860f15SJohn Edward Broadbent resolved)) 188375710de2SXiaochao Ma { 188475710de2SXiaochao Ma return; 188575710de2SXiaochao Ma } 188675710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 188775710de2SXiaochao Ma 18889ae226faSGeorge Liu sdbusplus::asio::setProperty( 18899ae226faSGeorge Liu *crow::connections::systemBus, "xyz.openbmc_project.Logging", 18909ae226faSGeorge Liu "/xyz/openbmc_project/logging/entry/" + entryId, 18919ae226faSGeorge Liu "xyz.openbmc_project.Logging.Entry", "Resolved", *resolved, 18925e7e2dc5SEd Tanous [asyncResp, entryId](const boost::system::error_code& ec) { 189375710de2SXiaochao Ma if (ec) 189475710de2SXiaochao Ma { 189575710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 189675710de2SXiaochao Ma messages::internalError(asyncResp->res); 189775710de2SXiaochao Ma return; 189875710de2SXiaochao Ma } 18999ae226faSGeorge Liu }); 19007e860f15SJohn Edward Broadbent }); 190175710de2SXiaochao Ma 19027e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 190322d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1904ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1905ed398213SEd Tanous 1906002d39b4SEd Tanous .methods(boost::beast::http::verb::delete_)( 1907002d39b4SEd Tanous [&app](const crow::Request& req, 1908002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 190922d268cbSEd Tanous const std::string& systemName, const std::string& param) { 19103ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1911336e96c6SChicago Duan { 191245ca1b86SEd Tanous return; 191345ca1b86SEd Tanous } 19147f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 19157f3e84a1SEd Tanous { 19167f3e84a1SEd Tanous // Option currently returns no systems. TBD 19177f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 19187f3e84a1SEd Tanous systemName); 19197f3e84a1SEd Tanous return; 19207f3e84a1SEd Tanous } 192122d268cbSEd Tanous if (systemName != "system") 192222d268cbSEd Tanous { 192322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 192422d268cbSEd Tanous systemName); 192522d268cbSEd Tanous return; 192622d268cbSEd Tanous } 1927336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1928336e96c6SChicago Duan 19297e860f15SJohn Edward Broadbent std::string entryID = param; 1930336e96c6SChicago Duan 1931336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1932336e96c6SChicago Duan 1933336e96c6SChicago Duan // Process response from Logging service. 1934002d39b4SEd Tanous auto respHandler = 19355e7e2dc5SEd Tanous [asyncResp, entryID](const boost::system::error_code& ec) { 1936002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1937336e96c6SChicago Duan if (ec) 1938336e96c6SChicago Duan { 19393de8d8baSGeorge Liu if (ec.value() == EBADR) 19403de8d8baSGeorge Liu { 194145ca1b86SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 194245ca1b86SEd Tanous entryID); 19433de8d8baSGeorge Liu return; 19443de8d8baSGeorge Liu } 1945336e96c6SChicago Duan // TODO Handle for specific error code 19460fda0f12SGeorge Liu BMCWEB_LOG_ERROR 19470fda0f12SGeorge Liu << "EventLogEntry (DBus) doDelete respHandler got error " 1948336e96c6SChicago Duan << ec; 1949336e96c6SChicago Duan asyncResp->res.result( 1950336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1951336e96c6SChicago Duan return; 1952336e96c6SChicago Duan } 1953336e96c6SChicago Duan 1954336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1955336e96c6SChicago Duan }; 1956336e96c6SChicago Duan 1957336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1958336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1959336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1960336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1961336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 19627e860f15SJohn Edward Broadbent }); 1963400fd1fbSAdriana Kobylak } 1964400fd1fbSAdriana Kobylak 19657e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1966400fd1fbSAdriana Kobylak { 19670fda0f12SGeorge Liu BMCWEB_ROUTE( 19680fda0f12SGeorge Liu app, 196922d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment") 1970ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 19717e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 197245ca1b86SEd Tanous [&app](const crow::Request& req, 19737e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 197422d268cbSEd Tanous const std::string& systemName, const std::string& param) { 19753ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 19767e860f15SJohn Edward Broadbent { 197745ca1b86SEd Tanous return; 197845ca1b86SEd Tanous } 197972e21377SMatt Spinler if (!http_helpers::isContentTypeAllowed( 198099351cd8SEd Tanous req.getHeaderValue("Accept"), 19814a0e1a0cSEd Tanous http_helpers::ContentType::OctetStream, true)) 1982400fd1fbSAdriana Kobylak { 1983002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 1984400fd1fbSAdriana Kobylak return; 1985400fd1fbSAdriana Kobylak } 19867f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 19877f3e84a1SEd Tanous { 19887f3e84a1SEd Tanous // Option currently returns no systems. TBD 19897f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 19907f3e84a1SEd Tanous systemName); 19917f3e84a1SEd Tanous return; 19927f3e84a1SEd Tanous } 199322d268cbSEd Tanous if (systemName != "system") 199422d268cbSEd Tanous { 199522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 199622d268cbSEd Tanous systemName); 199722d268cbSEd Tanous return; 199822d268cbSEd Tanous } 1999400fd1fbSAdriana Kobylak 20007e860f15SJohn Edward Broadbent std::string entryID = param; 2001400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 2002400fd1fbSAdriana Kobylak 2003400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 20045e7e2dc5SEd Tanous [asyncResp, entryID](const boost::system::error_code& ec, 2005400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 2006400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 2007400fd1fbSAdriana Kobylak { 2008002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "EventLogAttachment", 2009002d39b4SEd Tanous entryID); 2010400fd1fbSAdriana Kobylak return; 2011400fd1fbSAdriana Kobylak } 2012400fd1fbSAdriana Kobylak if (ec) 2013400fd1fbSAdriana Kobylak { 2014400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2015400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 2016400fd1fbSAdriana Kobylak return; 2017400fd1fbSAdriana Kobylak } 2018400fd1fbSAdriana Kobylak 2019400fd1fbSAdriana Kobylak int fd = -1; 2020400fd1fbSAdriana Kobylak fd = dup(unixfd); 2021400fd1fbSAdriana Kobylak if (fd == -1) 2022400fd1fbSAdriana Kobylak { 2023400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 2024400fd1fbSAdriana Kobylak return; 2025400fd1fbSAdriana Kobylak } 2026400fd1fbSAdriana Kobylak 2027400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 2028400fd1fbSAdriana Kobylak if (size == -1) 2029400fd1fbSAdriana Kobylak { 2030400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 2031400fd1fbSAdriana Kobylak return; 2032400fd1fbSAdriana Kobylak } 2033400fd1fbSAdriana Kobylak 2034400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 2035400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 2036400fd1fbSAdriana Kobylak if (size > maxFileSize) 2037400fd1fbSAdriana Kobylak { 2038002d39b4SEd Tanous BMCWEB_LOG_ERROR << "File size exceeds maximum allowed size of " 2039400fd1fbSAdriana Kobylak << maxFileSize; 2040400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 2041400fd1fbSAdriana Kobylak return; 2042400fd1fbSAdriana Kobylak } 2043400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 2044400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 2045400fd1fbSAdriana Kobylak if (rc == -1) 2046400fd1fbSAdriana Kobylak { 2047400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 2048400fd1fbSAdriana Kobylak return; 2049400fd1fbSAdriana Kobylak } 2050400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 2051400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 2052400fd1fbSAdriana Kobylak { 2053400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 2054400fd1fbSAdriana Kobylak return; 2055400fd1fbSAdriana Kobylak } 2056400fd1fbSAdriana Kobylak close(fd); 2057400fd1fbSAdriana Kobylak 2058400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 2059002d39b4SEd Tanous std::string output = crow::utility::base64encode(strData); 2060400fd1fbSAdriana Kobylak 2061d9f6c621SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::content_type, 2062400fd1fbSAdriana Kobylak "application/octet-stream"); 2063d9f6c621SEd Tanous asyncResp->res.addHeader( 2064d9f6c621SEd Tanous boost::beast::http::field::content_transfer_encoding, "Base64"); 2065400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 2066400fd1fbSAdriana Kobylak }, 2067400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 2068400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 2069400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 20707e860f15SJohn Edward Broadbent }); 20711da66f75SEd Tanous } 20721da66f75SEd Tanous 2073b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 2074b7028ebfSSpencer Ku 2075b7028ebfSSpencer Ku inline bool 2076b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 2077b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 2078b7028ebfSSpencer Ku { 2079b7028ebfSSpencer Ku std::error_code ec; 2080b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 2081b7028ebfSSpencer Ku if (ec) 2082b7028ebfSSpencer Ku { 2083b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << ec.message(); 2084b7028ebfSSpencer Ku return false; 2085b7028ebfSSpencer Ku } 2086b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 2087b7028ebfSSpencer Ku { 2088b7028ebfSSpencer Ku std::string filename = it.path().filename(); 2089b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 2090b7028ebfSSpencer Ku // path 209111ba3979SEd Tanous if (filename.starts_with("log")) 2092b7028ebfSSpencer Ku { 2093b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 2094b7028ebfSSpencer Ku } 2095b7028ebfSSpencer Ku } 2096b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 2097b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 2098b7028ebfSSpencer Ku // descending order. 2099b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 2100b7028ebfSSpencer Ku AlphanumLess<std::string>()); 2101b7028ebfSSpencer Ku 2102b7028ebfSSpencer Ku return true; 2103b7028ebfSSpencer Ku } 2104b7028ebfSSpencer Ku 210502cad96eSEd Tanous inline bool getHostLoggerEntries( 210602cad96eSEd Tanous const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip, 210702cad96eSEd Tanous uint64_t top, std::vector<std::string>& logEntries, size_t& logCount) 2108b7028ebfSSpencer Ku { 2109b7028ebfSSpencer Ku GzFileReader logFile; 2110b7028ebfSSpencer Ku 2111b7028ebfSSpencer Ku // Go though all log files and expose host logs. 2112b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 2113b7028ebfSSpencer Ku { 2114b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 2115b7028ebfSSpencer Ku { 2116b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to expose host logs"; 2117b7028ebfSSpencer Ku return false; 2118b7028ebfSSpencer Ku } 2119b7028ebfSSpencer Ku } 2120b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 2121b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 2122b7028ebfSSpencer Ku if (!lastMessage.empty()) 2123b7028ebfSSpencer Ku { 2124b7028ebfSSpencer Ku logCount++; 2125b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 2126b7028ebfSSpencer Ku { 2127b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 2128b7028ebfSSpencer Ku } 2129b7028ebfSSpencer Ku } 2130b7028ebfSSpencer Ku return true; 2131b7028ebfSSpencer Ku } 2132b7028ebfSSpencer Ku 2133b7028ebfSSpencer Ku inline void fillHostLoggerEntryJson(const std::string& logEntryID, 2134b7028ebfSSpencer Ku const std::string& msg, 21356d6574c9SJason M. Bills nlohmann::json::object_t& logEntryJson) 2136b7028ebfSSpencer Ku { 2137b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 21389c11a172SVijay Lobo logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 2139ef4c65b7SEd Tanous logEntryJson["@odata.id"] = boost::urls::format( 2140ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/{}", 2141ef4c65b7SEd Tanous logEntryID); 21426d6574c9SJason M. Bills logEntryJson["Name"] = "Host Logger Entry"; 21436d6574c9SJason M. Bills logEntryJson["Id"] = logEntryID; 21446d6574c9SJason M. Bills logEntryJson["Message"] = msg; 21456d6574c9SJason M. Bills logEntryJson["EntryType"] = "Oem"; 21466d6574c9SJason M. Bills logEntryJson["Severity"] = "OK"; 21476d6574c9SJason M. Bills logEntryJson["OemRecordFormat"] = "Host Logger Entry"; 2148b7028ebfSSpencer Ku } 2149b7028ebfSSpencer Ku 2150b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 2151b7028ebfSSpencer Ku { 215222d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/") 2153b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 21541476687dSEd Tanous .methods(boost::beast::http::verb::get)( 21551476687dSEd Tanous [&app](const crow::Request& req, 215622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 215722d268cbSEd Tanous const std::string& systemName) { 21583ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 215945ca1b86SEd Tanous { 216045ca1b86SEd Tanous return; 216145ca1b86SEd Tanous } 21627f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 21637f3e84a1SEd Tanous { 21647f3e84a1SEd Tanous // Option currently returns no systems. TBD 21657f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 21667f3e84a1SEd Tanous systemName); 21677f3e84a1SEd Tanous return; 21687f3e84a1SEd Tanous } 216922d268cbSEd Tanous if (systemName != "system") 217022d268cbSEd Tanous { 217122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 217222d268cbSEd Tanous systemName); 217322d268cbSEd Tanous return; 217422d268cbSEd Tanous } 2175b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 2176b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"; 2177b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 2178b7028ebfSSpencer Ku "#LogService.v1_1_0.LogService"; 2179b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 2180b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 2181b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 21821476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 21831476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 2184b7028ebfSSpencer Ku }); 2185b7028ebfSSpencer Ku } 2186b7028ebfSSpencer Ku 2187b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 2188b7028ebfSSpencer Ku { 2189b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 219022d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/") 2191b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2192002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2193002d39b4SEd Tanous [&app](const crow::Request& req, 219422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 219522d268cbSEd Tanous const std::string& systemName) { 2196c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2197c937d2bfSEd Tanous .canDelegateTop = true, 2198c937d2bfSEd Tanous .canDelegateSkip = true, 2199c937d2bfSEd Tanous }; 2200c937d2bfSEd Tanous query_param::Query delegatedQuery; 2201c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 22023ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 2203b7028ebfSSpencer Ku { 2204b7028ebfSSpencer Ku return; 2205b7028ebfSSpencer Ku } 22067f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 22077f3e84a1SEd Tanous { 22087f3e84a1SEd Tanous // Option currently returns no systems. TBD 22097f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 22107f3e84a1SEd Tanous systemName); 22117f3e84a1SEd Tanous return; 22127f3e84a1SEd Tanous } 221322d268cbSEd Tanous if (systemName != "system") 221422d268cbSEd Tanous { 221522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 221622d268cbSEd Tanous systemName); 221722d268cbSEd Tanous return; 221822d268cbSEd Tanous } 2219b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 2220b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 2221b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 2222b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 2223b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 2224b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 2225b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 22260fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2227b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 2228b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 2229b7028ebfSSpencer Ku 2230b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2231b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2232b7028ebfSSpencer Ku { 2233b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 2234b7028ebfSSpencer Ku return; 2235b7028ebfSSpencer Ku } 22363648c8beSEd Tanous // If we weren't provided top and skip limits, use the defaults. 22373648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 22385143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 2239b7028ebfSSpencer Ku size_t logCount = 0; 2240b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 2241b7028ebfSSpencer Ku // control by skip and top. 2242b7028ebfSSpencer Ku std::vector<std::string> logEntries; 22433648c8beSEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries, 22443648c8beSEd Tanous logCount)) 2245b7028ebfSSpencer Ku { 2246b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2247b7028ebfSSpencer Ku return; 2248b7028ebfSSpencer Ku } 2249b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 2250b7028ebfSSpencer Ku // log count 225126f6976fSEd Tanous if (logEntries.empty()) 2252b7028ebfSSpencer Ku { 2253b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 2254b7028ebfSSpencer Ku return; 2255b7028ebfSSpencer Ku } 225626f6976fSEd Tanous if (!logEntries.empty()) 2257b7028ebfSSpencer Ku { 2258b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 2259b7028ebfSSpencer Ku { 22606d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 22613648c8beSEd Tanous fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i], 22623648c8beSEd Tanous hostLogEntry); 2263b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(hostLogEntry)); 2264b7028ebfSSpencer Ku } 2265b7028ebfSSpencer Ku 2266b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 22673648c8beSEd Tanous if (skip + top < logCount) 2268b7028ebfSSpencer Ku { 2269b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 22700fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/HostLogger/Entries?$skip=" + 22713648c8beSEd Tanous std::to_string(skip + top); 2272b7028ebfSSpencer Ku } 2273b7028ebfSSpencer Ku } 2274b7028ebfSSpencer Ku }); 2275b7028ebfSSpencer Ku } 2276b7028ebfSSpencer Ku 2277b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 2278b7028ebfSSpencer Ku { 2279b7028ebfSSpencer Ku BMCWEB_ROUTE( 228022d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/") 2281b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2282b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 228345ca1b86SEd Tanous [&app](const crow::Request& req, 2284b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 228522d268cbSEd Tanous const std::string& systemName, const std::string& param) { 22863ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 228745ca1b86SEd Tanous { 228845ca1b86SEd Tanous return; 228945ca1b86SEd Tanous } 22907f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 22917f3e84a1SEd Tanous { 22927f3e84a1SEd Tanous // Option currently returns no systems. TBD 22937f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 22947f3e84a1SEd Tanous systemName); 22957f3e84a1SEd Tanous return; 22967f3e84a1SEd Tanous } 229722d268cbSEd Tanous if (systemName != "system") 229822d268cbSEd Tanous { 229922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 230022d268cbSEd Tanous systemName); 230122d268cbSEd Tanous return; 230222d268cbSEd Tanous } 2303b7028ebfSSpencer Ku const std::string& targetID = param; 2304b7028ebfSSpencer Ku 2305b7028ebfSSpencer Ku uint64_t idInt = 0; 2306ca45aa3cSEd Tanous 230784396af9SPatrick Williams auto [ptr, ec] = std::from_chars(&*targetID.begin(), &*targetID.end(), 230884396af9SPatrick Williams idInt); 23099db4ba25SJiaqing Zhao if (ec == std::errc::invalid_argument || 23109db4ba25SJiaqing Zhao ec == std::errc::result_out_of_range) 2311b7028ebfSSpencer Ku { 23129db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", param); 2313b7028ebfSSpencer Ku return; 2314b7028ebfSSpencer Ku } 2315b7028ebfSSpencer Ku 2316b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2317b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2318b7028ebfSSpencer Ku { 2319b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 2320b7028ebfSSpencer Ku return; 2321b7028ebfSSpencer Ku } 2322b7028ebfSSpencer Ku 2323b7028ebfSSpencer Ku size_t logCount = 0; 23243648c8beSEd Tanous size_t top = 1; 2325b7028ebfSSpencer Ku std::vector<std::string> logEntries; 2326b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 2327b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 2328b7028ebfSSpencer Ku // get that entry 2329002d39b4SEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries, 2330002d39b4SEd Tanous logCount)) 2331b7028ebfSSpencer Ku { 2332b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2333b7028ebfSSpencer Ku return; 2334b7028ebfSSpencer Ku } 2335b7028ebfSSpencer Ku 2336b7028ebfSSpencer Ku if (!logEntries.empty()) 2337b7028ebfSSpencer Ku { 23386d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 23396d6574c9SJason M. Bills fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry); 23406d6574c9SJason M. Bills asyncResp->res.jsonValue.update(hostLogEntry); 2341b7028ebfSSpencer Ku return; 2342b7028ebfSSpencer Ku } 2343b7028ebfSSpencer Ku 2344b7028ebfSSpencer Ku // Requested ID was not found 23459db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", param); 2346b7028ebfSSpencer Ku }); 2347b7028ebfSSpencer Ku } 2348b7028ebfSSpencer Ku 2349dd72e87bSClaire Weinan inline void handleBMCLogServicesCollectionGet( 2350fdd26906SClaire Weinan crow::App& app, const crow::Request& req, 2351fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 23521da66f75SEd Tanous { 23533ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 235445ca1b86SEd Tanous { 235545ca1b86SEd Tanous return; 235645ca1b86SEd Tanous } 23577e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 23587e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2359e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 23601da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2361e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 2362e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 2363002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 2364e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 23651da66f75SEd Tanous "Collection of LogServices for this Manager"; 2366002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 2367c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 2368fdd26906SClaire Weinan 2369c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 2370613dabeaSEd Tanous nlohmann::json::object_t journal; 2371613dabeaSEd Tanous journal["@odata.id"] = "/redfish/v1/Managers/bmc/LogServices/Journal"; 2372b2ba3072SPatrick Williams logServiceArray.emplace_back(std::move(journal)); 2373c4bf6374SJason M. Bills #endif 2374fdd26906SClaire Weinan 2375fdd26906SClaire Weinan asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); 2376fdd26906SClaire Weinan 2377fdd26906SClaire Weinan #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 237815912159SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 23797a1dbc48SGeorge Liu "xyz.openbmc_project.Collection.DeleteAll"}; 23807a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 23817a1dbc48SGeorge Liu "/xyz/openbmc_project/dump", 0, interfaces, 2382fdd26906SClaire Weinan [asyncResp]( 23837a1dbc48SGeorge Liu const boost::system::error_code& ec, 2384fdd26906SClaire Weinan const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 2385fdd26906SClaire Weinan if (ec) 2386fdd26906SClaire Weinan { 2387fdd26906SClaire Weinan BMCWEB_LOG_ERROR 2388dd72e87bSClaire Weinan << "handleBMCLogServicesCollectionGet respHandler got error " 2389fdd26906SClaire Weinan << ec; 2390fdd26906SClaire Weinan // Assume that getting an error simply means there are no dump 2391fdd26906SClaire Weinan // LogServices. Return without adding any error response. 2392fdd26906SClaire Weinan return; 2393fdd26906SClaire Weinan } 2394fdd26906SClaire Weinan 2395fdd26906SClaire Weinan nlohmann::json& logServiceArrayLocal = 2396fdd26906SClaire Weinan asyncResp->res.jsonValue["Members"]; 2397fdd26906SClaire Weinan 2398fdd26906SClaire Weinan for (const std::string& path : subTreePaths) 2399fdd26906SClaire Weinan { 2400fdd26906SClaire Weinan if (path == "/xyz/openbmc_project/dump/bmc") 2401fdd26906SClaire Weinan { 2402613dabeaSEd Tanous nlohmann::json::object_t member; 2403613dabeaSEd Tanous member["@odata.id"] = 2404613dabeaSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump"; 2405b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 2406fdd26906SClaire Weinan } 2407fdd26906SClaire Weinan else if (path == "/xyz/openbmc_project/dump/faultlog") 2408fdd26906SClaire Weinan { 2409613dabeaSEd Tanous nlohmann::json::object_t member; 2410613dabeaSEd Tanous member["@odata.id"] = 2411613dabeaSEd Tanous "/redfish/v1/Managers/bmc/LogServices/FaultLog"; 2412b2ba3072SPatrick Williams logServiceArrayLocal.emplace_back(std::move(member)); 2413fdd26906SClaire Weinan } 2414fdd26906SClaire Weinan } 2415fdd26906SClaire Weinan 2416e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2417fdd26906SClaire Weinan logServiceArrayLocal.size(); 24187a1dbc48SGeorge Liu }); 2419fdd26906SClaire Weinan #endif 2420fdd26906SClaire Weinan } 2421fdd26906SClaire Weinan 2422fdd26906SClaire Weinan inline void requestRoutesBMCLogServiceCollection(App& app) 2423fdd26906SClaire Weinan { 2424fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 2425fdd26906SClaire Weinan .privileges(redfish::privileges::getLogServiceCollection) 2426fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2427dd72e87bSClaire Weinan std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app))); 2428e1f26343SJason M. Bills } 2429e1f26343SJason M. Bills 24307e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 2431e1f26343SJason M. Bills { 24327e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 2433ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 24347e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 243545ca1b86SEd Tanous [&app](const crow::Request& req, 243645ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24373ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 24387e860f15SJohn Edward Broadbent { 243945ca1b86SEd Tanous return; 244045ca1b86SEd Tanous } 2441e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2442e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 24430f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 24440f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 2445002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 2446002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 2447ed34a4adSEd Tanous asyncResp->res.jsonValue["Id"] = "Journal"; 2448e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 24497c8c4058STejas Patil 24507c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 24512b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 2452002d39b4SEd Tanous asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 24537c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 24547c8c4058STejas Patil redfishDateTimeOffset.second; 24557c8c4058STejas Patil 24561476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 24571476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 24587e860f15SJohn Edward Broadbent }); 2459e1f26343SJason M. Bills } 2460e1f26343SJason M. Bills 24613a48b3a2SJason M. Bills static int 24623a48b3a2SJason M. Bills fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 2463e1f26343SJason M. Bills sd_journal* journal, 24643a48b3a2SJason M. Bills nlohmann::json::object_t& bmcJournalLogEntryJson) 2465e1f26343SJason M. Bills { 2466e1f26343SJason M. Bills // Get the Log Entry contents 2467e1f26343SJason M. Bills int ret = 0; 2468e1f26343SJason M. Bills 2469a8fe54f0SJason M. Bills std::string message; 2470a8fe54f0SJason M. Bills std::string_view syslogID; 2471a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 2472a8fe54f0SJason M. Bills if (ret < 0) 2473a8fe54f0SJason M. Bills { 2474a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 2475a8fe54f0SJason M. Bills << strerror(-ret); 2476a8fe54f0SJason M. Bills } 2477a8fe54f0SJason M. Bills if (!syslogID.empty()) 2478a8fe54f0SJason M. Bills { 2479a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 2480a8fe54f0SJason M. Bills } 2481a8fe54f0SJason M. Bills 248239e77504SEd Tanous std::string_view msg; 248316428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 2484e1f26343SJason M. Bills if (ret < 0) 2485e1f26343SJason M. Bills { 2486e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 2487e1f26343SJason M. Bills return 1; 2488e1f26343SJason M. Bills } 2489a8fe54f0SJason M. Bills message += std::string(msg); 2490e1f26343SJason M. Bills 2491e1f26343SJason M. Bills // Get the severity from the PRIORITY field 2492271584abSEd Tanous long int severity = 8; // Default to an invalid priority 249316428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 2494e1f26343SJason M. Bills if (ret < 0) 2495e1f26343SJason M. Bills { 2496e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 2497e1f26343SJason M. Bills } 2498e1f26343SJason M. Bills 2499e1f26343SJason M. Bills // Get the Created time from the timestamp 250016428a1aSJason M. Bills std::string entryTimeStr; 250116428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 2502e1f26343SJason M. Bills { 250316428a1aSJason M. Bills return 1; 2504e1f26343SJason M. Bills } 2505e1f26343SJason M. Bills 2506e1f26343SJason M. Bills // Fill in the log entry with the gathered data 25079c11a172SVijay Lobo bmcJournalLogEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 2508ef4c65b7SEd Tanous bmcJournalLogEntryJson["@odata.id"] = boost::urls::format( 2509ef4c65b7SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/{}", 2510eddfc437SWilly Tu bmcJournalLogEntryID); 251184afc48bSJason M. Bills bmcJournalLogEntryJson["Name"] = "BMC Journal Entry"; 251284afc48bSJason M. Bills bmcJournalLogEntryJson["Id"] = bmcJournalLogEntryID; 251384afc48bSJason M. Bills bmcJournalLogEntryJson["Message"] = std::move(message); 251484afc48bSJason M. Bills bmcJournalLogEntryJson["EntryType"] = "Oem"; 251584afc48bSJason M. Bills bmcJournalLogEntryJson["Severity"] = severity <= 2 ? "Critical" 2516738c1e61SPatrick Williams : severity <= 4 ? "Warning" 251784afc48bSJason M. Bills : "OK"; 251884afc48bSJason M. Bills bmcJournalLogEntryJson["OemRecordFormat"] = "BMC Journal Entry"; 251984afc48bSJason M. Bills bmcJournalLogEntryJson["Created"] = std::move(entryTimeStr); 2520e1f26343SJason M. Bills return 0; 2521e1f26343SJason M. Bills } 2522e1f26343SJason M. Bills 25237e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 2524e1f26343SJason M. Bills { 25257e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 2526ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 2527002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2528002d39b4SEd Tanous [&app](const crow::Request& req, 2529002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2530c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2531c937d2bfSEd Tanous .canDelegateTop = true, 2532c937d2bfSEd Tanous .canDelegateSkip = true, 2533c937d2bfSEd Tanous }; 2534c937d2bfSEd Tanous query_param::Query delegatedQuery; 2535c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 25363ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 2537193ad2faSJason M. Bills { 2538193ad2faSJason M. Bills return; 2539193ad2faSJason M. Bills } 25403648c8beSEd Tanous 25413648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 25425143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 25433648c8beSEd Tanous 25447e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 25457e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2546e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2547e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 25480f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 25490f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 2550e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 2551e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2552e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 25530fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2554e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2555e1f26343SJason M. Bills 25567e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 25577e860f15SJohn Edward Broadbent // unique ID for each entry 2558e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2559e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2560e1f26343SJason M. Bills if (ret < 0) 2561e1f26343SJason M. Bills { 2562002d39b4SEd Tanous BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 2563f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2564e1f26343SJason M. Bills return; 2565e1f26343SJason M. Bills } 25660fda0f12SGeorge Liu std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 25670fda0f12SGeorge Liu journalTmp, sd_journal_close); 2568e1f26343SJason M. Bills journalTmp = nullptr; 2569b01bf299SEd Tanous uint64_t entryCount = 0; 2570e85d6b16SJason M. Bills // Reset the unique ID on the first entry 2571e85d6b16SJason M. Bills bool firstEntry = true; 2572e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 2573e1f26343SJason M. Bills { 2574193ad2faSJason M. Bills entryCount++; 25757e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 25767e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 25773648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 2578193ad2faSJason M. Bills { 2579193ad2faSJason M. Bills continue; 2580193ad2faSJason M. Bills } 2581193ad2faSJason M. Bills 258216428a1aSJason M. Bills std::string idStr; 2583e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2584e1f26343SJason M. Bills { 2585e1f26343SJason M. Bills continue; 2586e1f26343SJason M. Bills } 2587e85d6b16SJason M. Bills firstEntry = false; 2588e85d6b16SJason M. Bills 25893a48b3a2SJason M. Bills nlohmann::json::object_t bmcJournalLogEntry; 2590c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 2591c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 2592e1f26343SJason M. Bills { 2593f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2594e1f26343SJason M. Bills return; 2595e1f26343SJason M. Bills } 2596b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(bmcJournalLogEntry)); 2597e1f26343SJason M. Bills } 2598193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 25993648c8beSEd Tanous if (skip + top < entryCount) 2600193ad2faSJason M. Bills { 2601193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 26020fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 26033648c8beSEd Tanous std::to_string(skip + top); 2604193ad2faSJason M. Bills } 26057e860f15SJohn Edward Broadbent }); 2606e1f26343SJason M. Bills } 2607e1f26343SJason M. Bills 26087e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 2609e1f26343SJason M. Bills { 26107e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 26117e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 2612ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 26137e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 261445ca1b86SEd Tanous [&app](const crow::Request& req, 26157e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26167e860f15SJohn Edward Broadbent const std::string& entryID) { 26173ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 261845ca1b86SEd Tanous { 261945ca1b86SEd Tanous return; 262045ca1b86SEd Tanous } 2621e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2622e1f26343SJason M. Bills uint64_t ts = 0; 2623271584abSEd Tanous uint64_t index = 0; 26248d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2625e1f26343SJason M. Bills { 262616428a1aSJason M. Bills return; 2627e1f26343SJason M. Bills } 2628e1f26343SJason M. Bills 2629e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2630e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2631e1f26343SJason M. Bills if (ret < 0) 2632e1f26343SJason M. Bills { 2633002d39b4SEd Tanous BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 2634f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2635e1f26343SJason M. Bills return; 2636e1f26343SJason M. Bills } 2637002d39b4SEd Tanous std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 2638002d39b4SEd Tanous journalTmp, sd_journal_close); 2639e1f26343SJason M. Bills journalTmp = nullptr; 26407e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 26417e860f15SJohn Edward Broadbent // index tracking the unique ID 2642af07e3f5SJason M. Bills std::string idStr; 2643af07e3f5SJason M. Bills bool firstEntry = true; 2644e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 26452056b6d1SManojkiran Eda if (ret < 0) 26462056b6d1SManojkiran Eda { 26472056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 26482056b6d1SManojkiran Eda << strerror(-ret); 26492056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 26502056b6d1SManojkiran Eda return; 26512056b6d1SManojkiran Eda } 2652271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2653e1f26343SJason M. Bills { 2654e1f26343SJason M. Bills sd_journal_next(journal.get()); 2655af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2656af07e3f5SJason M. Bills { 2657af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2658af07e3f5SJason M. Bills return; 2659af07e3f5SJason M. Bills } 2660af07e3f5SJason M. Bills firstEntry = false; 2661af07e3f5SJason M. Bills } 2662c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2663af07e3f5SJason M. Bills if (idStr != entryID) 2664c4bf6374SJason M. Bills { 26659db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 2666c4bf6374SJason M. Bills return; 2667c4bf6374SJason M. Bills } 2668c4bf6374SJason M. Bills 26693a48b3a2SJason M. Bills nlohmann::json::object_t bmcJournalLogEntry; 2670c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 26713a48b3a2SJason M. Bills bmcJournalLogEntry) != 0) 2672e1f26343SJason M. Bills { 2673f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2674e1f26343SJason M. Bills return; 2675e1f26343SJason M. Bills } 2676d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcJournalLogEntry); 26777e860f15SJohn Edward Broadbent }); 2678c9bb6861Sraviteja-b } 2679c9bb6861Sraviteja-b 2680fdd26906SClaire Weinan inline void 2681fdd26906SClaire Weinan getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2682fdd26906SClaire Weinan const std::string& dumpType) 2683c9bb6861Sraviteja-b { 2684fdd26906SClaire Weinan std::string dumpPath; 2685fdd26906SClaire Weinan std::string overWritePolicy; 2686fdd26906SClaire Weinan bool collectDiagnosticDataSupported = false; 2687fdd26906SClaire Weinan 2688fdd26906SClaire Weinan if (dumpType == "BMC") 268945ca1b86SEd Tanous { 2690fdd26906SClaire Weinan dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump"; 2691fdd26906SClaire Weinan overWritePolicy = "WrapsWhenFull"; 2692fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2693fdd26906SClaire Weinan } 2694fdd26906SClaire Weinan else if (dumpType == "FaultLog") 2695fdd26906SClaire Weinan { 2696fdd26906SClaire Weinan dumpPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog"; 2697fdd26906SClaire Weinan overWritePolicy = "Unknown"; 2698fdd26906SClaire Weinan collectDiagnosticDataSupported = false; 2699fdd26906SClaire Weinan } 2700fdd26906SClaire Weinan else if (dumpType == "System") 2701fdd26906SClaire Weinan { 2702fdd26906SClaire Weinan dumpPath = "/redfish/v1/Systems/system/LogServices/Dump"; 2703fdd26906SClaire Weinan overWritePolicy = "WrapsWhenFull"; 2704fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2705fdd26906SClaire Weinan } 2706fdd26906SClaire Weinan else 2707fdd26906SClaire Weinan { 2708fdd26906SClaire Weinan BMCWEB_LOG_ERROR << "getDumpServiceInfo() invalid dump type: " 2709fdd26906SClaire Weinan << dumpType; 2710fdd26906SClaire Weinan messages::internalError(asyncResp->res); 271145ca1b86SEd Tanous return; 271245ca1b86SEd Tanous } 2713fdd26906SClaire Weinan 2714fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = dumpPath; 2715fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; 2716c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 2717fdd26906SClaire Weinan asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; 2718fdd26906SClaire Weinan asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); 2719fdd26906SClaire Weinan asyncResp->res.jsonValue["OverWritePolicy"] = std::move(overWritePolicy); 27207c8c4058STejas Patil 27217c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 27222b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 27230fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 27247c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 27257c8c4058STejas Patil redfishDateTimeOffset.second; 27267c8c4058STejas Patil 2727fdd26906SClaire Weinan asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; 2728fdd26906SClaire Weinan 2729fdd26906SClaire Weinan if (collectDiagnosticDataSupported) 2730fdd26906SClaire Weinan { 2731002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 27321476687dSEd Tanous ["target"] = 2733fdd26906SClaire Weinan dumpPath + "/Actions/LogService.CollectDiagnosticData"; 2734fdd26906SClaire Weinan } 27350d946211SClaire Weinan 27360d946211SClaire Weinan constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface}; 27370d946211SClaire Weinan dbus::utility::getSubTreePaths( 27380d946211SClaire Weinan "/xyz/openbmc_project/dump", 0, interfaces, 27390d946211SClaire Weinan [asyncResp, dumpType, dumpPath]( 27400d946211SClaire Weinan const boost::system::error_code& ec, 27410d946211SClaire Weinan const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 27420d946211SClaire Weinan if (ec) 27430d946211SClaire Weinan { 27440d946211SClaire Weinan BMCWEB_LOG_ERROR << "getDumpServiceInfo respHandler got error " 27450d946211SClaire Weinan << ec; 27460d946211SClaire Weinan // Assume that getting an error simply means there are no dump 27470d946211SClaire Weinan // LogServices. Return without adding any error response. 27480d946211SClaire Weinan return; 27490d946211SClaire Weinan } 27500d946211SClaire Weinan 27510d946211SClaire Weinan const std::string dbusDumpPath = 27520d946211SClaire Weinan "/xyz/openbmc_project/dump/" + 27530d946211SClaire Weinan boost::algorithm::to_lower_copy(dumpType); 27540d946211SClaire Weinan 27550d946211SClaire Weinan for (const std::string& path : subTreePaths) 27560d946211SClaire Weinan { 27570d946211SClaire Weinan if (path == dbusDumpPath) 27580d946211SClaire Weinan { 27590d946211SClaire Weinan asyncResp->res 27600d946211SClaire Weinan .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 27610d946211SClaire Weinan dumpPath + "/Actions/LogService.ClearLog"; 27620d946211SClaire Weinan break; 27630d946211SClaire Weinan } 27640d946211SClaire Weinan } 27650d946211SClaire Weinan }); 2766c9bb6861Sraviteja-b } 2767c9bb6861Sraviteja-b 2768fdd26906SClaire Weinan inline void handleLogServicesDumpServiceGet( 2769fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2770fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 27717e860f15SJohn Edward Broadbent { 27723ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 277345ca1b86SEd Tanous { 277445ca1b86SEd Tanous return; 277545ca1b86SEd Tanous } 2776fdd26906SClaire Weinan getDumpServiceInfo(asyncResp, dumpType); 2777fdd26906SClaire Weinan } 2778c9bb6861Sraviteja-b 277922d268cbSEd Tanous inline void handleLogServicesDumpServiceComputerSystemGet( 278022d268cbSEd Tanous crow::App& app, const crow::Request& req, 278122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 278222d268cbSEd Tanous const std::string& chassisId) 278322d268cbSEd Tanous { 278422d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 278522d268cbSEd Tanous { 278622d268cbSEd Tanous return; 278722d268cbSEd Tanous } 278822d268cbSEd Tanous if (chassisId != "system") 278922d268cbSEd Tanous { 279022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 279122d268cbSEd Tanous return; 279222d268cbSEd Tanous } 279322d268cbSEd Tanous getDumpServiceInfo(asyncResp, "System"); 279422d268cbSEd Tanous } 279522d268cbSEd Tanous 2796fdd26906SClaire Weinan inline void handleLogServicesDumpEntriesCollectionGet( 2797fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2798fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2799fdd26906SClaire Weinan { 2800fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2801fdd26906SClaire Weinan { 2802fdd26906SClaire Weinan return; 2803fdd26906SClaire Weinan } 2804fdd26906SClaire Weinan getDumpEntryCollection(asyncResp, dumpType); 2805fdd26906SClaire Weinan } 2806fdd26906SClaire Weinan 280722d268cbSEd Tanous inline void handleLogServicesDumpEntriesCollectionComputerSystemGet( 280822d268cbSEd Tanous crow::App& app, const crow::Request& req, 280922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 281022d268cbSEd Tanous const std::string& chassisId) 281122d268cbSEd Tanous { 281222d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 281322d268cbSEd Tanous { 281422d268cbSEd Tanous return; 281522d268cbSEd Tanous } 281622d268cbSEd Tanous if (chassisId != "system") 281722d268cbSEd Tanous { 281822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 281922d268cbSEd Tanous return; 282022d268cbSEd Tanous } 282122d268cbSEd Tanous getDumpEntryCollection(asyncResp, "System"); 282222d268cbSEd Tanous } 282322d268cbSEd Tanous 2824fdd26906SClaire Weinan inline void handleLogServicesDumpEntryGet( 2825fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2826fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2827fdd26906SClaire Weinan const std::string& dumpId) 2828fdd26906SClaire Weinan { 2829fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2830fdd26906SClaire Weinan { 2831fdd26906SClaire Weinan return; 2832fdd26906SClaire Weinan } 2833fdd26906SClaire Weinan getDumpEntryById(asyncResp, dumpId, dumpType); 2834fdd26906SClaire Weinan } 283522d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemGet( 283622d268cbSEd Tanous crow::App& app, const crow::Request& req, 283722d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 283822d268cbSEd Tanous const std::string& chassisId, const std::string& dumpId) 283922d268cbSEd Tanous { 284022d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 284122d268cbSEd Tanous { 284222d268cbSEd Tanous return; 284322d268cbSEd Tanous } 284422d268cbSEd Tanous if (chassisId != "system") 284522d268cbSEd Tanous { 284622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 284722d268cbSEd Tanous return; 284822d268cbSEd Tanous } 284922d268cbSEd Tanous getDumpEntryById(asyncResp, dumpId, "System"); 285022d268cbSEd Tanous } 2851fdd26906SClaire Weinan 2852fdd26906SClaire Weinan inline void handleLogServicesDumpEntryDelete( 2853fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2854fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2855fdd26906SClaire Weinan const std::string& dumpId) 2856fdd26906SClaire Weinan { 2857fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2858fdd26906SClaire Weinan { 2859fdd26906SClaire Weinan return; 2860fdd26906SClaire Weinan } 2861fdd26906SClaire Weinan deleteDumpEntry(asyncResp, dumpId, dumpType); 2862fdd26906SClaire Weinan } 2863fdd26906SClaire Weinan 286422d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemDelete( 286522d268cbSEd Tanous crow::App& app, const crow::Request& req, 286622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 286722d268cbSEd Tanous const std::string& chassisId, const std::string& dumpId) 286822d268cbSEd Tanous { 286922d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 287022d268cbSEd Tanous { 287122d268cbSEd Tanous return; 287222d268cbSEd Tanous } 287322d268cbSEd Tanous if (chassisId != "system") 287422d268cbSEd Tanous { 287522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 287622d268cbSEd Tanous return; 287722d268cbSEd Tanous } 287822d268cbSEd Tanous deleteDumpEntry(asyncResp, dumpId, "System"); 287922d268cbSEd Tanous } 288022d268cbSEd Tanous 2881fdd26906SClaire Weinan inline void handleLogServicesDumpCollectDiagnosticDataPost( 2882fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2883fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2884fdd26906SClaire Weinan { 2885fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2886fdd26906SClaire Weinan { 2887fdd26906SClaire Weinan return; 2888fdd26906SClaire Weinan } 2889fdd26906SClaire Weinan createDump(asyncResp, req, dumpType); 2890fdd26906SClaire Weinan } 2891fdd26906SClaire Weinan 289222d268cbSEd Tanous inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost( 289322d268cbSEd Tanous crow::App& app, const crow::Request& req, 289422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 28957f3e84a1SEd Tanous const std::string& systemName) 289622d268cbSEd Tanous { 289722d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 289822d268cbSEd Tanous { 289922d268cbSEd Tanous return; 290022d268cbSEd Tanous } 29017f3e84a1SEd Tanous 29027f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 290322d268cbSEd Tanous { 29047f3e84a1SEd Tanous // Option currently returns no systems. TBD 29057f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 29067f3e84a1SEd Tanous systemName); 29077f3e84a1SEd Tanous return; 29087f3e84a1SEd Tanous } 29097f3e84a1SEd Tanous if (systemName != "system") 29107f3e84a1SEd Tanous { 29117f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 29127f3e84a1SEd Tanous systemName); 291322d268cbSEd Tanous return; 291422d268cbSEd Tanous } 291522d268cbSEd Tanous createDump(asyncResp, req, "System"); 291622d268cbSEd Tanous } 291722d268cbSEd Tanous 2918fdd26906SClaire Weinan inline void handleLogServicesDumpClearLogPost( 2919fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2920fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2921fdd26906SClaire Weinan { 2922fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2923fdd26906SClaire Weinan { 2924fdd26906SClaire Weinan return; 2925fdd26906SClaire Weinan } 2926fdd26906SClaire Weinan clearDump(asyncResp, dumpType); 2927fdd26906SClaire Weinan } 2928fdd26906SClaire Weinan 292922d268cbSEd Tanous inline void handleLogServicesDumpClearLogComputerSystemPost( 293022d268cbSEd Tanous crow::App& app, const crow::Request& req, 293122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29327f3e84a1SEd Tanous const std::string& systemName) 293322d268cbSEd Tanous { 293422d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 293522d268cbSEd Tanous { 293622d268cbSEd Tanous return; 293722d268cbSEd Tanous } 29387f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 293922d268cbSEd Tanous { 29407f3e84a1SEd Tanous // Option currently returns no systems. TBD 29417f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 29427f3e84a1SEd Tanous systemName); 29437f3e84a1SEd Tanous return; 29447f3e84a1SEd Tanous } 29457f3e84a1SEd Tanous if (systemName != "system") 29467f3e84a1SEd Tanous { 29477f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 29487f3e84a1SEd Tanous systemName); 294922d268cbSEd Tanous return; 295022d268cbSEd Tanous } 295122d268cbSEd Tanous clearDump(asyncResp, "System"); 295222d268cbSEd Tanous } 295322d268cbSEd Tanous 2954fdd26906SClaire Weinan inline void requestRoutesBMCDumpService(App& app) 2955fdd26906SClaire Weinan { 2956fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2957fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2958fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2959fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "BMC")); 2960fdd26906SClaire Weinan } 2961fdd26906SClaire Weinan 2962fdd26906SClaire Weinan inline void requestRoutesBMCDumpEntryCollection(App& app) 2963fdd26906SClaire Weinan { 2964fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2965fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2966fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2967fdd26906SClaire Weinan handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); 2968c9bb6861Sraviteja-b } 2969c9bb6861Sraviteja-b 29707e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2971c9bb6861Sraviteja-b { 29727e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 29737e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2974ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2975fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2976fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "BMC")); 2977fdd26906SClaire Weinan 29787e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 29797e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2980ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 2981fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2982fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); 2983c9bb6861Sraviteja-b } 2984c9bb6861Sraviteja-b 29857e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2986c9bb6861Sraviteja-b { 29870fda0f12SGeorge Liu BMCWEB_ROUTE( 29880fda0f12SGeorge Liu app, 29890fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2990ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 29917e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 2992fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, 2993fdd26906SClaire Weinan std::ref(app), "BMC")); 2994a43be80fSAsmitha Karunanithi } 2995a43be80fSAsmitha Karunanithi 29967e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 299780319af1SAsmitha Karunanithi { 29980fda0f12SGeorge Liu BMCWEB_ROUTE( 29990fda0f12SGeorge Liu app, 30000fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog/") 3001ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 3002fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 3003fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); 300445ca1b86SEd Tanous } 3005fdd26906SClaire Weinan 3006fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpService(App& app) 3007fdd26906SClaire Weinan { 3008fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/") 3009fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 3010fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 3011fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); 3012fdd26906SClaire Weinan } 3013fdd26906SClaire Weinan 3014fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntryCollection(App& app) 3015fdd26906SClaire Weinan { 3016fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/") 3017fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 3018fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 3019fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpEntriesCollectionGet, 3020fdd26906SClaire Weinan std::ref(app), "FaultLog")); 3021fdd26906SClaire Weinan } 3022fdd26906SClaire Weinan 3023fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntry(App& app) 3024fdd26906SClaire Weinan { 3025fdd26906SClaire Weinan BMCWEB_ROUTE(app, 3026fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/") 3027fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntry) 3028fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 3029fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); 3030fdd26906SClaire Weinan 3031fdd26906SClaire Weinan BMCWEB_ROUTE(app, 3032fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/") 3033fdd26906SClaire Weinan .privileges(redfish::privileges::deleteLogEntry) 3034fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 3035fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); 3036fdd26906SClaire Weinan } 3037fdd26906SClaire Weinan 3038fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpClear(App& app) 3039fdd26906SClaire Weinan { 3040fdd26906SClaire Weinan BMCWEB_ROUTE( 3041fdd26906SClaire Weinan app, 3042fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Actions/LogService.ClearLog/") 3043fdd26906SClaire Weinan .privileges(redfish::privileges::postLogService) 3044fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 3045fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); 30465cb1dd27SAsmitha Karunanithi } 30475cb1dd27SAsmitha Karunanithi 30487e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 30495cb1dd27SAsmitha Karunanithi { 305022d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/") 3051ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 30526ab9ad54SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 305322d268cbSEd Tanous handleLogServicesDumpServiceComputerSystemGet, std::ref(app))); 30545cb1dd27SAsmitha Karunanithi } 30555cb1dd27SAsmitha Karunanithi 30567e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 30577e860f15SJohn Edward Broadbent { 305822d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/") 3059ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 306022d268cbSEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 306122d268cbSEd Tanous handleLogServicesDumpEntriesCollectionComputerSystemGet, 306222d268cbSEd Tanous std::ref(app))); 30635cb1dd27SAsmitha Karunanithi } 30645cb1dd27SAsmitha Karunanithi 30657e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 30665cb1dd27SAsmitha Karunanithi { 30677e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 306822d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") 3069ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 30706ab9ad54SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 307122d268cbSEd Tanous handleLogServicesDumpEntryComputerSystemGet, std::ref(app))); 30728d1b46d7Szhanghch05 30737e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 307422d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") 3075ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 30766ab9ad54SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 307722d268cbSEd Tanous handleLogServicesDumpEntryComputerSystemDelete, std::ref(app))); 30785cb1dd27SAsmitha Karunanithi } 3079c9bb6861Sraviteja-b 30807e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 3081c9bb6861Sraviteja-b { 30820fda0f12SGeorge Liu BMCWEB_ROUTE( 30830fda0f12SGeorge Liu app, 308422d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 3085ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 308622d268cbSEd Tanous .methods(boost::beast::http::verb::post)(std::bind_front( 308722d268cbSEd Tanous handleLogServicesDumpCollectDiagnosticDataComputerSystemPost, 308822d268cbSEd Tanous std::ref(app))); 3089a43be80fSAsmitha Karunanithi } 3090a43be80fSAsmitha Karunanithi 30917e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 3092a43be80fSAsmitha Karunanithi { 30930fda0f12SGeorge Liu BMCWEB_ROUTE( 30940fda0f12SGeorge Liu app, 309522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/") 3096ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 30976ab9ad54SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 309822d268cbSEd Tanous handleLogServicesDumpClearLogComputerSystemPost, std::ref(app))); 3099013487e5Sraviteja-b } 3100013487e5Sraviteja-b 31017e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 31021da66f75SEd Tanous { 31033946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 31043946028dSAppaRao Puli // method for security reasons. 31051da66f75SEd Tanous /** 31061da66f75SEd Tanous * Functions triggers appropriate requests on DBus 31071da66f75SEd Tanous */ 310822d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/") 3109ed398213SEd Tanous // This is incorrect, should be: 3110ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 3111432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 3112002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3113002d39b4SEd Tanous [&app](const crow::Request& req, 311422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 311522d268cbSEd Tanous const std::string& systemName) { 31163ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 311745ca1b86SEd Tanous { 311845ca1b86SEd Tanous return; 311945ca1b86SEd Tanous } 31207f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 31217f3e84a1SEd Tanous { 31227f3e84a1SEd Tanous // Option currently returns no systems. TBD 31237f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 31247f3e84a1SEd Tanous systemName); 31257f3e84a1SEd Tanous return; 31267f3e84a1SEd Tanous } 312722d268cbSEd Tanous if (systemName != "system") 312822d268cbSEd Tanous { 312922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 313022d268cbSEd Tanous systemName); 313122d268cbSEd Tanous return; 313222d268cbSEd Tanous } 313322d268cbSEd Tanous 31347e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 31357e860f15SJohn Edward Broadbent // SubRoute 31360f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3137424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 3138e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 31398e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 31404f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 31414f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 314215b89725SV-Sanjana asyncResp->res.jsonValue["Id"] = "Crashdump"; 3143e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 3144e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 31457c8c4058STejas Patil 31467c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 31472b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 31487c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 31497c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 31507c8c4058STejas Patil redfishDateTimeOffset.second; 31517c8c4058STejas Patil 31521476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 3153ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 3154002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 31551476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog"; 3156002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 31571476687dSEd Tanous ["target"] = 31581476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData"; 31597e860f15SJohn Edward Broadbent }); 31601da66f75SEd Tanous } 31611da66f75SEd Tanous 31627e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 31635b61b5e8SJason M. Bills { 31640fda0f12SGeorge Liu BMCWEB_ROUTE( 31650fda0f12SGeorge Liu app, 316622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/") 3167ed398213SEd Tanous // This is incorrect, should be: 3168ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3169432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 31707e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 317145ca1b86SEd Tanous [&app](const crow::Request& req, 317222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 317322d268cbSEd Tanous const std::string& systemName) { 31743ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 317545ca1b86SEd Tanous { 317645ca1b86SEd Tanous return; 317745ca1b86SEd Tanous } 31787f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 31797f3e84a1SEd Tanous { 31807f3e84a1SEd Tanous // Option currently returns no systems. TBD 31817f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 31827f3e84a1SEd Tanous systemName); 31837f3e84a1SEd Tanous return; 31847f3e84a1SEd Tanous } 318522d268cbSEd Tanous if (systemName != "system") 318622d268cbSEd Tanous { 318722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 318822d268cbSEd Tanous systemName); 318922d268cbSEd Tanous return; 319022d268cbSEd Tanous } 31915b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 31925e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 3193cb13a392SEd Tanous const std::string&) { 31945b61b5e8SJason M. Bills if (ec) 31955b61b5e8SJason M. Bills { 31965b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 31975b61b5e8SJason M. Bills return; 31985b61b5e8SJason M. Bills } 31995b61b5e8SJason M. Bills messages::success(asyncResp->res); 32005b61b5e8SJason M. Bills }, 3201002d39b4SEd Tanous crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 32027e860f15SJohn Edward Broadbent }); 32035b61b5e8SJason M. Bills } 32045b61b5e8SJason M. Bills 32058d1b46d7Szhanghch05 static void 32068d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 32078d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 3208e855dd28SJason M. Bills { 3209043a0536SJohnathan Mantey auto getStoredLogCallback = 3210b9d36b47SEd Tanous [asyncResp, logID, 32115e7e2dc5SEd Tanous &logEntryJson](const boost::system::error_code& ec, 3212b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& params) { 3213e855dd28SJason M. Bills if (ec) 3214e855dd28SJason M. Bills { 3215e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 32161ddcf01aSJason M. Bills if (ec.value() == 32171ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 32181ddcf01aSJason M. Bills { 3219002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 32201ddcf01aSJason M. Bills } 32211ddcf01aSJason M. Bills else 32221ddcf01aSJason M. Bills { 3223e855dd28SJason M. Bills messages::internalError(asyncResp->res); 32241ddcf01aSJason M. Bills } 3225e855dd28SJason M. Bills return; 3226e855dd28SJason M. Bills } 3227043a0536SJohnathan Mantey 3228043a0536SJohnathan Mantey std::string timestamp{}; 3229043a0536SJohnathan Mantey std::string filename{}; 3230043a0536SJohnathan Mantey std::string logfile{}; 32312c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 3232043a0536SJohnathan Mantey 3233043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 3234e855dd28SJason M. Bills { 32359db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3236e855dd28SJason M. Bills return; 3237e855dd28SJason M. Bills } 3238e855dd28SJason M. Bills 3239043a0536SJohnathan Mantey std::string crashdumpURI = 3240e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 3241043a0536SJohnathan Mantey logID + "/" + filename; 324284afc48bSJason M. Bills nlohmann::json::object_t logEntry; 32439c11a172SVijay Lobo logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 3244ef4c65b7SEd Tanous logEntry["@odata.id"] = boost::urls::format( 3245ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/{}", 3246ef4c65b7SEd Tanous logID); 324784afc48bSJason M. Bills logEntry["Name"] = "CPU Crashdump"; 324884afc48bSJason M. Bills logEntry["Id"] = logID; 324984afc48bSJason M. Bills logEntry["EntryType"] = "Oem"; 325084afc48bSJason M. Bills logEntry["AdditionalDataURI"] = std::move(crashdumpURI); 325184afc48bSJason M. Bills logEntry["DiagnosticDataType"] = "OEM"; 325284afc48bSJason M. Bills logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; 325384afc48bSJason M. Bills logEntry["Created"] = std::move(timestamp); 32542b20ef6eSJason M. Bills 32552b20ef6eSJason M. Bills // If logEntryJson references an array of LogEntry resources 32562b20ef6eSJason M. Bills // ('Members' list), then push this as a new entry, otherwise set it 32572b20ef6eSJason M. Bills // directly 32582b20ef6eSJason M. Bills if (logEntryJson.is_array()) 32592b20ef6eSJason M. Bills { 32602b20ef6eSJason M. Bills logEntryJson.push_back(logEntry); 32612b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 32622b20ef6eSJason M. Bills logEntryJson.size(); 32632b20ef6eSJason M. Bills } 32642b20ef6eSJason M. Bills else 32652b20ef6eSJason M. Bills { 3266d405bb51SJason M. Bills logEntryJson.update(logEntry); 32672b20ef6eSJason M. Bills } 3268e855dd28SJason M. Bills }; 3269d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3270d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, crashdumpObject, 3271d1bde9e5SKrzysztof Grobelny crashdumpPath + std::string("/") + logID, crashdumpInterface, 3272d1bde9e5SKrzysztof Grobelny std::move(getStoredLogCallback)); 3273e855dd28SJason M. Bills } 3274e855dd28SJason M. Bills 32757e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 32761da66f75SEd Tanous { 32773946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 32783946028dSAppaRao Puli // method for security reasons. 32791da66f75SEd Tanous /** 32801da66f75SEd Tanous * Functions triggers appropriate requests on DBus 32811da66f75SEd Tanous */ 32827e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 328322d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/") 3284ed398213SEd Tanous // This is incorrect, should be. 3285ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 3286432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3287002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3288002d39b4SEd Tanous [&app](const crow::Request& req, 328922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 329022d268cbSEd Tanous const std::string& systemName) { 32913ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 329245ca1b86SEd Tanous { 329345ca1b86SEd Tanous return; 329445ca1b86SEd Tanous } 32957f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 32967f3e84a1SEd Tanous { 32977f3e84a1SEd Tanous // Option currently returns no systems. TBD 32987f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 32997f3e84a1SEd Tanous systemName); 33007f3e84a1SEd Tanous return; 33017f3e84a1SEd Tanous } 330222d268cbSEd Tanous if (systemName != "system") 330322d268cbSEd Tanous { 330422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 330522d268cbSEd Tanous systemName); 330622d268cbSEd Tanous return; 330722d268cbSEd Tanous } 330822d268cbSEd Tanous 33097a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 33107a1dbc48SGeorge Liu crashdumpInterface}; 33117a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 33127a1dbc48SGeorge Liu "/", 0, interfaces, 33137a1dbc48SGeorge Liu [asyncResp](const boost::system::error_code& ec, 33142b20ef6eSJason M. Bills const std::vector<std::string>& resp) { 33151da66f75SEd Tanous if (ec) 33161da66f75SEd Tanous { 33171da66f75SEd Tanous if (ec.value() != 33181da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 33191da66f75SEd Tanous { 33201da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 33211da66f75SEd Tanous << ec.message(); 3322f12894f8SJason M. Bills messages::internalError(asyncResp->res); 33231da66f75SEd Tanous return; 33241da66f75SEd Tanous } 33251da66f75SEd Tanous } 3326e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 33271da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 33280f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3329424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 3330002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 3331e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 3332424c4176SJason M. Bills "Collection of Crashdump Entries"; 3333002d39b4SEd Tanous asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3334a2dd60a6SBrandon Kim asyncResp->res.jsonValue["Members@odata.count"] = 0; 33352b20ef6eSJason M. Bills 33362b20ef6eSJason M. Bills for (const std::string& path : resp) 33371da66f75SEd Tanous { 33382b20ef6eSJason M. Bills const sdbusplus::message::object_path objPath(path); 3339e855dd28SJason M. Bills // Get the log ID 33402b20ef6eSJason M. Bills std::string logID = objPath.filename(); 33412b20ef6eSJason M. Bills if (logID.empty()) 33421da66f75SEd Tanous { 3343e855dd28SJason M. Bills continue; 33441da66f75SEd Tanous } 3345e855dd28SJason M. Bills // Add the log entry to the array 33462b20ef6eSJason M. Bills logCrashdumpEntry(asyncResp, logID, 33472b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"]); 33481da66f75SEd Tanous } 33497a1dbc48SGeorge Liu }); 33507e860f15SJohn Edward Broadbent }); 33511da66f75SEd Tanous } 33521da66f75SEd Tanous 33537e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 33541da66f75SEd Tanous { 33553946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 33563946028dSAppaRao Puli // method for security reasons. 33571da66f75SEd Tanous 33587e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 335922d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/") 3360ed398213SEd Tanous // this is incorrect, should be 3361ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 3362432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 33637e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 336445ca1b86SEd Tanous [&app](const crow::Request& req, 33657e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 336622d268cbSEd Tanous const std::string& systemName, const std::string& param) { 33673ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 336845ca1b86SEd Tanous { 336945ca1b86SEd Tanous return; 337045ca1b86SEd Tanous } 33717f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 33727f3e84a1SEd Tanous { 33737f3e84a1SEd Tanous // Option currently returns no systems. TBD 33747f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 33757f3e84a1SEd Tanous systemName); 33767f3e84a1SEd Tanous return; 33777f3e84a1SEd Tanous } 337822d268cbSEd Tanous if (systemName != "system") 337922d268cbSEd Tanous { 338022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 338122d268cbSEd Tanous systemName); 338222d268cbSEd Tanous return; 338322d268cbSEd Tanous } 33847e860f15SJohn Edward Broadbent const std::string& logID = param; 3385e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 33867e860f15SJohn Edward Broadbent }); 3387e855dd28SJason M. Bills } 3388e855dd28SJason M. Bills 33897e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 3390e855dd28SJason M. Bills { 33913946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 33923946028dSAppaRao Puli // method for security reasons. 33937e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 33947e860f15SJohn Edward Broadbent app, 339522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/") 3396ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 33977e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 3398a4ce114aSNan Zhou [](const crow::Request& req, 33997e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 340022d268cbSEd Tanous const std::string& systemName, const std::string& logID, 340122d268cbSEd Tanous const std::string& fileName) { 34022a9beeedSShounak Mitra // Do not call getRedfishRoute here since the crashdump file is not a 34032a9beeedSShounak Mitra // Redfish resource. 340422d268cbSEd Tanous 34057f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 34067f3e84a1SEd Tanous { 34077f3e84a1SEd Tanous // Option currently returns no systems. TBD 34087f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 34097f3e84a1SEd Tanous systemName); 34107f3e84a1SEd Tanous return; 34117f3e84a1SEd Tanous } 341222d268cbSEd Tanous if (systemName != "system") 341322d268cbSEd Tanous { 341422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 341522d268cbSEd Tanous systemName); 341622d268cbSEd Tanous return; 341722d268cbSEd Tanous } 341822d268cbSEd Tanous 3419043a0536SJohnathan Mantey auto getStoredLogCallback = 342039662a3bSEd Tanous [asyncResp, logID, fileName, url(boost::urls::url(req.url()))]( 34215e7e2dc5SEd Tanous const boost::system::error_code& ec, 3422002d39b4SEd Tanous const std::vector< 3423002d39b4SEd Tanous std::pair<std::string, dbus::utility::DbusVariantType>>& 34247e860f15SJohn Edward Broadbent resp) { 34251da66f75SEd Tanous if (ec) 34261da66f75SEd Tanous { 3427002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 3428f12894f8SJason M. Bills messages::internalError(asyncResp->res); 34291da66f75SEd Tanous return; 34301da66f75SEd Tanous } 3431e855dd28SJason M. Bills 3432043a0536SJohnathan Mantey std::string dbusFilename{}; 3433043a0536SJohnathan Mantey std::string dbusTimestamp{}; 3434043a0536SJohnathan Mantey std::string dbusFilepath{}; 3435043a0536SJohnathan Mantey 3436002d39b4SEd Tanous parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 3437002d39b4SEd Tanous dbusFilepath); 3438043a0536SJohnathan Mantey 3439043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 3440043a0536SJohnathan Mantey dbusFilepath.empty()) 34411da66f75SEd Tanous { 34429db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 34431da66f75SEd Tanous return; 34441da66f75SEd Tanous } 3445e855dd28SJason M. Bills 3446043a0536SJohnathan Mantey // Verify the file name parameter is correct 3447043a0536SJohnathan Mantey if (fileName != dbusFilename) 3448043a0536SJohnathan Mantey { 34499db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3450043a0536SJohnathan Mantey return; 3451043a0536SJohnathan Mantey } 3452043a0536SJohnathan Mantey 3453043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 3454043a0536SJohnathan Mantey { 34559db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3456043a0536SJohnathan Mantey return; 3457043a0536SJohnathan Mantey } 3458002d39b4SEd Tanous std::ifstream ifs(dbusFilepath, std::ios::in | std::ios::binary); 3459002d39b4SEd Tanous asyncResp->res.body() = 3460002d39b4SEd Tanous std::string(std::istreambuf_iterator<char>{ifs}, {}); 3461043a0536SJohnathan Mantey 34627e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 34637e860f15SJohn Edward Broadbent // from a browser 3464d9f6c621SEd Tanous asyncResp->res.addHeader( 3465d9f6c621SEd Tanous boost::beast::http::field::content_disposition, "attachment"); 34661da66f75SEd Tanous }; 3467d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3468d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, crashdumpObject, 3469d1bde9e5SKrzysztof Grobelny crashdumpPath + std::string("/") + logID, crashdumpInterface, 3470d1bde9e5SKrzysztof Grobelny std::move(getStoredLogCallback)); 34717e860f15SJohn Edward Broadbent }); 34721da66f75SEd Tanous } 34731da66f75SEd Tanous 3474c5a4c82aSJason M. Bills enum class OEMDiagnosticType 3475c5a4c82aSJason M. Bills { 3476c5a4c82aSJason M. Bills onDemand, 3477c5a4c82aSJason M. Bills telemetry, 3478c5a4c82aSJason M. Bills invalid, 3479c5a4c82aSJason M. Bills }; 3480c5a4c82aSJason M. Bills 348126ccae32SEd Tanous inline OEMDiagnosticType getOEMDiagnosticType(std::string_view oemDiagStr) 3482c5a4c82aSJason M. Bills { 3483c5a4c82aSJason M. Bills if (oemDiagStr == "OnDemand") 3484c5a4c82aSJason M. Bills { 3485c5a4c82aSJason M. Bills return OEMDiagnosticType::onDemand; 3486c5a4c82aSJason M. Bills } 3487c5a4c82aSJason M. Bills if (oemDiagStr == "Telemetry") 3488c5a4c82aSJason M. Bills { 3489c5a4c82aSJason M. Bills return OEMDiagnosticType::telemetry; 3490c5a4c82aSJason M. Bills } 3491c5a4c82aSJason M. Bills 3492c5a4c82aSJason M. Bills return OEMDiagnosticType::invalid; 3493c5a4c82aSJason M. Bills } 3494c5a4c82aSJason M. Bills 34957e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 34961da66f75SEd Tanous { 34973946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 34983946028dSAppaRao Puli // method for security reasons. 34990fda0f12SGeorge Liu BMCWEB_ROUTE( 35000fda0f12SGeorge Liu app, 350122d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") 3502ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 3503ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3504432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3505002d39b4SEd Tanous .methods(boost::beast::http::verb::post)( 3506002d39b4SEd Tanous [&app](const crow::Request& req, 350722d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 350822d268cbSEd Tanous const std::string& systemName) { 35093ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 351045ca1b86SEd Tanous { 351145ca1b86SEd Tanous return; 351245ca1b86SEd Tanous } 351322d268cbSEd Tanous 35147f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 35157f3e84a1SEd Tanous { 35167f3e84a1SEd Tanous // Option currently returns no systems. TBD 35177f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 35187f3e84a1SEd Tanous systemName); 35197f3e84a1SEd Tanous return; 35207f3e84a1SEd Tanous } 352122d268cbSEd Tanous if (systemName != "system") 352222d268cbSEd Tanous { 352322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 352422d268cbSEd Tanous systemName); 352522d268cbSEd Tanous return; 352622d268cbSEd Tanous } 352722d268cbSEd Tanous 35288e6c099aSJason M. Bills std::string diagnosticDataType; 35298e6c099aSJason M. Bills std::string oemDiagnosticDataType; 353015ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 3531002d39b4SEd Tanous req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 3532002d39b4SEd Tanous "OEMDiagnosticDataType", oemDiagnosticDataType)) 35338e6c099aSJason M. Bills { 35348e6c099aSJason M. Bills return; 35358e6c099aSJason M. Bills } 35368e6c099aSJason M. Bills 35378e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 35388e6c099aSJason M. Bills { 35398e6c099aSJason M. Bills BMCWEB_LOG_ERROR 35408e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 35418e6c099aSJason M. Bills messages::actionParameterValueFormatError( 35428e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 35438e6c099aSJason M. Bills "CollectDiagnosticData"); 35448e6c099aSJason M. Bills return; 35458e6c099aSJason M. Bills } 35468e6c099aSJason M. Bills 3547c5a4c82aSJason M. Bills OEMDiagnosticType oemDiagType = 3548c5a4c82aSJason M. Bills getOEMDiagnosticType(oemDiagnosticDataType); 3549c5a4c82aSJason M. Bills 3550c5a4c82aSJason M. Bills std::string iface; 3551c5a4c82aSJason M. Bills std::string method; 3552c5a4c82aSJason M. Bills std::string taskMatchStr; 3553c5a4c82aSJason M. Bills if (oemDiagType == OEMDiagnosticType::onDemand) 3554c5a4c82aSJason M. Bills { 3555c5a4c82aSJason M. Bills iface = crashdumpOnDemandInterface; 3556c5a4c82aSJason M. Bills method = "GenerateOnDemandLog"; 3557c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3558c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3559c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3560c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3561c5a4c82aSJason M. Bills } 3562c5a4c82aSJason M. Bills else if (oemDiagType == OEMDiagnosticType::telemetry) 3563c5a4c82aSJason M. Bills { 3564c5a4c82aSJason M. Bills iface = crashdumpTelemetryInterface; 3565c5a4c82aSJason M. Bills method = "GenerateTelemetryLog"; 3566c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3567c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3568c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3569c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3570c5a4c82aSJason M. Bills } 3571c5a4c82aSJason M. Bills else 3572c5a4c82aSJason M. Bills { 3573c5a4c82aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 3574c5a4c82aSJason M. Bills << oemDiagnosticDataType; 3575c5a4c82aSJason M. Bills messages::actionParameterValueFormatError( 3576002d39b4SEd Tanous asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType", 3577002d39b4SEd Tanous "CollectDiagnosticData"); 3578c5a4c82aSJason M. Bills return; 3579c5a4c82aSJason M. Bills } 3580c5a4c82aSJason M. Bills 3581c5a4c82aSJason M. Bills auto collectCrashdumpCallback = 3582c5a4c82aSJason M. Bills [asyncResp, payload(task::Payload(req)), 35835e7e2dc5SEd Tanous taskMatchStr](const boost::system::error_code& ec, 358498be3e39SEd Tanous const std::string&) mutable { 35851da66f75SEd Tanous if (ec) 35861da66f75SEd Tanous { 3587002d39b4SEd Tanous if (ec.value() == boost::system::errc::operation_not_supported) 35881da66f75SEd Tanous { 3589f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 35901da66f75SEd Tanous } 35914363d3b2SJason M. Bills else if (ec.value() == 35924363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 35934363d3b2SJason M. Bills { 3594002d39b4SEd Tanous messages::serviceTemporarilyUnavailable(asyncResp->res, 3595002d39b4SEd Tanous "60"); 35964363d3b2SJason M. Bills } 35971da66f75SEd Tanous else 35981da66f75SEd Tanous { 3599f12894f8SJason M. Bills messages::internalError(asyncResp->res); 36001da66f75SEd Tanous } 36011da66f75SEd Tanous return; 36021da66f75SEd Tanous } 3603002d39b4SEd Tanous std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 36048b24275dSEd Tanous [](const boost::system::error_code& ec2, sdbusplus::message_t&, 3605002d39b4SEd Tanous const std::shared_ptr<task::TaskData>& taskData) { 36068b24275dSEd Tanous if (!ec2) 360766afe4faSJames Feist { 3608002d39b4SEd Tanous taskData->messages.emplace_back(messages::taskCompletedOK( 3609e5d5006bSJames Feist std::to_string(taskData->index))); 3610831d6b09SJames Feist taskData->state = "Completed"; 361166afe4faSJames Feist } 361232898ceaSJames Feist return task::completed; 361366afe4faSJames Feist }, 3614c5a4c82aSJason M. Bills taskMatchStr); 3615c5a4c82aSJason M. Bills 361646229577SJames Feist task->startTimer(std::chrono::minutes(5)); 361746229577SJames Feist task->populateResp(asyncResp->res); 361898be3e39SEd Tanous task->payload.emplace(std::move(payload)); 36191da66f75SEd Tanous }; 36208e6c099aSJason M. Bills 36211da66f75SEd Tanous crow::connections::systemBus->async_method_call( 3622002d39b4SEd Tanous std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath, 3623002d39b4SEd Tanous iface, method); 36247e860f15SJohn Edward Broadbent }); 36256eda7685SKenny L. Ku } 36266eda7685SKenny L. Ku 3627cb92c03bSAndrew Geissler /** 3628cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 3629cb92c03bSAndrew Geissler */ 36307e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 3631cb92c03bSAndrew Geissler { 3632cb92c03bSAndrew Geissler /** 3633cb92c03bSAndrew Geissler * Function handles POST method request. 3634cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3635cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3636cb92c03bSAndrew Geissler */ 36377e860f15SJohn Edward Broadbent 36380fda0f12SGeorge Liu BMCWEB_ROUTE( 36390fda0f12SGeorge Liu app, 364022d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 3641ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 36427e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 364345ca1b86SEd Tanous [&app](const crow::Request& req, 364422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 364522d268cbSEd Tanous const std::string& systemName) { 36463ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 364745ca1b86SEd Tanous { 364845ca1b86SEd Tanous return; 364945ca1b86SEd Tanous } 36507f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 36517f3e84a1SEd Tanous { 36527f3e84a1SEd Tanous // Option currently returns no systems. TBD 36537f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 36547f3e84a1SEd Tanous systemName); 36557f3e84a1SEd Tanous return; 36567f3e84a1SEd Tanous } 365722d268cbSEd Tanous if (systemName != "system") 365822d268cbSEd Tanous { 365922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 366022d268cbSEd Tanous systemName); 366122d268cbSEd Tanous return; 366222d268cbSEd Tanous } 3663cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 3664cb92c03bSAndrew Geissler 3665cb92c03bSAndrew Geissler // Process response from Logging service. 36665e7e2dc5SEd Tanous auto respHandler = [asyncResp](const boost::system::error_code& ec) { 3667002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 3668cb92c03bSAndrew Geissler if (ec) 3669cb92c03bSAndrew Geissler { 3670cb92c03bSAndrew Geissler // TODO Handle for specific error code 3671002d39b4SEd Tanous BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 3672cb92c03bSAndrew Geissler asyncResp->res.result( 3673cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3674cb92c03bSAndrew Geissler return; 3675cb92c03bSAndrew Geissler } 3676cb92c03bSAndrew Geissler 3677002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content); 3678cb92c03bSAndrew Geissler }; 3679cb92c03bSAndrew Geissler 3680cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3681cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 36822c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 3683cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3684cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 36857e860f15SJohn Edward Broadbent }); 3686cb92c03bSAndrew Geissler } 3687a3316fc6SZhikuiRen 3688a3316fc6SZhikuiRen /**************************************************** 3689a3316fc6SZhikuiRen * Redfish PostCode interfaces 3690a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3691a3316fc6SZhikuiRen ******************************************************/ 36927e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 3693a3316fc6SZhikuiRen { 369422d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/") 3695ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 3696002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3697002d39b4SEd Tanous [&app](const crow::Request& req, 369822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 369922d268cbSEd Tanous const std::string& systemName) { 37003ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 370145ca1b86SEd Tanous { 370245ca1b86SEd Tanous return; 370345ca1b86SEd Tanous } 37047f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 37057f3e84a1SEd Tanous { 37067f3e84a1SEd Tanous // Option currently returns no systems. TBD 37077f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 37087f3e84a1SEd Tanous systemName); 37097f3e84a1SEd Tanous return; 37107f3e84a1SEd Tanous } 371122d268cbSEd Tanous if (systemName != "system") 371222d268cbSEd Tanous { 371322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 371422d268cbSEd Tanous systemName); 371522d268cbSEd Tanous return; 371622d268cbSEd Tanous } 37171476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 37181476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes"; 37191476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 37201476687dSEd Tanous "#LogService.v1_1_0.LogService"; 37211476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "POST Code Log Service"; 37221476687dSEd Tanous asyncResp->res.jsonValue["Description"] = "POST Code Log Service"; 3723ed34a4adSEd Tanous asyncResp->res.jsonValue["Id"] = "PostCodes"; 37241476687dSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 37251476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 37261476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 37277c8c4058STejas Patil 37287c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 37292b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 37300fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 37317c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 37327c8c4058STejas Patil redfishDateTimeOffset.second; 37337c8c4058STejas Patil 3734a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 37357e860f15SJohn Edward Broadbent {"target", 37360fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog"}}; 37377e860f15SJohn Edward Broadbent }); 3738a3316fc6SZhikuiRen } 3739a3316fc6SZhikuiRen 37407e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3741a3316fc6SZhikuiRen { 37420fda0f12SGeorge Liu BMCWEB_ROUTE( 37430fda0f12SGeorge Liu app, 374422d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/") 3745ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3746ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3747432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 37487e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 374945ca1b86SEd Tanous [&app](const crow::Request& req, 375022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 375122d268cbSEd Tanous const std::string& systemName) { 37523ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 375345ca1b86SEd Tanous { 375445ca1b86SEd Tanous return; 375545ca1b86SEd Tanous } 37567f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 37577f3e84a1SEd Tanous { 37587f3e84a1SEd Tanous // Option currently returns no systems. TBD 37597f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 37607f3e84a1SEd Tanous systemName); 37617f3e84a1SEd Tanous return; 37627f3e84a1SEd Tanous } 376322d268cbSEd Tanous if (systemName != "system") 376422d268cbSEd Tanous { 376522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 376622d268cbSEd Tanous systemName); 376722d268cbSEd Tanous return; 376822d268cbSEd Tanous } 3769a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3770a3316fc6SZhikuiRen 3771a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3772a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 37735e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 3774a3316fc6SZhikuiRen if (ec) 3775a3316fc6SZhikuiRen { 3776a3316fc6SZhikuiRen // TODO Handle for specific error code 3777002d39b4SEd Tanous BMCWEB_LOG_ERROR << "doClearPostCodes resp_handler got error " 37787e860f15SJohn Edward Broadbent << ec; 3779002d39b4SEd Tanous asyncResp->res.result( 3780002d39b4SEd Tanous boost::beast::http::status::internal_server_error); 3781a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3782a3316fc6SZhikuiRen return; 3783a3316fc6SZhikuiRen } 3784a3316fc6SZhikuiRen }, 378515124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 378615124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3787a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 37887e860f15SJohn Edward Broadbent }); 3789a3316fc6SZhikuiRen } 3790a3316fc6SZhikuiRen 37916f284d24SJiaqing Zhao /** 37926f284d24SJiaqing Zhao * @brief Parse post code ID and get the current value and index value 37936f284d24SJiaqing Zhao * eg: postCodeID=B1-2, currentValue=1, index=2 37946f284d24SJiaqing Zhao * 37956f284d24SJiaqing Zhao * @param[in] postCodeID Post Code ID 37966f284d24SJiaqing Zhao * @param[out] currentValue Current value 37976f284d24SJiaqing Zhao * @param[out] index Index value 37986f284d24SJiaqing Zhao * 37996f284d24SJiaqing Zhao * @return bool true if the parsing is successful, false the parsing fails 38006f284d24SJiaqing Zhao */ 38016f284d24SJiaqing Zhao inline static bool parsePostCode(const std::string& postCodeID, 38026f284d24SJiaqing Zhao uint64_t& currentValue, uint16_t& index) 38036f284d24SJiaqing Zhao { 38046f284d24SJiaqing Zhao std::vector<std::string> split; 380550ebd4afSEd Tanous bmcweb::split(split, postCodeID, '-'); 38066f284d24SJiaqing Zhao if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B') 38076f284d24SJiaqing Zhao { 38086f284d24SJiaqing Zhao return false; 38096f284d24SJiaqing Zhao } 38106f284d24SJiaqing Zhao 381184396af9SPatrick Williams auto start = std::next(split[0].begin()); 381284396af9SPatrick Williams auto end = split[0].end(); 381384396af9SPatrick Williams auto [ptrIndex, ecIndex] = std::from_chars(&*start, &*end, index); 38146f284d24SJiaqing Zhao 381584396af9SPatrick Williams if (ptrIndex != &*end || ecIndex != std::errc()) 38166f284d24SJiaqing Zhao { 38176f284d24SJiaqing Zhao return false; 38186f284d24SJiaqing Zhao } 38196f284d24SJiaqing Zhao 382084396af9SPatrick Williams start = split[1].begin(); 382184396af9SPatrick Williams end = split[1].end(); 38226f284d24SJiaqing Zhao 382384396af9SPatrick Williams auto [ptrValue, ecValue] = std::from_chars(&*start, &*end, currentValue); 38246f284d24SJiaqing Zhao 382584396af9SPatrick Williams return ptrValue == &*end && ecValue == std::errc(); 38266f284d24SJiaqing Zhao } 38276f284d24SJiaqing Zhao 38286f284d24SJiaqing Zhao static bool fillPostCodeEntry( 3829ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 38306c9a279eSManojkiran Eda const boost::container::flat_map< 38316c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3832a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3833a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3834a3316fc6SZhikuiRen { 3835a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3836fffb8c1fSEd Tanous const registries::Message* message = 3837fffb8c1fSEd Tanous registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3838a3316fc6SZhikuiRen 3839a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3840a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 38416c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 38426c9a279eSManojkiran Eda code : postcode) 3843a3316fc6SZhikuiRen { 3844a3316fc6SZhikuiRen currentCodeIndex++; 3845a3316fc6SZhikuiRen std::string postcodeEntryID = 3846a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3847a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3848a3316fc6SZhikuiRen 3849a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3850a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3851a3316fc6SZhikuiRen 3852a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3853a3316fc6SZhikuiRen { // already incremented 3854a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3855a3316fc6SZhikuiRen } 3856a3316fc6SZhikuiRen else 3857a3316fc6SZhikuiRen { 3858a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3859a3316fc6SZhikuiRen } 3860a3316fc6SZhikuiRen 3861a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3862a3316fc6SZhikuiRen // not fall between top and skip 3863a3316fc6SZhikuiRen if ((codeIndex == 0) && 3864a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3865a3316fc6SZhikuiRen { 3866a3316fc6SZhikuiRen continue; 3867a3316fc6SZhikuiRen } 3868a3316fc6SZhikuiRen 38694e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3870a3316fc6SZhikuiRen // currentIndex 3871a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3872a3316fc6SZhikuiRen { 3873a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3874a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3875a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3876a3316fc6SZhikuiRen continue; 3877a3316fc6SZhikuiRen } 3878a3316fc6SZhikuiRen 3879a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3880a3316fc6SZhikuiRen // index 3881a3316fc6SZhikuiRen 3882a3316fc6SZhikuiRen // Get the Created time from the timestamp 3883a3316fc6SZhikuiRen std::string entryTimeStr; 38842a025611SKonstantin Aladyshev entryTimeStr = redfish::time_utils::getDateTimeUintUs(usecSinceEpoch); 3885a3316fc6SZhikuiRen 3886a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3887a3316fc6SZhikuiRen std::ostringstream hexCode; 3888a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 38896c9a279eSManojkiran Eda << std::get<0>(code.second); 3890a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3891a3316fc6SZhikuiRen // Set Fixed -Point Notation 3892a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3893a3316fc6SZhikuiRen // Set precision to 4 digits 3894a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3895a3316fc6SZhikuiRen // Add double to stream 3896a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3897a3316fc6SZhikuiRen 38981e6deaf6SEd Tanous std::string bootIndexStr = std::to_string(bootIndex); 38991e6deaf6SEd Tanous std::string timeOffsetString = timeOffsetStr.str(); 39001e6deaf6SEd Tanous std::string hexCodeStr = hexCode.str(); 3901a3316fc6SZhikuiRen 39021e6deaf6SEd Tanous std::array<std::string_view, 3> messageArgs = { 39031e6deaf6SEd Tanous bootIndexStr, timeOffsetString, hexCodeStr}; 39041e6deaf6SEd Tanous 39051e6deaf6SEd Tanous std::string msg = 39061e6deaf6SEd Tanous redfish::registries::fillMessageArgs(messageArgs, message->message); 39071e6deaf6SEd Tanous if (msg.empty()) 3908a3316fc6SZhikuiRen { 39091e6deaf6SEd Tanous messages::internalError(asyncResp->res); 39101e6deaf6SEd Tanous return false; 3911a3316fc6SZhikuiRen } 3912a3316fc6SZhikuiRen 3913d4342a92STim Lee // Get Severity template from message registry 3914d4342a92STim Lee std::string severity; 3915d4342a92STim Lee if (message != nullptr) 3916d4342a92STim Lee { 39175f2b84eeSEd Tanous severity = message->messageSeverity; 3918d4342a92STim Lee } 3919d4342a92STim Lee 39206f284d24SJiaqing Zhao // Format entry 39216f284d24SJiaqing Zhao nlohmann::json::object_t bmcLogEntry; 39229c11a172SVijay Lobo bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 3923ef4c65b7SEd Tanous bmcLogEntry["@odata.id"] = boost::urls::format( 3924ef4c65b7SEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/{}", 3925ef4c65b7SEd Tanous postcodeEntryID); 392684afc48bSJason M. Bills bmcLogEntry["Name"] = "POST Code Log Entry"; 392784afc48bSJason M. Bills bmcLogEntry["Id"] = postcodeEntryID; 392884afc48bSJason M. Bills bmcLogEntry["Message"] = std::move(msg); 392984afc48bSJason M. Bills bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode"; 39301e6deaf6SEd Tanous bmcLogEntry["MessageArgs"] = messageArgs; 393184afc48bSJason M. Bills bmcLogEntry["EntryType"] = "Event"; 393284afc48bSJason M. Bills bmcLogEntry["Severity"] = std::move(severity); 393384afc48bSJason M. Bills bmcLogEntry["Created"] = entryTimeStr; 3934647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 3935647b3cdcSGeorge Liu { 3936647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 3937647b3cdcSGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3938647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 3939647b3cdcSGeorge Liu } 39406f284d24SJiaqing Zhao 39416f284d24SJiaqing Zhao // codeIndex is only specified when querying single entry, return only 39426f284d24SJiaqing Zhao // that entry in this case 39436f284d24SJiaqing Zhao if (codeIndex != 0) 39446f284d24SJiaqing Zhao { 3945ac106bf6SEd Tanous asyncResp->res.jsonValue.update(bmcLogEntry); 39466f284d24SJiaqing Zhao return true; 3947a3316fc6SZhikuiRen } 39486f284d24SJiaqing Zhao 3949ac106bf6SEd Tanous nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 3950b2ba3072SPatrick Williams logEntryArray.emplace_back(std::move(bmcLogEntry)); 39516f284d24SJiaqing Zhao } 39526f284d24SJiaqing Zhao 39536f284d24SJiaqing Zhao // Return value is always false when querying multiple entries 39546f284d24SJiaqing Zhao return false; 3955a3316fc6SZhikuiRen } 3956a3316fc6SZhikuiRen 3957ac106bf6SEd Tanous static void 3958ac106bf6SEd Tanous getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 39596f284d24SJiaqing Zhao const std::string& entryId) 3960a3316fc6SZhikuiRen { 39616f284d24SJiaqing Zhao uint16_t bootIndex = 0; 39626f284d24SJiaqing Zhao uint64_t codeIndex = 0; 39636f284d24SJiaqing Zhao if (!parsePostCode(entryId, codeIndex, bootIndex)) 39646f284d24SJiaqing Zhao { 39656f284d24SJiaqing Zhao // Requested ID was not found 3966ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 39676f284d24SJiaqing Zhao return; 39686f284d24SJiaqing Zhao } 39696f284d24SJiaqing Zhao 39706f284d24SJiaqing Zhao if (bootIndex == 0 || codeIndex == 0) 39716f284d24SJiaqing Zhao { 39726f284d24SJiaqing Zhao // 0 is an invalid index 3973ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 39746f284d24SJiaqing Zhao return; 39756f284d24SJiaqing Zhao } 39766f284d24SJiaqing Zhao 3977a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3978ac106bf6SEd Tanous [asyncResp, entryId, bootIndex, 39795e7e2dc5SEd Tanous codeIndex](const boost::system::error_code& ec, 39806c9a279eSManojkiran Eda const boost::container::flat_map< 39816c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 39826c9a279eSManojkiran Eda postcode) { 3983a3316fc6SZhikuiRen if (ec) 3984a3316fc6SZhikuiRen { 3985a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3986ac106bf6SEd Tanous messages::internalError(asyncResp->res); 3987a3316fc6SZhikuiRen return; 3988a3316fc6SZhikuiRen } 3989a3316fc6SZhikuiRen 3990a3316fc6SZhikuiRen if (postcode.empty()) 3991a3316fc6SZhikuiRen { 3992ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 3993a3316fc6SZhikuiRen return; 3994a3316fc6SZhikuiRen } 3995a3316fc6SZhikuiRen 3996ac106bf6SEd Tanous if (!fillPostCodeEntry(asyncResp, postcode, bootIndex, codeIndex)) 39976f284d24SJiaqing Zhao { 3998ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", entryId); 39996f284d24SJiaqing Zhao return; 40006f284d24SJiaqing Zhao } 4001a3316fc6SZhikuiRen }, 400215124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 400315124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 4004a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 4005a3316fc6SZhikuiRen bootIndex); 4006a3316fc6SZhikuiRen } 4007a3316fc6SZhikuiRen 4008ac106bf6SEd Tanous static void 4009ac106bf6SEd Tanous getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4010ac106bf6SEd Tanous const uint16_t bootIndex, const uint16_t bootCount, 4011ac106bf6SEd Tanous const uint64_t entryCount, size_t skip, size_t top) 4012a3316fc6SZhikuiRen { 4013a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 4014ac106bf6SEd Tanous [asyncResp, bootIndex, bootCount, entryCount, skip, 40155e7e2dc5SEd Tanous top](const boost::system::error_code& ec, 40166c9a279eSManojkiran Eda const boost::container::flat_map< 40176c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 40186c9a279eSManojkiran Eda postcode) { 4019a3316fc6SZhikuiRen if (ec) 4020a3316fc6SZhikuiRen { 4021a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 4022ac106bf6SEd Tanous messages::internalError(asyncResp->res); 4023a3316fc6SZhikuiRen return; 4024a3316fc6SZhikuiRen } 4025a3316fc6SZhikuiRen 4026a3316fc6SZhikuiRen uint64_t endCount = entryCount; 4027a3316fc6SZhikuiRen if (!postcode.empty()) 4028a3316fc6SZhikuiRen { 4029a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 40303648c8beSEd Tanous if (skip < endCount && (top + skip) > entryCount) 4031a3316fc6SZhikuiRen { 403289492a15SPatrick Williams uint64_t thisBootSkip = std::max(static_cast<uint64_t>(skip), 403389492a15SPatrick Williams entryCount) - 40343648c8beSEd Tanous entryCount; 4035a3316fc6SZhikuiRen uint64_t thisBootTop = 40363648c8beSEd Tanous std::min(static_cast<uint64_t>(top + skip), endCount) - 40373648c8beSEd Tanous entryCount; 4038a3316fc6SZhikuiRen 4039ac106bf6SEd Tanous fillPostCodeEntry(asyncResp, postcode, bootIndex, 0, 4040ac106bf6SEd Tanous thisBootSkip, thisBootTop); 4041a3316fc6SZhikuiRen } 4042ac106bf6SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = endCount; 4043a3316fc6SZhikuiRen } 4044a3316fc6SZhikuiRen 4045a3316fc6SZhikuiRen // continue to previous bootIndex 4046a3316fc6SZhikuiRen if (bootIndex < bootCount) 4047a3316fc6SZhikuiRen { 4048ac106bf6SEd Tanous getPostCodeForBoot(asyncResp, static_cast<uint16_t>(bootIndex + 1), 4049a3316fc6SZhikuiRen bootCount, endCount, skip, top); 4050a3316fc6SZhikuiRen } 405181584abeSJiaqing Zhao else if (skip + top < endCount) 4052a3316fc6SZhikuiRen { 4053ac106bf6SEd Tanous asyncResp->res.jsonValue["Members@odata.nextLink"] = 40540fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries?$skip=" + 4055a3316fc6SZhikuiRen std::to_string(skip + top); 4056a3316fc6SZhikuiRen } 4057a3316fc6SZhikuiRen }, 405815124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 405915124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 4060a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 4061a3316fc6SZhikuiRen bootIndex); 4062a3316fc6SZhikuiRen } 4063a3316fc6SZhikuiRen 40648d1b46d7Szhanghch05 static void 4065ac106bf6SEd Tanous getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 40663648c8beSEd Tanous size_t skip, size_t top) 4067a3316fc6SZhikuiRen { 4068a3316fc6SZhikuiRen uint64_t entryCount = 0; 40691e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint16_t>( 40701e1e598dSJonathan Doman *crow::connections::systemBus, 40711e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 40721e1e598dSJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 40731e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", 4074ac106bf6SEd Tanous [asyncResp, entryCount, skip, top](const boost::system::error_code& ec, 40751e1e598dSJonathan Doman const uint16_t bootCount) { 4076a3316fc6SZhikuiRen if (ec) 4077a3316fc6SZhikuiRen { 4078a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 4079ac106bf6SEd Tanous messages::internalError(asyncResp->res); 4080a3316fc6SZhikuiRen return; 4081a3316fc6SZhikuiRen } 4082ac106bf6SEd Tanous getPostCodeForBoot(asyncResp, 1, bootCount, entryCount, skip, top); 40831e1e598dSJonathan Doman }); 4084a3316fc6SZhikuiRen } 4085a3316fc6SZhikuiRen 40867e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 4087a3316fc6SZhikuiRen { 40887e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 408922d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/") 4090ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 40917e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 409245ca1b86SEd Tanous [&app](const crow::Request& req, 409322d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 409422d268cbSEd Tanous const std::string& systemName) { 4095c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 4096c937d2bfSEd Tanous .canDelegateTop = true, 4097c937d2bfSEd Tanous .canDelegateSkip = true, 4098c937d2bfSEd Tanous }; 4099c937d2bfSEd Tanous query_param::Query delegatedQuery; 4100c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 41013ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 410245ca1b86SEd Tanous { 410345ca1b86SEd Tanous return; 410445ca1b86SEd Tanous } 41057f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 41067f3e84a1SEd Tanous { 41077f3e84a1SEd Tanous // Option currently returns no systems. TBD 41087f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 41097f3e84a1SEd Tanous systemName); 41107f3e84a1SEd Tanous return; 41117f3e84a1SEd Tanous } 411222d268cbSEd Tanous 411322d268cbSEd Tanous if (systemName != "system") 411422d268cbSEd Tanous { 411522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 411622d268cbSEd Tanous systemName); 411722d268cbSEd Tanous return; 411822d268cbSEd Tanous } 4119a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 4120a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 4121a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 4122a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 4123a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 4124a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 4125a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 4126a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 4127a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 41283648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 41295143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 41303648c8beSEd Tanous getCurrentBootNumber(asyncResp, skip, top); 41317e860f15SJohn Edward Broadbent }); 4132a3316fc6SZhikuiRen } 4133a3316fc6SZhikuiRen 4134647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 4135647b3cdcSGeorge Liu { 41360fda0f12SGeorge Liu BMCWEB_ROUTE( 41370fda0f12SGeorge Liu app, 413822d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/") 4139647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 4140647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 414145ca1b86SEd Tanous [&app](const crow::Request& req, 4142647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 414322d268cbSEd Tanous const std::string& systemName, 4144647b3cdcSGeorge Liu const std::string& postCodeID) { 41453ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 414645ca1b86SEd Tanous { 414745ca1b86SEd Tanous return; 414845ca1b86SEd Tanous } 414972e21377SMatt Spinler if (!http_helpers::isContentTypeAllowed( 415099351cd8SEd Tanous req.getHeaderValue("Accept"), 41514a0e1a0cSEd Tanous http_helpers::ContentType::OctetStream, true)) 4152647b3cdcSGeorge Liu { 4153002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 4154647b3cdcSGeorge Liu return; 4155647b3cdcSGeorge Liu } 41567f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 41577f3e84a1SEd Tanous { 41587f3e84a1SEd Tanous // Option currently returns no systems. TBD 41597f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 41607f3e84a1SEd Tanous systemName); 41617f3e84a1SEd Tanous return; 41627f3e84a1SEd Tanous } 416322d268cbSEd Tanous if (systemName != "system") 416422d268cbSEd Tanous { 416522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 416622d268cbSEd Tanous systemName); 416722d268cbSEd Tanous return; 416822d268cbSEd Tanous } 4169647b3cdcSGeorge Liu 4170647b3cdcSGeorge Liu uint64_t currentValue = 0; 4171647b3cdcSGeorge Liu uint16_t index = 0; 4172647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 4173647b3cdcSGeorge Liu { 4174002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID); 4175647b3cdcSGeorge Liu return; 4176647b3cdcSGeorge Liu } 4177647b3cdcSGeorge Liu 4178647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 4179647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 41805e7e2dc5SEd Tanous const boost::system::error_code& ec, 4181002d39b4SEd Tanous const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>& 4182002d39b4SEd Tanous postcodes) { 4183647b3cdcSGeorge Liu if (ec.value() == EBADR) 4184647b3cdcSGeorge Liu { 4185002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4186002d39b4SEd Tanous postCodeID); 4187647b3cdcSGeorge Liu return; 4188647b3cdcSGeorge Liu } 4189647b3cdcSGeorge Liu if (ec) 4190647b3cdcSGeorge Liu { 4191647b3cdcSGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 4192647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 4193647b3cdcSGeorge Liu return; 4194647b3cdcSGeorge Liu } 4195647b3cdcSGeorge Liu 4196647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 4197002d39b4SEd Tanous if (value == std::string::npos || postcodes.size() < currentValue) 4198647b3cdcSGeorge Liu { 4199a7405d5fSGunnar Mills BMCWEB_LOG_WARNING << "Wrong currentValue value"; 4200002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4201002d39b4SEd Tanous postCodeID); 4202647b3cdcSGeorge Liu return; 4203647b3cdcSGeorge Liu } 4204647b3cdcSGeorge Liu 42059eb808c1SEd Tanous const auto& [tID, c] = postcodes[value]; 420646ff87baSEd Tanous if (c.empty()) 4207647b3cdcSGeorge Liu { 4208a7405d5fSGunnar Mills BMCWEB_LOG_WARNING << "No found post code data"; 4209002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4210002d39b4SEd Tanous postCodeID); 4211647b3cdcSGeorge Liu return; 4212647b3cdcSGeorge Liu } 421346ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 421446ff87baSEd Tanous const char* d = reinterpret_cast<const char*>(c.data()); 421546ff87baSEd Tanous std::string_view strData(d, c.size()); 4216647b3cdcSGeorge Liu 4217d9f6c621SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::content_type, 4218647b3cdcSGeorge Liu "application/octet-stream"); 4219d9f6c621SEd Tanous asyncResp->res.addHeader( 4220d9f6c621SEd Tanous boost::beast::http::field::content_transfer_encoding, "Base64"); 4221002d39b4SEd Tanous asyncResp->res.body() = crow::utility::base64encode(strData); 4222647b3cdcSGeorge Liu }, 4223647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 4224647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 4225002d39b4SEd Tanous "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index); 4226647b3cdcSGeorge Liu }); 4227647b3cdcSGeorge Liu } 4228647b3cdcSGeorge Liu 42297e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 4230a3316fc6SZhikuiRen { 42317e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 423222d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/") 4233ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 42347e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 423545ca1b86SEd Tanous [&app](const crow::Request& req, 42367e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 423722d268cbSEd Tanous const std::string& systemName, const std::string& targetID) { 42383ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 423945ca1b86SEd Tanous { 424045ca1b86SEd Tanous return; 424145ca1b86SEd Tanous } 42427f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 42437f3e84a1SEd Tanous { 42447f3e84a1SEd Tanous // Option currently returns no systems. TBD 42457f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 42467f3e84a1SEd Tanous systemName); 42477f3e84a1SEd Tanous return; 42487f3e84a1SEd Tanous } 424922d268cbSEd Tanous if (systemName != "system") 425022d268cbSEd Tanous { 425122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 425222d268cbSEd Tanous systemName); 425322d268cbSEd Tanous return; 425422d268cbSEd Tanous } 425522d268cbSEd Tanous 42566f284d24SJiaqing Zhao getPostCodeForEntry(asyncResp, targetID); 42577e860f15SJohn Edward Broadbent }); 4258a3316fc6SZhikuiRen } 4259a3316fc6SZhikuiRen 42601da66f75SEd Tanous } // namespace redfish 4261