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 18647b3cdcSGeorge Liu #include "http_utility.hpp" 194851d45dSJason M. Bills #include "registries.hpp" 204851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 214851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2246229577SJames Feist #include "task.hpp" 231da66f75SEd Tanous 24e1f26343SJason M. Bills #include <systemd/sd-journal.h> 25400fd1fbSAdriana Kobylak #include <unistd.h> 26e1f26343SJason M. Bills 277e860f15SJohn Edward Broadbent #include <app.hpp> 28400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 294851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 304851d45dSJason M. Bills #include <boost/beast/core/span.hpp> 31400fd1fbSAdriana Kobylak #include <boost/beast/http.hpp> 321da66f75SEd Tanous #include <boost/container/flat_map.hpp> 331ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 34cb92c03bSAndrew Geissler #include <error_messages.hpp> 35ed398213SEd Tanous #include <registries/privilege_registry.hpp> 361214b7e7SGunnar Mills 37647b3cdcSGeorge Liu #include <charconv> 384418c7f0SJames Feist #include <filesystem> 3975710de2SXiaochao Ma #include <optional> 40cd225da8SJason M. Bills #include <string_view> 41abf2add6SEd Tanous #include <variant> 421da66f75SEd Tanous 431da66f75SEd Tanous namespace redfish 441da66f75SEd Tanous { 451da66f75SEd Tanous 465b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 475b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 485b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 495b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 505b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 515b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 52424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 536eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 546eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 551da66f75SEd Tanous 564851d45dSJason M. Bills namespace message_registries 574851d45dSJason M. Bills { 584851d45dSJason M. Bills static const Message* getMessageFromRegistry( 594851d45dSJason M. Bills const std::string& messageKey, 604851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 614851d45dSJason M. Bills { 624851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 634851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 644851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 654851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 664851d45dSJason M. Bills messageKey.c_str()); 674851d45dSJason M. Bills }); 684851d45dSJason M. Bills if (messageIt != registry.cend()) 694851d45dSJason M. Bills { 704851d45dSJason M. Bills return &messageIt->second; 714851d45dSJason M. Bills } 724851d45dSJason M. Bills 734851d45dSJason M. Bills return nullptr; 744851d45dSJason M. Bills } 754851d45dSJason M. Bills 764851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 774851d45dSJason M. Bills { 784851d45dSJason M. Bills // Redfish MessageIds are in the form 794851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 804851d45dSJason M. Bills // the right Message 814851d45dSJason M. Bills std::vector<std::string> fields; 824851d45dSJason M. Bills fields.reserve(4); 834851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 844851d45dSJason M. Bills std::string& registryName = fields[0]; 854851d45dSJason M. Bills std::string& messageKey = fields[3]; 864851d45dSJason M. Bills 874851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 884851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 894851d45dSJason M. Bills { 904851d45dSJason M. Bills return getMessageFromRegistry( 914851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 924851d45dSJason M. Bills } 934851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 944851d45dSJason M. Bills { 954851d45dSJason M. Bills return getMessageFromRegistry( 964851d45dSJason M. Bills messageKey, 974851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 984851d45dSJason M. Bills } 994851d45dSJason M. Bills return nullptr; 1004851d45dSJason M. Bills } 1014851d45dSJason M. Bills } // namespace message_registries 1024851d45dSJason M. Bills 103f6150403SJames Feist namespace fs = std::filesystem; 1041da66f75SEd Tanous 105cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 10619bd78d9SPatrick Williams std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, 107cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 108cb92c03bSAndrew Geissler 109cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 110cb92c03bSAndrew Geissler sdbusplus::message::object_path, 111cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 112cb92c03bSAndrew Geissler 113cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 114cb92c03bSAndrew Geissler { 115d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 116d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 117d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 118d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 119cb92c03bSAndrew Geissler { 120cb92c03bSAndrew Geissler return "Critical"; 121cb92c03bSAndrew Geissler } 1223174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 123d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 124d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 125cb92c03bSAndrew Geissler { 126cb92c03bSAndrew Geissler return "OK"; 127cb92c03bSAndrew Geissler } 1283174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 129cb92c03bSAndrew Geissler { 130cb92c03bSAndrew Geissler return "Warning"; 131cb92c03bSAndrew Geissler } 132cb92c03bSAndrew Geissler return ""; 133cb92c03bSAndrew Geissler } 134cb92c03bSAndrew Geissler 1357e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 13639e77504SEd Tanous const std::string_view& field, 13739e77504SEd Tanous std::string_view& contents) 13816428a1aSJason M. Bills { 13916428a1aSJason M. Bills const char* data = nullptr; 14016428a1aSJason M. Bills size_t length = 0; 14116428a1aSJason M. Bills int ret = 0; 14216428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 143271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 144271584abSEd Tanous reinterpret_cast<const void**>(&data), &length); 14516428a1aSJason M. Bills if (ret < 0) 14616428a1aSJason M. Bills { 14716428a1aSJason M. Bills return ret; 14816428a1aSJason M. Bills } 14939e77504SEd Tanous contents = std::string_view(data, length); 15016428a1aSJason M. Bills // Only use the content after the "=" character. 15181ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 15216428a1aSJason M. Bills return ret; 15316428a1aSJason M. Bills } 15416428a1aSJason M. Bills 1557e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 1567e860f15SJohn Edward Broadbent const std::string_view& field, 1577e860f15SJohn Edward Broadbent const int& base, long int& contents) 15816428a1aSJason M. Bills { 15916428a1aSJason M. Bills int ret = 0; 16039e77504SEd Tanous std::string_view metadata; 16116428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 16216428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 16316428a1aSJason M. Bills if (ret < 0) 16416428a1aSJason M. Bills { 16516428a1aSJason M. Bills return ret; 16616428a1aSJason M. Bills } 167b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 16816428a1aSJason M. Bills return ret; 16916428a1aSJason M. Bills } 17016428a1aSJason M. Bills 1717e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1727e860f15SJohn Edward Broadbent std::string& entryTimestamp) 173a3316fc6SZhikuiRen { 174a3316fc6SZhikuiRen int ret = 0; 175a3316fc6SZhikuiRen uint64_t timestamp = 0; 176a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 177a3316fc6SZhikuiRen if (ret < 0) 178a3316fc6SZhikuiRen { 179a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 180a3316fc6SZhikuiRen << strerror(-ret); 181a3316fc6SZhikuiRen return false; 182a3316fc6SZhikuiRen } 1839c620e21SAsmitha Karunanithi entryTimestamp = crow::utility::getDateTime( 1849c620e21SAsmitha Karunanithi static_cast<std::time_t>(timestamp / 1000 / 1000)); 1859c620e21SAsmitha Karunanithi return true; 186a3316fc6SZhikuiRen } 187a3316fc6SZhikuiRen 1888d1b46d7Szhanghch05 static bool getSkipParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1898d1b46d7Szhanghch05 const crow::Request& req, uint64_t& skip) 19016428a1aSJason M. Bills { 191*d32c4fa9SEd Tanous boost::urls::query_params_view::iterator it = req.urlParams.find("$skip"); 1925a7e877eSJames Feist if (it != req.urlParams.end()) 19316428a1aSJason M. Bills { 1945a7e877eSJames Feist std::string skipParam = it->value(); 19516428a1aSJason M. Bills char* ptr = nullptr; 1965a7e877eSJames Feist skip = std::strtoul(skipParam.c_str(), &ptr, 10); 1975a7e877eSJames Feist if (skipParam.empty() || *ptr != '\0') 19816428a1aSJason M. Bills { 19916428a1aSJason M. Bills 2008d1b46d7Szhanghch05 messages::queryParameterValueTypeError( 2018d1b46d7Szhanghch05 asyncResp->res, std::string(skipParam), "$skip"); 20216428a1aSJason M. Bills return false; 20316428a1aSJason M. Bills } 20416428a1aSJason M. Bills } 20516428a1aSJason M. Bills return true; 20616428a1aSJason M. Bills } 20716428a1aSJason M. Bills 208271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 2098d1b46d7Szhanghch05 static bool getTopParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2108d1b46d7Szhanghch05 const crow::Request& req, uint64_t& top) 21116428a1aSJason M. Bills { 212*d32c4fa9SEd Tanous boost::urls::query_params_view::iterator it = req.urlParams.find("$top"); 2135a7e877eSJames Feist if (it != req.urlParams.end()) 21416428a1aSJason M. Bills { 2155a7e877eSJames Feist std::string topParam = it->value(); 21616428a1aSJason M. Bills char* ptr = nullptr; 2175a7e877eSJames Feist top = std::strtoul(topParam.c_str(), &ptr, 10); 2185a7e877eSJames Feist if (topParam.empty() || *ptr != '\0') 21916428a1aSJason M. Bills { 2208d1b46d7Szhanghch05 messages::queryParameterValueTypeError( 2218d1b46d7Szhanghch05 asyncResp->res, std::string(topParam), "$top"); 22216428a1aSJason M. Bills return false; 22316428a1aSJason M. Bills } 224271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 22516428a1aSJason M. Bills { 22616428a1aSJason M. Bills 22716428a1aSJason M. Bills messages::queryParameterOutOfRange( 2288d1b46d7Szhanghch05 asyncResp->res, std::to_string(top), "$top", 22916428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 23016428a1aSJason M. Bills return false; 23116428a1aSJason M. Bills } 23216428a1aSJason M. Bills } 23316428a1aSJason M. Bills return true; 23416428a1aSJason M. Bills } 23516428a1aSJason M. Bills 2367e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 237e85d6b16SJason M. Bills const bool firstEntry = true) 23816428a1aSJason M. Bills { 23916428a1aSJason M. Bills int ret = 0; 24016428a1aSJason M. Bills static uint64_t prevTs = 0; 24116428a1aSJason M. Bills static int index = 0; 242e85d6b16SJason M. Bills if (firstEntry) 243e85d6b16SJason M. Bills { 244e85d6b16SJason M. Bills prevTs = 0; 245e85d6b16SJason M. Bills } 246e85d6b16SJason M. Bills 24716428a1aSJason M. Bills // Get the entry timestamp 24816428a1aSJason M. Bills uint64_t curTs = 0; 24916428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 25016428a1aSJason M. Bills if (ret < 0) 25116428a1aSJason M. Bills { 25216428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 25316428a1aSJason M. Bills << strerror(-ret); 25416428a1aSJason M. Bills return false; 25516428a1aSJason M. Bills } 25616428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 25716428a1aSJason M. Bills if (curTs == prevTs) 25816428a1aSJason M. Bills { 25916428a1aSJason M. Bills index++; 26016428a1aSJason M. Bills } 26116428a1aSJason M. Bills else 26216428a1aSJason M. Bills { 26316428a1aSJason M. Bills // Otherwise, reset it 26416428a1aSJason M. Bills index = 0; 26516428a1aSJason M. Bills } 26616428a1aSJason M. Bills // Save the timestamp 26716428a1aSJason M. Bills prevTs = curTs; 26816428a1aSJason M. Bills 26916428a1aSJason M. Bills entryID = std::to_string(curTs); 27016428a1aSJason M. Bills if (index > 0) 27116428a1aSJason M. Bills { 27216428a1aSJason M. Bills entryID += "_" + std::to_string(index); 27316428a1aSJason M. Bills } 27416428a1aSJason M. Bills return true; 27516428a1aSJason M. Bills } 27616428a1aSJason M. Bills 277e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 278e85d6b16SJason M. Bills const bool firstEntry = true) 27995820184SJason M. Bills { 280271584abSEd Tanous static time_t prevTs = 0; 28195820184SJason M. Bills static int index = 0; 282e85d6b16SJason M. Bills if (firstEntry) 283e85d6b16SJason M. Bills { 284e85d6b16SJason M. Bills prevTs = 0; 285e85d6b16SJason M. Bills } 286e85d6b16SJason M. Bills 28795820184SJason M. Bills // Get the entry timestamp 288271584abSEd Tanous std::time_t curTs = 0; 28995820184SJason M. Bills std::tm timeStruct = {}; 29095820184SJason M. Bills std::istringstream entryStream(logEntry); 29195820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 29295820184SJason M. Bills { 29395820184SJason M. Bills curTs = std::mktime(&timeStruct); 29495820184SJason M. Bills } 29595820184SJason M. Bills // If the timestamp isn't unique, increment the index 29695820184SJason M. Bills if (curTs == prevTs) 29795820184SJason M. Bills { 29895820184SJason M. Bills index++; 29995820184SJason M. Bills } 30095820184SJason M. Bills else 30195820184SJason M. Bills { 30295820184SJason M. Bills // Otherwise, reset it 30395820184SJason M. Bills index = 0; 30495820184SJason M. Bills } 30595820184SJason M. Bills // Save the timestamp 30695820184SJason M. Bills prevTs = curTs; 30795820184SJason M. Bills 30895820184SJason M. Bills entryID = std::to_string(curTs); 30995820184SJason M. Bills if (index > 0) 31095820184SJason M. Bills { 31195820184SJason M. Bills entryID += "_" + std::to_string(index); 31295820184SJason M. Bills } 31395820184SJason M. Bills return true; 31495820184SJason M. Bills } 31595820184SJason M. Bills 3167e860f15SJohn Edward Broadbent inline static bool 3178d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3188d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 3198d1b46d7Szhanghch05 uint64_t& index) 32016428a1aSJason M. Bills { 32116428a1aSJason M. Bills if (entryID.empty()) 32216428a1aSJason M. Bills { 32316428a1aSJason M. Bills return false; 32416428a1aSJason M. Bills } 32516428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 32639e77504SEd Tanous std::string_view tsStr(entryID); 32716428a1aSJason M. Bills 32881ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 32916428a1aSJason M. Bills if (underscorePos != tsStr.npos) 33016428a1aSJason M. Bills { 33116428a1aSJason M. Bills // Timestamp has an index 33216428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 33339e77504SEd Tanous std::string_view indexStr(entryID); 33416428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 335c0bd5e4bSEd Tanous auto [ptr, ec] = std::from_chars( 336c0bd5e4bSEd Tanous indexStr.data(), indexStr.data() + indexStr.size(), index); 337c0bd5e4bSEd Tanous if (ec != std::errc()) 33816428a1aSJason M. Bills { 3398d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 34016428a1aSJason M. Bills return false; 34116428a1aSJason M. Bills } 34216428a1aSJason M. Bills } 34316428a1aSJason M. Bills // Timestamp has no index 344c0bd5e4bSEd Tanous auto [ptr, ec] = 345c0bd5e4bSEd Tanous std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp); 346c0bd5e4bSEd Tanous if (ec != std::errc()) 34716428a1aSJason M. Bills { 3488d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 34916428a1aSJason M. Bills return false; 35016428a1aSJason M. Bills } 35116428a1aSJason M. Bills return true; 35216428a1aSJason M. Bills } 35316428a1aSJason M. Bills 35495820184SJason M. Bills static bool 35595820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 35695820184SJason M. Bills { 35795820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 35895820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 35995820184SJason M. Bills 36095820184SJason M. Bills // Loop through the directory looking for redfish log files 36195820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 36295820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 36395820184SJason M. Bills { 36495820184SJason M. Bills // If we find a redfish log file, save the path 36595820184SJason M. Bills std::string filename = dirEnt.path().filename(); 36695820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 36795820184SJason M. Bills { 36895820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 36995820184SJason M. Bills } 37095820184SJason M. Bills } 37195820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 37295820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 37395820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 37495820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 37595820184SJason M. Bills 37695820184SJason M. Bills return !redfishLogFiles.empty(); 37795820184SJason M. Bills } 37895820184SJason M. Bills 3798d1b46d7Szhanghch05 inline void 3808d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3815cb1dd27SAsmitha Karunanithi const std::string& dumpType) 3825cb1dd27SAsmitha Karunanithi { 3835cb1dd27SAsmitha Karunanithi std::string dumpPath; 3845cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 3855cb1dd27SAsmitha Karunanithi { 3865cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 3875cb1dd27SAsmitha Karunanithi } 3885cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 3895cb1dd27SAsmitha Karunanithi { 3905cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 3915cb1dd27SAsmitha Karunanithi } 3925cb1dd27SAsmitha Karunanithi else 3935cb1dd27SAsmitha Karunanithi { 3945cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 3955cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 3965cb1dd27SAsmitha Karunanithi return; 3975cb1dd27SAsmitha Karunanithi } 3985cb1dd27SAsmitha Karunanithi 3995cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 4005cb1dd27SAsmitha Karunanithi [asyncResp, dumpPath, dumpType](const boost::system::error_code ec, 4015cb1dd27SAsmitha Karunanithi GetManagedObjectsType& resp) { 4025cb1dd27SAsmitha Karunanithi if (ec) 4035cb1dd27SAsmitha Karunanithi { 4045cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4055cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4065cb1dd27SAsmitha Karunanithi return; 4075cb1dd27SAsmitha Karunanithi } 4085cb1dd27SAsmitha Karunanithi 4095cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4105cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 411b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 412b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 413b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 414b47452b2SAsmitha Karunanithi "/entry/"; 4155cb1dd27SAsmitha Karunanithi 4165cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4175cb1dd27SAsmitha Karunanithi { 418b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 4195cb1dd27SAsmitha Karunanithi { 4205cb1dd27SAsmitha Karunanithi continue; 4215cb1dd27SAsmitha Karunanithi } 4225cb1dd27SAsmitha Karunanithi std::time_t timestamp; 4235cb1dd27SAsmitha Karunanithi uint64_t size = 0; 42435440d18SAsmitha Karunanithi std::string dumpStatus; 42535440d18SAsmitha Karunanithi nlohmann::json thisEntry; 4262dfd18efSEd Tanous 4272dfd18efSEd Tanous std::string entryID = object.first.filename(); 4282dfd18efSEd Tanous if (entryID.empty()) 4295cb1dd27SAsmitha Karunanithi { 4305cb1dd27SAsmitha Karunanithi continue; 4315cb1dd27SAsmitha Karunanithi } 4325cb1dd27SAsmitha Karunanithi 4335cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4345cb1dd27SAsmitha Karunanithi { 43535440d18SAsmitha Karunanithi if (interfaceMap.first == 43635440d18SAsmitha Karunanithi "xyz.openbmc_project.Common.Progress") 43735440d18SAsmitha Karunanithi { 43835440d18SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 43935440d18SAsmitha Karunanithi { 44035440d18SAsmitha Karunanithi if (propertyMap.first == "Status") 44135440d18SAsmitha Karunanithi { 44235440d18SAsmitha Karunanithi auto status = std::get_if<std::string>( 44335440d18SAsmitha Karunanithi &propertyMap.second); 44435440d18SAsmitha Karunanithi if (status == nullptr) 44535440d18SAsmitha Karunanithi { 44635440d18SAsmitha Karunanithi messages::internalError(asyncResp->res); 44735440d18SAsmitha Karunanithi break; 44835440d18SAsmitha Karunanithi } 44935440d18SAsmitha Karunanithi dumpStatus = *status; 45035440d18SAsmitha Karunanithi } 45135440d18SAsmitha Karunanithi } 45235440d18SAsmitha Karunanithi } 45335440d18SAsmitha Karunanithi else if (interfaceMap.first == 45435440d18SAsmitha Karunanithi "xyz.openbmc_project.Dump.Entry") 4555cb1dd27SAsmitha Karunanithi { 4565cb1dd27SAsmitha Karunanithi 4575cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4585cb1dd27SAsmitha Karunanithi { 4595cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4605cb1dd27SAsmitha Karunanithi { 4615cb1dd27SAsmitha Karunanithi auto sizePtr = 4625cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4635cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4645cb1dd27SAsmitha Karunanithi { 4655cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4665cb1dd27SAsmitha Karunanithi break; 4675cb1dd27SAsmitha Karunanithi } 4685cb1dd27SAsmitha Karunanithi size = *sizePtr; 4695cb1dd27SAsmitha Karunanithi break; 4705cb1dd27SAsmitha Karunanithi } 4715cb1dd27SAsmitha Karunanithi } 4725cb1dd27SAsmitha Karunanithi } 4735cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4745cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 4755cb1dd27SAsmitha Karunanithi { 4765cb1dd27SAsmitha Karunanithi 4775cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4785cb1dd27SAsmitha Karunanithi { 4795cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 4805cb1dd27SAsmitha Karunanithi { 4815cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 4825cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4835cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 4845cb1dd27SAsmitha Karunanithi { 4855cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4865cb1dd27SAsmitha Karunanithi break; 4875cb1dd27SAsmitha Karunanithi } 4885cb1dd27SAsmitha Karunanithi timestamp = 4895cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 4905cb1dd27SAsmitha Karunanithi break; 4915cb1dd27SAsmitha Karunanithi } 4925cb1dd27SAsmitha Karunanithi } 4935cb1dd27SAsmitha Karunanithi } 4945cb1dd27SAsmitha Karunanithi } 4955cb1dd27SAsmitha Karunanithi 49635440d18SAsmitha Karunanithi if (dumpStatus != "xyz.openbmc_project.Common.Progress." 49735440d18SAsmitha Karunanithi "OperationStatus.Completed" && 49835440d18SAsmitha Karunanithi !dumpStatus.empty()) 49935440d18SAsmitha Karunanithi { 50035440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 50135440d18SAsmitha Karunanithi continue; 50235440d18SAsmitha Karunanithi } 50335440d18SAsmitha Karunanithi 504647b3cdcSGeorge Liu thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 5055cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 5065cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 5075cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5085cb1dd27SAsmitha Karunanithi thisEntry["Created"] = crow::utility::getDateTime(timestamp); 5095cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 5105cb1dd27SAsmitha Karunanithi 511d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataSizeBytes"] = size; 5125cb1dd27SAsmitha Karunanithi 5135cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5145cb1dd27SAsmitha Karunanithi { 515d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 516d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 517de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 518de8d94a3SAbhishek Patel entryID + "/attachment"; 5195cb1dd27SAsmitha Karunanithi } 5205cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5215cb1dd27SAsmitha Karunanithi { 522d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 523d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 524d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 525de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 526de8d94a3SAbhishek Patel entryID + "/attachment"; 5275cb1dd27SAsmitha Karunanithi } 52835440d18SAsmitha Karunanithi entriesArray.push_back(std::move(thisEntry)); 5295cb1dd27SAsmitha Karunanithi } 5305cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 5315cb1dd27SAsmitha Karunanithi entriesArray.size(); 5325cb1dd27SAsmitha Karunanithi }, 5335cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5345cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5355cb1dd27SAsmitha Karunanithi } 5365cb1dd27SAsmitha Karunanithi 5378d1b46d7Szhanghch05 inline void 5388d1b46d7Szhanghch05 getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5398d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 5405cb1dd27SAsmitha Karunanithi { 5415cb1dd27SAsmitha Karunanithi std::string dumpPath; 5425cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5435cb1dd27SAsmitha Karunanithi { 5445cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5455cb1dd27SAsmitha Karunanithi } 5465cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5475cb1dd27SAsmitha Karunanithi { 5485cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5495cb1dd27SAsmitha Karunanithi } 5505cb1dd27SAsmitha Karunanithi else 5515cb1dd27SAsmitha Karunanithi { 5525cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5535cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5545cb1dd27SAsmitha Karunanithi return; 5555cb1dd27SAsmitha Karunanithi } 5565cb1dd27SAsmitha Karunanithi 5575cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 5585cb1dd27SAsmitha Karunanithi [asyncResp, entryID, dumpPath, dumpType]( 5595cb1dd27SAsmitha Karunanithi const boost::system::error_code ec, GetManagedObjectsType& resp) { 5605cb1dd27SAsmitha Karunanithi if (ec) 5615cb1dd27SAsmitha Karunanithi { 5625cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5635cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5645cb1dd27SAsmitha Karunanithi return; 5655cb1dd27SAsmitha Karunanithi } 5665cb1dd27SAsmitha Karunanithi 567b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 568b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 569b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 570b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 571b47452b2SAsmitha Karunanithi "/entry/"; 572b47452b2SAsmitha Karunanithi 5735cb1dd27SAsmitha Karunanithi for (auto& objectPath : resp) 5745cb1dd27SAsmitha Karunanithi { 575b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5765cb1dd27SAsmitha Karunanithi { 5775cb1dd27SAsmitha Karunanithi continue; 5785cb1dd27SAsmitha Karunanithi } 5795cb1dd27SAsmitha Karunanithi 5805cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 5815cb1dd27SAsmitha Karunanithi std::time_t timestamp; 5825cb1dd27SAsmitha Karunanithi uint64_t size = 0; 58335440d18SAsmitha Karunanithi std::string dumpStatus; 5845cb1dd27SAsmitha Karunanithi 5855cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 5865cb1dd27SAsmitha Karunanithi { 58735440d18SAsmitha Karunanithi if (interfaceMap.first == 58835440d18SAsmitha Karunanithi "xyz.openbmc_project.Common.Progress") 58935440d18SAsmitha Karunanithi { 59035440d18SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 59135440d18SAsmitha Karunanithi { 59235440d18SAsmitha Karunanithi if (propertyMap.first == "Status") 59335440d18SAsmitha Karunanithi { 59435440d18SAsmitha Karunanithi auto status = std::get_if<std::string>( 59535440d18SAsmitha Karunanithi &propertyMap.second); 59635440d18SAsmitha Karunanithi if (status == nullptr) 59735440d18SAsmitha Karunanithi { 59835440d18SAsmitha Karunanithi messages::internalError(asyncResp->res); 59935440d18SAsmitha Karunanithi break; 60035440d18SAsmitha Karunanithi } 60135440d18SAsmitha Karunanithi dumpStatus = *status; 60235440d18SAsmitha Karunanithi } 60335440d18SAsmitha Karunanithi } 60435440d18SAsmitha Karunanithi } 60535440d18SAsmitha Karunanithi else if (interfaceMap.first == 60635440d18SAsmitha Karunanithi "xyz.openbmc_project.Dump.Entry") 6075cb1dd27SAsmitha Karunanithi { 6085cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6095cb1dd27SAsmitha Karunanithi { 6105cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 6115cb1dd27SAsmitha Karunanithi { 6125cb1dd27SAsmitha Karunanithi auto sizePtr = 6135cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6145cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 6155cb1dd27SAsmitha Karunanithi { 6165cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6175cb1dd27SAsmitha Karunanithi break; 6185cb1dd27SAsmitha Karunanithi } 6195cb1dd27SAsmitha Karunanithi size = *sizePtr; 6205cb1dd27SAsmitha Karunanithi break; 6215cb1dd27SAsmitha Karunanithi } 6225cb1dd27SAsmitha Karunanithi } 6235cb1dd27SAsmitha Karunanithi } 6245cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 6255cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 6265cb1dd27SAsmitha Karunanithi { 6275cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6285cb1dd27SAsmitha Karunanithi { 6295cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 6305cb1dd27SAsmitha Karunanithi { 6315cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 6325cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6335cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 6345cb1dd27SAsmitha Karunanithi { 6355cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6365cb1dd27SAsmitha Karunanithi break; 6375cb1dd27SAsmitha Karunanithi } 6385cb1dd27SAsmitha Karunanithi timestamp = 6395cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 6405cb1dd27SAsmitha Karunanithi break; 6415cb1dd27SAsmitha Karunanithi } 6425cb1dd27SAsmitha Karunanithi } 6435cb1dd27SAsmitha Karunanithi } 6445cb1dd27SAsmitha Karunanithi } 6455cb1dd27SAsmitha Karunanithi 64635440d18SAsmitha Karunanithi if (dumpStatus != "xyz.openbmc_project.Common.Progress." 64735440d18SAsmitha Karunanithi "OperationStatus.Completed" && 64835440d18SAsmitha Karunanithi !dumpStatus.empty()) 64935440d18SAsmitha Karunanithi { 65035440d18SAsmitha Karunanithi // Dump status is not Complete 65135440d18SAsmitha Karunanithi // return not found until status is changed to Completed 65235440d18SAsmitha Karunanithi messages::resourceNotFound(asyncResp->res, 65335440d18SAsmitha Karunanithi dumpType + " dump", entryID); 65435440d18SAsmitha Karunanithi return; 65535440d18SAsmitha Karunanithi } 65635440d18SAsmitha Karunanithi 6575cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 658647b3cdcSGeorge Liu "#LogEntry.v1_8_0.LogEntry"; 6595cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6605cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6615cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6625cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6635cb1dd27SAsmitha Karunanithi crow::utility::getDateTime(timestamp); 6645cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6655cb1dd27SAsmitha Karunanithi 666d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6675cb1dd27SAsmitha Karunanithi 6685cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6695cb1dd27SAsmitha Karunanithi { 670d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 671d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 672de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 673de8d94a3SAbhishek Patel entryID + "/attachment"; 6745cb1dd27SAsmitha Karunanithi } 6755cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6765cb1dd27SAsmitha Karunanithi { 677d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 678d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["OEMDiagnosticDataType"] = 6795cb1dd27SAsmitha Karunanithi "System"; 680d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 681de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 682de8d94a3SAbhishek Patel entryID + "/attachment"; 6835cb1dd27SAsmitha Karunanithi } 6845cb1dd27SAsmitha Karunanithi } 685b47452b2SAsmitha Karunanithi if (foundDumpEntry == false) 686b47452b2SAsmitha Karunanithi { 687b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 688b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 689b47452b2SAsmitha Karunanithi return; 690b47452b2SAsmitha Karunanithi } 6915cb1dd27SAsmitha Karunanithi }, 6925cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6935cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6945cb1dd27SAsmitha Karunanithi } 6955cb1dd27SAsmitha Karunanithi 6968d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6979878256fSStanley Chu const std::string& entryID, 698b47452b2SAsmitha Karunanithi const std::string& dumpType) 6995cb1dd27SAsmitha Karunanithi { 7003de8d8baSGeorge Liu auto respHandler = [asyncResp, 7013de8d8baSGeorge Liu entryID](const boost::system::error_code ec) { 7025cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 7035cb1dd27SAsmitha Karunanithi if (ec) 7045cb1dd27SAsmitha Karunanithi { 7053de8d8baSGeorge Liu if (ec.value() == EBADR) 7063de8d8baSGeorge Liu { 7073de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 7083de8d8baSGeorge Liu return; 7093de8d8baSGeorge Liu } 7105cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 7115cb1dd27SAsmitha Karunanithi << ec; 7125cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 7135cb1dd27SAsmitha Karunanithi return; 7145cb1dd27SAsmitha Karunanithi } 7155cb1dd27SAsmitha Karunanithi }; 7165cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 7175cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 718b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 719b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 720b47452b2SAsmitha Karunanithi entryID, 7215cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 7225cb1dd27SAsmitha Karunanithi } 7235cb1dd27SAsmitha Karunanithi 7248d1b46d7Szhanghch05 inline void 7258d1b46d7Szhanghch05 createDumpTaskCallback(const crow::Request& req, 7268d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7278d1b46d7Szhanghch05 const uint32_t& dumpId, const std::string& dumpPath, 728a43be80fSAsmitha Karunanithi const std::string& dumpType) 729a43be80fSAsmitha Karunanithi { 730a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 7316145ed6fSAsmitha Karunanithi [dumpId, dumpPath, dumpType]( 732a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 733a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 734cb13a392SEd Tanous if (err) 735cb13a392SEd Tanous { 7366145ed6fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Error in creating a dump"; 7376145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 7386145ed6fSAsmitha Karunanithi return task::completed; 739cb13a392SEd Tanous } 740a43be80fSAsmitha Karunanithi std::vector<std::pair< 741a43be80fSAsmitha Karunanithi std::string, 742a43be80fSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string>>>>> 743a43be80fSAsmitha Karunanithi interfacesList; 744a43be80fSAsmitha Karunanithi 745a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 746a43be80fSAsmitha Karunanithi 747a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 748a43be80fSAsmitha Karunanithi 749b47452b2SAsmitha Karunanithi if (objPath.str == 750b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 751b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 752b47452b2SAsmitha Karunanithi "/entry/" + std::to_string(dumpId)) 753a43be80fSAsmitha Karunanithi { 754a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 755a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 756a43be80fSAsmitha Karunanithi 757a43be80fSAsmitha Karunanithi std::string headerLoc = 758a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 759a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 760a43be80fSAsmitha Karunanithi std::move(headerLoc)); 761a43be80fSAsmitha Karunanithi 762a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 763b47452b2SAsmitha Karunanithi return task::completed; 7646145ed6fSAsmitha Karunanithi } 765a43be80fSAsmitha Karunanithi return task::completed; 766a43be80fSAsmitha Karunanithi }, 767a43be80fSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus." 768a43be80fSAsmitha Karunanithi "ObjectManager'," 769a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 770a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 771a43be80fSAsmitha Karunanithi 772a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 773a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 774a43be80fSAsmitha Karunanithi task->payload.emplace(req); 775a43be80fSAsmitha Karunanithi } 776a43be80fSAsmitha Karunanithi 7778d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7788d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 779a43be80fSAsmitha Karunanithi { 780a43be80fSAsmitha Karunanithi 781a43be80fSAsmitha Karunanithi std::string dumpPath; 782a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 783a43be80fSAsmitha Karunanithi { 784a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 785a43be80fSAsmitha Karunanithi } 786a43be80fSAsmitha Karunanithi else if (dumpType == "System") 787a43be80fSAsmitha Karunanithi { 788a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 789a43be80fSAsmitha Karunanithi } 790a43be80fSAsmitha Karunanithi else 791a43be80fSAsmitha Karunanithi { 792a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 793a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 794a43be80fSAsmitha Karunanithi return; 795a43be80fSAsmitha Karunanithi } 796a43be80fSAsmitha Karunanithi 797a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 798a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 799a43be80fSAsmitha Karunanithi 800a43be80fSAsmitha Karunanithi if (!redfish::json_util::readJson( 801a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 802a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 803a43be80fSAsmitha Karunanithi { 804a43be80fSAsmitha Karunanithi return; 805a43be80fSAsmitha Karunanithi } 806a43be80fSAsmitha Karunanithi 807a43be80fSAsmitha Karunanithi if (dumpType == "System") 808a43be80fSAsmitha Karunanithi { 809a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 810a43be80fSAsmitha Karunanithi { 811a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 812a43be80fSAsmitha Karunanithi "'DiagnosticDataType'/" 813a43be80fSAsmitha Karunanithi "'OEMDiagnosticDataType' value not found!"; 814a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 815a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 816a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 817a43be80fSAsmitha Karunanithi return; 818a43be80fSAsmitha Karunanithi } 8193174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 820a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 821a43be80fSAsmitha Karunanithi { 822a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 823a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 824a43be80fSAsmitha Karunanithi "System Dump creation parameters"); 825a43be80fSAsmitha Karunanithi return; 826a43be80fSAsmitha Karunanithi } 827a43be80fSAsmitha Karunanithi } 828a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 829a43be80fSAsmitha Karunanithi { 830a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 831a43be80fSAsmitha Karunanithi { 832a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 833a43be80fSAsmitha Karunanithi "'DiagnosticDataType' not found!"; 834a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 835a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 836a43be80fSAsmitha Karunanithi return; 837a43be80fSAsmitha Karunanithi } 8383174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 839a43be80fSAsmitha Karunanithi { 840a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 841a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 842a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 843a43be80fSAsmitha Karunanithi "BMC Dump creation parameters"); 844a43be80fSAsmitha Karunanithi return; 845a43be80fSAsmitha Karunanithi } 846a43be80fSAsmitha Karunanithi } 847a43be80fSAsmitha Karunanithi 848a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 849a43be80fSAsmitha Karunanithi [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec, 850a43be80fSAsmitha Karunanithi const uint32_t& dumpId) { 851a43be80fSAsmitha Karunanithi if (ec) 852a43be80fSAsmitha Karunanithi { 853a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 854a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 855a43be80fSAsmitha Karunanithi return; 856a43be80fSAsmitha Karunanithi } 857a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 858a43be80fSAsmitha Karunanithi 859a43be80fSAsmitha Karunanithi createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType); 860a43be80fSAsmitha Karunanithi }, 861b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 862b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 863b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 864a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 865a43be80fSAsmitha Karunanithi } 866a43be80fSAsmitha Karunanithi 8678d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8688d1b46d7Szhanghch05 const std::string& dumpType) 86980319af1SAsmitha Karunanithi { 870b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 871b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 8728d1b46d7Szhanghch05 87380319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 874b47452b2SAsmitha Karunanithi [asyncResp, dumpType](const boost::system::error_code ec, 87580319af1SAsmitha Karunanithi const std::vector<std::string>& subTreePaths) { 87680319af1SAsmitha Karunanithi if (ec) 87780319af1SAsmitha Karunanithi { 87880319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 87980319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 88080319af1SAsmitha Karunanithi return; 88180319af1SAsmitha Karunanithi } 88280319af1SAsmitha Karunanithi 88380319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 88480319af1SAsmitha Karunanithi { 8852dfd18efSEd Tanous sdbusplus::message::object_path objPath(path); 8862dfd18efSEd Tanous std::string logID = objPath.filename(); 8872dfd18efSEd Tanous if (logID.empty()) 88880319af1SAsmitha Karunanithi { 8892dfd18efSEd Tanous continue; 89080319af1SAsmitha Karunanithi } 8912dfd18efSEd Tanous deleteDumpEntry(asyncResp, logID, dumpType); 89280319af1SAsmitha Karunanithi } 89380319af1SAsmitha Karunanithi }, 89480319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 89580319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 89680319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 897b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, 898b47452b2SAsmitha Karunanithi std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." + 899b47452b2SAsmitha Karunanithi dumpType}); 90080319af1SAsmitha Karunanithi } 90180319af1SAsmitha Karunanithi 9027e860f15SJohn Edward Broadbent inline static void parseCrashdumpParameters( 903043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params, 904043a0536SJohnathan Mantey std::string& filename, std::string& timestamp, std::string& logfile) 905043a0536SJohnathan Mantey { 906043a0536SJohnathan Mantey for (auto property : params) 907043a0536SJohnathan Mantey { 908043a0536SJohnathan Mantey if (property.first == "Timestamp") 909043a0536SJohnathan Mantey { 910043a0536SJohnathan Mantey const std::string* value = 9118d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 912043a0536SJohnathan Mantey if (value != nullptr) 913043a0536SJohnathan Mantey { 914043a0536SJohnathan Mantey timestamp = *value; 915043a0536SJohnathan Mantey } 916043a0536SJohnathan Mantey } 917043a0536SJohnathan Mantey else if (property.first == "Filename") 918043a0536SJohnathan Mantey { 919043a0536SJohnathan Mantey const std::string* value = 9208d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 921043a0536SJohnathan Mantey if (value != nullptr) 922043a0536SJohnathan Mantey { 923043a0536SJohnathan Mantey filename = *value; 924043a0536SJohnathan Mantey } 925043a0536SJohnathan Mantey } 926043a0536SJohnathan Mantey else if (property.first == "Log") 927043a0536SJohnathan Mantey { 928043a0536SJohnathan Mantey const std::string* value = 9298d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 930043a0536SJohnathan Mantey if (value != nullptr) 931043a0536SJohnathan Mantey { 932043a0536SJohnathan Mantey logfile = *value; 933043a0536SJohnathan Mantey } 934043a0536SJohnathan Mantey } 935043a0536SJohnathan Mantey } 936043a0536SJohnathan Mantey } 937043a0536SJohnathan Mantey 938a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 9397e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 9401da66f75SEd Tanous { 941c4bf6374SJason M. Bills /** 942c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 943c4bf6374SJason M. Bills */ 9447e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/") 945ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 9467e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 9477e860f15SJohn Edward Broadbent [](const crow::Request&, 9487e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 9497e860f15SJohn Edward Broadbent 950c4bf6374SJason M. Bills { 9517e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 9527e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 953c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 954c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 955c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 956029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 9577e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 9587e860f15SJohn Edward Broadbent "System Log Services Collection"; 959c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 960c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 9617e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 9627e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 963c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 964029573d4SEd Tanous logServiceArray.push_back( 9657e860f15SJohn Edward Broadbent {{"@odata.id", 9667e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog"}}); 9675cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 968c9bb6861Sraviteja-b logServiceArray.push_back( 9697e860f15SJohn Edward Broadbent {{"@odata.id", 9707e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump"}}); 971c9bb6861Sraviteja-b #endif 972c9bb6861Sraviteja-b 973d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 974d53dd41fSJason M. Bills logServiceArray.push_back( 975cb92c03bSAndrew Geissler {{"@odata.id", 976424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 977d53dd41fSJason M. Bills #endif 978c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 979c4bf6374SJason M. Bills logServiceArray.size(); 980a3316fc6SZhikuiRen 981a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 982a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 983a3316fc6SZhikuiRen const std::vector<std::string>& subtreePath) { 984a3316fc6SZhikuiRen if (ec) 985a3316fc6SZhikuiRen { 986a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 987a3316fc6SZhikuiRen return; 988a3316fc6SZhikuiRen } 989a3316fc6SZhikuiRen 990a3316fc6SZhikuiRen for (auto& pathStr : subtreePath) 991a3316fc6SZhikuiRen { 992a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 993a3316fc6SZhikuiRen { 99423a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 995a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 99623a21a1cSEd Tanous logServiceArrayLocal.push_back( 997a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 998a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 9997e860f15SJohn Edward Broadbent asyncResp->res 10007e860f15SJohn Edward Broadbent .jsonValue["Members@odata.count"] = 100123a21a1cSEd Tanous logServiceArrayLocal.size(); 1002a3316fc6SZhikuiRen return; 1003a3316fc6SZhikuiRen } 1004a3316fc6SZhikuiRen } 1005a3316fc6SZhikuiRen }, 1006a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 1007a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 10087e860f15SJohn Edward Broadbent "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 10097e860f15SJohn Edward Broadbent 0, std::array<const char*, 1>{postCodeIface}); 10107e860f15SJohn Edward Broadbent }); 1011c4bf6374SJason M. Bills } 1012c4bf6374SJason M. Bills 10137e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 1014c4bf6374SJason M. Bills { 10157e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 1016ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 10177e860f15SJohn Edward Broadbent .methods( 10187e860f15SJohn Edward Broadbent boost::beast::http::verb:: 10197e860f15SJohn Edward Broadbent get)([](const crow::Request&, 10207e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1021c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1022029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1023c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1024c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 1025c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 10267e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 10277e860f15SJohn Edward Broadbent "System Event Log Service"; 1028c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1029c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 10307c8c4058STejas Patil 10317c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 10327c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 10337c8c4058STejas Patil 10347c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 10357c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 10367c8c4058STejas Patil redfishDateTimeOffset.second; 10377c8c4058STejas Patil 1038c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1039c4bf6374SJason M. Bills {"@odata.id", 1040029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 1041e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1042e7d6c8b2SGunnar Mills 1043e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 1044e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 10457e860f15SJohn Edward Broadbent }); 1046489640c6SJason M. Bills } 1047489640c6SJason M. Bills 10487e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1049489640c6SJason M. Bills { 10507e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 1051489640c6SJason M. Bills "LogService.ClearLog/") 1052432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 10537e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 10547e860f15SJohn Edward Broadbent [](const crow::Request&, 10557e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1056489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1057489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1058489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1059489640c6SJason M. Bills { 1060489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1061489640c6SJason M. Bills { 1062489640c6SJason M. Bills std::error_code ec; 1063489640c6SJason M. Bills std::filesystem::remove(file, ec); 1064489640c6SJason M. Bills } 1065489640c6SJason M. Bills } 1066489640c6SJason M. Bills 1067489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1068489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1069489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1070489640c6SJason M. Bills if (ec) 1071489640c6SJason M. Bills { 10727e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " 10737e860f15SJohn Edward Broadbent << ec; 1074489640c6SJason M. Bills messages::internalError(asyncResp->res); 1075489640c6SJason M. Bills return; 1076489640c6SJason M. Bills } 1077489640c6SJason M. Bills 1078489640c6SJason M. Bills messages::success(asyncResp->res); 1079489640c6SJason M. Bills }, 1080489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 10817e860f15SJohn Edward Broadbent "org.freedesktop.systemd1.Manager", "ReloadUnit", 10827e860f15SJohn Edward Broadbent "rsyslog.service", "replace"); 10837e860f15SJohn Edward Broadbent }); 1084c4bf6374SJason M. Bills } 1085c4bf6374SJason M. Bills 108695820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 1087b5a76932SEd Tanous const std::string& logEntry, 108895820184SJason M. Bills nlohmann::json& logEntryJson) 1089c4bf6374SJason M. Bills { 109095820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1091cd225da8SJason M. Bills // First get the Timestamp 1092f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1093cd225da8SJason M. Bills if (space == std::string::npos) 109495820184SJason M. Bills { 109595820184SJason M. Bills return 1; 109695820184SJason M. Bills } 1097cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1098cd225da8SJason M. Bills // Then get the log contents 1099f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1100cd225da8SJason M. Bills if (entryStart == std::string::npos) 1101cd225da8SJason M. Bills { 1102cd225da8SJason M. Bills return 1; 1103cd225da8SJason M. Bills } 1104cd225da8SJason M. Bills std::string_view entry(logEntry); 1105cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1106cd225da8SJason M. Bills // Use split to separate the entry into its fields 1107cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1108cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1109cd225da8SJason M. Bills boost::token_compress_on); 1110cd225da8SJason M. Bills // We need at least a MessageId to be valid 1111cd225da8SJason M. Bills if (logEntryFields.size() < 1) 1112cd225da8SJason M. Bills { 1113cd225da8SJason M. Bills return 1; 1114cd225da8SJason M. Bills } 1115cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 111695820184SJason M. Bills 11174851d45dSJason M. Bills // Get the Message from the MessageRegistry 11184851d45dSJason M. Bills const message_registries::Message* message = 11194851d45dSJason M. Bills message_registries::getMessage(messageID); 1120c4bf6374SJason M. Bills 11214851d45dSJason M. Bills std::string msg; 11224851d45dSJason M. Bills std::string severity; 11234851d45dSJason M. Bills if (message != nullptr) 1124c4bf6374SJason M. Bills { 11254851d45dSJason M. Bills msg = message->message; 11264851d45dSJason M. Bills severity = message->severity; 1127c4bf6374SJason M. Bills } 1128c4bf6374SJason M. Bills 112915a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 113015a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 113115a86ff6SJason M. Bills if (logEntryFields.size() > 1) 113215a86ff6SJason M. Bills { 113315a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 113415a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 113515a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 113615a86ff6SJason M. Bills if (!messageArgsStart.empty()) 113715a86ff6SJason M. Bills { 113815a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 113915a86ff6SJason M. Bills } 114015a86ff6SJason M. Bills 114123a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1142c4bf6374SJason M. Bills 11434851d45dSJason M. Bills // Fill the MessageArgs into the Message 114495820184SJason M. Bills int i = 0; 114595820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11464851d45dSJason M. Bills { 114795820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11484851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11494851d45dSJason M. Bills if (argPos != std::string::npos) 11504851d45dSJason M. Bills { 115195820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11524851d45dSJason M. Bills } 11534851d45dSJason M. Bills } 115415a86ff6SJason M. Bills } 11554851d45dSJason M. Bills 115695820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 115795820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 115895820184SJason M. Bills // between the '.' and the '+', so just remove them. 1159f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1160f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 116195820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1162c4bf6374SJason M. Bills { 116395820184SJason M. Bills timestamp.erase(dot, plus - dot); 1164c4bf6374SJason M. Bills } 1165c4bf6374SJason M. Bills 1166c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 116795820184SJason M. Bills logEntryJson = { 1168647b3cdcSGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 1169029573d4SEd Tanous {"@odata.id", 1170897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 117195820184SJason M. Bills logEntryID}, 1172c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 117395820184SJason M. Bills {"Id", logEntryID}, 117495820184SJason M. Bills {"Message", std::move(msg)}, 117595820184SJason M. Bills {"MessageId", std::move(messageID)}, 1176f23b7296SEd Tanous {"MessageArgs", messageArgs}, 1177c4bf6374SJason M. Bills {"EntryType", "Event"}, 117895820184SJason M. Bills {"Severity", std::move(severity)}, 117995820184SJason M. Bills {"Created", std::move(timestamp)}}; 1180c4bf6374SJason M. Bills return 0; 1181c4bf6374SJason M. Bills } 1182c4bf6374SJason M. Bills 11837e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1184c4bf6374SJason M. Bills { 11857e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 11867e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 11878b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 11887e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 11897e860f15SJohn Edward Broadbent [](const crow::Request& req, 11907e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1191271584abSEd Tanous uint64_t skip = 0; 1192271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 11938d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 1194c4bf6374SJason M. Bills { 1195c4bf6374SJason M. Bills return; 1196c4bf6374SJason M. Bills } 11978d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 1198c4bf6374SJason M. Bills { 1199c4bf6374SJason M. Bills return; 1200c4bf6374SJason M. Bills } 12017e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 12027e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1203c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1204c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1205c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1206029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1207c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1208c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1209c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1210cb92c03bSAndrew Geissler 12117e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 12127e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 1213c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 12147e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 12157e860f15SJohn Edward Broadbent // entry 121695820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 121795820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1218b01bf299SEd Tanous uint64_t entryCount = 0; 1219cd225da8SJason M. Bills std::string logEntry; 122095820184SJason M. Bills 12217e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12227e860f15SJohn Edward Broadbent // backwards 12237e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 12247e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1225c4bf6374SJason M. Bills { 1226cd225da8SJason M. Bills std::ifstream logStream(*it); 122795820184SJason M. Bills if (!logStream.is_open()) 1228c4bf6374SJason M. Bills { 1229c4bf6374SJason M. Bills continue; 1230c4bf6374SJason M. Bills } 1231c4bf6374SJason M. Bills 1232e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1233e85d6b16SJason M. Bills bool firstEntry = true; 123495820184SJason M. Bills while (std::getline(logStream, logEntry)) 123595820184SJason M. Bills { 1236c4bf6374SJason M. Bills entryCount++; 12377e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip 12387e860f15SJohn Edward Broadbent // from the start) and top (number of entries to 12397e860f15SJohn Edward Broadbent // display) 1240c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1241c4bf6374SJason M. Bills { 1242c4bf6374SJason M. Bills continue; 1243c4bf6374SJason M. Bills } 1244c4bf6374SJason M. Bills 1245c4bf6374SJason M. Bills std::string idStr; 1246e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1247c4bf6374SJason M. Bills { 1248c4bf6374SJason M. Bills continue; 1249c4bf6374SJason M. Bills } 1250c4bf6374SJason M. Bills 1251e85d6b16SJason M. Bills if (firstEntry) 1252e85d6b16SJason M. Bills { 1253e85d6b16SJason M. Bills firstEntry = false; 1254e85d6b16SJason M. Bills } 1255e85d6b16SJason M. Bills 1256c4bf6374SJason M. Bills logEntryArray.push_back({}); 1257c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 12587e860f15SJohn Edward Broadbent if (fillEventLogEntryJson(idStr, logEntry, 12597e860f15SJohn Edward Broadbent bmcLogEntry) != 0) 1260c4bf6374SJason M. Bills { 1261c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1262c4bf6374SJason M. Bills return; 1263c4bf6374SJason M. Bills } 1264c4bf6374SJason M. Bills } 126595820184SJason M. Bills } 1266c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1267c4bf6374SJason M. Bills if (skip + top < entryCount) 1268c4bf6374SJason M. Bills { 1269c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 127095820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 127195820184SJason M. Bills "Entries?$skip=" + 1272c4bf6374SJason M. Bills std::to_string(skip + top); 1273c4bf6374SJason M. Bills } 12747e860f15SJohn Edward Broadbent }); 1275897967deSJason M. Bills } 1276897967deSJason M. Bills 12777e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1278897967deSJason M. Bills { 12797e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 12807e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1281ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 12827e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 12837e860f15SJohn Edward Broadbent [](const crow::Request&, 12847e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12857e860f15SJohn Edward Broadbent const std::string& param) { 12867e860f15SJohn Edward Broadbent const std::string& targetID = param; 12878d1b46d7Szhanghch05 12887e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 12897e860f15SJohn Edward Broadbent // entry to find the target entry 1290897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1291897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1292897967deSJason M. Bills std::string logEntry; 1293897967deSJason M. Bills 12947e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12957e860f15SJohn Edward Broadbent // backwards 12967e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 12977e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1298897967deSJason M. Bills { 1299897967deSJason M. Bills std::ifstream logStream(*it); 1300897967deSJason M. Bills if (!logStream.is_open()) 1301897967deSJason M. Bills { 1302897967deSJason M. Bills continue; 1303897967deSJason M. Bills } 1304897967deSJason M. Bills 1305897967deSJason M. Bills // Reset the unique ID on the first entry 1306897967deSJason M. Bills bool firstEntry = true; 1307897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1308897967deSJason M. Bills { 1309897967deSJason M. Bills std::string idStr; 1310897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1311897967deSJason M. Bills { 1312897967deSJason M. Bills continue; 1313897967deSJason M. Bills } 1314897967deSJason M. Bills 1315897967deSJason M. Bills if (firstEntry) 1316897967deSJason M. Bills { 1317897967deSJason M. Bills firstEntry = false; 1318897967deSJason M. Bills } 1319897967deSJason M. Bills 1320897967deSJason M. Bills if (idStr == targetID) 1321897967deSJason M. Bills { 13227e860f15SJohn Edward Broadbent if (fillEventLogEntryJson( 13237e860f15SJohn Edward Broadbent idStr, logEntry, 1324897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1325897967deSJason M. Bills { 1326897967deSJason M. Bills messages::internalError(asyncResp->res); 1327897967deSJason M. Bills return; 1328897967deSJason M. Bills } 1329897967deSJason M. Bills return; 1330897967deSJason M. Bills } 1331897967deSJason M. Bills } 1332897967deSJason M. Bills } 1333897967deSJason M. Bills // Requested ID was not found 1334897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 13357e860f15SJohn Edward Broadbent }); 133608a4e4b5SAnthony Wilson } 133708a4e4b5SAnthony Wilson 13387e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 133908a4e4b5SAnthony Wilson { 13407e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 13417e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1342ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 13437e860f15SJohn Edward Broadbent .methods( 13447e860f15SJohn Edward Broadbent boost::beast::http::verb:: 13457e860f15SJohn Edward Broadbent get)([](const crow::Request&, 13467e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 13477e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 13487e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 134908a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 135008a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 135108a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 135208a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 135308a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 135408a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 135508a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 135608a4e4b5SAnthony Wilson 1357cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1358cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1359cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1360cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1361cb92c03bSAndrew Geissler GetManagedObjectsType& resp) { 1362cb92c03bSAndrew Geissler if (ec) 1363cb92c03bSAndrew Geissler { 1364cb92c03bSAndrew Geissler // TODO Handle for specific error code 1365cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1366cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1367cb92c03bSAndrew Geissler << ec; 1368cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1369cb92c03bSAndrew Geissler return; 1370cb92c03bSAndrew Geissler } 1371cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1372cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1373cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 1374cb92c03bSAndrew Geissler for (auto& objectPath : resp) 1375cb92c03bSAndrew Geissler { 137666664f25SEd Tanous uint32_t* id = nullptr; 137766664f25SEd Tanous std::time_t timestamp{}; 1378d139c236SGeorge Liu std::time_t updateTimestamp{}; 137966664f25SEd Tanous std::string* severity = nullptr; 138066664f25SEd Tanous std::string* message = nullptr; 1381f86bb901SAdriana Kobylak std::string* filePath = nullptr; 138275710de2SXiaochao Ma bool resolved = false; 1383f86bb901SAdriana Kobylak for (auto& interfaceMap : objectPath.second) 1384f86bb901SAdriana Kobylak { 1385f86bb901SAdriana Kobylak if (interfaceMap.first == 1386f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1387f86bb901SAdriana Kobylak { 1388cb92c03bSAndrew Geissler for (auto& propertyMap : interfaceMap.second) 1389cb92c03bSAndrew Geissler { 1390cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1391cb92c03bSAndrew Geissler { 1392f86bb901SAdriana Kobylak id = std::get_if<uint32_t>( 1393f86bb901SAdriana Kobylak &propertyMap.second); 1394cb92c03bSAndrew Geissler } 1395cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1396cb92c03bSAndrew Geissler { 1397cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1398f86bb901SAdriana Kobylak std::get_if<uint64_t>( 1399f86bb901SAdriana Kobylak &propertyMap.second); 1400ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1401ebd45906SGeorge Liu { 14027e860f15SJohn Edward Broadbent timestamp = 14037e860f15SJohn Edward Broadbent crow::utility::getTimestamp( 14047e860f15SJohn Edward Broadbent *millisTimeStamp); 14057e860f15SJohn Edward Broadbent } 14067e860f15SJohn Edward Broadbent } 14077e860f15SJohn Edward Broadbent else if (propertyMap.first == 14087e860f15SJohn Edward Broadbent "UpdateTimestamp") 14097e860f15SJohn Edward Broadbent { 14107e860f15SJohn Edward Broadbent const uint64_t* millisTimeStamp = 14117e860f15SJohn Edward Broadbent std::get_if<uint64_t>( 14127e860f15SJohn Edward Broadbent &propertyMap.second); 14137e860f15SJohn Edward Broadbent if (millisTimeStamp != nullptr) 14147e860f15SJohn Edward Broadbent { 14157e860f15SJohn Edward Broadbent updateTimestamp = 14167e860f15SJohn Edward Broadbent crow::utility::getTimestamp( 14177e860f15SJohn Edward Broadbent *millisTimeStamp); 14187e860f15SJohn Edward Broadbent } 14197e860f15SJohn Edward Broadbent } 14207e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 14217e860f15SJohn Edward Broadbent { 14227e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 14237e860f15SJohn Edward Broadbent &propertyMap.second); 14247e860f15SJohn Edward Broadbent } 14257e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 14267e860f15SJohn Edward Broadbent { 14277e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 14287e860f15SJohn Edward Broadbent &propertyMap.second); 14297e860f15SJohn Edward Broadbent } 14307e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 14317e860f15SJohn Edward Broadbent { 14327e860f15SJohn Edward Broadbent bool* resolveptr = std::get_if<bool>( 14337e860f15SJohn Edward Broadbent &propertyMap.second); 14347e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 14357e860f15SJohn Edward Broadbent { 14367e860f15SJohn Edward Broadbent messages::internalError( 14377e860f15SJohn Edward Broadbent asyncResp->res); 14387e860f15SJohn Edward Broadbent return; 14397e860f15SJohn Edward Broadbent } 14407e860f15SJohn Edward Broadbent resolved = *resolveptr; 14417e860f15SJohn Edward Broadbent } 14427e860f15SJohn Edward Broadbent } 14437e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14447e860f15SJohn Edward Broadbent severity == nullptr) 14457e860f15SJohn Edward Broadbent { 14467e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 14477e860f15SJohn Edward Broadbent return; 14487e860f15SJohn Edward Broadbent } 14497e860f15SJohn Edward Broadbent } 14507e860f15SJohn Edward Broadbent else if (interfaceMap.first == 14517e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 14527e860f15SJohn Edward Broadbent { 14537e860f15SJohn Edward Broadbent for (auto& propertyMap : interfaceMap.second) 14547e860f15SJohn Edward Broadbent { 14557e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 14567e860f15SJohn Edward Broadbent { 14577e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 14587e860f15SJohn Edward Broadbent &propertyMap.second); 14597e860f15SJohn Edward Broadbent } 14607e860f15SJohn Edward Broadbent } 14617e860f15SJohn Edward Broadbent } 14627e860f15SJohn Edward Broadbent } 14637e860f15SJohn Edward Broadbent // Object path without the 14647e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 14657e860f15SJohn Edward Broadbent // and continue. 14667e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14677e860f15SJohn Edward Broadbent severity == nullptr) 14687e860f15SJohn Edward Broadbent { 14697e860f15SJohn Edward Broadbent continue; 14707e860f15SJohn Edward Broadbent } 14717e860f15SJohn Edward Broadbent entriesArray.push_back({}); 14727e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 14737e860f15SJohn Edward Broadbent thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 14747e860f15SJohn Edward Broadbent thisEntry["@odata.id"] = 14757e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/" 14767e860f15SJohn Edward Broadbent "LogServices/EventLog/Entries/" + 14777e860f15SJohn Edward Broadbent std::to_string(*id); 14787e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 14797e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 14807e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 14817e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 14827e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 14837e860f15SJohn Edward Broadbent thisEntry["Severity"] = 14847e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 14857e860f15SJohn Edward Broadbent thisEntry["Created"] = 14867e860f15SJohn Edward Broadbent crow::utility::getDateTime(timestamp); 14877e860f15SJohn Edward Broadbent thisEntry["Modified"] = 14887e860f15SJohn Edward Broadbent crow::utility::getDateTime(updateTimestamp); 14897e860f15SJohn Edward Broadbent if (filePath != nullptr) 14907e860f15SJohn Edward Broadbent { 14917e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 14927e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/" 14937e860f15SJohn Edward Broadbent "EventLog/" 14947e860f15SJohn Edward Broadbent "Entries/" + 14957e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 14967e860f15SJohn Edward Broadbent } 14977e860f15SJohn Edward Broadbent } 14987e860f15SJohn Edward Broadbent std::sort(entriesArray.begin(), entriesArray.end(), 14997e860f15SJohn Edward Broadbent [](const nlohmann::json& left, 15007e860f15SJohn Edward Broadbent const nlohmann::json& right) { 15017e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 15027e860f15SJohn Edward Broadbent }); 15037e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 15047e860f15SJohn Edward Broadbent entriesArray.size(); 15057e860f15SJohn Edward Broadbent }, 15067e860f15SJohn Edward Broadbent "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 15077e860f15SJohn Edward Broadbent "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 15087e860f15SJohn Edward Broadbent }); 15097e860f15SJohn Edward Broadbent } 15107e860f15SJohn Edward Broadbent 15117e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 15127e860f15SJohn Edward Broadbent { 15137e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 15147e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1515ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 15167e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 15177e860f15SJohn Edward Broadbent [](const crow::Request&, 15187e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 15197e860f15SJohn Edward Broadbent const std::string& param) 15207e860f15SJohn Edward Broadbent 15217e860f15SJohn Edward Broadbent { 15227e860f15SJohn Edward Broadbent std::string entryID = param; 15237e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 15247e860f15SJohn Edward Broadbent 15257e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 15267e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 15277e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 15287e860f15SJohn Edward Broadbent [asyncResp, entryID](const boost::system::error_code ec, 15297e860f15SJohn Edward Broadbent GetManagedPropertyType& resp) { 15307e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 15317e860f15SJohn Edward Broadbent { 15327e860f15SJohn Edward Broadbent messages::resourceNotFound( 15337e860f15SJohn Edward Broadbent asyncResp->res, "EventLogEntry", entryID); 15347e860f15SJohn Edward Broadbent return; 15357e860f15SJohn Edward Broadbent } 15367e860f15SJohn Edward Broadbent if (ec) 15377e860f15SJohn Edward Broadbent { 15387e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "EventLogEntry (DBus) " 15397e860f15SJohn Edward Broadbent "resp_handler got error " 15407e860f15SJohn Edward Broadbent << ec; 15417e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 15427e860f15SJohn Edward Broadbent return; 15437e860f15SJohn Edward Broadbent } 15447e860f15SJohn Edward Broadbent uint32_t* id = nullptr; 15457e860f15SJohn Edward Broadbent std::time_t timestamp{}; 15467e860f15SJohn Edward Broadbent std::time_t updateTimestamp{}; 15477e860f15SJohn Edward Broadbent std::string* severity = nullptr; 15487e860f15SJohn Edward Broadbent std::string* message = nullptr; 15497e860f15SJohn Edward Broadbent std::string* filePath = nullptr; 15507e860f15SJohn Edward Broadbent bool resolved = false; 15517e860f15SJohn Edward Broadbent 15527e860f15SJohn Edward Broadbent for (auto& propertyMap : resp) 15537e860f15SJohn Edward Broadbent { 15547e860f15SJohn Edward Broadbent if (propertyMap.first == "Id") 15557e860f15SJohn Edward Broadbent { 15567e860f15SJohn Edward Broadbent id = std::get_if<uint32_t>(&propertyMap.second); 15577e860f15SJohn Edward Broadbent } 15587e860f15SJohn Edward Broadbent else if (propertyMap.first == "Timestamp") 15597e860f15SJohn Edward Broadbent { 15607e860f15SJohn Edward Broadbent const uint64_t* millisTimeStamp = 15617e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 15627e860f15SJohn Edward Broadbent if (millisTimeStamp != nullptr) 15637e860f15SJohn Edward Broadbent { 1564d139c236SGeorge Liu timestamp = crow::utility::getTimestamp( 1565cb92c03bSAndrew Geissler *millisTimeStamp); 1566d139c236SGeorge Liu } 1567ebd45906SGeorge Liu } 1568d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1569d139c236SGeorge Liu { 1570d139c236SGeorge Liu const uint64_t* millisTimeStamp = 15717e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 1572ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1573ebd45906SGeorge Liu { 1574ebd45906SGeorge Liu updateTimestamp = 1575ebd45906SGeorge Liu crow::utility::getTimestamp( 1576d139c236SGeorge Liu *millisTimeStamp); 1577cb92c03bSAndrew Geissler } 1578ebd45906SGeorge Liu } 1579cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1580cb92c03bSAndrew Geissler { 1581cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1582cb92c03bSAndrew Geissler &propertyMap.second); 1583cb92c03bSAndrew Geissler } 1584cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1585cb92c03bSAndrew Geissler { 1586cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1587cb92c03bSAndrew Geissler &propertyMap.second); 1588ae34c8e8SAdriana Kobylak } 158975710de2SXiaochao Ma else if (propertyMap.first == "Resolved") 159075710de2SXiaochao Ma { 159175710de2SXiaochao Ma bool* resolveptr = 159275710de2SXiaochao Ma std::get_if<bool>(&propertyMap.second); 159375710de2SXiaochao Ma if (resolveptr == nullptr) 159475710de2SXiaochao Ma { 159575710de2SXiaochao Ma messages::internalError(asyncResp->res); 159675710de2SXiaochao Ma return; 159775710de2SXiaochao Ma } 159875710de2SXiaochao Ma resolved = *resolveptr; 159975710de2SXiaochao Ma } 16007e860f15SJohn Edward Broadbent else if (propertyMap.first == "Path") 1601f86bb901SAdriana Kobylak { 1602f86bb901SAdriana Kobylak filePath = std::get_if<std::string>( 1603f86bb901SAdriana Kobylak &propertyMap.second); 1604f86bb901SAdriana Kobylak } 1605f86bb901SAdriana Kobylak } 1606f86bb901SAdriana Kobylak if (id == nullptr || message == nullptr || 1607f86bb901SAdriana Kobylak severity == nullptr) 1608f86bb901SAdriana Kobylak { 1609ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1610271584abSEd Tanous return; 1611271584abSEd Tanous } 1612f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 1613f86bb901SAdriana Kobylak "#LogEntry.v1_8_0.LogEntry"; 1614f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.id"] = 16157e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/" 16167e860f15SJohn Edward Broadbent "Entries/" + 1617f86bb901SAdriana Kobylak std::to_string(*id); 16187e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 16197e860f15SJohn Edward Broadbent "System Event Log Entry"; 1620f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1621f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1622f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 1623f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1624f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1625f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1626f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 1627f86bb901SAdriana Kobylak crow::utility::getDateTime(timestamp); 1628f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 1629f86bb901SAdriana Kobylak crow::utility::getDateTime(updateTimestamp); 1630f86bb901SAdriana Kobylak if (filePath != nullptr) 1631f86bb901SAdriana Kobylak { 1632f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 16337e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/" 16347e860f15SJohn Edward Broadbent "EventLog/" 16357e860f15SJohn Edward Broadbent "attachment/" + 16367e860f15SJohn Edward Broadbent std::to_string(*id); 1637f86bb901SAdriana Kobylak } 1638cb92c03bSAndrew Geissler }, 1639cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1640cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1641f86bb901SAdriana Kobylak "org.freedesktop.DBus.Properties", "GetAll", ""); 16427e860f15SJohn Edward Broadbent }); 1643336e96c6SChicago Duan 16447e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16457e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1646ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 16477e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 16487e860f15SJohn Edward Broadbent [](const crow::Request& req, 16497e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16507e860f15SJohn Edward Broadbent const std::string& entryId) { 165175710de2SXiaochao Ma std::optional<bool> resolved; 165275710de2SXiaochao Ma 16537e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "Resolved", 16547e860f15SJohn Edward Broadbent resolved)) 165575710de2SXiaochao Ma { 165675710de2SXiaochao Ma return; 165775710de2SXiaochao Ma } 165875710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 165975710de2SXiaochao Ma 166075710de2SXiaochao Ma crow::connections::systemBus->async_method_call( 16614f48d5f6SEd Tanous [asyncResp, entryId](const boost::system::error_code ec) { 166275710de2SXiaochao Ma if (ec) 166375710de2SXiaochao Ma { 166475710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 166575710de2SXiaochao Ma messages::internalError(asyncResp->res); 166675710de2SXiaochao Ma return; 166775710de2SXiaochao Ma } 166875710de2SXiaochao Ma }, 166975710de2SXiaochao Ma "xyz.openbmc_project.Logging", 167075710de2SXiaochao Ma "/xyz/openbmc_project/logging/entry/" + entryId, 167175710de2SXiaochao Ma "org.freedesktop.DBus.Properties", "Set", 167275710de2SXiaochao Ma "xyz.openbmc_project.Logging.Entry", "Resolved", 167375710de2SXiaochao Ma std::variant<bool>(*resolved)); 16747e860f15SJohn Edward Broadbent }); 167575710de2SXiaochao Ma 16767e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16777e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1678ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1679ed398213SEd Tanous 16807e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 16817e860f15SJohn Edward Broadbent [](const crow::Request&, 16827e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16837e860f15SJohn Edward Broadbent const std::string& param) 16847e860f15SJohn Edward Broadbent 1685336e96c6SChicago Duan { 1686336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1687336e96c6SChicago Duan 16887e860f15SJohn Edward Broadbent std::string entryID = param; 1689336e96c6SChicago Duan 1690336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1691336e96c6SChicago Duan 1692336e96c6SChicago Duan // Process response from Logging service. 16937e860f15SJohn Edward Broadbent auto respHandler = [asyncResp, entryID]( 16947e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 16957e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 16967e860f15SJohn Edward Broadbent << "EventLogEntry (DBus) doDelete callback: Done"; 1697336e96c6SChicago Duan if (ec) 1698336e96c6SChicago Duan { 16993de8d8baSGeorge Liu if (ec.value() == EBADR) 17003de8d8baSGeorge Liu { 17017e860f15SJohn Edward Broadbent messages::resourceNotFound(asyncResp->res, 17027e860f15SJohn Edward Broadbent "LogEntry", entryID); 17033de8d8baSGeorge Liu return; 17043de8d8baSGeorge Liu } 1705336e96c6SChicago Duan // TODO Handle for specific error code 17067e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "EventLogEntry (DBus) doDelete " 17077e860f15SJohn Edward Broadbent "respHandler got error " 1708336e96c6SChicago Duan << ec; 1709336e96c6SChicago Duan asyncResp->res.result( 1710336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1711336e96c6SChicago Duan return; 1712336e96c6SChicago Duan } 1713336e96c6SChicago Duan 1714336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1715336e96c6SChicago Duan }; 1716336e96c6SChicago Duan 1717336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1718336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1719336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1720336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1721336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 17227e860f15SJohn Edward Broadbent }); 1723400fd1fbSAdriana Kobylak } 1724400fd1fbSAdriana Kobylak 17257e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1726400fd1fbSAdriana Kobylak { 17277e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" 17287e860f15SJohn Edward Broadbent "<str>/attachment") 1729ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 17307e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 17317e860f15SJohn Edward Broadbent [](const crow::Request& req, 17327e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 17337e860f15SJohn Edward Broadbent const std::string& param) 1734400fd1fbSAdriana Kobylak 17357e860f15SJohn Edward Broadbent { 1736647b3cdcSGeorge Liu if (!http_helpers::isOctetAccepted( 1737647b3cdcSGeorge Liu req.getHeaderValue("Accept"))) 1738400fd1fbSAdriana Kobylak { 17397e860f15SJohn Edward Broadbent asyncResp->res.result( 17407e860f15SJohn Edward Broadbent boost::beast::http::status::bad_request); 1741400fd1fbSAdriana Kobylak return; 1742400fd1fbSAdriana Kobylak } 1743400fd1fbSAdriana Kobylak 17447e860f15SJohn Edward Broadbent std::string entryID = param; 1745400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1746400fd1fbSAdriana Kobylak 1747400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 17487e860f15SJohn Edward Broadbent [asyncResp, 17497e860f15SJohn Edward Broadbent entryID](const boost::system::error_code ec, 1750400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 1751400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 1752400fd1fbSAdriana Kobylak { 17537e860f15SJohn Edward Broadbent messages::resourceNotFound( 17547e860f15SJohn Edward Broadbent asyncResp->res, "EventLogAttachment", entryID); 1755400fd1fbSAdriana Kobylak return; 1756400fd1fbSAdriana Kobylak } 1757400fd1fbSAdriana Kobylak if (ec) 1758400fd1fbSAdriana Kobylak { 1759400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1760400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1761400fd1fbSAdriana Kobylak return; 1762400fd1fbSAdriana Kobylak } 1763400fd1fbSAdriana Kobylak 1764400fd1fbSAdriana Kobylak int fd = -1; 1765400fd1fbSAdriana Kobylak fd = dup(unixfd); 1766400fd1fbSAdriana Kobylak if (fd == -1) 1767400fd1fbSAdriana Kobylak { 1768400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1769400fd1fbSAdriana Kobylak return; 1770400fd1fbSAdriana Kobylak } 1771400fd1fbSAdriana Kobylak 1772400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 1773400fd1fbSAdriana Kobylak if (size == -1) 1774400fd1fbSAdriana Kobylak { 1775400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1776400fd1fbSAdriana Kobylak return; 1777400fd1fbSAdriana Kobylak } 1778400fd1fbSAdriana Kobylak 1779400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 1780400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 1781400fd1fbSAdriana Kobylak if (size > maxFileSize) 1782400fd1fbSAdriana Kobylak { 1783400fd1fbSAdriana Kobylak BMCWEB_LOG_ERROR 1784400fd1fbSAdriana Kobylak << "File size exceeds maximum allowed size of " 1785400fd1fbSAdriana Kobylak << maxFileSize; 1786400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1787400fd1fbSAdriana Kobylak return; 1788400fd1fbSAdriana Kobylak } 1789400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 1790400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 1791400fd1fbSAdriana Kobylak if (rc == -1) 1792400fd1fbSAdriana Kobylak { 1793400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1794400fd1fbSAdriana Kobylak return; 1795400fd1fbSAdriana Kobylak } 1796400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 1797400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 1798400fd1fbSAdriana Kobylak { 1799400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1800400fd1fbSAdriana Kobylak return; 1801400fd1fbSAdriana Kobylak } 1802400fd1fbSAdriana Kobylak close(fd); 1803400fd1fbSAdriana Kobylak 1804400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 18057e860f15SJohn Edward Broadbent std::string output = 18067e860f15SJohn Edward Broadbent crow::utility::base64encode(strData); 1807400fd1fbSAdriana Kobylak 1808400fd1fbSAdriana Kobylak asyncResp->res.addHeader("Content-Type", 1809400fd1fbSAdriana Kobylak "application/octet-stream"); 18107e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Transfer-Encoding", 18117e860f15SJohn Edward Broadbent "Base64"); 1812400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 1813400fd1fbSAdriana Kobylak }, 1814400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 1815400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 1816400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 18177e860f15SJohn Edward Broadbent }); 18181da66f75SEd Tanous } 18191da66f75SEd Tanous 18207e860f15SJohn Edward Broadbent inline void requestRoutesBMCLogServiceCollection(App& app) 18211da66f75SEd Tanous { 18227e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 1823ad89dcf0SGunnar Mills .privileges(redfish::privileges::getLogServiceCollection) 18247e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 18257e860f15SJohn Edward Broadbent [](const crow::Request&, 18267e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 18277e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 18287e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1829e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 18301da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1831e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1832e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 18337e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 18347e860f15SJohn Edward Broadbent "Open BMC Log Services Collection"; 1835e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 18361da66f75SEd Tanous "Collection of LogServices for this Manager"; 18377e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 18387e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 1839c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 18405cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 18415cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 18427e860f15SJohn Edward Broadbent {{"@odata.id", 18437e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 18445cb1dd27SAsmitha Karunanithi #endif 1845c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1846c4bf6374SJason M. Bills logServiceArray.push_back( 18477e860f15SJohn Edward Broadbent {{"@odata.id", 18487e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1849c4bf6374SJason M. Bills #endif 1850e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1851c4bf6374SJason M. Bills logServiceArray.size(); 18527e860f15SJohn Edward Broadbent }); 1853e1f26343SJason M. Bills } 1854e1f26343SJason M. Bills 18557e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 1856e1f26343SJason M. Bills { 18577e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1858ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 18597e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 18607e860f15SJohn Edward Broadbent [](const crow::Request&, 18617e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 18628d1b46d7Szhanghch05 18637e860f15SJohn Edward Broadbent { 1864e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1865e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 18660f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18670f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 18687e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 18697e860f15SJohn Edward Broadbent "Open BMC Journal Log Service"; 18707e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 18717e860f15SJohn Edward Broadbent "BMC Journal Log Service"; 1872c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1873e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 18747c8c4058STejas Patil 18757c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 18767c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 18777c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 18787c8c4058STejas Patil redfishDateTimeOffset.first; 18797c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 18807c8c4058STejas Patil redfishDateTimeOffset.second; 18817c8c4058STejas Patil 1882cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1883cd50aa42SJason M. Bills {"@odata.id", 1884086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 18857e860f15SJohn Edward Broadbent }); 1886e1f26343SJason M. Bills } 1887e1f26343SJason M. Bills 1888c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 1889e1f26343SJason M. Bills sd_journal* journal, 1890c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 1891e1f26343SJason M. Bills { 1892e1f26343SJason M. Bills // Get the Log Entry contents 1893e1f26343SJason M. Bills int ret = 0; 1894e1f26343SJason M. Bills 1895a8fe54f0SJason M. Bills std::string message; 1896a8fe54f0SJason M. Bills std::string_view syslogID; 1897a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 1898a8fe54f0SJason M. Bills if (ret < 0) 1899a8fe54f0SJason M. Bills { 1900a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 1901a8fe54f0SJason M. Bills << strerror(-ret); 1902a8fe54f0SJason M. Bills } 1903a8fe54f0SJason M. Bills if (!syslogID.empty()) 1904a8fe54f0SJason M. Bills { 1905a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 1906a8fe54f0SJason M. Bills } 1907a8fe54f0SJason M. Bills 190839e77504SEd Tanous std::string_view msg; 190916428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1910e1f26343SJason M. Bills if (ret < 0) 1911e1f26343SJason M. Bills { 1912e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1913e1f26343SJason M. Bills return 1; 1914e1f26343SJason M. Bills } 1915a8fe54f0SJason M. Bills message += std::string(msg); 1916e1f26343SJason M. Bills 1917e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1918271584abSEd Tanous long int severity = 8; // Default to an invalid priority 191916428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1920e1f26343SJason M. Bills if (ret < 0) 1921e1f26343SJason M. Bills { 1922e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1923e1f26343SJason M. Bills } 1924e1f26343SJason M. Bills 1925e1f26343SJason M. Bills // Get the Created time from the timestamp 192616428a1aSJason M. Bills std::string entryTimeStr; 192716428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1928e1f26343SJason M. Bills { 192916428a1aSJason M. Bills return 1; 1930e1f26343SJason M. Bills } 1931e1f26343SJason M. Bills 1932e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1933c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 1934647b3cdcSGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 1935c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1936c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1937e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1938c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 1939a8fe54f0SJason M. Bills {"Message", std::move(message)}, 1940e1f26343SJason M. Bills {"EntryType", "Oem"}, 1941738c1e61SPatrick Williams {"Severity", severity <= 2 ? "Critical" 1942738c1e61SPatrick Williams : severity <= 4 ? "Warning" 1943738c1e61SPatrick Williams : "OK"}, 1944086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1945e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1946e1f26343SJason M. Bills return 0; 1947e1f26343SJason M. Bills } 1948e1f26343SJason M. Bills 19497e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 1950e1f26343SJason M. Bills { 19517e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1952ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 19537e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 19547e860f15SJohn Edward Broadbent [](const crow::Request& req, 19557e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1956193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1957271584abSEd Tanous uint64_t skip = 0; 1958271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 19598d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 1960193ad2faSJason M. Bills { 1961193ad2faSJason M. Bills return; 1962193ad2faSJason M. Bills } 19638d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 1964193ad2faSJason M. Bills { 1965193ad2faSJason M. Bills return; 1966193ad2faSJason M. Bills } 19677e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 19687e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1969e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1970e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 19710f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 19720f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1973e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1974e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1975e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 19767e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 19777e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 1978e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1979e1f26343SJason M. Bills 19807e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 19817e860f15SJohn Edward Broadbent // unique ID for each entry 1982e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1983e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1984e1f26343SJason M. Bills if (ret < 0) 1985e1f26343SJason M. Bills { 19867e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 19877e860f15SJohn Edward Broadbent << strerror(-ret); 1988f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1989e1f26343SJason M. Bills return; 1990e1f26343SJason M. Bills } 19917e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 19927e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 1993e1f26343SJason M. Bills journalTmp = nullptr; 1994b01bf299SEd Tanous uint64_t entryCount = 0; 1995e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1996e85d6b16SJason M. Bills bool firstEntry = true; 1997e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1998e1f26343SJason M. Bills { 1999193ad2faSJason M. Bills entryCount++; 20007e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 20017e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 2002193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 2003193ad2faSJason M. Bills { 2004193ad2faSJason M. Bills continue; 2005193ad2faSJason M. Bills } 2006193ad2faSJason M. Bills 200716428a1aSJason M. Bills std::string idStr; 2008e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2009e1f26343SJason M. Bills { 2010e1f26343SJason M. Bills continue; 2011e1f26343SJason M. Bills } 2012e1f26343SJason M. Bills 2013e85d6b16SJason M. Bills if (firstEntry) 2014e85d6b16SJason M. Bills { 2015e85d6b16SJason M. Bills firstEntry = false; 2016e85d6b16SJason M. Bills } 2017e85d6b16SJason M. Bills 2018e1f26343SJason M. Bills logEntryArray.push_back({}); 2019c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 2020c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 2021c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 2022e1f26343SJason M. Bills { 2023f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2024e1f26343SJason M. Bills return; 2025e1f26343SJason M. Bills } 2026e1f26343SJason M. Bills } 2027193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 2028193ad2faSJason M. Bills if (skip + top < entryCount) 2029193ad2faSJason M. Bills { 2030193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 20317e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/" 20327e860f15SJohn Edward Broadbent "Entries?$skip=" + 2033193ad2faSJason M. Bills std::to_string(skip + top); 2034193ad2faSJason M. Bills } 20357e860f15SJohn Edward Broadbent }); 2036e1f26343SJason M. Bills } 2037e1f26343SJason M. Bills 20387e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 2039e1f26343SJason M. Bills { 20407e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 20417e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 2042ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 20437e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 20447e860f15SJohn Edward Broadbent [](const crow::Request&, 20457e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 20467e860f15SJohn Edward Broadbent const std::string& entryID) { 2047e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2048e1f26343SJason M. Bills uint64_t ts = 0; 2049271584abSEd Tanous uint64_t index = 0; 20508d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2051e1f26343SJason M. Bills { 205216428a1aSJason M. Bills return; 2053e1f26343SJason M. Bills } 2054e1f26343SJason M. Bills 2055e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2056e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2057e1f26343SJason M. Bills if (ret < 0) 2058e1f26343SJason M. Bills { 20597e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 20607e860f15SJohn Edward Broadbent << strerror(-ret); 2061f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2062e1f26343SJason M. Bills return; 2063e1f26343SJason M. Bills } 20647e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 20657e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 2066e1f26343SJason M. Bills journalTmp = nullptr; 20677e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 20687e860f15SJohn Edward Broadbent // index tracking the unique ID 2069af07e3f5SJason M. Bills std::string idStr; 2070af07e3f5SJason M. Bills bool firstEntry = true; 2071e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 20722056b6d1SManojkiran Eda if (ret < 0) 20732056b6d1SManojkiran Eda { 20742056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 20752056b6d1SManojkiran Eda << strerror(-ret); 20762056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 20772056b6d1SManojkiran Eda return; 20782056b6d1SManojkiran Eda } 2079271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2080e1f26343SJason M. Bills { 2081e1f26343SJason M. Bills sd_journal_next(journal.get()); 2082af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2083af07e3f5SJason M. Bills { 2084af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2085af07e3f5SJason M. Bills return; 2086af07e3f5SJason M. Bills } 2087af07e3f5SJason M. Bills if (firstEntry) 2088af07e3f5SJason M. Bills { 2089af07e3f5SJason M. Bills firstEntry = false; 2090af07e3f5SJason M. Bills } 2091e1f26343SJason M. Bills } 2092c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2093af07e3f5SJason M. Bills if (idStr != entryID) 2094c4bf6374SJason M. Bills { 2095c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 2096c4bf6374SJason M. Bills return; 2097c4bf6374SJason M. Bills } 2098c4bf6374SJason M. Bills 2099c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 2100e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 2101e1f26343SJason M. Bills { 2102f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2103e1f26343SJason M. Bills return; 2104e1f26343SJason M. Bills } 21057e860f15SJohn Edward Broadbent }); 2106c9bb6861Sraviteja-b } 2107c9bb6861Sraviteja-b 21087e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpService(App& app) 2109c9bb6861Sraviteja-b { 21107e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2111ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 21127e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 21137e860f15SJohn Edward Broadbent [](const crow::Request&, 21147e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2115c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 21165cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 2117c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2118d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 2119c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 21205cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 21215cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2122c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 21237c8c4058STejas Patil 21247c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 21257c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 21267c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 21277c8c4058STejas Patil redfishDateTimeOffset.first; 21287c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 21297c8c4058STejas Patil redfishDateTimeOffset.second; 21307c8c4058STejas Patil 2131c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 21327e860f15SJohn Edward Broadbent {"@odata.id", 21337e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}}; 21345cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 21355cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 21365cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 21375cb1dd27SAsmitha Karunanithi "Actions/LogService.ClearLog"}}}, 2138d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 2139d337bb72SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 2140d337bb72SAsmitha Karunanithi "Actions/LogService.CollectDiagnosticData"}}}}; 21417e860f15SJohn Edward Broadbent }); 2142c9bb6861Sraviteja-b } 2143c9bb6861Sraviteja-b 21447e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntryCollection(App& app) 21457e860f15SJohn Edward Broadbent { 21467e860f15SJohn Edward Broadbent 2147c9bb6861Sraviteja-b /** 2148c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2149c9bb6861Sraviteja-b */ 21507e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2151ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 21527e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 21537e860f15SJohn Edward Broadbent [](const crow::Request&, 21547e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2155c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2156c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2157c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 21585cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 21595cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2160c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 21615cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2162c9bb6861Sraviteja-b 21635cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 21647e860f15SJohn Edward Broadbent }); 2165c9bb6861Sraviteja-b } 2166c9bb6861Sraviteja-b 21677e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2168c9bb6861Sraviteja-b { 21697e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 21707e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2171ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 21727e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 21737e860f15SJohn Edward Broadbent [](const crow::Request&, 21747e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 21757e860f15SJohn Edward Broadbent const std::string& param) { 21767e860f15SJohn Edward Broadbent getDumpEntryById(asyncResp, param, "BMC"); 21777e860f15SJohn Edward Broadbent }); 21787e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 21797e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2180ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 21817e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 21827e860f15SJohn Edward Broadbent [](const crow::Request&, 21837e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 21847e860f15SJohn Edward Broadbent const std::string& param) { 21857e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "bmc"); 21867e860f15SJohn Edward Broadbent }); 2187c9bb6861Sraviteja-b } 2188c9bb6861Sraviteja-b 21897e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2190c9bb6861Sraviteja-b { 21918d1b46d7Szhanghch05 21927e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 2193d337bb72SAsmitha Karunanithi "Actions/" 2194d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2195ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 21967e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 21977e860f15SJohn Edward Broadbent [](const crow::Request& req, 21987e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 21998d1b46d7Szhanghch05 createDump(asyncResp, req, "BMC"); 22007e860f15SJohn Edward Broadbent }); 2201a43be80fSAsmitha Karunanithi } 2202a43be80fSAsmitha Karunanithi 22037e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 220480319af1SAsmitha Karunanithi { 22057e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 220680319af1SAsmitha Karunanithi "Actions/" 220780319af1SAsmitha Karunanithi "LogService.ClearLog/") 2208ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 22097e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 22107e860f15SJohn Edward Broadbent [](const crow::Request&, 22117e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22128d1b46d7Szhanghch05 clearDump(asyncResp, "BMC"); 22137e860f15SJohn Edward Broadbent }); 22145cb1dd27SAsmitha Karunanithi } 22155cb1dd27SAsmitha Karunanithi 22167e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 22175cb1dd27SAsmitha Karunanithi { 22187e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/") 2219ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 22207e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22217e860f15SJohn Edward Broadbent [](const crow::Request&, 22227e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 22235cb1dd27SAsmitha Karunanithi 22247e860f15SJohn Edward Broadbent { 22255cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 22265cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 22275cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2228d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 22295cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 22307e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 22317e860f15SJohn Edward Broadbent "System Dump LogService"; 22325cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 22335cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 22347c8c4058STejas Patil 22357c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 22367c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 22377c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 22387c8c4058STejas Patil redfishDateTimeOffset.first; 22397c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 22407c8c4058STejas Patil redfishDateTimeOffset.second; 22417c8c4058STejas Patil 22425cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Entries"] = { 22435cb1dd27SAsmitha Karunanithi {"@odata.id", 22445cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"}}; 22455cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 22465cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 22477e860f15SJohn Edward Broadbent {{"target", 22487e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 22495cb1dd27SAsmitha Karunanithi "LogService.ClearLog"}}}, 2250d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 22517e860f15SJohn Edward Broadbent {{"target", 22527e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 2253d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData"}}}}; 22547e860f15SJohn Edward Broadbent }); 22555cb1dd27SAsmitha Karunanithi } 22565cb1dd27SAsmitha Karunanithi 22577e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 22587e860f15SJohn Edward Broadbent { 22597e860f15SJohn Edward Broadbent 22605cb1dd27SAsmitha Karunanithi /** 22615cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 22625cb1dd27SAsmitha Karunanithi */ 2263b2a3289dSAsmitha Karunanithi BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 2264ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 22657e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22667e860f15SJohn Edward Broadbent [](const crow::Request&, 2267864d6a17SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22685cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 22695cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 22705cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 22715cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 22725cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 22735cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 22745cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 22755cb1dd27SAsmitha Karunanithi 22765cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 22777e860f15SJohn Edward Broadbent }); 22785cb1dd27SAsmitha Karunanithi } 22795cb1dd27SAsmitha Karunanithi 22807e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 22815cb1dd27SAsmitha Karunanithi { 22827e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2283864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2284ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2285ed398213SEd Tanous 22867e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22877e860f15SJohn Edward Broadbent [](const crow::Request&, 22887e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22897e860f15SJohn Edward Broadbent const std::string& param) { 22907e860f15SJohn Edward Broadbent getDumpEntryById(asyncResp, param, "System"); 22917e860f15SJohn Edward Broadbent }); 22928d1b46d7Szhanghch05 22937e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2294864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2295ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 22967e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 22977e860f15SJohn Edward Broadbent [](const crow::Request&, 22987e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22997e860f15SJohn Edward Broadbent const std::string& param) { 23007e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "system"); 23017e860f15SJohn Edward Broadbent }); 23025cb1dd27SAsmitha Karunanithi } 2303c9bb6861Sraviteja-b 23047e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2305c9bb6861Sraviteja-b { 23067e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2307d337bb72SAsmitha Karunanithi "Actions/" 2308d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2309ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 23107e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 23117e860f15SJohn Edward Broadbent [](const crow::Request& req, 23127e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 23137e860f15SJohn Edward Broadbent 23147e860f15SJohn Edward Broadbent { createDump(asyncResp, req, "System"); }); 2315a43be80fSAsmitha Karunanithi } 2316a43be80fSAsmitha Karunanithi 23177e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2318a43be80fSAsmitha Karunanithi { 23197e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2320013487e5Sraviteja-b "Actions/" 2321013487e5Sraviteja-b "LogService.ClearLog/") 2322ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 23237e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 23247e860f15SJohn Edward Broadbent [](const crow::Request&, 23257e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 23267e860f15SJohn Edward Broadbent 23277e860f15SJohn Edward Broadbent { clearDump(asyncResp, "System"); }); 2328013487e5Sraviteja-b } 2329013487e5Sraviteja-b 23307e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 23311da66f75SEd Tanous { 23323946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 23333946028dSAppaRao Puli // method for security reasons. 23341da66f75SEd Tanous /** 23351da66f75SEd Tanous * Functions triggers appropriate requests on DBus 23361da66f75SEd Tanous */ 23377e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 2338ed398213SEd Tanous // This is incorrect, should be: 2339ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2340432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 23417e860f15SJohn Edward Broadbent .methods( 23427e860f15SJohn Edward Broadbent boost::beast::http::verb:: 23437e860f15SJohn Edward Broadbent get)([](const crow::Request&, 23447e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 23457e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 23467e860f15SJohn Edward Broadbent // SubRoute 23470f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2348424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2349e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 23508e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 23514f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 23524f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 23534f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2354e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2355e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 23567c8c4058STejas Patil 23577c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 23587c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 23597c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 23607c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 23617c8c4058STejas Patil redfishDateTimeOffset.second; 23627c8c4058STejas Patil 2363cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2364cd50aa42SJason M. Bills {"@odata.id", 2365424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 2366e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 23675b61b5e8SJason M. Bills {"#LogService.ClearLog", 23685b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 23695b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 23708e6c099aSJason M. Bills {"#LogService.CollectDiagnosticData", 2371424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 23728e6c099aSJason M. Bills "Actions/LogService.CollectDiagnosticData"}}}}; 23737e860f15SJohn Edward Broadbent }); 23741da66f75SEd Tanous } 23751da66f75SEd Tanous 23767e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 23775b61b5e8SJason M. Bills { 23787e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 23797e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 23805b61b5e8SJason M. Bills "LogService.ClearLog/") 2381ed398213SEd Tanous // This is incorrect, should be: 2382ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2383432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 23847e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 23857e860f15SJohn Edward Broadbent [](const crow::Request&, 23867e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 23875b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 23885b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2389cb13a392SEd Tanous const std::string&) { 23905b61b5e8SJason M. Bills if (ec) 23915b61b5e8SJason M. Bills { 23925b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 23935b61b5e8SJason M. Bills return; 23945b61b5e8SJason M. Bills } 23955b61b5e8SJason M. Bills messages::success(asyncResp->res); 23965b61b5e8SJason M. Bills }, 23977e860f15SJohn Edward Broadbent crashdumpObject, crashdumpPath, deleteAllInterface, 23987e860f15SJohn Edward Broadbent "DeleteAll"); 23997e860f15SJohn Edward Broadbent }); 24005b61b5e8SJason M. Bills } 24015b61b5e8SJason M. Bills 24028d1b46d7Szhanghch05 static void 24038d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24048d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 2405e855dd28SJason M. Bills { 2406043a0536SJohnathan Mantey auto getStoredLogCallback = 2407043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 2408e855dd28SJason M. Bills const boost::system::error_code ec, 2409043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params) { 2410e855dd28SJason M. Bills if (ec) 2411e855dd28SJason M. Bills { 2412e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 24131ddcf01aSJason M. Bills if (ec.value() == 24141ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 24151ddcf01aSJason M. Bills { 2416043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2417043a0536SJohnathan Mantey logID); 24181ddcf01aSJason M. Bills } 24191ddcf01aSJason M. Bills else 24201ddcf01aSJason M. Bills { 2421e855dd28SJason M. Bills messages::internalError(asyncResp->res); 24221ddcf01aSJason M. Bills } 2423e855dd28SJason M. Bills return; 2424e855dd28SJason M. Bills } 2425043a0536SJohnathan Mantey 2426043a0536SJohnathan Mantey std::string timestamp{}; 2427043a0536SJohnathan Mantey std::string filename{}; 2428043a0536SJohnathan Mantey std::string logfile{}; 24292c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2430043a0536SJohnathan Mantey 2431043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2432e855dd28SJason M. Bills { 2433043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 2434e855dd28SJason M. Bills return; 2435e855dd28SJason M. Bills } 2436e855dd28SJason M. Bills 2437043a0536SJohnathan Mantey std::string crashdumpURI = 2438e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2439043a0536SJohnathan Mantey logID + "/" + filename; 2440d0dbeefdSEd Tanous logEntryJson = {{"@odata.type", "#LogEntry.v1_7_0.LogEntry"}, 2441043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 2442043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 2443e855dd28SJason M. Bills logID}, 2444e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2445e855dd28SJason M. Bills {"Id", logID}, 2446e855dd28SJason M. Bills {"EntryType", "Oem"}, 24478e6c099aSJason M. Bills {"AdditionalDataURI", std::move(crashdumpURI)}, 24488e6c099aSJason M. Bills {"DiagnosticDataType", "OEM"}, 24498e6c099aSJason M. Bills {"OEMDiagnosticDataType", "PECICrashdump"}, 2450043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2451e855dd28SJason M. Bills }; 2452e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 24535b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 24545b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2455043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2456e855dd28SJason M. Bills } 2457e855dd28SJason M. Bills 24587e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 24591da66f75SEd Tanous { 24603946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24613946028dSAppaRao Puli // method for security reasons. 24621da66f75SEd Tanous /** 24631da66f75SEd Tanous * Functions triggers appropriate requests on DBus 24641da66f75SEd Tanous */ 24657e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24667e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 2467ed398213SEd Tanous // This is incorrect, should be. 2468ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 2469432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 24707e860f15SJohn Edward Broadbent .methods( 24717e860f15SJohn Edward Broadbent boost::beast::http::verb:: 24727e860f15SJohn Edward Broadbent get)([](const crow::Request&, 24737e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24747e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 24757e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2476e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2477e1f26343SJason M. Bills const boost::system::error_code ec, 24787e860f15SJohn Edward Broadbent const std::vector<std::string>& 24797e860f15SJohn Edward Broadbent resp) { 24801da66f75SEd Tanous if (ec) 24811da66f75SEd Tanous { 24821da66f75SEd Tanous if (ec.value() != 24831da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 24841da66f75SEd Tanous { 24851da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 24861da66f75SEd Tanous << ec.message(); 2487f12894f8SJason M. Bills messages::internalError(asyncResp->res); 24881da66f75SEd Tanous return; 24891da66f75SEd Tanous } 24901da66f75SEd Tanous } 2491e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 24921da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 24930f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2494424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2495424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2496e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2497424c4176SJason M. Bills "Collection of Crashdump Entries"; 24987e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 24997e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 2500e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2501e855dd28SJason M. Bills std::vector<std::string> logIDs; 2502e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2503e855dd28SJason M. Bills // enough to hold them 25041da66f75SEd Tanous for (const std::string& objpath : resp) 25051da66f75SEd Tanous { 2506e855dd28SJason M. Bills // Get the log ID 2507f23b7296SEd Tanous std::size_t lastPos = objpath.rfind('/'); 2508e855dd28SJason M. Bills if (lastPos == std::string::npos) 25091da66f75SEd Tanous { 2510e855dd28SJason M. Bills continue; 25111da66f75SEd Tanous } 2512e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2513e855dd28SJason M. Bills 2514e855dd28SJason M. Bills // Add a space for the log entry to the array 2515e855dd28SJason M. Bills logEntryArray.push_back({}); 2516e855dd28SJason M. Bills } 2517e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2518e855dd28SJason M. Bills size_t index = 0; 2519e855dd28SJason M. Bills for (const std::string& logID : logIDs) 2520e855dd28SJason M. Bills { 2521e855dd28SJason M. Bills // Add the log entry to the array 2522e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 25231da66f75SEd Tanous } 2524e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2525e1f26343SJason M. Bills logEntryArray.size(); 25261da66f75SEd Tanous }; 25271da66f75SEd Tanous crow::connections::systemBus->async_method_call( 25281da66f75SEd Tanous std::move(getLogEntriesCallback), 25291da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 25301da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 25311da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 25325b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 25337e860f15SJohn Edward Broadbent }); 25341da66f75SEd Tanous } 25351da66f75SEd Tanous 25367e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 25371da66f75SEd Tanous { 25383946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25393946028dSAppaRao Puli // method for security reasons. 25401da66f75SEd Tanous 25417e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 25427e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/") 2543ed398213SEd Tanous // this is incorrect, should be 2544ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 2545432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 25467e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 25477e860f15SJohn Edward Broadbent [](const crow::Request&, 25487e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25497e860f15SJohn Edward Broadbent const std::string& param) { 25507e860f15SJohn Edward Broadbent const std::string& logID = param; 2551e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 25527e860f15SJohn Edward Broadbent }); 2553e855dd28SJason M. Bills } 2554e855dd28SJason M. Bills 25557e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 2556e855dd28SJason M. Bills { 25573946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25583946028dSAppaRao Puli // method for security reasons. 25597e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 25607e860f15SJohn Edward Broadbent app, 25617e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/") 2562ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 25637e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 25647e860f15SJohn Edward Broadbent [](const crow::Request&, 25657e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25667e860f15SJohn Edward Broadbent const std::string& logID, const std::string& fileName) { 2567043a0536SJohnathan Mantey auto getStoredLogCallback = 2568043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 2569abf2add6SEd Tanous const boost::system::error_code ec, 25707e860f15SJohn Edward Broadbent const std::vector<std::pair<std::string, VariantType>>& 25717e860f15SJohn Edward Broadbent resp) { 25721da66f75SEd Tanous if (ec) 25731da66f75SEd Tanous { 2574043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2575043a0536SJohnathan Mantey << ec.message(); 2576f12894f8SJason M. Bills messages::internalError(asyncResp->res); 25771da66f75SEd Tanous return; 25781da66f75SEd Tanous } 2579e855dd28SJason M. Bills 2580043a0536SJohnathan Mantey std::string dbusFilename{}; 2581043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2582043a0536SJohnathan Mantey std::string dbusFilepath{}; 2583043a0536SJohnathan Mantey 25847e860f15SJohn Edward Broadbent parseCrashdumpParameters(resp, dbusFilename, 25857e860f15SJohn Edward Broadbent dbusTimestamp, dbusFilepath); 2586043a0536SJohnathan Mantey 2587043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2588043a0536SJohnathan Mantey dbusFilepath.empty()) 25891da66f75SEd Tanous { 25907e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 25917e860f15SJohn Edward Broadbent fileName); 25921da66f75SEd Tanous return; 25931da66f75SEd Tanous } 2594e855dd28SJason M. Bills 2595043a0536SJohnathan Mantey // Verify the file name parameter is correct 2596043a0536SJohnathan Mantey if (fileName != dbusFilename) 2597043a0536SJohnathan Mantey { 25987e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 25997e860f15SJohn Edward Broadbent fileName); 2600043a0536SJohnathan Mantey return; 2601043a0536SJohnathan Mantey } 2602043a0536SJohnathan Mantey 2603043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2604043a0536SJohnathan Mantey { 26057e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 26067e860f15SJohn Edward Broadbent fileName); 2607043a0536SJohnathan Mantey return; 2608043a0536SJohnathan Mantey } 2609043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 2610043a0536SJohnathan Mantey std::ios::binary | 2611043a0536SJohnathan Mantey std::ios::ate); 2612043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 2613043a0536SJohnathan Mantey if (fileSize < 0) 2614043a0536SJohnathan Mantey { 2615043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 2616043a0536SJohnathan Mantey return; 2617043a0536SJohnathan Mantey } 2618043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 2619043a0536SJohnathan Mantey 2620043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 2621043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 2622043a0536SJohnathan Mantey 2623043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 2624043a0536SJohnathan Mantey 26257e860f15SJohn Edward Broadbent // The cast to std::string is intentional in order to 26267e860f15SJohn Edward Broadbent // use the assign() that applies move mechanics 2627043a0536SJohnathan Mantey asyncResp->res.body().assign( 2628043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 2629043a0536SJohnathan Mantey 26307e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 26317e860f15SJohn Edward Broadbent // from a browser 26327e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Disposition", 26337e860f15SJohn Edward Broadbent "attachment"); 26341da66f75SEd Tanous }; 26351da66f75SEd Tanous crow::connections::systemBus->async_method_call( 26365b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 26375b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 26387e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 26397e860f15SJohn Edward Broadbent crashdumpInterface); 26407e860f15SJohn Edward Broadbent }); 26411da66f75SEd Tanous } 26421da66f75SEd Tanous 26437e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 26441da66f75SEd Tanous { 26453946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 26463946028dSAppaRao Puli // method for security reasons. 26477e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/" 26487e860f15SJohn Edward Broadbent "Actions/LogService.CollectDiagnosticData/") 2649ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 2650ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2651432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 26527e860f15SJohn Edward Broadbent .methods( 26537e860f15SJohn Edward Broadbent boost::beast::http::verb:: 26547e860f15SJohn Edward Broadbent post)([](const crow::Request& req, 26557e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26568e6c099aSJason M. Bills std::string diagnosticDataType; 26578e6c099aSJason M. Bills std::string oemDiagnosticDataType; 26588e6c099aSJason M. Bills if (!redfish::json_util::readJson( 26597e860f15SJohn Edward Broadbent req, asyncResp->res, "DiagnosticDataType", 26607e860f15SJohn Edward Broadbent diagnosticDataType, "OEMDiagnosticDataType", 26617e860f15SJohn Edward Broadbent oemDiagnosticDataType)) 26628e6c099aSJason M. Bills { 26638e6c099aSJason M. Bills return; 26648e6c099aSJason M. Bills } 26658e6c099aSJason M. Bills 26668e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 26678e6c099aSJason M. Bills { 26688e6c099aSJason M. Bills BMCWEB_LOG_ERROR 26698e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 26708e6c099aSJason M. Bills messages::actionParameterValueFormatError( 26718e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 26728e6c099aSJason M. Bills "CollectDiagnosticData"); 26738e6c099aSJason M. Bills return; 26748e6c099aSJason M. Bills } 26758e6c099aSJason M. Bills 26768e6c099aSJason M. Bills auto collectCrashdumpCallback = [asyncResp, req]( 26777e860f15SJohn Edward Broadbent const boost::system::error_code 26787e860f15SJohn Edward Broadbent ec, 2679cb13a392SEd Tanous const std::string&) { 26801da66f75SEd Tanous if (ec) 26811da66f75SEd Tanous { 26827e860f15SJohn Edward Broadbent if (ec.value() == 26837e860f15SJohn Edward Broadbent boost::system::errc::operation_not_supported) 26841da66f75SEd Tanous { 2685f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 26861da66f75SEd Tanous } 26874363d3b2SJason M. Bills else if (ec.value() == 26884363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 26894363d3b2SJason M. Bills { 26904363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 26914363d3b2SJason M. Bills "60"); 26924363d3b2SJason M. Bills } 26931da66f75SEd Tanous else 26941da66f75SEd Tanous { 2695f12894f8SJason M. Bills messages::internalError(asyncResp->res); 26961da66f75SEd Tanous } 26971da66f75SEd Tanous return; 26981da66f75SEd Tanous } 26997e860f15SJohn Edward Broadbent std::shared_ptr<task::TaskData> task = 27007e860f15SJohn Edward Broadbent task::TaskData::createTask( 27017e860f15SJohn Edward Broadbent [](boost::system::error_code err, 27027e860f15SJohn Edward Broadbent sdbusplus::message::message&, 270366afe4faSJames Feist const std::shared_ptr<task::TaskData>& taskData) { 270466afe4faSJames Feist if (!err) 270566afe4faSJames Feist { 2706e5d5006bSJames Feist taskData->messages.emplace_back( 2707e5d5006bSJames Feist messages::taskCompletedOK( 2708e5d5006bSJames Feist std::to_string(taskData->index))); 2709831d6b09SJames Feist taskData->state = "Completed"; 271066afe4faSJames Feist } 271132898ceaSJames Feist return task::completed; 271266afe4faSJames Feist }, 27137e860f15SJohn Edward Broadbent "type='signal',interface='org.freedesktop.DBus." 27147e860f15SJohn Edward Broadbent "Properties'," 271546229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 271646229577SJames Feist "crashdump'"); 271746229577SJames Feist task->startTimer(std::chrono::minutes(5)); 271846229577SJames Feist task->populateResp(asyncResp->res); 2719fe306728SJames Feist task->payload.emplace(req); 27201da66f75SEd Tanous }; 27218e6c099aSJason M. Bills 27228e6c099aSJason M. Bills if (oemDiagnosticDataType == "OnDemand") 27238e6c099aSJason M. Bills { 27241da66f75SEd Tanous crow::connections::systemBus->async_method_call( 27258e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 27268e6c099aSJason M. Bills crashdumpPath, crashdumpOnDemandInterface, 27278e6c099aSJason M. Bills "GenerateOnDemandLog"); 27281da66f75SEd Tanous } 27298e6c099aSJason M. Bills else if (oemDiagnosticDataType == "Telemetry") 27306eda7685SKenny L. Ku { 27318e6c099aSJason M. Bills crow::connections::systemBus->async_method_call( 27328e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 27338e6c099aSJason M. Bills crashdumpPath, crashdumpTelemetryInterface, 27348e6c099aSJason M. Bills "GenerateTelemetryLog"); 27356eda7685SKenny L. Ku } 27366eda7685SKenny L. Ku else 27376eda7685SKenny L. Ku { 27388e6c099aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 27398e6c099aSJason M. Bills << oemDiagnosticDataType; 27408e6c099aSJason M. Bills messages::actionParameterValueFormatError( 27417e860f15SJohn Edward Broadbent asyncResp->res, oemDiagnosticDataType, 27427e860f15SJohn Edward Broadbent "OEMDiagnosticDataType", "CollectDiagnosticData"); 27436eda7685SKenny L. Ku return; 27446eda7685SKenny L. Ku } 27457e860f15SJohn Edward Broadbent }); 27466eda7685SKenny L. Ku } 27476eda7685SKenny L. Ku 2748cb92c03bSAndrew Geissler /** 2749cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2750cb92c03bSAndrew Geissler */ 27517e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 2752cb92c03bSAndrew Geissler { 2753cb92c03bSAndrew Geissler /** 2754cb92c03bSAndrew Geissler * Function handles POST method request. 2755cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 2756cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 2757cb92c03bSAndrew Geissler */ 27587e860f15SJohn Edward Broadbent 27597e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 27607e860f15SJohn Edward Broadbent "LogService.ClearLog/") 2761ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 27627e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 27637e860f15SJohn Edward Broadbent [](const crow::Request&, 27647e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2765cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 2766cb92c03bSAndrew Geissler 2767cb92c03bSAndrew Geissler // Process response from Logging service. 27687e860f15SJohn Edward Broadbent auto respHandler = [asyncResp]( 27697e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 27707e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 27717e860f15SJohn Edward Broadbent << "doClearLog resp_handler callback: Done"; 2772cb92c03bSAndrew Geissler if (ec) 2773cb92c03bSAndrew Geissler { 2774cb92c03bSAndrew Geissler // TODO Handle for specific error code 27757e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " 27767e860f15SJohn Edward Broadbent << ec; 2777cb92c03bSAndrew Geissler asyncResp->res.result( 2778cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 2779cb92c03bSAndrew Geissler return; 2780cb92c03bSAndrew Geissler } 2781cb92c03bSAndrew Geissler 27827e860f15SJohn Edward Broadbent asyncResp->res.result( 27837e860f15SJohn Edward Broadbent boost::beast::http::status::no_content); 2784cb92c03bSAndrew Geissler }; 2785cb92c03bSAndrew Geissler 2786cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 2787cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 27882c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 2789cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 2790cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 27917e860f15SJohn Edward Broadbent }); 2792cb92c03bSAndrew Geissler } 2793a3316fc6SZhikuiRen 2794a3316fc6SZhikuiRen /**************************************************** 2795a3316fc6SZhikuiRen * Redfish PostCode interfaces 2796a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 2797a3316fc6SZhikuiRen ******************************************************/ 27987e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 2799a3316fc6SZhikuiRen { 28007e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 2801ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 28027e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 28037e860f15SJohn Edward Broadbent [](const crow::Request&, 28047e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2805a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 28067e860f15SJohn Edward Broadbent {"@odata.id", 28077e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes"}, 2808a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 2809a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 2810a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 2811a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 2812a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 2813a3316fc6SZhikuiRen {"Entries", 28147e860f15SJohn Edward Broadbent {{"@odata.id", "/redfish/v1/Systems/system/LogServices/" 28157e860f15SJohn Edward Broadbent "PostCodes/Entries"}}}}; 28167c8c4058STejas Patil 28177c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 28187c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 28197c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 28207c8c4058STejas Patil redfishDateTimeOffset.first; 28217c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 28227c8c4058STejas Patil redfishDateTimeOffset.second; 28237c8c4058STejas Patil 2824a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 28257e860f15SJohn Edward Broadbent {"target", 28267e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/" 2827a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 28287e860f15SJohn Edward Broadbent }); 2829a3316fc6SZhikuiRen } 2830a3316fc6SZhikuiRen 28317e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 2832a3316fc6SZhikuiRen { 28337e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 28347e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 2835a3316fc6SZhikuiRen "LogService.ClearLog/") 2836ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 2837ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2838432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 28397e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 28407e860f15SJohn Edward Broadbent [](const crow::Request&, 28417e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2842a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 2843a3316fc6SZhikuiRen 2844a3316fc6SZhikuiRen // Make call to post-code service to request clear all 2845a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2846a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 2847a3316fc6SZhikuiRen if (ec) 2848a3316fc6SZhikuiRen { 2849a3316fc6SZhikuiRen // TODO Handle for specific error code 2850a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 28517e860f15SJohn Edward Broadbent << "doClearPostCodes resp_handler got error " 28527e860f15SJohn Edward Broadbent << ec; 28537e860f15SJohn Edward Broadbent asyncResp->res.result(boost::beast::http::status:: 28547e860f15SJohn Edward Broadbent internal_server_error); 2855a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 2856a3316fc6SZhikuiRen return; 2857a3316fc6SZhikuiRen } 2858a3316fc6SZhikuiRen }, 285915124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 286015124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 2861a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 28627e860f15SJohn Edward Broadbent }); 2863a3316fc6SZhikuiRen } 2864a3316fc6SZhikuiRen 2865a3316fc6SZhikuiRen static void fillPostCodeEntry( 28668d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 28676c9a279eSManojkiran Eda const boost::container::flat_map< 28686c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 2869a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 2870a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 2871a3316fc6SZhikuiRen { 2872a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 2873a3316fc6SZhikuiRen const message_registries::Message* message = 28744a0bf539SManojkiran Eda message_registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 2875a3316fc6SZhikuiRen 2876a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 2877a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 2878a3316fc6SZhikuiRen 2879a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 28806c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 28816c9a279eSManojkiran Eda code : postcode) 2882a3316fc6SZhikuiRen { 2883a3316fc6SZhikuiRen currentCodeIndex++; 2884a3316fc6SZhikuiRen std::string postcodeEntryID = 2885a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 2886a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 2887a3316fc6SZhikuiRen 2888a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 2889a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 2890a3316fc6SZhikuiRen 2891a3316fc6SZhikuiRen if (1 == currentCodeIndex) 2892a3316fc6SZhikuiRen { // already incremented 2893a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 2894a3316fc6SZhikuiRen } 2895a3316fc6SZhikuiRen else 2896a3316fc6SZhikuiRen { 2897a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 2898a3316fc6SZhikuiRen } 2899a3316fc6SZhikuiRen 2900a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 2901a3316fc6SZhikuiRen // not fall between top and skip 2902a3316fc6SZhikuiRen if ((codeIndex == 0) && 2903a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 2904a3316fc6SZhikuiRen { 2905a3316fc6SZhikuiRen continue; 2906a3316fc6SZhikuiRen } 2907a3316fc6SZhikuiRen 29084e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 2909a3316fc6SZhikuiRen // currentIndex 2910a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 2911a3316fc6SZhikuiRen { 2912a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 2913a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 2914a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 2915a3316fc6SZhikuiRen continue; 2916a3316fc6SZhikuiRen } 2917a3316fc6SZhikuiRen 2918a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 2919a3316fc6SZhikuiRen // index 2920a3316fc6SZhikuiRen 2921a3316fc6SZhikuiRen // Get the Created time from the timestamp 2922a3316fc6SZhikuiRen std::string entryTimeStr; 29239c620e21SAsmitha Karunanithi entryTimeStr = crow::utility::getDateTime( 29249c620e21SAsmitha Karunanithi static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000)); 2925a3316fc6SZhikuiRen 2926a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 2927a3316fc6SZhikuiRen std::ostringstream hexCode; 2928a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 29296c9a279eSManojkiran Eda << std::get<0>(code.second); 2930a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 2931a3316fc6SZhikuiRen // Set Fixed -Point Notation 2932a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 2933a3316fc6SZhikuiRen // Set precision to 4 digits 2934a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 2935a3316fc6SZhikuiRen // Add double to stream 2936a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 2937a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 2938a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 2939a3316fc6SZhikuiRen 2940a3316fc6SZhikuiRen // Get MessageArgs template from message registry 2941a3316fc6SZhikuiRen std::string msg; 2942a3316fc6SZhikuiRen if (message != nullptr) 2943a3316fc6SZhikuiRen { 2944a3316fc6SZhikuiRen msg = message->message; 2945a3316fc6SZhikuiRen 2946a3316fc6SZhikuiRen // fill in this post code value 2947a3316fc6SZhikuiRen int i = 0; 2948a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 2949a3316fc6SZhikuiRen { 2950a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 2951a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 2952a3316fc6SZhikuiRen if (argPos != std::string::npos) 2953a3316fc6SZhikuiRen { 2954a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 2955a3316fc6SZhikuiRen } 2956a3316fc6SZhikuiRen } 2957a3316fc6SZhikuiRen } 2958a3316fc6SZhikuiRen 2959d4342a92STim Lee // Get Severity template from message registry 2960d4342a92STim Lee std::string severity; 2961d4342a92STim Lee if (message != nullptr) 2962d4342a92STim Lee { 2963d4342a92STim Lee severity = message->severity; 2964d4342a92STim Lee } 2965d4342a92STim Lee 2966a3316fc6SZhikuiRen // add to AsyncResp 2967a3316fc6SZhikuiRen logEntryArray.push_back({}); 2968a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 2969647b3cdcSGeorge Liu bmcLogEntry = {{"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 2970a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 2971a3316fc6SZhikuiRen "PostCodes/Entries/" + 2972a3316fc6SZhikuiRen postcodeEntryID}, 2973a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 2974a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 2975a3316fc6SZhikuiRen {"Message", std::move(msg)}, 29764a0bf539SManojkiran Eda {"MessageId", "OpenBMC.0.2.BIOSPOSTCode"}, 2977a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 2978a3316fc6SZhikuiRen {"EntryType", "Event"}, 2979a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 29809c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 2981647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 2982647b3cdcSGeorge Liu { 2983647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 2984647b3cdcSGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 2985647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 2986647b3cdcSGeorge Liu } 2987a3316fc6SZhikuiRen } 2988a3316fc6SZhikuiRen } 2989a3316fc6SZhikuiRen 29908d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2991a3316fc6SZhikuiRen const uint16_t bootIndex, 2992a3316fc6SZhikuiRen const uint64_t codeIndex) 2993a3316fc6SZhikuiRen { 2994a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 29956c9a279eSManojkiran Eda [aResp, bootIndex, 29966c9a279eSManojkiran Eda codeIndex](const boost::system::error_code ec, 29976c9a279eSManojkiran Eda const boost::container::flat_map< 29986c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 29996c9a279eSManojkiran Eda postcode) { 3000a3316fc6SZhikuiRen if (ec) 3001a3316fc6SZhikuiRen { 3002a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3003a3316fc6SZhikuiRen messages::internalError(aResp->res); 3004a3316fc6SZhikuiRen return; 3005a3316fc6SZhikuiRen } 3006a3316fc6SZhikuiRen 3007a3316fc6SZhikuiRen // skip the empty postcode boots 3008a3316fc6SZhikuiRen if (postcode.empty()) 3009a3316fc6SZhikuiRen { 3010a3316fc6SZhikuiRen return; 3011a3316fc6SZhikuiRen } 3012a3316fc6SZhikuiRen 3013a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3014a3316fc6SZhikuiRen 3015a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3016a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3017a3316fc6SZhikuiRen }, 301815124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 301915124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3020a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3021a3316fc6SZhikuiRen bootIndex); 3022a3316fc6SZhikuiRen } 3023a3316fc6SZhikuiRen 30248d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3025a3316fc6SZhikuiRen const uint16_t bootIndex, 3026a3316fc6SZhikuiRen const uint16_t bootCount, 3027a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 3028a3316fc6SZhikuiRen const uint64_t top) 3029a3316fc6SZhikuiRen { 3030a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3031a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3032a3316fc6SZhikuiRen top](const boost::system::error_code ec, 30336c9a279eSManojkiran Eda const boost::container::flat_map< 30346c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 30356c9a279eSManojkiran Eda postcode) { 3036a3316fc6SZhikuiRen if (ec) 3037a3316fc6SZhikuiRen { 3038a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3039a3316fc6SZhikuiRen messages::internalError(aResp->res); 3040a3316fc6SZhikuiRen return; 3041a3316fc6SZhikuiRen } 3042a3316fc6SZhikuiRen 3043a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3044a3316fc6SZhikuiRen if (!postcode.empty()) 3045a3316fc6SZhikuiRen { 3046a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 3047a3316fc6SZhikuiRen 3048a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3049a3316fc6SZhikuiRen { 3050a3316fc6SZhikuiRen uint64_t thisBootSkip = 3051a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3052a3316fc6SZhikuiRen uint64_t thisBootTop = 3053a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3054a3316fc6SZhikuiRen 3055a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3056a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3057a3316fc6SZhikuiRen } 3058a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3059a3316fc6SZhikuiRen } 3060a3316fc6SZhikuiRen 3061a3316fc6SZhikuiRen // continue to previous bootIndex 3062a3316fc6SZhikuiRen if (bootIndex < bootCount) 3063a3316fc6SZhikuiRen { 3064a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3065a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3066a3316fc6SZhikuiRen } 3067a3316fc6SZhikuiRen else 3068a3316fc6SZhikuiRen { 3069a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 3070a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3071a3316fc6SZhikuiRen "Entries?$skip=" + 3072a3316fc6SZhikuiRen std::to_string(skip + top); 3073a3316fc6SZhikuiRen } 3074a3316fc6SZhikuiRen }, 307515124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 307615124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3077a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3078a3316fc6SZhikuiRen bootIndex); 3079a3316fc6SZhikuiRen } 3080a3316fc6SZhikuiRen 30818d1b46d7Szhanghch05 static void 30828d1b46d7Szhanghch05 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3083a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3084a3316fc6SZhikuiRen { 3085a3316fc6SZhikuiRen uint64_t entryCount = 0; 3086a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3087a3316fc6SZhikuiRen [aResp, entryCount, skip, 3088a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3089a3316fc6SZhikuiRen const std::variant<uint16_t>& bootCount) { 3090a3316fc6SZhikuiRen if (ec) 3091a3316fc6SZhikuiRen { 3092a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3093a3316fc6SZhikuiRen messages::internalError(aResp->res); 3094a3316fc6SZhikuiRen return; 3095a3316fc6SZhikuiRen } 3096a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 3097a3316fc6SZhikuiRen if (pVal) 3098a3316fc6SZhikuiRen { 3099a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 3100a3316fc6SZhikuiRen } 3101a3316fc6SZhikuiRen else 3102a3316fc6SZhikuiRen { 3103a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 3104a3316fc6SZhikuiRen } 3105a3316fc6SZhikuiRen }, 310615124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 310715124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3108a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 3109a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 3110a3316fc6SZhikuiRen } 3111a3316fc6SZhikuiRen 31127e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3113a3316fc6SZhikuiRen { 31147e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 31157e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3116ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 31177e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 31187e860f15SJohn Edward Broadbent [](const crow::Request& req, 31197e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3120a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3121a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3122a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3123a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3124a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3125a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3126a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3127a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3128a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3129a3316fc6SZhikuiRen 3130a3316fc6SZhikuiRen uint64_t skip = 0; 3131a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 31328d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 3133a3316fc6SZhikuiRen { 3134a3316fc6SZhikuiRen return; 3135a3316fc6SZhikuiRen } 31368d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 3137a3316fc6SZhikuiRen { 3138a3316fc6SZhikuiRen return; 3139a3316fc6SZhikuiRen } 3140a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 31417e860f15SJohn Edward Broadbent }); 3142a3316fc6SZhikuiRen } 3143a3316fc6SZhikuiRen 3144647b3cdcSGeorge Liu /** 3145647b3cdcSGeorge Liu * @brief Parse post code ID and get the current value and index value 3146647b3cdcSGeorge Liu * eg: postCodeID=B1-2, currentValue=1, index=2 3147647b3cdcSGeorge Liu * 3148647b3cdcSGeorge Liu * @param[in] postCodeID Post Code ID 3149647b3cdcSGeorge Liu * @param[out] currentValue Current value 3150647b3cdcSGeorge Liu * @param[out] index Index value 3151647b3cdcSGeorge Liu * 3152647b3cdcSGeorge Liu * @return bool true if the parsing is successful, false the parsing fails 3153647b3cdcSGeorge Liu */ 3154647b3cdcSGeorge Liu inline static bool parsePostCode(const std::string& postCodeID, 3155647b3cdcSGeorge Liu uint64_t& currentValue, uint16_t& index) 3156647b3cdcSGeorge Liu { 3157647b3cdcSGeorge Liu std::vector<std::string> split; 3158647b3cdcSGeorge Liu boost::algorithm::split(split, postCodeID, boost::is_any_of("-")); 3159647b3cdcSGeorge Liu if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B') 3160647b3cdcSGeorge Liu { 3161647b3cdcSGeorge Liu return false; 3162647b3cdcSGeorge Liu } 3163647b3cdcSGeorge Liu 3164647b3cdcSGeorge Liu const char* start = split[0].data() + 1; 3165647b3cdcSGeorge Liu const char* end = split[0].data() + split[0].size(); 3166647b3cdcSGeorge Liu auto [ptrIndex, ecIndex] = std::from_chars(start, end, index); 3167647b3cdcSGeorge Liu 3168647b3cdcSGeorge Liu if (ptrIndex != end || ecIndex != std::errc()) 3169647b3cdcSGeorge Liu { 3170647b3cdcSGeorge Liu return false; 3171647b3cdcSGeorge Liu } 3172647b3cdcSGeorge Liu 3173647b3cdcSGeorge Liu start = split[1].data(); 3174647b3cdcSGeorge Liu end = split[1].data() + split[1].size(); 3175647b3cdcSGeorge Liu auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue); 3176647b3cdcSGeorge Liu if (ptrValue != end || ecValue != std::errc()) 3177647b3cdcSGeorge Liu { 3178647b3cdcSGeorge Liu return false; 3179647b3cdcSGeorge Liu } 3180647b3cdcSGeorge Liu 3181647b3cdcSGeorge Liu return true; 3182647b3cdcSGeorge Liu } 3183647b3cdcSGeorge Liu 3184647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3185647b3cdcSGeorge Liu { 3186647b3cdcSGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/" 3187647b3cdcSGeorge Liu "Entries/<str>/attachment/") 3188647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 3189647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 3190647b3cdcSGeorge Liu [](const crow::Request& req, 3191647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3192647b3cdcSGeorge Liu const std::string& postCodeID) { 3193647b3cdcSGeorge Liu if (!http_helpers::isOctetAccepted( 3194647b3cdcSGeorge Liu req.getHeaderValue("Accept"))) 3195647b3cdcSGeorge Liu { 3196647b3cdcSGeorge Liu asyncResp->res.result( 3197647b3cdcSGeorge Liu boost::beast::http::status::bad_request); 3198647b3cdcSGeorge Liu return; 3199647b3cdcSGeorge Liu } 3200647b3cdcSGeorge Liu 3201647b3cdcSGeorge Liu uint64_t currentValue = 0; 3202647b3cdcSGeorge Liu uint16_t index = 0; 3203647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 3204647b3cdcSGeorge Liu { 3205647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", 3206647b3cdcSGeorge Liu postCodeID); 3207647b3cdcSGeorge Liu return; 3208647b3cdcSGeorge Liu } 3209647b3cdcSGeorge Liu 3210647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 3211647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 3212647b3cdcSGeorge Liu const boost::system::error_code ec, 3213647b3cdcSGeorge Liu const std::vector<std::tuple< 3214647b3cdcSGeorge Liu uint64_t, std::vector<uint8_t>>>& postcodes) { 3215647b3cdcSGeorge Liu if (ec.value() == EBADR) 3216647b3cdcSGeorge Liu { 3217647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3218647b3cdcSGeorge Liu "LogEntry", postCodeID); 3219647b3cdcSGeorge Liu return; 3220647b3cdcSGeorge Liu } 3221647b3cdcSGeorge Liu if (ec) 3222647b3cdcSGeorge Liu { 3223647b3cdcSGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3224647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 3225647b3cdcSGeorge Liu return; 3226647b3cdcSGeorge Liu } 3227647b3cdcSGeorge Liu 3228647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 3229647b3cdcSGeorge Liu if (value == std::string::npos || 3230647b3cdcSGeorge Liu postcodes.size() < currentValue) 3231647b3cdcSGeorge Liu { 3232647b3cdcSGeorge Liu BMCWEB_LOG_ERROR << "Wrong currentValue value"; 3233647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3234647b3cdcSGeorge Liu "LogEntry", postCodeID); 3235647b3cdcSGeorge Liu return; 3236647b3cdcSGeorge Liu } 3237647b3cdcSGeorge Liu 3238647b3cdcSGeorge Liu auto& [tID, code] = postcodes[value]; 3239647b3cdcSGeorge Liu if (code.empty()) 3240647b3cdcSGeorge Liu { 3241647b3cdcSGeorge Liu BMCWEB_LOG_INFO << "No found post code data"; 3242647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3243647b3cdcSGeorge Liu "LogEntry", postCodeID); 3244647b3cdcSGeorge Liu return; 3245647b3cdcSGeorge Liu } 3246647b3cdcSGeorge Liu 3247647b3cdcSGeorge Liu std::string_view strData( 3248647b3cdcSGeorge Liu reinterpret_cast<const char*>(code.data()), 3249647b3cdcSGeorge Liu code.size()); 3250647b3cdcSGeorge Liu 3251647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Type", 3252647b3cdcSGeorge Liu "application/octet-stream"); 3253647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Transfer-Encoding", 3254647b3cdcSGeorge Liu "Base64"); 3255647b3cdcSGeorge Liu asyncResp->res.body() = 3256647b3cdcSGeorge Liu crow::utility::base64encode(strData); 3257647b3cdcSGeorge Liu }, 3258647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 3259647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 3260647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", 3261647b3cdcSGeorge Liu index); 3262647b3cdcSGeorge Liu }); 3263647b3cdcSGeorge Liu } 3264647b3cdcSGeorge Liu 32657e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 3266a3316fc6SZhikuiRen { 32677e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 32687e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/") 3269ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 32707e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 32717e860f15SJohn Edward Broadbent [](const crow::Request&, 32727e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 32737e860f15SJohn Edward Broadbent const std::string& targetID) { 3274647b3cdcSGeorge Liu uint16_t bootIndex = 0; 3275647b3cdcSGeorge Liu uint64_t codeIndex = 0; 3276647b3cdcSGeorge Liu if (!parsePostCode(targetID, codeIndex, bootIndex)) 3277a3316fc6SZhikuiRen { 3278a3316fc6SZhikuiRen // Requested ID was not found 3279a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 3280a3316fc6SZhikuiRen return; 3281a3316fc6SZhikuiRen } 3282a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3283a3316fc6SZhikuiRen { 3284a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 32857e860f15SJohn Edward Broadbent << targetID; 3286a3316fc6SZhikuiRen } 3287a3316fc6SZhikuiRen 32887e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = 32897e860f15SJohn Edward Broadbent "#LogEntry.v1_4_0.LogEntry"; 3290a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3291a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3292a3316fc6SZhikuiRen "Entries"; 3293a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3294a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3295a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3296a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3297a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3298a3316fc6SZhikuiRen 3299a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 33007e860f15SJohn Edward Broadbent }); 3301a3316fc6SZhikuiRen } 3302a3316fc6SZhikuiRen 33031da66f75SEd Tanous } // namespace redfish 3304