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 18*b7028ebfSSpencer Ku #include "gzfile.hpp" 19647b3cdcSGeorge Liu #include "http_utility.hpp" 20*b7028ebfSSpencer 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> 30400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 314851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 324851d45dSJason M. Bills #include <boost/beast/core/span.hpp> 33400fd1fbSAdriana Kobylak #include <boost/beast/http.hpp> 341da66f75SEd Tanous #include <boost/container/flat_map.hpp> 351ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 36cb92c03bSAndrew Geissler #include <error_messages.hpp> 37ed398213SEd Tanous #include <registries/privilege_registry.hpp> 381214b7e7SGunnar Mills 39647b3cdcSGeorge Liu #include <charconv> 404418c7f0SJames Feist #include <filesystem> 4175710de2SXiaochao Ma #include <optional> 42cd225da8SJason M. Bills #include <string_view> 43abf2add6SEd Tanous #include <variant> 441da66f75SEd Tanous 451da66f75SEd Tanous namespace redfish 461da66f75SEd Tanous { 471da66f75SEd Tanous 485b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 495b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 505b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 515b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 525b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 535b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 54424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 556eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 566eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 571da66f75SEd Tanous 584851d45dSJason M. Bills namespace message_registries 594851d45dSJason M. Bills { 604851d45dSJason M. Bills static const Message* getMessageFromRegistry( 614851d45dSJason M. Bills const std::string& messageKey, 624851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 634851d45dSJason M. Bills { 644851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 654851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 664851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 674851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 684851d45dSJason M. Bills messageKey.c_str()); 694851d45dSJason M. Bills }); 704851d45dSJason M. Bills if (messageIt != registry.cend()) 714851d45dSJason M. Bills { 724851d45dSJason M. Bills return &messageIt->second; 734851d45dSJason M. Bills } 744851d45dSJason M. Bills 754851d45dSJason M. Bills return nullptr; 764851d45dSJason M. Bills } 774851d45dSJason M. Bills 784851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 794851d45dSJason M. Bills { 804851d45dSJason M. Bills // Redfish MessageIds are in the form 814851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 824851d45dSJason M. Bills // the right Message 834851d45dSJason M. Bills std::vector<std::string> fields; 844851d45dSJason M. Bills fields.reserve(4); 854851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 864851d45dSJason M. Bills std::string& registryName = fields[0]; 874851d45dSJason M. Bills std::string& messageKey = fields[3]; 884851d45dSJason M. Bills 894851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 904851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 914851d45dSJason M. Bills { 924851d45dSJason M. Bills return getMessageFromRegistry( 934851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 944851d45dSJason M. Bills } 954851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 964851d45dSJason M. Bills { 974851d45dSJason M. Bills return getMessageFromRegistry( 984851d45dSJason M. Bills messageKey, 994851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 1004851d45dSJason M. Bills } 1014851d45dSJason M. Bills return nullptr; 1024851d45dSJason M. Bills } 1034851d45dSJason M. Bills } // namespace message_registries 1044851d45dSJason M. Bills 105f6150403SJames Feist namespace fs = std::filesystem; 1061da66f75SEd Tanous 107cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 10819bd78d9SPatrick Williams std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, 109cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 110cb92c03bSAndrew Geissler 111cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 112cb92c03bSAndrew Geissler sdbusplus::message::object_path, 113cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 114cb92c03bSAndrew Geissler 115cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 116cb92c03bSAndrew Geissler { 117d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 118d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 119d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 120d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 121cb92c03bSAndrew Geissler { 122cb92c03bSAndrew Geissler return "Critical"; 123cb92c03bSAndrew Geissler } 1243174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 125d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 126d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 127cb92c03bSAndrew Geissler { 128cb92c03bSAndrew Geissler return "OK"; 129cb92c03bSAndrew Geissler } 1303174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 131cb92c03bSAndrew Geissler { 132cb92c03bSAndrew Geissler return "Warning"; 133cb92c03bSAndrew Geissler } 134cb92c03bSAndrew Geissler return ""; 135cb92c03bSAndrew Geissler } 136cb92c03bSAndrew Geissler 1377e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 13839e77504SEd Tanous const std::string_view& field, 13939e77504SEd Tanous std::string_view& contents) 14016428a1aSJason M. Bills { 14116428a1aSJason M. Bills const char* data = nullptr; 14216428a1aSJason M. Bills size_t length = 0; 14316428a1aSJason M. Bills int ret = 0; 14416428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 145271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 146271584abSEd Tanous reinterpret_cast<const void**>(&data), &length); 14716428a1aSJason M. Bills if (ret < 0) 14816428a1aSJason M. Bills { 14916428a1aSJason M. Bills return ret; 15016428a1aSJason M. Bills } 15139e77504SEd Tanous contents = std::string_view(data, length); 15216428a1aSJason M. Bills // Only use the content after the "=" character. 15381ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 15416428a1aSJason M. Bills return ret; 15516428a1aSJason M. Bills } 15616428a1aSJason M. Bills 1577e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 1587e860f15SJohn Edward Broadbent const std::string_view& field, 1597e860f15SJohn Edward Broadbent const int& base, long int& contents) 16016428a1aSJason M. Bills { 16116428a1aSJason M. Bills int ret = 0; 16239e77504SEd Tanous std::string_view metadata; 16316428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 16416428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 16516428a1aSJason M. Bills if (ret < 0) 16616428a1aSJason M. Bills { 16716428a1aSJason M. Bills return ret; 16816428a1aSJason M. Bills } 169b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 17016428a1aSJason M. Bills return ret; 17116428a1aSJason M. Bills } 17216428a1aSJason M. Bills 1737e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1747e860f15SJohn Edward Broadbent std::string& entryTimestamp) 175a3316fc6SZhikuiRen { 176a3316fc6SZhikuiRen int ret = 0; 177a3316fc6SZhikuiRen uint64_t timestamp = 0; 178a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 179a3316fc6SZhikuiRen if (ret < 0) 180a3316fc6SZhikuiRen { 181a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 182a3316fc6SZhikuiRen << strerror(-ret); 183a3316fc6SZhikuiRen return false; 184a3316fc6SZhikuiRen } 1859c620e21SAsmitha Karunanithi entryTimestamp = crow::utility::getDateTime( 1869c620e21SAsmitha Karunanithi static_cast<std::time_t>(timestamp / 1000 / 1000)); 1879c620e21SAsmitha Karunanithi return true; 188a3316fc6SZhikuiRen } 189a3316fc6SZhikuiRen 1908d1b46d7Szhanghch05 static bool getSkipParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1918d1b46d7Szhanghch05 const crow::Request& req, uint64_t& skip) 19216428a1aSJason M. Bills { 193d32c4fa9SEd Tanous boost::urls::query_params_view::iterator it = req.urlParams.find("$skip"); 1945a7e877eSJames Feist if (it != req.urlParams.end()) 19516428a1aSJason M. Bills { 1965a7e877eSJames Feist std::string skipParam = it->value(); 19716428a1aSJason M. Bills char* ptr = nullptr; 1985a7e877eSJames Feist skip = std::strtoul(skipParam.c_str(), &ptr, 10); 1995a7e877eSJames Feist if (skipParam.empty() || *ptr != '\0') 20016428a1aSJason M. Bills { 20116428a1aSJason M. Bills 2028d1b46d7Szhanghch05 messages::queryParameterValueTypeError( 2038d1b46d7Szhanghch05 asyncResp->res, std::string(skipParam), "$skip"); 20416428a1aSJason M. Bills return false; 20516428a1aSJason M. Bills } 20616428a1aSJason M. Bills } 20716428a1aSJason M. Bills return true; 20816428a1aSJason M. Bills } 20916428a1aSJason M. Bills 210271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 2118d1b46d7Szhanghch05 static bool getTopParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2128d1b46d7Szhanghch05 const crow::Request& req, uint64_t& top) 21316428a1aSJason M. Bills { 214d32c4fa9SEd Tanous boost::urls::query_params_view::iterator it = req.urlParams.find("$top"); 2155a7e877eSJames Feist if (it != req.urlParams.end()) 21616428a1aSJason M. Bills { 2175a7e877eSJames Feist std::string topParam = it->value(); 21816428a1aSJason M. Bills char* ptr = nullptr; 2195a7e877eSJames Feist top = std::strtoul(topParam.c_str(), &ptr, 10); 2205a7e877eSJames Feist if (topParam.empty() || *ptr != '\0') 22116428a1aSJason M. Bills { 2228d1b46d7Szhanghch05 messages::queryParameterValueTypeError( 2238d1b46d7Szhanghch05 asyncResp->res, std::string(topParam), "$top"); 22416428a1aSJason M. Bills return false; 22516428a1aSJason M. Bills } 226271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 22716428a1aSJason M. Bills { 22816428a1aSJason M. Bills 22916428a1aSJason M. Bills messages::queryParameterOutOfRange( 2308d1b46d7Szhanghch05 asyncResp->res, std::to_string(top), "$top", 23116428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 23216428a1aSJason M. Bills return false; 23316428a1aSJason M. Bills } 23416428a1aSJason M. Bills } 23516428a1aSJason M. Bills return true; 23616428a1aSJason M. Bills } 23716428a1aSJason M. Bills 2387e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 239e85d6b16SJason M. Bills const bool firstEntry = true) 24016428a1aSJason M. Bills { 24116428a1aSJason M. Bills int ret = 0; 24216428a1aSJason M. Bills static uint64_t prevTs = 0; 24316428a1aSJason M. Bills static int index = 0; 244e85d6b16SJason M. Bills if (firstEntry) 245e85d6b16SJason M. Bills { 246e85d6b16SJason M. Bills prevTs = 0; 247e85d6b16SJason M. Bills } 248e85d6b16SJason M. Bills 24916428a1aSJason M. Bills // Get the entry timestamp 25016428a1aSJason M. Bills uint64_t curTs = 0; 25116428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 25216428a1aSJason M. Bills if (ret < 0) 25316428a1aSJason M. Bills { 25416428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 25516428a1aSJason M. Bills << strerror(-ret); 25616428a1aSJason M. Bills return false; 25716428a1aSJason M. Bills } 25816428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 25916428a1aSJason M. Bills if (curTs == prevTs) 26016428a1aSJason M. Bills { 26116428a1aSJason M. Bills index++; 26216428a1aSJason M. Bills } 26316428a1aSJason M. Bills else 26416428a1aSJason M. Bills { 26516428a1aSJason M. Bills // Otherwise, reset it 26616428a1aSJason M. Bills index = 0; 26716428a1aSJason M. Bills } 26816428a1aSJason M. Bills // Save the timestamp 26916428a1aSJason M. Bills prevTs = curTs; 27016428a1aSJason M. Bills 27116428a1aSJason M. Bills entryID = std::to_string(curTs); 27216428a1aSJason M. Bills if (index > 0) 27316428a1aSJason M. Bills { 27416428a1aSJason M. Bills entryID += "_" + std::to_string(index); 27516428a1aSJason M. Bills } 27616428a1aSJason M. Bills return true; 27716428a1aSJason M. Bills } 27816428a1aSJason M. Bills 279e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 280e85d6b16SJason M. Bills const bool firstEntry = true) 28195820184SJason M. Bills { 282271584abSEd Tanous static time_t prevTs = 0; 28395820184SJason M. Bills static int index = 0; 284e85d6b16SJason M. Bills if (firstEntry) 285e85d6b16SJason M. Bills { 286e85d6b16SJason M. Bills prevTs = 0; 287e85d6b16SJason M. Bills } 288e85d6b16SJason M. Bills 28995820184SJason M. Bills // Get the entry timestamp 290271584abSEd Tanous std::time_t curTs = 0; 29195820184SJason M. Bills std::tm timeStruct = {}; 29295820184SJason M. Bills std::istringstream entryStream(logEntry); 29395820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 29495820184SJason M. Bills { 29595820184SJason M. Bills curTs = std::mktime(&timeStruct); 29695820184SJason M. Bills } 29795820184SJason M. Bills // If the timestamp isn't unique, increment the index 29895820184SJason M. Bills if (curTs == prevTs) 29995820184SJason M. Bills { 30095820184SJason M. Bills index++; 30195820184SJason M. Bills } 30295820184SJason M. Bills else 30395820184SJason M. Bills { 30495820184SJason M. Bills // Otherwise, reset it 30595820184SJason M. Bills index = 0; 30695820184SJason M. Bills } 30795820184SJason M. Bills // Save the timestamp 30895820184SJason M. Bills prevTs = curTs; 30995820184SJason M. Bills 31095820184SJason M. Bills entryID = std::to_string(curTs); 31195820184SJason M. Bills if (index > 0) 31295820184SJason M. Bills { 31395820184SJason M. Bills entryID += "_" + std::to_string(index); 31495820184SJason M. Bills } 31595820184SJason M. Bills return true; 31695820184SJason M. Bills } 31795820184SJason M. Bills 3187e860f15SJohn Edward Broadbent inline static bool 3198d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3208d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 3218d1b46d7Szhanghch05 uint64_t& index) 32216428a1aSJason M. Bills { 32316428a1aSJason M. Bills if (entryID.empty()) 32416428a1aSJason M. Bills { 32516428a1aSJason M. Bills return false; 32616428a1aSJason M. Bills } 32716428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 32839e77504SEd Tanous std::string_view tsStr(entryID); 32916428a1aSJason M. Bills 33081ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 33116428a1aSJason M. Bills if (underscorePos != tsStr.npos) 33216428a1aSJason M. Bills { 33316428a1aSJason M. Bills // Timestamp has an index 33416428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 33539e77504SEd Tanous std::string_view indexStr(entryID); 33616428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 337c0bd5e4bSEd Tanous auto [ptr, ec] = std::from_chars( 338c0bd5e4bSEd Tanous indexStr.data(), indexStr.data() + indexStr.size(), index); 339c0bd5e4bSEd Tanous if (ec != std::errc()) 34016428a1aSJason M. Bills { 3418d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 34216428a1aSJason M. Bills return false; 34316428a1aSJason M. Bills } 34416428a1aSJason M. Bills } 34516428a1aSJason M. Bills // Timestamp has no index 346c0bd5e4bSEd Tanous auto [ptr, ec] = 347c0bd5e4bSEd Tanous std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp); 348c0bd5e4bSEd Tanous if (ec != std::errc()) 34916428a1aSJason M. Bills { 3508d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 35116428a1aSJason M. Bills return false; 35216428a1aSJason M. Bills } 35316428a1aSJason M. Bills return true; 35416428a1aSJason M. Bills } 35516428a1aSJason M. Bills 35695820184SJason M. Bills static bool 35795820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 35895820184SJason M. Bills { 35995820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 36095820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 36195820184SJason M. Bills 36295820184SJason M. Bills // Loop through the directory looking for redfish log files 36395820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 36495820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 36595820184SJason M. Bills { 36695820184SJason M. Bills // If we find a redfish log file, save the path 36795820184SJason M. Bills std::string filename = dirEnt.path().filename(); 36895820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 36995820184SJason M. Bills { 37095820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 37195820184SJason M. Bills } 37295820184SJason M. Bills } 37395820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 37495820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 37595820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 37695820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 37795820184SJason M. Bills 37895820184SJason M. Bills return !redfishLogFiles.empty(); 37995820184SJason M. Bills } 38095820184SJason M. Bills 3818d1b46d7Szhanghch05 inline void 3828d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3835cb1dd27SAsmitha Karunanithi const std::string& dumpType) 3845cb1dd27SAsmitha Karunanithi { 3855cb1dd27SAsmitha Karunanithi std::string dumpPath; 3865cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 3875cb1dd27SAsmitha Karunanithi { 3885cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 3895cb1dd27SAsmitha Karunanithi } 3905cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 3915cb1dd27SAsmitha Karunanithi { 3925cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 3935cb1dd27SAsmitha Karunanithi } 3945cb1dd27SAsmitha Karunanithi else 3955cb1dd27SAsmitha Karunanithi { 3965cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 3975cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 3985cb1dd27SAsmitha Karunanithi return; 3995cb1dd27SAsmitha Karunanithi } 4005cb1dd27SAsmitha Karunanithi 4015cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 4025cb1dd27SAsmitha Karunanithi [asyncResp, dumpPath, dumpType](const boost::system::error_code ec, 4035cb1dd27SAsmitha Karunanithi GetManagedObjectsType& resp) { 4045cb1dd27SAsmitha Karunanithi if (ec) 4055cb1dd27SAsmitha Karunanithi { 4065cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4075cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4085cb1dd27SAsmitha Karunanithi return; 4095cb1dd27SAsmitha Karunanithi } 4105cb1dd27SAsmitha Karunanithi 4115cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4125cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 413b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 414b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 415b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 416b47452b2SAsmitha Karunanithi "/entry/"; 4175cb1dd27SAsmitha Karunanithi 4185cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4195cb1dd27SAsmitha Karunanithi { 420b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 4215cb1dd27SAsmitha Karunanithi { 4225cb1dd27SAsmitha Karunanithi continue; 4235cb1dd27SAsmitha Karunanithi } 4245cb1dd27SAsmitha Karunanithi std::time_t timestamp; 4255cb1dd27SAsmitha Karunanithi uint64_t size = 0; 42635440d18SAsmitha Karunanithi std::string dumpStatus; 42735440d18SAsmitha Karunanithi nlohmann::json thisEntry; 4282dfd18efSEd Tanous 4292dfd18efSEd Tanous std::string entryID = object.first.filename(); 4302dfd18efSEd Tanous if (entryID.empty()) 4315cb1dd27SAsmitha Karunanithi { 4325cb1dd27SAsmitha Karunanithi continue; 4335cb1dd27SAsmitha Karunanithi } 4345cb1dd27SAsmitha Karunanithi 4355cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4365cb1dd27SAsmitha Karunanithi { 43735440d18SAsmitha Karunanithi if (interfaceMap.first == 43835440d18SAsmitha Karunanithi "xyz.openbmc_project.Common.Progress") 43935440d18SAsmitha Karunanithi { 44035440d18SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 44135440d18SAsmitha Karunanithi { 44235440d18SAsmitha Karunanithi if (propertyMap.first == "Status") 44335440d18SAsmitha Karunanithi { 44435440d18SAsmitha Karunanithi auto status = std::get_if<std::string>( 44535440d18SAsmitha Karunanithi &propertyMap.second); 44635440d18SAsmitha Karunanithi if (status == nullptr) 44735440d18SAsmitha Karunanithi { 44835440d18SAsmitha Karunanithi messages::internalError(asyncResp->res); 44935440d18SAsmitha Karunanithi break; 45035440d18SAsmitha Karunanithi } 45135440d18SAsmitha Karunanithi dumpStatus = *status; 45235440d18SAsmitha Karunanithi } 45335440d18SAsmitha Karunanithi } 45435440d18SAsmitha Karunanithi } 45535440d18SAsmitha Karunanithi else if (interfaceMap.first == 45635440d18SAsmitha Karunanithi "xyz.openbmc_project.Dump.Entry") 4575cb1dd27SAsmitha Karunanithi { 4585cb1dd27SAsmitha Karunanithi 4595cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4605cb1dd27SAsmitha Karunanithi { 4615cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4625cb1dd27SAsmitha Karunanithi { 4635cb1dd27SAsmitha Karunanithi auto sizePtr = 4645cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4655cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4665cb1dd27SAsmitha Karunanithi { 4675cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4685cb1dd27SAsmitha Karunanithi break; 4695cb1dd27SAsmitha Karunanithi } 4705cb1dd27SAsmitha Karunanithi size = *sizePtr; 4715cb1dd27SAsmitha Karunanithi break; 4725cb1dd27SAsmitha Karunanithi } 4735cb1dd27SAsmitha Karunanithi } 4745cb1dd27SAsmitha Karunanithi } 4755cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4765cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 4775cb1dd27SAsmitha Karunanithi { 4785cb1dd27SAsmitha Karunanithi 4795cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4805cb1dd27SAsmitha Karunanithi { 4815cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 4825cb1dd27SAsmitha Karunanithi { 4835cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 4845cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4855cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 4865cb1dd27SAsmitha Karunanithi { 4875cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4885cb1dd27SAsmitha Karunanithi break; 4895cb1dd27SAsmitha Karunanithi } 4905cb1dd27SAsmitha Karunanithi timestamp = 4915cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 4925cb1dd27SAsmitha Karunanithi break; 4935cb1dd27SAsmitha Karunanithi } 4945cb1dd27SAsmitha Karunanithi } 4955cb1dd27SAsmitha Karunanithi } 4965cb1dd27SAsmitha Karunanithi } 4975cb1dd27SAsmitha Karunanithi 49835440d18SAsmitha Karunanithi if (dumpStatus != "xyz.openbmc_project.Common.Progress." 49935440d18SAsmitha Karunanithi "OperationStatus.Completed" && 50035440d18SAsmitha Karunanithi !dumpStatus.empty()) 50135440d18SAsmitha Karunanithi { 50235440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 50335440d18SAsmitha Karunanithi continue; 50435440d18SAsmitha Karunanithi } 50535440d18SAsmitha Karunanithi 506647b3cdcSGeorge Liu thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 5075cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 5085cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 5095cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5105cb1dd27SAsmitha Karunanithi thisEntry["Created"] = crow::utility::getDateTime(timestamp); 5115cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 5125cb1dd27SAsmitha Karunanithi 513d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataSizeBytes"] = size; 5145cb1dd27SAsmitha Karunanithi 5155cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5165cb1dd27SAsmitha Karunanithi { 517d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 518d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 519de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 520de8d94a3SAbhishek Patel entryID + "/attachment"; 5215cb1dd27SAsmitha Karunanithi } 5225cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5235cb1dd27SAsmitha Karunanithi { 524d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 525d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 526d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 527de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 528de8d94a3SAbhishek Patel entryID + "/attachment"; 5295cb1dd27SAsmitha Karunanithi } 53035440d18SAsmitha Karunanithi entriesArray.push_back(std::move(thisEntry)); 5315cb1dd27SAsmitha Karunanithi } 5325cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 5335cb1dd27SAsmitha Karunanithi entriesArray.size(); 5345cb1dd27SAsmitha Karunanithi }, 5355cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5365cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5375cb1dd27SAsmitha Karunanithi } 5385cb1dd27SAsmitha Karunanithi 5398d1b46d7Szhanghch05 inline void 5408d1b46d7Szhanghch05 getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5418d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 5425cb1dd27SAsmitha Karunanithi { 5435cb1dd27SAsmitha Karunanithi std::string dumpPath; 5445cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5455cb1dd27SAsmitha Karunanithi { 5465cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5475cb1dd27SAsmitha Karunanithi } 5485cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5495cb1dd27SAsmitha Karunanithi { 5505cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5515cb1dd27SAsmitha Karunanithi } 5525cb1dd27SAsmitha Karunanithi else 5535cb1dd27SAsmitha Karunanithi { 5545cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5555cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5565cb1dd27SAsmitha Karunanithi return; 5575cb1dd27SAsmitha Karunanithi } 5585cb1dd27SAsmitha Karunanithi 5595cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 5605cb1dd27SAsmitha Karunanithi [asyncResp, entryID, dumpPath, dumpType]( 5615cb1dd27SAsmitha Karunanithi const boost::system::error_code ec, GetManagedObjectsType& resp) { 5625cb1dd27SAsmitha Karunanithi if (ec) 5635cb1dd27SAsmitha Karunanithi { 5645cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5655cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5665cb1dd27SAsmitha Karunanithi return; 5675cb1dd27SAsmitha Karunanithi } 5685cb1dd27SAsmitha Karunanithi 569b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 570b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 571b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 572b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 573b47452b2SAsmitha Karunanithi "/entry/"; 574b47452b2SAsmitha Karunanithi 5755cb1dd27SAsmitha Karunanithi for (auto& objectPath : resp) 5765cb1dd27SAsmitha Karunanithi { 577b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5785cb1dd27SAsmitha Karunanithi { 5795cb1dd27SAsmitha Karunanithi continue; 5805cb1dd27SAsmitha Karunanithi } 5815cb1dd27SAsmitha Karunanithi 5825cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 5835cb1dd27SAsmitha Karunanithi std::time_t timestamp; 5845cb1dd27SAsmitha Karunanithi uint64_t size = 0; 58535440d18SAsmitha Karunanithi std::string dumpStatus; 5865cb1dd27SAsmitha Karunanithi 5875cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 5885cb1dd27SAsmitha Karunanithi { 58935440d18SAsmitha Karunanithi if (interfaceMap.first == 59035440d18SAsmitha Karunanithi "xyz.openbmc_project.Common.Progress") 59135440d18SAsmitha Karunanithi { 59235440d18SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 59335440d18SAsmitha Karunanithi { 59435440d18SAsmitha Karunanithi if (propertyMap.first == "Status") 59535440d18SAsmitha Karunanithi { 59635440d18SAsmitha Karunanithi auto status = std::get_if<std::string>( 59735440d18SAsmitha Karunanithi &propertyMap.second); 59835440d18SAsmitha Karunanithi if (status == nullptr) 59935440d18SAsmitha Karunanithi { 60035440d18SAsmitha Karunanithi messages::internalError(asyncResp->res); 60135440d18SAsmitha Karunanithi break; 60235440d18SAsmitha Karunanithi } 60335440d18SAsmitha Karunanithi dumpStatus = *status; 60435440d18SAsmitha Karunanithi } 60535440d18SAsmitha Karunanithi } 60635440d18SAsmitha Karunanithi } 60735440d18SAsmitha Karunanithi else if (interfaceMap.first == 60835440d18SAsmitha Karunanithi "xyz.openbmc_project.Dump.Entry") 6095cb1dd27SAsmitha Karunanithi { 6105cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6115cb1dd27SAsmitha Karunanithi { 6125cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 6135cb1dd27SAsmitha Karunanithi { 6145cb1dd27SAsmitha Karunanithi auto sizePtr = 6155cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6165cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 6175cb1dd27SAsmitha Karunanithi { 6185cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6195cb1dd27SAsmitha Karunanithi break; 6205cb1dd27SAsmitha Karunanithi } 6215cb1dd27SAsmitha Karunanithi size = *sizePtr; 6225cb1dd27SAsmitha Karunanithi break; 6235cb1dd27SAsmitha Karunanithi } 6245cb1dd27SAsmitha Karunanithi } 6255cb1dd27SAsmitha Karunanithi } 6265cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 6275cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 6285cb1dd27SAsmitha Karunanithi { 6295cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6305cb1dd27SAsmitha Karunanithi { 6315cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 6325cb1dd27SAsmitha Karunanithi { 6335cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 6345cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6355cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 6365cb1dd27SAsmitha Karunanithi { 6375cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6385cb1dd27SAsmitha Karunanithi break; 6395cb1dd27SAsmitha Karunanithi } 6405cb1dd27SAsmitha Karunanithi timestamp = 6415cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 6425cb1dd27SAsmitha Karunanithi break; 6435cb1dd27SAsmitha Karunanithi } 6445cb1dd27SAsmitha Karunanithi } 6455cb1dd27SAsmitha Karunanithi } 6465cb1dd27SAsmitha Karunanithi } 6475cb1dd27SAsmitha Karunanithi 64835440d18SAsmitha Karunanithi if (dumpStatus != "xyz.openbmc_project.Common.Progress." 64935440d18SAsmitha Karunanithi "OperationStatus.Completed" && 65035440d18SAsmitha Karunanithi !dumpStatus.empty()) 65135440d18SAsmitha Karunanithi { 65235440d18SAsmitha Karunanithi // Dump status is not Complete 65335440d18SAsmitha Karunanithi // return not found until status is changed to Completed 65435440d18SAsmitha Karunanithi messages::resourceNotFound(asyncResp->res, 65535440d18SAsmitha Karunanithi dumpType + " dump", entryID); 65635440d18SAsmitha Karunanithi return; 65735440d18SAsmitha Karunanithi } 65835440d18SAsmitha Karunanithi 6595cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 660647b3cdcSGeorge Liu "#LogEntry.v1_8_0.LogEntry"; 6615cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6625cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6635cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6645cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6655cb1dd27SAsmitha Karunanithi crow::utility::getDateTime(timestamp); 6665cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6675cb1dd27SAsmitha Karunanithi 668d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6695cb1dd27SAsmitha Karunanithi 6705cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6715cb1dd27SAsmitha Karunanithi { 672d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 673d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 674de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 675de8d94a3SAbhishek Patel entryID + "/attachment"; 6765cb1dd27SAsmitha Karunanithi } 6775cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6785cb1dd27SAsmitha Karunanithi { 679d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 680d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["OEMDiagnosticDataType"] = 6815cb1dd27SAsmitha Karunanithi "System"; 682d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 683de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 684de8d94a3SAbhishek Patel entryID + "/attachment"; 6855cb1dd27SAsmitha Karunanithi } 6865cb1dd27SAsmitha Karunanithi } 687b47452b2SAsmitha Karunanithi if (foundDumpEntry == false) 688b47452b2SAsmitha Karunanithi { 689b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 690b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 691b47452b2SAsmitha Karunanithi return; 692b47452b2SAsmitha Karunanithi } 6935cb1dd27SAsmitha Karunanithi }, 6945cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6955cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6965cb1dd27SAsmitha Karunanithi } 6975cb1dd27SAsmitha Karunanithi 6988d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6999878256fSStanley Chu const std::string& entryID, 700b47452b2SAsmitha Karunanithi const std::string& dumpType) 7015cb1dd27SAsmitha Karunanithi { 7023de8d8baSGeorge Liu auto respHandler = [asyncResp, 7033de8d8baSGeorge Liu entryID](const boost::system::error_code ec) { 7045cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 7055cb1dd27SAsmitha Karunanithi if (ec) 7065cb1dd27SAsmitha Karunanithi { 7073de8d8baSGeorge Liu if (ec.value() == EBADR) 7083de8d8baSGeorge Liu { 7093de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 7103de8d8baSGeorge Liu return; 7113de8d8baSGeorge Liu } 7125cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 7135cb1dd27SAsmitha Karunanithi << ec; 7145cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 7155cb1dd27SAsmitha Karunanithi return; 7165cb1dd27SAsmitha Karunanithi } 7175cb1dd27SAsmitha Karunanithi }; 7185cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 7195cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 720b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 721b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 722b47452b2SAsmitha Karunanithi entryID, 7235cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 7245cb1dd27SAsmitha Karunanithi } 7255cb1dd27SAsmitha Karunanithi 7268d1b46d7Szhanghch05 inline void 7278d1b46d7Szhanghch05 createDumpTaskCallback(const crow::Request& req, 7288d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7298d1b46d7Szhanghch05 const uint32_t& dumpId, const std::string& dumpPath, 730a43be80fSAsmitha Karunanithi const std::string& dumpType) 731a43be80fSAsmitha Karunanithi { 732a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 7336145ed6fSAsmitha Karunanithi [dumpId, dumpPath, dumpType]( 734a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 735a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 736cb13a392SEd Tanous if (err) 737cb13a392SEd Tanous { 7386145ed6fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Error in creating a dump"; 7396145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 7406145ed6fSAsmitha Karunanithi return task::completed; 741cb13a392SEd Tanous } 742a43be80fSAsmitha Karunanithi std::vector<std::pair< 743a43be80fSAsmitha Karunanithi std::string, 744a43be80fSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string>>>>> 745a43be80fSAsmitha Karunanithi interfacesList; 746a43be80fSAsmitha Karunanithi 747a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 748a43be80fSAsmitha Karunanithi 749a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 750a43be80fSAsmitha Karunanithi 751b47452b2SAsmitha Karunanithi if (objPath.str == 752b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 753b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 754b47452b2SAsmitha Karunanithi "/entry/" + std::to_string(dumpId)) 755a43be80fSAsmitha Karunanithi { 756a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 757a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 758a43be80fSAsmitha Karunanithi 759a43be80fSAsmitha Karunanithi std::string headerLoc = 760a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 761a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 762a43be80fSAsmitha Karunanithi std::move(headerLoc)); 763a43be80fSAsmitha Karunanithi 764a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 765b47452b2SAsmitha Karunanithi return task::completed; 7666145ed6fSAsmitha Karunanithi } 767a43be80fSAsmitha Karunanithi return task::completed; 768a43be80fSAsmitha Karunanithi }, 769a43be80fSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus." 770a43be80fSAsmitha Karunanithi "ObjectManager'," 771a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 772a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 773a43be80fSAsmitha Karunanithi 774a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 775a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 776a43be80fSAsmitha Karunanithi task->payload.emplace(req); 777a43be80fSAsmitha Karunanithi } 778a43be80fSAsmitha Karunanithi 7798d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7808d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 781a43be80fSAsmitha Karunanithi { 782a43be80fSAsmitha Karunanithi 783a43be80fSAsmitha Karunanithi std::string dumpPath; 784a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 785a43be80fSAsmitha Karunanithi { 786a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 787a43be80fSAsmitha Karunanithi } 788a43be80fSAsmitha Karunanithi else if (dumpType == "System") 789a43be80fSAsmitha Karunanithi { 790a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 791a43be80fSAsmitha Karunanithi } 792a43be80fSAsmitha Karunanithi else 793a43be80fSAsmitha Karunanithi { 794a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 795a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 796a43be80fSAsmitha Karunanithi return; 797a43be80fSAsmitha Karunanithi } 798a43be80fSAsmitha Karunanithi 799a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 800a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 801a43be80fSAsmitha Karunanithi 802a43be80fSAsmitha Karunanithi if (!redfish::json_util::readJson( 803a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 804a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 805a43be80fSAsmitha Karunanithi { 806a43be80fSAsmitha Karunanithi return; 807a43be80fSAsmitha Karunanithi } 808a43be80fSAsmitha Karunanithi 809a43be80fSAsmitha Karunanithi if (dumpType == "System") 810a43be80fSAsmitha Karunanithi { 811a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 812a43be80fSAsmitha Karunanithi { 813a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 814a43be80fSAsmitha Karunanithi "'DiagnosticDataType'/" 815a43be80fSAsmitha Karunanithi "'OEMDiagnosticDataType' value not found!"; 816a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 817a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 818a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 819a43be80fSAsmitha Karunanithi return; 820a43be80fSAsmitha Karunanithi } 8213174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 822a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 823a43be80fSAsmitha Karunanithi { 824a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 825a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 826a43be80fSAsmitha Karunanithi "System Dump creation parameters"); 827a43be80fSAsmitha Karunanithi return; 828a43be80fSAsmitha Karunanithi } 829a43be80fSAsmitha Karunanithi } 830a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 831a43be80fSAsmitha Karunanithi { 832a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 833a43be80fSAsmitha Karunanithi { 834a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 835a43be80fSAsmitha Karunanithi "'DiagnosticDataType' not found!"; 836a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 837a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 838a43be80fSAsmitha Karunanithi return; 839a43be80fSAsmitha Karunanithi } 8403174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 841a43be80fSAsmitha Karunanithi { 842a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 843a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 844a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 845a43be80fSAsmitha Karunanithi "BMC Dump creation parameters"); 846a43be80fSAsmitha Karunanithi return; 847a43be80fSAsmitha Karunanithi } 848a43be80fSAsmitha Karunanithi } 849a43be80fSAsmitha Karunanithi 850a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 851a43be80fSAsmitha Karunanithi [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec, 852a43be80fSAsmitha Karunanithi const uint32_t& dumpId) { 853a43be80fSAsmitha Karunanithi if (ec) 854a43be80fSAsmitha Karunanithi { 855a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 856a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 857a43be80fSAsmitha Karunanithi return; 858a43be80fSAsmitha Karunanithi } 859a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 860a43be80fSAsmitha Karunanithi 861a43be80fSAsmitha Karunanithi createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType); 862a43be80fSAsmitha Karunanithi }, 863b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 864b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 865b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 866a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 867a43be80fSAsmitha Karunanithi } 868a43be80fSAsmitha Karunanithi 8698d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8708d1b46d7Szhanghch05 const std::string& dumpType) 87180319af1SAsmitha Karunanithi { 872b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 873b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 8748d1b46d7Szhanghch05 87580319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 876b47452b2SAsmitha Karunanithi [asyncResp, dumpType](const boost::system::error_code ec, 87780319af1SAsmitha Karunanithi const std::vector<std::string>& subTreePaths) { 87880319af1SAsmitha Karunanithi if (ec) 87980319af1SAsmitha Karunanithi { 88080319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 88180319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 88280319af1SAsmitha Karunanithi return; 88380319af1SAsmitha Karunanithi } 88480319af1SAsmitha Karunanithi 88580319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 88680319af1SAsmitha Karunanithi { 8872dfd18efSEd Tanous sdbusplus::message::object_path objPath(path); 8882dfd18efSEd Tanous std::string logID = objPath.filename(); 8892dfd18efSEd Tanous if (logID.empty()) 89080319af1SAsmitha Karunanithi { 8912dfd18efSEd Tanous continue; 89280319af1SAsmitha Karunanithi } 8932dfd18efSEd Tanous deleteDumpEntry(asyncResp, logID, dumpType); 89480319af1SAsmitha Karunanithi } 89580319af1SAsmitha Karunanithi }, 89680319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 89780319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 89880319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 899b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, 900b47452b2SAsmitha Karunanithi std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." + 901b47452b2SAsmitha Karunanithi dumpType}); 90280319af1SAsmitha Karunanithi } 90380319af1SAsmitha Karunanithi 9047e860f15SJohn Edward Broadbent inline static void parseCrashdumpParameters( 905043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params, 906043a0536SJohnathan Mantey std::string& filename, std::string& timestamp, std::string& logfile) 907043a0536SJohnathan Mantey { 908043a0536SJohnathan Mantey for (auto property : params) 909043a0536SJohnathan Mantey { 910043a0536SJohnathan Mantey if (property.first == "Timestamp") 911043a0536SJohnathan Mantey { 912043a0536SJohnathan Mantey const std::string* value = 9138d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 914043a0536SJohnathan Mantey if (value != nullptr) 915043a0536SJohnathan Mantey { 916043a0536SJohnathan Mantey timestamp = *value; 917043a0536SJohnathan Mantey } 918043a0536SJohnathan Mantey } 919043a0536SJohnathan Mantey else if (property.first == "Filename") 920043a0536SJohnathan Mantey { 921043a0536SJohnathan Mantey const std::string* value = 9228d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 923043a0536SJohnathan Mantey if (value != nullptr) 924043a0536SJohnathan Mantey { 925043a0536SJohnathan Mantey filename = *value; 926043a0536SJohnathan Mantey } 927043a0536SJohnathan Mantey } 928043a0536SJohnathan Mantey else if (property.first == "Log") 929043a0536SJohnathan Mantey { 930043a0536SJohnathan Mantey const std::string* value = 9318d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 932043a0536SJohnathan Mantey if (value != nullptr) 933043a0536SJohnathan Mantey { 934043a0536SJohnathan Mantey logfile = *value; 935043a0536SJohnathan Mantey } 936043a0536SJohnathan Mantey } 937043a0536SJohnathan Mantey } 938043a0536SJohnathan Mantey } 939043a0536SJohnathan Mantey 940a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 9417e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 9421da66f75SEd Tanous { 943c4bf6374SJason M. Bills /** 944c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 945c4bf6374SJason M. Bills */ 9467e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/") 947ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 9487e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 9497e860f15SJohn Edward Broadbent [](const crow::Request&, 9507e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 9517e860f15SJohn Edward Broadbent 952c4bf6374SJason M. Bills { 9537e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 9547e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 955c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 956c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 957c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 958029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 9597e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 9607e860f15SJohn Edward Broadbent "System Log Services Collection"; 961c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 962c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 9637e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 9647e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 965c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 966029573d4SEd Tanous logServiceArray.push_back( 9677e860f15SJohn Edward Broadbent {{"@odata.id", 9687e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog"}}); 9695cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 970c9bb6861Sraviteja-b logServiceArray.push_back( 9717e860f15SJohn Edward Broadbent {{"@odata.id", 9727e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump"}}); 973c9bb6861Sraviteja-b #endif 974c9bb6861Sraviteja-b 975d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 976d53dd41fSJason M. Bills logServiceArray.push_back( 977cb92c03bSAndrew Geissler {{"@odata.id", 978424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 979d53dd41fSJason M. Bills #endif 980*b7028ebfSSpencer Ku 981*b7028ebfSSpencer Ku #ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER 982*b7028ebfSSpencer Ku logServiceArray.push_back( 983*b7028ebfSSpencer Ku {{"@odata.id", 984*b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"}}); 985*b7028ebfSSpencer Ku #endif 986c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 987c4bf6374SJason M. Bills logServiceArray.size(); 988a3316fc6SZhikuiRen 989a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 990a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 991a3316fc6SZhikuiRen const std::vector<std::string>& subtreePath) { 992a3316fc6SZhikuiRen if (ec) 993a3316fc6SZhikuiRen { 994a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 995a3316fc6SZhikuiRen return; 996a3316fc6SZhikuiRen } 997a3316fc6SZhikuiRen 998a3316fc6SZhikuiRen for (auto& pathStr : subtreePath) 999a3316fc6SZhikuiRen { 1000a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 1001a3316fc6SZhikuiRen { 100223a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 1003a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 100423a21a1cSEd Tanous logServiceArrayLocal.push_back( 1005a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 1006a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 10077e860f15SJohn Edward Broadbent asyncResp->res 10087e860f15SJohn Edward Broadbent .jsonValue["Members@odata.count"] = 100923a21a1cSEd Tanous logServiceArrayLocal.size(); 1010a3316fc6SZhikuiRen return; 1011a3316fc6SZhikuiRen } 1012a3316fc6SZhikuiRen } 1013a3316fc6SZhikuiRen }, 1014a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 1015a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 10167e860f15SJohn Edward Broadbent "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 10177e860f15SJohn Edward Broadbent 0, std::array<const char*, 1>{postCodeIface}); 10187e860f15SJohn Edward Broadbent }); 1019c4bf6374SJason M. Bills } 1020c4bf6374SJason M. Bills 10217e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 1022c4bf6374SJason M. Bills { 10237e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 1024ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 10257e860f15SJohn Edward Broadbent .methods( 10267e860f15SJohn Edward Broadbent boost::beast::http::verb:: 10277e860f15SJohn Edward Broadbent get)([](const crow::Request&, 10287e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1029c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1030029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1031c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1032c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 1033c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 10347e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 10357e860f15SJohn Edward Broadbent "System Event Log Service"; 1036c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1037c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 10387c8c4058STejas Patil 10397c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 10407c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 10417c8c4058STejas Patil 10427c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 10437c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 10447c8c4058STejas Patil redfishDateTimeOffset.second; 10457c8c4058STejas Patil 1046c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1047c4bf6374SJason M. Bills {"@odata.id", 1048029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 1049e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1050e7d6c8b2SGunnar Mills 1051e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 1052e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 10537e860f15SJohn Edward Broadbent }); 1054489640c6SJason M. Bills } 1055489640c6SJason M. Bills 10567e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1057489640c6SJason M. Bills { 10587e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 1059489640c6SJason M. Bills "LogService.ClearLog/") 1060432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 10617e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 10627e860f15SJohn Edward Broadbent [](const crow::Request&, 10637e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1064489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1065489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1066489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1067489640c6SJason M. Bills { 1068489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1069489640c6SJason M. Bills { 1070489640c6SJason M. Bills std::error_code ec; 1071489640c6SJason M. Bills std::filesystem::remove(file, ec); 1072489640c6SJason M. Bills } 1073489640c6SJason M. Bills } 1074489640c6SJason M. Bills 1075489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1076489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1077489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1078489640c6SJason M. Bills if (ec) 1079489640c6SJason M. Bills { 10807e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " 10817e860f15SJohn Edward Broadbent << ec; 1082489640c6SJason M. Bills messages::internalError(asyncResp->res); 1083489640c6SJason M. Bills return; 1084489640c6SJason M. Bills } 1085489640c6SJason M. Bills 1086489640c6SJason M. Bills messages::success(asyncResp->res); 1087489640c6SJason M. Bills }, 1088489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 10897e860f15SJohn Edward Broadbent "org.freedesktop.systemd1.Manager", "ReloadUnit", 10907e860f15SJohn Edward Broadbent "rsyslog.service", "replace"); 10917e860f15SJohn Edward Broadbent }); 1092c4bf6374SJason M. Bills } 1093c4bf6374SJason M. Bills 109495820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 1095b5a76932SEd Tanous const std::string& logEntry, 109695820184SJason M. Bills nlohmann::json& logEntryJson) 1097c4bf6374SJason M. Bills { 109895820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1099cd225da8SJason M. Bills // First get the Timestamp 1100f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1101cd225da8SJason M. Bills if (space == std::string::npos) 110295820184SJason M. Bills { 110395820184SJason M. Bills return 1; 110495820184SJason M. Bills } 1105cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1106cd225da8SJason M. Bills // Then get the log contents 1107f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1108cd225da8SJason M. Bills if (entryStart == std::string::npos) 1109cd225da8SJason M. Bills { 1110cd225da8SJason M. Bills return 1; 1111cd225da8SJason M. Bills } 1112cd225da8SJason M. Bills std::string_view entry(logEntry); 1113cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1114cd225da8SJason M. Bills // Use split to separate the entry into its fields 1115cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1116cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1117cd225da8SJason M. Bills boost::token_compress_on); 1118cd225da8SJason M. Bills // We need at least a MessageId to be valid 1119cd225da8SJason M. Bills if (logEntryFields.size() < 1) 1120cd225da8SJason M. Bills { 1121cd225da8SJason M. Bills return 1; 1122cd225da8SJason M. Bills } 1123cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 112495820184SJason M. Bills 11254851d45dSJason M. Bills // Get the Message from the MessageRegistry 11264851d45dSJason M. Bills const message_registries::Message* message = 11274851d45dSJason M. Bills message_registries::getMessage(messageID); 1128c4bf6374SJason M. Bills 11294851d45dSJason M. Bills std::string msg; 11304851d45dSJason M. Bills std::string severity; 11314851d45dSJason M. Bills if (message != nullptr) 1132c4bf6374SJason M. Bills { 11334851d45dSJason M. Bills msg = message->message; 11344851d45dSJason M. Bills severity = message->severity; 1135c4bf6374SJason M. Bills } 1136c4bf6374SJason M. Bills 113715a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 113815a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 113915a86ff6SJason M. Bills if (logEntryFields.size() > 1) 114015a86ff6SJason M. Bills { 114115a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 114215a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 114315a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 114415a86ff6SJason M. Bills if (!messageArgsStart.empty()) 114515a86ff6SJason M. Bills { 114615a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 114715a86ff6SJason M. Bills } 114815a86ff6SJason M. Bills 114923a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1150c4bf6374SJason M. Bills 11514851d45dSJason M. Bills // Fill the MessageArgs into the Message 115295820184SJason M. Bills int i = 0; 115395820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11544851d45dSJason M. Bills { 115595820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11564851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11574851d45dSJason M. Bills if (argPos != std::string::npos) 11584851d45dSJason M. Bills { 115995820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11604851d45dSJason M. Bills } 11614851d45dSJason M. Bills } 116215a86ff6SJason M. Bills } 11634851d45dSJason M. Bills 116495820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 116595820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 116695820184SJason M. Bills // between the '.' and the '+', so just remove them. 1167f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1168f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 116995820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1170c4bf6374SJason M. Bills { 117195820184SJason M. Bills timestamp.erase(dot, plus - dot); 1172c4bf6374SJason M. Bills } 1173c4bf6374SJason M. Bills 1174c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 117595820184SJason M. Bills logEntryJson = { 1176647b3cdcSGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 1177029573d4SEd Tanous {"@odata.id", 1178897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 117995820184SJason M. Bills logEntryID}, 1180c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 118195820184SJason M. Bills {"Id", logEntryID}, 118295820184SJason M. Bills {"Message", std::move(msg)}, 118395820184SJason M. Bills {"MessageId", std::move(messageID)}, 1184f23b7296SEd Tanous {"MessageArgs", messageArgs}, 1185c4bf6374SJason M. Bills {"EntryType", "Event"}, 118695820184SJason M. Bills {"Severity", std::move(severity)}, 118795820184SJason M. Bills {"Created", std::move(timestamp)}}; 1188c4bf6374SJason M. Bills return 0; 1189c4bf6374SJason M. Bills } 1190c4bf6374SJason M. Bills 11917e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1192c4bf6374SJason M. Bills { 11937e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 11947e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 11958b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 11967e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 11977e860f15SJohn Edward Broadbent [](const crow::Request& req, 11987e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1199271584abSEd Tanous uint64_t skip = 0; 1200271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 12018d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 1202c4bf6374SJason M. Bills { 1203c4bf6374SJason M. Bills return; 1204c4bf6374SJason M. Bills } 12058d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 1206c4bf6374SJason M. Bills { 1207c4bf6374SJason M. Bills return; 1208c4bf6374SJason M. Bills } 12097e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 12107e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1211c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1212c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1213c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1214029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1215c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1216c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1217c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1218cb92c03bSAndrew Geissler 12197e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 12207e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 1221c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 12227e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 12237e860f15SJohn Edward Broadbent // entry 122495820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 122595820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1226b01bf299SEd Tanous uint64_t entryCount = 0; 1227cd225da8SJason M. Bills std::string logEntry; 122895820184SJason M. Bills 12297e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12307e860f15SJohn Edward Broadbent // backwards 12317e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 12327e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1233c4bf6374SJason M. Bills { 1234cd225da8SJason M. Bills std::ifstream logStream(*it); 123595820184SJason M. Bills if (!logStream.is_open()) 1236c4bf6374SJason M. Bills { 1237c4bf6374SJason M. Bills continue; 1238c4bf6374SJason M. Bills } 1239c4bf6374SJason M. Bills 1240e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1241e85d6b16SJason M. Bills bool firstEntry = true; 124295820184SJason M. Bills while (std::getline(logStream, logEntry)) 124395820184SJason M. Bills { 1244c4bf6374SJason M. Bills entryCount++; 12457e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip 12467e860f15SJohn Edward Broadbent // from the start) and top (number of entries to 12477e860f15SJohn Edward Broadbent // display) 1248c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1249c4bf6374SJason M. Bills { 1250c4bf6374SJason M. Bills continue; 1251c4bf6374SJason M. Bills } 1252c4bf6374SJason M. Bills 1253c4bf6374SJason M. Bills std::string idStr; 1254e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1255c4bf6374SJason M. Bills { 1256c4bf6374SJason M. Bills continue; 1257c4bf6374SJason M. Bills } 1258c4bf6374SJason M. Bills 1259e85d6b16SJason M. Bills if (firstEntry) 1260e85d6b16SJason M. Bills { 1261e85d6b16SJason M. Bills firstEntry = false; 1262e85d6b16SJason M. Bills } 1263e85d6b16SJason M. Bills 1264c4bf6374SJason M. Bills logEntryArray.push_back({}); 1265c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 12667e860f15SJohn Edward Broadbent if (fillEventLogEntryJson(idStr, logEntry, 12677e860f15SJohn Edward Broadbent bmcLogEntry) != 0) 1268c4bf6374SJason M. Bills { 1269c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1270c4bf6374SJason M. Bills return; 1271c4bf6374SJason M. Bills } 1272c4bf6374SJason M. Bills } 127395820184SJason M. Bills } 1274c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1275c4bf6374SJason M. Bills if (skip + top < entryCount) 1276c4bf6374SJason M. Bills { 1277c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 127895820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 127995820184SJason M. Bills "Entries?$skip=" + 1280c4bf6374SJason M. Bills std::to_string(skip + top); 1281c4bf6374SJason M. Bills } 12827e860f15SJohn Edward Broadbent }); 1283897967deSJason M. Bills } 1284897967deSJason M. Bills 12857e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1286897967deSJason M. Bills { 12877e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 12887e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1289ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 12907e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 12917e860f15SJohn Edward Broadbent [](const crow::Request&, 12927e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12937e860f15SJohn Edward Broadbent const std::string& param) { 12947e860f15SJohn Edward Broadbent const std::string& targetID = param; 12958d1b46d7Szhanghch05 12967e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 12977e860f15SJohn Edward Broadbent // entry to find the target entry 1298897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1299897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1300897967deSJason M. Bills std::string logEntry; 1301897967deSJason M. Bills 13027e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 13037e860f15SJohn Edward Broadbent // backwards 13047e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 13057e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1306897967deSJason M. Bills { 1307897967deSJason M. Bills std::ifstream logStream(*it); 1308897967deSJason M. Bills if (!logStream.is_open()) 1309897967deSJason M. Bills { 1310897967deSJason M. Bills continue; 1311897967deSJason M. Bills } 1312897967deSJason M. Bills 1313897967deSJason M. Bills // Reset the unique ID on the first entry 1314897967deSJason M. Bills bool firstEntry = true; 1315897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1316897967deSJason M. Bills { 1317897967deSJason M. Bills std::string idStr; 1318897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1319897967deSJason M. Bills { 1320897967deSJason M. Bills continue; 1321897967deSJason M. Bills } 1322897967deSJason M. Bills 1323897967deSJason M. Bills if (firstEntry) 1324897967deSJason M. Bills { 1325897967deSJason M. Bills firstEntry = false; 1326897967deSJason M. Bills } 1327897967deSJason M. Bills 1328897967deSJason M. Bills if (idStr == targetID) 1329897967deSJason M. Bills { 13307e860f15SJohn Edward Broadbent if (fillEventLogEntryJson( 13317e860f15SJohn Edward Broadbent idStr, logEntry, 1332897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1333897967deSJason M. Bills { 1334897967deSJason M. Bills messages::internalError(asyncResp->res); 1335897967deSJason M. Bills return; 1336897967deSJason M. Bills } 1337897967deSJason M. Bills return; 1338897967deSJason M. Bills } 1339897967deSJason M. Bills } 1340897967deSJason M. Bills } 1341897967deSJason M. Bills // Requested ID was not found 1342897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 13437e860f15SJohn Edward Broadbent }); 134408a4e4b5SAnthony Wilson } 134508a4e4b5SAnthony Wilson 13467e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 134708a4e4b5SAnthony Wilson { 13487e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 13497e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1350ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 13517e860f15SJohn Edward Broadbent .methods( 13527e860f15SJohn Edward Broadbent boost::beast::http::verb:: 13537e860f15SJohn Edward Broadbent get)([](const crow::Request&, 13547e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 13557e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 13567e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 135708a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 135808a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 135908a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 136008a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 136108a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 136208a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 136308a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 136408a4e4b5SAnthony Wilson 1365cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1366cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1367cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1368cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1369cb92c03bSAndrew Geissler GetManagedObjectsType& resp) { 1370cb92c03bSAndrew Geissler if (ec) 1371cb92c03bSAndrew Geissler { 1372cb92c03bSAndrew Geissler // TODO Handle for specific error code 1373cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1374cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1375cb92c03bSAndrew Geissler << ec; 1376cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1377cb92c03bSAndrew Geissler return; 1378cb92c03bSAndrew Geissler } 1379cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1380cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1381cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 1382cb92c03bSAndrew Geissler for (auto& objectPath : resp) 1383cb92c03bSAndrew Geissler { 138466664f25SEd Tanous uint32_t* id = nullptr; 138566664f25SEd Tanous std::time_t timestamp{}; 1386d139c236SGeorge Liu std::time_t updateTimestamp{}; 138766664f25SEd Tanous std::string* severity = nullptr; 138866664f25SEd Tanous std::string* message = nullptr; 1389f86bb901SAdriana Kobylak std::string* filePath = nullptr; 139075710de2SXiaochao Ma bool resolved = false; 1391f86bb901SAdriana Kobylak for (auto& interfaceMap : objectPath.second) 1392f86bb901SAdriana Kobylak { 1393f86bb901SAdriana Kobylak if (interfaceMap.first == 1394f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1395f86bb901SAdriana Kobylak { 1396cb92c03bSAndrew Geissler for (auto& propertyMap : interfaceMap.second) 1397cb92c03bSAndrew Geissler { 1398cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1399cb92c03bSAndrew Geissler { 1400f86bb901SAdriana Kobylak id = std::get_if<uint32_t>( 1401f86bb901SAdriana Kobylak &propertyMap.second); 1402cb92c03bSAndrew Geissler } 1403cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1404cb92c03bSAndrew Geissler { 1405cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1406f86bb901SAdriana Kobylak std::get_if<uint64_t>( 1407f86bb901SAdriana Kobylak &propertyMap.second); 1408ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1409ebd45906SGeorge Liu { 14107e860f15SJohn Edward Broadbent timestamp = 14117e860f15SJohn Edward Broadbent crow::utility::getTimestamp( 14127e860f15SJohn Edward Broadbent *millisTimeStamp); 14137e860f15SJohn Edward Broadbent } 14147e860f15SJohn Edward Broadbent } 14157e860f15SJohn Edward Broadbent else if (propertyMap.first == 14167e860f15SJohn Edward Broadbent "UpdateTimestamp") 14177e860f15SJohn Edward Broadbent { 14187e860f15SJohn Edward Broadbent const uint64_t* millisTimeStamp = 14197e860f15SJohn Edward Broadbent std::get_if<uint64_t>( 14207e860f15SJohn Edward Broadbent &propertyMap.second); 14217e860f15SJohn Edward Broadbent if (millisTimeStamp != nullptr) 14227e860f15SJohn Edward Broadbent { 14237e860f15SJohn Edward Broadbent updateTimestamp = 14247e860f15SJohn Edward Broadbent crow::utility::getTimestamp( 14257e860f15SJohn Edward Broadbent *millisTimeStamp); 14267e860f15SJohn Edward Broadbent } 14277e860f15SJohn Edward Broadbent } 14287e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 14297e860f15SJohn Edward Broadbent { 14307e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 14317e860f15SJohn Edward Broadbent &propertyMap.second); 14327e860f15SJohn Edward Broadbent } 14337e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 14347e860f15SJohn Edward Broadbent { 14357e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 14367e860f15SJohn Edward Broadbent &propertyMap.second); 14377e860f15SJohn Edward Broadbent } 14387e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 14397e860f15SJohn Edward Broadbent { 14407e860f15SJohn Edward Broadbent bool* resolveptr = std::get_if<bool>( 14417e860f15SJohn Edward Broadbent &propertyMap.second); 14427e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 14437e860f15SJohn Edward Broadbent { 14447e860f15SJohn Edward Broadbent messages::internalError( 14457e860f15SJohn Edward Broadbent asyncResp->res); 14467e860f15SJohn Edward Broadbent return; 14477e860f15SJohn Edward Broadbent } 14487e860f15SJohn Edward Broadbent resolved = *resolveptr; 14497e860f15SJohn Edward Broadbent } 14507e860f15SJohn Edward Broadbent } 14517e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14527e860f15SJohn Edward Broadbent severity == nullptr) 14537e860f15SJohn Edward Broadbent { 14547e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 14557e860f15SJohn Edward Broadbent return; 14567e860f15SJohn Edward Broadbent } 14577e860f15SJohn Edward Broadbent } 14587e860f15SJohn Edward Broadbent else if (interfaceMap.first == 14597e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 14607e860f15SJohn Edward Broadbent { 14617e860f15SJohn Edward Broadbent for (auto& propertyMap : interfaceMap.second) 14627e860f15SJohn Edward Broadbent { 14637e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 14647e860f15SJohn Edward Broadbent { 14657e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 14667e860f15SJohn Edward Broadbent &propertyMap.second); 14677e860f15SJohn Edward Broadbent } 14687e860f15SJohn Edward Broadbent } 14697e860f15SJohn Edward Broadbent } 14707e860f15SJohn Edward Broadbent } 14717e860f15SJohn Edward Broadbent // Object path without the 14727e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 14737e860f15SJohn Edward Broadbent // and continue. 14747e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14757e860f15SJohn Edward Broadbent severity == nullptr) 14767e860f15SJohn Edward Broadbent { 14777e860f15SJohn Edward Broadbent continue; 14787e860f15SJohn Edward Broadbent } 14797e860f15SJohn Edward Broadbent entriesArray.push_back({}); 14807e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 14817e860f15SJohn Edward Broadbent thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 14827e860f15SJohn Edward Broadbent thisEntry["@odata.id"] = 14837e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/" 14847e860f15SJohn Edward Broadbent "LogServices/EventLog/Entries/" + 14857e860f15SJohn Edward Broadbent std::to_string(*id); 14867e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 14877e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 14887e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 14897e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 14907e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 14917e860f15SJohn Edward Broadbent thisEntry["Severity"] = 14927e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 14937e860f15SJohn Edward Broadbent thisEntry["Created"] = 14947e860f15SJohn Edward Broadbent crow::utility::getDateTime(timestamp); 14957e860f15SJohn Edward Broadbent thisEntry["Modified"] = 14967e860f15SJohn Edward Broadbent crow::utility::getDateTime(updateTimestamp); 14977e860f15SJohn Edward Broadbent if (filePath != nullptr) 14987e860f15SJohn Edward Broadbent { 14997e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 15007e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/" 15017e860f15SJohn Edward Broadbent "EventLog/" 15027e860f15SJohn Edward Broadbent "Entries/" + 15037e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 15047e860f15SJohn Edward Broadbent } 15057e860f15SJohn Edward Broadbent } 15067e860f15SJohn Edward Broadbent std::sort(entriesArray.begin(), entriesArray.end(), 15077e860f15SJohn Edward Broadbent [](const nlohmann::json& left, 15087e860f15SJohn Edward Broadbent const nlohmann::json& right) { 15097e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 15107e860f15SJohn Edward Broadbent }); 15117e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 15127e860f15SJohn Edward Broadbent entriesArray.size(); 15137e860f15SJohn Edward Broadbent }, 15147e860f15SJohn Edward Broadbent "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 15157e860f15SJohn Edward Broadbent "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 15167e860f15SJohn Edward Broadbent }); 15177e860f15SJohn Edward Broadbent } 15187e860f15SJohn Edward Broadbent 15197e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 15207e860f15SJohn Edward Broadbent { 15217e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 15227e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1523ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 15247e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 15257e860f15SJohn Edward Broadbent [](const crow::Request&, 15267e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 15277e860f15SJohn Edward Broadbent const std::string& param) 15287e860f15SJohn Edward Broadbent 15297e860f15SJohn Edward Broadbent { 15307e860f15SJohn Edward Broadbent std::string entryID = param; 15317e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 15327e860f15SJohn Edward Broadbent 15337e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 15347e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 15357e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 15367e860f15SJohn Edward Broadbent [asyncResp, entryID](const boost::system::error_code ec, 15377e860f15SJohn Edward Broadbent GetManagedPropertyType& resp) { 15387e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 15397e860f15SJohn Edward Broadbent { 15407e860f15SJohn Edward Broadbent messages::resourceNotFound( 15417e860f15SJohn Edward Broadbent asyncResp->res, "EventLogEntry", entryID); 15427e860f15SJohn Edward Broadbent return; 15437e860f15SJohn Edward Broadbent } 15447e860f15SJohn Edward Broadbent if (ec) 15457e860f15SJohn Edward Broadbent { 15467e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "EventLogEntry (DBus) " 15477e860f15SJohn Edward Broadbent "resp_handler got error " 15487e860f15SJohn Edward Broadbent << ec; 15497e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 15507e860f15SJohn Edward Broadbent return; 15517e860f15SJohn Edward Broadbent } 15527e860f15SJohn Edward Broadbent uint32_t* id = nullptr; 15537e860f15SJohn Edward Broadbent std::time_t timestamp{}; 15547e860f15SJohn Edward Broadbent std::time_t updateTimestamp{}; 15557e860f15SJohn Edward Broadbent std::string* severity = nullptr; 15567e860f15SJohn Edward Broadbent std::string* message = nullptr; 15577e860f15SJohn Edward Broadbent std::string* filePath = nullptr; 15587e860f15SJohn Edward Broadbent bool resolved = false; 15597e860f15SJohn Edward Broadbent 15607e860f15SJohn Edward Broadbent for (auto& propertyMap : resp) 15617e860f15SJohn Edward Broadbent { 15627e860f15SJohn Edward Broadbent if (propertyMap.first == "Id") 15637e860f15SJohn Edward Broadbent { 15647e860f15SJohn Edward Broadbent id = std::get_if<uint32_t>(&propertyMap.second); 15657e860f15SJohn Edward Broadbent } 15667e860f15SJohn Edward Broadbent else if (propertyMap.first == "Timestamp") 15677e860f15SJohn Edward Broadbent { 15687e860f15SJohn Edward Broadbent const uint64_t* millisTimeStamp = 15697e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 15707e860f15SJohn Edward Broadbent if (millisTimeStamp != nullptr) 15717e860f15SJohn Edward Broadbent { 1572d139c236SGeorge Liu timestamp = crow::utility::getTimestamp( 1573cb92c03bSAndrew Geissler *millisTimeStamp); 1574d139c236SGeorge Liu } 1575ebd45906SGeorge Liu } 1576d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1577d139c236SGeorge Liu { 1578d139c236SGeorge Liu const uint64_t* millisTimeStamp = 15797e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 1580ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1581ebd45906SGeorge Liu { 1582ebd45906SGeorge Liu updateTimestamp = 1583ebd45906SGeorge Liu crow::utility::getTimestamp( 1584d139c236SGeorge Liu *millisTimeStamp); 1585cb92c03bSAndrew Geissler } 1586ebd45906SGeorge Liu } 1587cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1588cb92c03bSAndrew Geissler { 1589cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1590cb92c03bSAndrew Geissler &propertyMap.second); 1591cb92c03bSAndrew Geissler } 1592cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1593cb92c03bSAndrew Geissler { 1594cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1595cb92c03bSAndrew Geissler &propertyMap.second); 1596ae34c8e8SAdriana Kobylak } 159775710de2SXiaochao Ma else if (propertyMap.first == "Resolved") 159875710de2SXiaochao Ma { 159975710de2SXiaochao Ma bool* resolveptr = 160075710de2SXiaochao Ma std::get_if<bool>(&propertyMap.second); 160175710de2SXiaochao Ma if (resolveptr == nullptr) 160275710de2SXiaochao Ma { 160375710de2SXiaochao Ma messages::internalError(asyncResp->res); 160475710de2SXiaochao Ma return; 160575710de2SXiaochao Ma } 160675710de2SXiaochao Ma resolved = *resolveptr; 160775710de2SXiaochao Ma } 16087e860f15SJohn Edward Broadbent else if (propertyMap.first == "Path") 1609f86bb901SAdriana Kobylak { 1610f86bb901SAdriana Kobylak filePath = std::get_if<std::string>( 1611f86bb901SAdriana Kobylak &propertyMap.second); 1612f86bb901SAdriana Kobylak } 1613f86bb901SAdriana Kobylak } 1614f86bb901SAdriana Kobylak if (id == nullptr || message == nullptr || 1615f86bb901SAdriana Kobylak severity == nullptr) 1616f86bb901SAdriana Kobylak { 1617ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1618271584abSEd Tanous return; 1619271584abSEd Tanous } 1620f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 1621f86bb901SAdriana Kobylak "#LogEntry.v1_8_0.LogEntry"; 1622f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.id"] = 16237e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/" 16247e860f15SJohn Edward Broadbent "Entries/" + 1625f86bb901SAdriana Kobylak std::to_string(*id); 16267e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 16277e860f15SJohn Edward Broadbent "System Event Log Entry"; 1628f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1629f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1630f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 1631f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1632f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1633f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1634f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 1635f86bb901SAdriana Kobylak crow::utility::getDateTime(timestamp); 1636f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 1637f86bb901SAdriana Kobylak crow::utility::getDateTime(updateTimestamp); 1638f86bb901SAdriana Kobylak if (filePath != nullptr) 1639f86bb901SAdriana Kobylak { 1640f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 16417e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/" 16427e860f15SJohn Edward Broadbent "EventLog/" 16437e860f15SJohn Edward Broadbent "attachment/" + 16447e860f15SJohn Edward Broadbent std::to_string(*id); 1645f86bb901SAdriana Kobylak } 1646cb92c03bSAndrew Geissler }, 1647cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1648cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1649f86bb901SAdriana Kobylak "org.freedesktop.DBus.Properties", "GetAll", ""); 16507e860f15SJohn Edward Broadbent }); 1651336e96c6SChicago Duan 16527e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16537e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1654ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 16557e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 16567e860f15SJohn Edward Broadbent [](const crow::Request& req, 16577e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16587e860f15SJohn Edward Broadbent const std::string& entryId) { 165975710de2SXiaochao Ma std::optional<bool> resolved; 166075710de2SXiaochao Ma 16617e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "Resolved", 16627e860f15SJohn Edward Broadbent resolved)) 166375710de2SXiaochao Ma { 166475710de2SXiaochao Ma return; 166575710de2SXiaochao Ma } 166675710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 166775710de2SXiaochao Ma 166875710de2SXiaochao Ma crow::connections::systemBus->async_method_call( 16694f48d5f6SEd Tanous [asyncResp, entryId](const boost::system::error_code ec) { 167075710de2SXiaochao Ma if (ec) 167175710de2SXiaochao Ma { 167275710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 167375710de2SXiaochao Ma messages::internalError(asyncResp->res); 167475710de2SXiaochao Ma return; 167575710de2SXiaochao Ma } 167675710de2SXiaochao Ma }, 167775710de2SXiaochao Ma "xyz.openbmc_project.Logging", 167875710de2SXiaochao Ma "/xyz/openbmc_project/logging/entry/" + entryId, 167975710de2SXiaochao Ma "org.freedesktop.DBus.Properties", "Set", 168075710de2SXiaochao Ma "xyz.openbmc_project.Logging.Entry", "Resolved", 168175710de2SXiaochao Ma std::variant<bool>(*resolved)); 16827e860f15SJohn Edward Broadbent }); 168375710de2SXiaochao Ma 16847e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16857e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1686ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1687ed398213SEd Tanous 16887e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 16897e860f15SJohn Edward Broadbent [](const crow::Request&, 16907e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16917e860f15SJohn Edward Broadbent const std::string& param) 16927e860f15SJohn Edward Broadbent 1693336e96c6SChicago Duan { 1694336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1695336e96c6SChicago Duan 16967e860f15SJohn Edward Broadbent std::string entryID = param; 1697336e96c6SChicago Duan 1698336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1699336e96c6SChicago Duan 1700336e96c6SChicago Duan // Process response from Logging service. 17017e860f15SJohn Edward Broadbent auto respHandler = [asyncResp, entryID]( 17027e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 17037e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 17047e860f15SJohn Edward Broadbent << "EventLogEntry (DBus) doDelete callback: Done"; 1705336e96c6SChicago Duan if (ec) 1706336e96c6SChicago Duan { 17073de8d8baSGeorge Liu if (ec.value() == EBADR) 17083de8d8baSGeorge Liu { 17097e860f15SJohn Edward Broadbent messages::resourceNotFound(asyncResp->res, 17107e860f15SJohn Edward Broadbent "LogEntry", entryID); 17113de8d8baSGeorge Liu return; 17123de8d8baSGeorge Liu } 1713336e96c6SChicago Duan // TODO Handle for specific error code 17147e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "EventLogEntry (DBus) doDelete " 17157e860f15SJohn Edward Broadbent "respHandler got error " 1716336e96c6SChicago Duan << ec; 1717336e96c6SChicago Duan asyncResp->res.result( 1718336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1719336e96c6SChicago Duan return; 1720336e96c6SChicago Duan } 1721336e96c6SChicago Duan 1722336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1723336e96c6SChicago Duan }; 1724336e96c6SChicago Duan 1725336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1726336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1727336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1728336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1729336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 17307e860f15SJohn Edward Broadbent }); 1731400fd1fbSAdriana Kobylak } 1732400fd1fbSAdriana Kobylak 17337e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1734400fd1fbSAdriana Kobylak { 17357e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" 17367e860f15SJohn Edward Broadbent "<str>/attachment") 1737ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 17387e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 17397e860f15SJohn Edward Broadbent [](const crow::Request& req, 17407e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 17417e860f15SJohn Edward Broadbent const std::string& param) 1742400fd1fbSAdriana Kobylak 17437e860f15SJohn Edward Broadbent { 1744647b3cdcSGeorge Liu if (!http_helpers::isOctetAccepted( 1745647b3cdcSGeorge Liu req.getHeaderValue("Accept"))) 1746400fd1fbSAdriana Kobylak { 17477e860f15SJohn Edward Broadbent asyncResp->res.result( 17487e860f15SJohn Edward Broadbent boost::beast::http::status::bad_request); 1749400fd1fbSAdriana Kobylak return; 1750400fd1fbSAdriana Kobylak } 1751400fd1fbSAdriana Kobylak 17527e860f15SJohn Edward Broadbent std::string entryID = param; 1753400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1754400fd1fbSAdriana Kobylak 1755400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 17567e860f15SJohn Edward Broadbent [asyncResp, 17577e860f15SJohn Edward Broadbent entryID](const boost::system::error_code ec, 1758400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 1759400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 1760400fd1fbSAdriana Kobylak { 17617e860f15SJohn Edward Broadbent messages::resourceNotFound( 17627e860f15SJohn Edward Broadbent asyncResp->res, "EventLogAttachment", entryID); 1763400fd1fbSAdriana Kobylak return; 1764400fd1fbSAdriana Kobylak } 1765400fd1fbSAdriana Kobylak if (ec) 1766400fd1fbSAdriana Kobylak { 1767400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1768400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1769400fd1fbSAdriana Kobylak return; 1770400fd1fbSAdriana Kobylak } 1771400fd1fbSAdriana Kobylak 1772400fd1fbSAdriana Kobylak int fd = -1; 1773400fd1fbSAdriana Kobylak fd = dup(unixfd); 1774400fd1fbSAdriana Kobylak if (fd == -1) 1775400fd1fbSAdriana Kobylak { 1776400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1777400fd1fbSAdriana Kobylak return; 1778400fd1fbSAdriana Kobylak } 1779400fd1fbSAdriana Kobylak 1780400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 1781400fd1fbSAdriana Kobylak if (size == -1) 1782400fd1fbSAdriana Kobylak { 1783400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1784400fd1fbSAdriana Kobylak return; 1785400fd1fbSAdriana Kobylak } 1786400fd1fbSAdriana Kobylak 1787400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 1788400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 1789400fd1fbSAdriana Kobylak if (size > maxFileSize) 1790400fd1fbSAdriana Kobylak { 1791400fd1fbSAdriana Kobylak BMCWEB_LOG_ERROR 1792400fd1fbSAdriana Kobylak << "File size exceeds maximum allowed size of " 1793400fd1fbSAdriana Kobylak << maxFileSize; 1794400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1795400fd1fbSAdriana Kobylak return; 1796400fd1fbSAdriana Kobylak } 1797400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 1798400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 1799400fd1fbSAdriana Kobylak if (rc == -1) 1800400fd1fbSAdriana Kobylak { 1801400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1802400fd1fbSAdriana Kobylak return; 1803400fd1fbSAdriana Kobylak } 1804400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 1805400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 1806400fd1fbSAdriana Kobylak { 1807400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1808400fd1fbSAdriana Kobylak return; 1809400fd1fbSAdriana Kobylak } 1810400fd1fbSAdriana Kobylak close(fd); 1811400fd1fbSAdriana Kobylak 1812400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 18137e860f15SJohn Edward Broadbent std::string output = 18147e860f15SJohn Edward Broadbent crow::utility::base64encode(strData); 1815400fd1fbSAdriana Kobylak 1816400fd1fbSAdriana Kobylak asyncResp->res.addHeader("Content-Type", 1817400fd1fbSAdriana Kobylak "application/octet-stream"); 18187e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Transfer-Encoding", 18197e860f15SJohn Edward Broadbent "Base64"); 1820400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 1821400fd1fbSAdriana Kobylak }, 1822400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 1823400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 1824400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 18257e860f15SJohn Edward Broadbent }); 18261da66f75SEd Tanous } 18271da66f75SEd Tanous 1828*b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 1829*b7028ebfSSpencer Ku 1830*b7028ebfSSpencer Ku inline bool 1831*b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 1832*b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 1833*b7028ebfSSpencer Ku { 1834*b7028ebfSSpencer Ku std::error_code ec; 1835*b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 1836*b7028ebfSSpencer Ku if (ec) 1837*b7028ebfSSpencer Ku { 1838*b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << ec.message(); 1839*b7028ebfSSpencer Ku return false; 1840*b7028ebfSSpencer Ku } 1841*b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 1842*b7028ebfSSpencer Ku { 1843*b7028ebfSSpencer Ku std::string filename = it.path().filename(); 1844*b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 1845*b7028ebfSSpencer Ku // path 1846*b7028ebfSSpencer Ku if (boost::starts_with(filename, "log")) 1847*b7028ebfSSpencer Ku { 1848*b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 1849*b7028ebfSSpencer Ku } 1850*b7028ebfSSpencer Ku } 1851*b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 1852*b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 1853*b7028ebfSSpencer Ku // descending order. 1854*b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 1855*b7028ebfSSpencer Ku AlphanumLess<std::string>()); 1856*b7028ebfSSpencer Ku 1857*b7028ebfSSpencer Ku return true; 1858*b7028ebfSSpencer Ku } 1859*b7028ebfSSpencer Ku 1860*b7028ebfSSpencer Ku inline bool 1861*b7028ebfSSpencer Ku getHostLoggerEntries(std::vector<std::filesystem::path>& hostLoggerFiles, 1862*b7028ebfSSpencer Ku uint64_t& skip, uint64_t& top, 1863*b7028ebfSSpencer Ku std::vector<std::string>& logEntries, size_t& logCount) 1864*b7028ebfSSpencer Ku { 1865*b7028ebfSSpencer Ku GzFileReader logFile; 1866*b7028ebfSSpencer Ku 1867*b7028ebfSSpencer Ku // Go though all log files and expose host logs. 1868*b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 1869*b7028ebfSSpencer Ku { 1870*b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 1871*b7028ebfSSpencer Ku { 1872*b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to expose host logs"; 1873*b7028ebfSSpencer Ku return false; 1874*b7028ebfSSpencer Ku } 1875*b7028ebfSSpencer Ku } 1876*b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 1877*b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 1878*b7028ebfSSpencer Ku if (!lastMessage.empty()) 1879*b7028ebfSSpencer Ku { 1880*b7028ebfSSpencer Ku logCount++; 1881*b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 1882*b7028ebfSSpencer Ku { 1883*b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 1884*b7028ebfSSpencer Ku } 1885*b7028ebfSSpencer Ku } 1886*b7028ebfSSpencer Ku return true; 1887*b7028ebfSSpencer Ku } 1888*b7028ebfSSpencer Ku 1889*b7028ebfSSpencer Ku inline void fillHostLoggerEntryJson(const std::string& logEntryID, 1890*b7028ebfSSpencer Ku const std::string& msg, 1891*b7028ebfSSpencer Ku nlohmann::json& logEntryJson) 1892*b7028ebfSSpencer Ku { 1893*b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 1894*b7028ebfSSpencer Ku logEntryJson = { 1895*b7028ebfSSpencer Ku {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1896*b7028ebfSSpencer Ku {"@odata.id", 1897*b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/" + 1898*b7028ebfSSpencer Ku logEntryID}, 1899*b7028ebfSSpencer Ku {"Name", "Host Logger Entry"}, 1900*b7028ebfSSpencer Ku {"Id", logEntryID}, 1901*b7028ebfSSpencer Ku {"Message", msg}, 1902*b7028ebfSSpencer Ku {"EntryType", "Oem"}, 1903*b7028ebfSSpencer Ku {"Severity", "OK"}, 1904*b7028ebfSSpencer Ku {"OemRecordFormat", "Host Logger Entry"}}; 1905*b7028ebfSSpencer Ku } 1906*b7028ebfSSpencer Ku 1907*b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 1908*b7028ebfSSpencer Ku { 1909*b7028ebfSSpencer Ku BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/HostLogger/") 1910*b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 1911*b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 1912*b7028ebfSSpencer Ku [](const crow::Request&, 1913*b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1914*b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1915*b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"; 1916*b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1917*b7028ebfSSpencer Ku "#LogService.v1_1_0.LogService"; 1918*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 1919*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 1920*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 1921*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Entries"] = { 1922*b7028ebfSSpencer Ku {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 1923*b7028ebfSSpencer Ku "HostLogger/Entries"}}; 1924*b7028ebfSSpencer Ku }); 1925*b7028ebfSSpencer Ku } 1926*b7028ebfSSpencer Ku 1927*b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 1928*b7028ebfSSpencer Ku { 1929*b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 1930*b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/") 1931*b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 1932*b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 1933*b7028ebfSSpencer Ku [](const crow::Request& req, 1934*b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1935*b7028ebfSSpencer Ku uint64_t skip = 0; 1936*b7028ebfSSpencer Ku uint64_t top = maxEntriesPerPage; // Show max 1000 entries by 1937*b7028ebfSSpencer Ku // default, allow range 1 to 1938*b7028ebfSSpencer Ku // 1000 entries per page. 1939*b7028ebfSSpencer Ku if (!getSkipParam(asyncResp, req, skip)) 1940*b7028ebfSSpencer Ku { 1941*b7028ebfSSpencer Ku return; 1942*b7028ebfSSpencer Ku } 1943*b7028ebfSSpencer Ku if (!getTopParam(asyncResp, req, top)) 1944*b7028ebfSSpencer Ku { 1945*b7028ebfSSpencer Ku return; 1946*b7028ebfSSpencer Ku } 1947*b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1948*b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 1949*b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1950*b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 1951*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 1952*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 1953*b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 1954*b7028ebfSSpencer Ku nlohmann::json& logEntryArray = 1955*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members"]; 1956*b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 1957*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 1958*b7028ebfSSpencer Ku 1959*b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 1960*b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 1961*b7028ebfSSpencer Ku { 1962*b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 1963*b7028ebfSSpencer Ku return; 1964*b7028ebfSSpencer Ku } 1965*b7028ebfSSpencer Ku 1966*b7028ebfSSpencer Ku size_t logCount = 0; 1967*b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 1968*b7028ebfSSpencer Ku // control by skip and top. 1969*b7028ebfSSpencer Ku std::vector<std::string> logEntries; 1970*b7028ebfSSpencer Ku if (!getHostLoggerEntries(hostLoggerFiles, skip, top, 1971*b7028ebfSSpencer Ku logEntries, logCount)) 1972*b7028ebfSSpencer Ku { 1973*b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 1974*b7028ebfSSpencer Ku return; 1975*b7028ebfSSpencer Ku } 1976*b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 1977*b7028ebfSSpencer Ku // log count 1978*b7028ebfSSpencer Ku if (logEntries.size() == 0) 1979*b7028ebfSSpencer Ku { 1980*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 1981*b7028ebfSSpencer Ku return; 1982*b7028ebfSSpencer Ku } 1983*b7028ebfSSpencer Ku if (logEntries.size() > 0) 1984*b7028ebfSSpencer Ku { 1985*b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 1986*b7028ebfSSpencer Ku { 1987*b7028ebfSSpencer Ku logEntryArray.push_back({}); 1988*b7028ebfSSpencer Ku nlohmann::json& hostLogEntry = logEntryArray.back(); 1989*b7028ebfSSpencer Ku fillHostLoggerEntryJson(std::to_string(skip + i), 1990*b7028ebfSSpencer Ku logEntries[i], hostLogEntry); 1991*b7028ebfSSpencer Ku } 1992*b7028ebfSSpencer Ku 1993*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 1994*b7028ebfSSpencer Ku if (skip + top < logCount) 1995*b7028ebfSSpencer Ku { 1996*b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 1997*b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/" 1998*b7028ebfSSpencer Ku "Entries?$skip=" + 1999*b7028ebfSSpencer Ku std::to_string(skip + top); 2000*b7028ebfSSpencer Ku } 2001*b7028ebfSSpencer Ku } 2002*b7028ebfSSpencer Ku }); 2003*b7028ebfSSpencer Ku } 2004*b7028ebfSSpencer Ku 2005*b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 2006*b7028ebfSSpencer Ku { 2007*b7028ebfSSpencer Ku BMCWEB_ROUTE( 2008*b7028ebfSSpencer Ku app, "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/<str>/") 2009*b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 2010*b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 2011*b7028ebfSSpencer Ku [](const crow::Request&, 2012*b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2013*b7028ebfSSpencer Ku const std::string& param) { 2014*b7028ebfSSpencer Ku const std::string& targetID = param; 2015*b7028ebfSSpencer Ku 2016*b7028ebfSSpencer Ku uint64_t idInt = 0; 2017*b7028ebfSSpencer Ku auto [ptr, ec] = std::from_chars( 2018*b7028ebfSSpencer Ku targetID.data(), targetID.data() + targetID.size(), idInt); 2019*b7028ebfSSpencer Ku if (ec == std::errc::invalid_argument) 2020*b7028ebfSSpencer Ku { 2021*b7028ebfSSpencer Ku messages::resourceMissingAtURI(asyncResp->res, targetID); 2022*b7028ebfSSpencer Ku return; 2023*b7028ebfSSpencer Ku } 2024*b7028ebfSSpencer Ku if (ec == std::errc::result_out_of_range) 2025*b7028ebfSSpencer Ku { 2026*b7028ebfSSpencer Ku messages::resourceMissingAtURI(asyncResp->res, targetID); 2027*b7028ebfSSpencer Ku return; 2028*b7028ebfSSpencer Ku } 2029*b7028ebfSSpencer Ku 2030*b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2031*b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2032*b7028ebfSSpencer Ku { 2033*b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 2034*b7028ebfSSpencer Ku return; 2035*b7028ebfSSpencer Ku } 2036*b7028ebfSSpencer Ku 2037*b7028ebfSSpencer Ku size_t logCount = 0; 2038*b7028ebfSSpencer Ku uint64_t top = 1; 2039*b7028ebfSSpencer Ku std::vector<std::string> logEntries; 2040*b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 2041*b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 2042*b7028ebfSSpencer Ku // get that entry 2043*b7028ebfSSpencer Ku if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, 2044*b7028ebfSSpencer Ku logEntries, logCount)) 2045*b7028ebfSSpencer Ku { 2046*b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2047*b7028ebfSSpencer Ku return; 2048*b7028ebfSSpencer Ku } 2049*b7028ebfSSpencer Ku 2050*b7028ebfSSpencer Ku if (!logEntries.empty()) 2051*b7028ebfSSpencer Ku { 2052*b7028ebfSSpencer Ku fillHostLoggerEntryJson(targetID, logEntries[0], 2053*b7028ebfSSpencer Ku asyncResp->res.jsonValue); 2054*b7028ebfSSpencer Ku return; 2055*b7028ebfSSpencer Ku } 2056*b7028ebfSSpencer Ku 2057*b7028ebfSSpencer Ku // Requested ID was not found 2058*b7028ebfSSpencer Ku messages::resourceMissingAtURI(asyncResp->res, targetID); 2059*b7028ebfSSpencer Ku }); 2060*b7028ebfSSpencer Ku } 2061*b7028ebfSSpencer Ku 20627e860f15SJohn Edward Broadbent inline void requestRoutesBMCLogServiceCollection(App& app) 20631da66f75SEd Tanous { 20647e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 2065ad89dcf0SGunnar Mills .privileges(redfish::privileges::getLogServiceCollection) 20667e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 20677e860f15SJohn Edward Broadbent [](const crow::Request&, 20687e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 20697e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 20707e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2071e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 20721da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2073e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 2074e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 20757e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 20767e860f15SJohn Edward Broadbent "Open BMC Log Services Collection"; 2077e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 20781da66f75SEd Tanous "Collection of LogServices for this Manager"; 20797e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 20807e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 2081c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 20825cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 20835cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 20847e860f15SJohn Edward Broadbent {{"@odata.id", 20857e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 20865cb1dd27SAsmitha Karunanithi #endif 2087c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 2088c4bf6374SJason M. Bills logServiceArray.push_back( 20897e860f15SJohn Edward Broadbent {{"@odata.id", 20907e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 2091c4bf6374SJason M. Bills #endif 2092e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2093c4bf6374SJason M. Bills logServiceArray.size(); 20947e860f15SJohn Edward Broadbent }); 2095e1f26343SJason M. Bills } 2096e1f26343SJason M. Bills 20977e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 2098e1f26343SJason M. Bills { 20997e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 2100ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 21017e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 21027e860f15SJohn Edward Broadbent [](const crow::Request&, 21037e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 21048d1b46d7Szhanghch05 21057e860f15SJohn Edward Broadbent { 2106e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2107e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 21080f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 21090f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 21107e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 21117e860f15SJohn Edward Broadbent "Open BMC Journal Log Service"; 21127e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 21137e860f15SJohn Edward Broadbent "BMC Journal Log Service"; 2114c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 2115e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 21167c8c4058STejas Patil 21177c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 21187c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 21197c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 21207c8c4058STejas Patil redfishDateTimeOffset.first; 21217c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 21227c8c4058STejas Patil redfishDateTimeOffset.second; 21237c8c4058STejas Patil 2124cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2125cd50aa42SJason M. Bills {"@odata.id", 2126086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 21277e860f15SJohn Edward Broadbent }); 2128e1f26343SJason M. Bills } 2129e1f26343SJason M. Bills 2130c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 2131e1f26343SJason M. Bills sd_journal* journal, 2132c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 2133e1f26343SJason M. Bills { 2134e1f26343SJason M. Bills // Get the Log Entry contents 2135e1f26343SJason M. Bills int ret = 0; 2136e1f26343SJason M. Bills 2137a8fe54f0SJason M. Bills std::string message; 2138a8fe54f0SJason M. Bills std::string_view syslogID; 2139a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 2140a8fe54f0SJason M. Bills if (ret < 0) 2141a8fe54f0SJason M. Bills { 2142a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 2143a8fe54f0SJason M. Bills << strerror(-ret); 2144a8fe54f0SJason M. Bills } 2145a8fe54f0SJason M. Bills if (!syslogID.empty()) 2146a8fe54f0SJason M. Bills { 2147a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 2148a8fe54f0SJason M. Bills } 2149a8fe54f0SJason M. Bills 215039e77504SEd Tanous std::string_view msg; 215116428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 2152e1f26343SJason M. Bills if (ret < 0) 2153e1f26343SJason M. Bills { 2154e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 2155e1f26343SJason M. Bills return 1; 2156e1f26343SJason M. Bills } 2157a8fe54f0SJason M. Bills message += std::string(msg); 2158e1f26343SJason M. Bills 2159e1f26343SJason M. Bills // Get the severity from the PRIORITY field 2160271584abSEd Tanous long int severity = 8; // Default to an invalid priority 216116428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 2162e1f26343SJason M. Bills if (ret < 0) 2163e1f26343SJason M. Bills { 2164e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 2165e1f26343SJason M. Bills } 2166e1f26343SJason M. Bills 2167e1f26343SJason M. Bills // Get the Created time from the timestamp 216816428a1aSJason M. Bills std::string entryTimeStr; 216916428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 2170e1f26343SJason M. Bills { 217116428a1aSJason M. Bills return 1; 2172e1f26343SJason M. Bills } 2173e1f26343SJason M. Bills 2174e1f26343SJason M. Bills // Fill in the log entry with the gathered data 2175c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 2176647b3cdcSGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 2177c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 2178c4bf6374SJason M. Bills bmcJournalLogEntryID}, 2179e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 2180c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 2181a8fe54f0SJason M. Bills {"Message", std::move(message)}, 2182e1f26343SJason M. Bills {"EntryType", "Oem"}, 2183738c1e61SPatrick Williams {"Severity", severity <= 2 ? "Critical" 2184738c1e61SPatrick Williams : severity <= 4 ? "Warning" 2185738c1e61SPatrick Williams : "OK"}, 2186086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 2187e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 2188e1f26343SJason M. Bills return 0; 2189e1f26343SJason M. Bills } 2190e1f26343SJason M. Bills 21917e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 2192e1f26343SJason M. Bills { 21937e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 2194ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 21957e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 21967e860f15SJohn Edward Broadbent [](const crow::Request& req, 21977e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2198193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 2199271584abSEd Tanous uint64_t skip = 0; 2200271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 22018d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 2202193ad2faSJason M. Bills { 2203193ad2faSJason M. Bills return; 2204193ad2faSJason M. Bills } 22058d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 2206193ad2faSJason M. Bills { 2207193ad2faSJason M. Bills return; 2208193ad2faSJason M. Bills } 22097e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 22107e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2211e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2212e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 22130f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 22140f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 2215e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 2216e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2217e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 22187e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 22197e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 2220e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2221e1f26343SJason M. Bills 22227e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 22237e860f15SJohn Edward Broadbent // unique ID for each entry 2224e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2225e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2226e1f26343SJason M. Bills if (ret < 0) 2227e1f26343SJason M. Bills { 22287e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 22297e860f15SJohn Edward Broadbent << strerror(-ret); 2230f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2231e1f26343SJason M. Bills return; 2232e1f26343SJason M. Bills } 22337e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 22347e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 2235e1f26343SJason M. Bills journalTmp = nullptr; 2236b01bf299SEd Tanous uint64_t entryCount = 0; 2237e85d6b16SJason M. Bills // Reset the unique ID on the first entry 2238e85d6b16SJason M. Bills bool firstEntry = true; 2239e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 2240e1f26343SJason M. Bills { 2241193ad2faSJason M. Bills entryCount++; 22427e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 22437e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 2244193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 2245193ad2faSJason M. Bills { 2246193ad2faSJason M. Bills continue; 2247193ad2faSJason M. Bills } 2248193ad2faSJason M. Bills 224916428a1aSJason M. Bills std::string idStr; 2250e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2251e1f26343SJason M. Bills { 2252e1f26343SJason M. Bills continue; 2253e1f26343SJason M. Bills } 2254e1f26343SJason M. Bills 2255e85d6b16SJason M. Bills if (firstEntry) 2256e85d6b16SJason M. Bills { 2257e85d6b16SJason M. Bills firstEntry = false; 2258e85d6b16SJason M. Bills } 2259e85d6b16SJason M. Bills 2260e1f26343SJason M. Bills logEntryArray.push_back({}); 2261c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 2262c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 2263c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 2264e1f26343SJason M. Bills { 2265f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2266e1f26343SJason M. Bills return; 2267e1f26343SJason M. Bills } 2268e1f26343SJason M. Bills } 2269193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 2270193ad2faSJason M. Bills if (skip + top < entryCount) 2271193ad2faSJason M. Bills { 2272193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 22737e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/" 22747e860f15SJohn Edward Broadbent "Entries?$skip=" + 2275193ad2faSJason M. Bills std::to_string(skip + top); 2276193ad2faSJason M. Bills } 22777e860f15SJohn Edward Broadbent }); 2278e1f26343SJason M. Bills } 2279e1f26343SJason M. Bills 22807e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 2281e1f26343SJason M. Bills { 22827e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 22837e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 2284ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 22857e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22867e860f15SJohn Edward Broadbent [](const crow::Request&, 22877e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22887e860f15SJohn Edward Broadbent const std::string& entryID) { 2289e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2290e1f26343SJason M. Bills uint64_t ts = 0; 2291271584abSEd Tanous uint64_t index = 0; 22928d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2293e1f26343SJason M. Bills { 229416428a1aSJason M. Bills return; 2295e1f26343SJason M. Bills } 2296e1f26343SJason M. Bills 2297e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2298e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2299e1f26343SJason M. Bills if (ret < 0) 2300e1f26343SJason M. Bills { 23017e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 23027e860f15SJohn Edward Broadbent << strerror(-ret); 2303f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2304e1f26343SJason M. Bills return; 2305e1f26343SJason M. Bills } 23067e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 23077e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 2308e1f26343SJason M. Bills journalTmp = nullptr; 23097e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 23107e860f15SJohn Edward Broadbent // index tracking the unique ID 2311af07e3f5SJason M. Bills std::string idStr; 2312af07e3f5SJason M. Bills bool firstEntry = true; 2313e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 23142056b6d1SManojkiran Eda if (ret < 0) 23152056b6d1SManojkiran Eda { 23162056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 23172056b6d1SManojkiran Eda << strerror(-ret); 23182056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 23192056b6d1SManojkiran Eda return; 23202056b6d1SManojkiran Eda } 2321271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2322e1f26343SJason M. Bills { 2323e1f26343SJason M. Bills sd_journal_next(journal.get()); 2324af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2325af07e3f5SJason M. Bills { 2326af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2327af07e3f5SJason M. Bills return; 2328af07e3f5SJason M. Bills } 2329af07e3f5SJason M. Bills if (firstEntry) 2330af07e3f5SJason M. Bills { 2331af07e3f5SJason M. Bills firstEntry = false; 2332af07e3f5SJason M. Bills } 2333e1f26343SJason M. Bills } 2334c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2335af07e3f5SJason M. Bills if (idStr != entryID) 2336c4bf6374SJason M. Bills { 2337c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 2338c4bf6374SJason M. Bills return; 2339c4bf6374SJason M. Bills } 2340c4bf6374SJason M. Bills 2341c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 2342e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 2343e1f26343SJason M. Bills { 2344f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2345e1f26343SJason M. Bills return; 2346e1f26343SJason M. Bills } 23477e860f15SJohn Edward Broadbent }); 2348c9bb6861Sraviteja-b } 2349c9bb6861Sraviteja-b 23507e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpService(App& app) 2351c9bb6861Sraviteja-b { 23527e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2353ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 23547e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 23557e860f15SJohn Edward Broadbent [](const crow::Request&, 23567e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2357c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 23585cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 2359c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2360d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 2361c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 23625cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 23635cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2364c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 23657c8c4058STejas Patil 23667c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 23677c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 23687c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 23697c8c4058STejas Patil redfishDateTimeOffset.first; 23707c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 23717c8c4058STejas Patil redfishDateTimeOffset.second; 23727c8c4058STejas Patil 2373c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 23747e860f15SJohn Edward Broadbent {"@odata.id", 23757e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}}; 23765cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 23775cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 23785cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 23795cb1dd27SAsmitha Karunanithi "Actions/LogService.ClearLog"}}}, 2380d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 2381d337bb72SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 2382d337bb72SAsmitha Karunanithi "Actions/LogService.CollectDiagnosticData"}}}}; 23837e860f15SJohn Edward Broadbent }); 2384c9bb6861Sraviteja-b } 2385c9bb6861Sraviteja-b 23867e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntryCollection(App& app) 23877e860f15SJohn Edward Broadbent { 23887e860f15SJohn Edward Broadbent 2389c9bb6861Sraviteja-b /** 2390c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2391c9bb6861Sraviteja-b */ 23927e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2393ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 23947e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 23957e860f15SJohn Edward Broadbent [](const crow::Request&, 23967e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2397c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2398c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2399c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 24005cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 24015cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2402c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 24035cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2404c9bb6861Sraviteja-b 24055cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 24067e860f15SJohn Edward Broadbent }); 2407c9bb6861Sraviteja-b } 2408c9bb6861Sraviteja-b 24097e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2410c9bb6861Sraviteja-b { 24117e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24127e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2413ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 24147e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24157e860f15SJohn Edward Broadbent [](const crow::Request&, 24167e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24177e860f15SJohn Edward Broadbent const std::string& param) { 24187e860f15SJohn Edward Broadbent getDumpEntryById(asyncResp, param, "BMC"); 24197e860f15SJohn Edward Broadbent }); 24207e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24217e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2422ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 24237e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 24247e860f15SJohn Edward Broadbent [](const crow::Request&, 24257e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24267e860f15SJohn Edward Broadbent const std::string& param) { 24277e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "bmc"); 24287e860f15SJohn Edward Broadbent }); 2429c9bb6861Sraviteja-b } 2430c9bb6861Sraviteja-b 24317e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2432c9bb6861Sraviteja-b { 24338d1b46d7Szhanghch05 24347e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 2435d337bb72SAsmitha Karunanithi "Actions/" 2436d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2437ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 24387e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 24397e860f15SJohn Edward Broadbent [](const crow::Request& req, 24407e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24418d1b46d7Szhanghch05 createDump(asyncResp, req, "BMC"); 24427e860f15SJohn Edward Broadbent }); 2443a43be80fSAsmitha Karunanithi } 2444a43be80fSAsmitha Karunanithi 24457e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 244680319af1SAsmitha Karunanithi { 24477e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 244880319af1SAsmitha Karunanithi "Actions/" 244980319af1SAsmitha Karunanithi "LogService.ClearLog/") 2450ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 24517e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 24527e860f15SJohn Edward Broadbent [](const crow::Request&, 24537e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24548d1b46d7Szhanghch05 clearDump(asyncResp, "BMC"); 24557e860f15SJohn Edward Broadbent }); 24565cb1dd27SAsmitha Karunanithi } 24575cb1dd27SAsmitha Karunanithi 24587e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 24595cb1dd27SAsmitha Karunanithi { 24607e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/") 2461ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 24627e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24637e860f15SJohn Edward Broadbent [](const crow::Request&, 24647e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 24655cb1dd27SAsmitha Karunanithi 24667e860f15SJohn Edward Broadbent { 24675cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 24685cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 24695cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2470d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 24715cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 24727e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 24737e860f15SJohn Edward Broadbent "System Dump LogService"; 24745cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 24755cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 24767c8c4058STejas Patil 24777c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 24787c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 24797c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 24807c8c4058STejas Patil redfishDateTimeOffset.first; 24817c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 24827c8c4058STejas Patil redfishDateTimeOffset.second; 24837c8c4058STejas Patil 24845cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Entries"] = { 24855cb1dd27SAsmitha Karunanithi {"@odata.id", 24865cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"}}; 24875cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 24885cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 24897e860f15SJohn Edward Broadbent {{"target", 24907e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 24915cb1dd27SAsmitha Karunanithi "LogService.ClearLog"}}}, 2492d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 24937e860f15SJohn Edward Broadbent {{"target", 24947e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 2495d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData"}}}}; 24967e860f15SJohn Edward Broadbent }); 24975cb1dd27SAsmitha Karunanithi } 24985cb1dd27SAsmitha Karunanithi 24997e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 25007e860f15SJohn Edward Broadbent { 25017e860f15SJohn Edward Broadbent 25025cb1dd27SAsmitha Karunanithi /** 25035cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 25045cb1dd27SAsmitha Karunanithi */ 2505b2a3289dSAsmitha Karunanithi BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 2506ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 25077e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 25087e860f15SJohn Edward Broadbent [](const crow::Request&, 2509864d6a17SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 25105cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 25115cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 25125cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 25135cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 25145cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 25155cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 25165cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 25175cb1dd27SAsmitha Karunanithi 25185cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 25197e860f15SJohn Edward Broadbent }); 25205cb1dd27SAsmitha Karunanithi } 25215cb1dd27SAsmitha Karunanithi 25227e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 25235cb1dd27SAsmitha Karunanithi { 25247e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2525864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2526ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2527ed398213SEd Tanous 25287e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 25297e860f15SJohn Edward Broadbent [](const crow::Request&, 25307e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25317e860f15SJohn Edward Broadbent const std::string& param) { 25327e860f15SJohn Edward Broadbent getDumpEntryById(asyncResp, param, "System"); 25337e860f15SJohn Edward Broadbent }); 25348d1b46d7Szhanghch05 25357e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2536864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2537ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 25387e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 25397e860f15SJohn Edward Broadbent [](const crow::Request&, 25407e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25417e860f15SJohn Edward Broadbent const std::string& param) { 25427e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "system"); 25437e860f15SJohn Edward Broadbent }); 25445cb1dd27SAsmitha Karunanithi } 2545c9bb6861Sraviteja-b 25467e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2547c9bb6861Sraviteja-b { 25487e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2549d337bb72SAsmitha Karunanithi "Actions/" 2550d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2551ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 25527e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 25537e860f15SJohn Edward Broadbent [](const crow::Request& req, 25547e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 25557e860f15SJohn Edward Broadbent 25567e860f15SJohn Edward Broadbent { createDump(asyncResp, req, "System"); }); 2557a43be80fSAsmitha Karunanithi } 2558a43be80fSAsmitha Karunanithi 25597e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2560a43be80fSAsmitha Karunanithi { 25617e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2562013487e5Sraviteja-b "Actions/" 2563013487e5Sraviteja-b "LogService.ClearLog/") 2564ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 25657e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 25667e860f15SJohn Edward Broadbent [](const crow::Request&, 25677e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 25687e860f15SJohn Edward Broadbent 25697e860f15SJohn Edward Broadbent { clearDump(asyncResp, "System"); }); 2570013487e5Sraviteja-b } 2571013487e5Sraviteja-b 25727e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 25731da66f75SEd Tanous { 25743946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25753946028dSAppaRao Puli // method for security reasons. 25761da66f75SEd Tanous /** 25771da66f75SEd Tanous * Functions triggers appropriate requests on DBus 25781da66f75SEd Tanous */ 25797e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 2580ed398213SEd Tanous // This is incorrect, should be: 2581ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2582432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 25837e860f15SJohn Edward Broadbent .methods( 25847e860f15SJohn Edward Broadbent boost::beast::http::verb:: 25857e860f15SJohn Edward Broadbent get)([](const crow::Request&, 25867e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 25877e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 25887e860f15SJohn Edward Broadbent // SubRoute 25890f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2590424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2591e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 25928e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 25934f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 25944f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 25954f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2596e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2597e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 25987c8c4058STejas Patil 25997c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 26007c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 26017c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 26027c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 26037c8c4058STejas Patil redfishDateTimeOffset.second; 26047c8c4058STejas Patil 2605cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2606cd50aa42SJason M. Bills {"@odata.id", 2607424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 2608e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 26095b61b5e8SJason M. Bills {"#LogService.ClearLog", 26105b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 26115b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 26128e6c099aSJason M. Bills {"#LogService.CollectDiagnosticData", 2613424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 26148e6c099aSJason M. Bills "Actions/LogService.CollectDiagnosticData"}}}}; 26157e860f15SJohn Edward Broadbent }); 26161da66f75SEd Tanous } 26171da66f75SEd Tanous 26187e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 26195b61b5e8SJason M. Bills { 26207e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 26217e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 26225b61b5e8SJason M. Bills "LogService.ClearLog/") 2623ed398213SEd Tanous // This is incorrect, should be: 2624ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2625432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 26267e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 26277e860f15SJohn Edward Broadbent [](const crow::Request&, 26287e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26295b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 26305b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2631cb13a392SEd Tanous const std::string&) { 26325b61b5e8SJason M. Bills if (ec) 26335b61b5e8SJason M. Bills { 26345b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 26355b61b5e8SJason M. Bills return; 26365b61b5e8SJason M. Bills } 26375b61b5e8SJason M. Bills messages::success(asyncResp->res); 26385b61b5e8SJason M. Bills }, 26397e860f15SJohn Edward Broadbent crashdumpObject, crashdumpPath, deleteAllInterface, 26407e860f15SJohn Edward Broadbent "DeleteAll"); 26417e860f15SJohn Edward Broadbent }); 26425b61b5e8SJason M. Bills } 26435b61b5e8SJason M. Bills 26448d1b46d7Szhanghch05 static void 26458d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26468d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 2647e855dd28SJason M. Bills { 2648043a0536SJohnathan Mantey auto getStoredLogCallback = 2649043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 2650e855dd28SJason M. Bills const boost::system::error_code ec, 2651043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params) { 2652e855dd28SJason M. Bills if (ec) 2653e855dd28SJason M. Bills { 2654e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 26551ddcf01aSJason M. Bills if (ec.value() == 26561ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 26571ddcf01aSJason M. Bills { 2658043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2659043a0536SJohnathan Mantey logID); 26601ddcf01aSJason M. Bills } 26611ddcf01aSJason M. Bills else 26621ddcf01aSJason M. Bills { 2663e855dd28SJason M. Bills messages::internalError(asyncResp->res); 26641ddcf01aSJason M. Bills } 2665e855dd28SJason M. Bills return; 2666e855dd28SJason M. Bills } 2667043a0536SJohnathan Mantey 2668043a0536SJohnathan Mantey std::string timestamp{}; 2669043a0536SJohnathan Mantey std::string filename{}; 2670043a0536SJohnathan Mantey std::string logfile{}; 26712c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2672043a0536SJohnathan Mantey 2673043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2674e855dd28SJason M. Bills { 2675043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 2676e855dd28SJason M. Bills return; 2677e855dd28SJason M. Bills } 2678e855dd28SJason M. Bills 2679043a0536SJohnathan Mantey std::string crashdumpURI = 2680e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2681043a0536SJohnathan Mantey logID + "/" + filename; 2682d0dbeefdSEd Tanous logEntryJson = {{"@odata.type", "#LogEntry.v1_7_0.LogEntry"}, 2683043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 2684043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 2685e855dd28SJason M. Bills logID}, 2686e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2687e855dd28SJason M. Bills {"Id", logID}, 2688e855dd28SJason M. Bills {"EntryType", "Oem"}, 26898e6c099aSJason M. Bills {"AdditionalDataURI", std::move(crashdumpURI)}, 26908e6c099aSJason M. Bills {"DiagnosticDataType", "OEM"}, 26918e6c099aSJason M. Bills {"OEMDiagnosticDataType", "PECICrashdump"}, 2692043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2693e855dd28SJason M. Bills }; 2694e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 26955b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 26965b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2697043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2698e855dd28SJason M. Bills } 2699e855dd28SJason M. Bills 27007e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 27011da66f75SEd Tanous { 27023946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 27033946028dSAppaRao Puli // method for security reasons. 27041da66f75SEd Tanous /** 27051da66f75SEd Tanous * Functions triggers appropriate requests on DBus 27061da66f75SEd Tanous */ 27077e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 27087e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 2709ed398213SEd Tanous // This is incorrect, should be. 2710ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 2711432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 27127e860f15SJohn Edward Broadbent .methods( 27137e860f15SJohn Edward Broadbent boost::beast::http::verb:: 27147e860f15SJohn Edward Broadbent get)([](const crow::Request&, 27157e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 27167e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 27177e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2718e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2719e1f26343SJason M. Bills const boost::system::error_code ec, 27207e860f15SJohn Edward Broadbent const std::vector<std::string>& 27217e860f15SJohn Edward Broadbent resp) { 27221da66f75SEd Tanous if (ec) 27231da66f75SEd Tanous { 27241da66f75SEd Tanous if (ec.value() != 27251da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 27261da66f75SEd Tanous { 27271da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 27281da66f75SEd Tanous << ec.message(); 2729f12894f8SJason M. Bills messages::internalError(asyncResp->res); 27301da66f75SEd Tanous return; 27311da66f75SEd Tanous } 27321da66f75SEd Tanous } 2733e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 27341da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 27350f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2736424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2737424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2738e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2739424c4176SJason M. Bills "Collection of Crashdump Entries"; 27407e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 27417e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 2742e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2743e855dd28SJason M. Bills std::vector<std::string> logIDs; 2744e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2745e855dd28SJason M. Bills // enough to hold them 27461da66f75SEd Tanous for (const std::string& objpath : resp) 27471da66f75SEd Tanous { 2748e855dd28SJason M. Bills // Get the log ID 2749f23b7296SEd Tanous std::size_t lastPos = objpath.rfind('/'); 2750e855dd28SJason M. Bills if (lastPos == std::string::npos) 27511da66f75SEd Tanous { 2752e855dd28SJason M. Bills continue; 27531da66f75SEd Tanous } 2754e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2755e855dd28SJason M. Bills 2756e855dd28SJason M. Bills // Add a space for the log entry to the array 2757e855dd28SJason M. Bills logEntryArray.push_back({}); 2758e855dd28SJason M. Bills } 2759e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2760e855dd28SJason M. Bills size_t index = 0; 2761e855dd28SJason M. Bills for (const std::string& logID : logIDs) 2762e855dd28SJason M. Bills { 2763e855dd28SJason M. Bills // Add the log entry to the array 2764e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 27651da66f75SEd Tanous } 2766e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2767e1f26343SJason M. Bills logEntryArray.size(); 27681da66f75SEd Tanous }; 27691da66f75SEd Tanous crow::connections::systemBus->async_method_call( 27701da66f75SEd Tanous std::move(getLogEntriesCallback), 27711da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 27721da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 27731da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 27745b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 27757e860f15SJohn Edward Broadbent }); 27761da66f75SEd Tanous } 27771da66f75SEd Tanous 27787e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 27791da66f75SEd Tanous { 27803946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 27813946028dSAppaRao Puli // method for security reasons. 27821da66f75SEd Tanous 27837e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 27847e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/") 2785ed398213SEd Tanous // this is incorrect, should be 2786ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 2787432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 27887e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 27897e860f15SJohn Edward Broadbent [](const crow::Request&, 27907e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 27917e860f15SJohn Edward Broadbent const std::string& param) { 27927e860f15SJohn Edward Broadbent const std::string& logID = param; 2793e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 27947e860f15SJohn Edward Broadbent }); 2795e855dd28SJason M. Bills } 2796e855dd28SJason M. Bills 27977e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 2798e855dd28SJason M. Bills { 27993946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28003946028dSAppaRao Puli // method for security reasons. 28017e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 28027e860f15SJohn Edward Broadbent app, 28037e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/") 2804ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 28057e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 28067e860f15SJohn Edward Broadbent [](const crow::Request&, 28077e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 28087e860f15SJohn Edward Broadbent const std::string& logID, const std::string& fileName) { 2809043a0536SJohnathan Mantey auto getStoredLogCallback = 2810043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 2811abf2add6SEd Tanous const boost::system::error_code ec, 28127e860f15SJohn Edward Broadbent const std::vector<std::pair<std::string, VariantType>>& 28137e860f15SJohn Edward Broadbent resp) { 28141da66f75SEd Tanous if (ec) 28151da66f75SEd Tanous { 2816043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2817043a0536SJohnathan Mantey << ec.message(); 2818f12894f8SJason M. Bills messages::internalError(asyncResp->res); 28191da66f75SEd Tanous return; 28201da66f75SEd Tanous } 2821e855dd28SJason M. Bills 2822043a0536SJohnathan Mantey std::string dbusFilename{}; 2823043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2824043a0536SJohnathan Mantey std::string dbusFilepath{}; 2825043a0536SJohnathan Mantey 28267e860f15SJohn Edward Broadbent parseCrashdumpParameters(resp, dbusFilename, 28277e860f15SJohn Edward Broadbent dbusTimestamp, dbusFilepath); 2828043a0536SJohnathan Mantey 2829043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2830043a0536SJohnathan Mantey dbusFilepath.empty()) 28311da66f75SEd Tanous { 28327e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 28337e860f15SJohn Edward Broadbent fileName); 28341da66f75SEd Tanous return; 28351da66f75SEd Tanous } 2836e855dd28SJason M. Bills 2837043a0536SJohnathan Mantey // Verify the file name parameter is correct 2838043a0536SJohnathan Mantey if (fileName != dbusFilename) 2839043a0536SJohnathan Mantey { 28407e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 28417e860f15SJohn Edward Broadbent fileName); 2842043a0536SJohnathan Mantey return; 2843043a0536SJohnathan Mantey } 2844043a0536SJohnathan Mantey 2845043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2846043a0536SJohnathan Mantey { 28477e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 28487e860f15SJohn Edward Broadbent fileName); 2849043a0536SJohnathan Mantey return; 2850043a0536SJohnathan Mantey } 2851043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 2852043a0536SJohnathan Mantey std::ios::binary | 2853043a0536SJohnathan Mantey std::ios::ate); 2854043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 2855043a0536SJohnathan Mantey if (fileSize < 0) 2856043a0536SJohnathan Mantey { 2857043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 2858043a0536SJohnathan Mantey return; 2859043a0536SJohnathan Mantey } 2860043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 2861043a0536SJohnathan Mantey 2862043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 2863043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 2864043a0536SJohnathan Mantey 2865043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 2866043a0536SJohnathan Mantey 28677e860f15SJohn Edward Broadbent // The cast to std::string is intentional in order to 28687e860f15SJohn Edward Broadbent // use the assign() that applies move mechanics 2869043a0536SJohnathan Mantey asyncResp->res.body().assign( 2870043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 2871043a0536SJohnathan Mantey 28727e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 28737e860f15SJohn Edward Broadbent // from a browser 28747e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Disposition", 28757e860f15SJohn Edward Broadbent "attachment"); 28761da66f75SEd Tanous }; 28771da66f75SEd Tanous crow::connections::systemBus->async_method_call( 28785b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 28795b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 28807e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 28817e860f15SJohn Edward Broadbent crashdumpInterface); 28827e860f15SJohn Edward Broadbent }); 28831da66f75SEd Tanous } 28841da66f75SEd Tanous 28857e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 28861da66f75SEd Tanous { 28873946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28883946028dSAppaRao Puli // method for security reasons. 28897e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/" 28907e860f15SJohn Edward Broadbent "Actions/LogService.CollectDiagnosticData/") 2891ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 2892ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2893432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 28947e860f15SJohn Edward Broadbent .methods( 28957e860f15SJohn Edward Broadbent boost::beast::http::verb:: 28967e860f15SJohn Edward Broadbent post)([](const crow::Request& req, 28977e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 28988e6c099aSJason M. Bills std::string diagnosticDataType; 28998e6c099aSJason M. Bills std::string oemDiagnosticDataType; 29008e6c099aSJason M. Bills if (!redfish::json_util::readJson( 29017e860f15SJohn Edward Broadbent req, asyncResp->res, "DiagnosticDataType", 29027e860f15SJohn Edward Broadbent diagnosticDataType, "OEMDiagnosticDataType", 29037e860f15SJohn Edward Broadbent oemDiagnosticDataType)) 29048e6c099aSJason M. Bills { 29058e6c099aSJason M. Bills return; 29068e6c099aSJason M. Bills } 29078e6c099aSJason M. Bills 29088e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 29098e6c099aSJason M. Bills { 29108e6c099aSJason M. Bills BMCWEB_LOG_ERROR 29118e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 29128e6c099aSJason M. Bills messages::actionParameterValueFormatError( 29138e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 29148e6c099aSJason M. Bills "CollectDiagnosticData"); 29158e6c099aSJason M. Bills return; 29168e6c099aSJason M. Bills } 29178e6c099aSJason M. Bills 29188e6c099aSJason M. Bills auto collectCrashdumpCallback = [asyncResp, req]( 29197e860f15SJohn Edward Broadbent const boost::system::error_code 29207e860f15SJohn Edward Broadbent ec, 2921cb13a392SEd Tanous const std::string&) { 29221da66f75SEd Tanous if (ec) 29231da66f75SEd Tanous { 29247e860f15SJohn Edward Broadbent if (ec.value() == 29257e860f15SJohn Edward Broadbent boost::system::errc::operation_not_supported) 29261da66f75SEd Tanous { 2927f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 29281da66f75SEd Tanous } 29294363d3b2SJason M. Bills else if (ec.value() == 29304363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 29314363d3b2SJason M. Bills { 29324363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 29334363d3b2SJason M. Bills "60"); 29344363d3b2SJason M. Bills } 29351da66f75SEd Tanous else 29361da66f75SEd Tanous { 2937f12894f8SJason M. Bills messages::internalError(asyncResp->res); 29381da66f75SEd Tanous } 29391da66f75SEd Tanous return; 29401da66f75SEd Tanous } 29417e860f15SJohn Edward Broadbent std::shared_ptr<task::TaskData> task = 29427e860f15SJohn Edward Broadbent task::TaskData::createTask( 29437e860f15SJohn Edward Broadbent [](boost::system::error_code err, 29447e860f15SJohn Edward Broadbent sdbusplus::message::message&, 294566afe4faSJames Feist const std::shared_ptr<task::TaskData>& taskData) { 294666afe4faSJames Feist if (!err) 294766afe4faSJames Feist { 2948e5d5006bSJames Feist taskData->messages.emplace_back( 2949e5d5006bSJames Feist messages::taskCompletedOK( 2950e5d5006bSJames Feist std::to_string(taskData->index))); 2951831d6b09SJames Feist taskData->state = "Completed"; 295266afe4faSJames Feist } 295332898ceaSJames Feist return task::completed; 295466afe4faSJames Feist }, 29557e860f15SJohn Edward Broadbent "type='signal',interface='org.freedesktop.DBus." 29567e860f15SJohn Edward Broadbent "Properties'," 295746229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 295846229577SJames Feist "crashdump'"); 295946229577SJames Feist task->startTimer(std::chrono::minutes(5)); 296046229577SJames Feist task->populateResp(asyncResp->res); 2961fe306728SJames Feist task->payload.emplace(req); 29621da66f75SEd Tanous }; 29638e6c099aSJason M. Bills 29648e6c099aSJason M. Bills if (oemDiagnosticDataType == "OnDemand") 29658e6c099aSJason M. Bills { 29661da66f75SEd Tanous crow::connections::systemBus->async_method_call( 29678e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 29688e6c099aSJason M. Bills crashdumpPath, crashdumpOnDemandInterface, 29698e6c099aSJason M. Bills "GenerateOnDemandLog"); 29701da66f75SEd Tanous } 29718e6c099aSJason M. Bills else if (oemDiagnosticDataType == "Telemetry") 29726eda7685SKenny L. Ku { 29738e6c099aSJason M. Bills crow::connections::systemBus->async_method_call( 29748e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 29758e6c099aSJason M. Bills crashdumpPath, crashdumpTelemetryInterface, 29768e6c099aSJason M. Bills "GenerateTelemetryLog"); 29776eda7685SKenny L. Ku } 29786eda7685SKenny L. Ku else 29796eda7685SKenny L. Ku { 29808e6c099aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 29818e6c099aSJason M. Bills << oemDiagnosticDataType; 29828e6c099aSJason M. Bills messages::actionParameterValueFormatError( 29837e860f15SJohn Edward Broadbent asyncResp->res, oemDiagnosticDataType, 29847e860f15SJohn Edward Broadbent "OEMDiagnosticDataType", "CollectDiagnosticData"); 29856eda7685SKenny L. Ku return; 29866eda7685SKenny L. Ku } 29877e860f15SJohn Edward Broadbent }); 29886eda7685SKenny L. Ku } 29896eda7685SKenny L. Ku 2990cb92c03bSAndrew Geissler /** 2991cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2992cb92c03bSAndrew Geissler */ 29937e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 2994cb92c03bSAndrew Geissler { 2995cb92c03bSAndrew Geissler /** 2996cb92c03bSAndrew Geissler * Function handles POST method request. 2997cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 2998cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 2999cb92c03bSAndrew Geissler */ 30007e860f15SJohn Edward Broadbent 30017e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 30027e860f15SJohn Edward Broadbent "LogService.ClearLog/") 3003ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 30047e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 30057e860f15SJohn Edward Broadbent [](const crow::Request&, 30067e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3007cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 3008cb92c03bSAndrew Geissler 3009cb92c03bSAndrew Geissler // Process response from Logging service. 30107e860f15SJohn Edward Broadbent auto respHandler = [asyncResp]( 30117e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 30127e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 30137e860f15SJohn Edward Broadbent << "doClearLog resp_handler callback: Done"; 3014cb92c03bSAndrew Geissler if (ec) 3015cb92c03bSAndrew Geissler { 3016cb92c03bSAndrew Geissler // TODO Handle for specific error code 30177e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " 30187e860f15SJohn Edward Broadbent << ec; 3019cb92c03bSAndrew Geissler asyncResp->res.result( 3020cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3021cb92c03bSAndrew Geissler return; 3022cb92c03bSAndrew Geissler } 3023cb92c03bSAndrew Geissler 30247e860f15SJohn Edward Broadbent asyncResp->res.result( 30257e860f15SJohn Edward Broadbent boost::beast::http::status::no_content); 3026cb92c03bSAndrew Geissler }; 3027cb92c03bSAndrew Geissler 3028cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3029cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 30302c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 3031cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3032cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 30337e860f15SJohn Edward Broadbent }); 3034cb92c03bSAndrew Geissler } 3035a3316fc6SZhikuiRen 3036a3316fc6SZhikuiRen /**************************************************** 3037a3316fc6SZhikuiRen * Redfish PostCode interfaces 3038a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3039a3316fc6SZhikuiRen ******************************************************/ 30407e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 3041a3316fc6SZhikuiRen { 30427e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 3043ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 30447e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 30457e860f15SJohn Edward Broadbent [](const crow::Request&, 30467e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3047a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 30487e860f15SJohn Edward Broadbent {"@odata.id", 30497e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes"}, 3050a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 3051a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 3052a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 3053a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 3054a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 3055a3316fc6SZhikuiRen {"Entries", 30567e860f15SJohn Edward Broadbent {{"@odata.id", "/redfish/v1/Systems/system/LogServices/" 30577e860f15SJohn Edward Broadbent "PostCodes/Entries"}}}}; 30587c8c4058STejas Patil 30597c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 30607c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 30617c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 30627c8c4058STejas Patil redfishDateTimeOffset.first; 30637c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 30647c8c4058STejas Patil redfishDateTimeOffset.second; 30657c8c4058STejas Patil 3066a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 30677e860f15SJohn Edward Broadbent {"target", 30687e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/" 3069a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 30707e860f15SJohn Edward Broadbent }); 3071a3316fc6SZhikuiRen } 3072a3316fc6SZhikuiRen 30737e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3074a3316fc6SZhikuiRen { 30757e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 30767e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 3077a3316fc6SZhikuiRen "LogService.ClearLog/") 3078ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3079ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3080432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 30817e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 30827e860f15SJohn Edward Broadbent [](const crow::Request&, 30837e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3084a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3085a3316fc6SZhikuiRen 3086a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3087a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3088a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3089a3316fc6SZhikuiRen if (ec) 3090a3316fc6SZhikuiRen { 3091a3316fc6SZhikuiRen // TODO Handle for specific error code 3092a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 30937e860f15SJohn Edward Broadbent << "doClearPostCodes resp_handler got error " 30947e860f15SJohn Edward Broadbent << ec; 30957e860f15SJohn Edward Broadbent asyncResp->res.result(boost::beast::http::status:: 30967e860f15SJohn Edward Broadbent internal_server_error); 3097a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3098a3316fc6SZhikuiRen return; 3099a3316fc6SZhikuiRen } 3100a3316fc6SZhikuiRen }, 310115124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 310215124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3103a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 31047e860f15SJohn Edward Broadbent }); 3105a3316fc6SZhikuiRen } 3106a3316fc6SZhikuiRen 3107a3316fc6SZhikuiRen static void fillPostCodeEntry( 31088d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 31096c9a279eSManojkiran Eda const boost::container::flat_map< 31106c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3111a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3112a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3113a3316fc6SZhikuiRen { 3114a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3115a3316fc6SZhikuiRen const message_registries::Message* message = 31164a0bf539SManojkiran Eda message_registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3117a3316fc6SZhikuiRen 3118a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3119a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 3120a3316fc6SZhikuiRen 3121a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 31226c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 31236c9a279eSManojkiran Eda code : postcode) 3124a3316fc6SZhikuiRen { 3125a3316fc6SZhikuiRen currentCodeIndex++; 3126a3316fc6SZhikuiRen std::string postcodeEntryID = 3127a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3128a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3129a3316fc6SZhikuiRen 3130a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3131a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3132a3316fc6SZhikuiRen 3133a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3134a3316fc6SZhikuiRen { // already incremented 3135a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3136a3316fc6SZhikuiRen } 3137a3316fc6SZhikuiRen else 3138a3316fc6SZhikuiRen { 3139a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3140a3316fc6SZhikuiRen } 3141a3316fc6SZhikuiRen 3142a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3143a3316fc6SZhikuiRen // not fall between top and skip 3144a3316fc6SZhikuiRen if ((codeIndex == 0) && 3145a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3146a3316fc6SZhikuiRen { 3147a3316fc6SZhikuiRen continue; 3148a3316fc6SZhikuiRen } 3149a3316fc6SZhikuiRen 31504e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3151a3316fc6SZhikuiRen // currentIndex 3152a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3153a3316fc6SZhikuiRen { 3154a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3155a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3156a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3157a3316fc6SZhikuiRen continue; 3158a3316fc6SZhikuiRen } 3159a3316fc6SZhikuiRen 3160a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3161a3316fc6SZhikuiRen // index 3162a3316fc6SZhikuiRen 3163a3316fc6SZhikuiRen // Get the Created time from the timestamp 3164a3316fc6SZhikuiRen std::string entryTimeStr; 31659c620e21SAsmitha Karunanithi entryTimeStr = crow::utility::getDateTime( 31669c620e21SAsmitha Karunanithi static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000)); 3167a3316fc6SZhikuiRen 3168a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3169a3316fc6SZhikuiRen std::ostringstream hexCode; 3170a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 31716c9a279eSManojkiran Eda << std::get<0>(code.second); 3172a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3173a3316fc6SZhikuiRen // Set Fixed -Point Notation 3174a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3175a3316fc6SZhikuiRen // Set precision to 4 digits 3176a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3177a3316fc6SZhikuiRen // Add double to stream 3178a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3179a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3180a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3181a3316fc6SZhikuiRen 3182a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3183a3316fc6SZhikuiRen std::string msg; 3184a3316fc6SZhikuiRen if (message != nullptr) 3185a3316fc6SZhikuiRen { 3186a3316fc6SZhikuiRen msg = message->message; 3187a3316fc6SZhikuiRen 3188a3316fc6SZhikuiRen // fill in this post code value 3189a3316fc6SZhikuiRen int i = 0; 3190a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3191a3316fc6SZhikuiRen { 3192a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3193a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3194a3316fc6SZhikuiRen if (argPos != std::string::npos) 3195a3316fc6SZhikuiRen { 3196a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3197a3316fc6SZhikuiRen } 3198a3316fc6SZhikuiRen } 3199a3316fc6SZhikuiRen } 3200a3316fc6SZhikuiRen 3201d4342a92STim Lee // Get Severity template from message registry 3202d4342a92STim Lee std::string severity; 3203d4342a92STim Lee if (message != nullptr) 3204d4342a92STim Lee { 3205d4342a92STim Lee severity = message->severity; 3206d4342a92STim Lee } 3207d4342a92STim Lee 3208a3316fc6SZhikuiRen // add to AsyncResp 3209a3316fc6SZhikuiRen logEntryArray.push_back({}); 3210a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 3211647b3cdcSGeorge Liu bmcLogEntry = {{"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 3212a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 3213a3316fc6SZhikuiRen "PostCodes/Entries/" + 3214a3316fc6SZhikuiRen postcodeEntryID}, 3215a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 3216a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 3217a3316fc6SZhikuiRen {"Message", std::move(msg)}, 32184a0bf539SManojkiran Eda {"MessageId", "OpenBMC.0.2.BIOSPOSTCode"}, 3219a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 3220a3316fc6SZhikuiRen {"EntryType", "Event"}, 3221a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 32229c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 3223647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 3224647b3cdcSGeorge Liu { 3225647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 3226647b3cdcSGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3227647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 3228647b3cdcSGeorge Liu } 3229a3316fc6SZhikuiRen } 3230a3316fc6SZhikuiRen } 3231a3316fc6SZhikuiRen 32328d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3233a3316fc6SZhikuiRen const uint16_t bootIndex, 3234a3316fc6SZhikuiRen const uint64_t codeIndex) 3235a3316fc6SZhikuiRen { 3236a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 32376c9a279eSManojkiran Eda [aResp, bootIndex, 32386c9a279eSManojkiran Eda codeIndex](const boost::system::error_code ec, 32396c9a279eSManojkiran Eda const boost::container::flat_map< 32406c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 32416c9a279eSManojkiran Eda postcode) { 3242a3316fc6SZhikuiRen if (ec) 3243a3316fc6SZhikuiRen { 3244a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3245a3316fc6SZhikuiRen messages::internalError(aResp->res); 3246a3316fc6SZhikuiRen return; 3247a3316fc6SZhikuiRen } 3248a3316fc6SZhikuiRen 3249a3316fc6SZhikuiRen // skip the empty postcode boots 3250a3316fc6SZhikuiRen if (postcode.empty()) 3251a3316fc6SZhikuiRen { 3252a3316fc6SZhikuiRen return; 3253a3316fc6SZhikuiRen } 3254a3316fc6SZhikuiRen 3255a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3256a3316fc6SZhikuiRen 3257a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3258a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3259a3316fc6SZhikuiRen }, 326015124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 326115124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3262a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3263a3316fc6SZhikuiRen bootIndex); 3264a3316fc6SZhikuiRen } 3265a3316fc6SZhikuiRen 32668d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3267a3316fc6SZhikuiRen const uint16_t bootIndex, 3268a3316fc6SZhikuiRen const uint16_t bootCount, 3269a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 3270a3316fc6SZhikuiRen const uint64_t top) 3271a3316fc6SZhikuiRen { 3272a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3273a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3274a3316fc6SZhikuiRen top](const boost::system::error_code ec, 32756c9a279eSManojkiran Eda const boost::container::flat_map< 32766c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 32776c9a279eSManojkiran Eda postcode) { 3278a3316fc6SZhikuiRen if (ec) 3279a3316fc6SZhikuiRen { 3280a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3281a3316fc6SZhikuiRen messages::internalError(aResp->res); 3282a3316fc6SZhikuiRen return; 3283a3316fc6SZhikuiRen } 3284a3316fc6SZhikuiRen 3285a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3286a3316fc6SZhikuiRen if (!postcode.empty()) 3287a3316fc6SZhikuiRen { 3288a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 3289a3316fc6SZhikuiRen 3290a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3291a3316fc6SZhikuiRen { 3292a3316fc6SZhikuiRen uint64_t thisBootSkip = 3293a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3294a3316fc6SZhikuiRen uint64_t thisBootTop = 3295a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3296a3316fc6SZhikuiRen 3297a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3298a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3299a3316fc6SZhikuiRen } 3300a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3301a3316fc6SZhikuiRen } 3302a3316fc6SZhikuiRen 3303a3316fc6SZhikuiRen // continue to previous bootIndex 3304a3316fc6SZhikuiRen if (bootIndex < bootCount) 3305a3316fc6SZhikuiRen { 3306a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3307a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3308a3316fc6SZhikuiRen } 3309a3316fc6SZhikuiRen else 3310a3316fc6SZhikuiRen { 3311a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 3312a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3313a3316fc6SZhikuiRen "Entries?$skip=" + 3314a3316fc6SZhikuiRen std::to_string(skip + top); 3315a3316fc6SZhikuiRen } 3316a3316fc6SZhikuiRen }, 331715124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 331815124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3319a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3320a3316fc6SZhikuiRen bootIndex); 3321a3316fc6SZhikuiRen } 3322a3316fc6SZhikuiRen 33238d1b46d7Szhanghch05 static void 33248d1b46d7Szhanghch05 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3325a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3326a3316fc6SZhikuiRen { 3327a3316fc6SZhikuiRen uint64_t entryCount = 0; 3328a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3329a3316fc6SZhikuiRen [aResp, entryCount, skip, 3330a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3331a3316fc6SZhikuiRen const std::variant<uint16_t>& bootCount) { 3332a3316fc6SZhikuiRen if (ec) 3333a3316fc6SZhikuiRen { 3334a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3335a3316fc6SZhikuiRen messages::internalError(aResp->res); 3336a3316fc6SZhikuiRen return; 3337a3316fc6SZhikuiRen } 3338a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 3339a3316fc6SZhikuiRen if (pVal) 3340a3316fc6SZhikuiRen { 3341a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 3342a3316fc6SZhikuiRen } 3343a3316fc6SZhikuiRen else 3344a3316fc6SZhikuiRen { 3345a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 3346a3316fc6SZhikuiRen } 3347a3316fc6SZhikuiRen }, 334815124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 334915124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3350a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 3351a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 3352a3316fc6SZhikuiRen } 3353a3316fc6SZhikuiRen 33547e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3355a3316fc6SZhikuiRen { 33567e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 33577e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3358ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 33597e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 33607e860f15SJohn Edward Broadbent [](const crow::Request& req, 33617e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3362a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3363a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3364a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3365a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3366a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3367a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3368a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3369a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3370a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3371a3316fc6SZhikuiRen 3372a3316fc6SZhikuiRen uint64_t skip = 0; 3373a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 33748d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 3375a3316fc6SZhikuiRen { 3376a3316fc6SZhikuiRen return; 3377a3316fc6SZhikuiRen } 33788d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 3379a3316fc6SZhikuiRen { 3380a3316fc6SZhikuiRen return; 3381a3316fc6SZhikuiRen } 3382a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 33837e860f15SJohn Edward Broadbent }); 3384a3316fc6SZhikuiRen } 3385a3316fc6SZhikuiRen 3386647b3cdcSGeorge Liu /** 3387647b3cdcSGeorge Liu * @brief Parse post code ID and get the current value and index value 3388647b3cdcSGeorge Liu * eg: postCodeID=B1-2, currentValue=1, index=2 3389647b3cdcSGeorge Liu * 3390647b3cdcSGeorge Liu * @param[in] postCodeID Post Code ID 3391647b3cdcSGeorge Liu * @param[out] currentValue Current value 3392647b3cdcSGeorge Liu * @param[out] index Index value 3393647b3cdcSGeorge Liu * 3394647b3cdcSGeorge Liu * @return bool true if the parsing is successful, false the parsing fails 3395647b3cdcSGeorge Liu */ 3396647b3cdcSGeorge Liu inline static bool parsePostCode(const std::string& postCodeID, 3397647b3cdcSGeorge Liu uint64_t& currentValue, uint16_t& index) 3398647b3cdcSGeorge Liu { 3399647b3cdcSGeorge Liu std::vector<std::string> split; 3400647b3cdcSGeorge Liu boost::algorithm::split(split, postCodeID, boost::is_any_of("-")); 3401647b3cdcSGeorge Liu if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B') 3402647b3cdcSGeorge Liu { 3403647b3cdcSGeorge Liu return false; 3404647b3cdcSGeorge Liu } 3405647b3cdcSGeorge Liu 3406647b3cdcSGeorge Liu const char* start = split[0].data() + 1; 3407647b3cdcSGeorge Liu const char* end = split[0].data() + split[0].size(); 3408647b3cdcSGeorge Liu auto [ptrIndex, ecIndex] = std::from_chars(start, end, index); 3409647b3cdcSGeorge Liu 3410647b3cdcSGeorge Liu if (ptrIndex != end || ecIndex != std::errc()) 3411647b3cdcSGeorge Liu { 3412647b3cdcSGeorge Liu return false; 3413647b3cdcSGeorge Liu } 3414647b3cdcSGeorge Liu 3415647b3cdcSGeorge Liu start = split[1].data(); 3416647b3cdcSGeorge Liu end = split[1].data() + split[1].size(); 3417647b3cdcSGeorge Liu auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue); 3418647b3cdcSGeorge Liu if (ptrValue != end || ecValue != std::errc()) 3419647b3cdcSGeorge Liu { 3420647b3cdcSGeorge Liu return false; 3421647b3cdcSGeorge Liu } 3422647b3cdcSGeorge Liu 3423647b3cdcSGeorge Liu return true; 3424647b3cdcSGeorge Liu } 3425647b3cdcSGeorge Liu 3426647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3427647b3cdcSGeorge Liu { 3428647b3cdcSGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/" 3429647b3cdcSGeorge Liu "Entries/<str>/attachment/") 3430647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 3431647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 3432647b3cdcSGeorge Liu [](const crow::Request& req, 3433647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3434647b3cdcSGeorge Liu const std::string& postCodeID) { 3435647b3cdcSGeorge Liu if (!http_helpers::isOctetAccepted( 3436647b3cdcSGeorge Liu req.getHeaderValue("Accept"))) 3437647b3cdcSGeorge Liu { 3438647b3cdcSGeorge Liu asyncResp->res.result( 3439647b3cdcSGeorge Liu boost::beast::http::status::bad_request); 3440647b3cdcSGeorge Liu return; 3441647b3cdcSGeorge Liu } 3442647b3cdcSGeorge Liu 3443647b3cdcSGeorge Liu uint64_t currentValue = 0; 3444647b3cdcSGeorge Liu uint16_t index = 0; 3445647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 3446647b3cdcSGeorge Liu { 3447647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", 3448647b3cdcSGeorge Liu postCodeID); 3449647b3cdcSGeorge Liu return; 3450647b3cdcSGeorge Liu } 3451647b3cdcSGeorge Liu 3452647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 3453647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 3454647b3cdcSGeorge Liu const boost::system::error_code ec, 3455647b3cdcSGeorge Liu const std::vector<std::tuple< 3456647b3cdcSGeorge Liu uint64_t, std::vector<uint8_t>>>& postcodes) { 3457647b3cdcSGeorge Liu if (ec.value() == EBADR) 3458647b3cdcSGeorge Liu { 3459647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3460647b3cdcSGeorge Liu "LogEntry", postCodeID); 3461647b3cdcSGeorge Liu return; 3462647b3cdcSGeorge Liu } 3463647b3cdcSGeorge Liu if (ec) 3464647b3cdcSGeorge Liu { 3465647b3cdcSGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3466647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 3467647b3cdcSGeorge Liu return; 3468647b3cdcSGeorge Liu } 3469647b3cdcSGeorge Liu 3470647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 3471647b3cdcSGeorge Liu if (value == std::string::npos || 3472647b3cdcSGeorge Liu postcodes.size() < currentValue) 3473647b3cdcSGeorge Liu { 3474647b3cdcSGeorge Liu BMCWEB_LOG_ERROR << "Wrong currentValue value"; 3475647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3476647b3cdcSGeorge Liu "LogEntry", postCodeID); 3477647b3cdcSGeorge Liu return; 3478647b3cdcSGeorge Liu } 3479647b3cdcSGeorge Liu 3480647b3cdcSGeorge Liu auto& [tID, code] = postcodes[value]; 3481647b3cdcSGeorge Liu if (code.empty()) 3482647b3cdcSGeorge Liu { 3483647b3cdcSGeorge Liu BMCWEB_LOG_INFO << "No found post code data"; 3484647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3485647b3cdcSGeorge Liu "LogEntry", postCodeID); 3486647b3cdcSGeorge Liu return; 3487647b3cdcSGeorge Liu } 3488647b3cdcSGeorge Liu 3489647b3cdcSGeorge Liu std::string_view strData( 3490647b3cdcSGeorge Liu reinterpret_cast<const char*>(code.data()), 3491647b3cdcSGeorge Liu code.size()); 3492647b3cdcSGeorge Liu 3493647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Type", 3494647b3cdcSGeorge Liu "application/octet-stream"); 3495647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Transfer-Encoding", 3496647b3cdcSGeorge Liu "Base64"); 3497647b3cdcSGeorge Liu asyncResp->res.body() = 3498647b3cdcSGeorge Liu crow::utility::base64encode(strData); 3499647b3cdcSGeorge Liu }, 3500647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 3501647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 3502647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", 3503647b3cdcSGeorge Liu index); 3504647b3cdcSGeorge Liu }); 3505647b3cdcSGeorge Liu } 3506647b3cdcSGeorge Liu 35077e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 3508a3316fc6SZhikuiRen { 35097e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 35107e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/") 3511ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 35127e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 35137e860f15SJohn Edward Broadbent [](const crow::Request&, 35147e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 35157e860f15SJohn Edward Broadbent const std::string& targetID) { 3516647b3cdcSGeorge Liu uint16_t bootIndex = 0; 3517647b3cdcSGeorge Liu uint64_t codeIndex = 0; 3518647b3cdcSGeorge Liu if (!parsePostCode(targetID, codeIndex, bootIndex)) 3519a3316fc6SZhikuiRen { 3520a3316fc6SZhikuiRen // Requested ID was not found 3521a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 3522a3316fc6SZhikuiRen return; 3523a3316fc6SZhikuiRen } 3524a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3525a3316fc6SZhikuiRen { 3526a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 35277e860f15SJohn Edward Broadbent << targetID; 3528a3316fc6SZhikuiRen } 3529a3316fc6SZhikuiRen 35307e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = 35317e860f15SJohn Edward Broadbent "#LogEntry.v1_4_0.LogEntry"; 3532a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3533a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3534a3316fc6SZhikuiRen "Entries"; 3535a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3536a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3537a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3538a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3539a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3540a3316fc6SZhikuiRen 3541a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 35427e860f15SJohn Edward Broadbent }); 3543a3316fc6SZhikuiRen } 3544a3316fc6SZhikuiRen 35451da66f75SEd Tanous } // namespace redfish 3546