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 187a1dbc48SGeorge Liu #include "dbus_utility.hpp" 19b7028ebfSSpencer Ku #include "gzfile.hpp" 20647b3cdcSGeorge Liu #include "http_utility.hpp" 21b7028ebfSSpencer Ku #include "human_sort.hpp" 224851d45dSJason M. Bills #include "registries.hpp" 234851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 244851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2546229577SJames Feist #include "task.hpp" 261da66f75SEd Tanous 27e1f26343SJason M. Bills #include <systemd/sd-journal.h> 288e31778eSAsmitha Karunanithi #include <tinyxml2.h> 29400fd1fbSAdriana Kobylak #include <unistd.h> 30e1f26343SJason M. Bills 317e860f15SJohn Edward Broadbent #include <app.hpp> 329896eaedSEd Tanous #include <boost/algorithm/string/case_conv.hpp> 3311ba3979SEd Tanous #include <boost/algorithm/string/classification.hpp> 34400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 354851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 3607c8c20dSEd Tanous #include <boost/beast/http/verb.hpp> 371da66f75SEd Tanous #include <boost/container/flat_map.hpp> 381ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 39cb92c03bSAndrew Geissler #include <error_messages.hpp> 4045ca1b86SEd Tanous #include <query.hpp> 41ed398213SEd Tanous #include <registries/privilege_registry.hpp> 42d1bde9e5SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 43d1bde9e5SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 44d1bde9e5SKrzysztof Grobelny #include <utils/dbus_utils.hpp> 452b82937eSEd Tanous #include <utils/time_utils.hpp> 461214b7e7SGunnar Mills 477a1dbc48SGeorge Liu #include <array> 48647b3cdcSGeorge Liu #include <charconv> 494418c7f0SJames Feist #include <filesystem> 5075710de2SXiaochao Ma #include <optional> 5126702d01SEd Tanous #include <span> 52cd225da8SJason M. Bills #include <string_view> 53abf2add6SEd Tanous #include <variant> 541da66f75SEd Tanous 551da66f75SEd Tanous namespace redfish 561da66f75SEd Tanous { 571da66f75SEd Tanous 585b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 595b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 605b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 615b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 625b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 635b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 64424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 656eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 666eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 671da66f75SEd Tanous 688e31778eSAsmitha Karunanithi enum class DumpCreationProgress 698e31778eSAsmitha Karunanithi { 708e31778eSAsmitha Karunanithi DUMP_CREATE_SUCCESS, 718e31778eSAsmitha Karunanithi DUMP_CREATE_FAILED, 728e31778eSAsmitha Karunanithi DUMP_CREATE_INPROGRESS 738e31778eSAsmitha Karunanithi }; 748e31778eSAsmitha Karunanithi 75fffb8c1fSEd Tanous namespace registries 764851d45dSJason M. Bills { 7726702d01SEd Tanous static const Message* 7826702d01SEd Tanous getMessageFromRegistry(const std::string& messageKey, 7926702d01SEd Tanous const std::span<const MessageEntry> registry) 804851d45dSJason M. Bills { 81002d39b4SEd Tanous std::span<const MessageEntry>::iterator messageIt = 82002d39b4SEd Tanous std::find_if(registry.begin(), registry.end(), 834851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 84e662eae8SEd Tanous return std::strcmp(messageEntry.first, messageKey.c_str()) == 0; 854851d45dSJason M. Bills }); 8626702d01SEd Tanous if (messageIt != registry.end()) 874851d45dSJason M. Bills { 884851d45dSJason M. Bills return &messageIt->second; 894851d45dSJason M. Bills } 904851d45dSJason M. Bills 914851d45dSJason M. Bills return nullptr; 924851d45dSJason M. Bills } 934851d45dSJason M. Bills 944851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 954851d45dSJason M. Bills { 964851d45dSJason M. Bills // Redfish MessageIds are in the form 974851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 984851d45dSJason M. Bills // the right Message 994851d45dSJason M. Bills std::vector<std::string> fields; 1004851d45dSJason M. Bills fields.reserve(4); 1014851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 10202cad96eSEd Tanous const std::string& registryName = fields[0]; 10302cad96eSEd Tanous const std::string& messageKey = fields[3]; 1044851d45dSJason M. Bills 1054851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 1064851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 1074851d45dSJason M. Bills { 1084851d45dSJason M. Bills return getMessageFromRegistry( 10926702d01SEd Tanous messageKey, std::span<const MessageEntry>(base::registry)); 1104851d45dSJason M. Bills } 1114851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 1124851d45dSJason M. Bills { 1134851d45dSJason M. Bills return getMessageFromRegistry( 11426702d01SEd Tanous messageKey, std::span<const MessageEntry>(openbmc::registry)); 1154851d45dSJason M. Bills } 1164851d45dSJason M. Bills return nullptr; 1174851d45dSJason M. Bills } 118fffb8c1fSEd Tanous } // namespace registries 1194851d45dSJason M. Bills 120f6150403SJames Feist namespace fs = std::filesystem; 1211da66f75SEd Tanous 122cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 123cb92c03bSAndrew Geissler { 124d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 125d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 126d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 127d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 128cb92c03bSAndrew Geissler { 129cb92c03bSAndrew Geissler return "Critical"; 130cb92c03bSAndrew Geissler } 1313174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 132d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 133d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 134cb92c03bSAndrew Geissler { 135cb92c03bSAndrew Geissler return "OK"; 136cb92c03bSAndrew Geissler } 1373174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 138cb92c03bSAndrew Geissler { 139cb92c03bSAndrew Geissler return "Warning"; 140cb92c03bSAndrew Geissler } 141cb92c03bSAndrew Geissler return ""; 142cb92c03bSAndrew Geissler } 143cb92c03bSAndrew Geissler 1449017faf2SAbhishek Patel inline std::optional<bool> getProviderNotifyAction(const std::string& notify) 1459017faf2SAbhishek Patel { 1469017faf2SAbhishek Patel std::optional<bool> notifyAction; 1479017faf2SAbhishek Patel if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Notify") 1489017faf2SAbhishek Patel { 1499017faf2SAbhishek Patel notifyAction = true; 1509017faf2SAbhishek Patel } 1519017faf2SAbhishek Patel else if (notify == "xyz.openbmc_project.Logging.Entry.Notify.Inhibit") 1529017faf2SAbhishek Patel { 1539017faf2SAbhishek Patel notifyAction = false; 1549017faf2SAbhishek Patel } 1559017faf2SAbhishek Patel 1569017faf2SAbhishek Patel return notifyAction; 1579017faf2SAbhishek Patel } 1589017faf2SAbhishek Patel 1597e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 16039e77504SEd Tanous const std::string_view& field, 16139e77504SEd Tanous std::string_view& contents) 16216428a1aSJason M. Bills { 16316428a1aSJason M. Bills const char* data = nullptr; 16416428a1aSJason M. Bills size_t length = 0; 16516428a1aSJason M. Bills int ret = 0; 16616428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 16746ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 16846ff87baSEd Tanous const void** dataVoid = reinterpret_cast<const void**>(&data); 16946ff87baSEd Tanous 17046ff87baSEd Tanous ret = sd_journal_get_data(journal, field.data(), dataVoid, &length); 17116428a1aSJason M. Bills if (ret < 0) 17216428a1aSJason M. Bills { 17316428a1aSJason M. Bills return ret; 17416428a1aSJason M. Bills } 17539e77504SEd Tanous contents = std::string_view(data, length); 17616428a1aSJason M. Bills // Only use the content after the "=" character. 17781ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 17816428a1aSJason M. Bills return ret; 17916428a1aSJason M. Bills } 18016428a1aSJason M. Bills 1817e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 1827e860f15SJohn Edward Broadbent const std::string_view& field, 1837e860f15SJohn Edward Broadbent const int& base, long int& contents) 18416428a1aSJason M. Bills { 18516428a1aSJason M. Bills int ret = 0; 18639e77504SEd Tanous std::string_view metadata; 18716428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 18816428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 18916428a1aSJason M. Bills if (ret < 0) 19016428a1aSJason M. Bills { 19116428a1aSJason M. Bills return ret; 19216428a1aSJason M. Bills } 193b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 19416428a1aSJason M. Bills return ret; 19516428a1aSJason M. Bills } 19616428a1aSJason M. Bills 1977e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1987e860f15SJohn Edward Broadbent std::string& entryTimestamp) 199a3316fc6SZhikuiRen { 200a3316fc6SZhikuiRen int ret = 0; 201a3316fc6SZhikuiRen uint64_t timestamp = 0; 202a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 203a3316fc6SZhikuiRen if (ret < 0) 204a3316fc6SZhikuiRen { 205a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 206a3316fc6SZhikuiRen << strerror(-ret); 207a3316fc6SZhikuiRen return false; 208a3316fc6SZhikuiRen } 2092b82937eSEd Tanous entryTimestamp = 2102b82937eSEd Tanous redfish::time_utils::getDateTimeUint(timestamp / 1000 / 1000); 2119c620e21SAsmitha Karunanithi return true; 212a3316fc6SZhikuiRen } 21350b8a43aSEd Tanous 2147e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 215e85d6b16SJason M. Bills const bool firstEntry = true) 21616428a1aSJason M. Bills { 21716428a1aSJason M. Bills int ret = 0; 21816428a1aSJason M. Bills static uint64_t prevTs = 0; 21916428a1aSJason M. Bills static int index = 0; 220e85d6b16SJason M. Bills if (firstEntry) 221e85d6b16SJason M. Bills { 222e85d6b16SJason M. Bills prevTs = 0; 223e85d6b16SJason M. Bills } 224e85d6b16SJason M. Bills 22516428a1aSJason M. Bills // Get the entry timestamp 22616428a1aSJason M. Bills uint64_t curTs = 0; 22716428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 22816428a1aSJason M. Bills if (ret < 0) 22916428a1aSJason M. Bills { 23016428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 23116428a1aSJason M. Bills << strerror(-ret); 23216428a1aSJason M. Bills return false; 23316428a1aSJason M. Bills } 23416428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 23516428a1aSJason M. Bills if (curTs == prevTs) 23616428a1aSJason M. Bills { 23716428a1aSJason M. Bills index++; 23816428a1aSJason M. Bills } 23916428a1aSJason M. Bills else 24016428a1aSJason M. Bills { 24116428a1aSJason M. Bills // Otherwise, reset it 24216428a1aSJason M. Bills index = 0; 24316428a1aSJason M. Bills } 24416428a1aSJason M. Bills // Save the timestamp 24516428a1aSJason M. Bills prevTs = curTs; 24616428a1aSJason M. Bills 24716428a1aSJason M. Bills entryID = std::to_string(curTs); 24816428a1aSJason M. Bills if (index > 0) 24916428a1aSJason M. Bills { 25016428a1aSJason M. Bills entryID += "_" + std::to_string(index); 25116428a1aSJason M. Bills } 25216428a1aSJason M. Bills return true; 25316428a1aSJason M. Bills } 25416428a1aSJason M. Bills 255e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 256e85d6b16SJason M. Bills const bool firstEntry = true) 25795820184SJason M. Bills { 258271584abSEd Tanous static time_t prevTs = 0; 25995820184SJason M. Bills static int index = 0; 260e85d6b16SJason M. Bills if (firstEntry) 261e85d6b16SJason M. Bills { 262e85d6b16SJason M. Bills prevTs = 0; 263e85d6b16SJason M. Bills } 264e85d6b16SJason M. Bills 26595820184SJason M. Bills // Get the entry timestamp 266271584abSEd Tanous std::time_t curTs = 0; 26795820184SJason M. Bills std::tm timeStruct = {}; 26895820184SJason M. Bills std::istringstream entryStream(logEntry); 26995820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 27095820184SJason M. Bills { 27195820184SJason M. Bills curTs = std::mktime(&timeStruct); 27295820184SJason M. Bills } 27395820184SJason M. Bills // If the timestamp isn't unique, increment the index 27495820184SJason M. Bills if (curTs == prevTs) 27595820184SJason M. Bills { 27695820184SJason M. Bills index++; 27795820184SJason M. Bills } 27895820184SJason M. Bills else 27995820184SJason M. Bills { 28095820184SJason M. Bills // Otherwise, reset it 28195820184SJason M. Bills index = 0; 28295820184SJason M. Bills } 28395820184SJason M. Bills // Save the timestamp 28495820184SJason M. Bills prevTs = curTs; 28595820184SJason M. Bills 28695820184SJason M. Bills entryID = std::to_string(curTs); 28795820184SJason M. Bills if (index > 0) 28895820184SJason M. Bills { 28995820184SJason M. Bills entryID += "_" + std::to_string(index); 29095820184SJason M. Bills } 29195820184SJason M. Bills return true; 29295820184SJason M. Bills } 29395820184SJason M. Bills 2947e860f15SJohn Edward Broadbent inline static bool 2958d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2968d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 2978d1b46d7Szhanghch05 uint64_t& index) 29816428a1aSJason M. Bills { 29916428a1aSJason M. Bills if (entryID.empty()) 30016428a1aSJason M. Bills { 30116428a1aSJason M. Bills return false; 30216428a1aSJason M. Bills } 30316428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 30439e77504SEd Tanous std::string_view tsStr(entryID); 30516428a1aSJason M. Bills 30681ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 30771d5d8dbSEd Tanous if (underscorePos != std::string_view::npos) 30816428a1aSJason M. Bills { 30916428a1aSJason M. Bills // Timestamp has an index 31016428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 31139e77504SEd Tanous std::string_view indexStr(entryID); 31216428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 313c0bd5e4bSEd Tanous auto [ptr, ec] = std::from_chars( 314c0bd5e4bSEd Tanous indexStr.data(), indexStr.data() + indexStr.size(), index); 315c0bd5e4bSEd Tanous if (ec != std::errc()) 31616428a1aSJason M. Bills { 3179db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 31816428a1aSJason M. Bills return false; 31916428a1aSJason M. Bills } 32016428a1aSJason M. Bills } 32116428a1aSJason M. Bills // Timestamp has no index 322c0bd5e4bSEd Tanous auto [ptr, ec] = 323c0bd5e4bSEd Tanous std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp); 324c0bd5e4bSEd Tanous if (ec != std::errc()) 32516428a1aSJason M. Bills { 3269db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 32716428a1aSJason M. Bills return false; 32816428a1aSJason M. Bills } 32916428a1aSJason M. Bills return true; 33016428a1aSJason M. Bills } 33116428a1aSJason M. Bills 33295820184SJason M. Bills static bool 33395820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 33495820184SJason M. Bills { 33595820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 33695820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 33795820184SJason M. Bills 33895820184SJason M. Bills // Loop through the directory looking for redfish log files 33995820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 34095820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 34195820184SJason M. Bills { 34295820184SJason M. Bills // If we find a redfish log file, save the path 34395820184SJason M. Bills std::string filename = dirEnt.path().filename(); 34411ba3979SEd Tanous if (filename.starts_with(redfishLogFilename)) 34595820184SJason M. Bills { 34695820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 34795820184SJason M. Bills } 34895820184SJason M. Bills } 34995820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 35095820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 35195820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 35295820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 35395820184SJason M. Bills 35495820184SJason M. Bills return !redfishLogFiles.empty(); 35595820184SJason M. Bills } 35695820184SJason M. Bills 357aefe3786SClaire Weinan inline void parseDumpEntryFromDbusObject( 3582d613eb6SJiaqing Zhao const dbus::utility::ManagedObjectType::value_type& object, 359c6fecdabSClaire Weinan std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs, 360aefe3786SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 361aefe3786SClaire Weinan { 362aefe3786SClaire Weinan for (const auto& interfaceMap : object.second) 363aefe3786SClaire Weinan { 364aefe3786SClaire Weinan if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") 365aefe3786SClaire Weinan { 366aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 367aefe3786SClaire Weinan { 368aefe3786SClaire Weinan if (propertyMap.first == "Status") 369aefe3786SClaire Weinan { 370aefe3786SClaire Weinan const auto* status = 371aefe3786SClaire Weinan std::get_if<std::string>(&propertyMap.second); 372aefe3786SClaire Weinan if (status == nullptr) 373aefe3786SClaire Weinan { 374aefe3786SClaire Weinan messages::internalError(asyncResp->res); 375aefe3786SClaire Weinan break; 376aefe3786SClaire Weinan } 377aefe3786SClaire Weinan dumpStatus = *status; 378aefe3786SClaire Weinan } 379aefe3786SClaire Weinan } 380aefe3786SClaire Weinan } 381aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 382aefe3786SClaire Weinan { 383aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 384aefe3786SClaire Weinan { 385aefe3786SClaire Weinan if (propertyMap.first == "Size") 386aefe3786SClaire Weinan { 387aefe3786SClaire Weinan const auto* sizePtr = 388aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 389aefe3786SClaire Weinan if (sizePtr == nullptr) 390aefe3786SClaire Weinan { 391aefe3786SClaire Weinan messages::internalError(asyncResp->res); 392aefe3786SClaire Weinan break; 393aefe3786SClaire Weinan } 394aefe3786SClaire Weinan size = *sizePtr; 395aefe3786SClaire Weinan break; 396aefe3786SClaire Weinan } 397aefe3786SClaire Weinan } 398aefe3786SClaire Weinan } 399aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") 400aefe3786SClaire Weinan { 401aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 402aefe3786SClaire Weinan { 403aefe3786SClaire Weinan if (propertyMap.first == "Elapsed") 404aefe3786SClaire Weinan { 405aefe3786SClaire Weinan const uint64_t* usecsTimeStamp = 406aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 407aefe3786SClaire Weinan if (usecsTimeStamp == nullptr) 408aefe3786SClaire Weinan { 409aefe3786SClaire Weinan messages::internalError(asyncResp->res); 410aefe3786SClaire Weinan break; 411aefe3786SClaire Weinan } 412c6fecdabSClaire Weinan timestampUs = *usecsTimeStamp; 413aefe3786SClaire Weinan break; 414aefe3786SClaire Weinan } 415aefe3786SClaire Weinan } 416aefe3786SClaire Weinan } 417aefe3786SClaire Weinan } 418aefe3786SClaire Weinan } 419aefe3786SClaire Weinan 42021ab404cSNan Zhou static std::string getDumpEntriesPath(const std::string& dumpType) 421fdd26906SClaire Weinan { 422fdd26906SClaire Weinan std::string entriesPath; 423fdd26906SClaire Weinan 424fdd26906SClaire Weinan if (dumpType == "BMC") 425fdd26906SClaire Weinan { 426fdd26906SClaire Weinan entriesPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 427fdd26906SClaire Weinan } 428fdd26906SClaire Weinan else if (dumpType == "FaultLog") 429fdd26906SClaire Weinan { 430fdd26906SClaire Weinan entriesPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/"; 431fdd26906SClaire Weinan } 432fdd26906SClaire Weinan else if (dumpType == "System") 433fdd26906SClaire Weinan { 434fdd26906SClaire Weinan entriesPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 435fdd26906SClaire Weinan } 436fdd26906SClaire Weinan else 437fdd26906SClaire Weinan { 438fdd26906SClaire Weinan BMCWEB_LOG_ERROR << "getDumpEntriesPath() invalid dump type: " 439fdd26906SClaire Weinan << dumpType; 440fdd26906SClaire Weinan } 441fdd26906SClaire Weinan 442fdd26906SClaire Weinan // Returns empty string on error 443fdd26906SClaire Weinan return entriesPath; 444fdd26906SClaire Weinan } 445fdd26906SClaire Weinan 4468d1b46d7Szhanghch05 inline void 4478d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4485cb1dd27SAsmitha Karunanithi const std::string& dumpType) 4495cb1dd27SAsmitha Karunanithi { 450fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 451fdd26906SClaire Weinan if (entriesPath.empty()) 4525cb1dd27SAsmitha Karunanithi { 4535cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4545cb1dd27SAsmitha Karunanithi return; 4555cb1dd27SAsmitha Karunanithi } 4565cb1dd27SAsmitha Karunanithi 4575cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 458fdd26906SClaire Weinan [asyncResp, entriesPath, 459711ac7a9SEd Tanous dumpType](const boost::system::error_code ec, 460711ac7a9SEd Tanous dbus::utility::ManagedObjectType& resp) { 4615cb1dd27SAsmitha Karunanithi if (ec) 4625cb1dd27SAsmitha Karunanithi { 4635cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4645cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4655cb1dd27SAsmitha Karunanithi return; 4665cb1dd27SAsmitha Karunanithi } 4675cb1dd27SAsmitha Karunanithi 468fdd26906SClaire Weinan // Remove ending slash 469fdd26906SClaire Weinan std::string odataIdStr = entriesPath; 470fdd26906SClaire Weinan if (!odataIdStr.empty()) 471fdd26906SClaire Weinan { 472fdd26906SClaire Weinan odataIdStr.pop_back(); 473fdd26906SClaire Weinan } 474fdd26906SClaire Weinan 475fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = 476fdd26906SClaire Weinan "#LogEntryCollection.LogEntryCollection"; 477fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr); 478fdd26906SClaire Weinan asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries"; 479fdd26906SClaire Weinan asyncResp->res.jsonValue["Description"] = 480fdd26906SClaire Weinan "Collection of " + dumpType + " Dump Entries"; 481fdd26906SClaire Weinan 4825cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4835cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 484b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 485b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 486002d39b4SEd Tanous std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; 4875cb1dd27SAsmitha Karunanithi 488002d39b4SEd Tanous std::sort(resp.begin(), resp.end(), [](const auto& l, const auto& r) { 489002d39b4SEd Tanous return AlphanumLess<std::string>()(l.first.filename(), 490002d39b4SEd Tanous r.first.filename()); 491565dfb6fSClaire Weinan }); 492565dfb6fSClaire Weinan 4935cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4945cb1dd27SAsmitha Karunanithi { 495b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 4965cb1dd27SAsmitha Karunanithi { 4975cb1dd27SAsmitha Karunanithi continue; 4985cb1dd27SAsmitha Karunanithi } 499c6fecdabSClaire Weinan uint64_t timestampUs = 0; 5005cb1dd27SAsmitha Karunanithi uint64_t size = 0; 50135440d18SAsmitha Karunanithi std::string dumpStatus; 502433b68b4SJason M. Bills nlohmann::json::object_t thisEntry; 5032dfd18efSEd Tanous 5042dfd18efSEd Tanous std::string entryID = object.first.filename(); 5052dfd18efSEd Tanous if (entryID.empty()) 5065cb1dd27SAsmitha Karunanithi { 5075cb1dd27SAsmitha Karunanithi continue; 5085cb1dd27SAsmitha Karunanithi } 5095cb1dd27SAsmitha Karunanithi 510c6fecdabSClaire Weinan parseDumpEntryFromDbusObject(object, dumpStatus, size, timestampUs, 511aefe3786SClaire Weinan asyncResp); 5125cb1dd27SAsmitha Karunanithi 5130fda0f12SGeorge Liu if (dumpStatus != 5140fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 51535440d18SAsmitha Karunanithi !dumpStatus.empty()) 51635440d18SAsmitha Karunanithi { 51735440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 51835440d18SAsmitha Karunanithi continue; 51935440d18SAsmitha Karunanithi } 52035440d18SAsmitha Karunanithi 5219c11a172SVijay Lobo thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 522fdd26906SClaire Weinan thisEntry["@odata.id"] = entriesPath + entryID; 5235cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 5245cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5255cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 526bbd80db8SClaire Weinan thisEntry["Created"] = 527bbd80db8SClaire Weinan redfish::time_utils::getDateTimeUintUs(timestampUs); 5285cb1dd27SAsmitha Karunanithi 5295cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5305cb1dd27SAsmitha Karunanithi { 531d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 532d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 533fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 534fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 5355cb1dd27SAsmitha Karunanithi } 5365cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5375cb1dd27SAsmitha Karunanithi { 538d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 539d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 540d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 541fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 542fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 5435cb1dd27SAsmitha Karunanithi } 54435440d18SAsmitha Karunanithi entriesArray.push_back(std::move(thisEntry)); 5455cb1dd27SAsmitha Karunanithi } 546002d39b4SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size(); 5475cb1dd27SAsmitha Karunanithi }, 5485cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5495cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5505cb1dd27SAsmitha Karunanithi } 5515cb1dd27SAsmitha Karunanithi 5528d1b46d7Szhanghch05 inline void 553c7a6d660SClaire Weinan getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5548d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 5555cb1dd27SAsmitha Karunanithi { 556fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 557fdd26906SClaire Weinan if (entriesPath.empty()) 5585cb1dd27SAsmitha Karunanithi { 5595cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5605cb1dd27SAsmitha Karunanithi return; 5615cb1dd27SAsmitha Karunanithi } 5625cb1dd27SAsmitha Karunanithi 5635cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 564fdd26906SClaire Weinan [asyncResp, entryID, dumpType, 565fdd26906SClaire Weinan entriesPath](const boost::system::error_code ec, 56602cad96eSEd Tanous const dbus::utility::ManagedObjectType& resp) { 5675cb1dd27SAsmitha Karunanithi if (ec) 5685cb1dd27SAsmitha Karunanithi { 5695cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5705cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5715cb1dd27SAsmitha Karunanithi return; 5725cb1dd27SAsmitha Karunanithi } 5735cb1dd27SAsmitha Karunanithi 574b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 575b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 576b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 577002d39b4SEd Tanous std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; 578b47452b2SAsmitha Karunanithi 5799eb808c1SEd Tanous for (const auto& objectPath : resp) 5805cb1dd27SAsmitha Karunanithi { 581b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5825cb1dd27SAsmitha Karunanithi { 5835cb1dd27SAsmitha Karunanithi continue; 5845cb1dd27SAsmitha Karunanithi } 5855cb1dd27SAsmitha Karunanithi 5865cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 587c6fecdabSClaire Weinan uint64_t timestampUs = 0; 5885cb1dd27SAsmitha Karunanithi uint64_t size = 0; 58935440d18SAsmitha Karunanithi std::string dumpStatus; 5905cb1dd27SAsmitha Karunanithi 591aefe3786SClaire Weinan parseDumpEntryFromDbusObject(objectPath, dumpStatus, size, 592c6fecdabSClaire Weinan timestampUs, asyncResp); 5935cb1dd27SAsmitha Karunanithi 5940fda0f12SGeorge Liu if (dumpStatus != 5950fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 59635440d18SAsmitha Karunanithi !dumpStatus.empty()) 59735440d18SAsmitha Karunanithi { 59835440d18SAsmitha Karunanithi // Dump status is not Complete 59935440d18SAsmitha Karunanithi // return not found until status is changed to Completed 600d1bde9e5SKrzysztof Grobelny messages::resourceNotFound(asyncResp->res, dumpType + " dump", 601d1bde9e5SKrzysztof Grobelny entryID); 60235440d18SAsmitha Karunanithi return; 60335440d18SAsmitha Karunanithi } 60435440d18SAsmitha Karunanithi 6055cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 6069c11a172SVijay Lobo "#LogEntry.v1_9_0.LogEntry"; 607fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID; 6085cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6095cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6105cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 611bbd80db8SClaire Weinan asyncResp->res.jsonValue["Created"] = 612bbd80db8SClaire Weinan redfish::time_utils::getDateTimeUintUs(timestampUs); 6135cb1dd27SAsmitha Karunanithi 6145cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6155cb1dd27SAsmitha Karunanithi { 616d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 617d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 618fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 619fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6205cb1dd27SAsmitha Karunanithi } 6215cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6225cb1dd27SAsmitha Karunanithi { 623d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 624002d39b4SEd Tanous asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System"; 625d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 626fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 627fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6285cb1dd27SAsmitha Karunanithi } 6295cb1dd27SAsmitha Karunanithi } 630e05aec50SEd Tanous if (!foundDumpEntry) 631b47452b2SAsmitha Karunanithi { 632b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 633b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 634b47452b2SAsmitha Karunanithi return; 635b47452b2SAsmitha Karunanithi } 6365cb1dd27SAsmitha Karunanithi }, 6375cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6385cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6395cb1dd27SAsmitha Karunanithi } 6405cb1dd27SAsmitha Karunanithi 6418d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6429878256fSStanley Chu const std::string& entryID, 643b47452b2SAsmitha Karunanithi const std::string& dumpType) 6445cb1dd27SAsmitha Karunanithi { 645002d39b4SEd Tanous auto respHandler = 646002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec) { 6475cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6485cb1dd27SAsmitha Karunanithi if (ec) 6495cb1dd27SAsmitha Karunanithi { 6503de8d8baSGeorge Liu if (ec.value() == EBADR) 6513de8d8baSGeorge Liu { 6523de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 6533de8d8baSGeorge Liu return; 6543de8d8baSGeorge Liu } 6555cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 656fdd26906SClaire Weinan << ec << " entryID=" << entryID; 6575cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6585cb1dd27SAsmitha Karunanithi return; 6595cb1dd27SAsmitha Karunanithi } 6605cb1dd27SAsmitha Karunanithi }; 6615cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 6625cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 663b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 664b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 665b47452b2SAsmitha Karunanithi entryID, 6665cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 6675cb1dd27SAsmitha Karunanithi } 6685cb1dd27SAsmitha Karunanithi 6698e31778eSAsmitha Karunanithi inline DumpCreationProgress 6708e31778eSAsmitha Karunanithi mapDbusStatusToDumpProgress(const std::string& status) 671a43be80fSAsmitha Karunanithi { 6728e31778eSAsmitha Karunanithi if (status == 6738e31778eSAsmitha Karunanithi "xyz.openbmc_project.Common.Progress.OperationStatus.Failed" || 6748e31778eSAsmitha Karunanithi status == "xyz.openbmc_project.Common.Progress.OperationStatus.Aborted") 6758e31778eSAsmitha Karunanithi { 6768e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_FAILED; 6778e31778eSAsmitha Karunanithi } 6788e31778eSAsmitha Karunanithi if (status == 6798e31778eSAsmitha Karunanithi "xyz.openbmc_project.Common.Progress.OperationStatus.Completed") 6808e31778eSAsmitha Karunanithi { 6818e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_SUCCESS; 6828e31778eSAsmitha Karunanithi } 6838e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_INPROGRESS; 6848e31778eSAsmitha Karunanithi } 6858e31778eSAsmitha Karunanithi 6868e31778eSAsmitha Karunanithi inline DumpCreationProgress 6878e31778eSAsmitha Karunanithi getDumpCompletionStatus(const dbus::utility::DBusPropertiesMap& values) 6888e31778eSAsmitha Karunanithi { 6898e31778eSAsmitha Karunanithi for (const auto& [key, val] : values) 6908e31778eSAsmitha Karunanithi { 6918e31778eSAsmitha Karunanithi if (key == "Status") 6928e31778eSAsmitha Karunanithi { 6938e31778eSAsmitha Karunanithi const std::string* value = std::get_if<std::string>(&val); 6948e31778eSAsmitha Karunanithi if (value == nullptr) 6958e31778eSAsmitha Karunanithi { 6968e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Status property value is null"; 6978e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_FAILED; 6988e31778eSAsmitha Karunanithi } 6998e31778eSAsmitha Karunanithi return mapDbusStatusToDumpProgress(*value); 7008e31778eSAsmitha Karunanithi } 7018e31778eSAsmitha Karunanithi } 7028e31778eSAsmitha Karunanithi return DumpCreationProgress::DUMP_CREATE_INPROGRESS; 7038e31778eSAsmitha Karunanithi } 7048e31778eSAsmitha Karunanithi 7058e31778eSAsmitha Karunanithi inline std::string getDumpEntryPath(const std::string& dumpPath) 7068e31778eSAsmitha Karunanithi { 7078e31778eSAsmitha Karunanithi if (dumpPath == "/xyz/openbmc_project/dump/bmc/entry") 7088e31778eSAsmitha Karunanithi { 7098e31778eSAsmitha Karunanithi return "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 7108e31778eSAsmitha Karunanithi } 7118e31778eSAsmitha Karunanithi if (dumpPath == "/xyz/openbmc_project/dump/system/entry") 7128e31778eSAsmitha Karunanithi { 7138e31778eSAsmitha Karunanithi return "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 7148e31778eSAsmitha Karunanithi } 7158e31778eSAsmitha Karunanithi return ""; 7168e31778eSAsmitha Karunanithi } 7178e31778eSAsmitha Karunanithi 7188e31778eSAsmitha Karunanithi inline void createDumpTaskCallback( 7198e31778eSAsmitha Karunanithi task::Payload&& payload, 7208e31778eSAsmitha Karunanithi const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7218e31778eSAsmitha Karunanithi const sdbusplus::message::object_path& createdObjPath) 7228e31778eSAsmitha Karunanithi { 7238e31778eSAsmitha Karunanithi const std::string dumpPath = createdObjPath.parent_path().str; 7248e31778eSAsmitha Karunanithi const std::string dumpId = createdObjPath.filename(); 7258e31778eSAsmitha Karunanithi 7268e31778eSAsmitha Karunanithi std::string dumpEntryPath = getDumpEntryPath(dumpPath); 7278e31778eSAsmitha Karunanithi 7288e31778eSAsmitha Karunanithi if (dumpEntryPath.empty()) 7298e31778eSAsmitha Karunanithi { 7308e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type received"; 7318e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 7328e31778eSAsmitha Karunanithi return; 7338e31778eSAsmitha Karunanithi } 7348e31778eSAsmitha Karunanithi 7358e31778eSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 7368e31778eSAsmitha Karunanithi [asyncResp, payload, createdObjPath, 7378e31778eSAsmitha Karunanithi dumpEntryPath{std::move(dumpEntryPath)}, 7388e31778eSAsmitha Karunanithi dumpId](const boost::system::error_code ec, 7398e31778eSAsmitha Karunanithi const std::string& introspectXml) { 7408e31778eSAsmitha Karunanithi if (ec) 7418e31778eSAsmitha Karunanithi { 7428e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Introspect call failed with error: " 7438e31778eSAsmitha Karunanithi << ec.message(); 7448e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 7458e31778eSAsmitha Karunanithi return; 7468e31778eSAsmitha Karunanithi } 7478e31778eSAsmitha Karunanithi 7488e31778eSAsmitha Karunanithi // Check if the created dump object has implemented Progress 7498e31778eSAsmitha Karunanithi // interface to track dump completion. If yes, fetch the "Status" 7508e31778eSAsmitha Karunanithi // property of the interface, modify the task state accordingly. 7518e31778eSAsmitha Karunanithi // Else, return task completed. 7528e31778eSAsmitha Karunanithi tinyxml2::XMLDocument doc; 7538e31778eSAsmitha Karunanithi 7548e31778eSAsmitha Karunanithi doc.Parse(introspectXml.data(), introspectXml.size()); 7558e31778eSAsmitha Karunanithi tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node"); 7568e31778eSAsmitha Karunanithi if (pRoot == nullptr) 7578e31778eSAsmitha Karunanithi { 7588e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << "XML document failed to parse"; 7598e31778eSAsmitha Karunanithi messages::internalError(asyncResp->res); 7608e31778eSAsmitha Karunanithi return; 7618e31778eSAsmitha Karunanithi } 7628e31778eSAsmitha Karunanithi tinyxml2::XMLElement* interfaceNode = 7638e31778eSAsmitha Karunanithi pRoot->FirstChildElement("interface"); 7648e31778eSAsmitha Karunanithi 7658e31778eSAsmitha Karunanithi bool isProgressIntfPresent = false; 7668e31778eSAsmitha Karunanithi while (interfaceNode != nullptr) 7678e31778eSAsmitha Karunanithi { 7688e31778eSAsmitha Karunanithi const char* thisInterfaceName = interfaceNode->Attribute("name"); 7698e31778eSAsmitha Karunanithi if (thisInterfaceName != nullptr) 7708e31778eSAsmitha Karunanithi { 7718e31778eSAsmitha Karunanithi if (thisInterfaceName == 7728e31778eSAsmitha Karunanithi std::string_view("xyz.openbmc_project.Common.Progress")) 7738e31778eSAsmitha Karunanithi { 7748e31778eSAsmitha Karunanithi interfaceNode = 7758e31778eSAsmitha Karunanithi interfaceNode->NextSiblingElement("interface"); 7768e31778eSAsmitha Karunanithi continue; 7778e31778eSAsmitha Karunanithi } 7788e31778eSAsmitha Karunanithi isProgressIntfPresent = true; 7798e31778eSAsmitha Karunanithi break; 7808e31778eSAsmitha Karunanithi } 7818e31778eSAsmitha Karunanithi interfaceNode = interfaceNode->NextSiblingElement("interface"); 7828e31778eSAsmitha Karunanithi } 7838e31778eSAsmitha Karunanithi 784a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 7858e31778eSAsmitha Karunanithi [createdObjPath, dumpEntryPath, dumpId, isProgressIntfPresent]( 7865b378546SPatrick Williams boost::system::error_code err, sdbusplus::message_t& msg, 787a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 788cb13a392SEd Tanous if (err) 789cb13a392SEd Tanous { 7908e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << createdObjPath.str 7918e31778eSAsmitha Karunanithi << ": Error in creating dump"; 7928e31778eSAsmitha Karunanithi taskData->messages.emplace_back(messages::internalError()); 7936145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 7946145ed6fSAsmitha Karunanithi return task::completed; 795cb13a392SEd Tanous } 796b9d36b47SEd Tanous 7978e31778eSAsmitha Karunanithi if (isProgressIntfPresent) 798a43be80fSAsmitha Karunanithi { 7998e31778eSAsmitha Karunanithi dbus::utility::DBusPropertiesMap values; 8008e31778eSAsmitha Karunanithi std::string prop; 8018e31778eSAsmitha Karunanithi msg.read(prop, values); 8028e31778eSAsmitha Karunanithi 8038e31778eSAsmitha Karunanithi DumpCreationProgress dumpStatus = 8048e31778eSAsmitha Karunanithi getDumpCompletionStatus(values); 8058e31778eSAsmitha Karunanithi if (dumpStatus == DumpCreationProgress::DUMP_CREATE_FAILED) 8068e31778eSAsmitha Karunanithi { 8078e31778eSAsmitha Karunanithi BMCWEB_LOG_ERROR << createdObjPath.str 8088e31778eSAsmitha Karunanithi << ": Error in creating dump"; 8098e31778eSAsmitha Karunanithi taskData->state = "Cancelled"; 8108e31778eSAsmitha Karunanithi return task::completed; 8118e31778eSAsmitha Karunanithi } 8128e31778eSAsmitha Karunanithi 8138e31778eSAsmitha Karunanithi if (dumpStatus == DumpCreationProgress::DUMP_CREATE_INPROGRESS) 8148e31778eSAsmitha Karunanithi { 8158e31778eSAsmitha Karunanithi BMCWEB_LOG_DEBUG << createdObjPath.str 8168e31778eSAsmitha Karunanithi << ": Dump creation task is in progress"; 8178e31778eSAsmitha Karunanithi return !task::completed; 8188e31778eSAsmitha Karunanithi } 8198e31778eSAsmitha Karunanithi } 8208e31778eSAsmitha Karunanithi 821a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 822a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 823a43be80fSAsmitha Karunanithi 824a43be80fSAsmitha Karunanithi std::string headerLoc = 8258e31778eSAsmitha Karunanithi "Location: " + dumpEntryPath + http_helpers::urlEncode(dumpId); 826002d39b4SEd Tanous taskData->payload->httpHeaders.emplace_back(std::move(headerLoc)); 827a43be80fSAsmitha Karunanithi 8288e31778eSAsmitha Karunanithi BMCWEB_LOG_DEBUG << createdObjPath.str 8298e31778eSAsmitha Karunanithi << ": Dump creation task completed"; 830a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 831b47452b2SAsmitha Karunanithi return task::completed; 832a43be80fSAsmitha Karunanithi }, 8338e31778eSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus.Properties'," 8348e31778eSAsmitha Karunanithi "member='PropertiesChanged',path='" + 8358e31778eSAsmitha Karunanithi createdObjPath.str + "'"); 836a43be80fSAsmitha Karunanithi 8378e31778eSAsmitha Karunanithi // The task timer is set to max time limit within which the 8388e31778eSAsmitha Karunanithi // requested dump will be collected. 8398e31778eSAsmitha Karunanithi task->startTimer(std::chrono::minutes(6)); 840a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 8418e31778eSAsmitha Karunanithi task->payload.emplace(payload); 8428e31778eSAsmitha Karunanithi }, 8438e31778eSAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", createdObjPath, 8448e31778eSAsmitha Karunanithi "org.freedesktop.DBus.Introspectable", "Introspect"); 845a43be80fSAsmitha Karunanithi } 846a43be80fSAsmitha Karunanithi 8478d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8488d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 849a43be80fSAsmitha Karunanithi { 850fdd26906SClaire Weinan std::string dumpPath = getDumpEntriesPath(dumpType); 851fdd26906SClaire Weinan if (dumpPath.empty()) 852a43be80fSAsmitha Karunanithi { 853a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 854a43be80fSAsmitha Karunanithi return; 855a43be80fSAsmitha Karunanithi } 856a43be80fSAsmitha Karunanithi 857a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 858a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 859a43be80fSAsmitha Karunanithi 86015ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 861a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 862a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 863a43be80fSAsmitha Karunanithi { 864a43be80fSAsmitha Karunanithi return; 865a43be80fSAsmitha Karunanithi } 866a43be80fSAsmitha Karunanithi 867a43be80fSAsmitha Karunanithi if (dumpType == "System") 868a43be80fSAsmitha Karunanithi { 869a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 870a43be80fSAsmitha Karunanithi { 8714978b63fSJason M. Bills BMCWEB_LOG_ERROR 8724978b63fSJason M. Bills << "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"; 873a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 874a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 875a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 876a43be80fSAsmitha Karunanithi return; 877a43be80fSAsmitha Karunanithi } 8783174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 879a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 880a43be80fSAsmitha Karunanithi { 881a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 882ace85d60SEd Tanous messages::internalError(asyncResp->res); 883a43be80fSAsmitha Karunanithi return; 884a43be80fSAsmitha Karunanithi } 8855907571dSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/"; 886a43be80fSAsmitha Karunanithi } 887a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 888a43be80fSAsmitha Karunanithi { 889a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 890a43be80fSAsmitha Karunanithi { 8910fda0f12SGeorge Liu BMCWEB_LOG_ERROR 8920fda0f12SGeorge Liu << "CreateDump action parameter 'DiagnosticDataType' not found!"; 893a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 894a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 895a43be80fSAsmitha Karunanithi return; 896a43be80fSAsmitha Karunanithi } 8973174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 898a43be80fSAsmitha Karunanithi { 899a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 900a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 901ace85d60SEd Tanous messages::internalError(asyncResp->res); 902a43be80fSAsmitha Karunanithi return; 903a43be80fSAsmitha Karunanithi } 9045907571dSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/"; 9055907571dSAsmitha Karunanithi } 9065907571dSAsmitha Karunanithi else 9075907571dSAsmitha Karunanithi { 9085907571dSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump failed. Unknown dump type"; 9095907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 9105907571dSAsmitha Karunanithi return; 911a43be80fSAsmitha Karunanithi } 912a43be80fSAsmitha Karunanithi 9138e31778eSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>> 9148e31778eSAsmitha Karunanithi createDumpParamVec; 9158e31778eSAsmitha Karunanithi 916a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 9175b378546SPatrick Williams [asyncResp, payload(task::Payload(req)), dumpPath]( 9185b378546SPatrick Williams const boost::system::error_code ec, const sdbusplus::message_t& msg, 9198e31778eSAsmitha Karunanithi const sdbusplus::message::object_path& objPath) mutable { 920a43be80fSAsmitha Karunanithi if (ec) 921a43be80fSAsmitha Karunanithi { 922a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 9235907571dSAsmitha Karunanithi const sd_bus_error* dbusError = msg.get_error(); 9245907571dSAsmitha Karunanithi if (dbusError == nullptr) 9255907571dSAsmitha Karunanithi { 9265907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 9275907571dSAsmitha Karunanithi return; 9285907571dSAsmitha Karunanithi } 9295907571dSAsmitha Karunanithi 9305907571dSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump DBus error: " << dbusError->name 9315907571dSAsmitha Karunanithi << " and error msg: " << dbusError->message; 9325907571dSAsmitha Karunanithi if (std::string_view( 9335907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.NotAllowed") == 9345907571dSAsmitha Karunanithi dbusError->name) 9355907571dSAsmitha Karunanithi { 9365907571dSAsmitha Karunanithi messages::resourceInStandby(asyncResp->res); 9375907571dSAsmitha Karunanithi return; 9385907571dSAsmitha Karunanithi } 9395907571dSAsmitha Karunanithi if (std::string_view( 9405907571dSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.Error.Disabled") == 9415907571dSAsmitha Karunanithi dbusError->name) 9425907571dSAsmitha Karunanithi { 9435907571dSAsmitha Karunanithi messages::serviceDisabled(asyncResp->res, dumpPath); 9445907571dSAsmitha Karunanithi return; 9455907571dSAsmitha Karunanithi } 9465907571dSAsmitha Karunanithi if (std::string_view( 9475907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.Unavailable") == 9485907571dSAsmitha Karunanithi dbusError->name) 9495907571dSAsmitha Karunanithi { 9505907571dSAsmitha Karunanithi messages::resourceInUse(asyncResp->res); 9515907571dSAsmitha Karunanithi return; 9525907571dSAsmitha Karunanithi } 9535907571dSAsmitha Karunanithi // Other Dbus errors such as: 9545907571dSAsmitha Karunanithi // xyz.openbmc_project.Common.Error.InvalidArgument & 9555907571dSAsmitha Karunanithi // org.freedesktop.DBus.Error.InvalidArgs are all related to 9565907571dSAsmitha Karunanithi // the dbus call that is made here in the bmcweb 9575907571dSAsmitha Karunanithi // implementation and has nothing to do with the client's 9585907571dSAsmitha Karunanithi // input in the request. Hence, returning internal error 9595907571dSAsmitha Karunanithi // back to the client. 960a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 961a43be80fSAsmitha Karunanithi return; 962a43be80fSAsmitha Karunanithi } 9638e31778eSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Path: " << objPath.str; 9648e31778eSAsmitha Karunanithi createDumpTaskCallback(std::move(payload), asyncResp, objPath); 965a43be80fSAsmitha Karunanithi }, 966b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 967b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 968b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 9698e31778eSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec); 970a43be80fSAsmitha Karunanithi } 971a43be80fSAsmitha Karunanithi 9728d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 9738d1b46d7Szhanghch05 const std::string& dumpType) 97480319af1SAsmitha Karunanithi { 975b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 976b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 9778d1b46d7Szhanghch05 978*0d946211SClaire Weinan crow::connections::systemBus->async_method_call( 979*0d946211SClaire Weinan [asyncResp](const boost::system::error_code& ec) { 98080319af1SAsmitha Karunanithi if (ec) 98180319af1SAsmitha Karunanithi { 982*0d946211SClaire Weinan BMCWEB_LOG_ERROR << "clearDump resp_handler got error " << ec; 98380319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 98480319af1SAsmitha Karunanithi return; 98580319af1SAsmitha Karunanithi } 986*0d946211SClaire Weinan }, 987*0d946211SClaire Weinan "xyz.openbmc_project.Dump.Manager", 988*0d946211SClaire Weinan "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 989*0d946211SClaire Weinan "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 99080319af1SAsmitha Karunanithi } 99180319af1SAsmitha Karunanithi 992b9d36b47SEd Tanous inline static void 993b9d36b47SEd Tanous parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params, 994b9d36b47SEd Tanous std::string& filename, std::string& timestamp, 995b9d36b47SEd Tanous std::string& logfile) 996043a0536SJohnathan Mantey { 997d1bde9e5SKrzysztof Grobelny const std::string* filenamePtr = nullptr; 998d1bde9e5SKrzysztof Grobelny const std::string* timestampPtr = nullptr; 999d1bde9e5SKrzysztof Grobelny const std::string* logfilePtr = nullptr; 1000d1bde9e5SKrzysztof Grobelny 1001d1bde9e5SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1002d1bde9e5SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), params, "Timestamp", timestampPtr, 1003d1bde9e5SKrzysztof Grobelny "Filename", filenamePtr, "Log", logfilePtr); 1004d1bde9e5SKrzysztof Grobelny 1005d1bde9e5SKrzysztof Grobelny if (!success) 1006043a0536SJohnathan Mantey { 1007d1bde9e5SKrzysztof Grobelny return; 1008043a0536SJohnathan Mantey } 1009d1bde9e5SKrzysztof Grobelny 1010d1bde9e5SKrzysztof Grobelny if (filenamePtr != nullptr) 1011043a0536SJohnathan Mantey { 1012d1bde9e5SKrzysztof Grobelny filename = *filenamePtr; 1013d1bde9e5SKrzysztof Grobelny } 1014d1bde9e5SKrzysztof Grobelny 1015d1bde9e5SKrzysztof Grobelny if (timestampPtr != nullptr) 1016043a0536SJohnathan Mantey { 1017d1bde9e5SKrzysztof Grobelny timestamp = *timestampPtr; 1018043a0536SJohnathan Mantey } 1019d1bde9e5SKrzysztof Grobelny 1020d1bde9e5SKrzysztof Grobelny if (logfilePtr != nullptr) 1021043a0536SJohnathan Mantey { 1022d1bde9e5SKrzysztof Grobelny logfile = *logfilePtr; 1023043a0536SJohnathan Mantey } 1024043a0536SJohnathan Mantey } 1025043a0536SJohnathan Mantey 10267e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 10271da66f75SEd Tanous { 1028c4bf6374SJason M. Bills /** 1029c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 1030c4bf6374SJason M. Bills */ 103122d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/") 1032ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 1033002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1034002d39b4SEd Tanous [&app](const crow::Request& req, 103522d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 103622d268cbSEd Tanous const std::string& systemName) { 10373ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1038c4bf6374SJason M. Bills { 103945ca1b86SEd Tanous return; 104045ca1b86SEd Tanous } 104122d268cbSEd Tanous if (systemName != "system") 104222d268cbSEd Tanous { 104322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 104422d268cbSEd Tanous systemName); 104522d268cbSEd Tanous return; 104622d268cbSEd Tanous } 104722d268cbSEd Tanous 10487e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 10497e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1050c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1051c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 1052c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1053029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 105445ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 1055c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1056c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 1057002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 1058c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 10591476687dSEd Tanous nlohmann::json::object_t eventLog; 10601476687dSEd Tanous eventLog["@odata.id"] = 10611476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 10621476687dSEd Tanous logServiceArray.push_back(std::move(eventLog)); 10635cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 10641476687dSEd Tanous nlohmann::json::object_t dumpLog; 1065002d39b4SEd Tanous dumpLog["@odata.id"] = "/redfish/v1/Systems/system/LogServices/Dump"; 10661476687dSEd Tanous logServiceArray.push_back(std::move(dumpLog)); 1067c9bb6861Sraviteja-b #endif 1068c9bb6861Sraviteja-b 1069d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 10701476687dSEd Tanous nlohmann::json::object_t crashdump; 10711476687dSEd Tanous crashdump["@odata.id"] = 10721476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump"; 10731476687dSEd Tanous logServiceArray.push_back(std::move(crashdump)); 1074d53dd41fSJason M. Bills #endif 1075b7028ebfSSpencer Ku 1076b7028ebfSSpencer Ku #ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER 10771476687dSEd Tanous nlohmann::json::object_t hostlogger; 10781476687dSEd Tanous hostlogger["@odata.id"] = 10791476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger"; 10801476687dSEd Tanous logServiceArray.push_back(std::move(hostlogger)); 1081b7028ebfSSpencer Ku #endif 1082c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1083c4bf6374SJason M. Bills logServiceArray.size(); 1084a3316fc6SZhikuiRen 10857a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 10867a1dbc48SGeorge Liu "xyz.openbmc_project.State.Boot.PostCode"}; 10877a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 10887a1dbc48SGeorge Liu "/", 0, interfaces, 10897a1dbc48SGeorge Liu [asyncResp](const boost::system::error_code& ec, 1090b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& 1091b9d36b47SEd Tanous subtreePath) { 1092a3316fc6SZhikuiRen if (ec) 1093a3316fc6SZhikuiRen { 1094a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 1095a3316fc6SZhikuiRen return; 1096a3316fc6SZhikuiRen } 1097a3316fc6SZhikuiRen 109855f79e6fSEd Tanous for (const auto& pathStr : subtreePath) 1099a3316fc6SZhikuiRen { 1100a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 1101a3316fc6SZhikuiRen { 110223a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 1103a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 1104613dabeaSEd Tanous nlohmann::json::object_t member; 1105613dabeaSEd Tanous member["@odata.id"] = 1106613dabeaSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes"; 1107613dabeaSEd Tanous 1108613dabeaSEd Tanous logServiceArrayLocal.push_back(std::move(member)); 1109613dabeaSEd Tanous 111045ca1b86SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 111123a21a1cSEd Tanous logServiceArrayLocal.size(); 1112a3316fc6SZhikuiRen return; 1113a3316fc6SZhikuiRen } 1114a3316fc6SZhikuiRen } 11157a1dbc48SGeorge Liu }); 11167e860f15SJohn Edward Broadbent }); 1117c4bf6374SJason M. Bills } 1118c4bf6374SJason M. Bills 11197e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 1120c4bf6374SJason M. Bills { 112122d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/") 1122ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 1123002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1124002d39b4SEd Tanous [&app](const crow::Request& req, 112522d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 112622d268cbSEd Tanous const std::string& systemName) { 11273ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 112845ca1b86SEd Tanous { 112945ca1b86SEd Tanous return; 113045ca1b86SEd Tanous } 113122d268cbSEd Tanous if (systemName != "system") 113222d268cbSEd Tanous { 113322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 113422d268cbSEd Tanous systemName); 113522d268cbSEd Tanous return; 113622d268cbSEd Tanous } 1137c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1138029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1139c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1140c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 1141c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 1142002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 1143c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1144c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 11457c8c4058STejas Patil 11467c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 11472b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 11487c8c4058STejas Patil 11497c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 11507c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 11517c8c4058STejas Patil redfishDateTimeOffset.second; 11527c8c4058STejas Patil 11531476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 11541476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1155e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1156e7d6c8b2SGunnar Mills 11570fda0f12SGeorge Liu {"target", 11580fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog"}}; 11597e860f15SJohn Edward Broadbent }); 1160489640c6SJason M. Bills } 1161489640c6SJason M. Bills 11627e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1163489640c6SJason M. Bills { 11644978b63fSJason M. Bills BMCWEB_ROUTE( 11654978b63fSJason M. Bills app, 116622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 1167432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 11687e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 116945ca1b86SEd Tanous [&app](const crow::Request& req, 117022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 117122d268cbSEd Tanous const std::string& systemName) { 11723ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 117345ca1b86SEd Tanous { 117445ca1b86SEd Tanous return; 117545ca1b86SEd Tanous } 117622d268cbSEd Tanous if (systemName != "system") 117722d268cbSEd Tanous { 117822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 117922d268cbSEd Tanous systemName); 118022d268cbSEd Tanous return; 118122d268cbSEd Tanous } 1182489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1183489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1184489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1185489640c6SJason M. Bills { 1186489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1187489640c6SJason M. Bills { 1188489640c6SJason M. Bills std::error_code ec; 1189489640c6SJason M. Bills std::filesystem::remove(file, ec); 1190489640c6SJason M. Bills } 1191489640c6SJason M. Bills } 1192489640c6SJason M. Bills 1193489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1194489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1195489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1196489640c6SJason M. Bills if (ec) 1197489640c6SJason M. Bills { 1198002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 1199489640c6SJason M. Bills messages::internalError(asyncResp->res); 1200489640c6SJason M. Bills return; 1201489640c6SJason M. Bills } 1202489640c6SJason M. Bills 1203489640c6SJason M. Bills messages::success(asyncResp->res); 1204489640c6SJason M. Bills }, 1205489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1206002d39b4SEd Tanous "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1207002d39b4SEd Tanous "replace"); 12087e860f15SJohn Edward Broadbent }); 1209c4bf6374SJason M. Bills } 1210c4bf6374SJason M. Bills 1211ac992cdeSJason M. Bills enum class LogParseError 1212ac992cdeSJason M. Bills { 1213ac992cdeSJason M. Bills success, 1214ac992cdeSJason M. Bills parseFailed, 1215ac992cdeSJason M. Bills messageIdNotInRegistry, 1216ac992cdeSJason M. Bills }; 1217ac992cdeSJason M. Bills 1218ac992cdeSJason M. Bills static LogParseError 1219ac992cdeSJason M. Bills fillEventLogEntryJson(const std::string& logEntryID, 1220b5a76932SEd Tanous const std::string& logEntry, 1221de703c5dSJason M. Bills nlohmann::json::object_t& logEntryJson) 1222c4bf6374SJason M. Bills { 122395820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1224cd225da8SJason M. Bills // First get the Timestamp 1225f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1226cd225da8SJason M. Bills if (space == std::string::npos) 122795820184SJason M. Bills { 1228ac992cdeSJason M. Bills return LogParseError::parseFailed; 122995820184SJason M. Bills } 1230cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1231cd225da8SJason M. Bills // Then get the log contents 1232f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1233cd225da8SJason M. Bills if (entryStart == std::string::npos) 1234cd225da8SJason M. Bills { 1235ac992cdeSJason M. Bills return LogParseError::parseFailed; 1236cd225da8SJason M. Bills } 1237cd225da8SJason M. Bills std::string_view entry(logEntry); 1238cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1239cd225da8SJason M. Bills // Use split to separate the entry into its fields 1240cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1241cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1242cd225da8SJason M. Bills boost::token_compress_on); 1243cd225da8SJason M. Bills // We need at least a MessageId to be valid 124426f6976fSEd Tanous if (logEntryFields.empty()) 1245cd225da8SJason M. Bills { 1246ac992cdeSJason M. Bills return LogParseError::parseFailed; 1247cd225da8SJason M. Bills } 1248cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 124995820184SJason M. Bills 12504851d45dSJason M. Bills // Get the Message from the MessageRegistry 1251fffb8c1fSEd Tanous const registries::Message* message = registries::getMessage(messageID); 1252c4bf6374SJason M. Bills 125354417b02SSui Chen if (message == nullptr) 1254c4bf6374SJason M. Bills { 125554417b02SSui Chen BMCWEB_LOG_WARNING << "Log entry not found in registry: " << logEntry; 1256ac992cdeSJason M. Bills return LogParseError::messageIdNotInRegistry; 1257c4bf6374SJason M. Bills } 1258c4bf6374SJason M. Bills 125954417b02SSui Chen std::string msg = message->message; 126054417b02SSui Chen 126115a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 126226702d01SEd Tanous std::span<std::string> messageArgs; 126315a86ff6SJason M. Bills if (logEntryFields.size() > 1) 126415a86ff6SJason M. Bills { 126515a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 126615a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 126715a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 126815a86ff6SJason M. Bills if (!messageArgsStart.empty()) 126915a86ff6SJason M. Bills { 127015a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 127115a86ff6SJason M. Bills } 127215a86ff6SJason M. Bills 127323a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1274c4bf6374SJason M. Bills 12754851d45dSJason M. Bills // Fill the MessageArgs into the Message 127695820184SJason M. Bills int i = 0; 127795820184SJason M. Bills for (const std::string& messageArg : messageArgs) 12784851d45dSJason M. Bills { 127995820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 12804851d45dSJason M. Bills size_t argPos = msg.find(argStr); 12814851d45dSJason M. Bills if (argPos != std::string::npos) 12824851d45dSJason M. Bills { 128395820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 12844851d45dSJason M. Bills } 12854851d45dSJason M. Bills } 128615a86ff6SJason M. Bills } 12874851d45dSJason M. Bills 128895820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 128995820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 129095820184SJason M. Bills // between the '.' and the '+', so just remove them. 1291f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1292f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 129395820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1294c4bf6374SJason M. Bills { 129595820184SJason M. Bills timestamp.erase(dot, plus - dot); 1296c4bf6374SJason M. Bills } 1297c4bf6374SJason M. Bills 1298c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 12999c11a172SVijay Lobo logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 130084afc48bSJason M. Bills logEntryJson["@odata.id"] = 130184afc48bSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + logEntryID; 130284afc48bSJason M. Bills logEntryJson["Name"] = "System Event Log Entry"; 130384afc48bSJason M. Bills logEntryJson["Id"] = logEntryID; 130484afc48bSJason M. Bills logEntryJson["Message"] = std::move(msg); 130584afc48bSJason M. Bills logEntryJson["MessageId"] = std::move(messageID); 130684afc48bSJason M. Bills logEntryJson["MessageArgs"] = messageArgs; 130784afc48bSJason M. Bills logEntryJson["EntryType"] = "Event"; 130884afc48bSJason M. Bills logEntryJson["Severity"] = message->messageSeverity; 130984afc48bSJason M. Bills logEntryJson["Created"] = std::move(timestamp); 1310ac992cdeSJason M. Bills return LogParseError::success; 1311c4bf6374SJason M. Bills } 1312c4bf6374SJason M. Bills 13137e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1314c4bf6374SJason M. Bills { 131522d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") 13168b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 1317002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1318002d39b4SEd Tanous [&app](const crow::Request& req, 131922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 132022d268cbSEd Tanous const std::string& systemName) { 1321c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1322c937d2bfSEd Tanous .canDelegateTop = true, 1323c937d2bfSEd Tanous .canDelegateSkip = true, 1324c937d2bfSEd Tanous }; 1325c937d2bfSEd Tanous query_param::Query delegatedQuery; 1326c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 13273ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 1328c4bf6374SJason M. Bills { 1329c4bf6374SJason M. Bills return; 1330c4bf6374SJason M. Bills } 133122d268cbSEd Tanous if (systemName != "system") 133222d268cbSEd Tanous { 133322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 133422d268cbSEd Tanous systemName); 133522d268cbSEd Tanous return; 133622d268cbSEd Tanous } 133722d268cbSEd Tanous 13385143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 13393648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 13403648c8beSEd Tanous 13417e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 13427e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1343c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1344c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1345c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1346029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1347c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1348c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1349c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1350cb92c03bSAndrew Geissler 13514978b63fSJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1352c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 13537e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 13547e860f15SJohn Edward Broadbent // entry 135595820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 135695820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1357b01bf299SEd Tanous uint64_t entryCount = 0; 1358cd225da8SJason M. Bills std::string logEntry; 135995820184SJason M. Bills 13607e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 13617e860f15SJohn Edward Broadbent // backwards 1362002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1363002d39b4SEd Tanous it++) 1364c4bf6374SJason M. Bills { 1365cd225da8SJason M. Bills std::ifstream logStream(*it); 136695820184SJason M. Bills if (!logStream.is_open()) 1367c4bf6374SJason M. Bills { 1368c4bf6374SJason M. Bills continue; 1369c4bf6374SJason M. Bills } 1370c4bf6374SJason M. Bills 1371e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1372e85d6b16SJason M. Bills bool firstEntry = true; 137395820184SJason M. Bills while (std::getline(logStream, logEntry)) 137495820184SJason M. Bills { 1375c4bf6374SJason M. Bills std::string idStr; 1376e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1377c4bf6374SJason M. Bills { 1378c4bf6374SJason M. Bills continue; 1379c4bf6374SJason M. Bills } 1380e85d6b16SJason M. Bills firstEntry = false; 1381e85d6b16SJason M. Bills 1382de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 1383ac992cdeSJason M. Bills LogParseError status = 1384ac992cdeSJason M. Bills fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); 1385ac992cdeSJason M. Bills if (status == LogParseError::messageIdNotInRegistry) 1386ac992cdeSJason M. Bills { 1387ac992cdeSJason M. Bills continue; 1388ac992cdeSJason M. Bills } 1389ac992cdeSJason M. Bills if (status != LogParseError::success) 1390c4bf6374SJason M. Bills { 1391c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1392c4bf6374SJason M. Bills return; 1393c4bf6374SJason M. Bills } 1394de703c5dSJason M. Bills 1395de703c5dSJason M. Bills entryCount++; 1396de703c5dSJason M. Bills // Handle paging using skip (number of entries to skip from the 1397de703c5dSJason M. Bills // start) and top (number of entries to display) 13983648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 1399de703c5dSJason M. Bills { 1400de703c5dSJason M. Bills continue; 1401de703c5dSJason M. Bills } 1402de703c5dSJason M. Bills 1403de703c5dSJason M. Bills logEntryArray.push_back(std::move(bmcLogEntry)); 1404c4bf6374SJason M. Bills } 140595820184SJason M. Bills } 1406c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 14073648c8beSEd Tanous if (skip + top < entryCount) 1408c4bf6374SJason M. Bills { 1409c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 14104978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries?$skip=" + 14113648c8beSEd Tanous std::to_string(skip + top); 1412c4bf6374SJason M. Bills } 14137e860f15SJohn Edward Broadbent }); 1414897967deSJason M. Bills } 1415897967deSJason M. Bills 14167e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1417897967deSJason M. Bills { 14187e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 141922d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1420ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 14217e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 142245ca1b86SEd Tanous [&app](const crow::Request& req, 14237e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 142422d268cbSEd Tanous const std::string& systemName, const std::string& param) { 14253ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 142645ca1b86SEd Tanous { 142745ca1b86SEd Tanous return; 142845ca1b86SEd Tanous } 142922d268cbSEd Tanous 143022d268cbSEd Tanous if (systemName != "system") 143122d268cbSEd Tanous { 143222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 143322d268cbSEd Tanous systemName); 143422d268cbSEd Tanous return; 143522d268cbSEd Tanous } 143622d268cbSEd Tanous 14377e860f15SJohn Edward Broadbent const std::string& targetID = param; 14388d1b46d7Szhanghch05 14397e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 14407e860f15SJohn Edward Broadbent // entry to find the target entry 1441897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1442897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1443897967deSJason M. Bills std::string logEntry; 1444897967deSJason M. Bills 14457e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 14467e860f15SJohn Edward Broadbent // backwards 1447002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1448002d39b4SEd Tanous it++) 1449897967deSJason M. Bills { 1450897967deSJason M. Bills std::ifstream logStream(*it); 1451897967deSJason M. Bills if (!logStream.is_open()) 1452897967deSJason M. Bills { 1453897967deSJason M. Bills continue; 1454897967deSJason M. Bills } 1455897967deSJason M. Bills 1456897967deSJason M. Bills // Reset the unique ID on the first entry 1457897967deSJason M. Bills bool firstEntry = true; 1458897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1459897967deSJason M. Bills { 1460897967deSJason M. Bills std::string idStr; 1461897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1462897967deSJason M. Bills { 1463897967deSJason M. Bills continue; 1464897967deSJason M. Bills } 1465897967deSJason M. Bills firstEntry = false; 1466897967deSJason M. Bills 1467897967deSJason M. Bills if (idStr == targetID) 1468897967deSJason M. Bills { 1469de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 1470ac992cdeSJason M. Bills LogParseError status = 1471ac992cdeSJason M. Bills fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); 1472ac992cdeSJason M. Bills if (status != LogParseError::success) 1473897967deSJason M. Bills { 1474897967deSJason M. Bills messages::internalError(asyncResp->res); 1475897967deSJason M. Bills return; 1476897967deSJason M. Bills } 1477d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcLogEntry); 1478897967deSJason M. Bills return; 1479897967deSJason M. Bills } 1480897967deSJason M. Bills } 1481897967deSJason M. Bills } 1482897967deSJason M. Bills // Requested ID was not found 14839db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", targetID); 14847e860f15SJohn Edward Broadbent }); 148508a4e4b5SAnthony Wilson } 148608a4e4b5SAnthony Wilson 14877e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 148808a4e4b5SAnthony Wilson { 148922d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/") 1490ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 1491002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1492002d39b4SEd Tanous [&app](const crow::Request& req, 149322d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 149422d268cbSEd Tanous const std::string& systemName) { 14953ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 149645ca1b86SEd Tanous { 149745ca1b86SEd Tanous return; 149845ca1b86SEd Tanous } 149922d268cbSEd Tanous if (systemName != "system") 150022d268cbSEd Tanous { 150122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 150222d268cbSEd Tanous systemName); 150322d268cbSEd Tanous return; 150422d268cbSEd Tanous } 150522d268cbSEd Tanous 15067e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 15077e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 150808a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 150908a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 151008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 151108a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 151208a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 151308a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 151408a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 151508a4e4b5SAnthony Wilson 1516cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1517cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1518cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1519cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1520914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& resp) { 1521cb92c03bSAndrew Geissler if (ec) 1522cb92c03bSAndrew Geissler { 1523cb92c03bSAndrew Geissler // TODO Handle for specific error code 1524cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1525002d39b4SEd Tanous << "getLogEntriesIfaceData resp_handler got error " << ec; 1526cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1527cb92c03bSAndrew Geissler return; 1528cb92c03bSAndrew Geissler } 1529002d39b4SEd Tanous nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 1530cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 15319eb808c1SEd Tanous for (const auto& objectPath : resp) 1532cb92c03bSAndrew Geissler { 1533914e2d5dSEd Tanous const uint32_t* id = nullptr; 1534c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1535c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1536914e2d5dSEd Tanous const std::string* severity = nullptr; 1537914e2d5dSEd Tanous const std::string* message = nullptr; 1538914e2d5dSEd Tanous const std::string* filePath = nullptr; 15399c11a172SVijay Lobo const std::string* resolution = nullptr; 154075710de2SXiaochao Ma bool resolved = false; 15419017faf2SAbhishek Patel const std::string* notify = nullptr; 15429017faf2SAbhishek Patel 15439eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 1544f86bb901SAdriana Kobylak { 1545f86bb901SAdriana Kobylak if (interfaceMap.first == 1546f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1547f86bb901SAdriana Kobylak { 1548002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 1549cb92c03bSAndrew Geissler { 1550cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1551cb92c03bSAndrew Geissler { 1552002d39b4SEd Tanous id = std::get_if<uint32_t>(&propertyMap.second); 1553cb92c03bSAndrew Geissler } 1554cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1555cb92c03bSAndrew Geissler { 1556002d39b4SEd Tanous timestamp = 1557002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 15587e860f15SJohn Edward Broadbent } 1559002d39b4SEd Tanous else if (propertyMap.first == "UpdateTimestamp") 15607e860f15SJohn Edward Broadbent { 1561002d39b4SEd Tanous updateTimestamp = 1562002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 15637e860f15SJohn Edward Broadbent } 15647e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 15657e860f15SJohn Edward Broadbent { 15667e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 15677e860f15SJohn Edward Broadbent &propertyMap.second); 15687e860f15SJohn Edward Broadbent } 15699c11a172SVijay Lobo else if (propertyMap.first == "Resolution") 15709c11a172SVijay Lobo { 15719c11a172SVijay Lobo resolution = std::get_if<std::string>( 15729c11a172SVijay Lobo &propertyMap.second); 15739c11a172SVijay Lobo } 15747e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 15757e860f15SJohn Edward Broadbent { 15767e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 15777e860f15SJohn Edward Broadbent &propertyMap.second); 15787e860f15SJohn Edward Broadbent } 15797e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 15807e860f15SJohn Edward Broadbent { 1581914e2d5dSEd Tanous const bool* resolveptr = 1582002d39b4SEd Tanous std::get_if<bool>(&propertyMap.second); 15837e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 15847e860f15SJohn Edward Broadbent { 1585002d39b4SEd Tanous messages::internalError(asyncResp->res); 15867e860f15SJohn Edward Broadbent return; 15877e860f15SJohn Edward Broadbent } 15887e860f15SJohn Edward Broadbent resolved = *resolveptr; 15897e860f15SJohn Edward Broadbent } 15909017faf2SAbhishek Patel else if (propertyMap.first == 15919017faf2SAbhishek Patel "ServiceProviderNotify") 15929017faf2SAbhishek Patel { 15939017faf2SAbhishek Patel notify = std::get_if<std::string>( 15949017faf2SAbhishek Patel &propertyMap.second); 15959017faf2SAbhishek Patel if (notify == nullptr) 15969017faf2SAbhishek Patel { 15979017faf2SAbhishek Patel messages::internalError(asyncResp->res); 15989017faf2SAbhishek Patel return; 15999017faf2SAbhishek Patel } 16009017faf2SAbhishek Patel } 16017e860f15SJohn Edward Broadbent } 16027e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 16037e860f15SJohn Edward Broadbent severity == nullptr) 16047e860f15SJohn Edward Broadbent { 16057e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 16067e860f15SJohn Edward Broadbent return; 16077e860f15SJohn Edward Broadbent } 16087e860f15SJohn Edward Broadbent } 16097e860f15SJohn Edward Broadbent else if (interfaceMap.first == 16107e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 16117e860f15SJohn Edward Broadbent { 1612002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 16137e860f15SJohn Edward Broadbent { 16147e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 16157e860f15SJohn Edward Broadbent { 16167e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 16177e860f15SJohn Edward Broadbent &propertyMap.second); 16187e860f15SJohn Edward Broadbent } 16197e860f15SJohn Edward Broadbent } 16207e860f15SJohn Edward Broadbent } 16217e860f15SJohn Edward Broadbent } 16227e860f15SJohn Edward Broadbent // Object path without the 16237e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 16247e860f15SJohn Edward Broadbent // and continue. 16257e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 1626c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1627c419c759SEd Tanous updateTimestamp == nullptr) 16287e860f15SJohn Edward Broadbent { 16297e860f15SJohn Edward Broadbent continue; 16307e860f15SJohn Edward Broadbent } 16317e860f15SJohn Edward Broadbent entriesArray.push_back({}); 16327e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 16339c11a172SVijay Lobo thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 16347e860f15SJohn Edward Broadbent thisEntry["@odata.id"] = 16350fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 16367e860f15SJohn Edward Broadbent std::to_string(*id); 16377e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 16387e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 16397e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 16407e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 16419c11a172SVijay Lobo if ((resolution != nullptr) && (!(*resolution).empty())) 16429c11a172SVijay Lobo { 16439c11a172SVijay Lobo thisEntry["Resolution"] = *resolution; 16449c11a172SVijay Lobo } 16459017faf2SAbhishek Patel std::optional<bool> notifyAction = 16469017faf2SAbhishek Patel getProviderNotifyAction(*notify); 16479017faf2SAbhishek Patel if (notifyAction) 16489017faf2SAbhishek Patel { 16499017faf2SAbhishek Patel thisEntry["ServiceProviderNotified"] = *notifyAction; 16509017faf2SAbhishek Patel } 16517e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 16527e860f15SJohn Edward Broadbent thisEntry["Severity"] = 16537e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 16547e860f15SJohn Edward Broadbent thisEntry["Created"] = 16552b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*timestamp); 16567e860f15SJohn Edward Broadbent thisEntry["Modified"] = 16572b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*updateTimestamp); 16587e860f15SJohn Edward Broadbent if (filePath != nullptr) 16597e860f15SJohn Edward Broadbent { 16607e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 16610fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 16627e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 16637e860f15SJohn Edward Broadbent } 16647e860f15SJohn Edward Broadbent } 1665002d39b4SEd Tanous std::sort( 1666002d39b4SEd Tanous entriesArray.begin(), entriesArray.end(), 1667002d39b4SEd Tanous [](const nlohmann::json& left, const nlohmann::json& right) { 16687e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 16697e860f15SJohn Edward Broadbent }); 16707e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 16717e860f15SJohn Edward Broadbent entriesArray.size(); 16727e860f15SJohn Edward Broadbent }, 16737e860f15SJohn Edward Broadbent "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 16747e860f15SJohn Edward Broadbent "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 16757e860f15SJohn Edward Broadbent }); 16767e860f15SJohn Edward Broadbent } 16777e860f15SJohn Edward Broadbent 16787e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 16797e860f15SJohn Edward Broadbent { 16807e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 168122d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1682ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 1683002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1684002d39b4SEd Tanous [&app](const crow::Request& req, 16857e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 168622d268cbSEd Tanous const std::string& systemName, const std::string& param) { 16873ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 16887e860f15SJohn Edward Broadbent { 168945ca1b86SEd Tanous return; 169045ca1b86SEd Tanous } 169122d268cbSEd Tanous if (systemName != "system") 169222d268cbSEd Tanous { 169322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 169422d268cbSEd Tanous systemName); 169522d268cbSEd Tanous return; 169622d268cbSEd Tanous } 169722d268cbSEd Tanous 16987e860f15SJohn Edward Broadbent std::string entryID = param; 16997e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 17007e860f15SJohn Edward Broadbent 17017e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 17027e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 1703d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1704d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, "xyz.openbmc_project.Logging", 1705d1bde9e5SKrzysztof Grobelny "/xyz/openbmc_project/logging/entry/" + entryID, "", 1706002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec, 1707b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 17087e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 17097e860f15SJohn Edward Broadbent { 1710d1bde9e5SKrzysztof Grobelny messages::resourceNotFound(asyncResp->res, "EventLogEntry", 1711d1bde9e5SKrzysztof Grobelny entryID); 17127e860f15SJohn Edward Broadbent return; 17137e860f15SJohn Edward Broadbent } 17147e860f15SJohn Edward Broadbent if (ec) 17157e860f15SJohn Edward Broadbent { 17160fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1717002d39b4SEd Tanous << "EventLogEntry (DBus) resp_handler got error " << ec; 17187e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 17197e860f15SJohn Edward Broadbent return; 17207e860f15SJohn Edward Broadbent } 1721914e2d5dSEd Tanous const uint32_t* id = nullptr; 1722c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1723c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1724914e2d5dSEd Tanous const std::string* severity = nullptr; 1725914e2d5dSEd Tanous const std::string* message = nullptr; 1726914e2d5dSEd Tanous const std::string* filePath = nullptr; 17279c11a172SVijay Lobo const std::string* resolution = nullptr; 17287e860f15SJohn Edward Broadbent bool resolved = false; 17299017faf2SAbhishek Patel const std::string* notify = nullptr; 17307e860f15SJohn Edward Broadbent 1731d1bde9e5SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1732d1bde9e5SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), resp, "Id", id, "Timestamp", 1733d1bde9e5SKrzysztof Grobelny timestamp, "UpdateTimestamp", updateTimestamp, "Severity", 17349c11a172SVijay Lobo severity, "Message", message, "Resolved", resolved, 17359017faf2SAbhishek Patel "Resolution", resolution, "Path", filePath, 17369017faf2SAbhishek Patel "ServiceProviderNotify", notify); 1737d1bde9e5SKrzysztof Grobelny 1738d1bde9e5SKrzysztof Grobelny if (!success) 173975710de2SXiaochao Ma { 174075710de2SXiaochao Ma messages::internalError(asyncResp->res); 174175710de2SXiaochao Ma return; 174275710de2SXiaochao Ma } 1743d1bde9e5SKrzysztof Grobelny 1744002d39b4SEd Tanous if (id == nullptr || message == nullptr || severity == nullptr || 17459017faf2SAbhishek Patel timestamp == nullptr || updateTimestamp == nullptr || 17469017faf2SAbhishek Patel notify == nullptr) 1747f86bb901SAdriana Kobylak { 1748ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1749271584abSEd Tanous return; 1750271584abSEd Tanous } 17519017faf2SAbhishek Patel 1752f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 17539c11a172SVijay Lobo "#LogEntry.v1_9_0.LogEntry"; 1754f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.id"] = 17550fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 1756f86bb901SAdriana Kobylak std::to_string(*id); 175745ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Event Log Entry"; 1758f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1759f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1760f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 17619017faf2SAbhishek Patel std::optional<bool> notifyAction = getProviderNotifyAction(*notify); 17629017faf2SAbhishek Patel if (notifyAction) 17639017faf2SAbhishek Patel { 17649017faf2SAbhishek Patel asyncResp->res.jsonValue["ServiceProviderNotified"] = 17659017faf2SAbhishek Patel *notifyAction; 17669017faf2SAbhishek Patel } 17679c11a172SVijay Lobo if ((resolution != nullptr) && (!(*resolution).empty())) 17689c11a172SVijay Lobo { 17699c11a172SVijay Lobo asyncResp->res.jsonValue["Resolution"] = *resolution; 17709c11a172SVijay Lobo } 1771f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1772f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1773f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1774f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 17752b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*timestamp); 1776f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 17772b82937eSEd Tanous redfish::time_utils::getDateTimeUintMs(*updateTimestamp); 1778f86bb901SAdriana Kobylak if (filePath != nullptr) 1779f86bb901SAdriana Kobylak { 1780f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 1781e7dbd530SPotin Lai "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 1782e7dbd530SPotin Lai std::to_string(*id) + "/attachment"; 1783f86bb901SAdriana Kobylak } 1784d1bde9e5SKrzysztof Grobelny }); 17857e860f15SJohn Edward Broadbent }); 1786336e96c6SChicago Duan 17877e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 178822d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1789ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 17907e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 179145ca1b86SEd Tanous [&app](const crow::Request& req, 17927e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 179322d268cbSEd Tanous const std::string& systemName, const std::string& entryId) { 17943ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 179545ca1b86SEd Tanous { 179645ca1b86SEd Tanous return; 179745ca1b86SEd Tanous } 179822d268cbSEd Tanous if (systemName != "system") 179922d268cbSEd Tanous { 180022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 180122d268cbSEd Tanous systemName); 180222d268cbSEd Tanous return; 180322d268cbSEd Tanous } 180475710de2SXiaochao Ma std::optional<bool> resolved; 180575710de2SXiaochao Ma 180615ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", 18077e860f15SJohn Edward Broadbent resolved)) 180875710de2SXiaochao Ma { 180975710de2SXiaochao Ma return; 181075710de2SXiaochao Ma } 181175710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 181275710de2SXiaochao Ma 181375710de2SXiaochao Ma crow::connections::systemBus->async_method_call( 18144f48d5f6SEd Tanous [asyncResp, entryId](const boost::system::error_code ec) { 181575710de2SXiaochao Ma if (ec) 181675710de2SXiaochao Ma { 181775710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 181875710de2SXiaochao Ma messages::internalError(asyncResp->res); 181975710de2SXiaochao Ma return; 182075710de2SXiaochao Ma } 182175710de2SXiaochao Ma }, 182275710de2SXiaochao Ma "xyz.openbmc_project.Logging", 182375710de2SXiaochao Ma "/xyz/openbmc_project/logging/entry/" + entryId, 182475710de2SXiaochao Ma "org.freedesktop.DBus.Properties", "Set", 182575710de2SXiaochao Ma "xyz.openbmc_project.Logging.Entry", "Resolved", 1826168e20c1SEd Tanous dbus::utility::DbusVariantType(*resolved)); 18277e860f15SJohn Edward Broadbent }); 182875710de2SXiaochao Ma 18297e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 183022d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/") 1831ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1832ed398213SEd Tanous 1833002d39b4SEd Tanous .methods(boost::beast::http::verb::delete_)( 1834002d39b4SEd Tanous [&app](const crow::Request& req, 1835002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 183622d268cbSEd Tanous const std::string& systemName, const std::string& param) { 18373ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1838336e96c6SChicago Duan { 183945ca1b86SEd Tanous return; 184045ca1b86SEd Tanous } 184122d268cbSEd Tanous if (systemName != "system") 184222d268cbSEd Tanous { 184322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 184422d268cbSEd Tanous systemName); 184522d268cbSEd Tanous return; 184622d268cbSEd Tanous } 1847336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1848336e96c6SChicago Duan 18497e860f15SJohn Edward Broadbent std::string entryID = param; 1850336e96c6SChicago Duan 1851336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1852336e96c6SChicago Duan 1853336e96c6SChicago Duan // Process response from Logging service. 1854002d39b4SEd Tanous auto respHandler = 1855002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec) { 1856002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1857336e96c6SChicago Duan if (ec) 1858336e96c6SChicago Duan { 18593de8d8baSGeorge Liu if (ec.value() == EBADR) 18603de8d8baSGeorge Liu { 186145ca1b86SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 186245ca1b86SEd Tanous entryID); 18633de8d8baSGeorge Liu return; 18643de8d8baSGeorge Liu } 1865336e96c6SChicago Duan // TODO Handle for specific error code 18660fda0f12SGeorge Liu BMCWEB_LOG_ERROR 18670fda0f12SGeorge Liu << "EventLogEntry (DBus) doDelete respHandler got error " 1868336e96c6SChicago Duan << ec; 1869336e96c6SChicago Duan asyncResp->res.result( 1870336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1871336e96c6SChicago Duan return; 1872336e96c6SChicago Duan } 1873336e96c6SChicago Duan 1874336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1875336e96c6SChicago Duan }; 1876336e96c6SChicago Duan 1877336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1878336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1879336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1880336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1881336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 18827e860f15SJohn Edward Broadbent }); 1883400fd1fbSAdriana Kobylak } 1884400fd1fbSAdriana Kobylak 18857e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1886400fd1fbSAdriana Kobylak { 18870fda0f12SGeorge Liu BMCWEB_ROUTE( 18880fda0f12SGeorge Liu app, 188922d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment") 1890ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 18917e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 189245ca1b86SEd Tanous [&app](const crow::Request& req, 18937e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 189422d268cbSEd Tanous const std::string& systemName, const std::string& param) { 18953ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 18967e860f15SJohn Edward Broadbent { 189745ca1b86SEd Tanous return; 189845ca1b86SEd Tanous } 189999351cd8SEd Tanous if (http_helpers::isContentTypeAllowed( 190099351cd8SEd Tanous req.getHeaderValue("Accept"), 19014a0e1a0cSEd Tanous http_helpers::ContentType::OctetStream, true)) 1902400fd1fbSAdriana Kobylak { 1903002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 1904400fd1fbSAdriana Kobylak return; 1905400fd1fbSAdriana Kobylak } 190622d268cbSEd Tanous if (systemName != "system") 190722d268cbSEd Tanous { 190822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 190922d268cbSEd Tanous systemName); 191022d268cbSEd Tanous return; 191122d268cbSEd Tanous } 1912400fd1fbSAdriana Kobylak 19137e860f15SJohn Edward Broadbent std::string entryID = param; 1914400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1915400fd1fbSAdriana Kobylak 1916400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 1917002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec, 1918400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 1919400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 1920400fd1fbSAdriana Kobylak { 1921002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "EventLogAttachment", 1922002d39b4SEd Tanous entryID); 1923400fd1fbSAdriana Kobylak return; 1924400fd1fbSAdriana Kobylak } 1925400fd1fbSAdriana Kobylak if (ec) 1926400fd1fbSAdriana Kobylak { 1927400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1928400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1929400fd1fbSAdriana Kobylak return; 1930400fd1fbSAdriana Kobylak } 1931400fd1fbSAdriana Kobylak 1932400fd1fbSAdriana Kobylak int fd = -1; 1933400fd1fbSAdriana Kobylak fd = dup(unixfd); 1934400fd1fbSAdriana Kobylak if (fd == -1) 1935400fd1fbSAdriana Kobylak { 1936400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1937400fd1fbSAdriana Kobylak return; 1938400fd1fbSAdriana Kobylak } 1939400fd1fbSAdriana Kobylak 1940400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 1941400fd1fbSAdriana Kobylak if (size == -1) 1942400fd1fbSAdriana Kobylak { 1943400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1944400fd1fbSAdriana Kobylak return; 1945400fd1fbSAdriana Kobylak } 1946400fd1fbSAdriana Kobylak 1947400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 1948400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 1949400fd1fbSAdriana Kobylak if (size > maxFileSize) 1950400fd1fbSAdriana Kobylak { 1951002d39b4SEd Tanous BMCWEB_LOG_ERROR << "File size exceeds maximum allowed size of " 1952400fd1fbSAdriana Kobylak << maxFileSize; 1953400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1954400fd1fbSAdriana Kobylak return; 1955400fd1fbSAdriana Kobylak } 1956400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 1957400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 1958400fd1fbSAdriana Kobylak if (rc == -1) 1959400fd1fbSAdriana Kobylak { 1960400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1961400fd1fbSAdriana Kobylak return; 1962400fd1fbSAdriana Kobylak } 1963400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 1964400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 1965400fd1fbSAdriana Kobylak { 1966400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1967400fd1fbSAdriana Kobylak return; 1968400fd1fbSAdriana Kobylak } 1969400fd1fbSAdriana Kobylak close(fd); 1970400fd1fbSAdriana Kobylak 1971400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 1972002d39b4SEd Tanous std::string output = crow::utility::base64encode(strData); 1973400fd1fbSAdriana Kobylak 1974d9f6c621SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::content_type, 1975400fd1fbSAdriana Kobylak "application/octet-stream"); 1976d9f6c621SEd Tanous asyncResp->res.addHeader( 1977d9f6c621SEd Tanous boost::beast::http::field::content_transfer_encoding, "Base64"); 1978400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 1979400fd1fbSAdriana Kobylak }, 1980400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 1981400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 1982400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 19837e860f15SJohn Edward Broadbent }); 19841da66f75SEd Tanous } 19851da66f75SEd Tanous 1986b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 1987b7028ebfSSpencer Ku 1988b7028ebfSSpencer Ku inline bool 1989b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 1990b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 1991b7028ebfSSpencer Ku { 1992b7028ebfSSpencer Ku std::error_code ec; 1993b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 1994b7028ebfSSpencer Ku if (ec) 1995b7028ebfSSpencer Ku { 1996b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << ec.message(); 1997b7028ebfSSpencer Ku return false; 1998b7028ebfSSpencer Ku } 1999b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 2000b7028ebfSSpencer Ku { 2001b7028ebfSSpencer Ku std::string filename = it.path().filename(); 2002b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 2003b7028ebfSSpencer Ku // path 200411ba3979SEd Tanous if (filename.starts_with("log")) 2005b7028ebfSSpencer Ku { 2006b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 2007b7028ebfSSpencer Ku } 2008b7028ebfSSpencer Ku } 2009b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 2010b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 2011b7028ebfSSpencer Ku // descending order. 2012b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 2013b7028ebfSSpencer Ku AlphanumLess<std::string>()); 2014b7028ebfSSpencer Ku 2015b7028ebfSSpencer Ku return true; 2016b7028ebfSSpencer Ku } 2017b7028ebfSSpencer Ku 201802cad96eSEd Tanous inline bool getHostLoggerEntries( 201902cad96eSEd Tanous const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip, 202002cad96eSEd Tanous uint64_t top, std::vector<std::string>& logEntries, size_t& logCount) 2021b7028ebfSSpencer Ku { 2022b7028ebfSSpencer Ku GzFileReader logFile; 2023b7028ebfSSpencer Ku 2024b7028ebfSSpencer Ku // Go though all log files and expose host logs. 2025b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 2026b7028ebfSSpencer Ku { 2027b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 2028b7028ebfSSpencer Ku { 2029b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to expose host logs"; 2030b7028ebfSSpencer Ku return false; 2031b7028ebfSSpencer Ku } 2032b7028ebfSSpencer Ku } 2033b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 2034b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 2035b7028ebfSSpencer Ku if (!lastMessage.empty()) 2036b7028ebfSSpencer Ku { 2037b7028ebfSSpencer Ku logCount++; 2038b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 2039b7028ebfSSpencer Ku { 2040b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 2041b7028ebfSSpencer Ku } 2042b7028ebfSSpencer Ku } 2043b7028ebfSSpencer Ku return true; 2044b7028ebfSSpencer Ku } 2045b7028ebfSSpencer Ku 2046b7028ebfSSpencer Ku inline void fillHostLoggerEntryJson(const std::string& logEntryID, 2047b7028ebfSSpencer Ku const std::string& msg, 20486d6574c9SJason M. Bills nlohmann::json::object_t& logEntryJson) 2049b7028ebfSSpencer Ku { 2050b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 20519c11a172SVijay Lobo logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 20526d6574c9SJason M. Bills logEntryJson["@odata.id"] = 2053b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/" + 20546d6574c9SJason M. Bills logEntryID; 20556d6574c9SJason M. Bills logEntryJson["Name"] = "Host Logger Entry"; 20566d6574c9SJason M. Bills logEntryJson["Id"] = logEntryID; 20576d6574c9SJason M. Bills logEntryJson["Message"] = msg; 20586d6574c9SJason M. Bills logEntryJson["EntryType"] = "Oem"; 20596d6574c9SJason M. Bills logEntryJson["Severity"] = "OK"; 20606d6574c9SJason M. Bills logEntryJson["OemRecordFormat"] = "Host Logger Entry"; 2061b7028ebfSSpencer Ku } 2062b7028ebfSSpencer Ku 2063b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 2064b7028ebfSSpencer Ku { 206522d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/") 2066b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 20671476687dSEd Tanous .methods(boost::beast::http::verb::get)( 20681476687dSEd Tanous [&app](const crow::Request& req, 206922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 207022d268cbSEd Tanous const std::string& systemName) { 20713ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 207245ca1b86SEd Tanous { 207345ca1b86SEd Tanous return; 207445ca1b86SEd Tanous } 207522d268cbSEd Tanous if (systemName != "system") 207622d268cbSEd Tanous { 207722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 207822d268cbSEd Tanous systemName); 207922d268cbSEd Tanous return; 208022d268cbSEd Tanous } 2081b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 2082b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"; 2083b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 2084b7028ebfSSpencer Ku "#LogService.v1_1_0.LogService"; 2085b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 2086b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 2087b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 20881476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 20891476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 2090b7028ebfSSpencer Ku }); 2091b7028ebfSSpencer Ku } 2092b7028ebfSSpencer Ku 2093b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 2094b7028ebfSSpencer Ku { 2095b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 209622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/") 2097b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2098002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2099002d39b4SEd Tanous [&app](const crow::Request& req, 210022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 210122d268cbSEd Tanous const std::string& systemName) { 2102c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2103c937d2bfSEd Tanous .canDelegateTop = true, 2104c937d2bfSEd Tanous .canDelegateSkip = true, 2105c937d2bfSEd Tanous }; 2106c937d2bfSEd Tanous query_param::Query delegatedQuery; 2107c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 21083ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 2109b7028ebfSSpencer Ku { 2110b7028ebfSSpencer Ku return; 2111b7028ebfSSpencer Ku } 211222d268cbSEd Tanous if (systemName != "system") 211322d268cbSEd Tanous { 211422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 211522d268cbSEd Tanous systemName); 211622d268cbSEd Tanous return; 211722d268cbSEd Tanous } 2118b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 2119b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 2120b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 2121b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 2122b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 2123b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 2124b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 21250fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2126b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 2127b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 2128b7028ebfSSpencer Ku 2129b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2130b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2131b7028ebfSSpencer Ku { 2132b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 2133b7028ebfSSpencer Ku return; 2134b7028ebfSSpencer Ku } 21353648c8beSEd Tanous // If we weren't provided top and skip limits, use the defaults. 21363648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 21375143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 2138b7028ebfSSpencer Ku size_t logCount = 0; 2139b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 2140b7028ebfSSpencer Ku // control by skip and top. 2141b7028ebfSSpencer Ku std::vector<std::string> logEntries; 21423648c8beSEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries, 21433648c8beSEd Tanous logCount)) 2144b7028ebfSSpencer Ku { 2145b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2146b7028ebfSSpencer Ku return; 2147b7028ebfSSpencer Ku } 2148b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 2149b7028ebfSSpencer Ku // log count 215026f6976fSEd Tanous if (logEntries.empty()) 2151b7028ebfSSpencer Ku { 2152b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 2153b7028ebfSSpencer Ku return; 2154b7028ebfSSpencer Ku } 215526f6976fSEd Tanous if (!logEntries.empty()) 2156b7028ebfSSpencer Ku { 2157b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 2158b7028ebfSSpencer Ku { 21596d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 21603648c8beSEd Tanous fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i], 21613648c8beSEd Tanous hostLogEntry); 21626d6574c9SJason M. Bills logEntryArray.push_back(std::move(hostLogEntry)); 2163b7028ebfSSpencer Ku } 2164b7028ebfSSpencer Ku 2165b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 21663648c8beSEd Tanous if (skip + top < logCount) 2167b7028ebfSSpencer Ku { 2168b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 21690fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/HostLogger/Entries?$skip=" + 21703648c8beSEd Tanous std::to_string(skip + top); 2171b7028ebfSSpencer Ku } 2172b7028ebfSSpencer Ku } 2173b7028ebfSSpencer Ku }); 2174b7028ebfSSpencer Ku } 2175b7028ebfSSpencer Ku 2176b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 2177b7028ebfSSpencer Ku { 2178b7028ebfSSpencer Ku BMCWEB_ROUTE( 217922d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/") 2180b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2181b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 218245ca1b86SEd Tanous [&app](const crow::Request& req, 2183b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 218422d268cbSEd Tanous const std::string& systemName, const std::string& param) { 21853ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 218645ca1b86SEd Tanous { 218745ca1b86SEd Tanous return; 218845ca1b86SEd Tanous } 218922d268cbSEd Tanous if (systemName != "system") 219022d268cbSEd Tanous { 219122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 219222d268cbSEd Tanous systemName); 219322d268cbSEd Tanous return; 219422d268cbSEd Tanous } 2195b7028ebfSSpencer Ku const std::string& targetID = param; 2196b7028ebfSSpencer Ku 2197b7028ebfSSpencer Ku uint64_t idInt = 0; 2198ca45aa3cSEd Tanous 2199ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 2200ca45aa3cSEd Tanous const char* end = targetID.data() + targetID.size(); 2201ca45aa3cSEd Tanous 2202ca45aa3cSEd Tanous auto [ptr, ec] = std::from_chars(targetID.data(), end, idInt); 22039db4ba25SJiaqing Zhao if (ec == std::errc::invalid_argument || 22049db4ba25SJiaqing Zhao ec == std::errc::result_out_of_range) 2205b7028ebfSSpencer Ku { 22069db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", param); 2207b7028ebfSSpencer Ku return; 2208b7028ebfSSpencer Ku } 2209b7028ebfSSpencer Ku 2210b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2211b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2212b7028ebfSSpencer Ku { 2213b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 2214b7028ebfSSpencer Ku return; 2215b7028ebfSSpencer Ku } 2216b7028ebfSSpencer Ku 2217b7028ebfSSpencer Ku size_t logCount = 0; 22183648c8beSEd Tanous size_t top = 1; 2219b7028ebfSSpencer Ku std::vector<std::string> logEntries; 2220b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 2221b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 2222b7028ebfSSpencer Ku // get that entry 2223002d39b4SEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries, 2224002d39b4SEd Tanous logCount)) 2225b7028ebfSSpencer Ku { 2226b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2227b7028ebfSSpencer Ku return; 2228b7028ebfSSpencer Ku } 2229b7028ebfSSpencer Ku 2230b7028ebfSSpencer Ku if (!logEntries.empty()) 2231b7028ebfSSpencer Ku { 22326d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 22336d6574c9SJason M. Bills fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry); 22346d6574c9SJason M. Bills asyncResp->res.jsonValue.update(hostLogEntry); 2235b7028ebfSSpencer Ku return; 2236b7028ebfSSpencer Ku } 2237b7028ebfSSpencer Ku 2238b7028ebfSSpencer Ku // Requested ID was not found 22399db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", param); 2240b7028ebfSSpencer Ku }); 2241b7028ebfSSpencer Ku } 2242b7028ebfSSpencer Ku 2243dd72e87bSClaire Weinan inline void handleBMCLogServicesCollectionGet( 2244fdd26906SClaire Weinan crow::App& app, const crow::Request& req, 2245fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 22461da66f75SEd Tanous { 22473ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 224845ca1b86SEd Tanous { 224945ca1b86SEd Tanous return; 225045ca1b86SEd Tanous } 22517e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 22527e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2253e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 22541da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2255e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 2256e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 2257002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 2258e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 22591da66f75SEd Tanous "Collection of LogServices for this Manager"; 2260002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 2261c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 2262fdd26906SClaire Weinan 2263c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 2264613dabeaSEd Tanous nlohmann::json::object_t journal; 2265613dabeaSEd Tanous journal["@odata.id"] = "/redfish/v1/Managers/bmc/LogServices/Journal"; 2266613dabeaSEd Tanous logServiceArray.push_back(std::move(journal)); 2267c4bf6374SJason M. Bills #endif 2268fdd26906SClaire Weinan 2269fdd26906SClaire Weinan asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); 2270fdd26906SClaire Weinan 2271fdd26906SClaire Weinan #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 227215912159SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 22737a1dbc48SGeorge Liu "xyz.openbmc_project.Collection.DeleteAll"}; 22747a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 22757a1dbc48SGeorge Liu "/xyz/openbmc_project/dump", 0, interfaces, 2276fdd26906SClaire Weinan [asyncResp]( 22777a1dbc48SGeorge Liu const boost::system::error_code& ec, 2278fdd26906SClaire Weinan const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 2279fdd26906SClaire Weinan if (ec) 2280fdd26906SClaire Weinan { 2281fdd26906SClaire Weinan BMCWEB_LOG_ERROR 2282dd72e87bSClaire Weinan << "handleBMCLogServicesCollectionGet respHandler got error " 2283fdd26906SClaire Weinan << ec; 2284fdd26906SClaire Weinan // Assume that getting an error simply means there are no dump 2285fdd26906SClaire Weinan // LogServices. Return without adding any error response. 2286fdd26906SClaire Weinan return; 2287fdd26906SClaire Weinan } 2288fdd26906SClaire Weinan 2289fdd26906SClaire Weinan nlohmann::json& logServiceArrayLocal = 2290fdd26906SClaire Weinan asyncResp->res.jsonValue["Members"]; 2291fdd26906SClaire Weinan 2292fdd26906SClaire Weinan for (const std::string& path : subTreePaths) 2293fdd26906SClaire Weinan { 2294fdd26906SClaire Weinan if (path == "/xyz/openbmc_project/dump/bmc") 2295fdd26906SClaire Weinan { 2296613dabeaSEd Tanous nlohmann::json::object_t member; 2297613dabeaSEd Tanous member["@odata.id"] = 2298613dabeaSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Dump"; 2299613dabeaSEd Tanous logServiceArrayLocal.push_back(std::move(member)); 2300fdd26906SClaire Weinan } 2301fdd26906SClaire Weinan else if (path == "/xyz/openbmc_project/dump/faultlog") 2302fdd26906SClaire Weinan { 2303613dabeaSEd Tanous nlohmann::json::object_t member; 2304613dabeaSEd Tanous member["@odata.id"] = 2305613dabeaSEd Tanous "/redfish/v1/Managers/bmc/LogServices/FaultLog"; 2306613dabeaSEd Tanous logServiceArrayLocal.push_back(std::move(member)); 2307fdd26906SClaire Weinan } 2308fdd26906SClaire Weinan } 2309fdd26906SClaire Weinan 2310e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2311fdd26906SClaire Weinan logServiceArrayLocal.size(); 23127a1dbc48SGeorge Liu }); 2313fdd26906SClaire Weinan #endif 2314fdd26906SClaire Weinan } 2315fdd26906SClaire Weinan 2316fdd26906SClaire Weinan inline void requestRoutesBMCLogServiceCollection(App& app) 2317fdd26906SClaire Weinan { 2318fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 2319fdd26906SClaire Weinan .privileges(redfish::privileges::getLogServiceCollection) 2320fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2321dd72e87bSClaire Weinan std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app))); 2322e1f26343SJason M. Bills } 2323e1f26343SJason M. Bills 23247e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 2325e1f26343SJason M. Bills { 23267e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 2327ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 23287e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 232945ca1b86SEd Tanous [&app](const crow::Request& req, 233045ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 23313ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 23327e860f15SJohn Edward Broadbent { 233345ca1b86SEd Tanous return; 233445ca1b86SEd Tanous } 2335e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2336e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 23370f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 23380f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 2339002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 2340002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 2341c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 2342e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 23437c8c4058STejas Patil 23447c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 23452b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 2346002d39b4SEd Tanous asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 23477c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 23487c8c4058STejas Patil redfishDateTimeOffset.second; 23497c8c4058STejas Patil 23501476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 23511476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 23527e860f15SJohn Edward Broadbent }); 2353e1f26343SJason M. Bills } 2354e1f26343SJason M. Bills 23553a48b3a2SJason M. Bills static int 23563a48b3a2SJason M. Bills fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 2357e1f26343SJason M. Bills sd_journal* journal, 23583a48b3a2SJason M. Bills nlohmann::json::object_t& bmcJournalLogEntryJson) 2359e1f26343SJason M. Bills { 2360e1f26343SJason M. Bills // Get the Log Entry contents 2361e1f26343SJason M. Bills int ret = 0; 2362e1f26343SJason M. Bills 2363a8fe54f0SJason M. Bills std::string message; 2364a8fe54f0SJason M. Bills std::string_view syslogID; 2365a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 2366a8fe54f0SJason M. Bills if (ret < 0) 2367a8fe54f0SJason M. Bills { 2368a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 2369a8fe54f0SJason M. Bills << strerror(-ret); 2370a8fe54f0SJason M. Bills } 2371a8fe54f0SJason M. Bills if (!syslogID.empty()) 2372a8fe54f0SJason M. Bills { 2373a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 2374a8fe54f0SJason M. Bills } 2375a8fe54f0SJason M. Bills 237639e77504SEd Tanous std::string_view msg; 237716428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 2378e1f26343SJason M. Bills if (ret < 0) 2379e1f26343SJason M. Bills { 2380e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 2381e1f26343SJason M. Bills return 1; 2382e1f26343SJason M. Bills } 2383a8fe54f0SJason M. Bills message += std::string(msg); 2384e1f26343SJason M. Bills 2385e1f26343SJason M. Bills // Get the severity from the PRIORITY field 2386271584abSEd Tanous long int severity = 8; // Default to an invalid priority 238716428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 2388e1f26343SJason M. Bills if (ret < 0) 2389e1f26343SJason M. Bills { 2390e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 2391e1f26343SJason M. Bills } 2392e1f26343SJason M. Bills 2393e1f26343SJason M. Bills // Get the Created time from the timestamp 239416428a1aSJason M. Bills std::string entryTimeStr; 239516428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 2396e1f26343SJason M. Bills { 239716428a1aSJason M. Bills return 1; 2398e1f26343SJason M. Bills } 2399e1f26343SJason M. Bills 2400e1f26343SJason M. Bills // Fill in the log entry with the gathered data 24019c11a172SVijay Lobo bmcJournalLogEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 240284afc48bSJason M. Bills bmcJournalLogEntryJson["@odata.id"] = 240384afc48bSJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 240484afc48bSJason M. Bills bmcJournalLogEntryID; 240584afc48bSJason M. Bills bmcJournalLogEntryJson["Name"] = "BMC Journal Entry"; 240684afc48bSJason M. Bills bmcJournalLogEntryJson["Id"] = bmcJournalLogEntryID; 240784afc48bSJason M. Bills bmcJournalLogEntryJson["Message"] = std::move(message); 240884afc48bSJason M. Bills bmcJournalLogEntryJson["EntryType"] = "Oem"; 240984afc48bSJason M. Bills bmcJournalLogEntryJson["Severity"] = severity <= 2 ? "Critical" 2410738c1e61SPatrick Williams : severity <= 4 ? "Warning" 241184afc48bSJason M. Bills : "OK"; 241284afc48bSJason M. Bills bmcJournalLogEntryJson["OemRecordFormat"] = "BMC Journal Entry"; 241384afc48bSJason M. Bills bmcJournalLogEntryJson["Created"] = std::move(entryTimeStr); 2414e1f26343SJason M. Bills return 0; 2415e1f26343SJason M. Bills } 2416e1f26343SJason M. Bills 24177e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 2418e1f26343SJason M. Bills { 24197e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 2420ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 2421002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2422002d39b4SEd Tanous [&app](const crow::Request& req, 2423002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2424c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2425c937d2bfSEd Tanous .canDelegateTop = true, 2426c937d2bfSEd Tanous .canDelegateSkip = true, 2427c937d2bfSEd Tanous }; 2428c937d2bfSEd Tanous query_param::Query delegatedQuery; 2429c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 24303ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 2431193ad2faSJason M. Bills { 2432193ad2faSJason M. Bills return; 2433193ad2faSJason M. Bills } 24343648c8beSEd Tanous 24353648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 24365143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 24373648c8beSEd Tanous 24387e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 24397e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2440e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2441e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 24420f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 24430f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 2444e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 2445e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2446e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 24470fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2448e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2449e1f26343SJason M. Bills 24507e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 24517e860f15SJohn Edward Broadbent // unique ID for each entry 2452e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2453e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2454e1f26343SJason M. Bills if (ret < 0) 2455e1f26343SJason M. Bills { 2456002d39b4SEd Tanous BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 2457f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2458e1f26343SJason M. Bills return; 2459e1f26343SJason M. Bills } 24600fda0f12SGeorge Liu std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 24610fda0f12SGeorge Liu journalTmp, sd_journal_close); 2462e1f26343SJason M. Bills journalTmp = nullptr; 2463b01bf299SEd Tanous uint64_t entryCount = 0; 2464e85d6b16SJason M. Bills // Reset the unique ID on the first entry 2465e85d6b16SJason M. Bills bool firstEntry = true; 2466e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 2467e1f26343SJason M. Bills { 2468193ad2faSJason M. Bills entryCount++; 24697e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 24707e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 24713648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 2472193ad2faSJason M. Bills { 2473193ad2faSJason M. Bills continue; 2474193ad2faSJason M. Bills } 2475193ad2faSJason M. Bills 247616428a1aSJason M. Bills std::string idStr; 2477e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2478e1f26343SJason M. Bills { 2479e1f26343SJason M. Bills continue; 2480e1f26343SJason M. Bills } 2481e85d6b16SJason M. Bills firstEntry = false; 2482e85d6b16SJason M. Bills 24833a48b3a2SJason M. Bills nlohmann::json::object_t bmcJournalLogEntry; 2484c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 2485c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 2486e1f26343SJason M. Bills { 2487f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2488e1f26343SJason M. Bills return; 2489e1f26343SJason M. Bills } 24903a48b3a2SJason M. Bills logEntryArray.push_back(std::move(bmcJournalLogEntry)); 2491e1f26343SJason M. Bills } 2492193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 24933648c8beSEd Tanous if (skip + top < entryCount) 2494193ad2faSJason M. Bills { 2495193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 24960fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 24973648c8beSEd Tanous std::to_string(skip + top); 2498193ad2faSJason M. Bills } 24997e860f15SJohn Edward Broadbent }); 2500e1f26343SJason M. Bills } 2501e1f26343SJason M. Bills 25027e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 2503e1f26343SJason M. Bills { 25047e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 25057e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 2506ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 25077e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 250845ca1b86SEd Tanous [&app](const crow::Request& req, 25097e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25107e860f15SJohn Edward Broadbent const std::string& entryID) { 25113ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 251245ca1b86SEd Tanous { 251345ca1b86SEd Tanous return; 251445ca1b86SEd Tanous } 2515e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2516e1f26343SJason M. Bills uint64_t ts = 0; 2517271584abSEd Tanous uint64_t index = 0; 25188d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2519e1f26343SJason M. Bills { 252016428a1aSJason M. Bills return; 2521e1f26343SJason M. Bills } 2522e1f26343SJason M. Bills 2523e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2524e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2525e1f26343SJason M. Bills if (ret < 0) 2526e1f26343SJason M. Bills { 2527002d39b4SEd Tanous BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 2528f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2529e1f26343SJason M. Bills return; 2530e1f26343SJason M. Bills } 2531002d39b4SEd Tanous std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 2532002d39b4SEd Tanous journalTmp, sd_journal_close); 2533e1f26343SJason M. Bills journalTmp = nullptr; 25347e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 25357e860f15SJohn Edward Broadbent // index tracking the unique ID 2536af07e3f5SJason M. Bills std::string idStr; 2537af07e3f5SJason M. Bills bool firstEntry = true; 2538e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 25392056b6d1SManojkiran Eda if (ret < 0) 25402056b6d1SManojkiran Eda { 25412056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 25422056b6d1SManojkiran Eda << strerror(-ret); 25432056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 25442056b6d1SManojkiran Eda return; 25452056b6d1SManojkiran Eda } 2546271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2547e1f26343SJason M. Bills { 2548e1f26343SJason M. Bills sd_journal_next(journal.get()); 2549af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2550af07e3f5SJason M. Bills { 2551af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2552af07e3f5SJason M. Bills return; 2553af07e3f5SJason M. Bills } 2554af07e3f5SJason M. Bills firstEntry = false; 2555af07e3f5SJason M. Bills } 2556c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2557af07e3f5SJason M. Bills if (idStr != entryID) 2558c4bf6374SJason M. Bills { 25599db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 2560c4bf6374SJason M. Bills return; 2561c4bf6374SJason M. Bills } 2562c4bf6374SJason M. Bills 25633a48b3a2SJason M. Bills nlohmann::json::object_t bmcJournalLogEntry; 2564c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 25653a48b3a2SJason M. Bills bmcJournalLogEntry) != 0) 2566e1f26343SJason M. Bills { 2567f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2568e1f26343SJason M. Bills return; 2569e1f26343SJason M. Bills } 2570d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcJournalLogEntry); 25717e860f15SJohn Edward Broadbent }); 2572c9bb6861Sraviteja-b } 2573c9bb6861Sraviteja-b 2574fdd26906SClaire Weinan inline void 2575fdd26906SClaire Weinan getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2576fdd26906SClaire Weinan const std::string& dumpType) 2577c9bb6861Sraviteja-b { 2578fdd26906SClaire Weinan std::string dumpPath; 2579fdd26906SClaire Weinan std::string overWritePolicy; 2580fdd26906SClaire Weinan bool collectDiagnosticDataSupported = false; 2581fdd26906SClaire Weinan 2582fdd26906SClaire Weinan if (dumpType == "BMC") 258345ca1b86SEd Tanous { 2584fdd26906SClaire Weinan dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump"; 2585fdd26906SClaire Weinan overWritePolicy = "WrapsWhenFull"; 2586fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2587fdd26906SClaire Weinan } 2588fdd26906SClaire Weinan else if (dumpType == "FaultLog") 2589fdd26906SClaire Weinan { 2590fdd26906SClaire Weinan dumpPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog"; 2591fdd26906SClaire Weinan overWritePolicy = "Unknown"; 2592fdd26906SClaire Weinan collectDiagnosticDataSupported = false; 2593fdd26906SClaire Weinan } 2594fdd26906SClaire Weinan else if (dumpType == "System") 2595fdd26906SClaire Weinan { 2596fdd26906SClaire Weinan dumpPath = "/redfish/v1/Systems/system/LogServices/Dump"; 2597fdd26906SClaire Weinan overWritePolicy = "WrapsWhenFull"; 2598fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2599fdd26906SClaire Weinan } 2600fdd26906SClaire Weinan else 2601fdd26906SClaire Weinan { 2602fdd26906SClaire Weinan BMCWEB_LOG_ERROR << "getDumpServiceInfo() invalid dump type: " 2603fdd26906SClaire Weinan << dumpType; 2604fdd26906SClaire Weinan messages::internalError(asyncResp->res); 260545ca1b86SEd Tanous return; 260645ca1b86SEd Tanous } 2607fdd26906SClaire Weinan 2608fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = dumpPath; 2609fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; 2610c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 2611fdd26906SClaire Weinan asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; 2612fdd26906SClaire Weinan asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); 2613fdd26906SClaire Weinan asyncResp->res.jsonValue["OverWritePolicy"] = std::move(overWritePolicy); 26147c8c4058STejas Patil 26157c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 26162b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 26170fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 26187c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 26197c8c4058STejas Patil redfishDateTimeOffset.second; 26207c8c4058STejas Patil 2621fdd26906SClaire Weinan asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; 2622fdd26906SClaire Weinan 2623fdd26906SClaire Weinan if (collectDiagnosticDataSupported) 2624fdd26906SClaire Weinan { 2625002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 26261476687dSEd Tanous ["target"] = 2627fdd26906SClaire Weinan dumpPath + "/Actions/LogService.CollectDiagnosticData"; 2628fdd26906SClaire Weinan } 2629*0d946211SClaire Weinan 2630*0d946211SClaire Weinan constexpr std::array<std::string_view, 1> interfaces = {deleteAllInterface}; 2631*0d946211SClaire Weinan dbus::utility::getSubTreePaths( 2632*0d946211SClaire Weinan "/xyz/openbmc_project/dump", 0, interfaces, 2633*0d946211SClaire Weinan [asyncResp, dumpType, dumpPath]( 2634*0d946211SClaire Weinan const boost::system::error_code& ec, 2635*0d946211SClaire Weinan const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 2636*0d946211SClaire Weinan if (ec) 2637*0d946211SClaire Weinan { 2638*0d946211SClaire Weinan BMCWEB_LOG_ERROR << "getDumpServiceInfo respHandler got error " 2639*0d946211SClaire Weinan << ec; 2640*0d946211SClaire Weinan // Assume that getting an error simply means there are no dump 2641*0d946211SClaire Weinan // LogServices. Return without adding any error response. 2642*0d946211SClaire Weinan return; 2643*0d946211SClaire Weinan } 2644*0d946211SClaire Weinan 2645*0d946211SClaire Weinan const std::string dbusDumpPath = 2646*0d946211SClaire Weinan "/xyz/openbmc_project/dump/" + 2647*0d946211SClaire Weinan boost::algorithm::to_lower_copy(dumpType); 2648*0d946211SClaire Weinan 2649*0d946211SClaire Weinan for (const std::string& path : subTreePaths) 2650*0d946211SClaire Weinan { 2651*0d946211SClaire Weinan if (path == dbusDumpPath) 2652*0d946211SClaire Weinan { 2653*0d946211SClaire Weinan asyncResp->res 2654*0d946211SClaire Weinan .jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 2655*0d946211SClaire Weinan dumpPath + "/Actions/LogService.ClearLog"; 2656*0d946211SClaire Weinan break; 2657*0d946211SClaire Weinan } 2658*0d946211SClaire Weinan } 2659*0d946211SClaire Weinan }); 2660c9bb6861Sraviteja-b } 2661c9bb6861Sraviteja-b 2662fdd26906SClaire Weinan inline void handleLogServicesDumpServiceGet( 2663fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2664fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 26657e860f15SJohn Edward Broadbent { 26663ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 266745ca1b86SEd Tanous { 266845ca1b86SEd Tanous return; 266945ca1b86SEd Tanous } 2670fdd26906SClaire Weinan getDumpServiceInfo(asyncResp, dumpType); 2671fdd26906SClaire Weinan } 2672c9bb6861Sraviteja-b 267322d268cbSEd Tanous inline void handleLogServicesDumpServiceComputerSystemGet( 267422d268cbSEd Tanous crow::App& app, const crow::Request& req, 267522d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 267622d268cbSEd Tanous const std::string& chassisId) 267722d268cbSEd Tanous { 267822d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 267922d268cbSEd Tanous { 268022d268cbSEd Tanous return; 268122d268cbSEd Tanous } 268222d268cbSEd Tanous if (chassisId != "system") 268322d268cbSEd Tanous { 268422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 268522d268cbSEd Tanous return; 268622d268cbSEd Tanous } 268722d268cbSEd Tanous getDumpServiceInfo(asyncResp, "System"); 268822d268cbSEd Tanous } 268922d268cbSEd Tanous 2690fdd26906SClaire Weinan inline void handleLogServicesDumpEntriesCollectionGet( 2691fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2692fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2693fdd26906SClaire Weinan { 2694fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2695fdd26906SClaire Weinan { 2696fdd26906SClaire Weinan return; 2697fdd26906SClaire Weinan } 2698fdd26906SClaire Weinan getDumpEntryCollection(asyncResp, dumpType); 2699fdd26906SClaire Weinan } 2700fdd26906SClaire Weinan 270122d268cbSEd Tanous inline void handleLogServicesDumpEntriesCollectionComputerSystemGet( 270222d268cbSEd Tanous crow::App& app, const crow::Request& req, 270322d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 270422d268cbSEd Tanous const std::string& chassisId) 270522d268cbSEd Tanous { 270622d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 270722d268cbSEd Tanous { 270822d268cbSEd Tanous return; 270922d268cbSEd Tanous } 271022d268cbSEd Tanous if (chassisId != "system") 271122d268cbSEd Tanous { 271222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 271322d268cbSEd Tanous return; 271422d268cbSEd Tanous } 271522d268cbSEd Tanous getDumpEntryCollection(asyncResp, "System"); 271622d268cbSEd Tanous } 271722d268cbSEd Tanous 2718fdd26906SClaire Weinan inline void handleLogServicesDumpEntryGet( 2719fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2720fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2721fdd26906SClaire Weinan const std::string& dumpId) 2722fdd26906SClaire Weinan { 2723fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2724fdd26906SClaire Weinan { 2725fdd26906SClaire Weinan return; 2726fdd26906SClaire Weinan } 2727fdd26906SClaire Weinan getDumpEntryById(asyncResp, dumpId, dumpType); 2728fdd26906SClaire Weinan } 272922d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemGet( 273022d268cbSEd Tanous crow::App& app, const crow::Request& req, 273122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 273222d268cbSEd Tanous const std::string& chassisId, const std::string& dumpId) 273322d268cbSEd Tanous { 273422d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 273522d268cbSEd Tanous { 273622d268cbSEd Tanous return; 273722d268cbSEd Tanous } 273822d268cbSEd Tanous if (chassisId != "system") 273922d268cbSEd Tanous { 274022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 274122d268cbSEd Tanous return; 274222d268cbSEd Tanous } 274322d268cbSEd Tanous getDumpEntryById(asyncResp, dumpId, "System"); 274422d268cbSEd Tanous } 2745fdd26906SClaire Weinan 2746fdd26906SClaire Weinan inline void handleLogServicesDumpEntryDelete( 2747fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2748fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2749fdd26906SClaire Weinan const std::string& dumpId) 2750fdd26906SClaire Weinan { 2751fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2752fdd26906SClaire Weinan { 2753fdd26906SClaire Weinan return; 2754fdd26906SClaire Weinan } 2755fdd26906SClaire Weinan deleteDumpEntry(asyncResp, dumpId, dumpType); 2756fdd26906SClaire Weinan } 2757fdd26906SClaire Weinan 275822d268cbSEd Tanous inline void handleLogServicesDumpEntryComputerSystemDelete( 275922d268cbSEd Tanous crow::App& app, const crow::Request& req, 276022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 276122d268cbSEd Tanous const std::string& chassisId, const std::string& dumpId) 276222d268cbSEd Tanous { 276322d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 276422d268cbSEd Tanous { 276522d268cbSEd Tanous return; 276622d268cbSEd Tanous } 276722d268cbSEd Tanous if (chassisId != "system") 276822d268cbSEd Tanous { 276922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 277022d268cbSEd Tanous return; 277122d268cbSEd Tanous } 277222d268cbSEd Tanous deleteDumpEntry(asyncResp, dumpId, "System"); 277322d268cbSEd Tanous } 277422d268cbSEd Tanous 2775fdd26906SClaire Weinan inline void handleLogServicesDumpCollectDiagnosticDataPost( 2776fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2777fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2778fdd26906SClaire Weinan { 2779fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2780fdd26906SClaire Weinan { 2781fdd26906SClaire Weinan return; 2782fdd26906SClaire Weinan } 2783fdd26906SClaire Weinan createDump(asyncResp, req, dumpType); 2784fdd26906SClaire Weinan } 2785fdd26906SClaire Weinan 278622d268cbSEd Tanous inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost( 278722d268cbSEd Tanous crow::App& app, const crow::Request& req, 278822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 278922d268cbSEd Tanous const std::string& chassisId) 279022d268cbSEd Tanous { 279122d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 279222d268cbSEd Tanous { 279322d268cbSEd Tanous return; 279422d268cbSEd Tanous } 279522d268cbSEd Tanous if (chassisId != "system") 279622d268cbSEd Tanous { 279722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 279822d268cbSEd Tanous return; 279922d268cbSEd Tanous } 280022d268cbSEd Tanous createDump(asyncResp, req, "System"); 280122d268cbSEd Tanous } 280222d268cbSEd Tanous 2803fdd26906SClaire Weinan inline void handleLogServicesDumpClearLogPost( 2804fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2805fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2806fdd26906SClaire Weinan { 2807fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2808fdd26906SClaire Weinan { 2809fdd26906SClaire Weinan return; 2810fdd26906SClaire Weinan } 2811fdd26906SClaire Weinan clearDump(asyncResp, dumpType); 2812fdd26906SClaire Weinan } 2813fdd26906SClaire Weinan 281422d268cbSEd Tanous inline void handleLogServicesDumpClearLogComputerSystemPost( 281522d268cbSEd Tanous crow::App& app, const crow::Request& req, 281622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 281722d268cbSEd Tanous const std::string& chassisId) 281822d268cbSEd Tanous { 281922d268cbSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 282022d268cbSEd Tanous { 282122d268cbSEd Tanous return; 282222d268cbSEd Tanous } 282322d268cbSEd Tanous if (chassisId != "system") 282422d268cbSEd Tanous { 282522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", chassisId); 282622d268cbSEd Tanous return; 282722d268cbSEd Tanous } 282822d268cbSEd Tanous clearDump(asyncResp, "System"); 282922d268cbSEd Tanous } 283022d268cbSEd Tanous 2831fdd26906SClaire Weinan inline void requestRoutesBMCDumpService(App& app) 2832fdd26906SClaire Weinan { 2833fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2834fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2835fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2836fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "BMC")); 2837fdd26906SClaire Weinan } 2838fdd26906SClaire Weinan 2839fdd26906SClaire Weinan inline void requestRoutesBMCDumpEntryCollection(App& app) 2840fdd26906SClaire Weinan { 2841fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2842fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2843fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2844fdd26906SClaire Weinan handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); 2845c9bb6861Sraviteja-b } 2846c9bb6861Sraviteja-b 28477e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2848c9bb6861Sraviteja-b { 28497e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 28507e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2851ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2852fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2853fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "BMC")); 2854fdd26906SClaire Weinan 28557e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 28567e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2857ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 2858fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2859fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); 2860c9bb6861Sraviteja-b } 2861c9bb6861Sraviteja-b 28627e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2863c9bb6861Sraviteja-b { 28640fda0f12SGeorge Liu BMCWEB_ROUTE( 28650fda0f12SGeorge Liu app, 28660fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2867ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 28687e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 2869fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, 2870fdd26906SClaire Weinan std::ref(app), "BMC")); 2871a43be80fSAsmitha Karunanithi } 2872a43be80fSAsmitha Karunanithi 28737e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 287480319af1SAsmitha Karunanithi { 28750fda0f12SGeorge Liu BMCWEB_ROUTE( 28760fda0f12SGeorge Liu app, 28770fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog/") 2878ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 2879fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 2880fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); 288145ca1b86SEd Tanous } 2882fdd26906SClaire Weinan 2883fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpService(App& app) 2884fdd26906SClaire Weinan { 2885fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/") 2886fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2887fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2888fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); 2889fdd26906SClaire Weinan } 2890fdd26906SClaire Weinan 2891fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntryCollection(App& app) 2892fdd26906SClaire Weinan { 2893fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/") 2894fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2895fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2896fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpEntriesCollectionGet, 2897fdd26906SClaire Weinan std::ref(app), "FaultLog")); 2898fdd26906SClaire Weinan } 2899fdd26906SClaire Weinan 2900fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntry(App& app) 2901fdd26906SClaire Weinan { 2902fdd26906SClaire Weinan BMCWEB_ROUTE(app, 2903fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/") 2904fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntry) 2905fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2906fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); 2907fdd26906SClaire Weinan 2908fdd26906SClaire Weinan BMCWEB_ROUTE(app, 2909fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/") 2910fdd26906SClaire Weinan .privileges(redfish::privileges::deleteLogEntry) 2911fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2912fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); 2913fdd26906SClaire Weinan } 2914fdd26906SClaire Weinan 2915fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpClear(App& app) 2916fdd26906SClaire Weinan { 2917fdd26906SClaire Weinan BMCWEB_ROUTE( 2918fdd26906SClaire Weinan app, 2919fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Actions/LogService.ClearLog/") 2920fdd26906SClaire Weinan .privileges(redfish::privileges::postLogService) 2921fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 2922fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); 29235cb1dd27SAsmitha Karunanithi } 29245cb1dd27SAsmitha Karunanithi 29257e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 29265cb1dd27SAsmitha Karunanithi { 292722d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/") 2928ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 29296ab9ad54SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 293022d268cbSEd Tanous handleLogServicesDumpServiceComputerSystemGet, std::ref(app))); 29315cb1dd27SAsmitha Karunanithi } 29325cb1dd27SAsmitha Karunanithi 29337e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 29347e860f15SJohn Edward Broadbent { 293522d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/") 2936ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 293722d268cbSEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 293822d268cbSEd Tanous handleLogServicesDumpEntriesCollectionComputerSystemGet, 293922d268cbSEd Tanous std::ref(app))); 29405cb1dd27SAsmitha Karunanithi } 29415cb1dd27SAsmitha Karunanithi 29427e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 29435cb1dd27SAsmitha Karunanithi { 29447e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 294522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") 2946ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 29476ab9ad54SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 294822d268cbSEd Tanous handleLogServicesDumpEntryComputerSystemGet, std::ref(app))); 29498d1b46d7Szhanghch05 29507e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 295122d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Entries/<str>/") 2952ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 29536ab9ad54SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 295422d268cbSEd Tanous handleLogServicesDumpEntryComputerSystemDelete, std::ref(app))); 29555cb1dd27SAsmitha Karunanithi } 2956c9bb6861Sraviteja-b 29577e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2958c9bb6861Sraviteja-b { 29590fda0f12SGeorge Liu BMCWEB_ROUTE( 29600fda0f12SGeorge Liu app, 296122d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2962ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 296322d268cbSEd Tanous .methods(boost::beast::http::verb::post)(std::bind_front( 296422d268cbSEd Tanous handleLogServicesDumpCollectDiagnosticDataComputerSystemPost, 296522d268cbSEd Tanous std::ref(app))); 2966a43be80fSAsmitha Karunanithi } 2967a43be80fSAsmitha Karunanithi 29687e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2969a43be80fSAsmitha Karunanithi { 29700fda0f12SGeorge Liu BMCWEB_ROUTE( 29710fda0f12SGeorge Liu app, 297222d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Dump/Actions/LogService.ClearLog/") 2973ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 29746ab9ad54SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 297522d268cbSEd Tanous handleLogServicesDumpClearLogComputerSystemPost, std::ref(app))); 2976013487e5Sraviteja-b } 2977013487e5Sraviteja-b 29787e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 29791da66f75SEd Tanous { 29803946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 29813946028dSAppaRao Puli // method for security reasons. 29821da66f75SEd Tanous /** 29831da66f75SEd Tanous * Functions triggers appropriate requests on DBus 29841da66f75SEd Tanous */ 298522d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/") 2986ed398213SEd Tanous // This is incorrect, should be: 2987ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2988432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 2989002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2990002d39b4SEd Tanous [&app](const crow::Request& req, 299122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 299222d268cbSEd Tanous const std::string& systemName) { 29933ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 299445ca1b86SEd Tanous { 299545ca1b86SEd Tanous return; 299645ca1b86SEd Tanous } 299722d268cbSEd Tanous if (systemName != "system") 299822d268cbSEd Tanous { 299922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 300022d268cbSEd Tanous systemName); 300122d268cbSEd Tanous return; 300222d268cbSEd Tanous } 300322d268cbSEd Tanous 30047e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 30057e860f15SJohn Edward Broadbent // SubRoute 30060f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3007424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 3008e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 30098e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 30104f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 30114f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 30124f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 3013e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 3014e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 30157c8c4058STejas Patil 30167c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 30172b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 30187c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 30197c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 30207c8c4058STejas Patil redfishDateTimeOffset.second; 30217c8c4058STejas Patil 30221476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 30231476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 3024002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 30251476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog"; 3026002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 30271476687dSEd Tanous ["target"] = 30281476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData"; 30297e860f15SJohn Edward Broadbent }); 30301da66f75SEd Tanous } 30311da66f75SEd Tanous 30327e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 30335b61b5e8SJason M. Bills { 30340fda0f12SGeorge Liu BMCWEB_ROUTE( 30350fda0f12SGeorge Liu app, 303622d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.ClearLog/") 3037ed398213SEd Tanous // This is incorrect, should be: 3038ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3039432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 30407e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 304145ca1b86SEd Tanous [&app](const crow::Request& req, 304222d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 304322d268cbSEd Tanous const std::string& systemName) { 30443ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 304545ca1b86SEd Tanous { 304645ca1b86SEd Tanous return; 304745ca1b86SEd Tanous } 304822d268cbSEd Tanous if (systemName != "system") 304922d268cbSEd Tanous { 305022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 305122d268cbSEd Tanous systemName); 305222d268cbSEd Tanous return; 305322d268cbSEd Tanous } 30545b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 30555b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 3056cb13a392SEd Tanous const std::string&) { 30575b61b5e8SJason M. Bills if (ec) 30585b61b5e8SJason M. Bills { 30595b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 30605b61b5e8SJason M. Bills return; 30615b61b5e8SJason M. Bills } 30625b61b5e8SJason M. Bills messages::success(asyncResp->res); 30635b61b5e8SJason M. Bills }, 3064002d39b4SEd Tanous crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 30657e860f15SJohn Edward Broadbent }); 30665b61b5e8SJason M. Bills } 30675b61b5e8SJason M. Bills 30688d1b46d7Szhanghch05 static void 30698d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 30708d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 3071e855dd28SJason M. Bills { 3072043a0536SJohnathan Mantey auto getStoredLogCallback = 3073b9d36b47SEd Tanous [asyncResp, logID, 3074b9d36b47SEd Tanous &logEntryJson](const boost::system::error_code ec, 3075b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& params) { 3076e855dd28SJason M. Bills if (ec) 3077e855dd28SJason M. Bills { 3078e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 30791ddcf01aSJason M. Bills if (ec.value() == 30801ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 30811ddcf01aSJason M. Bills { 3082002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 30831ddcf01aSJason M. Bills } 30841ddcf01aSJason M. Bills else 30851ddcf01aSJason M. Bills { 3086e855dd28SJason M. Bills messages::internalError(asyncResp->res); 30871ddcf01aSJason M. Bills } 3088e855dd28SJason M. Bills return; 3089e855dd28SJason M. Bills } 3090043a0536SJohnathan Mantey 3091043a0536SJohnathan Mantey std::string timestamp{}; 3092043a0536SJohnathan Mantey std::string filename{}; 3093043a0536SJohnathan Mantey std::string logfile{}; 30942c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 3095043a0536SJohnathan Mantey 3096043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 3097e855dd28SJason M. Bills { 30989db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3099e855dd28SJason M. Bills return; 3100e855dd28SJason M. Bills } 3101e855dd28SJason M. Bills 3102043a0536SJohnathan Mantey std::string crashdumpURI = 3103e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 3104043a0536SJohnathan Mantey logID + "/" + filename; 310584afc48bSJason M. Bills nlohmann::json::object_t logEntry; 31069c11a172SVijay Lobo logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 310784afc48bSJason M. Bills logEntry["@odata.id"] = 310884afc48bSJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + logID; 310984afc48bSJason M. Bills logEntry["Name"] = "CPU Crashdump"; 311084afc48bSJason M. Bills logEntry["Id"] = logID; 311184afc48bSJason M. Bills logEntry["EntryType"] = "Oem"; 311284afc48bSJason M. Bills logEntry["AdditionalDataURI"] = std::move(crashdumpURI); 311384afc48bSJason M. Bills logEntry["DiagnosticDataType"] = "OEM"; 311484afc48bSJason M. Bills logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; 311584afc48bSJason M. Bills logEntry["Created"] = std::move(timestamp); 31162b20ef6eSJason M. Bills 31172b20ef6eSJason M. Bills // If logEntryJson references an array of LogEntry resources 31182b20ef6eSJason M. Bills // ('Members' list), then push this as a new entry, otherwise set it 31192b20ef6eSJason M. Bills // directly 31202b20ef6eSJason M. Bills if (logEntryJson.is_array()) 31212b20ef6eSJason M. Bills { 31222b20ef6eSJason M. Bills logEntryJson.push_back(logEntry); 31232b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 31242b20ef6eSJason M. Bills logEntryJson.size(); 31252b20ef6eSJason M. Bills } 31262b20ef6eSJason M. Bills else 31272b20ef6eSJason M. Bills { 3128d405bb51SJason M. Bills logEntryJson.update(logEntry); 31292b20ef6eSJason M. Bills } 3130e855dd28SJason M. Bills }; 3131d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3132d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, crashdumpObject, 3133d1bde9e5SKrzysztof Grobelny crashdumpPath + std::string("/") + logID, crashdumpInterface, 3134d1bde9e5SKrzysztof Grobelny std::move(getStoredLogCallback)); 3135e855dd28SJason M. Bills } 3136e855dd28SJason M. Bills 31377e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 31381da66f75SEd Tanous { 31393946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 31403946028dSAppaRao Puli // method for security reasons. 31411da66f75SEd Tanous /** 31421da66f75SEd Tanous * Functions triggers appropriate requests on DBus 31431da66f75SEd Tanous */ 31447e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 314522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/") 3146ed398213SEd Tanous // This is incorrect, should be. 3147ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 3148432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3149002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3150002d39b4SEd Tanous [&app](const crow::Request& req, 315122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 315222d268cbSEd Tanous const std::string& systemName) { 31533ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 315445ca1b86SEd Tanous { 315545ca1b86SEd Tanous return; 315645ca1b86SEd Tanous } 315722d268cbSEd Tanous if (systemName != "system") 315822d268cbSEd Tanous { 315922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 316022d268cbSEd Tanous systemName); 316122d268cbSEd Tanous return; 316222d268cbSEd Tanous } 316322d268cbSEd Tanous 31647a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 31657a1dbc48SGeorge Liu crashdumpInterface}; 31667a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 31677a1dbc48SGeorge Liu "/", 0, interfaces, 31687a1dbc48SGeorge Liu [asyncResp](const boost::system::error_code& ec, 31692b20ef6eSJason M. Bills const std::vector<std::string>& resp) { 31701da66f75SEd Tanous if (ec) 31711da66f75SEd Tanous { 31721da66f75SEd Tanous if (ec.value() != 31731da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 31741da66f75SEd Tanous { 31751da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 31761da66f75SEd Tanous << ec.message(); 3177f12894f8SJason M. Bills messages::internalError(asyncResp->res); 31781da66f75SEd Tanous return; 31791da66f75SEd Tanous } 31801da66f75SEd Tanous } 3181e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 31821da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 31830f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3184424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 3185002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 3186e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 3187424c4176SJason M. Bills "Collection of Crashdump Entries"; 3188002d39b4SEd Tanous asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3189a2dd60a6SBrandon Kim asyncResp->res.jsonValue["Members@odata.count"] = 0; 31902b20ef6eSJason M. Bills 31912b20ef6eSJason M. Bills for (const std::string& path : resp) 31921da66f75SEd Tanous { 31932b20ef6eSJason M. Bills const sdbusplus::message::object_path objPath(path); 3194e855dd28SJason M. Bills // Get the log ID 31952b20ef6eSJason M. Bills std::string logID = objPath.filename(); 31962b20ef6eSJason M. Bills if (logID.empty()) 31971da66f75SEd Tanous { 3198e855dd28SJason M. Bills continue; 31991da66f75SEd Tanous } 3200e855dd28SJason M. Bills // Add the log entry to the array 32012b20ef6eSJason M. Bills logCrashdumpEntry(asyncResp, logID, 32022b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"]); 32031da66f75SEd Tanous } 32047a1dbc48SGeorge Liu }); 32057e860f15SJohn Edward Broadbent }); 32061da66f75SEd Tanous } 32071da66f75SEd Tanous 32087e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 32091da66f75SEd Tanous { 32103946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 32113946028dSAppaRao Puli // method for security reasons. 32121da66f75SEd Tanous 32137e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 321422d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/") 3215ed398213SEd Tanous // this is incorrect, should be 3216ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 3217432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 32187e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 321945ca1b86SEd Tanous [&app](const crow::Request& req, 32207e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 322122d268cbSEd Tanous const std::string& systemName, const std::string& param) { 32223ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 322345ca1b86SEd Tanous { 322445ca1b86SEd Tanous return; 322545ca1b86SEd Tanous } 322622d268cbSEd Tanous if (systemName != "system") 322722d268cbSEd Tanous { 322822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 322922d268cbSEd Tanous systemName); 323022d268cbSEd Tanous return; 323122d268cbSEd Tanous } 32327e860f15SJohn Edward Broadbent const std::string& logID = param; 3233e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 32347e860f15SJohn Edward Broadbent }); 3235e855dd28SJason M. Bills } 3236e855dd28SJason M. Bills 32377e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 3238e855dd28SJason M. Bills { 32393946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 32403946028dSAppaRao Puli // method for security reasons. 32417e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 32427e860f15SJohn Edward Broadbent app, 324322d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Entries/<str>/<str>/") 3244ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 32457e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 3246a4ce114aSNan Zhou [](const crow::Request& req, 32477e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 324822d268cbSEd Tanous const std::string& systemName, const std::string& logID, 324922d268cbSEd Tanous const std::string& fileName) { 32502a9beeedSShounak Mitra // Do not call getRedfishRoute here since the crashdump file is not a 32512a9beeedSShounak Mitra // Redfish resource. 325222d268cbSEd Tanous 325322d268cbSEd Tanous if (systemName != "system") 325422d268cbSEd Tanous { 325522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 325622d268cbSEd Tanous systemName); 325722d268cbSEd Tanous return; 325822d268cbSEd Tanous } 325922d268cbSEd Tanous 3260043a0536SJohnathan Mantey auto getStoredLogCallback = 3261002d39b4SEd Tanous [asyncResp, logID, fileName, url(boost::urls::url(req.urlView))]( 3262abf2add6SEd Tanous const boost::system::error_code ec, 3263002d39b4SEd Tanous const std::vector< 3264002d39b4SEd Tanous std::pair<std::string, dbus::utility::DbusVariantType>>& 32657e860f15SJohn Edward Broadbent resp) { 32661da66f75SEd Tanous if (ec) 32671da66f75SEd Tanous { 3268002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 3269f12894f8SJason M. Bills messages::internalError(asyncResp->res); 32701da66f75SEd Tanous return; 32711da66f75SEd Tanous } 3272e855dd28SJason M. Bills 3273043a0536SJohnathan Mantey std::string dbusFilename{}; 3274043a0536SJohnathan Mantey std::string dbusTimestamp{}; 3275043a0536SJohnathan Mantey std::string dbusFilepath{}; 3276043a0536SJohnathan Mantey 3277002d39b4SEd Tanous parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 3278002d39b4SEd Tanous dbusFilepath); 3279043a0536SJohnathan Mantey 3280043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 3281043a0536SJohnathan Mantey dbusFilepath.empty()) 32821da66f75SEd Tanous { 32839db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 32841da66f75SEd Tanous return; 32851da66f75SEd Tanous } 3286e855dd28SJason M. Bills 3287043a0536SJohnathan Mantey // Verify the file name parameter is correct 3288043a0536SJohnathan Mantey if (fileName != dbusFilename) 3289043a0536SJohnathan Mantey { 32909db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3291043a0536SJohnathan Mantey return; 3292043a0536SJohnathan Mantey } 3293043a0536SJohnathan Mantey 3294043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 3295043a0536SJohnathan Mantey { 32969db4ba25SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 3297043a0536SJohnathan Mantey return; 3298043a0536SJohnathan Mantey } 3299002d39b4SEd Tanous std::ifstream ifs(dbusFilepath, std::ios::in | std::ios::binary); 3300002d39b4SEd Tanous asyncResp->res.body() = 3301002d39b4SEd Tanous std::string(std::istreambuf_iterator<char>{ifs}, {}); 3302043a0536SJohnathan Mantey 33037e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 33047e860f15SJohn Edward Broadbent // from a browser 3305d9f6c621SEd Tanous asyncResp->res.addHeader( 3306d9f6c621SEd Tanous boost::beast::http::field::content_disposition, "attachment"); 33071da66f75SEd Tanous }; 3308d1bde9e5SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3309d1bde9e5SKrzysztof Grobelny *crow::connections::systemBus, crashdumpObject, 3310d1bde9e5SKrzysztof Grobelny crashdumpPath + std::string("/") + logID, crashdumpInterface, 3311d1bde9e5SKrzysztof Grobelny std::move(getStoredLogCallback)); 33127e860f15SJohn Edward Broadbent }); 33131da66f75SEd Tanous } 33141da66f75SEd Tanous 3315c5a4c82aSJason M. Bills enum class OEMDiagnosticType 3316c5a4c82aSJason M. Bills { 3317c5a4c82aSJason M. Bills onDemand, 3318c5a4c82aSJason M. Bills telemetry, 3319c5a4c82aSJason M. Bills invalid, 3320c5a4c82aSJason M. Bills }; 3321c5a4c82aSJason M. Bills 3322f7725d79SEd Tanous inline OEMDiagnosticType 3323f7725d79SEd Tanous getOEMDiagnosticType(const std::string_view& oemDiagStr) 3324c5a4c82aSJason M. Bills { 3325c5a4c82aSJason M. Bills if (oemDiagStr == "OnDemand") 3326c5a4c82aSJason M. Bills { 3327c5a4c82aSJason M. Bills return OEMDiagnosticType::onDemand; 3328c5a4c82aSJason M. Bills } 3329c5a4c82aSJason M. Bills if (oemDiagStr == "Telemetry") 3330c5a4c82aSJason M. Bills { 3331c5a4c82aSJason M. Bills return OEMDiagnosticType::telemetry; 3332c5a4c82aSJason M. Bills } 3333c5a4c82aSJason M. Bills 3334c5a4c82aSJason M. Bills return OEMDiagnosticType::invalid; 3335c5a4c82aSJason M. Bills } 3336c5a4c82aSJason M. Bills 33377e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 33381da66f75SEd Tanous { 33393946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 33403946028dSAppaRao Puli // method for security reasons. 33410fda0f12SGeorge Liu BMCWEB_ROUTE( 33420fda0f12SGeorge Liu app, 334322d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") 3344ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 3345ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3346432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3347002d39b4SEd Tanous .methods(boost::beast::http::verb::post)( 3348002d39b4SEd Tanous [&app](const crow::Request& req, 334922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 335022d268cbSEd Tanous const std::string& systemName) { 33513ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 335245ca1b86SEd Tanous { 335345ca1b86SEd Tanous return; 335445ca1b86SEd Tanous } 335522d268cbSEd Tanous 335622d268cbSEd Tanous if (systemName != "system") 335722d268cbSEd Tanous { 335822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 335922d268cbSEd Tanous systemName); 336022d268cbSEd Tanous return; 336122d268cbSEd Tanous } 336222d268cbSEd Tanous 33638e6c099aSJason M. Bills std::string diagnosticDataType; 33648e6c099aSJason M. Bills std::string oemDiagnosticDataType; 336515ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 3366002d39b4SEd Tanous req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 3367002d39b4SEd Tanous "OEMDiagnosticDataType", oemDiagnosticDataType)) 33688e6c099aSJason M. Bills { 33698e6c099aSJason M. Bills return; 33708e6c099aSJason M. Bills } 33718e6c099aSJason M. Bills 33728e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 33738e6c099aSJason M. Bills { 33748e6c099aSJason M. Bills BMCWEB_LOG_ERROR 33758e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 33768e6c099aSJason M. Bills messages::actionParameterValueFormatError( 33778e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 33788e6c099aSJason M. Bills "CollectDiagnosticData"); 33798e6c099aSJason M. Bills return; 33808e6c099aSJason M. Bills } 33818e6c099aSJason M. Bills 3382c5a4c82aSJason M. Bills OEMDiagnosticType oemDiagType = 3383c5a4c82aSJason M. Bills getOEMDiagnosticType(oemDiagnosticDataType); 3384c5a4c82aSJason M. Bills 3385c5a4c82aSJason M. Bills std::string iface; 3386c5a4c82aSJason M. Bills std::string method; 3387c5a4c82aSJason M. Bills std::string taskMatchStr; 3388c5a4c82aSJason M. Bills if (oemDiagType == OEMDiagnosticType::onDemand) 3389c5a4c82aSJason M. Bills { 3390c5a4c82aSJason M. Bills iface = crashdumpOnDemandInterface; 3391c5a4c82aSJason M. Bills method = "GenerateOnDemandLog"; 3392c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3393c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3394c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3395c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3396c5a4c82aSJason M. Bills } 3397c5a4c82aSJason M. Bills else if (oemDiagType == OEMDiagnosticType::telemetry) 3398c5a4c82aSJason M. Bills { 3399c5a4c82aSJason M. Bills iface = crashdumpTelemetryInterface; 3400c5a4c82aSJason M. Bills method = "GenerateTelemetryLog"; 3401c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3402c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3403c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3404c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3405c5a4c82aSJason M. Bills } 3406c5a4c82aSJason M. Bills else 3407c5a4c82aSJason M. Bills { 3408c5a4c82aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 3409c5a4c82aSJason M. Bills << oemDiagnosticDataType; 3410c5a4c82aSJason M. Bills messages::actionParameterValueFormatError( 3411002d39b4SEd Tanous asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType", 3412002d39b4SEd Tanous "CollectDiagnosticData"); 3413c5a4c82aSJason M. Bills return; 3414c5a4c82aSJason M. Bills } 3415c5a4c82aSJason M. Bills 3416c5a4c82aSJason M. Bills auto collectCrashdumpCallback = 3417c5a4c82aSJason M. Bills [asyncResp, payload(task::Payload(req)), 3418c5a4c82aSJason M. Bills taskMatchStr](const boost::system::error_code ec, 341998be3e39SEd Tanous const std::string&) mutable { 34201da66f75SEd Tanous if (ec) 34211da66f75SEd Tanous { 3422002d39b4SEd Tanous if (ec.value() == boost::system::errc::operation_not_supported) 34231da66f75SEd Tanous { 3424f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 34251da66f75SEd Tanous } 34264363d3b2SJason M. Bills else if (ec.value() == 34274363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 34284363d3b2SJason M. Bills { 3429002d39b4SEd Tanous messages::serviceTemporarilyUnavailable(asyncResp->res, 3430002d39b4SEd Tanous "60"); 34314363d3b2SJason M. Bills } 34321da66f75SEd Tanous else 34331da66f75SEd Tanous { 3434f12894f8SJason M. Bills messages::internalError(asyncResp->res); 34351da66f75SEd Tanous } 34361da66f75SEd Tanous return; 34371da66f75SEd Tanous } 3438002d39b4SEd Tanous std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 343959d494eeSPatrick Williams [](boost::system::error_code err, sdbusplus::message_t&, 3440002d39b4SEd Tanous const std::shared_ptr<task::TaskData>& taskData) { 344166afe4faSJames Feist if (!err) 344266afe4faSJames Feist { 3443002d39b4SEd Tanous taskData->messages.emplace_back(messages::taskCompletedOK( 3444e5d5006bSJames Feist std::to_string(taskData->index))); 3445831d6b09SJames Feist taskData->state = "Completed"; 344666afe4faSJames Feist } 344732898ceaSJames Feist return task::completed; 344866afe4faSJames Feist }, 3449c5a4c82aSJason M. Bills taskMatchStr); 3450c5a4c82aSJason M. Bills 345146229577SJames Feist task->startTimer(std::chrono::minutes(5)); 345246229577SJames Feist task->populateResp(asyncResp->res); 345398be3e39SEd Tanous task->payload.emplace(std::move(payload)); 34541da66f75SEd Tanous }; 34558e6c099aSJason M. Bills 34561da66f75SEd Tanous crow::connections::systemBus->async_method_call( 3457002d39b4SEd Tanous std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath, 3458002d39b4SEd Tanous iface, method); 34597e860f15SJohn Edward Broadbent }); 34606eda7685SKenny L. Ku } 34616eda7685SKenny L. Ku 3462cb92c03bSAndrew Geissler /** 3463cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 3464cb92c03bSAndrew Geissler */ 34657e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 3466cb92c03bSAndrew Geissler { 3467cb92c03bSAndrew Geissler /** 3468cb92c03bSAndrew Geissler * Function handles POST method request. 3469cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3470cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3471cb92c03bSAndrew Geissler */ 34727e860f15SJohn Edward Broadbent 34730fda0f12SGeorge Liu BMCWEB_ROUTE( 34740fda0f12SGeorge Liu app, 347522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/EventLog/Actions/LogService.ClearLog/") 3476ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 34777e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 347845ca1b86SEd Tanous [&app](const crow::Request& req, 347922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 348022d268cbSEd Tanous const std::string& systemName) { 34813ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 348245ca1b86SEd Tanous { 348345ca1b86SEd Tanous return; 348445ca1b86SEd Tanous } 348522d268cbSEd Tanous if (systemName != "system") 348622d268cbSEd Tanous { 348722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 348822d268cbSEd Tanous systemName); 348922d268cbSEd Tanous return; 349022d268cbSEd Tanous } 3491cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 3492cb92c03bSAndrew Geissler 3493cb92c03bSAndrew Geissler // Process response from Logging service. 3494002d39b4SEd Tanous auto respHandler = [asyncResp](const boost::system::error_code ec) { 3495002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 3496cb92c03bSAndrew Geissler if (ec) 3497cb92c03bSAndrew Geissler { 3498cb92c03bSAndrew Geissler // TODO Handle for specific error code 3499002d39b4SEd Tanous BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 3500cb92c03bSAndrew Geissler asyncResp->res.result( 3501cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3502cb92c03bSAndrew Geissler return; 3503cb92c03bSAndrew Geissler } 3504cb92c03bSAndrew Geissler 3505002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content); 3506cb92c03bSAndrew Geissler }; 3507cb92c03bSAndrew Geissler 3508cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3509cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 35102c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 3511cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3512cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 35137e860f15SJohn Edward Broadbent }); 3514cb92c03bSAndrew Geissler } 3515a3316fc6SZhikuiRen 3516a3316fc6SZhikuiRen /**************************************************** 3517a3316fc6SZhikuiRen * Redfish PostCode interfaces 3518a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3519a3316fc6SZhikuiRen ******************************************************/ 35207e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 3521a3316fc6SZhikuiRen { 352222d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/") 3523ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 3524002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3525002d39b4SEd Tanous [&app](const crow::Request& req, 352622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 352722d268cbSEd Tanous const std::string& systemName) { 35283ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 352945ca1b86SEd Tanous { 353045ca1b86SEd Tanous return; 353145ca1b86SEd Tanous } 353222d268cbSEd Tanous if (systemName != "system") 353322d268cbSEd Tanous { 353422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 353522d268cbSEd Tanous systemName); 353622d268cbSEd Tanous return; 353722d268cbSEd Tanous } 35381476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 35391476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes"; 35401476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 35411476687dSEd Tanous "#LogService.v1_1_0.LogService"; 35421476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "POST Code Log Service"; 35431476687dSEd Tanous asyncResp->res.jsonValue["Description"] = "POST Code Log Service"; 35441476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "BIOS POST Code Log"; 35451476687dSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 35461476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 35471476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 35487c8c4058STejas Patil 35497c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 35502b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 35510fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 35527c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 35537c8c4058STejas Patil redfishDateTimeOffset.second; 35547c8c4058STejas Patil 3555a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 35567e860f15SJohn Edward Broadbent {"target", 35570fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog"}}; 35587e860f15SJohn Edward Broadbent }); 3559a3316fc6SZhikuiRen } 3560a3316fc6SZhikuiRen 35617e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3562a3316fc6SZhikuiRen { 35630fda0f12SGeorge Liu BMCWEB_ROUTE( 35640fda0f12SGeorge Liu app, 356522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Actions/LogService.ClearLog/") 3566ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3567ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3568432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 35697e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 357045ca1b86SEd Tanous [&app](const crow::Request& req, 357122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 357222d268cbSEd Tanous const std::string& systemName) { 35733ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 357445ca1b86SEd Tanous { 357545ca1b86SEd Tanous return; 357645ca1b86SEd Tanous } 357722d268cbSEd Tanous if (systemName != "system") 357822d268cbSEd Tanous { 357922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 358022d268cbSEd Tanous systemName); 358122d268cbSEd Tanous return; 358222d268cbSEd Tanous } 3583a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3584a3316fc6SZhikuiRen 3585a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3586a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3587a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3588a3316fc6SZhikuiRen if (ec) 3589a3316fc6SZhikuiRen { 3590a3316fc6SZhikuiRen // TODO Handle for specific error code 3591002d39b4SEd Tanous BMCWEB_LOG_ERROR << "doClearPostCodes resp_handler got error " 35927e860f15SJohn Edward Broadbent << ec; 3593002d39b4SEd Tanous asyncResp->res.result( 3594002d39b4SEd Tanous boost::beast::http::status::internal_server_error); 3595a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3596a3316fc6SZhikuiRen return; 3597a3316fc6SZhikuiRen } 3598a3316fc6SZhikuiRen }, 359915124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 360015124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3601a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 36027e860f15SJohn Edward Broadbent }); 3603a3316fc6SZhikuiRen } 3604a3316fc6SZhikuiRen 36056f284d24SJiaqing Zhao /** 36066f284d24SJiaqing Zhao * @brief Parse post code ID and get the current value and index value 36076f284d24SJiaqing Zhao * eg: postCodeID=B1-2, currentValue=1, index=2 36086f284d24SJiaqing Zhao * 36096f284d24SJiaqing Zhao * @param[in] postCodeID Post Code ID 36106f284d24SJiaqing Zhao * @param[out] currentValue Current value 36116f284d24SJiaqing Zhao * @param[out] index Index value 36126f284d24SJiaqing Zhao * 36136f284d24SJiaqing Zhao * @return bool true if the parsing is successful, false the parsing fails 36146f284d24SJiaqing Zhao */ 36156f284d24SJiaqing Zhao inline static bool parsePostCode(const std::string& postCodeID, 36166f284d24SJiaqing Zhao uint64_t& currentValue, uint16_t& index) 36176f284d24SJiaqing Zhao { 36186f284d24SJiaqing Zhao std::vector<std::string> split; 36196f284d24SJiaqing Zhao boost::algorithm::split(split, postCodeID, boost::is_any_of("-")); 36206f284d24SJiaqing Zhao if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B') 36216f284d24SJiaqing Zhao { 36226f284d24SJiaqing Zhao return false; 36236f284d24SJiaqing Zhao } 36246f284d24SJiaqing Zhao 36256f284d24SJiaqing Zhao // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 36266f284d24SJiaqing Zhao const char* start = split[0].data() + 1; 36276f284d24SJiaqing Zhao // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 36286f284d24SJiaqing Zhao const char* end = split[0].data() + split[0].size(); 36296f284d24SJiaqing Zhao auto [ptrIndex, ecIndex] = std::from_chars(start, end, index); 36306f284d24SJiaqing Zhao 36316f284d24SJiaqing Zhao if (ptrIndex != end || ecIndex != std::errc()) 36326f284d24SJiaqing Zhao { 36336f284d24SJiaqing Zhao return false; 36346f284d24SJiaqing Zhao } 36356f284d24SJiaqing Zhao 36366f284d24SJiaqing Zhao start = split[1].data(); 36376f284d24SJiaqing Zhao 36386f284d24SJiaqing Zhao // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 36396f284d24SJiaqing Zhao end = split[1].data() + split[1].size(); 36406f284d24SJiaqing Zhao auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue); 36416f284d24SJiaqing Zhao 36426f284d24SJiaqing Zhao return ptrValue == end && ecValue == std::errc(); 36436f284d24SJiaqing Zhao } 36446f284d24SJiaqing Zhao 36456f284d24SJiaqing Zhao static bool fillPostCodeEntry( 36468d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 36476c9a279eSManojkiran Eda const boost::container::flat_map< 36486c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3649a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3650a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3651a3316fc6SZhikuiRen { 3652a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3653fffb8c1fSEd Tanous const registries::Message* message = 3654fffb8c1fSEd Tanous registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3655a3316fc6SZhikuiRen 3656a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3657a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 36586c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 36596c9a279eSManojkiran Eda code : postcode) 3660a3316fc6SZhikuiRen { 3661a3316fc6SZhikuiRen currentCodeIndex++; 3662a3316fc6SZhikuiRen std::string postcodeEntryID = 3663a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3664a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3665a3316fc6SZhikuiRen 3666a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3667a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3668a3316fc6SZhikuiRen 3669a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3670a3316fc6SZhikuiRen { // already incremented 3671a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3672a3316fc6SZhikuiRen } 3673a3316fc6SZhikuiRen else 3674a3316fc6SZhikuiRen { 3675a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3676a3316fc6SZhikuiRen } 3677a3316fc6SZhikuiRen 3678a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3679a3316fc6SZhikuiRen // not fall between top and skip 3680a3316fc6SZhikuiRen if ((codeIndex == 0) && 3681a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3682a3316fc6SZhikuiRen { 3683a3316fc6SZhikuiRen continue; 3684a3316fc6SZhikuiRen } 3685a3316fc6SZhikuiRen 36864e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3687a3316fc6SZhikuiRen // currentIndex 3688a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3689a3316fc6SZhikuiRen { 3690a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3691a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3692a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3693a3316fc6SZhikuiRen continue; 3694a3316fc6SZhikuiRen } 3695a3316fc6SZhikuiRen 3696a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3697a3316fc6SZhikuiRen // index 3698a3316fc6SZhikuiRen 3699a3316fc6SZhikuiRen // Get the Created time from the timestamp 3700a3316fc6SZhikuiRen std::string entryTimeStr; 37011d8782e7SNan Zhou entryTimeStr = 37022b82937eSEd Tanous redfish::time_utils::getDateTimeUint(usecSinceEpoch / 1000 / 1000); 3703a3316fc6SZhikuiRen 3704a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3705a3316fc6SZhikuiRen std::ostringstream hexCode; 3706a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 37076c9a279eSManojkiran Eda << std::get<0>(code.second); 3708a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3709a3316fc6SZhikuiRen // Set Fixed -Point Notation 3710a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3711a3316fc6SZhikuiRen // Set precision to 4 digits 3712a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3713a3316fc6SZhikuiRen // Add double to stream 3714a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3715a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3716a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3717a3316fc6SZhikuiRen 3718a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3719a3316fc6SZhikuiRen std::string msg; 3720a3316fc6SZhikuiRen if (message != nullptr) 3721a3316fc6SZhikuiRen { 3722a3316fc6SZhikuiRen msg = message->message; 3723a3316fc6SZhikuiRen 3724a3316fc6SZhikuiRen // fill in this post code value 3725a3316fc6SZhikuiRen int i = 0; 3726a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3727a3316fc6SZhikuiRen { 3728a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3729a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3730a3316fc6SZhikuiRen if (argPos != std::string::npos) 3731a3316fc6SZhikuiRen { 3732a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3733a3316fc6SZhikuiRen } 3734a3316fc6SZhikuiRen } 3735a3316fc6SZhikuiRen } 3736a3316fc6SZhikuiRen 3737d4342a92STim Lee // Get Severity template from message registry 3738d4342a92STim Lee std::string severity; 3739d4342a92STim Lee if (message != nullptr) 3740d4342a92STim Lee { 37415f2b84eeSEd Tanous severity = message->messageSeverity; 3742d4342a92STim Lee } 3743d4342a92STim Lee 37446f284d24SJiaqing Zhao // Format entry 37456f284d24SJiaqing Zhao nlohmann::json::object_t bmcLogEntry; 37469c11a172SVijay Lobo bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry"; 374784afc48bSJason M. Bills bmcLogEntry["@odata.id"] = 37480fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 374984afc48bSJason M. Bills postcodeEntryID; 375084afc48bSJason M. Bills bmcLogEntry["Name"] = "POST Code Log Entry"; 375184afc48bSJason M. Bills bmcLogEntry["Id"] = postcodeEntryID; 375284afc48bSJason M. Bills bmcLogEntry["Message"] = std::move(msg); 375384afc48bSJason M. Bills bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode"; 375484afc48bSJason M. Bills bmcLogEntry["MessageArgs"] = std::move(messageArgs); 375584afc48bSJason M. Bills bmcLogEntry["EntryType"] = "Event"; 375684afc48bSJason M. Bills bmcLogEntry["Severity"] = std::move(severity); 375784afc48bSJason M. Bills bmcLogEntry["Created"] = entryTimeStr; 3758647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 3759647b3cdcSGeorge Liu { 3760647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 3761647b3cdcSGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3762647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 3763647b3cdcSGeorge Liu } 37646f284d24SJiaqing Zhao 37656f284d24SJiaqing Zhao // codeIndex is only specified when querying single entry, return only 37666f284d24SJiaqing Zhao // that entry in this case 37676f284d24SJiaqing Zhao if (codeIndex != 0) 37686f284d24SJiaqing Zhao { 37696f284d24SJiaqing Zhao aResp->res.jsonValue.update(bmcLogEntry); 37706f284d24SJiaqing Zhao return true; 3771a3316fc6SZhikuiRen } 37726f284d24SJiaqing Zhao 37736f284d24SJiaqing Zhao nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 37746f284d24SJiaqing Zhao logEntryArray.push_back(std::move(bmcLogEntry)); 37756f284d24SJiaqing Zhao } 37766f284d24SJiaqing Zhao 37776f284d24SJiaqing Zhao // Return value is always false when querying multiple entries 37786f284d24SJiaqing Zhao return false; 3779a3316fc6SZhikuiRen } 3780a3316fc6SZhikuiRen 37818d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 37826f284d24SJiaqing Zhao const std::string& entryId) 3783a3316fc6SZhikuiRen { 37846f284d24SJiaqing Zhao uint16_t bootIndex = 0; 37856f284d24SJiaqing Zhao uint64_t codeIndex = 0; 37866f284d24SJiaqing Zhao if (!parsePostCode(entryId, codeIndex, bootIndex)) 37876f284d24SJiaqing Zhao { 37886f284d24SJiaqing Zhao // Requested ID was not found 37896f284d24SJiaqing Zhao messages::resourceNotFound(aResp->res, "LogEntry", entryId); 37906f284d24SJiaqing Zhao return; 37916f284d24SJiaqing Zhao } 37926f284d24SJiaqing Zhao 37936f284d24SJiaqing Zhao if (bootIndex == 0 || codeIndex == 0) 37946f284d24SJiaqing Zhao { 37956f284d24SJiaqing Zhao // 0 is an invalid index 37966f284d24SJiaqing Zhao messages::resourceNotFound(aResp->res, "LogEntry", entryId); 37976f284d24SJiaqing Zhao return; 37986f284d24SJiaqing Zhao } 37996f284d24SJiaqing Zhao 3800a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 38016f284d24SJiaqing Zhao [aResp, entryId, bootIndex, 38026c9a279eSManojkiran Eda codeIndex](const boost::system::error_code ec, 38036c9a279eSManojkiran Eda const boost::container::flat_map< 38046c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 38056c9a279eSManojkiran Eda postcode) { 3806a3316fc6SZhikuiRen if (ec) 3807a3316fc6SZhikuiRen { 3808a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3809a3316fc6SZhikuiRen messages::internalError(aResp->res); 3810a3316fc6SZhikuiRen return; 3811a3316fc6SZhikuiRen } 3812a3316fc6SZhikuiRen 3813a3316fc6SZhikuiRen if (postcode.empty()) 3814a3316fc6SZhikuiRen { 38156f284d24SJiaqing Zhao messages::resourceNotFound(aResp->res, "LogEntry", entryId); 3816a3316fc6SZhikuiRen return; 3817a3316fc6SZhikuiRen } 3818a3316fc6SZhikuiRen 38196f284d24SJiaqing Zhao if (!fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex)) 38206f284d24SJiaqing Zhao { 38216f284d24SJiaqing Zhao messages::resourceNotFound(aResp->res, "LogEntry", entryId); 38226f284d24SJiaqing Zhao return; 38236f284d24SJiaqing Zhao } 3824a3316fc6SZhikuiRen }, 382515124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 382615124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3827a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3828a3316fc6SZhikuiRen bootIndex); 3829a3316fc6SZhikuiRen } 3830a3316fc6SZhikuiRen 38318d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3832a3316fc6SZhikuiRen const uint16_t bootIndex, 3833a3316fc6SZhikuiRen const uint16_t bootCount, 38343648c8beSEd Tanous const uint64_t entryCount, size_t skip, 38353648c8beSEd Tanous size_t top) 3836a3316fc6SZhikuiRen { 3837a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3838a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3839a3316fc6SZhikuiRen top](const boost::system::error_code ec, 38406c9a279eSManojkiran Eda const boost::container::flat_map< 38416c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 38426c9a279eSManojkiran Eda postcode) { 3843a3316fc6SZhikuiRen if (ec) 3844a3316fc6SZhikuiRen { 3845a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3846a3316fc6SZhikuiRen messages::internalError(aResp->res); 3847a3316fc6SZhikuiRen return; 3848a3316fc6SZhikuiRen } 3849a3316fc6SZhikuiRen 3850a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3851a3316fc6SZhikuiRen if (!postcode.empty()) 3852a3316fc6SZhikuiRen { 3853a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 38543648c8beSEd Tanous if (skip < endCount && (top + skip) > entryCount) 3855a3316fc6SZhikuiRen { 38563648c8beSEd Tanous uint64_t thisBootSkip = 38573648c8beSEd Tanous std::max(static_cast<uint64_t>(skip), entryCount) - 38583648c8beSEd Tanous entryCount; 3859a3316fc6SZhikuiRen uint64_t thisBootTop = 38603648c8beSEd Tanous std::min(static_cast<uint64_t>(top + skip), endCount) - 38613648c8beSEd Tanous entryCount; 3862a3316fc6SZhikuiRen 3863002d39b4SEd Tanous fillPostCodeEntry(aResp, postcode, bootIndex, 0, thisBootSkip, 3864002d39b4SEd Tanous thisBootTop); 3865a3316fc6SZhikuiRen } 3866a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3867a3316fc6SZhikuiRen } 3868a3316fc6SZhikuiRen 3869a3316fc6SZhikuiRen // continue to previous bootIndex 3870a3316fc6SZhikuiRen if (bootIndex < bootCount) 3871a3316fc6SZhikuiRen { 3872a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3873a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3874a3316fc6SZhikuiRen } 387581584abeSJiaqing Zhao else if (skip + top < endCount) 3876a3316fc6SZhikuiRen { 3877a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 38780fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries?$skip=" + 3879a3316fc6SZhikuiRen std::to_string(skip + top); 3880a3316fc6SZhikuiRen } 3881a3316fc6SZhikuiRen }, 388215124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 388315124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3884a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3885a3316fc6SZhikuiRen bootIndex); 3886a3316fc6SZhikuiRen } 3887a3316fc6SZhikuiRen 38888d1b46d7Szhanghch05 static void 38898d1b46d7Szhanghch05 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 38903648c8beSEd Tanous size_t skip, size_t top) 3891a3316fc6SZhikuiRen { 3892a3316fc6SZhikuiRen uint64_t entryCount = 0; 38931e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint16_t>( 38941e1e598dSJonathan Doman *crow::connections::systemBus, 38951e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 38961e1e598dSJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 38971e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", 38981e1e598dSJonathan Doman [aResp, entryCount, skip, top](const boost::system::error_code ec, 38991e1e598dSJonathan Doman const uint16_t bootCount) { 3900a3316fc6SZhikuiRen if (ec) 3901a3316fc6SZhikuiRen { 3902a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3903a3316fc6SZhikuiRen messages::internalError(aResp->res); 3904a3316fc6SZhikuiRen return; 3905a3316fc6SZhikuiRen } 39061e1e598dSJonathan Doman getPostCodeForBoot(aResp, 1, bootCount, entryCount, skip, top); 39071e1e598dSJonathan Doman }); 3908a3316fc6SZhikuiRen } 3909a3316fc6SZhikuiRen 39107e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3911a3316fc6SZhikuiRen { 39127e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 391322d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/") 3914ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 39157e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 391645ca1b86SEd Tanous [&app](const crow::Request& req, 391722d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 391822d268cbSEd Tanous const std::string& systemName) { 3919c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 3920c937d2bfSEd Tanous .canDelegateTop = true, 3921c937d2bfSEd Tanous .canDelegateSkip = true, 3922c937d2bfSEd Tanous }; 3923c937d2bfSEd Tanous query_param::Query delegatedQuery; 3924c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 39253ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 392645ca1b86SEd Tanous { 392745ca1b86SEd Tanous return; 392845ca1b86SEd Tanous } 392922d268cbSEd Tanous 393022d268cbSEd Tanous if (systemName != "system") 393122d268cbSEd Tanous { 393222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 393322d268cbSEd Tanous systemName); 393422d268cbSEd Tanous return; 393522d268cbSEd Tanous } 3936a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3937a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3938a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3939a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3940a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3941a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3942a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3943a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3944a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 39453648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 39465143f7a5SJiaqing Zhao size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop); 39473648c8beSEd Tanous getCurrentBootNumber(asyncResp, skip, top); 39487e860f15SJohn Edward Broadbent }); 3949a3316fc6SZhikuiRen } 3950a3316fc6SZhikuiRen 3951647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3952647b3cdcSGeorge Liu { 39530fda0f12SGeorge Liu BMCWEB_ROUTE( 39540fda0f12SGeorge Liu app, 395522d268cbSEd Tanous "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/attachment/") 3956647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 3957647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 395845ca1b86SEd Tanous [&app](const crow::Request& req, 3959647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 396022d268cbSEd Tanous const std::string& systemName, 3961647b3cdcSGeorge Liu const std::string& postCodeID) { 39623ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 396345ca1b86SEd Tanous { 396445ca1b86SEd Tanous return; 396545ca1b86SEd Tanous } 396699351cd8SEd Tanous if (http_helpers::isContentTypeAllowed( 396799351cd8SEd Tanous req.getHeaderValue("Accept"), 39684a0e1a0cSEd Tanous http_helpers::ContentType::OctetStream, true)) 3969647b3cdcSGeorge Liu { 3970002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 3971647b3cdcSGeorge Liu return; 3972647b3cdcSGeorge Liu } 397322d268cbSEd Tanous if (systemName != "system") 397422d268cbSEd Tanous { 397522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 397622d268cbSEd Tanous systemName); 397722d268cbSEd Tanous return; 397822d268cbSEd Tanous } 3979647b3cdcSGeorge Liu 3980647b3cdcSGeorge Liu uint64_t currentValue = 0; 3981647b3cdcSGeorge Liu uint16_t index = 0; 3982647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 3983647b3cdcSGeorge Liu { 3984002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID); 3985647b3cdcSGeorge Liu return; 3986647b3cdcSGeorge Liu } 3987647b3cdcSGeorge Liu 3988647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 3989647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 3990647b3cdcSGeorge Liu const boost::system::error_code ec, 3991002d39b4SEd Tanous const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>& 3992002d39b4SEd Tanous postcodes) { 3993647b3cdcSGeorge Liu if (ec.value() == EBADR) 3994647b3cdcSGeorge Liu { 3995002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 3996002d39b4SEd Tanous postCodeID); 3997647b3cdcSGeorge Liu return; 3998647b3cdcSGeorge Liu } 3999647b3cdcSGeorge Liu if (ec) 4000647b3cdcSGeorge Liu { 4001647b3cdcSGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 4002647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 4003647b3cdcSGeorge Liu return; 4004647b3cdcSGeorge Liu } 4005647b3cdcSGeorge Liu 4006647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 4007002d39b4SEd Tanous if (value == std::string::npos || postcodes.size() < currentValue) 4008647b3cdcSGeorge Liu { 4009647b3cdcSGeorge Liu BMCWEB_LOG_ERROR << "Wrong currentValue value"; 4010002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4011002d39b4SEd Tanous postCodeID); 4012647b3cdcSGeorge Liu return; 4013647b3cdcSGeorge Liu } 4014647b3cdcSGeorge Liu 40159eb808c1SEd Tanous const auto& [tID, c] = postcodes[value]; 401646ff87baSEd Tanous if (c.empty()) 4017647b3cdcSGeorge Liu { 4018647b3cdcSGeorge Liu BMCWEB_LOG_INFO << "No found post code data"; 4019002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 4020002d39b4SEd Tanous postCodeID); 4021647b3cdcSGeorge Liu return; 4022647b3cdcSGeorge Liu } 402346ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 402446ff87baSEd Tanous const char* d = reinterpret_cast<const char*>(c.data()); 402546ff87baSEd Tanous std::string_view strData(d, c.size()); 4026647b3cdcSGeorge Liu 4027d9f6c621SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::content_type, 4028647b3cdcSGeorge Liu "application/octet-stream"); 4029d9f6c621SEd Tanous asyncResp->res.addHeader( 4030d9f6c621SEd Tanous boost::beast::http::field::content_transfer_encoding, "Base64"); 4031002d39b4SEd Tanous asyncResp->res.body() = crow::utility::base64encode(strData); 4032647b3cdcSGeorge Liu }, 4033647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 4034647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 4035002d39b4SEd Tanous "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index); 4036647b3cdcSGeorge Liu }); 4037647b3cdcSGeorge Liu } 4038647b3cdcSGeorge Liu 40397e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 4040a3316fc6SZhikuiRen { 40417e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 404222d268cbSEd Tanous app, "/redfish/v1/Systems/<str>/LogServices/PostCodes/Entries/<str>/") 4043ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 40447e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 404545ca1b86SEd Tanous [&app](const crow::Request& req, 40467e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 404722d268cbSEd Tanous const std::string& systemName, const std::string& targetID) { 40483ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 404945ca1b86SEd Tanous { 405045ca1b86SEd Tanous return; 405145ca1b86SEd Tanous } 405222d268cbSEd Tanous if (systemName != "system") 405322d268cbSEd Tanous { 405422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 405522d268cbSEd Tanous systemName); 405622d268cbSEd Tanous return; 405722d268cbSEd Tanous } 405822d268cbSEd Tanous 40596f284d24SJiaqing Zhao getPostCodeForEntry(asyncResp, targetID); 40607e860f15SJohn Edward Broadbent }); 4061a3316fc6SZhikuiRen } 4062a3316fc6SZhikuiRen 40631da66f75SEd Tanous } // namespace redfish 4064