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 18b7028ebfSSpencer Ku #include "gzfile.hpp" 19647b3cdcSGeorge Liu #include "http_utility.hpp" 20b7028ebfSSpencer Ku #include "human_sort.hpp" 214851d45dSJason M. Bills #include "registries.hpp" 224851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 234851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2446229577SJames Feist #include "task.hpp" 251da66f75SEd Tanous 26e1f26343SJason M. Bills #include <systemd/sd-journal.h> 27400fd1fbSAdriana Kobylak #include <unistd.h> 28e1f26343SJason M. Bills 297e860f15SJohn Edward Broadbent #include <app.hpp> 309896eaedSEd Tanous #include <boost/algorithm/string/case_conv.hpp> 3111ba3979SEd Tanous #include <boost/algorithm/string/classification.hpp> 32400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 334851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 3407c8c20dSEd Tanous #include <boost/beast/http/verb.hpp> 351da66f75SEd Tanous #include <boost/container/flat_map.hpp> 361ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 37168e20c1SEd Tanous #include <dbus_utility.hpp> 38cb92c03bSAndrew Geissler #include <error_messages.hpp> 3945ca1b86SEd Tanous #include <query.hpp> 40ed398213SEd Tanous #include <registries/privilege_registry.hpp> 411214b7e7SGunnar Mills 42647b3cdcSGeorge Liu #include <charconv> 434418c7f0SJames Feist #include <filesystem> 4475710de2SXiaochao Ma #include <optional> 4526702d01SEd Tanous #include <span> 46cd225da8SJason M. Bills #include <string_view> 47abf2add6SEd Tanous #include <variant> 481da66f75SEd Tanous 491da66f75SEd Tanous namespace redfish 501da66f75SEd Tanous { 511da66f75SEd Tanous 525b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 535b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 545b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 555b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 565b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 575b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 58424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 596eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 606eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 611da66f75SEd Tanous 62fffb8c1fSEd Tanous namespace registries 634851d45dSJason M. Bills { 6426702d01SEd Tanous static const Message* 6526702d01SEd Tanous getMessageFromRegistry(const std::string& messageKey, 6626702d01SEd Tanous const std::span<const MessageEntry> registry) 674851d45dSJason M. Bills { 68002d39b4SEd Tanous std::span<const MessageEntry>::iterator messageIt = 69002d39b4SEd Tanous std::find_if(registry.begin(), registry.end(), 704851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 71e662eae8SEd Tanous return std::strcmp(messageEntry.first, messageKey.c_str()) == 0; 724851d45dSJason M. Bills }); 7326702d01SEd Tanous if (messageIt != registry.end()) 744851d45dSJason M. Bills { 754851d45dSJason M. Bills return &messageIt->second; 764851d45dSJason M. Bills } 774851d45dSJason M. Bills 784851d45dSJason M. Bills return nullptr; 794851d45dSJason M. Bills } 804851d45dSJason M. Bills 814851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 824851d45dSJason M. Bills { 834851d45dSJason M. Bills // Redfish MessageIds are in the form 844851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 854851d45dSJason M. Bills // the right Message 864851d45dSJason M. Bills std::vector<std::string> fields; 874851d45dSJason M. Bills fields.reserve(4); 884851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 8902cad96eSEd Tanous const std::string& registryName = fields[0]; 9002cad96eSEd Tanous const std::string& messageKey = fields[3]; 914851d45dSJason M. Bills 924851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 934851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 944851d45dSJason M. Bills { 954851d45dSJason M. Bills return getMessageFromRegistry( 9626702d01SEd Tanous messageKey, std::span<const MessageEntry>(base::registry)); 974851d45dSJason M. Bills } 984851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 994851d45dSJason M. Bills { 1004851d45dSJason M. Bills return getMessageFromRegistry( 10126702d01SEd Tanous messageKey, std::span<const MessageEntry>(openbmc::registry)); 1024851d45dSJason M. Bills } 1034851d45dSJason M. Bills return nullptr; 1044851d45dSJason M. Bills } 105fffb8c1fSEd Tanous } // namespace registries 1064851d45dSJason M. Bills 107f6150403SJames Feist namespace fs = std::filesystem; 1081da66f75SEd Tanous 109cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 110cb92c03bSAndrew Geissler { 111d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 112d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 113d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 114d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 115cb92c03bSAndrew Geissler { 116cb92c03bSAndrew Geissler return "Critical"; 117cb92c03bSAndrew Geissler } 1183174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 119d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 120d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 121cb92c03bSAndrew Geissler { 122cb92c03bSAndrew Geissler return "OK"; 123cb92c03bSAndrew Geissler } 1243174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 125cb92c03bSAndrew Geissler { 126cb92c03bSAndrew Geissler return "Warning"; 127cb92c03bSAndrew Geissler } 128cb92c03bSAndrew Geissler return ""; 129cb92c03bSAndrew Geissler } 130cb92c03bSAndrew Geissler 1317e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 13239e77504SEd Tanous const std::string_view& field, 13339e77504SEd Tanous std::string_view& contents) 13416428a1aSJason M. Bills { 13516428a1aSJason M. Bills const char* data = nullptr; 13616428a1aSJason M. Bills size_t length = 0; 13716428a1aSJason M. Bills int ret = 0; 13816428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 13946ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 14046ff87baSEd Tanous const void** dataVoid = reinterpret_cast<const void**>(&data); 14146ff87baSEd Tanous 14246ff87baSEd Tanous ret = sd_journal_get_data(journal, field.data(), dataVoid, &length); 14316428a1aSJason M. Bills if (ret < 0) 14416428a1aSJason M. Bills { 14516428a1aSJason M. Bills return ret; 14616428a1aSJason M. Bills } 14739e77504SEd Tanous contents = std::string_view(data, length); 14816428a1aSJason M. Bills // Only use the content after the "=" character. 14981ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 15016428a1aSJason M. Bills return ret; 15116428a1aSJason M. Bills } 15216428a1aSJason M. Bills 1537e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 1547e860f15SJohn Edward Broadbent const std::string_view& field, 1557e860f15SJohn Edward Broadbent const int& base, long int& contents) 15616428a1aSJason M. Bills { 15716428a1aSJason M. Bills int ret = 0; 15839e77504SEd Tanous std::string_view metadata; 15916428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 16016428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 16116428a1aSJason M. Bills if (ret < 0) 16216428a1aSJason M. Bills { 16316428a1aSJason M. Bills return ret; 16416428a1aSJason M. Bills } 165b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 16616428a1aSJason M. Bills return ret; 16716428a1aSJason M. Bills } 16816428a1aSJason M. Bills 1697e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1707e860f15SJohn Edward Broadbent std::string& entryTimestamp) 171a3316fc6SZhikuiRen { 172a3316fc6SZhikuiRen int ret = 0; 173a3316fc6SZhikuiRen uint64_t timestamp = 0; 174a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 175a3316fc6SZhikuiRen if (ret < 0) 176a3316fc6SZhikuiRen { 177a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 178a3316fc6SZhikuiRen << strerror(-ret); 179a3316fc6SZhikuiRen return false; 180a3316fc6SZhikuiRen } 1811d8782e7SNan Zhou entryTimestamp = crow::utility::getDateTimeUint(timestamp / 1000 / 1000); 1829c620e21SAsmitha Karunanithi return true; 183a3316fc6SZhikuiRen } 18450b8a43aSEd Tanous 1857e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 186e85d6b16SJason M. Bills const bool firstEntry = true) 18716428a1aSJason M. Bills { 18816428a1aSJason M. Bills int ret = 0; 18916428a1aSJason M. Bills static uint64_t prevTs = 0; 19016428a1aSJason M. Bills static int index = 0; 191e85d6b16SJason M. Bills if (firstEntry) 192e85d6b16SJason M. Bills { 193e85d6b16SJason M. Bills prevTs = 0; 194e85d6b16SJason M. Bills } 195e85d6b16SJason M. Bills 19616428a1aSJason M. Bills // Get the entry timestamp 19716428a1aSJason M. Bills uint64_t curTs = 0; 19816428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 19916428a1aSJason M. Bills if (ret < 0) 20016428a1aSJason M. Bills { 20116428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 20216428a1aSJason M. Bills << strerror(-ret); 20316428a1aSJason M. Bills return false; 20416428a1aSJason M. Bills } 20516428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 20616428a1aSJason M. Bills if (curTs == prevTs) 20716428a1aSJason M. Bills { 20816428a1aSJason M. Bills index++; 20916428a1aSJason M. Bills } 21016428a1aSJason M. Bills else 21116428a1aSJason M. Bills { 21216428a1aSJason M. Bills // Otherwise, reset it 21316428a1aSJason M. Bills index = 0; 21416428a1aSJason M. Bills } 21516428a1aSJason M. Bills // Save the timestamp 21616428a1aSJason M. Bills prevTs = curTs; 21716428a1aSJason M. Bills 21816428a1aSJason M. Bills entryID = std::to_string(curTs); 21916428a1aSJason M. Bills if (index > 0) 22016428a1aSJason M. Bills { 22116428a1aSJason M. Bills entryID += "_" + std::to_string(index); 22216428a1aSJason M. Bills } 22316428a1aSJason M. Bills return true; 22416428a1aSJason M. Bills } 22516428a1aSJason M. Bills 226e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 227e85d6b16SJason M. Bills const bool firstEntry = true) 22895820184SJason M. Bills { 229271584abSEd Tanous static time_t prevTs = 0; 23095820184SJason M. Bills static int index = 0; 231e85d6b16SJason M. Bills if (firstEntry) 232e85d6b16SJason M. Bills { 233e85d6b16SJason M. Bills prevTs = 0; 234e85d6b16SJason M. Bills } 235e85d6b16SJason M. Bills 23695820184SJason M. Bills // Get the entry timestamp 237271584abSEd Tanous std::time_t curTs = 0; 23895820184SJason M. Bills std::tm timeStruct = {}; 23995820184SJason M. Bills std::istringstream entryStream(logEntry); 24095820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 24195820184SJason M. Bills { 24295820184SJason M. Bills curTs = std::mktime(&timeStruct); 24395820184SJason M. Bills } 24495820184SJason M. Bills // If the timestamp isn't unique, increment the index 24595820184SJason M. Bills if (curTs == prevTs) 24695820184SJason M. Bills { 24795820184SJason M. Bills index++; 24895820184SJason M. Bills } 24995820184SJason M. Bills else 25095820184SJason M. Bills { 25195820184SJason M. Bills // Otherwise, reset it 25295820184SJason M. Bills index = 0; 25395820184SJason M. Bills } 25495820184SJason M. Bills // Save the timestamp 25595820184SJason M. Bills prevTs = curTs; 25695820184SJason M. Bills 25795820184SJason M. Bills entryID = std::to_string(curTs); 25895820184SJason M. Bills if (index > 0) 25995820184SJason M. Bills { 26095820184SJason M. Bills entryID += "_" + std::to_string(index); 26195820184SJason M. Bills } 26295820184SJason M. Bills return true; 26395820184SJason M. Bills } 26495820184SJason M. Bills 2657e860f15SJohn Edward Broadbent inline static bool 2668d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2678d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 2688d1b46d7Szhanghch05 uint64_t& index) 26916428a1aSJason M. Bills { 27016428a1aSJason M. Bills if (entryID.empty()) 27116428a1aSJason M. Bills { 27216428a1aSJason M. Bills return false; 27316428a1aSJason M. Bills } 27416428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 27539e77504SEd Tanous std::string_view tsStr(entryID); 27616428a1aSJason M. Bills 27781ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 27871d5d8dbSEd Tanous if (underscorePos != std::string_view::npos) 27916428a1aSJason M. Bills { 28016428a1aSJason M. Bills // Timestamp has an index 28116428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 28239e77504SEd Tanous std::string_view indexStr(entryID); 28316428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 284c0bd5e4bSEd Tanous auto [ptr, ec] = std::from_chars( 285c0bd5e4bSEd Tanous indexStr.data(), indexStr.data() + indexStr.size(), index); 286c0bd5e4bSEd Tanous if (ec != std::errc()) 28716428a1aSJason M. Bills { 288ace85d60SEd Tanous messages::resourceMissingAtURI( 289ace85d60SEd Tanous asyncResp->res, crow::utility::urlFromPieces(entryID)); 29016428a1aSJason M. Bills return false; 29116428a1aSJason M. Bills } 29216428a1aSJason M. Bills } 29316428a1aSJason M. Bills // Timestamp has no index 294c0bd5e4bSEd Tanous auto [ptr, ec] = 295c0bd5e4bSEd Tanous std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp); 296c0bd5e4bSEd Tanous if (ec != std::errc()) 29716428a1aSJason M. Bills { 298ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, 299ace85d60SEd Tanous crow::utility::urlFromPieces(entryID)); 30016428a1aSJason M. Bills return false; 30116428a1aSJason M. Bills } 30216428a1aSJason M. Bills return true; 30316428a1aSJason M. Bills } 30416428a1aSJason M. Bills 30595820184SJason M. Bills static bool 30695820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 30795820184SJason M. Bills { 30895820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 30995820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 31095820184SJason M. Bills 31195820184SJason M. Bills // Loop through the directory looking for redfish log files 31295820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 31395820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 31495820184SJason M. Bills { 31595820184SJason M. Bills // If we find a redfish log file, save the path 31695820184SJason M. Bills std::string filename = dirEnt.path().filename(); 31711ba3979SEd Tanous if (filename.starts_with(redfishLogFilename)) 31895820184SJason M. Bills { 31995820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 32095820184SJason M. Bills } 32195820184SJason M. Bills } 32295820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 32395820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 32495820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 32595820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 32695820184SJason M. Bills 32795820184SJason M. Bills return !redfishLogFiles.empty(); 32895820184SJason M. Bills } 32995820184SJason M. Bills 330aefe3786SClaire Weinan inline void parseDumpEntryFromDbusObject( 331aefe3786SClaire Weinan const dbus::utility::ManagedItem& object, std::string& dumpStatus, 332aefe3786SClaire Weinan uint64_t& size, uint64_t& timestamp, 333aefe3786SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 334aefe3786SClaire Weinan { 335aefe3786SClaire Weinan for (const auto& interfaceMap : object.second) 336aefe3786SClaire Weinan { 337aefe3786SClaire Weinan if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") 338aefe3786SClaire Weinan { 339aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 340aefe3786SClaire Weinan { 341aefe3786SClaire Weinan if (propertyMap.first == "Status") 342aefe3786SClaire Weinan { 343aefe3786SClaire Weinan const auto* status = 344aefe3786SClaire Weinan std::get_if<std::string>(&propertyMap.second); 345aefe3786SClaire Weinan if (status == nullptr) 346aefe3786SClaire Weinan { 347aefe3786SClaire Weinan messages::internalError(asyncResp->res); 348aefe3786SClaire Weinan break; 349aefe3786SClaire Weinan } 350aefe3786SClaire Weinan dumpStatus = *status; 351aefe3786SClaire Weinan } 352aefe3786SClaire Weinan } 353aefe3786SClaire Weinan } 354aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 355aefe3786SClaire Weinan { 356aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 357aefe3786SClaire Weinan { 358aefe3786SClaire Weinan if (propertyMap.first == "Size") 359aefe3786SClaire Weinan { 360aefe3786SClaire Weinan const auto* sizePtr = 361aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 362aefe3786SClaire Weinan if (sizePtr == nullptr) 363aefe3786SClaire Weinan { 364aefe3786SClaire Weinan messages::internalError(asyncResp->res); 365aefe3786SClaire Weinan break; 366aefe3786SClaire Weinan } 367aefe3786SClaire Weinan size = *sizePtr; 368aefe3786SClaire Weinan break; 369aefe3786SClaire Weinan } 370aefe3786SClaire Weinan } 371aefe3786SClaire Weinan } 372aefe3786SClaire Weinan else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") 373aefe3786SClaire Weinan { 374aefe3786SClaire Weinan for (const auto& propertyMap : interfaceMap.second) 375aefe3786SClaire Weinan { 376aefe3786SClaire Weinan if (propertyMap.first == "Elapsed") 377aefe3786SClaire Weinan { 378aefe3786SClaire Weinan const uint64_t* usecsTimeStamp = 379aefe3786SClaire Weinan std::get_if<uint64_t>(&propertyMap.second); 380aefe3786SClaire Weinan if (usecsTimeStamp == nullptr) 381aefe3786SClaire Weinan { 382aefe3786SClaire Weinan messages::internalError(asyncResp->res); 383aefe3786SClaire Weinan break; 384aefe3786SClaire Weinan } 385aefe3786SClaire Weinan timestamp = *usecsTimeStamp; 386aefe3786SClaire Weinan break; 387aefe3786SClaire Weinan } 388aefe3786SClaire Weinan } 389aefe3786SClaire Weinan } 390aefe3786SClaire Weinan } 391aefe3786SClaire Weinan } 392aefe3786SClaire Weinan 39321ab404cSNan Zhou static std::string getDumpEntriesPath(const std::string& dumpType) 394fdd26906SClaire Weinan { 395fdd26906SClaire Weinan std::string entriesPath; 396fdd26906SClaire Weinan 397fdd26906SClaire Weinan if (dumpType == "BMC") 398fdd26906SClaire Weinan { 399fdd26906SClaire Weinan entriesPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 400fdd26906SClaire Weinan } 401fdd26906SClaire Weinan else if (dumpType == "FaultLog") 402fdd26906SClaire Weinan { 403fdd26906SClaire Weinan entriesPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/"; 404fdd26906SClaire Weinan } 405fdd26906SClaire Weinan else if (dumpType == "System") 406fdd26906SClaire Weinan { 407fdd26906SClaire Weinan entriesPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 408fdd26906SClaire Weinan } 409fdd26906SClaire Weinan else 410fdd26906SClaire Weinan { 411fdd26906SClaire Weinan BMCWEB_LOG_ERROR << "getDumpEntriesPath() invalid dump type: " 412fdd26906SClaire Weinan << dumpType; 413fdd26906SClaire Weinan } 414fdd26906SClaire Weinan 415fdd26906SClaire Weinan // Returns empty string on error 416fdd26906SClaire Weinan return entriesPath; 417fdd26906SClaire Weinan } 418fdd26906SClaire Weinan 4198d1b46d7Szhanghch05 inline void 4208d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4215cb1dd27SAsmitha Karunanithi const std::string& dumpType) 4225cb1dd27SAsmitha Karunanithi { 423fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 424fdd26906SClaire Weinan if (entriesPath.empty()) 4255cb1dd27SAsmitha Karunanithi { 4265cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4275cb1dd27SAsmitha Karunanithi return; 4285cb1dd27SAsmitha Karunanithi } 4295cb1dd27SAsmitha Karunanithi 4305cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 431fdd26906SClaire Weinan [asyncResp, entriesPath, 432711ac7a9SEd Tanous dumpType](const boost::system::error_code ec, 433711ac7a9SEd Tanous dbus::utility::ManagedObjectType& resp) { 4345cb1dd27SAsmitha Karunanithi if (ec) 4355cb1dd27SAsmitha Karunanithi { 4365cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4375cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4385cb1dd27SAsmitha Karunanithi return; 4395cb1dd27SAsmitha Karunanithi } 4405cb1dd27SAsmitha Karunanithi 441fdd26906SClaire Weinan // Remove ending slash 442fdd26906SClaire Weinan std::string odataIdStr = entriesPath; 443fdd26906SClaire Weinan if (!odataIdStr.empty()) 444fdd26906SClaire Weinan { 445fdd26906SClaire Weinan odataIdStr.pop_back(); 446fdd26906SClaire Weinan } 447fdd26906SClaire Weinan 448fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = 449fdd26906SClaire Weinan "#LogEntryCollection.LogEntryCollection"; 450fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = std::move(odataIdStr); 451fdd26906SClaire Weinan asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entries"; 452fdd26906SClaire Weinan asyncResp->res.jsonValue["Description"] = 453fdd26906SClaire Weinan "Collection of " + dumpType + " Dump Entries"; 454fdd26906SClaire Weinan 4555cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4565cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 457b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 458b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 459002d39b4SEd Tanous std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; 4605cb1dd27SAsmitha Karunanithi 461002d39b4SEd Tanous std::sort(resp.begin(), resp.end(), [](const auto& l, const auto& r) { 462002d39b4SEd Tanous return AlphanumLess<std::string>()(l.first.filename(), 463002d39b4SEd Tanous r.first.filename()); 464565dfb6fSClaire Weinan }); 465565dfb6fSClaire Weinan 4665cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4675cb1dd27SAsmitha Karunanithi { 468b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 4695cb1dd27SAsmitha Karunanithi { 4705cb1dd27SAsmitha Karunanithi continue; 4715cb1dd27SAsmitha Karunanithi } 4721d8782e7SNan Zhou uint64_t timestamp = 0; 4735cb1dd27SAsmitha Karunanithi uint64_t size = 0; 47435440d18SAsmitha Karunanithi std::string dumpStatus; 475433b68b4SJason M. Bills nlohmann::json::object_t thisEntry; 4762dfd18efSEd Tanous 4772dfd18efSEd Tanous std::string entryID = object.first.filename(); 4782dfd18efSEd Tanous if (entryID.empty()) 4795cb1dd27SAsmitha Karunanithi { 4805cb1dd27SAsmitha Karunanithi continue; 4815cb1dd27SAsmitha Karunanithi } 4825cb1dd27SAsmitha Karunanithi 483aefe3786SClaire Weinan parseDumpEntryFromDbusObject(object, dumpStatus, size, timestamp, 484aefe3786SClaire Weinan asyncResp); 4855cb1dd27SAsmitha Karunanithi 4860fda0f12SGeorge Liu if (dumpStatus != 4870fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 48835440d18SAsmitha Karunanithi !dumpStatus.empty()) 48935440d18SAsmitha Karunanithi { 49035440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 49135440d18SAsmitha Karunanithi continue; 49235440d18SAsmitha Karunanithi } 49335440d18SAsmitha Karunanithi 494647b3cdcSGeorge Liu thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 495fdd26906SClaire Weinan thisEntry["@odata.id"] = entriesPath + entryID; 4965cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 4975cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 498002d39b4SEd Tanous thisEntry["Created"] = crow::utility::getDateTimeUint(timestamp); 4995cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 5005cb1dd27SAsmitha Karunanithi 5015cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5025cb1dd27SAsmitha Karunanithi { 503d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 504d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 505fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 506fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 5075cb1dd27SAsmitha Karunanithi } 5085cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5095cb1dd27SAsmitha Karunanithi { 510d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 511d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 512d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 513fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 514fdd26906SClaire Weinan thisEntry["AdditionalDataSizeBytes"] = size; 5155cb1dd27SAsmitha Karunanithi } 51635440d18SAsmitha Karunanithi entriesArray.push_back(std::move(thisEntry)); 5175cb1dd27SAsmitha Karunanithi } 518002d39b4SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size(); 5195cb1dd27SAsmitha Karunanithi }, 5205cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5215cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5225cb1dd27SAsmitha Karunanithi } 5235cb1dd27SAsmitha Karunanithi 5248d1b46d7Szhanghch05 inline void 525c7a6d660SClaire Weinan getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5268d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 5275cb1dd27SAsmitha Karunanithi { 528fdd26906SClaire Weinan std::string entriesPath = getDumpEntriesPath(dumpType); 529fdd26906SClaire Weinan if (entriesPath.empty()) 5305cb1dd27SAsmitha Karunanithi { 5315cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5325cb1dd27SAsmitha Karunanithi return; 5335cb1dd27SAsmitha Karunanithi } 5345cb1dd27SAsmitha Karunanithi 5355cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 536fdd26906SClaire Weinan [asyncResp, entryID, dumpType, 537fdd26906SClaire Weinan entriesPath](const boost::system::error_code ec, 53802cad96eSEd Tanous const dbus::utility::ManagedObjectType& resp) { 5395cb1dd27SAsmitha Karunanithi if (ec) 5405cb1dd27SAsmitha Karunanithi { 5415cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5425cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5435cb1dd27SAsmitha Karunanithi return; 5445cb1dd27SAsmitha Karunanithi } 5455cb1dd27SAsmitha Karunanithi 546b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 547b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 548b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 549002d39b4SEd Tanous std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; 550b47452b2SAsmitha Karunanithi 5519eb808c1SEd Tanous for (const auto& objectPath : resp) 5525cb1dd27SAsmitha Karunanithi { 553b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5545cb1dd27SAsmitha Karunanithi { 5555cb1dd27SAsmitha Karunanithi continue; 5565cb1dd27SAsmitha Karunanithi } 5575cb1dd27SAsmitha Karunanithi 5585cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 5591d8782e7SNan Zhou uint64_t timestamp = 0; 5605cb1dd27SAsmitha Karunanithi uint64_t size = 0; 56135440d18SAsmitha Karunanithi std::string dumpStatus; 5625cb1dd27SAsmitha Karunanithi 563aefe3786SClaire Weinan parseDumpEntryFromDbusObject(objectPath, dumpStatus, size, 564aefe3786SClaire Weinan timestamp, asyncResp); 5655cb1dd27SAsmitha Karunanithi 5660fda0f12SGeorge Liu if (dumpStatus != 5670fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 56835440d18SAsmitha Karunanithi !dumpStatus.empty()) 56935440d18SAsmitha Karunanithi { 57035440d18SAsmitha Karunanithi // Dump status is not Complete 57135440d18SAsmitha Karunanithi // return not found until status is changed to Completed 572002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, dumpType + " dump", 573002d39b4SEd Tanous entryID); 57435440d18SAsmitha Karunanithi return; 57535440d18SAsmitha Karunanithi } 57635440d18SAsmitha Karunanithi 5775cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 578647b3cdcSGeorge Liu "#LogEntry.v1_8_0.LogEntry"; 579fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID; 5805cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 5815cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 5825cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 5831d8782e7SNan Zhou crow::utility::getDateTimeUint(timestamp); 5845cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 5855cb1dd27SAsmitha Karunanithi 5865cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5875cb1dd27SAsmitha Karunanithi { 588d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 589d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 590fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 591fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 5925cb1dd27SAsmitha Karunanithi } 5935cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5945cb1dd27SAsmitha Karunanithi { 595d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 596002d39b4SEd Tanous asyncResp->res.jsonValue["OEMDiagnosticDataType"] = "System"; 597d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 598fdd26906SClaire Weinan entriesPath + entryID + "/attachment"; 599fdd26906SClaire Weinan asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6005cb1dd27SAsmitha Karunanithi } 6015cb1dd27SAsmitha Karunanithi } 602e05aec50SEd Tanous if (!foundDumpEntry) 603b47452b2SAsmitha Karunanithi { 604b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 605b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 606b47452b2SAsmitha Karunanithi return; 607b47452b2SAsmitha Karunanithi } 6085cb1dd27SAsmitha Karunanithi }, 6095cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6105cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6115cb1dd27SAsmitha Karunanithi } 6125cb1dd27SAsmitha Karunanithi 6138d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6149878256fSStanley Chu const std::string& entryID, 615b47452b2SAsmitha Karunanithi const std::string& dumpType) 6165cb1dd27SAsmitha Karunanithi { 617002d39b4SEd Tanous auto respHandler = 618002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec) { 6195cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6205cb1dd27SAsmitha Karunanithi if (ec) 6215cb1dd27SAsmitha Karunanithi { 6223de8d8baSGeorge Liu if (ec.value() == EBADR) 6233de8d8baSGeorge Liu { 6243de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 6253de8d8baSGeorge Liu return; 6263de8d8baSGeorge Liu } 6275cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 628fdd26906SClaire Weinan << ec << " entryID=" << entryID; 6295cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6305cb1dd27SAsmitha Karunanithi return; 6315cb1dd27SAsmitha Karunanithi } 6325cb1dd27SAsmitha Karunanithi }; 6335cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 6345cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 635b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 636b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 637b47452b2SAsmitha Karunanithi entryID, 6385cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 6395cb1dd27SAsmitha Karunanithi } 6405cb1dd27SAsmitha Karunanithi 6418d1b46d7Szhanghch05 inline void 64298be3e39SEd Tanous createDumpTaskCallback(task::Payload&& payload, 6438d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6448d1b46d7Szhanghch05 const uint32_t& dumpId, const std::string& dumpPath, 645a43be80fSAsmitha Karunanithi const std::string& dumpType) 646a43be80fSAsmitha Karunanithi { 647a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 64859d494eeSPatrick Williams [dumpId, dumpPath, 64959d494eeSPatrick Williams dumpType](boost::system::error_code err, sdbusplus::message_t& m, 650a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 651cb13a392SEd Tanous if (err) 652cb13a392SEd Tanous { 6536145ed6fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Error in creating a dump"; 6546145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 6556145ed6fSAsmitha Karunanithi return task::completed; 656cb13a392SEd Tanous } 657b9d36b47SEd Tanous 658b9d36b47SEd Tanous dbus::utility::DBusInteracesMap interfacesList; 659a43be80fSAsmitha Karunanithi 660a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 661a43be80fSAsmitha Karunanithi 662a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 663a43be80fSAsmitha Karunanithi 664b47452b2SAsmitha Karunanithi if (objPath.str == 665b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 666b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 667b47452b2SAsmitha Karunanithi "/entry/" + std::to_string(dumpId)) 668a43be80fSAsmitha Karunanithi { 669a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 670a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 671a43be80fSAsmitha Karunanithi 672a43be80fSAsmitha Karunanithi std::string headerLoc = 673a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 674002d39b4SEd Tanous taskData->payload->httpHeaders.emplace_back(std::move(headerLoc)); 675a43be80fSAsmitha Karunanithi 676a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 677b47452b2SAsmitha Karunanithi return task::completed; 6786145ed6fSAsmitha Karunanithi } 679a43be80fSAsmitha Karunanithi return task::completed; 680a43be80fSAsmitha Karunanithi }, 6814978b63fSJason M. Bills "type='signal',interface='org.freedesktop.DBus.ObjectManager'," 682a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 683a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 684a43be80fSAsmitha Karunanithi 685a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 686a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 68798be3e39SEd Tanous task->payload.emplace(std::move(payload)); 688a43be80fSAsmitha Karunanithi } 689a43be80fSAsmitha Karunanithi 6908d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6918d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 692a43be80fSAsmitha Karunanithi { 693fdd26906SClaire Weinan std::string dumpPath = getDumpEntriesPath(dumpType); 694fdd26906SClaire Weinan if (dumpPath.empty()) 695a43be80fSAsmitha Karunanithi { 696a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 697a43be80fSAsmitha Karunanithi return; 698a43be80fSAsmitha Karunanithi } 699a43be80fSAsmitha Karunanithi 700a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 701a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 702a43be80fSAsmitha Karunanithi 70315ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 704a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 705a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 706a43be80fSAsmitha Karunanithi { 707a43be80fSAsmitha Karunanithi return; 708a43be80fSAsmitha Karunanithi } 709a43be80fSAsmitha Karunanithi 710a43be80fSAsmitha Karunanithi if (dumpType == "System") 711a43be80fSAsmitha Karunanithi { 712a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 713a43be80fSAsmitha Karunanithi { 7144978b63fSJason M. Bills BMCWEB_LOG_ERROR 7154978b63fSJason M. Bills << "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"; 716a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 717a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 718a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 719a43be80fSAsmitha Karunanithi return; 720a43be80fSAsmitha Karunanithi } 7213174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 722a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 723a43be80fSAsmitha Karunanithi { 724a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 725ace85d60SEd Tanous messages::internalError(asyncResp->res); 726a43be80fSAsmitha Karunanithi return; 727a43be80fSAsmitha Karunanithi } 728*5907571dSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/"; 729a43be80fSAsmitha Karunanithi } 730a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 731a43be80fSAsmitha Karunanithi { 732a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 733a43be80fSAsmitha Karunanithi { 7340fda0f12SGeorge Liu BMCWEB_LOG_ERROR 7350fda0f12SGeorge Liu << "CreateDump action parameter 'DiagnosticDataType' not found!"; 736a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 737a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 738a43be80fSAsmitha Karunanithi return; 739a43be80fSAsmitha Karunanithi } 7403174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 741a43be80fSAsmitha Karunanithi { 742a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 743a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 744ace85d60SEd Tanous messages::internalError(asyncResp->res); 745a43be80fSAsmitha Karunanithi return; 746a43be80fSAsmitha Karunanithi } 747*5907571dSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/"; 748*5907571dSAsmitha Karunanithi } 749*5907571dSAsmitha Karunanithi else 750*5907571dSAsmitha Karunanithi { 751*5907571dSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump failed. Unknown dump type"; 752*5907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 753*5907571dSAsmitha Karunanithi return; 754a43be80fSAsmitha Karunanithi } 755a43be80fSAsmitha Karunanithi 756a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 75798be3e39SEd Tanous [asyncResp, payload(task::Payload(req)), dumpPath, 75898be3e39SEd Tanous dumpType](const boost::system::error_code ec, 759*5907571dSAsmitha Karunanithi const sdbusplus::message::message& msg, 76098be3e39SEd Tanous const uint32_t& dumpId) mutable { 761a43be80fSAsmitha Karunanithi if (ec) 762a43be80fSAsmitha Karunanithi { 763a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 764*5907571dSAsmitha Karunanithi const sd_bus_error* dbusError = msg.get_error(); 765*5907571dSAsmitha Karunanithi if (dbusError == nullptr) 766*5907571dSAsmitha Karunanithi { 767*5907571dSAsmitha Karunanithi messages::internalError(asyncResp->res); 768*5907571dSAsmitha Karunanithi return; 769*5907571dSAsmitha Karunanithi } 770*5907571dSAsmitha Karunanithi 771*5907571dSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump DBus error: " << dbusError->name 772*5907571dSAsmitha Karunanithi << " and error msg: " << dbusError->message; 773*5907571dSAsmitha Karunanithi if (std::string_view( 774*5907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.NotAllowed") == 775*5907571dSAsmitha Karunanithi dbusError->name) 776*5907571dSAsmitha Karunanithi { 777*5907571dSAsmitha Karunanithi messages::resourceInStandby(asyncResp->res); 778*5907571dSAsmitha Karunanithi return; 779*5907571dSAsmitha Karunanithi } 780*5907571dSAsmitha Karunanithi if (std::string_view( 781*5907571dSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create.Error.Disabled") == 782*5907571dSAsmitha Karunanithi dbusError->name) 783*5907571dSAsmitha Karunanithi { 784*5907571dSAsmitha Karunanithi messages::serviceDisabled(asyncResp->res, dumpPath); 785*5907571dSAsmitha Karunanithi return; 786*5907571dSAsmitha Karunanithi } 787*5907571dSAsmitha Karunanithi if (std::string_view( 788*5907571dSAsmitha Karunanithi "xyz.openbmc_project.Common.Error.Unavailable") == 789*5907571dSAsmitha Karunanithi dbusError->name) 790*5907571dSAsmitha Karunanithi { 791*5907571dSAsmitha Karunanithi messages::resourceInUse(asyncResp->res); 792*5907571dSAsmitha Karunanithi return; 793*5907571dSAsmitha Karunanithi } 794*5907571dSAsmitha Karunanithi // Other Dbus errors such as: 795*5907571dSAsmitha Karunanithi // xyz.openbmc_project.Common.Error.InvalidArgument & 796*5907571dSAsmitha Karunanithi // org.freedesktop.DBus.Error.InvalidArgs are all related to 797*5907571dSAsmitha Karunanithi // the dbus call that is made here in the bmcweb 798*5907571dSAsmitha Karunanithi // implementation and has nothing to do with the client's 799*5907571dSAsmitha Karunanithi // input in the request. Hence, returning internal error 800*5907571dSAsmitha Karunanithi // back to the client. 801a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 802a43be80fSAsmitha Karunanithi return; 803a43be80fSAsmitha Karunanithi } 804a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 805a43be80fSAsmitha Karunanithi 806002d39b4SEd Tanous createDumpTaskCallback(std::move(payload), asyncResp, dumpId, dumpPath, 807002d39b4SEd Tanous dumpType); 808a43be80fSAsmitha Karunanithi }, 809b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 810b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 811b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 812a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 813a43be80fSAsmitha Karunanithi } 814a43be80fSAsmitha Karunanithi 8158d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8168d1b46d7Szhanghch05 const std::string& dumpType) 81780319af1SAsmitha Karunanithi { 818b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 819b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 8208d1b46d7Szhanghch05 82180319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 822b9d36b47SEd Tanous [asyncResp, dumpType]( 823b9d36b47SEd Tanous const boost::system::error_code ec, 824b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 82580319af1SAsmitha Karunanithi if (ec) 82680319af1SAsmitha Karunanithi { 82780319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 82880319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 82980319af1SAsmitha Karunanithi return; 83080319af1SAsmitha Karunanithi } 83180319af1SAsmitha Karunanithi 83280319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 83380319af1SAsmitha Karunanithi { 8342dfd18efSEd Tanous sdbusplus::message::object_path objPath(path); 8352dfd18efSEd Tanous std::string logID = objPath.filename(); 8362dfd18efSEd Tanous if (logID.empty()) 83780319af1SAsmitha Karunanithi { 8382dfd18efSEd Tanous continue; 83980319af1SAsmitha Karunanithi } 8402dfd18efSEd Tanous deleteDumpEntry(asyncResp, logID, dumpType); 84180319af1SAsmitha Karunanithi } 84280319af1SAsmitha Karunanithi }, 84380319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 84480319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 84580319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 846b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, 847b47452b2SAsmitha Karunanithi std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." + 848b47452b2SAsmitha Karunanithi dumpType}); 84980319af1SAsmitha Karunanithi } 85080319af1SAsmitha Karunanithi 851b9d36b47SEd Tanous inline static void 852b9d36b47SEd Tanous parseCrashdumpParameters(const dbus::utility::DBusPropertiesMap& params, 853b9d36b47SEd Tanous std::string& filename, std::string& timestamp, 854b9d36b47SEd Tanous std::string& logfile) 855043a0536SJohnathan Mantey { 856043a0536SJohnathan Mantey for (auto property : params) 857043a0536SJohnathan Mantey { 858043a0536SJohnathan Mantey if (property.first == "Timestamp") 859043a0536SJohnathan Mantey { 860043a0536SJohnathan Mantey const std::string* value = 8618d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 862043a0536SJohnathan Mantey if (value != nullptr) 863043a0536SJohnathan Mantey { 864043a0536SJohnathan Mantey timestamp = *value; 865043a0536SJohnathan Mantey } 866043a0536SJohnathan Mantey } 867043a0536SJohnathan Mantey else if (property.first == "Filename") 868043a0536SJohnathan Mantey { 869043a0536SJohnathan Mantey const std::string* value = 8708d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 871043a0536SJohnathan Mantey if (value != nullptr) 872043a0536SJohnathan Mantey { 873043a0536SJohnathan Mantey filename = *value; 874043a0536SJohnathan Mantey } 875043a0536SJohnathan Mantey } 876043a0536SJohnathan Mantey else if (property.first == "Log") 877043a0536SJohnathan Mantey { 878043a0536SJohnathan Mantey const std::string* value = 8798d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 880043a0536SJohnathan Mantey if (value != nullptr) 881043a0536SJohnathan Mantey { 882043a0536SJohnathan Mantey logfile = *value; 883043a0536SJohnathan Mantey } 884043a0536SJohnathan Mantey } 885043a0536SJohnathan Mantey } 886043a0536SJohnathan Mantey } 887043a0536SJohnathan Mantey 888a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 8897e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 8901da66f75SEd Tanous { 891c4bf6374SJason M. Bills /** 892c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 893c4bf6374SJason M. Bills */ 8947e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/") 895ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 896002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 897002d39b4SEd Tanous [&app](const crow::Request& req, 898002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 8993ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 900c4bf6374SJason M. Bills { 90145ca1b86SEd Tanous return; 90245ca1b86SEd Tanous } 9037e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 9047e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 905c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 906c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 907c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 908029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 90945ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 910c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 911c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 912002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 913c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 9141476687dSEd Tanous nlohmann::json::object_t eventLog; 9151476687dSEd Tanous eventLog["@odata.id"] = 9161476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 9171476687dSEd Tanous logServiceArray.push_back(std::move(eventLog)); 9185cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 9191476687dSEd Tanous nlohmann::json::object_t dumpLog; 920002d39b4SEd Tanous dumpLog["@odata.id"] = "/redfish/v1/Systems/system/LogServices/Dump"; 9211476687dSEd Tanous logServiceArray.push_back(std::move(dumpLog)); 922c9bb6861Sraviteja-b #endif 923c9bb6861Sraviteja-b 924d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 9251476687dSEd Tanous nlohmann::json::object_t crashdump; 9261476687dSEd Tanous crashdump["@odata.id"] = 9271476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump"; 9281476687dSEd Tanous logServiceArray.push_back(std::move(crashdump)); 929d53dd41fSJason M. Bills #endif 930b7028ebfSSpencer Ku 931b7028ebfSSpencer Ku #ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER 9321476687dSEd Tanous nlohmann::json::object_t hostlogger; 9331476687dSEd Tanous hostlogger["@odata.id"] = 9341476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger"; 9351476687dSEd Tanous logServiceArray.push_back(std::move(hostlogger)); 936b7028ebfSSpencer Ku #endif 937c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 938c4bf6374SJason M. Bills logServiceArray.size(); 939a3316fc6SZhikuiRen 940a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 94145ca1b86SEd Tanous [asyncResp](const boost::system::error_code ec, 942b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& 943b9d36b47SEd Tanous subtreePath) { 944a3316fc6SZhikuiRen if (ec) 945a3316fc6SZhikuiRen { 946a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 947a3316fc6SZhikuiRen return; 948a3316fc6SZhikuiRen } 949a3316fc6SZhikuiRen 95055f79e6fSEd Tanous for (const auto& pathStr : subtreePath) 951a3316fc6SZhikuiRen { 952a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 953a3316fc6SZhikuiRen { 95423a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 955a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 95623a21a1cSEd Tanous logServiceArrayLocal.push_back( 9570fda0f12SGeorge Liu {{"@odata.id", 9580fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes"}}); 95945ca1b86SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 96023a21a1cSEd Tanous logServiceArrayLocal.size(); 961a3316fc6SZhikuiRen return; 962a3316fc6SZhikuiRen } 963a3316fc6SZhikuiRen } 964a3316fc6SZhikuiRen }, 965a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 966a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 96745ca1b86SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 96845ca1b86SEd Tanous std::array<const char*, 1>{postCodeIface}); 9697e860f15SJohn Edward Broadbent }); 970c4bf6374SJason M. Bills } 971c4bf6374SJason M. Bills 9727e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 973c4bf6374SJason M. Bills { 9747e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 975ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 976002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 977002d39b4SEd Tanous [&app](const crow::Request& req, 978002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 9793ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 98045ca1b86SEd Tanous { 98145ca1b86SEd Tanous return; 98245ca1b86SEd Tanous } 983c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 984029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 985c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 986c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 987c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 988002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 989c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 990c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 9917c8c4058STejas Patil 9927c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 9937c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 9947c8c4058STejas Patil 9957c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 9967c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 9977c8c4058STejas Patil redfishDateTimeOffset.second; 9987c8c4058STejas Patil 9991476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 10001476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1001e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1002e7d6c8b2SGunnar Mills 10030fda0f12SGeorge Liu {"target", 10040fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog"}}; 10057e860f15SJohn Edward Broadbent }); 1006489640c6SJason M. Bills } 1007489640c6SJason M. Bills 10087e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1009489640c6SJason M. Bills { 10104978b63fSJason M. Bills BMCWEB_ROUTE( 10114978b63fSJason M. Bills app, 10124978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/") 1013432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 10147e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 101545ca1b86SEd Tanous [&app](const crow::Request& req, 10167e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 10173ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 101845ca1b86SEd Tanous { 101945ca1b86SEd Tanous return; 102045ca1b86SEd Tanous } 1021489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1022489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1023489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1024489640c6SJason M. Bills { 1025489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1026489640c6SJason M. Bills { 1027489640c6SJason M. Bills std::error_code ec; 1028489640c6SJason M. Bills std::filesystem::remove(file, ec); 1029489640c6SJason M. Bills } 1030489640c6SJason M. Bills } 1031489640c6SJason M. Bills 1032489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1033489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1034489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1035489640c6SJason M. Bills if (ec) 1036489640c6SJason M. Bills { 1037002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 1038489640c6SJason M. Bills messages::internalError(asyncResp->res); 1039489640c6SJason M. Bills return; 1040489640c6SJason M. Bills } 1041489640c6SJason M. Bills 1042489640c6SJason M. Bills messages::success(asyncResp->res); 1043489640c6SJason M. Bills }, 1044489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1045002d39b4SEd Tanous "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1046002d39b4SEd Tanous "replace"); 10477e860f15SJohn Edward Broadbent }); 1048c4bf6374SJason M. Bills } 1049c4bf6374SJason M. Bills 1050ac992cdeSJason M. Bills enum class LogParseError 1051ac992cdeSJason M. Bills { 1052ac992cdeSJason M. Bills success, 1053ac992cdeSJason M. Bills parseFailed, 1054ac992cdeSJason M. Bills messageIdNotInRegistry, 1055ac992cdeSJason M. Bills }; 1056ac992cdeSJason M. Bills 1057ac992cdeSJason M. Bills static LogParseError 1058ac992cdeSJason M. Bills fillEventLogEntryJson(const std::string& logEntryID, 1059b5a76932SEd Tanous const std::string& logEntry, 1060de703c5dSJason M. Bills nlohmann::json::object_t& logEntryJson) 1061c4bf6374SJason M. Bills { 106295820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1063cd225da8SJason M. Bills // First get the Timestamp 1064f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1065cd225da8SJason M. Bills if (space == std::string::npos) 106695820184SJason M. Bills { 1067ac992cdeSJason M. Bills return LogParseError::parseFailed; 106895820184SJason M. Bills } 1069cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1070cd225da8SJason M. Bills // Then get the log contents 1071f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1072cd225da8SJason M. Bills if (entryStart == std::string::npos) 1073cd225da8SJason M. Bills { 1074ac992cdeSJason M. Bills return LogParseError::parseFailed; 1075cd225da8SJason M. Bills } 1076cd225da8SJason M. Bills std::string_view entry(logEntry); 1077cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1078cd225da8SJason M. Bills // Use split to separate the entry into its fields 1079cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1080cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1081cd225da8SJason M. Bills boost::token_compress_on); 1082cd225da8SJason M. Bills // We need at least a MessageId to be valid 108326f6976fSEd Tanous if (logEntryFields.empty()) 1084cd225da8SJason M. Bills { 1085ac992cdeSJason M. Bills return LogParseError::parseFailed; 1086cd225da8SJason M. Bills } 1087cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 108895820184SJason M. Bills 10894851d45dSJason M. Bills // Get the Message from the MessageRegistry 1090fffb8c1fSEd Tanous const registries::Message* message = registries::getMessage(messageID); 1091c4bf6374SJason M. Bills 109254417b02SSui Chen if (message == nullptr) 1093c4bf6374SJason M. Bills { 109454417b02SSui Chen BMCWEB_LOG_WARNING << "Log entry not found in registry: " << logEntry; 1095ac992cdeSJason M. Bills return LogParseError::messageIdNotInRegistry; 1096c4bf6374SJason M. Bills } 1097c4bf6374SJason M. Bills 109854417b02SSui Chen std::string msg = message->message; 109954417b02SSui Chen 110015a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 110126702d01SEd Tanous std::span<std::string> messageArgs; 110215a86ff6SJason M. Bills if (logEntryFields.size() > 1) 110315a86ff6SJason M. Bills { 110415a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 110515a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 110615a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 110715a86ff6SJason M. Bills if (!messageArgsStart.empty()) 110815a86ff6SJason M. Bills { 110915a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 111015a86ff6SJason M. Bills } 111115a86ff6SJason M. Bills 111223a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1113c4bf6374SJason M. Bills 11144851d45dSJason M. Bills // Fill the MessageArgs into the Message 111595820184SJason M. Bills int i = 0; 111695820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11174851d45dSJason M. Bills { 111895820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11194851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11204851d45dSJason M. Bills if (argPos != std::string::npos) 11214851d45dSJason M. Bills { 112295820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11234851d45dSJason M. Bills } 11244851d45dSJason M. Bills } 112515a86ff6SJason M. Bills } 11264851d45dSJason M. Bills 112795820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 112895820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 112995820184SJason M. Bills // between the '.' and the '+', so just remove them. 1130f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1131f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 113295820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1133c4bf6374SJason M. Bills { 113495820184SJason M. Bills timestamp.erase(dot, plus - dot); 1135c4bf6374SJason M. Bills } 1136c4bf6374SJason M. Bills 1137c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 113884afc48bSJason M. Bills logEntryJson["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 113984afc48bSJason M. Bills logEntryJson["@odata.id"] = 114084afc48bSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + logEntryID; 114184afc48bSJason M. Bills logEntryJson["Name"] = "System Event Log Entry"; 114284afc48bSJason M. Bills logEntryJson["Id"] = logEntryID; 114384afc48bSJason M. Bills logEntryJson["Message"] = std::move(msg); 114484afc48bSJason M. Bills logEntryJson["MessageId"] = std::move(messageID); 114584afc48bSJason M. Bills logEntryJson["MessageArgs"] = messageArgs; 114684afc48bSJason M. Bills logEntryJson["EntryType"] = "Event"; 114784afc48bSJason M. Bills logEntryJson["Severity"] = message->messageSeverity; 114884afc48bSJason M. Bills logEntryJson["Created"] = std::move(timestamp); 1149ac992cdeSJason M. Bills return LogParseError::success; 1150c4bf6374SJason M. Bills } 1151c4bf6374SJason M. Bills 11527e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1153c4bf6374SJason M. Bills { 11547e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 11557e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 11568b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 1157002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1158002d39b4SEd Tanous [&app](const crow::Request& req, 1159002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1160c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1161c937d2bfSEd Tanous .canDelegateTop = true, 1162c937d2bfSEd Tanous .canDelegateSkip = true, 1163c937d2bfSEd Tanous }; 1164c937d2bfSEd Tanous query_param::Query delegatedQuery; 1165c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 11663ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 1167c4bf6374SJason M. Bills { 1168c4bf6374SJason M. Bills return; 1169c4bf6374SJason M. Bills } 11703648c8beSEd Tanous size_t top = 11713648c8beSEd Tanous delegatedQuery.top.value_or(query_param::maxEntriesPerPage); 11723648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 11733648c8beSEd Tanous 11747e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 11757e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1176c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1177c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1178c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1179029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1180c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1181c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1182c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1183cb92c03bSAndrew Geissler 11844978b63fSJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1185c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 11867e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 11877e860f15SJohn Edward Broadbent // entry 118895820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 118995820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1190b01bf299SEd Tanous uint64_t entryCount = 0; 1191cd225da8SJason M. Bills std::string logEntry; 119295820184SJason M. Bills 11937e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 11947e860f15SJohn Edward Broadbent // backwards 1195002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1196002d39b4SEd Tanous it++) 1197c4bf6374SJason M. Bills { 1198cd225da8SJason M. Bills std::ifstream logStream(*it); 119995820184SJason M. Bills if (!logStream.is_open()) 1200c4bf6374SJason M. Bills { 1201c4bf6374SJason M. Bills continue; 1202c4bf6374SJason M. Bills } 1203c4bf6374SJason M. Bills 1204e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1205e85d6b16SJason M. Bills bool firstEntry = true; 120695820184SJason M. Bills while (std::getline(logStream, logEntry)) 120795820184SJason M. Bills { 1208c4bf6374SJason M. Bills std::string idStr; 1209e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1210c4bf6374SJason M. Bills { 1211c4bf6374SJason M. Bills continue; 1212c4bf6374SJason M. Bills } 1213e85d6b16SJason M. Bills firstEntry = false; 1214e85d6b16SJason M. Bills 1215de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 1216ac992cdeSJason M. Bills LogParseError status = 1217ac992cdeSJason M. Bills fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); 1218ac992cdeSJason M. Bills if (status == LogParseError::messageIdNotInRegistry) 1219ac992cdeSJason M. Bills { 1220ac992cdeSJason M. Bills continue; 1221ac992cdeSJason M. Bills } 1222ac992cdeSJason M. Bills if (status != LogParseError::success) 1223c4bf6374SJason M. Bills { 1224c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1225c4bf6374SJason M. Bills return; 1226c4bf6374SJason M. Bills } 1227de703c5dSJason M. Bills 1228de703c5dSJason M. Bills entryCount++; 1229de703c5dSJason M. Bills // Handle paging using skip (number of entries to skip from the 1230de703c5dSJason M. Bills // start) and top (number of entries to display) 12313648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 1232de703c5dSJason M. Bills { 1233de703c5dSJason M. Bills continue; 1234de703c5dSJason M. Bills } 1235de703c5dSJason M. Bills 1236de703c5dSJason M. Bills logEntryArray.push_back(std::move(bmcLogEntry)); 1237c4bf6374SJason M. Bills } 123895820184SJason M. Bills } 1239c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 12403648c8beSEd Tanous if (skip + top < entryCount) 1241c4bf6374SJason M. Bills { 1242c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 12434978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries?$skip=" + 12443648c8beSEd Tanous std::to_string(skip + top); 1245c4bf6374SJason M. Bills } 12467e860f15SJohn Edward Broadbent }); 1247897967deSJason M. Bills } 1248897967deSJason M. Bills 12497e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1250897967deSJason M. Bills { 12517e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 12527e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1253ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 12547e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 125545ca1b86SEd Tanous [&app](const crow::Request& req, 12567e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12577e860f15SJohn Edward Broadbent const std::string& param) { 12583ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 125945ca1b86SEd Tanous { 126045ca1b86SEd Tanous return; 126145ca1b86SEd Tanous } 12627e860f15SJohn Edward Broadbent const std::string& targetID = param; 12638d1b46d7Szhanghch05 12647e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 12657e860f15SJohn Edward Broadbent // entry to find the target entry 1266897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1267897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1268897967deSJason M. Bills std::string logEntry; 1269897967deSJason M. Bills 12707e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12717e860f15SJohn Edward Broadbent // backwards 1272002d39b4SEd Tanous for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1273002d39b4SEd Tanous it++) 1274897967deSJason M. Bills { 1275897967deSJason M. Bills std::ifstream logStream(*it); 1276897967deSJason M. Bills if (!logStream.is_open()) 1277897967deSJason M. Bills { 1278897967deSJason M. Bills continue; 1279897967deSJason M. Bills } 1280897967deSJason M. Bills 1281897967deSJason M. Bills // Reset the unique ID on the first entry 1282897967deSJason M. Bills bool firstEntry = true; 1283897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1284897967deSJason M. Bills { 1285897967deSJason M. Bills std::string idStr; 1286897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1287897967deSJason M. Bills { 1288897967deSJason M. Bills continue; 1289897967deSJason M. Bills } 1290897967deSJason M. Bills firstEntry = false; 1291897967deSJason M. Bills 1292897967deSJason M. Bills if (idStr == targetID) 1293897967deSJason M. Bills { 1294de703c5dSJason M. Bills nlohmann::json::object_t bmcLogEntry; 1295ac992cdeSJason M. Bills LogParseError status = 1296ac992cdeSJason M. Bills fillEventLogEntryJson(idStr, logEntry, bmcLogEntry); 1297ac992cdeSJason M. Bills if (status != LogParseError::success) 1298897967deSJason M. Bills { 1299897967deSJason M. Bills messages::internalError(asyncResp->res); 1300897967deSJason M. Bills return; 1301897967deSJason M. Bills } 1302d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcLogEntry); 1303897967deSJason M. Bills return; 1304897967deSJason M. Bills } 1305897967deSJason M. Bills } 1306897967deSJason M. Bills } 1307897967deSJason M. Bills // Requested ID was not found 1308002d39b4SEd Tanous messages::resourceMissingAtURI(asyncResp->res, 1309002d39b4SEd Tanous crow::utility::urlFromPieces(targetID)); 13107e860f15SJohn Edward Broadbent }); 131108a4e4b5SAnthony Wilson } 131208a4e4b5SAnthony Wilson 13137e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 131408a4e4b5SAnthony Wilson { 13157e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 13167e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1317ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 1318002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1319002d39b4SEd Tanous [&app](const crow::Request& req, 1320002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 13213ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 132245ca1b86SEd Tanous { 132345ca1b86SEd Tanous return; 132445ca1b86SEd Tanous } 13257e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 13267e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 132708a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 132808a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 132908a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 133008a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 133108a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 133208a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 133308a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 133408a4e4b5SAnthony Wilson 1335cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1336cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1337cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1338cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1339914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& resp) { 1340cb92c03bSAndrew Geissler if (ec) 1341cb92c03bSAndrew Geissler { 1342cb92c03bSAndrew Geissler // TODO Handle for specific error code 1343cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1344002d39b4SEd Tanous << "getLogEntriesIfaceData resp_handler got error " << ec; 1345cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1346cb92c03bSAndrew Geissler return; 1347cb92c03bSAndrew Geissler } 1348002d39b4SEd Tanous nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 1349cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 13509eb808c1SEd Tanous for (const auto& objectPath : resp) 1351cb92c03bSAndrew Geissler { 1352914e2d5dSEd Tanous const uint32_t* id = nullptr; 1353c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1354c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1355914e2d5dSEd Tanous const std::string* severity = nullptr; 1356914e2d5dSEd Tanous const std::string* message = nullptr; 1357914e2d5dSEd Tanous const std::string* filePath = nullptr; 135875710de2SXiaochao Ma bool resolved = false; 13599eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 1360f86bb901SAdriana Kobylak { 1361f86bb901SAdriana Kobylak if (interfaceMap.first == 1362f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1363f86bb901SAdriana Kobylak { 1364002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 1365cb92c03bSAndrew Geissler { 1366cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1367cb92c03bSAndrew Geissler { 1368002d39b4SEd Tanous id = std::get_if<uint32_t>(&propertyMap.second); 1369cb92c03bSAndrew Geissler } 1370cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1371cb92c03bSAndrew Geissler { 1372002d39b4SEd Tanous timestamp = 1373002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 13747e860f15SJohn Edward Broadbent } 1375002d39b4SEd Tanous else if (propertyMap.first == "UpdateTimestamp") 13767e860f15SJohn Edward Broadbent { 1377002d39b4SEd Tanous updateTimestamp = 1378002d39b4SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 13797e860f15SJohn Edward Broadbent } 13807e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 13817e860f15SJohn Edward Broadbent { 13827e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 13837e860f15SJohn Edward Broadbent &propertyMap.second); 13847e860f15SJohn Edward Broadbent } 13857e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 13867e860f15SJohn Edward Broadbent { 13877e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 13887e860f15SJohn Edward Broadbent &propertyMap.second); 13897e860f15SJohn Edward Broadbent } 13907e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 13917e860f15SJohn Edward Broadbent { 1392914e2d5dSEd Tanous const bool* resolveptr = 1393002d39b4SEd Tanous std::get_if<bool>(&propertyMap.second); 13947e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 13957e860f15SJohn Edward Broadbent { 1396002d39b4SEd Tanous messages::internalError(asyncResp->res); 13977e860f15SJohn Edward Broadbent return; 13987e860f15SJohn Edward Broadbent } 13997e860f15SJohn Edward Broadbent resolved = *resolveptr; 14007e860f15SJohn Edward Broadbent } 14017e860f15SJohn Edward Broadbent } 14027e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14037e860f15SJohn Edward Broadbent severity == nullptr) 14047e860f15SJohn Edward Broadbent { 14057e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 14067e860f15SJohn Edward Broadbent return; 14077e860f15SJohn Edward Broadbent } 14087e860f15SJohn Edward Broadbent } 14097e860f15SJohn Edward Broadbent else if (interfaceMap.first == 14107e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 14117e860f15SJohn Edward Broadbent { 1412002d39b4SEd Tanous for (const auto& propertyMap : interfaceMap.second) 14137e860f15SJohn Edward Broadbent { 14147e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 14157e860f15SJohn Edward Broadbent { 14167e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 14177e860f15SJohn Edward Broadbent &propertyMap.second); 14187e860f15SJohn Edward Broadbent } 14197e860f15SJohn Edward Broadbent } 14207e860f15SJohn Edward Broadbent } 14217e860f15SJohn Edward Broadbent } 14227e860f15SJohn Edward Broadbent // Object path without the 14237e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 14247e860f15SJohn Edward Broadbent // and continue. 14257e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 1426c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1427c419c759SEd Tanous updateTimestamp == nullptr) 14287e860f15SJohn Edward Broadbent { 14297e860f15SJohn Edward Broadbent continue; 14307e860f15SJohn Edward Broadbent } 14317e860f15SJohn Edward Broadbent entriesArray.push_back({}); 14327e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 14337e860f15SJohn Edward Broadbent thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 14347e860f15SJohn Edward Broadbent thisEntry["@odata.id"] = 14350fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 14367e860f15SJohn Edward Broadbent std::to_string(*id); 14377e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 14387e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 14397e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 14407e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 14417e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 14427e860f15SJohn Edward Broadbent thisEntry["Severity"] = 14437e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 14447e860f15SJohn Edward Broadbent thisEntry["Created"] = 1445c419c759SEd Tanous crow::utility::getDateTimeUintMs(*timestamp); 14467e860f15SJohn Edward Broadbent thisEntry["Modified"] = 1447c419c759SEd Tanous crow::utility::getDateTimeUintMs(*updateTimestamp); 14487e860f15SJohn Edward Broadbent if (filePath != nullptr) 14497e860f15SJohn Edward Broadbent { 14507e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 14510fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 14527e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 14537e860f15SJohn Edward Broadbent } 14547e860f15SJohn Edward Broadbent } 1455002d39b4SEd Tanous std::sort( 1456002d39b4SEd Tanous entriesArray.begin(), entriesArray.end(), 1457002d39b4SEd Tanous [](const nlohmann::json& left, const nlohmann::json& right) { 14587e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 14597e860f15SJohn Edward Broadbent }); 14607e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 14617e860f15SJohn Edward Broadbent entriesArray.size(); 14627e860f15SJohn Edward Broadbent }, 14637e860f15SJohn Edward Broadbent "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 14647e860f15SJohn Edward Broadbent "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 14657e860f15SJohn Edward Broadbent }); 14667e860f15SJohn Edward Broadbent } 14677e860f15SJohn Edward Broadbent 14687e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 14697e860f15SJohn Edward Broadbent { 14707e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 14717e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1472ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 1473002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1474002d39b4SEd Tanous [&app](const crow::Request& req, 14757e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 147645ca1b86SEd Tanous const std::string& param) { 14773ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 14787e860f15SJohn Edward Broadbent { 147945ca1b86SEd Tanous return; 148045ca1b86SEd Tanous } 14817e860f15SJohn Edward Broadbent std::string entryID = param; 14827e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 14837e860f15SJohn Edward Broadbent 14847e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 14857e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 14867e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 1487002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec, 1488b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 14897e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 14907e860f15SJohn Edward Broadbent { 1491002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "EventLogEntry", 1492002d39b4SEd Tanous entryID); 14937e860f15SJohn Edward Broadbent return; 14947e860f15SJohn Edward Broadbent } 14957e860f15SJohn Edward Broadbent if (ec) 14967e860f15SJohn Edward Broadbent { 14970fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1498002d39b4SEd Tanous << "EventLogEntry (DBus) resp_handler got error " << ec; 14997e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 15007e860f15SJohn Edward Broadbent return; 15017e860f15SJohn Edward Broadbent } 1502914e2d5dSEd Tanous const uint32_t* id = nullptr; 1503c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1504c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1505914e2d5dSEd Tanous const std::string* severity = nullptr; 1506914e2d5dSEd Tanous const std::string* message = nullptr; 1507914e2d5dSEd Tanous const std::string* filePath = nullptr; 15087e860f15SJohn Edward Broadbent bool resolved = false; 15097e860f15SJohn Edward Broadbent 15109eb808c1SEd Tanous for (const auto& propertyMap : resp) 15117e860f15SJohn Edward Broadbent { 15127e860f15SJohn Edward Broadbent if (propertyMap.first == "Id") 15137e860f15SJohn Edward Broadbent { 15147e860f15SJohn Edward Broadbent id = std::get_if<uint32_t>(&propertyMap.second); 15157e860f15SJohn Edward Broadbent } 15167e860f15SJohn Edward Broadbent else if (propertyMap.first == "Timestamp") 15177e860f15SJohn Edward Broadbent { 1518002d39b4SEd Tanous timestamp = std::get_if<uint64_t>(&propertyMap.second); 1519ebd45906SGeorge Liu } 1520d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1521d139c236SGeorge Liu { 1522ebd45906SGeorge Liu updateTimestamp = 1523c419c759SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 1524ebd45906SGeorge Liu } 1525cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1526cb92c03bSAndrew Geissler { 1527002d39b4SEd Tanous severity = std::get_if<std::string>(&propertyMap.second); 1528cb92c03bSAndrew Geissler } 1529cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1530cb92c03bSAndrew Geissler { 1531002d39b4SEd Tanous message = std::get_if<std::string>(&propertyMap.second); 1532ae34c8e8SAdriana Kobylak } 153375710de2SXiaochao Ma else if (propertyMap.first == "Resolved") 153475710de2SXiaochao Ma { 1535914e2d5dSEd Tanous const bool* resolveptr = 153675710de2SXiaochao Ma std::get_if<bool>(&propertyMap.second); 153775710de2SXiaochao Ma if (resolveptr == nullptr) 153875710de2SXiaochao Ma { 153975710de2SXiaochao Ma messages::internalError(asyncResp->res); 154075710de2SXiaochao Ma return; 154175710de2SXiaochao Ma } 154275710de2SXiaochao Ma resolved = *resolveptr; 154375710de2SXiaochao Ma } 15447e860f15SJohn Edward Broadbent else if (propertyMap.first == "Path") 1545f86bb901SAdriana Kobylak { 1546002d39b4SEd Tanous filePath = std::get_if<std::string>(&propertyMap.second); 1547f86bb901SAdriana Kobylak } 1548f86bb901SAdriana Kobylak } 1549002d39b4SEd Tanous if (id == nullptr || message == nullptr || severity == nullptr || 1550002d39b4SEd Tanous timestamp == nullptr || updateTimestamp == nullptr) 1551f86bb901SAdriana Kobylak { 1552ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1553271584abSEd Tanous return; 1554271584abSEd Tanous } 1555f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 1556f86bb901SAdriana Kobylak "#LogEntry.v1_8_0.LogEntry"; 1557f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.id"] = 15580fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 1559f86bb901SAdriana Kobylak std::to_string(*id); 156045ca1b86SEd Tanous asyncResp->res.jsonValue["Name"] = "System Event Log Entry"; 1561f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1562f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1563f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 1564f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1565f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1566f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1567f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 1568c419c759SEd Tanous crow::utility::getDateTimeUintMs(*timestamp); 1569f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 1570c419c759SEd Tanous crow::utility::getDateTimeUintMs(*updateTimestamp); 1571f86bb901SAdriana Kobylak if (filePath != nullptr) 1572f86bb901SAdriana Kobylak { 1573f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 1574e7dbd530SPotin Lai "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 1575e7dbd530SPotin Lai std::to_string(*id) + "/attachment"; 1576f86bb901SAdriana Kobylak } 1577cb92c03bSAndrew Geissler }, 1578cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1579cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1580f86bb901SAdriana Kobylak "org.freedesktop.DBus.Properties", "GetAll", ""); 15817e860f15SJohn Edward Broadbent }); 1582336e96c6SChicago Duan 15837e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 15847e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1585ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 15867e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 158745ca1b86SEd Tanous [&app](const crow::Request& req, 15887e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 15897e860f15SJohn Edward Broadbent const std::string& entryId) { 15903ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 159145ca1b86SEd Tanous { 159245ca1b86SEd Tanous return; 159345ca1b86SEd Tanous } 159475710de2SXiaochao Ma std::optional<bool> resolved; 159575710de2SXiaochao Ma 159615ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", 15977e860f15SJohn Edward Broadbent resolved)) 159875710de2SXiaochao Ma { 159975710de2SXiaochao Ma return; 160075710de2SXiaochao Ma } 160175710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 160275710de2SXiaochao Ma 160375710de2SXiaochao Ma crow::connections::systemBus->async_method_call( 16044f48d5f6SEd Tanous [asyncResp, entryId](const boost::system::error_code ec) { 160575710de2SXiaochao Ma if (ec) 160675710de2SXiaochao Ma { 160775710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 160875710de2SXiaochao Ma messages::internalError(asyncResp->res); 160975710de2SXiaochao Ma return; 161075710de2SXiaochao Ma } 161175710de2SXiaochao Ma }, 161275710de2SXiaochao Ma "xyz.openbmc_project.Logging", 161375710de2SXiaochao Ma "/xyz/openbmc_project/logging/entry/" + entryId, 161475710de2SXiaochao Ma "org.freedesktop.DBus.Properties", "Set", 161575710de2SXiaochao Ma "xyz.openbmc_project.Logging.Entry", "Resolved", 1616168e20c1SEd Tanous dbus::utility::DbusVariantType(*resolved)); 16177e860f15SJohn Edward Broadbent }); 161875710de2SXiaochao Ma 16197e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16207e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1621ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1622ed398213SEd Tanous 1623002d39b4SEd Tanous .methods(boost::beast::http::verb::delete_)( 1624002d39b4SEd Tanous [&app](const crow::Request& req, 1625002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 162645ca1b86SEd Tanous const std::string& param) { 16273ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1628336e96c6SChicago Duan { 162945ca1b86SEd Tanous return; 163045ca1b86SEd Tanous } 1631336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1632336e96c6SChicago Duan 16337e860f15SJohn Edward Broadbent std::string entryID = param; 1634336e96c6SChicago Duan 1635336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1636336e96c6SChicago Duan 1637336e96c6SChicago Duan // Process response from Logging service. 1638002d39b4SEd Tanous auto respHandler = 1639002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec) { 1640002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1641336e96c6SChicago Duan if (ec) 1642336e96c6SChicago Duan { 16433de8d8baSGeorge Liu if (ec.value() == EBADR) 16443de8d8baSGeorge Liu { 164545ca1b86SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 164645ca1b86SEd Tanous entryID); 16473de8d8baSGeorge Liu return; 16483de8d8baSGeorge Liu } 1649336e96c6SChicago Duan // TODO Handle for specific error code 16500fda0f12SGeorge Liu BMCWEB_LOG_ERROR 16510fda0f12SGeorge Liu << "EventLogEntry (DBus) doDelete respHandler got error " 1652336e96c6SChicago Duan << ec; 1653336e96c6SChicago Duan asyncResp->res.result( 1654336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1655336e96c6SChicago Duan return; 1656336e96c6SChicago Duan } 1657336e96c6SChicago Duan 1658336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1659336e96c6SChicago Duan }; 1660336e96c6SChicago Duan 1661336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1662336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1663336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1664336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1665336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 16667e860f15SJohn Edward Broadbent }); 1667400fd1fbSAdriana Kobylak } 1668400fd1fbSAdriana Kobylak 16697e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1670400fd1fbSAdriana Kobylak { 16710fda0f12SGeorge Liu BMCWEB_ROUTE( 16720fda0f12SGeorge Liu app, 16730fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/attachment") 1674ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 16757e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 167645ca1b86SEd Tanous [&app](const crow::Request& req, 16777e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 167845ca1b86SEd Tanous const std::string& param) { 16793ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 16807e860f15SJohn Edward Broadbent { 168145ca1b86SEd Tanous return; 168245ca1b86SEd Tanous } 1683002d39b4SEd Tanous if (!http_helpers::isOctetAccepted(req.getHeaderValue("Accept"))) 1684400fd1fbSAdriana Kobylak { 1685002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 1686400fd1fbSAdriana Kobylak return; 1687400fd1fbSAdriana Kobylak } 1688400fd1fbSAdriana Kobylak 16897e860f15SJohn Edward Broadbent std::string entryID = param; 1690400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1691400fd1fbSAdriana Kobylak 1692400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 1693002d39b4SEd Tanous [asyncResp, entryID](const boost::system::error_code ec, 1694400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 1695400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 1696400fd1fbSAdriana Kobylak { 1697002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "EventLogAttachment", 1698002d39b4SEd Tanous entryID); 1699400fd1fbSAdriana Kobylak return; 1700400fd1fbSAdriana Kobylak } 1701400fd1fbSAdriana Kobylak if (ec) 1702400fd1fbSAdriana Kobylak { 1703400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1704400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1705400fd1fbSAdriana Kobylak return; 1706400fd1fbSAdriana Kobylak } 1707400fd1fbSAdriana Kobylak 1708400fd1fbSAdriana Kobylak int fd = -1; 1709400fd1fbSAdriana Kobylak fd = dup(unixfd); 1710400fd1fbSAdriana Kobylak if (fd == -1) 1711400fd1fbSAdriana Kobylak { 1712400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1713400fd1fbSAdriana Kobylak return; 1714400fd1fbSAdriana Kobylak } 1715400fd1fbSAdriana Kobylak 1716400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 1717400fd1fbSAdriana Kobylak if (size == -1) 1718400fd1fbSAdriana Kobylak { 1719400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1720400fd1fbSAdriana Kobylak return; 1721400fd1fbSAdriana Kobylak } 1722400fd1fbSAdriana Kobylak 1723400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 1724400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 1725400fd1fbSAdriana Kobylak if (size > maxFileSize) 1726400fd1fbSAdriana Kobylak { 1727002d39b4SEd Tanous BMCWEB_LOG_ERROR << "File size exceeds maximum allowed size of " 1728400fd1fbSAdriana Kobylak << maxFileSize; 1729400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1730400fd1fbSAdriana Kobylak return; 1731400fd1fbSAdriana Kobylak } 1732400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 1733400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 1734400fd1fbSAdriana Kobylak if (rc == -1) 1735400fd1fbSAdriana Kobylak { 1736400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1737400fd1fbSAdriana Kobylak return; 1738400fd1fbSAdriana Kobylak } 1739400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 1740400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 1741400fd1fbSAdriana Kobylak { 1742400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1743400fd1fbSAdriana Kobylak return; 1744400fd1fbSAdriana Kobylak } 1745400fd1fbSAdriana Kobylak close(fd); 1746400fd1fbSAdriana Kobylak 1747400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 1748002d39b4SEd Tanous std::string output = crow::utility::base64encode(strData); 1749400fd1fbSAdriana Kobylak 1750400fd1fbSAdriana Kobylak asyncResp->res.addHeader("Content-Type", 1751400fd1fbSAdriana Kobylak "application/octet-stream"); 1752002d39b4SEd Tanous asyncResp->res.addHeader("Content-Transfer-Encoding", "Base64"); 1753400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 1754400fd1fbSAdriana Kobylak }, 1755400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 1756400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 1757400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 17587e860f15SJohn Edward Broadbent }); 17591da66f75SEd Tanous } 17601da66f75SEd Tanous 1761b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 1762b7028ebfSSpencer Ku 1763b7028ebfSSpencer Ku inline bool 1764b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 1765b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 1766b7028ebfSSpencer Ku { 1767b7028ebfSSpencer Ku std::error_code ec; 1768b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 1769b7028ebfSSpencer Ku if (ec) 1770b7028ebfSSpencer Ku { 1771b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << ec.message(); 1772b7028ebfSSpencer Ku return false; 1773b7028ebfSSpencer Ku } 1774b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 1775b7028ebfSSpencer Ku { 1776b7028ebfSSpencer Ku std::string filename = it.path().filename(); 1777b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 1778b7028ebfSSpencer Ku // path 177911ba3979SEd Tanous if (filename.starts_with("log")) 1780b7028ebfSSpencer Ku { 1781b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 1782b7028ebfSSpencer Ku } 1783b7028ebfSSpencer Ku } 1784b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 1785b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 1786b7028ebfSSpencer Ku // descending order. 1787b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 1788b7028ebfSSpencer Ku AlphanumLess<std::string>()); 1789b7028ebfSSpencer Ku 1790b7028ebfSSpencer Ku return true; 1791b7028ebfSSpencer Ku } 1792b7028ebfSSpencer Ku 179302cad96eSEd Tanous inline bool getHostLoggerEntries( 179402cad96eSEd Tanous const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip, 179502cad96eSEd Tanous uint64_t top, std::vector<std::string>& logEntries, size_t& logCount) 1796b7028ebfSSpencer Ku { 1797b7028ebfSSpencer Ku GzFileReader logFile; 1798b7028ebfSSpencer Ku 1799b7028ebfSSpencer Ku // Go though all log files and expose host logs. 1800b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 1801b7028ebfSSpencer Ku { 1802b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 1803b7028ebfSSpencer Ku { 1804b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to expose host logs"; 1805b7028ebfSSpencer Ku return false; 1806b7028ebfSSpencer Ku } 1807b7028ebfSSpencer Ku } 1808b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 1809b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 1810b7028ebfSSpencer Ku if (!lastMessage.empty()) 1811b7028ebfSSpencer Ku { 1812b7028ebfSSpencer Ku logCount++; 1813b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 1814b7028ebfSSpencer Ku { 1815b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 1816b7028ebfSSpencer Ku } 1817b7028ebfSSpencer Ku } 1818b7028ebfSSpencer Ku return true; 1819b7028ebfSSpencer Ku } 1820b7028ebfSSpencer Ku 1821b7028ebfSSpencer Ku inline void fillHostLoggerEntryJson(const std::string& logEntryID, 1822b7028ebfSSpencer Ku const std::string& msg, 18236d6574c9SJason M. Bills nlohmann::json::object_t& logEntryJson) 1824b7028ebfSSpencer Ku { 1825b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 18266d6574c9SJason M. Bills logEntryJson["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 18276d6574c9SJason M. Bills logEntryJson["@odata.id"] = 1828b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/" + 18296d6574c9SJason M. Bills logEntryID; 18306d6574c9SJason M. Bills logEntryJson["Name"] = "Host Logger Entry"; 18316d6574c9SJason M. Bills logEntryJson["Id"] = logEntryID; 18326d6574c9SJason M. Bills logEntryJson["Message"] = msg; 18336d6574c9SJason M. Bills logEntryJson["EntryType"] = "Oem"; 18346d6574c9SJason M. Bills logEntryJson["Severity"] = "OK"; 18356d6574c9SJason M. Bills logEntryJson["OemRecordFormat"] = "Host Logger Entry"; 1836b7028ebfSSpencer Ku } 1837b7028ebfSSpencer Ku 1838b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 1839b7028ebfSSpencer Ku { 1840b7028ebfSSpencer Ku BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/HostLogger/") 1841b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 18421476687dSEd Tanous .methods(boost::beast::http::verb::get)( 18431476687dSEd Tanous [&app](const crow::Request& req, 18441476687dSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 18453ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 184645ca1b86SEd Tanous { 184745ca1b86SEd Tanous return; 184845ca1b86SEd Tanous } 1849b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1850b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"; 1851b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1852b7028ebfSSpencer Ku "#LogService.v1_1_0.LogService"; 1853b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 1854b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 1855b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 18561476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 18571476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 1858b7028ebfSSpencer Ku }); 1859b7028ebfSSpencer Ku } 1860b7028ebfSSpencer Ku 1861b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 1862b7028ebfSSpencer Ku { 1863b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 1864b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/") 1865b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 1866002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1867002d39b4SEd Tanous [&app](const crow::Request& req, 1868002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1869c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 1870c937d2bfSEd Tanous .canDelegateTop = true, 1871c937d2bfSEd Tanous .canDelegateSkip = true, 1872c937d2bfSEd Tanous }; 1873c937d2bfSEd Tanous query_param::Query delegatedQuery; 1874c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 18753ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 1876b7028ebfSSpencer Ku { 1877b7028ebfSSpencer Ku return; 1878b7028ebfSSpencer Ku } 1879b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1880b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 1881b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1882b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 1883b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 1884b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 1885b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 18860fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1887b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 1888b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 1889b7028ebfSSpencer Ku 1890b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 1891b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 1892b7028ebfSSpencer Ku { 1893b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 1894b7028ebfSSpencer Ku return; 1895b7028ebfSSpencer Ku } 18963648c8beSEd Tanous // If we weren't provided top and skip limits, use the defaults. 18973648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 18983648c8beSEd Tanous size_t top = 18993648c8beSEd Tanous delegatedQuery.top.value_or(query_param::maxEntriesPerPage); 1900b7028ebfSSpencer Ku size_t logCount = 0; 1901b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 1902b7028ebfSSpencer Ku // control by skip and top. 1903b7028ebfSSpencer Ku std::vector<std::string> logEntries; 19043648c8beSEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries, 19053648c8beSEd Tanous logCount)) 1906b7028ebfSSpencer Ku { 1907b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 1908b7028ebfSSpencer Ku return; 1909b7028ebfSSpencer Ku } 1910b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 1911b7028ebfSSpencer Ku // log count 191226f6976fSEd Tanous if (logEntries.empty()) 1913b7028ebfSSpencer Ku { 1914b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 1915b7028ebfSSpencer Ku return; 1916b7028ebfSSpencer Ku } 191726f6976fSEd Tanous if (!logEntries.empty()) 1918b7028ebfSSpencer Ku { 1919b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 1920b7028ebfSSpencer Ku { 19216d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 19223648c8beSEd Tanous fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i], 19233648c8beSEd Tanous hostLogEntry); 19246d6574c9SJason M. Bills logEntryArray.push_back(std::move(hostLogEntry)); 1925b7028ebfSSpencer Ku } 1926b7028ebfSSpencer Ku 1927b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 19283648c8beSEd Tanous if (skip + top < logCount) 1929b7028ebfSSpencer Ku { 1930b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 19310fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/HostLogger/Entries?$skip=" + 19323648c8beSEd Tanous std::to_string(skip + top); 1933b7028ebfSSpencer Ku } 1934b7028ebfSSpencer Ku } 1935b7028ebfSSpencer Ku }); 1936b7028ebfSSpencer Ku } 1937b7028ebfSSpencer Ku 1938b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 1939b7028ebfSSpencer Ku { 1940b7028ebfSSpencer Ku BMCWEB_ROUTE( 1941b7028ebfSSpencer Ku app, "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/<str>/") 1942b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 1943b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 194445ca1b86SEd Tanous [&app](const crow::Request& req, 1945b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1946b7028ebfSSpencer Ku const std::string& param) { 19473ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 194845ca1b86SEd Tanous { 194945ca1b86SEd Tanous return; 195045ca1b86SEd Tanous } 1951b7028ebfSSpencer Ku const std::string& targetID = param; 1952b7028ebfSSpencer Ku 1953b7028ebfSSpencer Ku uint64_t idInt = 0; 1954ca45aa3cSEd Tanous 1955ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 1956ca45aa3cSEd Tanous const char* end = targetID.data() + targetID.size(); 1957ca45aa3cSEd Tanous 1958ca45aa3cSEd Tanous auto [ptr, ec] = std::from_chars(targetID.data(), end, idInt); 1959b7028ebfSSpencer Ku if (ec == std::errc::invalid_argument) 1960b7028ebfSSpencer Ku { 1961ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 1962b7028ebfSSpencer Ku return; 1963b7028ebfSSpencer Ku } 1964b7028ebfSSpencer Ku if (ec == std::errc::result_out_of_range) 1965b7028ebfSSpencer Ku { 1966ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 1967b7028ebfSSpencer Ku return; 1968b7028ebfSSpencer Ku } 1969b7028ebfSSpencer Ku 1970b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 1971b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 1972b7028ebfSSpencer Ku { 1973b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 1974b7028ebfSSpencer Ku return; 1975b7028ebfSSpencer Ku } 1976b7028ebfSSpencer Ku 1977b7028ebfSSpencer Ku size_t logCount = 0; 19783648c8beSEd Tanous size_t top = 1; 1979b7028ebfSSpencer Ku std::vector<std::string> logEntries; 1980b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 1981b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 1982b7028ebfSSpencer Ku // get that entry 1983002d39b4SEd Tanous if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries, 1984002d39b4SEd Tanous logCount)) 1985b7028ebfSSpencer Ku { 1986b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 1987b7028ebfSSpencer Ku return; 1988b7028ebfSSpencer Ku } 1989b7028ebfSSpencer Ku 1990b7028ebfSSpencer Ku if (!logEntries.empty()) 1991b7028ebfSSpencer Ku { 19926d6574c9SJason M. Bills nlohmann::json::object_t hostLogEntry; 19936d6574c9SJason M. Bills fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry); 19946d6574c9SJason M. Bills asyncResp->res.jsonValue.update(hostLogEntry); 1995b7028ebfSSpencer Ku return; 1996b7028ebfSSpencer Ku } 1997b7028ebfSSpencer Ku 1998b7028ebfSSpencer Ku // Requested ID was not found 1999ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2000b7028ebfSSpencer Ku }); 2001b7028ebfSSpencer Ku } 2002b7028ebfSSpencer Ku 2003fdd26906SClaire Weinan constexpr char const* dumpManagerIface = 2004fdd26906SClaire Weinan "xyz.openbmc_project.Collection.DeleteAll"; 2005fdd26906SClaire Weinan inline void handleLogServicesCollectionGet( 2006fdd26906SClaire Weinan crow::App& app, const crow::Request& req, 2007fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 20081da66f75SEd Tanous { 20093ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 201045ca1b86SEd Tanous { 201145ca1b86SEd Tanous return; 201245ca1b86SEd Tanous } 20137e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 20147e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2015e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 20161da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2017e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 2018e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 2019002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 2020e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 20211da66f75SEd Tanous "Collection of LogServices for this Manager"; 2022002d39b4SEd Tanous nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 2023c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 2024fdd26906SClaire Weinan 2025c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 2026c4bf6374SJason M. Bills logServiceArray.push_back( 2027002d39b4SEd Tanous {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 2028c4bf6374SJason M. Bills #endif 2029fdd26906SClaire Weinan 2030fdd26906SClaire Weinan asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); 2031fdd26906SClaire Weinan 2032fdd26906SClaire Weinan #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 2033fdd26906SClaire Weinan auto respHandler = 2034fdd26906SClaire Weinan [asyncResp]( 2035fdd26906SClaire Weinan const boost::system::error_code ec, 2036fdd26906SClaire Weinan const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { 2037fdd26906SClaire Weinan if (ec) 2038fdd26906SClaire Weinan { 2039fdd26906SClaire Weinan BMCWEB_LOG_ERROR 2040fdd26906SClaire Weinan << "handleLogServicesCollectionGet respHandler got error " 2041fdd26906SClaire Weinan << ec; 2042fdd26906SClaire Weinan // Assume that getting an error simply means there are no dump 2043fdd26906SClaire Weinan // LogServices. Return without adding any error response. 2044fdd26906SClaire Weinan return; 2045fdd26906SClaire Weinan } 2046fdd26906SClaire Weinan 2047fdd26906SClaire Weinan nlohmann::json& logServiceArrayLocal = 2048fdd26906SClaire Weinan asyncResp->res.jsonValue["Members"]; 2049fdd26906SClaire Weinan 2050fdd26906SClaire Weinan for (const std::string& path : subTreePaths) 2051fdd26906SClaire Weinan { 2052fdd26906SClaire Weinan if (path == "/xyz/openbmc_project/dump/bmc") 2053fdd26906SClaire Weinan { 2054fdd26906SClaire Weinan logServiceArrayLocal.push_back( 2055fdd26906SClaire Weinan {{"@odata.id", 2056fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 2057fdd26906SClaire Weinan } 2058fdd26906SClaire Weinan else if (path == "/xyz/openbmc_project/dump/faultlog") 2059fdd26906SClaire Weinan { 2060fdd26906SClaire Weinan logServiceArrayLocal.push_back( 2061fdd26906SClaire Weinan {{"@odata.id", 2062fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog"}}); 2063fdd26906SClaire Weinan } 2064fdd26906SClaire Weinan } 2065fdd26906SClaire Weinan 2066e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2067fdd26906SClaire Weinan logServiceArrayLocal.size(); 2068fdd26906SClaire Weinan }; 2069fdd26906SClaire Weinan 2070fdd26906SClaire Weinan crow::connections::systemBus->async_method_call( 2071fdd26906SClaire Weinan respHandler, "xyz.openbmc_project.ObjectMapper", 2072fdd26906SClaire Weinan "/xyz/openbmc_project/object_mapper", 2073fdd26906SClaire Weinan "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 2074fdd26906SClaire Weinan "/xyz/openbmc_project/dump", 0, 2075fdd26906SClaire Weinan std::array<const char*, 1>{dumpManagerIface}); 2076fdd26906SClaire Weinan #endif 2077fdd26906SClaire Weinan } 2078fdd26906SClaire Weinan 2079fdd26906SClaire Weinan inline void requestRoutesBMCLogServiceCollection(App& app) 2080fdd26906SClaire Weinan { 2081fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 2082fdd26906SClaire Weinan .privileges(redfish::privileges::getLogServiceCollection) 2083fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2084fdd26906SClaire Weinan std::bind_front(handleLogServicesCollectionGet, std::ref(app))); 2085e1f26343SJason M. Bills } 2086e1f26343SJason M. Bills 20877e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 2088e1f26343SJason M. Bills { 20897e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 2090ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 20917e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 209245ca1b86SEd Tanous [&app](const crow::Request& req, 209345ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 20943ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 20957e860f15SJohn Edward Broadbent { 209645ca1b86SEd Tanous return; 209745ca1b86SEd Tanous } 2098e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2099e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 21000f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 21010f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 2102002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 2103002d39b4SEd Tanous asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 2104c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 2105e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 21067c8c4058STejas Patil 21077c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 21087c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 2109002d39b4SEd Tanous asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 21107c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 21117c8c4058STejas Patil redfishDateTimeOffset.second; 21127c8c4058STejas Patil 21131476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 21141476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 21157e860f15SJohn Edward Broadbent }); 2116e1f26343SJason M. Bills } 2117e1f26343SJason M. Bills 21183a48b3a2SJason M. Bills static int 21193a48b3a2SJason M. Bills fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 2120e1f26343SJason M. Bills sd_journal* journal, 21213a48b3a2SJason M. Bills nlohmann::json::object_t& bmcJournalLogEntryJson) 2122e1f26343SJason M. Bills { 2123e1f26343SJason M. Bills // Get the Log Entry contents 2124e1f26343SJason M. Bills int ret = 0; 2125e1f26343SJason M. Bills 2126a8fe54f0SJason M. Bills std::string message; 2127a8fe54f0SJason M. Bills std::string_view syslogID; 2128a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 2129a8fe54f0SJason M. Bills if (ret < 0) 2130a8fe54f0SJason M. Bills { 2131a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 2132a8fe54f0SJason M. Bills << strerror(-ret); 2133a8fe54f0SJason M. Bills } 2134a8fe54f0SJason M. Bills if (!syslogID.empty()) 2135a8fe54f0SJason M. Bills { 2136a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 2137a8fe54f0SJason M. Bills } 2138a8fe54f0SJason M. Bills 213939e77504SEd Tanous std::string_view msg; 214016428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 2141e1f26343SJason M. Bills if (ret < 0) 2142e1f26343SJason M. Bills { 2143e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 2144e1f26343SJason M. Bills return 1; 2145e1f26343SJason M. Bills } 2146a8fe54f0SJason M. Bills message += std::string(msg); 2147e1f26343SJason M. Bills 2148e1f26343SJason M. Bills // Get the severity from the PRIORITY field 2149271584abSEd Tanous long int severity = 8; // Default to an invalid priority 215016428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 2151e1f26343SJason M. Bills if (ret < 0) 2152e1f26343SJason M. Bills { 2153e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 2154e1f26343SJason M. Bills } 2155e1f26343SJason M. Bills 2156e1f26343SJason M. Bills // Get the Created time from the timestamp 215716428a1aSJason M. Bills std::string entryTimeStr; 215816428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 2159e1f26343SJason M. Bills { 216016428a1aSJason M. Bills return 1; 2161e1f26343SJason M. Bills } 2162e1f26343SJason M. Bills 2163e1f26343SJason M. Bills // Fill in the log entry with the gathered data 216484afc48bSJason M. Bills bmcJournalLogEntryJson["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 216584afc48bSJason M. Bills bmcJournalLogEntryJson["@odata.id"] = 216684afc48bSJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 216784afc48bSJason M. Bills bmcJournalLogEntryID; 216884afc48bSJason M. Bills bmcJournalLogEntryJson["Name"] = "BMC Journal Entry"; 216984afc48bSJason M. Bills bmcJournalLogEntryJson["Id"] = bmcJournalLogEntryID; 217084afc48bSJason M. Bills bmcJournalLogEntryJson["Message"] = std::move(message); 217184afc48bSJason M. Bills bmcJournalLogEntryJson["EntryType"] = "Oem"; 217284afc48bSJason M. Bills bmcJournalLogEntryJson["Severity"] = severity <= 2 ? "Critical" 2173738c1e61SPatrick Williams : severity <= 4 ? "Warning" 217484afc48bSJason M. Bills : "OK"; 217584afc48bSJason M. Bills bmcJournalLogEntryJson["OemRecordFormat"] = "BMC Journal Entry"; 217684afc48bSJason M. Bills bmcJournalLogEntryJson["Created"] = std::move(entryTimeStr); 2177e1f26343SJason M. Bills return 0; 2178e1f26343SJason M. Bills } 2179e1f26343SJason M. Bills 21807e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 2181e1f26343SJason M. Bills { 21827e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 2183ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 2184002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2185002d39b4SEd Tanous [&app](const crow::Request& req, 2186002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2187c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 2188c937d2bfSEd Tanous .canDelegateTop = true, 2189c937d2bfSEd Tanous .canDelegateSkip = true, 2190c937d2bfSEd Tanous }; 2191c937d2bfSEd Tanous query_param::Query delegatedQuery; 2192c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 21933ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 2194193ad2faSJason M. Bills { 2195193ad2faSJason M. Bills return; 2196193ad2faSJason M. Bills } 21973648c8beSEd Tanous 21983648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 21993648c8beSEd Tanous size_t top = 22003648c8beSEd Tanous delegatedQuery.top.value_or(query_param::maxEntriesPerPage); 22013648c8beSEd Tanous 22027e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 22037e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2204e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2205e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 22060f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 22070f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 2208e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 2209e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2210e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 22110fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2212e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2213e1f26343SJason M. Bills 22147e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 22157e860f15SJohn Edward Broadbent // unique ID for each entry 2216e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2217e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2218e1f26343SJason M. Bills if (ret < 0) 2219e1f26343SJason M. Bills { 2220002d39b4SEd Tanous BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 2221f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2222e1f26343SJason M. Bills return; 2223e1f26343SJason M. Bills } 22240fda0f12SGeorge Liu std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 22250fda0f12SGeorge Liu journalTmp, sd_journal_close); 2226e1f26343SJason M. Bills journalTmp = nullptr; 2227b01bf299SEd Tanous uint64_t entryCount = 0; 2228e85d6b16SJason M. Bills // Reset the unique ID on the first entry 2229e85d6b16SJason M. Bills bool firstEntry = true; 2230e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 2231e1f26343SJason M. Bills { 2232193ad2faSJason M. Bills entryCount++; 22337e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 22347e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 22353648c8beSEd Tanous if (entryCount <= skip || entryCount > skip + top) 2236193ad2faSJason M. Bills { 2237193ad2faSJason M. Bills continue; 2238193ad2faSJason M. Bills } 2239193ad2faSJason M. Bills 224016428a1aSJason M. Bills std::string idStr; 2241e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2242e1f26343SJason M. Bills { 2243e1f26343SJason M. Bills continue; 2244e1f26343SJason M. Bills } 2245e85d6b16SJason M. Bills firstEntry = false; 2246e85d6b16SJason M. Bills 22473a48b3a2SJason M. Bills nlohmann::json::object_t bmcJournalLogEntry; 2248c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 2249c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 2250e1f26343SJason M. Bills { 2251f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2252e1f26343SJason M. Bills return; 2253e1f26343SJason M. Bills } 22543a48b3a2SJason M. Bills logEntryArray.push_back(std::move(bmcJournalLogEntry)); 2255e1f26343SJason M. Bills } 2256193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 22573648c8beSEd Tanous if (skip + top < entryCount) 2258193ad2faSJason M. Bills { 2259193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 22600fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 22613648c8beSEd Tanous std::to_string(skip + top); 2262193ad2faSJason M. Bills } 22637e860f15SJohn Edward Broadbent }); 2264e1f26343SJason M. Bills } 2265e1f26343SJason M. Bills 22667e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 2267e1f26343SJason M. Bills { 22687e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 22697e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 2270ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 22717e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 227245ca1b86SEd Tanous [&app](const crow::Request& req, 22737e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22747e860f15SJohn Edward Broadbent const std::string& entryID) { 22753ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 227645ca1b86SEd Tanous { 227745ca1b86SEd Tanous return; 227845ca1b86SEd Tanous } 2279e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2280e1f26343SJason M. Bills uint64_t ts = 0; 2281271584abSEd Tanous uint64_t index = 0; 22828d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2283e1f26343SJason M. Bills { 228416428a1aSJason M. Bills return; 2285e1f26343SJason M. Bills } 2286e1f26343SJason M. Bills 2287e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2288e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2289e1f26343SJason M. Bills if (ret < 0) 2290e1f26343SJason M. Bills { 2291002d39b4SEd Tanous BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 2292f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2293e1f26343SJason M. Bills return; 2294e1f26343SJason M. Bills } 2295002d39b4SEd Tanous std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 2296002d39b4SEd Tanous journalTmp, sd_journal_close); 2297e1f26343SJason M. Bills journalTmp = nullptr; 22987e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 22997e860f15SJohn Edward Broadbent // index tracking the unique ID 2300af07e3f5SJason M. Bills std::string idStr; 2301af07e3f5SJason M. Bills bool firstEntry = true; 2302e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 23032056b6d1SManojkiran Eda if (ret < 0) 23042056b6d1SManojkiran Eda { 23052056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 23062056b6d1SManojkiran Eda << strerror(-ret); 23072056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 23082056b6d1SManojkiran Eda return; 23092056b6d1SManojkiran Eda } 2310271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2311e1f26343SJason M. Bills { 2312e1f26343SJason M. Bills sd_journal_next(journal.get()); 2313af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2314af07e3f5SJason M. Bills { 2315af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2316af07e3f5SJason M. Bills return; 2317af07e3f5SJason M. Bills } 2318af07e3f5SJason M. Bills firstEntry = false; 2319af07e3f5SJason M. Bills } 2320c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2321af07e3f5SJason M. Bills if (idStr != entryID) 2322c4bf6374SJason M. Bills { 2323ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2324c4bf6374SJason M. Bills return; 2325c4bf6374SJason M. Bills } 2326c4bf6374SJason M. Bills 23273a48b3a2SJason M. Bills nlohmann::json::object_t bmcJournalLogEntry; 2328c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 23293a48b3a2SJason M. Bills bmcJournalLogEntry) != 0) 2330e1f26343SJason M. Bills { 2331f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2332e1f26343SJason M. Bills return; 2333e1f26343SJason M. Bills } 2334d405bb51SJason M. Bills asyncResp->res.jsonValue.update(bmcJournalLogEntry); 23357e860f15SJohn Edward Broadbent }); 2336c9bb6861Sraviteja-b } 2337c9bb6861Sraviteja-b 2338fdd26906SClaire Weinan inline void 2339fdd26906SClaire Weinan getDumpServiceInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2340fdd26906SClaire Weinan const std::string& dumpType) 2341c9bb6861Sraviteja-b { 2342fdd26906SClaire Weinan std::string dumpPath; 2343fdd26906SClaire Weinan std::string overWritePolicy; 2344fdd26906SClaire Weinan bool collectDiagnosticDataSupported = false; 2345fdd26906SClaire Weinan 2346fdd26906SClaire Weinan if (dumpType == "BMC") 234745ca1b86SEd Tanous { 2348fdd26906SClaire Weinan dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump"; 2349fdd26906SClaire Weinan overWritePolicy = "WrapsWhenFull"; 2350fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2351fdd26906SClaire Weinan } 2352fdd26906SClaire Weinan else if (dumpType == "FaultLog") 2353fdd26906SClaire Weinan { 2354fdd26906SClaire Weinan dumpPath = "/redfish/v1/Managers/bmc/LogServices/FaultLog"; 2355fdd26906SClaire Weinan overWritePolicy = "Unknown"; 2356fdd26906SClaire Weinan collectDiagnosticDataSupported = false; 2357fdd26906SClaire Weinan } 2358fdd26906SClaire Weinan else if (dumpType == "System") 2359fdd26906SClaire Weinan { 2360fdd26906SClaire Weinan dumpPath = "/redfish/v1/Systems/system/LogServices/Dump"; 2361fdd26906SClaire Weinan overWritePolicy = "WrapsWhenFull"; 2362fdd26906SClaire Weinan collectDiagnosticDataSupported = true; 2363fdd26906SClaire Weinan } 2364fdd26906SClaire Weinan else 2365fdd26906SClaire Weinan { 2366fdd26906SClaire Weinan BMCWEB_LOG_ERROR << "getDumpServiceInfo() invalid dump type: " 2367fdd26906SClaire Weinan << dumpType; 2368fdd26906SClaire Weinan messages::internalError(asyncResp->res); 236945ca1b86SEd Tanous return; 237045ca1b86SEd Tanous } 2371fdd26906SClaire Weinan 2372fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.id"] = dumpPath; 2373fdd26906SClaire Weinan asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService"; 2374c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 2375fdd26906SClaire Weinan asyncResp->res.jsonValue["Description"] = dumpType + " Dump LogService"; 2376fdd26906SClaire Weinan asyncResp->res.jsonValue["Id"] = std::filesystem::path(dumpPath).filename(); 2377fdd26906SClaire Weinan asyncResp->res.jsonValue["OverWritePolicy"] = std::move(overWritePolicy); 23787c8c4058STejas Patil 23797c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 23807c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 23810fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 23827c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 23837c8c4058STejas Patil redfishDateTimeOffset.second; 23847c8c4058STejas Patil 2385fdd26906SClaire Weinan asyncResp->res.jsonValue["Entries"]["@odata.id"] = dumpPath + "/Entries"; 2386002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 2387fdd26906SClaire Weinan dumpPath + "/Actions/LogService.ClearLog"; 2388fdd26906SClaire Weinan 2389fdd26906SClaire Weinan if (collectDiagnosticDataSupported) 2390fdd26906SClaire Weinan { 2391002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 23921476687dSEd Tanous ["target"] = 2393fdd26906SClaire Weinan dumpPath + "/Actions/LogService.CollectDiagnosticData"; 2394fdd26906SClaire Weinan } 2395c9bb6861Sraviteja-b } 2396c9bb6861Sraviteja-b 2397fdd26906SClaire Weinan inline void handleLogServicesDumpServiceGet( 2398fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2399fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 24007e860f15SJohn Edward Broadbent { 24013ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 240245ca1b86SEd Tanous { 240345ca1b86SEd Tanous return; 240445ca1b86SEd Tanous } 2405fdd26906SClaire Weinan getDumpServiceInfo(asyncResp, dumpType); 2406fdd26906SClaire Weinan } 2407c9bb6861Sraviteja-b 2408fdd26906SClaire Weinan inline void handleLogServicesDumpEntriesCollectionGet( 2409fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2410fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2411fdd26906SClaire Weinan { 2412fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2413fdd26906SClaire Weinan { 2414fdd26906SClaire Weinan return; 2415fdd26906SClaire Weinan } 2416fdd26906SClaire Weinan getDumpEntryCollection(asyncResp, dumpType); 2417fdd26906SClaire Weinan } 2418fdd26906SClaire Weinan 2419fdd26906SClaire Weinan inline void handleLogServicesDumpEntryGet( 2420fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2421fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2422fdd26906SClaire Weinan const std::string& dumpId) 2423fdd26906SClaire Weinan { 2424fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2425fdd26906SClaire Weinan { 2426fdd26906SClaire Weinan return; 2427fdd26906SClaire Weinan } 2428fdd26906SClaire Weinan getDumpEntryById(asyncResp, dumpId, dumpType); 2429fdd26906SClaire Weinan } 2430fdd26906SClaire Weinan 2431fdd26906SClaire Weinan inline void handleLogServicesDumpEntryDelete( 2432fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2433fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2434fdd26906SClaire Weinan const std::string& dumpId) 2435fdd26906SClaire Weinan { 2436fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2437fdd26906SClaire Weinan { 2438fdd26906SClaire Weinan return; 2439fdd26906SClaire Weinan } 2440fdd26906SClaire Weinan deleteDumpEntry(asyncResp, dumpId, dumpType); 2441fdd26906SClaire Weinan } 2442fdd26906SClaire Weinan 2443fdd26906SClaire Weinan inline void handleLogServicesDumpCollectDiagnosticDataPost( 2444fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2445fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2446fdd26906SClaire Weinan { 2447fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2448fdd26906SClaire Weinan { 2449fdd26906SClaire Weinan return; 2450fdd26906SClaire Weinan } 2451fdd26906SClaire Weinan createDump(asyncResp, req, dumpType); 2452fdd26906SClaire Weinan } 2453fdd26906SClaire Weinan 2454fdd26906SClaire Weinan inline void handleLogServicesDumpClearLogPost( 2455fdd26906SClaire Weinan crow::App& app, const std::string& dumpType, const crow::Request& req, 2456fdd26906SClaire Weinan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2457fdd26906SClaire Weinan { 2458fdd26906SClaire Weinan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2459fdd26906SClaire Weinan { 2460fdd26906SClaire Weinan return; 2461fdd26906SClaire Weinan } 2462fdd26906SClaire Weinan clearDump(asyncResp, dumpType); 2463fdd26906SClaire Weinan } 2464fdd26906SClaire Weinan 2465fdd26906SClaire Weinan inline void requestRoutesBMCDumpService(App& app) 2466fdd26906SClaire Weinan { 2467fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2468fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2469fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2470fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "BMC")); 2471fdd26906SClaire Weinan } 2472fdd26906SClaire Weinan 2473fdd26906SClaire Weinan inline void requestRoutesBMCDumpEntryCollection(App& app) 2474fdd26906SClaire Weinan { 2475fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2476fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2477fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2478fdd26906SClaire Weinan handleLogServicesDumpEntriesCollectionGet, std::ref(app), "BMC")); 2479c9bb6861Sraviteja-b } 2480c9bb6861Sraviteja-b 24817e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2482c9bb6861Sraviteja-b { 24837e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24847e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2485ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2486fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2487fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "BMC")); 2488fdd26906SClaire Weinan 24897e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24907e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2491ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 2492fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2493fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "BMC")); 2494c9bb6861Sraviteja-b } 2495c9bb6861Sraviteja-b 24967e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2497c9bb6861Sraviteja-b { 24980fda0f12SGeorge Liu BMCWEB_ROUTE( 24990fda0f12SGeorge Liu app, 25000fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2501ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 25027e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 2503fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, 2504fdd26906SClaire Weinan std::ref(app), "BMC")); 2505a43be80fSAsmitha Karunanithi } 2506a43be80fSAsmitha Karunanithi 25077e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 250880319af1SAsmitha Karunanithi { 25090fda0f12SGeorge Liu BMCWEB_ROUTE( 25100fda0f12SGeorge Liu app, 25110fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog/") 2512ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 2513fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 2514fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "BMC")); 251545ca1b86SEd Tanous } 2516fdd26906SClaire Weinan 2517fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpService(App& app) 2518fdd26906SClaire Weinan { 2519fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/") 2520fdd26906SClaire Weinan .privileges(redfish::privileges::getLogService) 2521fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2522fdd26906SClaire Weinan handleLogServicesDumpServiceGet, std::ref(app), "FaultLog")); 2523fdd26906SClaire Weinan } 2524fdd26906SClaire Weinan 2525fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntryCollection(App& app) 2526fdd26906SClaire Weinan { 2527fdd26906SClaire Weinan BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/") 2528fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntryCollection) 2529fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)( 2530fdd26906SClaire Weinan std::bind_front(handleLogServicesDumpEntriesCollectionGet, 2531fdd26906SClaire Weinan std::ref(app), "FaultLog")); 2532fdd26906SClaire Weinan } 2533fdd26906SClaire Weinan 2534fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpEntry(App& app) 2535fdd26906SClaire Weinan { 2536fdd26906SClaire Weinan BMCWEB_ROUTE(app, 2537fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/") 2538fdd26906SClaire Weinan .privileges(redfish::privileges::getLogEntry) 2539fdd26906SClaire Weinan .methods(boost::beast::http::verb::get)(std::bind_front( 2540fdd26906SClaire Weinan handleLogServicesDumpEntryGet, std::ref(app), "FaultLog")); 2541fdd26906SClaire Weinan 2542fdd26906SClaire Weinan BMCWEB_ROUTE(app, 2543fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/<str>/") 2544fdd26906SClaire Weinan .privileges(redfish::privileges::deleteLogEntry) 2545fdd26906SClaire Weinan .methods(boost::beast::http::verb::delete_)(std::bind_front( 2546fdd26906SClaire Weinan handleLogServicesDumpEntryDelete, std::ref(app), "FaultLog")); 2547fdd26906SClaire Weinan } 2548fdd26906SClaire Weinan 2549fdd26906SClaire Weinan inline void requestRoutesFaultLogDumpClear(App& app) 2550fdd26906SClaire Weinan { 2551fdd26906SClaire Weinan BMCWEB_ROUTE( 2552fdd26906SClaire Weinan app, 2553fdd26906SClaire Weinan "/redfish/v1/Managers/bmc/LogServices/FaultLog/Actions/LogService.ClearLog/") 2554fdd26906SClaire Weinan .privileges(redfish::privileges::postLogService) 2555fdd26906SClaire Weinan .methods(boost::beast::http::verb::post)(std::bind_front( 2556fdd26906SClaire Weinan handleLogServicesDumpClearLogPost, std::ref(app), "FaultLog")); 25575cb1dd27SAsmitha Karunanithi } 25585cb1dd27SAsmitha Karunanithi 25597e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 25605cb1dd27SAsmitha Karunanithi { 25617e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/") 2562ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 2563002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2564002d39b4SEd Tanous [&app](const crow::Request& req, 2565002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 25663ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 25677e860f15SJohn Edward Broadbent { 256845ca1b86SEd Tanous return; 256945ca1b86SEd Tanous } 25705cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 25715cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 25725cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2573d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 25745cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 257545ca1b86SEd Tanous asyncResp->res.jsonValue["Description"] = "System Dump LogService"; 25765cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 25775cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 25787c8c4058STejas Patil 25797c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 25807c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 258145ca1b86SEd Tanous asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 25827c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 25837c8c4058STejas Patil redfishDateTimeOffset.second; 25847c8c4058STejas Patil 25851476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 25861476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 2587002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 25881476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog"; 25891476687dSEd Tanous 2590002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 25911476687dSEd Tanous ["target"] = 25921476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData"; 25937e860f15SJohn Edward Broadbent }); 25945cb1dd27SAsmitha Karunanithi } 25955cb1dd27SAsmitha Karunanithi 25967e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 25977e860f15SJohn Edward Broadbent { 25987e860f15SJohn Edward Broadbent 25995cb1dd27SAsmitha Karunanithi /** 26005cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 26015cb1dd27SAsmitha Karunanithi */ 2602b2a3289dSAsmitha Karunanithi BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 2603ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 26047e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 260545ca1b86SEd Tanous [&app](const crow::Request& req, 2606864d6a17SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26073ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 260845ca1b86SEd Tanous { 260945ca1b86SEd Tanous return; 261045ca1b86SEd Tanous } 26115cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 26127e860f15SJohn Edward Broadbent }); 26135cb1dd27SAsmitha Karunanithi } 26145cb1dd27SAsmitha Karunanithi 26157e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 26165cb1dd27SAsmitha Karunanithi { 26177e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2618864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2619ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2620ed398213SEd Tanous 26217e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 262245ca1b86SEd Tanous [&app](const crow::Request& req, 26237e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26247e860f15SJohn Edward Broadbent const std::string& param) { 26253ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2626c7a6d660SClaire Weinan { 2627c7a6d660SClaire Weinan return; 2628c7a6d660SClaire Weinan } 2629c7a6d660SClaire Weinan getDumpEntryById(asyncResp, param, "System"); 26307e860f15SJohn Edward Broadbent }); 26318d1b46d7Szhanghch05 26327e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2633864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2634ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 26357e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 263645ca1b86SEd Tanous [&app](const crow::Request& req, 26377e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26387e860f15SJohn Edward Broadbent const std::string& param) { 26393ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 264045ca1b86SEd Tanous { 264145ca1b86SEd Tanous return; 264245ca1b86SEd Tanous } 26437e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "system"); 26447e860f15SJohn Edward Broadbent }); 26455cb1dd27SAsmitha Karunanithi } 2646c9bb6861Sraviteja-b 26477e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2648c9bb6861Sraviteja-b { 26490fda0f12SGeorge Liu BMCWEB_ROUTE( 26500fda0f12SGeorge Liu app, 26510fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2652ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 26537e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 265445ca1b86SEd Tanous [&app](const crow::Request& req, 265545ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26563ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 265745ca1b86SEd Tanous { 265845ca1b86SEd Tanous return; 265945ca1b86SEd Tanous } 266045ca1b86SEd Tanous createDump(asyncResp, req, "System"); 266145ca1b86SEd Tanous }); 2662a43be80fSAsmitha Karunanithi } 2663a43be80fSAsmitha Karunanithi 26647e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2665a43be80fSAsmitha Karunanithi { 26660fda0f12SGeorge Liu BMCWEB_ROUTE( 26670fda0f12SGeorge Liu app, 26680fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog/") 2669ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 26707e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 267145ca1b86SEd Tanous [&app](const crow::Request& req, 26727e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 26737e860f15SJohn Edward Broadbent 267445ca1b86SEd Tanous { 26753ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 267645ca1b86SEd Tanous { 267745ca1b86SEd Tanous return; 267845ca1b86SEd Tanous } 267945ca1b86SEd Tanous clearDump(asyncResp, "System"); 268045ca1b86SEd Tanous }); 2681013487e5Sraviteja-b } 2682013487e5Sraviteja-b 26837e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 26841da66f75SEd Tanous { 26853946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 26863946028dSAppaRao Puli // method for security reasons. 26871da66f75SEd Tanous /** 26881da66f75SEd Tanous * Functions triggers appropriate requests on DBus 26891da66f75SEd Tanous */ 26907e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 2691ed398213SEd Tanous // This is incorrect, should be: 2692ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2693432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 2694002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2695002d39b4SEd Tanous [&app](const crow::Request& req, 2696002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26973ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 269845ca1b86SEd Tanous { 269945ca1b86SEd Tanous return; 270045ca1b86SEd Tanous } 27017e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 27027e860f15SJohn Edward Broadbent // SubRoute 27030f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2704424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2705e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 27068e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 27074f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 27084f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 27094f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2710e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2711e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 27127c8c4058STejas Patil 27137c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 27147c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 27157c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 27167c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 27177c8c4058STejas Patil redfishDateTimeOffset.second; 27187c8c4058STejas Patil 27191476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 27201476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2721002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] = 27221476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog"; 2723002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] 27241476687dSEd Tanous ["target"] = 27251476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData"; 27267e860f15SJohn Edward Broadbent }); 27271da66f75SEd Tanous } 27281da66f75SEd Tanous 27297e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 27305b61b5e8SJason M. Bills { 27310fda0f12SGeorge Liu BMCWEB_ROUTE( 27320fda0f12SGeorge Liu app, 27330fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog/") 2734ed398213SEd Tanous // This is incorrect, should be: 2735ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2736432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 27377e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 273845ca1b86SEd Tanous [&app](const crow::Request& req, 27397e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 27403ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 274145ca1b86SEd Tanous { 274245ca1b86SEd Tanous return; 274345ca1b86SEd Tanous } 27445b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 27455b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2746cb13a392SEd Tanous const std::string&) { 27475b61b5e8SJason M. Bills if (ec) 27485b61b5e8SJason M. Bills { 27495b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 27505b61b5e8SJason M. Bills return; 27515b61b5e8SJason M. Bills } 27525b61b5e8SJason M. Bills messages::success(asyncResp->res); 27535b61b5e8SJason M. Bills }, 2754002d39b4SEd Tanous crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 27557e860f15SJohn Edward Broadbent }); 27565b61b5e8SJason M. Bills } 27575b61b5e8SJason M. Bills 27588d1b46d7Szhanghch05 static void 27598d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 27608d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 2761e855dd28SJason M. Bills { 2762043a0536SJohnathan Mantey auto getStoredLogCallback = 2763b9d36b47SEd Tanous [asyncResp, logID, 2764b9d36b47SEd Tanous &logEntryJson](const boost::system::error_code ec, 2765b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& params) { 2766e855dd28SJason M. Bills if (ec) 2767e855dd28SJason M. Bills { 2768e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 27691ddcf01aSJason M. Bills if (ec.value() == 27701ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 27711ddcf01aSJason M. Bills { 2772002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", logID); 27731ddcf01aSJason M. Bills } 27741ddcf01aSJason M. Bills else 27751ddcf01aSJason M. Bills { 2776e855dd28SJason M. Bills messages::internalError(asyncResp->res); 27771ddcf01aSJason M. Bills } 2778e855dd28SJason M. Bills return; 2779e855dd28SJason M. Bills } 2780043a0536SJohnathan Mantey 2781043a0536SJohnathan Mantey std::string timestamp{}; 2782043a0536SJohnathan Mantey std::string filename{}; 2783043a0536SJohnathan Mantey std::string logfile{}; 27842c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2785043a0536SJohnathan Mantey 2786043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2787e855dd28SJason M. Bills { 2788002d39b4SEd Tanous messages::resourceMissingAtURI(asyncResp->res, 2789002d39b4SEd Tanous crow::utility::urlFromPieces(logID)); 2790e855dd28SJason M. Bills return; 2791e855dd28SJason M. Bills } 2792e855dd28SJason M. Bills 2793043a0536SJohnathan Mantey std::string crashdumpURI = 2794e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2795043a0536SJohnathan Mantey logID + "/" + filename; 279684afc48bSJason M. Bills nlohmann::json::object_t logEntry; 279784afc48bSJason M. Bills logEntry["@odata.type"] = "#LogEntry.v1_7_0.LogEntry"; 279884afc48bSJason M. Bills logEntry["@odata.id"] = 279984afc48bSJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + logID; 280084afc48bSJason M. Bills logEntry["Name"] = "CPU Crashdump"; 280184afc48bSJason M. Bills logEntry["Id"] = logID; 280284afc48bSJason M. Bills logEntry["EntryType"] = "Oem"; 280384afc48bSJason M. Bills logEntry["AdditionalDataURI"] = std::move(crashdumpURI); 280484afc48bSJason M. Bills logEntry["DiagnosticDataType"] = "OEM"; 280584afc48bSJason M. Bills logEntry["OEMDiagnosticDataType"] = "PECICrashdump"; 280684afc48bSJason M. Bills logEntry["Created"] = std::move(timestamp); 28072b20ef6eSJason M. Bills 28082b20ef6eSJason M. Bills // If logEntryJson references an array of LogEntry resources 28092b20ef6eSJason M. Bills // ('Members' list), then push this as a new entry, otherwise set it 28102b20ef6eSJason M. Bills // directly 28112b20ef6eSJason M. Bills if (logEntryJson.is_array()) 28122b20ef6eSJason M. Bills { 28132b20ef6eSJason M. Bills logEntryJson.push_back(logEntry); 28142b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 28152b20ef6eSJason M. Bills logEntryJson.size(); 28162b20ef6eSJason M. Bills } 28172b20ef6eSJason M. Bills else 28182b20ef6eSJason M. Bills { 2819d405bb51SJason M. Bills logEntryJson.update(logEntry); 28202b20ef6eSJason M. Bills } 2821e855dd28SJason M. Bills }; 2822e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 28235b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 28245b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2825043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2826e855dd28SJason M. Bills } 2827e855dd28SJason M. Bills 28287e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 28291da66f75SEd Tanous { 28303946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28313946028dSAppaRao Puli // method for security reasons. 28321da66f75SEd Tanous /** 28331da66f75SEd Tanous * Functions triggers appropriate requests on DBus 28341da66f75SEd Tanous */ 28357e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 28367e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 2837ed398213SEd Tanous // This is incorrect, should be. 2838ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 2839432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 2840002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2841002d39b4SEd Tanous [&app](const crow::Request& req, 2842002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 28433ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 284445ca1b86SEd Tanous { 284545ca1b86SEd Tanous return; 284645ca1b86SEd Tanous } 28472b20ef6eSJason M. Bills crow::connections::systemBus->async_method_call( 28482b20ef6eSJason M. Bills [asyncResp](const boost::system::error_code ec, 28492b20ef6eSJason M. Bills const std::vector<std::string>& resp) { 28501da66f75SEd Tanous if (ec) 28511da66f75SEd Tanous { 28521da66f75SEd Tanous if (ec.value() != 28531da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 28541da66f75SEd Tanous { 28551da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 28561da66f75SEd Tanous << ec.message(); 2857f12894f8SJason M. Bills messages::internalError(asyncResp->res); 28581da66f75SEd Tanous return; 28591da66f75SEd Tanous } 28601da66f75SEd Tanous } 2861e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 28621da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 28630f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2864424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2865002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2866e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2867424c4176SJason M. Bills "Collection of Crashdump Entries"; 2868002d39b4SEd Tanous asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 2869a2dd60a6SBrandon Kim asyncResp->res.jsonValue["Members@odata.count"] = 0; 28702b20ef6eSJason M. Bills 28712b20ef6eSJason M. Bills for (const std::string& path : resp) 28721da66f75SEd Tanous { 28732b20ef6eSJason M. Bills const sdbusplus::message::object_path objPath(path); 2874e855dd28SJason M. Bills // Get the log ID 28752b20ef6eSJason M. Bills std::string logID = objPath.filename(); 28762b20ef6eSJason M. Bills if (logID.empty()) 28771da66f75SEd Tanous { 2878e855dd28SJason M. Bills continue; 28791da66f75SEd Tanous } 2880e855dd28SJason M. Bills // Add the log entry to the array 28812b20ef6eSJason M. Bills logCrashdumpEntry(asyncResp, logID, 28822b20ef6eSJason M. Bills asyncResp->res.jsonValue["Members"]); 28831da66f75SEd Tanous } 28842b20ef6eSJason M. Bills }, 28851da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 28861da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 28871da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 28885b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 28897e860f15SJohn Edward Broadbent }); 28901da66f75SEd Tanous } 28911da66f75SEd Tanous 28927e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 28931da66f75SEd Tanous { 28943946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28953946028dSAppaRao Puli // method for security reasons. 28961da66f75SEd Tanous 28977e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 28987e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/") 2899ed398213SEd Tanous // this is incorrect, should be 2900ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 2901432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 29027e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 290345ca1b86SEd Tanous [&app](const crow::Request& req, 29047e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29057e860f15SJohn Edward Broadbent const std::string& param) { 29063ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 290745ca1b86SEd Tanous { 290845ca1b86SEd Tanous return; 290945ca1b86SEd Tanous } 29107e860f15SJohn Edward Broadbent const std::string& logID = param; 2911e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 29127e860f15SJohn Edward Broadbent }); 2913e855dd28SJason M. Bills } 2914e855dd28SJason M. Bills 29157e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 2916e855dd28SJason M. Bills { 29173946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 29183946028dSAppaRao Puli // method for security reasons. 29197e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 29207e860f15SJohn Edward Broadbent app, 29217e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/") 2922ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 29237e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 2924a4ce114aSNan Zhou [](const crow::Request& req, 29257e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29267e860f15SJohn Edward Broadbent const std::string& logID, const std::string& fileName) { 29272a9beeedSShounak Mitra // Do not call getRedfishRoute here since the crashdump file is not a 29282a9beeedSShounak Mitra // Redfish resource. 2929043a0536SJohnathan Mantey auto getStoredLogCallback = 2930002d39b4SEd Tanous [asyncResp, logID, fileName, url(boost::urls::url(req.urlView))]( 2931abf2add6SEd Tanous const boost::system::error_code ec, 2932002d39b4SEd Tanous const std::vector< 2933002d39b4SEd Tanous std::pair<std::string, dbus::utility::DbusVariantType>>& 29347e860f15SJohn Edward Broadbent resp) { 29351da66f75SEd Tanous if (ec) 29361da66f75SEd Tanous { 2937002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 2938f12894f8SJason M. Bills messages::internalError(asyncResp->res); 29391da66f75SEd Tanous return; 29401da66f75SEd Tanous } 2941e855dd28SJason M. Bills 2942043a0536SJohnathan Mantey std::string dbusFilename{}; 2943043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2944043a0536SJohnathan Mantey std::string dbusFilepath{}; 2945043a0536SJohnathan Mantey 2946002d39b4SEd Tanous parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 2947002d39b4SEd Tanous dbusFilepath); 2948043a0536SJohnathan Mantey 2949043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2950043a0536SJohnathan Mantey dbusFilepath.empty()) 29511da66f75SEd Tanous { 2952ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 29531da66f75SEd Tanous return; 29541da66f75SEd Tanous } 2955e855dd28SJason M. Bills 2956043a0536SJohnathan Mantey // Verify the file name parameter is correct 2957043a0536SJohnathan Mantey if (fileName != dbusFilename) 2958043a0536SJohnathan Mantey { 2959ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 2960043a0536SJohnathan Mantey return; 2961043a0536SJohnathan Mantey } 2962043a0536SJohnathan Mantey 2963043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2964043a0536SJohnathan Mantey { 2965ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 2966043a0536SJohnathan Mantey return; 2967043a0536SJohnathan Mantey } 2968002d39b4SEd Tanous std::ifstream ifs(dbusFilepath, std::ios::in | std::ios::binary); 2969002d39b4SEd Tanous asyncResp->res.body() = 2970002d39b4SEd Tanous std::string(std::istreambuf_iterator<char>{ifs}, {}); 2971043a0536SJohnathan Mantey 29727e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 29737e860f15SJohn Edward Broadbent // from a browser 2974002d39b4SEd Tanous asyncResp->res.addHeader("Content-Disposition", "attachment"); 29751da66f75SEd Tanous }; 29761da66f75SEd Tanous crow::connections::systemBus->async_method_call( 29775b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 29785b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2979002d39b4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 29807e860f15SJohn Edward Broadbent }); 29811da66f75SEd Tanous } 29821da66f75SEd Tanous 2983c5a4c82aSJason M. Bills enum class OEMDiagnosticType 2984c5a4c82aSJason M. Bills { 2985c5a4c82aSJason M. Bills onDemand, 2986c5a4c82aSJason M. Bills telemetry, 2987c5a4c82aSJason M. Bills invalid, 2988c5a4c82aSJason M. Bills }; 2989c5a4c82aSJason M. Bills 2990f7725d79SEd Tanous inline OEMDiagnosticType 2991f7725d79SEd Tanous getOEMDiagnosticType(const std::string_view& oemDiagStr) 2992c5a4c82aSJason M. Bills { 2993c5a4c82aSJason M. Bills if (oemDiagStr == "OnDemand") 2994c5a4c82aSJason M. Bills { 2995c5a4c82aSJason M. Bills return OEMDiagnosticType::onDemand; 2996c5a4c82aSJason M. Bills } 2997c5a4c82aSJason M. Bills if (oemDiagStr == "Telemetry") 2998c5a4c82aSJason M. Bills { 2999c5a4c82aSJason M. Bills return OEMDiagnosticType::telemetry; 3000c5a4c82aSJason M. Bills } 3001c5a4c82aSJason M. Bills 3002c5a4c82aSJason M. Bills return OEMDiagnosticType::invalid; 3003c5a4c82aSJason M. Bills } 3004c5a4c82aSJason M. Bills 30057e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 30061da66f75SEd Tanous { 30073946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 30083946028dSAppaRao Puli // method for security reasons. 30090fda0f12SGeorge Liu BMCWEB_ROUTE( 30100fda0f12SGeorge Liu app, 30110fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") 3012ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 3013ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3014432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 3015002d39b4SEd Tanous .methods(boost::beast::http::verb::post)( 3016002d39b4SEd Tanous [&app](const crow::Request& req, 30177e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 30183ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 301945ca1b86SEd Tanous { 302045ca1b86SEd Tanous return; 302145ca1b86SEd Tanous } 30228e6c099aSJason M. Bills std::string diagnosticDataType; 30238e6c099aSJason M. Bills std::string oemDiagnosticDataType; 302415ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 3025002d39b4SEd Tanous req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 3026002d39b4SEd Tanous "OEMDiagnosticDataType", oemDiagnosticDataType)) 30278e6c099aSJason M. Bills { 30288e6c099aSJason M. Bills return; 30298e6c099aSJason M. Bills } 30308e6c099aSJason M. Bills 30318e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 30328e6c099aSJason M. Bills { 30338e6c099aSJason M. Bills BMCWEB_LOG_ERROR 30348e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 30358e6c099aSJason M. Bills messages::actionParameterValueFormatError( 30368e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 30378e6c099aSJason M. Bills "CollectDiagnosticData"); 30388e6c099aSJason M. Bills return; 30398e6c099aSJason M. Bills } 30408e6c099aSJason M. Bills 3041c5a4c82aSJason M. Bills OEMDiagnosticType oemDiagType = 3042c5a4c82aSJason M. Bills getOEMDiagnosticType(oemDiagnosticDataType); 3043c5a4c82aSJason M. Bills 3044c5a4c82aSJason M. Bills std::string iface; 3045c5a4c82aSJason M. Bills std::string method; 3046c5a4c82aSJason M. Bills std::string taskMatchStr; 3047c5a4c82aSJason M. Bills if (oemDiagType == OEMDiagnosticType::onDemand) 3048c5a4c82aSJason M. Bills { 3049c5a4c82aSJason M. Bills iface = crashdumpOnDemandInterface; 3050c5a4c82aSJason M. Bills method = "GenerateOnDemandLog"; 3051c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3052c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3053c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3054c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3055c5a4c82aSJason M. Bills } 3056c5a4c82aSJason M. Bills else if (oemDiagType == OEMDiagnosticType::telemetry) 3057c5a4c82aSJason M. Bills { 3058c5a4c82aSJason M. Bills iface = crashdumpTelemetryInterface; 3059c5a4c82aSJason M. Bills method = "GenerateTelemetryLog"; 3060c5a4c82aSJason M. Bills taskMatchStr = "type='signal'," 3061c5a4c82aSJason M. Bills "interface='org.freedesktop.DBus.Properties'," 3062c5a4c82aSJason M. Bills "member='PropertiesChanged'," 3063c5a4c82aSJason M. Bills "arg0namespace='com.intel.crashdump'"; 3064c5a4c82aSJason M. Bills } 3065c5a4c82aSJason M. Bills else 3066c5a4c82aSJason M. Bills { 3067c5a4c82aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 3068c5a4c82aSJason M. Bills << oemDiagnosticDataType; 3069c5a4c82aSJason M. Bills messages::actionParameterValueFormatError( 3070002d39b4SEd Tanous asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType", 3071002d39b4SEd Tanous "CollectDiagnosticData"); 3072c5a4c82aSJason M. Bills return; 3073c5a4c82aSJason M. Bills } 3074c5a4c82aSJason M. Bills 3075c5a4c82aSJason M. Bills auto collectCrashdumpCallback = 3076c5a4c82aSJason M. Bills [asyncResp, payload(task::Payload(req)), 3077c5a4c82aSJason M. Bills taskMatchStr](const boost::system::error_code ec, 307898be3e39SEd Tanous const std::string&) mutable { 30791da66f75SEd Tanous if (ec) 30801da66f75SEd Tanous { 3081002d39b4SEd Tanous if (ec.value() == boost::system::errc::operation_not_supported) 30821da66f75SEd Tanous { 3083f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 30841da66f75SEd Tanous } 30854363d3b2SJason M. Bills else if (ec.value() == 30864363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 30874363d3b2SJason M. Bills { 3088002d39b4SEd Tanous messages::serviceTemporarilyUnavailable(asyncResp->res, 3089002d39b4SEd Tanous "60"); 30904363d3b2SJason M. Bills } 30911da66f75SEd Tanous else 30921da66f75SEd Tanous { 3093f12894f8SJason M. Bills messages::internalError(asyncResp->res); 30941da66f75SEd Tanous } 30951da66f75SEd Tanous return; 30961da66f75SEd Tanous } 3097002d39b4SEd Tanous std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 309859d494eeSPatrick Williams [](boost::system::error_code err, sdbusplus::message_t&, 3099002d39b4SEd Tanous const std::shared_ptr<task::TaskData>& taskData) { 310066afe4faSJames Feist if (!err) 310166afe4faSJames Feist { 3102002d39b4SEd Tanous taskData->messages.emplace_back(messages::taskCompletedOK( 3103e5d5006bSJames Feist std::to_string(taskData->index))); 3104831d6b09SJames Feist taskData->state = "Completed"; 310566afe4faSJames Feist } 310632898ceaSJames Feist return task::completed; 310766afe4faSJames Feist }, 3108c5a4c82aSJason M. Bills taskMatchStr); 3109c5a4c82aSJason M. Bills 311046229577SJames Feist task->startTimer(std::chrono::minutes(5)); 311146229577SJames Feist task->populateResp(asyncResp->res); 311298be3e39SEd Tanous task->payload.emplace(std::move(payload)); 31131da66f75SEd Tanous }; 31148e6c099aSJason M. Bills 31151da66f75SEd Tanous crow::connections::systemBus->async_method_call( 3116002d39b4SEd Tanous std::move(collectCrashdumpCallback), crashdumpObject, crashdumpPath, 3117002d39b4SEd Tanous iface, method); 31187e860f15SJohn Edward Broadbent }); 31196eda7685SKenny L. Ku } 31206eda7685SKenny L. Ku 3121cb92c03bSAndrew Geissler /** 3122cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 3123cb92c03bSAndrew Geissler */ 31247e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 3125cb92c03bSAndrew Geissler { 3126cb92c03bSAndrew Geissler /** 3127cb92c03bSAndrew Geissler * Function handles POST method request. 3128cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3129cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3130cb92c03bSAndrew Geissler */ 31317e860f15SJohn Edward Broadbent 31320fda0f12SGeorge Liu BMCWEB_ROUTE( 31330fda0f12SGeorge Liu app, 31340fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/") 3135ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 31367e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 313745ca1b86SEd Tanous [&app](const crow::Request& req, 31387e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 31393ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 314045ca1b86SEd Tanous { 314145ca1b86SEd Tanous return; 314245ca1b86SEd Tanous } 3143cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 3144cb92c03bSAndrew Geissler 3145cb92c03bSAndrew Geissler // Process response from Logging service. 3146002d39b4SEd Tanous auto respHandler = [asyncResp](const boost::system::error_code ec) { 3147002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 3148cb92c03bSAndrew Geissler if (ec) 3149cb92c03bSAndrew Geissler { 3150cb92c03bSAndrew Geissler // TODO Handle for specific error code 3151002d39b4SEd Tanous BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 3152cb92c03bSAndrew Geissler asyncResp->res.result( 3153cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3154cb92c03bSAndrew Geissler return; 3155cb92c03bSAndrew Geissler } 3156cb92c03bSAndrew Geissler 3157002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content); 3158cb92c03bSAndrew Geissler }; 3159cb92c03bSAndrew Geissler 3160cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3161cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 31622c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 3163cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3164cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 31657e860f15SJohn Edward Broadbent }); 3166cb92c03bSAndrew Geissler } 3167a3316fc6SZhikuiRen 3168a3316fc6SZhikuiRen /**************************************************** 3169a3316fc6SZhikuiRen * Redfish PostCode interfaces 3170a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3171a3316fc6SZhikuiRen ******************************************************/ 31727e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 3173a3316fc6SZhikuiRen { 31747e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 3175ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 3176002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 3177002d39b4SEd Tanous [&app](const crow::Request& req, 3178002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 31793ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 318045ca1b86SEd Tanous { 318145ca1b86SEd Tanous return; 318245ca1b86SEd Tanous } 31831476687dSEd Tanous 31841476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 31851476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes"; 31861476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 31871476687dSEd Tanous "#LogService.v1_1_0.LogService"; 31881476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "POST Code Log Service"; 31891476687dSEd Tanous asyncResp->res.jsonValue["Description"] = "POST Code Log Service"; 31901476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "BIOS POST Code Log"; 31911476687dSEd Tanous asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 31921476687dSEd Tanous asyncResp->res.jsonValue["Entries"]["@odata.id"] = 31931476687dSEd Tanous "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 31947c8c4058STejas Patil 31957c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 31967c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 31970fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 31987c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 31997c8c4058STejas Patil redfishDateTimeOffset.second; 32007c8c4058STejas Patil 3201a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 32027e860f15SJohn Edward Broadbent {"target", 32030fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog"}}; 32047e860f15SJohn Edward Broadbent }); 3205a3316fc6SZhikuiRen } 3206a3316fc6SZhikuiRen 32077e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3208a3316fc6SZhikuiRen { 32090fda0f12SGeorge Liu BMCWEB_ROUTE( 32100fda0f12SGeorge Liu app, 32110fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog/") 3212ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3213ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3214432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 32157e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 321645ca1b86SEd Tanous [&app](const crow::Request& req, 32177e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 32183ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 321945ca1b86SEd Tanous { 322045ca1b86SEd Tanous return; 322145ca1b86SEd Tanous } 3222a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3223a3316fc6SZhikuiRen 3224a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3225a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3226a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3227a3316fc6SZhikuiRen if (ec) 3228a3316fc6SZhikuiRen { 3229a3316fc6SZhikuiRen // TODO Handle for specific error code 3230002d39b4SEd Tanous BMCWEB_LOG_ERROR << "doClearPostCodes resp_handler got error " 32317e860f15SJohn Edward Broadbent << ec; 3232002d39b4SEd Tanous asyncResp->res.result( 3233002d39b4SEd Tanous boost::beast::http::status::internal_server_error); 3234a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3235a3316fc6SZhikuiRen return; 3236a3316fc6SZhikuiRen } 3237a3316fc6SZhikuiRen }, 323815124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 323915124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3240a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 32417e860f15SJohn Edward Broadbent }); 3242a3316fc6SZhikuiRen } 3243a3316fc6SZhikuiRen 3244a3316fc6SZhikuiRen static void fillPostCodeEntry( 32458d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 32466c9a279eSManojkiran Eda const boost::container::flat_map< 32476c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3248a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3249a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3250a3316fc6SZhikuiRen { 3251a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3252fffb8c1fSEd Tanous const registries::Message* message = 3253fffb8c1fSEd Tanous registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3254a3316fc6SZhikuiRen 3255a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3256a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 3257a3316fc6SZhikuiRen 3258a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 32596c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 32606c9a279eSManojkiran Eda code : postcode) 3261a3316fc6SZhikuiRen { 3262a3316fc6SZhikuiRen currentCodeIndex++; 3263a3316fc6SZhikuiRen std::string postcodeEntryID = 3264a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3265a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3266a3316fc6SZhikuiRen 3267a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3268a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3269a3316fc6SZhikuiRen 3270a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3271a3316fc6SZhikuiRen { // already incremented 3272a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3273a3316fc6SZhikuiRen } 3274a3316fc6SZhikuiRen else 3275a3316fc6SZhikuiRen { 3276a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3277a3316fc6SZhikuiRen } 3278a3316fc6SZhikuiRen 3279a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3280a3316fc6SZhikuiRen // not fall between top and skip 3281a3316fc6SZhikuiRen if ((codeIndex == 0) && 3282a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3283a3316fc6SZhikuiRen { 3284a3316fc6SZhikuiRen continue; 3285a3316fc6SZhikuiRen } 3286a3316fc6SZhikuiRen 32874e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3288a3316fc6SZhikuiRen // currentIndex 3289a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3290a3316fc6SZhikuiRen { 3291a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3292a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3293a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3294a3316fc6SZhikuiRen continue; 3295a3316fc6SZhikuiRen } 3296a3316fc6SZhikuiRen 3297a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3298a3316fc6SZhikuiRen // index 3299a3316fc6SZhikuiRen 3300a3316fc6SZhikuiRen // Get the Created time from the timestamp 3301a3316fc6SZhikuiRen std::string entryTimeStr; 33021d8782e7SNan Zhou entryTimeStr = 33031d8782e7SNan Zhou crow::utility::getDateTimeUint(usecSinceEpoch / 1000 / 1000); 3304a3316fc6SZhikuiRen 3305a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3306a3316fc6SZhikuiRen std::ostringstream hexCode; 3307a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 33086c9a279eSManojkiran Eda << std::get<0>(code.second); 3309a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3310a3316fc6SZhikuiRen // Set Fixed -Point Notation 3311a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3312a3316fc6SZhikuiRen // Set precision to 4 digits 3313a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3314a3316fc6SZhikuiRen // Add double to stream 3315a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3316a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3317a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3318a3316fc6SZhikuiRen 3319a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3320a3316fc6SZhikuiRen std::string msg; 3321a3316fc6SZhikuiRen if (message != nullptr) 3322a3316fc6SZhikuiRen { 3323a3316fc6SZhikuiRen msg = message->message; 3324a3316fc6SZhikuiRen 3325a3316fc6SZhikuiRen // fill in this post code value 3326a3316fc6SZhikuiRen int i = 0; 3327a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3328a3316fc6SZhikuiRen { 3329a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3330a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3331a3316fc6SZhikuiRen if (argPos != std::string::npos) 3332a3316fc6SZhikuiRen { 3333a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3334a3316fc6SZhikuiRen } 3335a3316fc6SZhikuiRen } 3336a3316fc6SZhikuiRen } 3337a3316fc6SZhikuiRen 3338d4342a92STim Lee // Get Severity template from message registry 3339d4342a92STim Lee std::string severity; 3340d4342a92STim Lee if (message != nullptr) 3341d4342a92STim Lee { 33425f2b84eeSEd Tanous severity = message->messageSeverity; 3343d4342a92STim Lee } 3344d4342a92STim Lee 3345a3316fc6SZhikuiRen // add to AsyncResp 3346a3316fc6SZhikuiRen logEntryArray.push_back({}); 3347a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 334884afc48bSJason M. Bills bmcLogEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 334984afc48bSJason M. Bills bmcLogEntry["@odata.id"] = 33500fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 335184afc48bSJason M. Bills postcodeEntryID; 335284afc48bSJason M. Bills bmcLogEntry["Name"] = "POST Code Log Entry"; 335384afc48bSJason M. Bills bmcLogEntry["Id"] = postcodeEntryID; 335484afc48bSJason M. Bills bmcLogEntry["Message"] = std::move(msg); 335584afc48bSJason M. Bills bmcLogEntry["MessageId"] = "OpenBMC.0.2.BIOSPOSTCode"; 335684afc48bSJason M. Bills bmcLogEntry["MessageArgs"] = std::move(messageArgs); 335784afc48bSJason M. Bills bmcLogEntry["EntryType"] = "Event"; 335884afc48bSJason M. Bills bmcLogEntry["Severity"] = std::move(severity); 335984afc48bSJason M. Bills bmcLogEntry["Created"] = entryTimeStr; 3360647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 3361647b3cdcSGeorge Liu { 3362647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 3363647b3cdcSGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3364647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 3365647b3cdcSGeorge Liu } 3366a3316fc6SZhikuiRen } 3367a3316fc6SZhikuiRen } 3368a3316fc6SZhikuiRen 33698d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3370a3316fc6SZhikuiRen const uint16_t bootIndex, 3371a3316fc6SZhikuiRen const uint64_t codeIndex) 3372a3316fc6SZhikuiRen { 3373a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 33746c9a279eSManojkiran Eda [aResp, bootIndex, 33756c9a279eSManojkiran Eda codeIndex](const boost::system::error_code ec, 33766c9a279eSManojkiran Eda const boost::container::flat_map< 33776c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 33786c9a279eSManojkiran Eda postcode) { 3379a3316fc6SZhikuiRen if (ec) 3380a3316fc6SZhikuiRen { 3381a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3382a3316fc6SZhikuiRen messages::internalError(aResp->res); 3383a3316fc6SZhikuiRen return; 3384a3316fc6SZhikuiRen } 3385a3316fc6SZhikuiRen 3386a3316fc6SZhikuiRen // skip the empty postcode boots 3387a3316fc6SZhikuiRen if (postcode.empty()) 3388a3316fc6SZhikuiRen { 3389a3316fc6SZhikuiRen return; 3390a3316fc6SZhikuiRen } 3391a3316fc6SZhikuiRen 3392a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3393a3316fc6SZhikuiRen 3394a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3395a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3396a3316fc6SZhikuiRen }, 339715124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 339815124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3399a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3400a3316fc6SZhikuiRen bootIndex); 3401a3316fc6SZhikuiRen } 3402a3316fc6SZhikuiRen 34038d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3404a3316fc6SZhikuiRen const uint16_t bootIndex, 3405a3316fc6SZhikuiRen const uint16_t bootCount, 34063648c8beSEd Tanous const uint64_t entryCount, size_t skip, 34073648c8beSEd Tanous size_t top) 3408a3316fc6SZhikuiRen { 3409a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3410a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3411a3316fc6SZhikuiRen top](const boost::system::error_code ec, 34126c9a279eSManojkiran Eda const boost::container::flat_map< 34136c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 34146c9a279eSManojkiran Eda postcode) { 3415a3316fc6SZhikuiRen if (ec) 3416a3316fc6SZhikuiRen { 3417a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3418a3316fc6SZhikuiRen messages::internalError(aResp->res); 3419a3316fc6SZhikuiRen return; 3420a3316fc6SZhikuiRen } 3421a3316fc6SZhikuiRen 3422a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3423a3316fc6SZhikuiRen if (!postcode.empty()) 3424a3316fc6SZhikuiRen { 3425a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 34263648c8beSEd Tanous if (skip < endCount && (top + skip) > entryCount) 3427a3316fc6SZhikuiRen { 34283648c8beSEd Tanous uint64_t thisBootSkip = 34293648c8beSEd Tanous std::max(static_cast<uint64_t>(skip), entryCount) - 34303648c8beSEd Tanous entryCount; 3431a3316fc6SZhikuiRen uint64_t thisBootTop = 34323648c8beSEd Tanous std::min(static_cast<uint64_t>(top + skip), endCount) - 34333648c8beSEd Tanous entryCount; 3434a3316fc6SZhikuiRen 3435002d39b4SEd Tanous fillPostCodeEntry(aResp, postcode, bootIndex, 0, thisBootSkip, 3436002d39b4SEd Tanous thisBootTop); 3437a3316fc6SZhikuiRen } 3438a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3439a3316fc6SZhikuiRen } 3440a3316fc6SZhikuiRen 3441a3316fc6SZhikuiRen // continue to previous bootIndex 3442a3316fc6SZhikuiRen if (bootIndex < bootCount) 3443a3316fc6SZhikuiRen { 3444a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3445a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3446a3316fc6SZhikuiRen } 344781584abeSJiaqing Zhao else if (skip + top < endCount) 3448a3316fc6SZhikuiRen { 3449a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 34500fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries?$skip=" + 3451a3316fc6SZhikuiRen std::to_string(skip + top); 3452a3316fc6SZhikuiRen } 3453a3316fc6SZhikuiRen }, 345415124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 345515124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3456a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3457a3316fc6SZhikuiRen bootIndex); 3458a3316fc6SZhikuiRen } 3459a3316fc6SZhikuiRen 34608d1b46d7Szhanghch05 static void 34618d1b46d7Szhanghch05 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 34623648c8beSEd Tanous size_t skip, size_t top) 3463a3316fc6SZhikuiRen { 3464a3316fc6SZhikuiRen uint64_t entryCount = 0; 34651e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint16_t>( 34661e1e598dSJonathan Doman *crow::connections::systemBus, 34671e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 34681e1e598dSJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 34691e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", 34701e1e598dSJonathan Doman [aResp, entryCount, skip, top](const boost::system::error_code ec, 34711e1e598dSJonathan Doman const uint16_t bootCount) { 3472a3316fc6SZhikuiRen if (ec) 3473a3316fc6SZhikuiRen { 3474a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3475a3316fc6SZhikuiRen messages::internalError(aResp->res); 3476a3316fc6SZhikuiRen return; 3477a3316fc6SZhikuiRen } 34781e1e598dSJonathan Doman getPostCodeForBoot(aResp, 1, bootCount, entryCount, skip, top); 34791e1e598dSJonathan Doman }); 3480a3316fc6SZhikuiRen } 3481a3316fc6SZhikuiRen 34827e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3483a3316fc6SZhikuiRen { 34847e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 34857e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3486ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 34877e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 348845ca1b86SEd Tanous [&app](const crow::Request& req, 34897e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3490c937d2bfSEd Tanous query_param::QueryCapabilities capabilities = { 3491c937d2bfSEd Tanous .canDelegateTop = true, 3492c937d2bfSEd Tanous .canDelegateSkip = true, 3493c937d2bfSEd Tanous }; 3494c937d2bfSEd Tanous query_param::Query delegatedQuery; 3495c937d2bfSEd Tanous if (!redfish::setUpRedfishRouteWithDelegation( 34963ba00073SCarson Labrado app, req, asyncResp, delegatedQuery, capabilities)) 349745ca1b86SEd Tanous { 349845ca1b86SEd Tanous return; 349945ca1b86SEd Tanous } 3500a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3501a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3502a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3503a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3504a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3505a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3506a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3507a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3508a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 35093648c8beSEd Tanous size_t skip = delegatedQuery.skip.value_or(0); 35103648c8beSEd Tanous size_t top = 35113648c8beSEd Tanous delegatedQuery.top.value_or(query_param::maxEntriesPerPage); 35123648c8beSEd Tanous getCurrentBootNumber(asyncResp, skip, top); 35137e860f15SJohn Edward Broadbent }); 3514a3316fc6SZhikuiRen } 3515a3316fc6SZhikuiRen 3516647b3cdcSGeorge Liu /** 3517647b3cdcSGeorge Liu * @brief Parse post code ID and get the current value and index value 3518647b3cdcSGeorge Liu * eg: postCodeID=B1-2, currentValue=1, index=2 3519647b3cdcSGeorge Liu * 3520647b3cdcSGeorge Liu * @param[in] postCodeID Post Code ID 3521647b3cdcSGeorge Liu * @param[out] currentValue Current value 3522647b3cdcSGeorge Liu * @param[out] index Index value 3523647b3cdcSGeorge Liu * 3524647b3cdcSGeorge Liu * @return bool true if the parsing is successful, false the parsing fails 3525647b3cdcSGeorge Liu */ 3526647b3cdcSGeorge Liu inline static bool parsePostCode(const std::string& postCodeID, 3527647b3cdcSGeorge Liu uint64_t& currentValue, uint16_t& index) 3528647b3cdcSGeorge Liu { 3529647b3cdcSGeorge Liu std::vector<std::string> split; 3530647b3cdcSGeorge Liu boost::algorithm::split(split, postCodeID, boost::is_any_of("-")); 3531647b3cdcSGeorge Liu if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B') 3532647b3cdcSGeorge Liu { 3533647b3cdcSGeorge Liu return false; 3534647b3cdcSGeorge Liu } 3535647b3cdcSGeorge Liu 3536ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3537647b3cdcSGeorge Liu const char* start = split[0].data() + 1; 3538ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3539647b3cdcSGeorge Liu const char* end = split[0].data() + split[0].size(); 3540647b3cdcSGeorge Liu auto [ptrIndex, ecIndex] = std::from_chars(start, end, index); 3541647b3cdcSGeorge Liu 3542647b3cdcSGeorge Liu if (ptrIndex != end || ecIndex != std::errc()) 3543647b3cdcSGeorge Liu { 3544647b3cdcSGeorge Liu return false; 3545647b3cdcSGeorge Liu } 3546647b3cdcSGeorge Liu 3547647b3cdcSGeorge Liu start = split[1].data(); 3548ca45aa3cSEd Tanous 3549ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3550647b3cdcSGeorge Liu end = split[1].data() + split[1].size(); 3551647b3cdcSGeorge Liu auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue); 3552647b3cdcSGeorge Liu 3553517d9a58STony Lee return ptrValue == end && ecValue == std::errc(); 3554647b3cdcSGeorge Liu } 3555647b3cdcSGeorge Liu 3556647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3557647b3cdcSGeorge Liu { 35580fda0f12SGeorge Liu BMCWEB_ROUTE( 35590fda0f12SGeorge Liu app, 35600fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/attachment/") 3561647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 3562647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 356345ca1b86SEd Tanous [&app](const crow::Request& req, 3564647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3565647b3cdcSGeorge Liu const std::string& postCodeID) { 35663ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 356745ca1b86SEd Tanous { 356845ca1b86SEd Tanous return; 356945ca1b86SEd Tanous } 3570002d39b4SEd Tanous if (!http_helpers::isOctetAccepted(req.getHeaderValue("Accept"))) 3571647b3cdcSGeorge Liu { 3572002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::bad_request); 3573647b3cdcSGeorge Liu return; 3574647b3cdcSGeorge Liu } 3575647b3cdcSGeorge Liu 3576647b3cdcSGeorge Liu uint64_t currentValue = 0; 3577647b3cdcSGeorge Liu uint16_t index = 0; 3578647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 3579647b3cdcSGeorge Liu { 3580002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", postCodeID); 3581647b3cdcSGeorge Liu return; 3582647b3cdcSGeorge Liu } 3583647b3cdcSGeorge Liu 3584647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 3585647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 3586647b3cdcSGeorge Liu const boost::system::error_code ec, 3587002d39b4SEd Tanous const std::vector<std::tuple<uint64_t, std::vector<uint8_t>>>& 3588002d39b4SEd Tanous postcodes) { 3589647b3cdcSGeorge Liu if (ec.value() == EBADR) 3590647b3cdcSGeorge Liu { 3591002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 3592002d39b4SEd Tanous postCodeID); 3593647b3cdcSGeorge Liu return; 3594647b3cdcSGeorge Liu } 3595647b3cdcSGeorge Liu if (ec) 3596647b3cdcSGeorge Liu { 3597647b3cdcSGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3598647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 3599647b3cdcSGeorge Liu return; 3600647b3cdcSGeorge Liu } 3601647b3cdcSGeorge Liu 3602647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 3603002d39b4SEd Tanous if (value == std::string::npos || postcodes.size() < currentValue) 3604647b3cdcSGeorge Liu { 3605647b3cdcSGeorge Liu BMCWEB_LOG_ERROR << "Wrong currentValue value"; 3606002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 3607002d39b4SEd Tanous postCodeID); 3608647b3cdcSGeorge Liu return; 3609647b3cdcSGeorge Liu } 3610647b3cdcSGeorge Liu 36119eb808c1SEd Tanous const auto& [tID, c] = postcodes[value]; 361246ff87baSEd Tanous if (c.empty()) 3613647b3cdcSGeorge Liu { 3614647b3cdcSGeorge Liu BMCWEB_LOG_INFO << "No found post code data"; 3615002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "LogEntry", 3616002d39b4SEd Tanous postCodeID); 3617647b3cdcSGeorge Liu return; 3618647b3cdcSGeorge Liu } 361946ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 362046ff87baSEd Tanous const char* d = reinterpret_cast<const char*>(c.data()); 362146ff87baSEd Tanous std::string_view strData(d, c.size()); 3622647b3cdcSGeorge Liu 3623647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Type", 3624647b3cdcSGeorge Liu "application/octet-stream"); 3625002d39b4SEd Tanous asyncResp->res.addHeader("Content-Transfer-Encoding", "Base64"); 3626002d39b4SEd Tanous asyncResp->res.body() = crow::utility::base64encode(strData); 3627647b3cdcSGeorge Liu }, 3628647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 3629647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 3630002d39b4SEd Tanous "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", index); 3631647b3cdcSGeorge Liu }); 3632647b3cdcSGeorge Liu } 3633647b3cdcSGeorge Liu 36347e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 3635a3316fc6SZhikuiRen { 36367e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 36377e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/") 3638ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 36397e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 364045ca1b86SEd Tanous [&app](const crow::Request& req, 36417e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 36427e860f15SJohn Edward Broadbent const std::string& targetID) { 36433ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 364445ca1b86SEd Tanous { 364545ca1b86SEd Tanous return; 364645ca1b86SEd Tanous } 3647647b3cdcSGeorge Liu uint16_t bootIndex = 0; 3648647b3cdcSGeorge Liu uint64_t codeIndex = 0; 3649647b3cdcSGeorge Liu if (!parsePostCode(targetID, codeIndex, bootIndex)) 3650a3316fc6SZhikuiRen { 3651a3316fc6SZhikuiRen // Requested ID was not found 3652ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 3653a3316fc6SZhikuiRen return; 3654a3316fc6SZhikuiRen } 3655a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3656a3316fc6SZhikuiRen { 3657a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 36587e860f15SJohn Edward Broadbent << targetID; 3659a3316fc6SZhikuiRen } 3660a3316fc6SZhikuiRen 3661002d39b4SEd Tanous asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 3662a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 36630fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3664a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3665a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3666a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3667a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3668a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3669a3316fc6SZhikuiRen 3670a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 36717e860f15SJohn Edward Broadbent }); 3672a3316fc6SZhikuiRen } 3673a3316fc6SZhikuiRen 36741da66f75SEd Tanous } // namespace redfish 3675