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 181da66f75SEd Tanous #include "node.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> 25e1f26343SJason M. Bills 264851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 274851d45dSJason M. Bills #include <boost/beast/core/span.hpp> 281da66f75SEd Tanous #include <boost/container/flat_map.hpp> 291ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 300657843aSraviteja-b #include <dump_offload.hpp> 31cb92c03bSAndrew Geissler #include <error_messages.hpp> 321214b7e7SGunnar Mills 334418c7f0SJames Feist #include <filesystem> 34cd225da8SJason M. Bills #include <string_view> 35abf2add6SEd Tanous #include <variant> 361da66f75SEd Tanous 371da66f75SEd Tanous namespace redfish 381da66f75SEd Tanous { 391da66f75SEd Tanous 405b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 415b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 425b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 435b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 445b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 455b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 46424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 475b61b5e8SJason M. Bills constexpr char const* crashdumpRawPECIInterface = 48424c4176SJason M. Bills "com.intel.crashdump.SendRawPeci"; 496eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 506eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 511da66f75SEd Tanous 524851d45dSJason M. Bills namespace message_registries 534851d45dSJason M. Bills { 544851d45dSJason M. Bills static const Message* getMessageFromRegistry( 554851d45dSJason M. Bills const std::string& messageKey, 564851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 574851d45dSJason M. Bills { 584851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 594851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 604851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 614851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 624851d45dSJason M. Bills messageKey.c_str()); 634851d45dSJason M. Bills }); 644851d45dSJason M. Bills if (messageIt != registry.cend()) 654851d45dSJason M. Bills { 664851d45dSJason M. Bills return &messageIt->second; 674851d45dSJason M. Bills } 684851d45dSJason M. Bills 694851d45dSJason M. Bills return nullptr; 704851d45dSJason M. Bills } 714851d45dSJason M. Bills 724851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 734851d45dSJason M. Bills { 744851d45dSJason M. Bills // Redfish MessageIds are in the form 754851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 764851d45dSJason M. Bills // the right Message 774851d45dSJason M. Bills std::vector<std::string> fields; 784851d45dSJason M. Bills fields.reserve(4); 794851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 804851d45dSJason M. Bills std::string& registryName = fields[0]; 814851d45dSJason M. Bills std::string& messageKey = fields[3]; 824851d45dSJason M. Bills 834851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 844851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 854851d45dSJason M. Bills { 864851d45dSJason M. Bills return getMessageFromRegistry( 874851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 884851d45dSJason M. Bills } 894851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 904851d45dSJason M. Bills { 914851d45dSJason M. Bills return getMessageFromRegistry( 924851d45dSJason M. Bills messageKey, 934851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 944851d45dSJason M. Bills } 954851d45dSJason M. Bills return nullptr; 964851d45dSJason M. Bills } 974851d45dSJason M. Bills } // namespace message_registries 984851d45dSJason M. Bills 99f6150403SJames Feist namespace fs = std::filesystem; 1001da66f75SEd Tanous 101cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 10219bd78d9SPatrick Williams std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, 103cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 104cb92c03bSAndrew Geissler 105cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 106cb92c03bSAndrew Geissler sdbusplus::message::object_path, 107cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 108cb92c03bSAndrew Geissler 109cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 110cb92c03bSAndrew Geissler { 111cb92c03bSAndrew Geissler if (s == "xyz.openbmc_project.Logging.Entry.Level.Alert") 112cb92c03bSAndrew Geissler { 113cb92c03bSAndrew Geissler return "Critical"; 114cb92c03bSAndrew Geissler } 115cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") 116cb92c03bSAndrew Geissler { 117cb92c03bSAndrew Geissler return "Critical"; 118cb92c03bSAndrew Geissler } 119cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Debug") 120cb92c03bSAndrew Geissler { 121cb92c03bSAndrew Geissler return "OK"; 122cb92c03bSAndrew Geissler } 123cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") 124cb92c03bSAndrew Geissler { 125cb92c03bSAndrew Geissler return "Critical"; 126cb92c03bSAndrew Geissler } 127cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Error") 128cb92c03bSAndrew Geissler { 129cb92c03bSAndrew Geissler return "Critical"; 130cb92c03bSAndrew Geissler } 131cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") 132cb92c03bSAndrew Geissler { 133cb92c03bSAndrew Geissler return "OK"; 134cb92c03bSAndrew Geissler } 135cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Notice") 136cb92c03bSAndrew Geissler { 137cb92c03bSAndrew Geissler return "OK"; 138cb92c03bSAndrew Geissler } 139cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 140cb92c03bSAndrew Geissler { 141cb92c03bSAndrew Geissler return "Warning"; 142cb92c03bSAndrew Geissler } 143cb92c03bSAndrew Geissler return ""; 144cb92c03bSAndrew Geissler } 145cb92c03bSAndrew Geissler 14616428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal, 14739e77504SEd Tanous const std::string_view& field, 14839e77504SEd Tanous std::string_view& contents) 14916428a1aSJason M. Bills { 15016428a1aSJason M. Bills const char* data = nullptr; 15116428a1aSJason M. Bills size_t length = 0; 15216428a1aSJason M. Bills int ret = 0; 15316428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 154271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 155271584abSEd Tanous reinterpret_cast<const void**>(&data), &length); 15616428a1aSJason M. Bills if (ret < 0) 15716428a1aSJason M. Bills { 15816428a1aSJason M. Bills return ret; 15916428a1aSJason M. Bills } 16039e77504SEd Tanous contents = std::string_view(data, length); 16116428a1aSJason M. Bills // Only use the content after the "=" character. 16216428a1aSJason M. Bills contents.remove_prefix(std::min(contents.find("=") + 1, contents.size())); 16316428a1aSJason M. Bills return ret; 16416428a1aSJason M. Bills } 16516428a1aSJason M. Bills 16616428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal, 16739e77504SEd Tanous const std::string_view& field, const int& base, 168271584abSEd Tanous long int& contents) 16916428a1aSJason M. Bills { 17016428a1aSJason M. Bills int ret = 0; 17139e77504SEd Tanous std::string_view metadata; 17216428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 17316428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 17416428a1aSJason M. Bills if (ret < 0) 17516428a1aSJason M. Bills { 17616428a1aSJason M. Bills return ret; 17716428a1aSJason M. Bills } 178b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 17916428a1aSJason M. Bills return ret; 18016428a1aSJason M. Bills } 18116428a1aSJason M. Bills 182a3316fc6SZhikuiRen static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp) 183a3316fc6SZhikuiRen { 184a3316fc6SZhikuiRen int ret = 0; 185a3316fc6SZhikuiRen uint64_t timestamp = 0; 186a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 187a3316fc6SZhikuiRen if (ret < 0) 188a3316fc6SZhikuiRen { 189a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 190a3316fc6SZhikuiRen << strerror(-ret); 191a3316fc6SZhikuiRen return false; 192a3316fc6SZhikuiRen } 1939c620e21SAsmitha Karunanithi entryTimestamp = crow::utility::getDateTime( 1949c620e21SAsmitha Karunanithi static_cast<std::time_t>(timestamp / 1000 / 1000)); 1959c620e21SAsmitha Karunanithi return true; 196a3316fc6SZhikuiRen } 197a3316fc6SZhikuiRen 19816428a1aSJason M. Bills static bool getSkipParam(crow::Response& res, const crow::Request& req, 199271584abSEd Tanous uint64_t& skip) 20016428a1aSJason M. Bills { 2015a7e877eSJames Feist boost::urls::url_view::params_type::iterator it = 2025a7e877eSJames Feist req.urlParams.find("$skip"); 2035a7e877eSJames Feist if (it != req.urlParams.end()) 20416428a1aSJason M. Bills { 2055a7e877eSJames Feist std::string skipParam = it->value(); 20616428a1aSJason M. Bills char* ptr = nullptr; 2075a7e877eSJames Feist skip = std::strtoul(skipParam.c_str(), &ptr, 10); 2085a7e877eSJames Feist if (skipParam.empty() || *ptr != '\0') 20916428a1aSJason M. Bills { 21016428a1aSJason M. Bills 21116428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(skipParam), 21216428a1aSJason M. Bills "$skip"); 21316428a1aSJason M. Bills return false; 21416428a1aSJason M. Bills } 21516428a1aSJason M. Bills } 21616428a1aSJason M. Bills return true; 21716428a1aSJason M. Bills } 21816428a1aSJason M. Bills 219271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 22016428a1aSJason M. Bills static bool getTopParam(crow::Response& res, const crow::Request& req, 221271584abSEd Tanous uint64_t& top) 22216428a1aSJason M. Bills { 2235a7e877eSJames Feist boost::urls::url_view::params_type::iterator it = 2245a7e877eSJames Feist req.urlParams.find("$top"); 2255a7e877eSJames Feist if (it != req.urlParams.end()) 22616428a1aSJason M. Bills { 2275a7e877eSJames Feist std::string topParam = it->value(); 22816428a1aSJason M. Bills char* ptr = nullptr; 2295a7e877eSJames Feist top = std::strtoul(topParam.c_str(), &ptr, 10); 2305a7e877eSJames Feist if (topParam.empty() || *ptr != '\0') 23116428a1aSJason M. Bills { 23216428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(topParam), 23316428a1aSJason M. Bills "$top"); 23416428a1aSJason M. Bills return false; 23516428a1aSJason M. Bills } 236271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 23716428a1aSJason M. Bills { 23816428a1aSJason M. Bills 23916428a1aSJason M. Bills messages::queryParameterOutOfRange( 24016428a1aSJason M. Bills res, std::to_string(top), "$top", 24116428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 24216428a1aSJason M. Bills return false; 24316428a1aSJason M. Bills } 24416428a1aSJason M. Bills } 24516428a1aSJason M. Bills return true; 24616428a1aSJason M. Bills } 24716428a1aSJason M. Bills 248e85d6b16SJason M. Bills static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 249e85d6b16SJason M. Bills const bool firstEntry = true) 25016428a1aSJason M. Bills { 25116428a1aSJason M. Bills int ret = 0; 25216428a1aSJason M. Bills static uint64_t prevTs = 0; 25316428a1aSJason M. Bills static int index = 0; 254e85d6b16SJason M. Bills if (firstEntry) 255e85d6b16SJason M. Bills { 256e85d6b16SJason M. Bills prevTs = 0; 257e85d6b16SJason M. Bills } 258e85d6b16SJason M. Bills 25916428a1aSJason M. Bills // Get the entry timestamp 26016428a1aSJason M. Bills uint64_t curTs = 0; 26116428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 26216428a1aSJason M. Bills if (ret < 0) 26316428a1aSJason M. Bills { 26416428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 26516428a1aSJason M. Bills << strerror(-ret); 26616428a1aSJason M. Bills return false; 26716428a1aSJason M. Bills } 26816428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 26916428a1aSJason M. Bills if (curTs == prevTs) 27016428a1aSJason M. Bills { 27116428a1aSJason M. Bills index++; 27216428a1aSJason M. Bills } 27316428a1aSJason M. Bills else 27416428a1aSJason M. Bills { 27516428a1aSJason M. Bills // Otherwise, reset it 27616428a1aSJason M. Bills index = 0; 27716428a1aSJason M. Bills } 27816428a1aSJason M. Bills // Save the timestamp 27916428a1aSJason M. Bills prevTs = curTs; 28016428a1aSJason M. Bills 28116428a1aSJason M. Bills entryID = std::to_string(curTs); 28216428a1aSJason M. Bills if (index > 0) 28316428a1aSJason M. Bills { 28416428a1aSJason M. Bills entryID += "_" + std::to_string(index); 28516428a1aSJason M. Bills } 28616428a1aSJason M. Bills return true; 28716428a1aSJason M. Bills } 28816428a1aSJason M. Bills 289e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 290e85d6b16SJason M. Bills const bool firstEntry = true) 29195820184SJason M. Bills { 292271584abSEd Tanous static time_t prevTs = 0; 29395820184SJason M. Bills static int index = 0; 294e85d6b16SJason M. Bills if (firstEntry) 295e85d6b16SJason M. Bills { 296e85d6b16SJason M. Bills prevTs = 0; 297e85d6b16SJason M. Bills } 298e85d6b16SJason M. Bills 29995820184SJason M. Bills // Get the entry timestamp 300271584abSEd Tanous std::time_t curTs = 0; 30195820184SJason M. Bills std::tm timeStruct = {}; 30295820184SJason M. Bills std::istringstream entryStream(logEntry); 30395820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 30495820184SJason M. Bills { 30595820184SJason M. Bills curTs = std::mktime(&timeStruct); 30695820184SJason M. Bills } 30795820184SJason M. Bills // If the timestamp isn't unique, increment the index 30895820184SJason M. Bills if (curTs == prevTs) 30995820184SJason M. Bills { 31095820184SJason M. Bills index++; 31195820184SJason M. Bills } 31295820184SJason M. Bills else 31395820184SJason M. Bills { 31495820184SJason M. Bills // Otherwise, reset it 31595820184SJason M. Bills index = 0; 31695820184SJason M. Bills } 31795820184SJason M. Bills // Save the timestamp 31895820184SJason M. Bills prevTs = curTs; 31995820184SJason M. Bills 32095820184SJason M. Bills entryID = std::to_string(curTs); 32195820184SJason M. Bills if (index > 0) 32295820184SJason M. Bills { 32395820184SJason M. Bills entryID += "_" + std::to_string(index); 32495820184SJason M. Bills } 32595820184SJason M. Bills return true; 32695820184SJason M. Bills } 32795820184SJason M. Bills 32816428a1aSJason M. Bills static bool getTimestampFromID(crow::Response& res, const std::string& entryID, 329271584abSEd Tanous uint64_t& timestamp, uint64_t& index) 33016428a1aSJason M. Bills { 33116428a1aSJason M. Bills if (entryID.empty()) 33216428a1aSJason M. Bills { 33316428a1aSJason M. Bills return false; 33416428a1aSJason M. Bills } 33516428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 33639e77504SEd Tanous std::string_view tsStr(entryID); 33716428a1aSJason M. Bills 33816428a1aSJason M. Bills auto underscorePos = tsStr.find("_"); 33916428a1aSJason M. Bills if (underscorePos != tsStr.npos) 34016428a1aSJason M. Bills { 34116428a1aSJason M. Bills // Timestamp has an index 34216428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 34339e77504SEd Tanous std::string_view indexStr(entryID); 34416428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 34516428a1aSJason M. Bills std::size_t pos; 34616428a1aSJason M. Bills try 34716428a1aSJason M. Bills { 34839e77504SEd Tanous index = std::stoul(std::string(indexStr), &pos); 34916428a1aSJason M. Bills } 350271584abSEd Tanous catch (std::invalid_argument&) 35116428a1aSJason M. Bills { 35216428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 35316428a1aSJason M. Bills return false; 35416428a1aSJason M. Bills } 355271584abSEd Tanous catch (std::out_of_range&) 35616428a1aSJason M. Bills { 35716428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 35816428a1aSJason M. Bills return false; 35916428a1aSJason M. Bills } 36016428a1aSJason M. Bills if (pos != indexStr.size()) 36116428a1aSJason M. Bills { 36216428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 36316428a1aSJason M. Bills return false; 36416428a1aSJason M. Bills } 36516428a1aSJason M. Bills } 36616428a1aSJason M. Bills // Timestamp has no index 36716428a1aSJason M. Bills std::size_t pos; 36816428a1aSJason M. Bills try 36916428a1aSJason M. Bills { 37039e77504SEd Tanous timestamp = std::stoull(std::string(tsStr), &pos); 37116428a1aSJason M. Bills } 372271584abSEd Tanous catch (std::invalid_argument&) 37316428a1aSJason M. Bills { 37416428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 37516428a1aSJason M. Bills return false; 37616428a1aSJason M. Bills } 377271584abSEd Tanous catch (std::out_of_range&) 37816428a1aSJason M. Bills { 37916428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 38016428a1aSJason M. Bills return false; 38116428a1aSJason M. Bills } 38216428a1aSJason M. Bills if (pos != tsStr.size()) 38316428a1aSJason M. Bills { 38416428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 38516428a1aSJason M. Bills return false; 38616428a1aSJason M. Bills } 38716428a1aSJason M. Bills return true; 38816428a1aSJason M. Bills } 38916428a1aSJason M. Bills 39095820184SJason M. Bills static bool 39195820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 39295820184SJason M. Bills { 39395820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 39495820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 39595820184SJason M. Bills 39695820184SJason M. Bills // Loop through the directory looking for redfish log files 39795820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 39895820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 39995820184SJason M. Bills { 40095820184SJason M. Bills // If we find a redfish log file, save the path 40195820184SJason M. Bills std::string filename = dirEnt.path().filename(); 40295820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 40395820184SJason M. Bills { 40495820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 40595820184SJason M. Bills } 40695820184SJason M. Bills } 40795820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 40895820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 40995820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 41095820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 41195820184SJason M. Bills 41295820184SJason M. Bills return !redfishLogFiles.empty(); 41395820184SJason M. Bills } 41495820184SJason M. Bills 4155cb1dd27SAsmitha Karunanithi inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp, 4165cb1dd27SAsmitha Karunanithi const std::string& dumpType) 4175cb1dd27SAsmitha Karunanithi { 4185cb1dd27SAsmitha Karunanithi std::string dumpPath; 4195cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 4205cb1dd27SAsmitha Karunanithi { 4215cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 4225cb1dd27SAsmitha Karunanithi } 4235cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 4245cb1dd27SAsmitha Karunanithi { 4255cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 4265cb1dd27SAsmitha Karunanithi } 4275cb1dd27SAsmitha Karunanithi else 4285cb1dd27SAsmitha Karunanithi { 4295cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 4305cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4315cb1dd27SAsmitha Karunanithi return; 4325cb1dd27SAsmitha Karunanithi } 4335cb1dd27SAsmitha Karunanithi 4345cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 4355cb1dd27SAsmitha Karunanithi [asyncResp, dumpPath, dumpType](const boost::system::error_code ec, 4365cb1dd27SAsmitha Karunanithi GetManagedObjectsType& resp) { 4375cb1dd27SAsmitha Karunanithi if (ec) 4385cb1dd27SAsmitha Karunanithi { 4395cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4405cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4415cb1dd27SAsmitha Karunanithi return; 4425cb1dd27SAsmitha Karunanithi } 4435cb1dd27SAsmitha Karunanithi 4445cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4455cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 4465cb1dd27SAsmitha Karunanithi 4475cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4485cb1dd27SAsmitha Karunanithi { 4495cb1dd27SAsmitha Karunanithi bool foundDumpEntry = false; 4505cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4515cb1dd27SAsmitha Karunanithi { 4525cb1dd27SAsmitha Karunanithi if (interfaceMap.first == 4535cb1dd27SAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 4545cb1dd27SAsmitha Karunanithi { 4555cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 4565cb1dd27SAsmitha Karunanithi break; 4575cb1dd27SAsmitha Karunanithi } 4585cb1dd27SAsmitha Karunanithi } 4595cb1dd27SAsmitha Karunanithi 4605cb1dd27SAsmitha Karunanithi if (foundDumpEntry == false) 4615cb1dd27SAsmitha Karunanithi { 4625cb1dd27SAsmitha Karunanithi continue; 4635cb1dd27SAsmitha Karunanithi } 4645cb1dd27SAsmitha Karunanithi std::time_t timestamp; 4655cb1dd27SAsmitha Karunanithi uint64_t size = 0; 4665cb1dd27SAsmitha Karunanithi entriesArray.push_back({}); 4675cb1dd27SAsmitha Karunanithi nlohmann::json& thisEntry = entriesArray.back(); 4685cb1dd27SAsmitha Karunanithi const std::string& path = 4695cb1dd27SAsmitha Karunanithi static_cast<const std::string&>(object.first); 4705cb1dd27SAsmitha Karunanithi std::size_t lastPos = path.rfind("/"); 4715cb1dd27SAsmitha Karunanithi if (lastPos == std::string::npos) 4725cb1dd27SAsmitha Karunanithi { 4735cb1dd27SAsmitha Karunanithi continue; 4745cb1dd27SAsmitha Karunanithi } 4755cb1dd27SAsmitha Karunanithi std::string entryID = path.substr(lastPos + 1); 4765cb1dd27SAsmitha Karunanithi 4775cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4785cb1dd27SAsmitha Karunanithi { 4795cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 4805cb1dd27SAsmitha Karunanithi { 4815cb1dd27SAsmitha Karunanithi 4825cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4835cb1dd27SAsmitha Karunanithi { 4845cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4855cb1dd27SAsmitha Karunanithi { 4865cb1dd27SAsmitha Karunanithi auto sizePtr = 4875cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4885cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4895cb1dd27SAsmitha Karunanithi { 4905cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4915cb1dd27SAsmitha Karunanithi break; 4925cb1dd27SAsmitha Karunanithi } 4935cb1dd27SAsmitha Karunanithi size = *sizePtr; 4945cb1dd27SAsmitha Karunanithi break; 4955cb1dd27SAsmitha Karunanithi } 4965cb1dd27SAsmitha Karunanithi } 4975cb1dd27SAsmitha Karunanithi } 4985cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4995cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 5005cb1dd27SAsmitha Karunanithi { 5015cb1dd27SAsmitha Karunanithi 5025cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 5035cb1dd27SAsmitha Karunanithi { 5045cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 5055cb1dd27SAsmitha Karunanithi { 5065cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 5075cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5085cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 5095cb1dd27SAsmitha Karunanithi { 5105cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5115cb1dd27SAsmitha Karunanithi break; 5125cb1dd27SAsmitha Karunanithi } 5135cb1dd27SAsmitha Karunanithi timestamp = 5145cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 5155cb1dd27SAsmitha Karunanithi break; 5165cb1dd27SAsmitha Karunanithi } 5175cb1dd27SAsmitha Karunanithi } 5185cb1dd27SAsmitha Karunanithi } 5195cb1dd27SAsmitha Karunanithi } 5205cb1dd27SAsmitha Karunanithi 5215cb1dd27SAsmitha Karunanithi thisEntry["@odata.type"] = "#LogEntry.v1_5_1.LogEntry"; 5225cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 5235cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 5245cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5255cb1dd27SAsmitha Karunanithi thisEntry["Created"] = crow::utility::getDateTime(timestamp); 5265cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 5275cb1dd27SAsmitha Karunanithi 5285cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["@odata.type"] = 5295cb1dd27SAsmitha Karunanithi "#OemLogEntry.v1_0_0.OpenBmc"; 5305cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] = size; 5315cb1dd27SAsmitha Karunanithi 5325cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5335cb1dd27SAsmitha Karunanithi { 5345cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] = 5355cb1dd27SAsmitha Karunanithi "Manager"; 5365cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] = 5375cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 5385cb1dd27SAsmitha Karunanithi "attachment/" + 5395cb1dd27SAsmitha Karunanithi entryID; 5405cb1dd27SAsmitha Karunanithi } 5415cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5425cb1dd27SAsmitha Karunanithi { 5435cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] = "OEM"; 5445cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] = 5455cb1dd27SAsmitha Karunanithi "System"; 5465cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] = 5475cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/" 5485cb1dd27SAsmitha Karunanithi "attachment/" + 5495cb1dd27SAsmitha Karunanithi entryID; 5505cb1dd27SAsmitha Karunanithi } 5515cb1dd27SAsmitha Karunanithi } 5525cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 5535cb1dd27SAsmitha Karunanithi entriesArray.size(); 5545cb1dd27SAsmitha Karunanithi }, 5555cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5565cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5575cb1dd27SAsmitha Karunanithi } 5585cb1dd27SAsmitha Karunanithi 5595cb1dd27SAsmitha Karunanithi inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp, 5605cb1dd27SAsmitha Karunanithi const std::string& entryID, 5615cb1dd27SAsmitha Karunanithi const std::string& dumpType) 5625cb1dd27SAsmitha Karunanithi { 5635cb1dd27SAsmitha Karunanithi std::string dumpPath; 5645cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5655cb1dd27SAsmitha Karunanithi { 5665cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5675cb1dd27SAsmitha Karunanithi } 5685cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5695cb1dd27SAsmitha Karunanithi { 5705cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5715cb1dd27SAsmitha Karunanithi } 5725cb1dd27SAsmitha Karunanithi else 5735cb1dd27SAsmitha Karunanithi { 5745cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5755cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5765cb1dd27SAsmitha Karunanithi return; 5775cb1dd27SAsmitha Karunanithi } 5785cb1dd27SAsmitha Karunanithi 5795cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 5805cb1dd27SAsmitha Karunanithi [asyncResp, entryID, dumpPath, dumpType]( 5815cb1dd27SAsmitha Karunanithi const boost::system::error_code ec, GetManagedObjectsType& resp) { 5825cb1dd27SAsmitha Karunanithi if (ec) 5835cb1dd27SAsmitha Karunanithi { 5845cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5855cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5865cb1dd27SAsmitha Karunanithi return; 5875cb1dd27SAsmitha Karunanithi } 5885cb1dd27SAsmitha Karunanithi 5895cb1dd27SAsmitha Karunanithi for (auto& objectPath : resp) 5905cb1dd27SAsmitha Karunanithi { 5915cb1dd27SAsmitha Karunanithi if (objectPath.first.str.find( 5925cb1dd27SAsmitha Karunanithi "/xyz/openbmc_project/dump/entry/" + entryID) == 5935cb1dd27SAsmitha Karunanithi std::string::npos) 5945cb1dd27SAsmitha Karunanithi { 5955cb1dd27SAsmitha Karunanithi continue; 5965cb1dd27SAsmitha Karunanithi } 5975cb1dd27SAsmitha Karunanithi 5985cb1dd27SAsmitha Karunanithi bool foundDumpEntry = false; 5995cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 6005cb1dd27SAsmitha Karunanithi { 6015cb1dd27SAsmitha Karunanithi if (interfaceMap.first == 6025cb1dd27SAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 6035cb1dd27SAsmitha Karunanithi { 6045cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 6055cb1dd27SAsmitha Karunanithi break; 6065cb1dd27SAsmitha Karunanithi } 6075cb1dd27SAsmitha Karunanithi } 6085cb1dd27SAsmitha Karunanithi if (foundDumpEntry == false) 6095cb1dd27SAsmitha Karunanithi { 6105cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 6115cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6125cb1dd27SAsmitha Karunanithi return; 6135cb1dd27SAsmitha Karunanithi } 6145cb1dd27SAsmitha Karunanithi 6155cb1dd27SAsmitha Karunanithi std::time_t timestamp; 6165cb1dd27SAsmitha Karunanithi uint64_t size = 0; 6175cb1dd27SAsmitha Karunanithi 6185cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 6195cb1dd27SAsmitha Karunanithi { 6205cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 6215cb1dd27SAsmitha Karunanithi { 6225cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6235cb1dd27SAsmitha Karunanithi { 6245cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 6255cb1dd27SAsmitha Karunanithi { 6265cb1dd27SAsmitha Karunanithi auto sizePtr = 6275cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6285cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 6295cb1dd27SAsmitha Karunanithi { 6305cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6315cb1dd27SAsmitha Karunanithi break; 6325cb1dd27SAsmitha Karunanithi } 6335cb1dd27SAsmitha Karunanithi size = *sizePtr; 6345cb1dd27SAsmitha Karunanithi break; 6355cb1dd27SAsmitha Karunanithi } 6365cb1dd27SAsmitha Karunanithi } 6375cb1dd27SAsmitha Karunanithi } 6385cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 6395cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 6405cb1dd27SAsmitha Karunanithi { 6415cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6425cb1dd27SAsmitha Karunanithi { 6435cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 6445cb1dd27SAsmitha Karunanithi { 6455cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 6465cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6475cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 6485cb1dd27SAsmitha Karunanithi { 6495cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6505cb1dd27SAsmitha Karunanithi break; 6515cb1dd27SAsmitha Karunanithi } 6525cb1dd27SAsmitha Karunanithi timestamp = 6535cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 6545cb1dd27SAsmitha Karunanithi break; 6555cb1dd27SAsmitha Karunanithi } 6565cb1dd27SAsmitha Karunanithi } 6575cb1dd27SAsmitha Karunanithi } 6585cb1dd27SAsmitha Karunanithi } 6595cb1dd27SAsmitha Karunanithi 6605cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 6615cb1dd27SAsmitha Karunanithi "#LogEntry.v1_5_1.LogEntry"; 6625cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6635cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6645cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6655cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6665cb1dd27SAsmitha Karunanithi crow::utility::getDateTime(timestamp); 6675cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6685cb1dd27SAsmitha Karunanithi 6695cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 6705cb1dd27SAsmitha Karunanithi "#OemLogEntry.v1_0_0.OpenBmc"; 6715cb1dd27SAsmitha Karunanithi asyncResp->res 6725cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] = 6735cb1dd27SAsmitha Karunanithi size; 6745cb1dd27SAsmitha Karunanithi 6755cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6765cb1dd27SAsmitha Karunanithi { 6775cb1dd27SAsmitha Karunanithi asyncResp->res 6785cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] = 6795cb1dd27SAsmitha Karunanithi "Manager"; 6805cb1dd27SAsmitha Karunanithi asyncResp->res 6815cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] = 6825cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 6835cb1dd27SAsmitha Karunanithi "attachment/" + 6845cb1dd27SAsmitha Karunanithi entryID; 6855cb1dd27SAsmitha Karunanithi } 6865cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6875cb1dd27SAsmitha Karunanithi { 6885cb1dd27SAsmitha Karunanithi asyncResp->res 6895cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] = 6905cb1dd27SAsmitha Karunanithi "OEM"; 6915cb1dd27SAsmitha Karunanithi asyncResp->res 6925cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] = 6935cb1dd27SAsmitha Karunanithi "System"; 6945cb1dd27SAsmitha Karunanithi asyncResp->res 6955cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] = 6965cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/" 6975cb1dd27SAsmitha Karunanithi "attachment/" + 6985cb1dd27SAsmitha Karunanithi entryID; 6995cb1dd27SAsmitha Karunanithi } 7005cb1dd27SAsmitha Karunanithi } 7015cb1dd27SAsmitha Karunanithi }, 7025cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 7035cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 7045cb1dd27SAsmitha Karunanithi } 7055cb1dd27SAsmitha Karunanithi 7065cb1dd27SAsmitha Karunanithi inline void deleteDumpEntry(crow::Response& res, const std::string& entryID) 7075cb1dd27SAsmitha Karunanithi { 7085cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 7095cb1dd27SAsmitha Karunanithi 7105cb1dd27SAsmitha Karunanithi auto respHandler = [asyncResp](const boost::system::error_code ec) { 7115cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 7125cb1dd27SAsmitha Karunanithi if (ec) 7135cb1dd27SAsmitha Karunanithi { 7145cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 7155cb1dd27SAsmitha Karunanithi << ec; 7165cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 7175cb1dd27SAsmitha Karunanithi return; 7185cb1dd27SAsmitha Karunanithi } 7195cb1dd27SAsmitha Karunanithi }; 7205cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 7215cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 7225cb1dd27SAsmitha Karunanithi "/xyz/openbmc_project/dump/entry/" + entryID, 7235cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 7245cb1dd27SAsmitha Karunanithi } 7255cb1dd27SAsmitha Karunanithi 726a43be80fSAsmitha Karunanithi inline void createDumpTaskCallback(const crow::Request& req, 727a43be80fSAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp, 728a43be80fSAsmitha Karunanithi const uint32_t& dumpId, 729a43be80fSAsmitha Karunanithi const std::string& dumpPath, 730a43be80fSAsmitha Karunanithi const std::string& dumpType) 731a43be80fSAsmitha Karunanithi { 732a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 733cb13a392SEd Tanous [dumpId, dumpPath, dumpType, asyncResp]( 734a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 735a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 736cb13a392SEd Tanous if (err) 737cb13a392SEd Tanous { 738cb13a392SEd Tanous messages::internalError(asyncResp->res); 739cb13a392SEd Tanous return false; 740cb13a392SEd Tanous } 741a43be80fSAsmitha Karunanithi std::vector<std::pair< 742a43be80fSAsmitha Karunanithi std::string, 743a43be80fSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string>>>>> 744a43be80fSAsmitha Karunanithi interfacesList; 745a43be80fSAsmitha Karunanithi 746a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 747a43be80fSAsmitha Karunanithi 748a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 749a43be80fSAsmitha Karunanithi 750a43be80fSAsmitha Karunanithi for (auto& interface : interfacesList) 751a43be80fSAsmitha Karunanithi { 752a43be80fSAsmitha Karunanithi if (interface.first == 753a43be80fSAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 754a43be80fSAsmitha Karunanithi { 755a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 756a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 757a43be80fSAsmitha Karunanithi 758a43be80fSAsmitha Karunanithi std::string headerLoc = 759a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 760a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 761a43be80fSAsmitha Karunanithi std::move(headerLoc)); 762a43be80fSAsmitha Karunanithi 763a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 764a43be80fSAsmitha Karunanithi return task::completed; 765a43be80fSAsmitha Karunanithi } 766a43be80fSAsmitha Karunanithi } 767a43be80fSAsmitha Karunanithi return !task::completed; 768a43be80fSAsmitha Karunanithi }, 769a43be80fSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus." 770a43be80fSAsmitha Karunanithi "ObjectManager'," 771a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 772a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 773a43be80fSAsmitha Karunanithi 774a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 775a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 776a43be80fSAsmitha Karunanithi task->payload.emplace(req); 777a43be80fSAsmitha Karunanithi } 778a43be80fSAsmitha Karunanithi 779a43be80fSAsmitha Karunanithi inline void createDump(crow::Response& res, const crow::Request& req, 780a43be80fSAsmitha Karunanithi const std::string& dumpType) 781a43be80fSAsmitha Karunanithi { 782a43be80fSAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 783a43be80fSAsmitha Karunanithi 784a43be80fSAsmitha Karunanithi std::string dumpPath; 785a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 786a43be80fSAsmitha Karunanithi { 787a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 788a43be80fSAsmitha Karunanithi } 789a43be80fSAsmitha Karunanithi else if (dumpType == "System") 790a43be80fSAsmitha Karunanithi { 791a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 792a43be80fSAsmitha Karunanithi } 793a43be80fSAsmitha Karunanithi else 794a43be80fSAsmitha Karunanithi { 795a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 796a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 797a43be80fSAsmitha Karunanithi return; 798a43be80fSAsmitha Karunanithi } 799a43be80fSAsmitha Karunanithi 800a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 801a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 802a43be80fSAsmitha Karunanithi 803a43be80fSAsmitha Karunanithi if (!redfish::json_util::readJson( 804a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 805a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 806a43be80fSAsmitha Karunanithi { 807a43be80fSAsmitha Karunanithi return; 808a43be80fSAsmitha Karunanithi } 809a43be80fSAsmitha Karunanithi 810a43be80fSAsmitha Karunanithi if (dumpType == "System") 811a43be80fSAsmitha Karunanithi { 812a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 813a43be80fSAsmitha Karunanithi { 814a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 815a43be80fSAsmitha Karunanithi "'DiagnosticDataType'/" 816a43be80fSAsmitha Karunanithi "'OEMDiagnosticDataType' value not found!"; 817a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 818a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 819a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 820a43be80fSAsmitha Karunanithi return; 821a43be80fSAsmitha Karunanithi } 822a43be80fSAsmitha Karunanithi else if ((*oemDiagnosticDataType != "System") || 823a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 824a43be80fSAsmitha Karunanithi { 825a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 826a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 827a43be80fSAsmitha Karunanithi "System Dump creation parameters"); 828a43be80fSAsmitha Karunanithi return; 829a43be80fSAsmitha Karunanithi } 830a43be80fSAsmitha Karunanithi } 831a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 832a43be80fSAsmitha Karunanithi { 833a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 834a43be80fSAsmitha Karunanithi { 835a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 836a43be80fSAsmitha Karunanithi "'DiagnosticDataType' not found!"; 837a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 838a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 839a43be80fSAsmitha Karunanithi return; 840a43be80fSAsmitha Karunanithi } 841a43be80fSAsmitha Karunanithi else if (*diagnosticDataType != "Manager") 842a43be80fSAsmitha Karunanithi { 843a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 844a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 845a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 846a43be80fSAsmitha Karunanithi "BMC Dump creation parameters"); 847a43be80fSAsmitha Karunanithi return; 848a43be80fSAsmitha Karunanithi } 849a43be80fSAsmitha Karunanithi } 850a43be80fSAsmitha Karunanithi 851a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 852a43be80fSAsmitha Karunanithi [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec, 853a43be80fSAsmitha Karunanithi const uint32_t& dumpId) { 854a43be80fSAsmitha Karunanithi if (ec) 855a43be80fSAsmitha Karunanithi { 856a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 857a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 858a43be80fSAsmitha Karunanithi return; 859a43be80fSAsmitha Karunanithi } 860a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 861a43be80fSAsmitha Karunanithi 862a43be80fSAsmitha Karunanithi createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType); 863a43be80fSAsmitha Karunanithi }, 864a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 865a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 866a43be80fSAsmitha Karunanithi } 867a43be80fSAsmitha Karunanithi 86880319af1SAsmitha Karunanithi inline void clearDump(crow::Response& res, const std::string& dumpInterface) 86980319af1SAsmitha Karunanithi { 87080319af1SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 87180319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 87280319af1SAsmitha Karunanithi [asyncResp](const boost::system::error_code ec, 87380319af1SAsmitha Karunanithi const std::vector<std::string>& subTreePaths) { 87480319af1SAsmitha Karunanithi if (ec) 87580319af1SAsmitha Karunanithi { 87680319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 87780319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 87880319af1SAsmitha Karunanithi return; 87980319af1SAsmitha Karunanithi } 88080319af1SAsmitha Karunanithi 88180319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 88280319af1SAsmitha Karunanithi { 88380319af1SAsmitha Karunanithi std::size_t pos = path.rfind("/"); 88480319af1SAsmitha Karunanithi if (pos != std::string::npos) 88580319af1SAsmitha Karunanithi { 88680319af1SAsmitha Karunanithi std::string logID = path.substr(pos + 1); 88780319af1SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, logID); 88880319af1SAsmitha Karunanithi } 88980319af1SAsmitha Karunanithi } 89080319af1SAsmitha Karunanithi }, 89180319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 89280319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 89380319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 89480319af1SAsmitha Karunanithi "/xyz/openbmc_project/dump", 0, 89580319af1SAsmitha Karunanithi std::array<std::string, 1>{dumpInterface}); 89680319af1SAsmitha Karunanithi } 89780319af1SAsmitha Karunanithi 898043a0536SJohnathan Mantey static void ParseCrashdumpParameters( 899043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params, 900043a0536SJohnathan Mantey std::string& filename, std::string& timestamp, std::string& logfile) 901043a0536SJohnathan Mantey { 902043a0536SJohnathan Mantey for (auto property : params) 903043a0536SJohnathan Mantey { 904043a0536SJohnathan Mantey if (property.first == "Timestamp") 905043a0536SJohnathan Mantey { 906043a0536SJohnathan Mantey const std::string* value = 9078d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 908043a0536SJohnathan Mantey if (value != nullptr) 909043a0536SJohnathan Mantey { 910043a0536SJohnathan Mantey timestamp = *value; 911043a0536SJohnathan Mantey } 912043a0536SJohnathan Mantey } 913043a0536SJohnathan Mantey else if (property.first == "Filename") 914043a0536SJohnathan Mantey { 915043a0536SJohnathan Mantey const std::string* value = 9168d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 917043a0536SJohnathan Mantey if (value != nullptr) 918043a0536SJohnathan Mantey { 919043a0536SJohnathan Mantey filename = *value; 920043a0536SJohnathan Mantey } 921043a0536SJohnathan Mantey } 922043a0536SJohnathan Mantey else if (property.first == "Log") 923043a0536SJohnathan Mantey { 924043a0536SJohnathan Mantey const std::string* value = 9258d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 926043a0536SJohnathan Mantey if (value != nullptr) 927043a0536SJohnathan Mantey { 928043a0536SJohnathan Mantey logfile = *value; 929043a0536SJohnathan Mantey } 930043a0536SJohnathan Mantey } 931043a0536SJohnathan Mantey } 932043a0536SJohnathan Mantey } 933043a0536SJohnathan Mantey 934a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 935c4bf6374SJason M. Bills class SystemLogServiceCollection : public Node 9361da66f75SEd Tanous { 9371da66f75SEd Tanous public: 93852cc112dSEd Tanous SystemLogServiceCollection(App& app) : 939029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/") 940c4bf6374SJason M. Bills { 941c4bf6374SJason M. Bills entityPrivileges = { 942c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 943c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 944c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 945c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 946c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 947c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 948c4bf6374SJason M. Bills } 949c4bf6374SJason M. Bills 950c4bf6374SJason M. Bills private: 951c4bf6374SJason M. Bills /** 952c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 953c4bf6374SJason M. Bills */ 954cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 955cb13a392SEd Tanous const std::vector<std::string>&) override 956c4bf6374SJason M. Bills { 957c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 958c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 959c4bf6374SJason M. Bills // it has a duplicate entry for members 960c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 961c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 962c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 963029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 964c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 965c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 966c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 967c4bf6374SJason M. Bills nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 968c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 969029573d4SEd Tanous logServiceArray.push_back( 970029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}}); 9715cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 972c9bb6861Sraviteja-b logServiceArray.push_back( 9735cb1dd27SAsmitha Karunanithi {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}}); 974c9bb6861Sraviteja-b #endif 975c9bb6861Sraviteja-b 976d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 977d53dd41fSJason M. Bills logServiceArray.push_back( 978cb92c03bSAndrew Geissler {{"@odata.id", 979424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 980d53dd41fSJason M. Bills #endif 981c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 982c4bf6374SJason M. Bills logServiceArray.size(); 983a3316fc6SZhikuiRen 984a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 985a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 986a3316fc6SZhikuiRen const std::vector<std::string>& subtreePath) { 987a3316fc6SZhikuiRen if (ec) 988a3316fc6SZhikuiRen { 989a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 990a3316fc6SZhikuiRen return; 991a3316fc6SZhikuiRen } 992a3316fc6SZhikuiRen 993a3316fc6SZhikuiRen for (auto& pathStr : subtreePath) 994a3316fc6SZhikuiRen { 995a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 996a3316fc6SZhikuiRen { 99723a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 998a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 99923a21a1cSEd Tanous logServiceArrayLocal.push_back( 1000a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 1001a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 1002a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 100323a21a1cSEd Tanous logServiceArrayLocal.size(); 1004a3316fc6SZhikuiRen return; 1005a3316fc6SZhikuiRen } 1006a3316fc6SZhikuiRen } 1007a3316fc6SZhikuiRen }, 1008a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 1009a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 1010a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 1011a3316fc6SZhikuiRen std::array<const char*, 1>{postCodeIface}); 1012c4bf6374SJason M. Bills } 1013c4bf6374SJason M. Bills }; 1014c4bf6374SJason M. Bills 1015c4bf6374SJason M. Bills class EventLogService : public Node 1016c4bf6374SJason M. Bills { 1017c4bf6374SJason M. Bills public: 101852cc112dSEd Tanous EventLogService(App& app) : 1019029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 1020c4bf6374SJason M. Bills { 1021c4bf6374SJason M. Bills entityPrivileges = { 1022c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1023c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1024c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1025c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1026c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1027c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1028c4bf6374SJason M. Bills } 1029c4bf6374SJason M. Bills 1030c4bf6374SJason M. Bills private: 1031cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1032cb13a392SEd Tanous const std::vector<std::string>&) override 1033c4bf6374SJason M. Bills { 1034c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1035c4bf6374SJason M. Bills 1036c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1037029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1038c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1039c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 1040c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 1041c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 1042c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1043c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1044c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1045c4bf6374SJason M. Bills {"@odata.id", 1046029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 1047e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1048e7d6c8b2SGunnar Mills 1049e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 1050e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 1051489640c6SJason M. Bills } 1052489640c6SJason M. Bills }; 1053489640c6SJason M. Bills 10541f56a3a6STim Lee class JournalEventLogClear : public Node 1055489640c6SJason M. Bills { 1056489640c6SJason M. Bills public: 105752cc112dSEd Tanous JournalEventLogClear(App& app) : 1058489640c6SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 1059489640c6SJason M. Bills "LogService.ClearLog/") 1060489640c6SJason M. Bills { 1061489640c6SJason M. Bills entityPrivileges = { 1062489640c6SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1063489640c6SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1064489640c6SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1065489640c6SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1066489640c6SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1067489640c6SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1068489640c6SJason M. Bills } 1069489640c6SJason M. Bills 1070489640c6SJason M. Bills private: 1071cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 1072cb13a392SEd Tanous const std::vector<std::string>&) override 1073489640c6SJason M. Bills { 1074489640c6SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1075489640c6SJason M. Bills 1076489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1077489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1078489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1079489640c6SJason M. Bills { 1080489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1081489640c6SJason M. Bills { 1082489640c6SJason M. Bills std::error_code ec; 1083489640c6SJason M. Bills std::filesystem::remove(file, ec); 1084489640c6SJason M. Bills } 1085489640c6SJason M. Bills } 1086489640c6SJason M. Bills 1087489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1088489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1089489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1090489640c6SJason M. Bills if (ec) 1091489640c6SJason M. Bills { 1092489640c6SJason M. Bills BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 1093489640c6SJason M. Bills messages::internalError(asyncResp->res); 1094489640c6SJason M. Bills return; 1095489640c6SJason M. Bills } 1096489640c6SJason M. Bills 1097489640c6SJason M. Bills messages::success(asyncResp->res); 1098489640c6SJason M. Bills }, 1099489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1100489640c6SJason M. Bills "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1101489640c6SJason M. Bills "replace"); 1102c4bf6374SJason M. Bills } 1103c4bf6374SJason M. Bills }; 1104c4bf6374SJason M. Bills 110595820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 110695820184SJason M. Bills const std::string logEntry, 110795820184SJason M. Bills nlohmann::json& logEntryJson) 1108c4bf6374SJason M. Bills { 110995820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1110cd225da8SJason M. Bills // First get the Timestamp 1111cd225da8SJason M. Bills size_t space = logEntry.find_first_of(" "); 1112cd225da8SJason M. Bills if (space == std::string::npos) 111395820184SJason M. Bills { 111495820184SJason M. Bills return 1; 111595820184SJason M. Bills } 1116cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1117cd225da8SJason M. Bills // Then get the log contents 1118cd225da8SJason M. Bills size_t entryStart = logEntry.find_first_not_of(" ", space); 1119cd225da8SJason M. Bills if (entryStart == std::string::npos) 1120cd225da8SJason M. Bills { 1121cd225da8SJason M. Bills return 1; 1122cd225da8SJason M. Bills } 1123cd225da8SJason M. Bills std::string_view entry(logEntry); 1124cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1125cd225da8SJason M. Bills // Use split to separate the entry into its fields 1126cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1127cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1128cd225da8SJason M. Bills boost::token_compress_on); 1129cd225da8SJason M. Bills // We need at least a MessageId to be valid 1130cd225da8SJason M. Bills if (logEntryFields.size() < 1) 1131cd225da8SJason M. Bills { 1132cd225da8SJason M. Bills return 1; 1133cd225da8SJason M. Bills } 1134cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 113595820184SJason M. Bills 11364851d45dSJason M. Bills // Get the Message from the MessageRegistry 11374851d45dSJason M. Bills const message_registries::Message* message = 11384851d45dSJason M. Bills message_registries::getMessage(messageID); 1139c4bf6374SJason M. Bills 11404851d45dSJason M. Bills std::string msg; 11414851d45dSJason M. Bills std::string severity; 11424851d45dSJason M. Bills if (message != nullptr) 1143c4bf6374SJason M. Bills { 11444851d45dSJason M. Bills msg = message->message; 11454851d45dSJason M. Bills severity = message->severity; 1146c4bf6374SJason M. Bills } 1147c4bf6374SJason M. Bills 114815a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 114915a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 115015a86ff6SJason M. Bills if (logEntryFields.size() > 1) 115115a86ff6SJason M. Bills { 115215a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 115315a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 115415a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 115515a86ff6SJason M. Bills if (!messageArgsStart.empty()) 115615a86ff6SJason M. Bills { 115715a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 115815a86ff6SJason M. Bills } 115915a86ff6SJason M. Bills 116023a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1161c4bf6374SJason M. Bills 11624851d45dSJason M. Bills // Fill the MessageArgs into the Message 116395820184SJason M. Bills int i = 0; 116495820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11654851d45dSJason M. Bills { 116695820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11674851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11684851d45dSJason M. Bills if (argPos != std::string::npos) 11694851d45dSJason M. Bills { 117095820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11714851d45dSJason M. Bills } 11724851d45dSJason M. Bills } 117315a86ff6SJason M. Bills } 11744851d45dSJason M. Bills 117595820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 117695820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 117795820184SJason M. Bills // between the '.' and the '+', so just remove them. 117895820184SJason M. Bills std::size_t dot = timestamp.find_first_of("."); 117995820184SJason M. Bills std::size_t plus = timestamp.find_first_of("+"); 118095820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1181c4bf6374SJason M. Bills { 118295820184SJason M. Bills timestamp.erase(dot, plus - dot); 1183c4bf6374SJason M. Bills } 1184c4bf6374SJason M. Bills 1185c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 118695820184SJason M. Bills logEntryJson = { 1187cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1188029573d4SEd Tanous {"@odata.id", 1189897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 119095820184SJason M. Bills logEntryID}, 1191c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 119295820184SJason M. Bills {"Id", logEntryID}, 119395820184SJason M. Bills {"Message", std::move(msg)}, 119495820184SJason M. Bills {"MessageId", std::move(messageID)}, 1195c4bf6374SJason M. Bills {"MessageArgs", std::move(messageArgs)}, 1196c4bf6374SJason M. Bills {"EntryType", "Event"}, 119795820184SJason M. Bills {"Severity", std::move(severity)}, 119895820184SJason M. Bills {"Created", std::move(timestamp)}}; 1199c4bf6374SJason M. Bills return 0; 1200c4bf6374SJason M. Bills } 1201c4bf6374SJason M. Bills 120227062605SAnthony Wilson class JournalEventLogEntryCollection : public Node 1203c4bf6374SJason M. Bills { 1204c4bf6374SJason M. Bills public: 120552cc112dSEd Tanous JournalEventLogEntryCollection(App& app) : 1206029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1207c4bf6374SJason M. Bills { 1208c4bf6374SJason M. Bills entityPrivileges = { 1209c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1210c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1211c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1212c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1213c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1214c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1215c4bf6374SJason M. Bills } 1216c4bf6374SJason M. Bills 1217c4bf6374SJason M. Bills private: 1218c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1219cb13a392SEd Tanous const std::vector<std::string>&) override 1220c4bf6374SJason M. Bills { 1221c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1222271584abSEd Tanous uint64_t skip = 0; 1223271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 1224c4bf6374SJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1225c4bf6374SJason M. Bills { 1226c4bf6374SJason M. Bills return; 1227c4bf6374SJason M. Bills } 1228c4bf6374SJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1229c4bf6374SJason M. Bills { 1230c4bf6374SJason M. Bills return; 1231c4bf6374SJason M. Bills } 1232c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 1233c4bf6374SJason M. Bills // it has a duplicate entry for members 1234c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1235c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1236c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1237029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1238c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1239c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1240c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1241cb92c03bSAndrew Geissler 1242c4bf6374SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1243c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 124495820184SJason M. Bills // Go through the log files and create a unique ID for each entry 124595820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 124695820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1247b01bf299SEd Tanous uint64_t entryCount = 0; 1248cd225da8SJason M. Bills std::string logEntry; 124995820184SJason M. Bills 125095820184SJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 1251cd225da8SJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1252cd225da8SJason M. Bills it++) 1253c4bf6374SJason M. Bills { 1254cd225da8SJason M. Bills std::ifstream logStream(*it); 125595820184SJason M. Bills if (!logStream.is_open()) 1256c4bf6374SJason M. Bills { 1257c4bf6374SJason M. Bills continue; 1258c4bf6374SJason M. Bills } 1259c4bf6374SJason M. Bills 1260e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1261e85d6b16SJason M. Bills bool firstEntry = true; 126295820184SJason M. Bills while (std::getline(logStream, logEntry)) 126395820184SJason M. Bills { 1264c4bf6374SJason M. Bills entryCount++; 1265c4bf6374SJason M. Bills // Handle paging using skip (number of entries to skip from the 1266c4bf6374SJason M. Bills // start) and top (number of entries to display) 1267c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1268c4bf6374SJason M. Bills { 1269c4bf6374SJason M. Bills continue; 1270c4bf6374SJason M. Bills } 1271c4bf6374SJason M. Bills 1272c4bf6374SJason M. Bills std::string idStr; 1273e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1274c4bf6374SJason M. Bills { 1275c4bf6374SJason M. Bills continue; 1276c4bf6374SJason M. Bills } 1277c4bf6374SJason M. Bills 1278e85d6b16SJason M. Bills if (firstEntry) 1279e85d6b16SJason M. Bills { 1280e85d6b16SJason M. Bills firstEntry = false; 1281e85d6b16SJason M. Bills } 1282e85d6b16SJason M. Bills 1283c4bf6374SJason M. Bills logEntryArray.push_back({}); 1284c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 128595820184SJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0) 1286c4bf6374SJason M. Bills { 1287c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1288c4bf6374SJason M. Bills return; 1289c4bf6374SJason M. Bills } 1290c4bf6374SJason M. Bills } 129195820184SJason M. Bills } 1292c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1293c4bf6374SJason M. Bills if (skip + top < entryCount) 1294c4bf6374SJason M. Bills { 1295c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 129695820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 129795820184SJason M. Bills "Entries?$skip=" + 1298c4bf6374SJason M. Bills std::to_string(skip + top); 1299c4bf6374SJason M. Bills } 130008a4e4b5SAnthony Wilson } 130108a4e4b5SAnthony Wilson }; 130208a4e4b5SAnthony Wilson 1303897967deSJason M. Bills class JournalEventLogEntry : public Node 1304897967deSJason M. Bills { 1305897967deSJason M. Bills public: 130652cc112dSEd Tanous JournalEventLogEntry(App& app) : 1307897967deSJason M. Bills Node(app, 1308897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1309897967deSJason M. Bills std::string()) 1310897967deSJason M. Bills { 1311897967deSJason M. Bills entityPrivileges = { 1312897967deSJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1313897967deSJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1314897967deSJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1315897967deSJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1316897967deSJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1317897967deSJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1318897967deSJason M. Bills } 1319897967deSJason M. Bills 1320897967deSJason M. Bills private: 1321cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1322897967deSJason M. Bills const std::vector<std::string>& params) override 1323897967deSJason M. Bills { 1324897967deSJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1325897967deSJason M. Bills if (params.size() != 1) 1326897967deSJason M. Bills { 1327897967deSJason M. Bills messages::internalError(asyncResp->res); 1328897967deSJason M. Bills return; 1329897967deSJason M. Bills } 1330897967deSJason M. Bills const std::string& targetID = params[0]; 1331897967deSJason M. Bills 1332897967deSJason M. Bills // Go through the log files and check the unique ID for each entry to 1333897967deSJason M. Bills // find the target entry 1334897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1335897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1336897967deSJason M. Bills std::string logEntry; 1337897967deSJason M. Bills 1338897967deSJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 1339897967deSJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1340897967deSJason M. Bills it++) 1341897967deSJason M. Bills { 1342897967deSJason M. Bills std::ifstream logStream(*it); 1343897967deSJason M. Bills if (!logStream.is_open()) 1344897967deSJason M. Bills { 1345897967deSJason M. Bills continue; 1346897967deSJason M. Bills } 1347897967deSJason M. Bills 1348897967deSJason M. Bills // Reset the unique ID on the first entry 1349897967deSJason M. Bills bool firstEntry = true; 1350897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1351897967deSJason M. Bills { 1352897967deSJason M. Bills std::string idStr; 1353897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1354897967deSJason M. Bills { 1355897967deSJason M. Bills continue; 1356897967deSJason M. Bills } 1357897967deSJason M. Bills 1358897967deSJason M. Bills if (firstEntry) 1359897967deSJason M. Bills { 1360897967deSJason M. Bills firstEntry = false; 1361897967deSJason M. Bills } 1362897967deSJason M. Bills 1363897967deSJason M. Bills if (idStr == targetID) 1364897967deSJason M. Bills { 1365897967deSJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, 1366897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1367897967deSJason M. Bills { 1368897967deSJason M. Bills messages::internalError(asyncResp->res); 1369897967deSJason M. Bills return; 1370897967deSJason M. Bills } 1371897967deSJason M. Bills return; 1372897967deSJason M. Bills } 1373897967deSJason M. Bills } 1374897967deSJason M. Bills } 1375897967deSJason M. Bills // Requested ID was not found 1376897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 1377897967deSJason M. Bills } 1378897967deSJason M. Bills }; 1379897967deSJason M. Bills 138008a4e4b5SAnthony Wilson class DBusEventLogEntryCollection : public Node 138108a4e4b5SAnthony Wilson { 138208a4e4b5SAnthony Wilson public: 138352cc112dSEd Tanous DBusEventLogEntryCollection(App& app) : 138408a4e4b5SAnthony Wilson Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 138508a4e4b5SAnthony Wilson { 138608a4e4b5SAnthony Wilson entityPrivileges = { 138708a4e4b5SAnthony Wilson {boost::beast::http::verb::get, {{"Login"}}}, 138808a4e4b5SAnthony Wilson {boost::beast::http::verb::head, {{"Login"}}}, 138908a4e4b5SAnthony Wilson {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 139008a4e4b5SAnthony Wilson {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 139108a4e4b5SAnthony Wilson {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 139208a4e4b5SAnthony Wilson {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 139308a4e4b5SAnthony Wilson } 139408a4e4b5SAnthony Wilson 139508a4e4b5SAnthony Wilson private: 1396cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1397cb13a392SEd Tanous const std::vector<std::string>&) override 139808a4e4b5SAnthony Wilson { 139908a4e4b5SAnthony Wilson std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 140008a4e4b5SAnthony Wilson 140108a4e4b5SAnthony Wilson // Collections don't include the static data added by SubRoute because 140208a4e4b5SAnthony Wilson // it has a duplicate entry for members 140308a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 140408a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 140508a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 140608a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 140708a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 140808a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 140908a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 141008a4e4b5SAnthony Wilson 1411cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1412cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1413cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1414cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1415cb92c03bSAndrew Geissler GetManagedObjectsType& resp) { 1416cb92c03bSAndrew Geissler if (ec) 1417cb92c03bSAndrew Geissler { 1418cb92c03bSAndrew Geissler // TODO Handle for specific error code 1419cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1420cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1421cb92c03bSAndrew Geissler << ec; 1422cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1423cb92c03bSAndrew Geissler return; 1424cb92c03bSAndrew Geissler } 1425cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1426cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1427cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 1428cb92c03bSAndrew Geissler for (auto& objectPath : resp) 1429cb92c03bSAndrew Geissler { 1430cb92c03bSAndrew Geissler for (auto& interfaceMap : objectPath.second) 1431cb92c03bSAndrew Geissler { 1432cb92c03bSAndrew Geissler if (interfaceMap.first != 1433cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry") 1434cb92c03bSAndrew Geissler { 1435cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Bailing early on " 1436cb92c03bSAndrew Geissler << interfaceMap.first; 1437cb92c03bSAndrew Geissler continue; 1438cb92c03bSAndrew Geissler } 1439cb92c03bSAndrew Geissler entriesArray.push_back({}); 1440cb92c03bSAndrew Geissler nlohmann::json& thisEntry = entriesArray.back(); 144166664f25SEd Tanous uint32_t* id = nullptr; 144266664f25SEd Tanous std::time_t timestamp{}; 1443d139c236SGeorge Liu std::time_t updateTimestamp{}; 144466664f25SEd Tanous std::string* severity = nullptr; 144566664f25SEd Tanous std::string* message = nullptr; 1446d139c236SGeorge Liu 1447cb92c03bSAndrew Geissler for (auto& propertyMap : interfaceMap.second) 1448cb92c03bSAndrew Geissler { 1449cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1450cb92c03bSAndrew Geissler { 14518d78b7a9SPatrick Williams id = std::get_if<uint32_t>(&propertyMap.second); 1452cb92c03bSAndrew Geissler if (id == nullptr) 1453cb92c03bSAndrew Geissler { 14540f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1455cb92c03bSAndrew Geissler } 1456cb92c03bSAndrew Geissler } 1457cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1458cb92c03bSAndrew Geissler { 1459cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1460cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1461cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1462cb92c03bSAndrew Geissler { 14630f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1464cb92c03bSAndrew Geissler } 1465*ebd45906SGeorge Liu else 1466*ebd45906SGeorge Liu { 1467d139c236SGeorge Liu timestamp = crow::utility::getTimestamp( 1468cb92c03bSAndrew Geissler *millisTimeStamp); 1469d139c236SGeorge Liu } 1470*ebd45906SGeorge Liu } 1471d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1472d139c236SGeorge Liu { 1473d139c236SGeorge Liu const uint64_t* millisTimeStamp = 1474d139c236SGeorge Liu std::get_if<uint64_t>(&propertyMap.second); 1475d139c236SGeorge Liu if (millisTimeStamp == nullptr) 1476d139c236SGeorge Liu { 1477d139c236SGeorge Liu messages::internalError(asyncResp->res); 1478d139c236SGeorge Liu } 1479*ebd45906SGeorge Liu else 1480*ebd45906SGeorge Liu { 1481*ebd45906SGeorge Liu updateTimestamp = 1482*ebd45906SGeorge Liu crow::utility::getTimestamp( 1483d139c236SGeorge Liu *millisTimeStamp); 1484cb92c03bSAndrew Geissler } 1485*ebd45906SGeorge Liu } 1486cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1487cb92c03bSAndrew Geissler { 1488cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1489cb92c03bSAndrew Geissler &propertyMap.second); 1490cb92c03bSAndrew Geissler if (severity == nullptr) 1491cb92c03bSAndrew Geissler { 14920f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1493cb92c03bSAndrew Geissler } 1494cb92c03bSAndrew Geissler } 1495cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1496cb92c03bSAndrew Geissler { 1497cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1498cb92c03bSAndrew Geissler &propertyMap.second); 1499cb92c03bSAndrew Geissler if (message == nullptr) 1500cb92c03bSAndrew Geissler { 15010f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1502cb92c03bSAndrew Geissler } 1503cb92c03bSAndrew Geissler } 1504cb92c03bSAndrew Geissler } 1505cb92c03bSAndrew Geissler thisEntry = { 1506d139c236SGeorge Liu {"@odata.type", "#LogEntry.v1_6_0.LogEntry"}, 1507cb92c03bSAndrew Geissler {"@odata.id", 1508cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1509cb92c03bSAndrew Geissler "Entries/" + 1510cb92c03bSAndrew Geissler std::to_string(*id)}, 151127062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1512cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1513cb92c03bSAndrew Geissler {"Message", *message}, 1514cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1515cb92c03bSAndrew Geissler {"Severity", 1516cb92c03bSAndrew Geissler translateSeverityDbusToRedfish(*severity)}, 1517d139c236SGeorge Liu {"Created", crow::utility::getDateTime(timestamp)}, 1518d139c236SGeorge Liu {"Modified", 1519d139c236SGeorge Liu crow::utility::getDateTime(updateTimestamp)}}; 1520cb92c03bSAndrew Geissler } 1521cb92c03bSAndrew Geissler } 1522cb92c03bSAndrew Geissler std::sort(entriesArray.begin(), entriesArray.end(), 1523cb92c03bSAndrew Geissler [](const nlohmann::json& left, 1524cb92c03bSAndrew Geissler const nlohmann::json& right) { 1525cb92c03bSAndrew Geissler return (left["Id"] <= right["Id"]); 1526cb92c03bSAndrew Geissler }); 1527cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members@odata.count"] = 1528cb92c03bSAndrew Geissler entriesArray.size(); 1529cb92c03bSAndrew Geissler }, 1530cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 1531cb92c03bSAndrew Geissler "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 1532c4bf6374SJason M. Bills } 1533c4bf6374SJason M. Bills }; 1534c4bf6374SJason M. Bills 153508a4e4b5SAnthony Wilson class DBusEventLogEntry : public Node 1536c4bf6374SJason M. Bills { 1537c4bf6374SJason M. Bills public: 153852cc112dSEd Tanous DBusEventLogEntry(App& app) : 1539c4bf6374SJason M. Bills Node(app, 1540029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1541029573d4SEd Tanous std::string()) 1542c4bf6374SJason M. Bills { 1543c4bf6374SJason M. Bills entityPrivileges = { 1544c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1545c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1546c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1547c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1548c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1549c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1550c4bf6374SJason M. Bills } 1551c4bf6374SJason M. Bills 1552c4bf6374SJason M. Bills private: 1553cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1554c4bf6374SJason M. Bills const std::vector<std::string>& params) override 1555c4bf6374SJason M. Bills { 1556c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1557029573d4SEd Tanous if (params.size() != 1) 1558c4bf6374SJason M. Bills { 1559c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1560c4bf6374SJason M. Bills return; 1561c4bf6374SJason M. Bills } 1562029573d4SEd Tanous const std::string& entryID = params[0]; 1563cb92c03bSAndrew Geissler 1564cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1565cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1566cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1567cb92c03bSAndrew Geissler [asyncResp, entryID](const boost::system::error_code ec, 1568cb92c03bSAndrew Geissler GetManagedPropertyType& resp) { 1569cb92c03bSAndrew Geissler if (ec) 1570cb92c03bSAndrew Geissler { 1571cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1572cb92c03bSAndrew Geissler << "EventLogEntry (DBus) resp_handler got error " << ec; 1573cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1574cb92c03bSAndrew Geissler return; 1575cb92c03bSAndrew Geissler } 157666664f25SEd Tanous uint32_t* id = nullptr; 157766664f25SEd Tanous std::time_t timestamp{}; 1578d139c236SGeorge Liu std::time_t updateTimestamp{}; 157966664f25SEd Tanous std::string* severity = nullptr; 158066664f25SEd Tanous std::string* message = nullptr; 1581d139c236SGeorge Liu 1582cb92c03bSAndrew Geissler for (auto& propertyMap : resp) 1583cb92c03bSAndrew Geissler { 1584cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1585cb92c03bSAndrew Geissler { 1586cb92c03bSAndrew Geissler id = std::get_if<uint32_t>(&propertyMap.second); 1587cb92c03bSAndrew Geissler if (id == nullptr) 1588cb92c03bSAndrew Geissler { 15890f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1590cb92c03bSAndrew Geissler } 1591cb92c03bSAndrew Geissler } 1592cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1593cb92c03bSAndrew Geissler { 1594cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1595cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1596cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1597cb92c03bSAndrew Geissler { 15980f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1599cb92c03bSAndrew Geissler } 1600*ebd45906SGeorge Liu else 1601*ebd45906SGeorge Liu { 1602cb92c03bSAndrew Geissler timestamp = 1603d139c236SGeorge Liu crow::utility::getTimestamp(*millisTimeStamp); 1604d139c236SGeorge Liu } 1605*ebd45906SGeorge Liu } 1606d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1607d139c236SGeorge Liu { 1608d139c236SGeorge Liu const uint64_t* millisTimeStamp = 1609d139c236SGeorge Liu std::get_if<uint64_t>(&propertyMap.second); 1610d139c236SGeorge Liu if (millisTimeStamp == nullptr) 1611d139c236SGeorge Liu { 1612d139c236SGeorge Liu messages::internalError(asyncResp->res); 1613d139c236SGeorge Liu } 1614*ebd45906SGeorge Liu else 1615*ebd45906SGeorge Liu { 1616d139c236SGeorge Liu updateTimestamp = 1617d139c236SGeorge Liu crow::utility::getTimestamp(*millisTimeStamp); 1618cb92c03bSAndrew Geissler } 1619*ebd45906SGeorge Liu } 1620cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1621cb92c03bSAndrew Geissler { 1622cb92c03bSAndrew Geissler severity = 1623cb92c03bSAndrew Geissler std::get_if<std::string>(&propertyMap.second); 1624cb92c03bSAndrew Geissler if (severity == nullptr) 1625cb92c03bSAndrew Geissler { 16260f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1627cb92c03bSAndrew Geissler } 1628cb92c03bSAndrew Geissler } 1629cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1630cb92c03bSAndrew Geissler { 1631cb92c03bSAndrew Geissler message = std::get_if<std::string>(&propertyMap.second); 1632cb92c03bSAndrew Geissler if (message == nullptr) 1633cb92c03bSAndrew Geissler { 16340f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1635cb92c03bSAndrew Geissler } 1636cb92c03bSAndrew Geissler } 1637cb92c03bSAndrew Geissler } 1638271584abSEd Tanous if (id == nullptr || message == nullptr || severity == nullptr) 1639271584abSEd Tanous { 1640271584abSEd Tanous return; 1641271584abSEd Tanous } 1642cb92c03bSAndrew Geissler asyncResp->res.jsonValue = { 1643d139c236SGeorge Liu {"@odata.type", "#LogEntry.v1_6_0.LogEntry"}, 1644cb92c03bSAndrew Geissler {"@odata.id", 1645cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1646cb92c03bSAndrew Geissler "Entries/" + 1647cb92c03bSAndrew Geissler std::to_string(*id)}, 164827062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1649cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1650cb92c03bSAndrew Geissler {"Message", *message}, 1651cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1652cb92c03bSAndrew Geissler {"Severity", translateSeverityDbusToRedfish(*severity)}, 1653d139c236SGeorge Liu {"Created", crow::utility::getDateTime(timestamp)}, 1654d139c236SGeorge Liu {"Modified", crow::utility::getDateTime(updateTimestamp)}}; 1655cb92c03bSAndrew Geissler }, 1656cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1657cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1658cb92c03bSAndrew Geissler "org.freedesktop.DBus.Properties", "GetAll", 1659cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry"); 1660c4bf6374SJason M. Bills } 1661336e96c6SChicago Duan 1662cb13a392SEd Tanous void doDelete(crow::Response& res, const crow::Request&, 1663336e96c6SChicago Duan const std::vector<std::string>& params) override 1664336e96c6SChicago Duan { 1665336e96c6SChicago Duan 1666336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1667336e96c6SChicago Duan 1668336e96c6SChicago Duan auto asyncResp = std::make_shared<AsyncResp>(res); 1669336e96c6SChicago Duan 1670336e96c6SChicago Duan if (params.size() != 1) 1671336e96c6SChicago Duan { 1672336e96c6SChicago Duan messages::internalError(asyncResp->res); 1673336e96c6SChicago Duan return; 1674336e96c6SChicago Duan } 1675336e96c6SChicago Duan std::string entryID = params[0]; 1676336e96c6SChicago Duan 1677336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1678336e96c6SChicago Duan 1679336e96c6SChicago Duan // Process response from Logging service. 1680336e96c6SChicago Duan auto respHandler = [asyncResp](const boost::system::error_code ec) { 1681336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1682336e96c6SChicago Duan if (ec) 1683336e96c6SChicago Duan { 1684336e96c6SChicago Duan // TODO Handle for specific error code 1685336e96c6SChicago Duan BMCWEB_LOG_ERROR 1686336e96c6SChicago Duan << "EventLogEntry (DBus) doDelete respHandler got error " 1687336e96c6SChicago Duan << ec; 1688336e96c6SChicago Duan asyncResp->res.result( 1689336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1690336e96c6SChicago Duan return; 1691336e96c6SChicago Duan } 1692336e96c6SChicago Duan 1693336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1694336e96c6SChicago Duan }; 1695336e96c6SChicago Duan 1696336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1697336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1698336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1699336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1700336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 1701336e96c6SChicago Duan } 1702c4bf6374SJason M. Bills }; 1703c4bf6374SJason M. Bills 1704c4bf6374SJason M. Bills class BMCLogServiceCollection : public Node 1705c4bf6374SJason M. Bills { 1706c4bf6374SJason M. Bills public: 170752cc112dSEd Tanous BMCLogServiceCollection(App& app) : 17084ed77cd5SEd Tanous Node(app, "/redfish/v1/Managers/bmc/LogServices/") 17091da66f75SEd Tanous { 17101da66f75SEd Tanous entityPrivileges = { 1711e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1712e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1713e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1714e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1715e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1716e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 17171da66f75SEd Tanous } 17181da66f75SEd Tanous 17191da66f75SEd Tanous private: 17201da66f75SEd Tanous /** 17211da66f75SEd Tanous * Functions triggers appropriate requests on DBus 17221da66f75SEd Tanous */ 1723cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1724cb13a392SEd Tanous const std::vector<std::string>&) override 17251da66f75SEd Tanous { 1726e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 17271da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 17281da66f75SEd Tanous // it has a duplicate entry for members 1729e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 17301da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1731e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1732e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 1733e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 1734e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 17351da66f75SEd Tanous "Collection of LogServices for this Manager"; 1736c4bf6374SJason M. Bills nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 1737c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 17385cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 17395cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 17405cb1dd27SAsmitha Karunanithi {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 17415cb1dd27SAsmitha Karunanithi #endif 1742c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1743c4bf6374SJason M. Bills logServiceArray.push_back( 174408a4e4b5SAnthony Wilson {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1745c4bf6374SJason M. Bills #endif 1746e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1747c4bf6374SJason M. Bills logServiceArray.size(); 17481da66f75SEd Tanous } 17491da66f75SEd Tanous }; 17501da66f75SEd Tanous 1751c4bf6374SJason M. Bills class BMCJournalLogService : public Node 17521da66f75SEd Tanous { 17531da66f75SEd Tanous public: 175452cc112dSEd Tanous BMCJournalLogService(App& app) : 1755c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1756e1f26343SJason M. Bills { 1757e1f26343SJason M. Bills entityPrivileges = { 1758e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1759e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1760e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1761e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1762e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1763e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1764e1f26343SJason M. Bills } 1765e1f26343SJason M. Bills 1766e1f26343SJason M. Bills private: 1767cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1768cb13a392SEd Tanous const std::vector<std::string>&) override 1769e1f26343SJason M. Bills { 1770e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1771e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1772e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 17730f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 17740f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 1775c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 1776c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 1777c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1778e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1779cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1780cd50aa42SJason M. Bills {"@odata.id", 1781086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 1782e1f26343SJason M. Bills } 1783e1f26343SJason M. Bills }; 1784e1f26343SJason M. Bills 1785c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 1786e1f26343SJason M. Bills sd_journal* journal, 1787c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 1788e1f26343SJason M. Bills { 1789e1f26343SJason M. Bills // Get the Log Entry contents 1790e1f26343SJason M. Bills int ret = 0; 1791e1f26343SJason M. Bills 179239e77504SEd Tanous std::string_view msg; 179316428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1794e1f26343SJason M. Bills if (ret < 0) 1795e1f26343SJason M. Bills { 1796e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1797e1f26343SJason M. Bills return 1; 1798e1f26343SJason M. Bills } 1799e1f26343SJason M. Bills 1800e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1801271584abSEd Tanous long int severity = 8; // Default to an invalid priority 180216428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1803e1f26343SJason M. Bills if (ret < 0) 1804e1f26343SJason M. Bills { 1805e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1806e1f26343SJason M. Bills } 1807e1f26343SJason M. Bills 1808e1f26343SJason M. Bills // Get the Created time from the timestamp 180916428a1aSJason M. Bills std::string entryTimeStr; 181016428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1811e1f26343SJason M. Bills { 181216428a1aSJason M. Bills return 1; 1813e1f26343SJason M. Bills } 1814e1f26343SJason M. Bills 1815e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1816c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 1817cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1818c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1819c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1820e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1821c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 182216428a1aSJason M. Bills {"Message", msg}, 1823e1f26343SJason M. Bills {"EntryType", "Oem"}, 1824e1f26343SJason M. Bills {"Severity", 1825b6a61a5eSJason M. Bills severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"}, 1826086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1827e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1828e1f26343SJason M. Bills return 0; 1829e1f26343SJason M. Bills } 1830e1f26343SJason M. Bills 1831c4bf6374SJason M. Bills class BMCJournalLogEntryCollection : public Node 1832e1f26343SJason M. Bills { 1833e1f26343SJason M. Bills public: 183452cc112dSEd Tanous BMCJournalLogEntryCollection(App& app) : 1835c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1836e1f26343SJason M. Bills { 1837e1f26343SJason M. Bills entityPrivileges = { 1838e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1839e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1840e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1841e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1842e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1843e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1844e1f26343SJason M. Bills } 1845e1f26343SJason M. Bills 1846e1f26343SJason M. Bills private: 1847e1f26343SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1848cb13a392SEd Tanous const std::vector<std::string>&) override 1849e1f26343SJason M. Bills { 1850e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1851193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1852271584abSEd Tanous uint64_t skip = 0; 1853271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 185416428a1aSJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1855193ad2faSJason M. Bills { 1856193ad2faSJason M. Bills return; 1857193ad2faSJason M. Bills } 185816428a1aSJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1859193ad2faSJason M. Bills { 1860193ad2faSJason M. Bills return; 1861193ad2faSJason M. Bills } 1862e1f26343SJason M. Bills // Collections don't include the static data added by SubRoute because 1863e1f26343SJason M. Bills // it has a duplicate entry for members 1864e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1865e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 18660f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18670f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1868e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1869c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1870e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1871e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1872e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 18730f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18740f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries"; 1875e1f26343SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1876e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1877e1f26343SJason M. Bills 1878e1f26343SJason M. Bills // Go through the journal and use the timestamp to create a unique ID 1879e1f26343SJason M. Bills // for each entry 1880e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1881e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1882e1f26343SJason M. Bills if (ret < 0) 1883e1f26343SJason M. Bills { 1884e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1885f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1886e1f26343SJason M. Bills return; 1887e1f26343SJason M. Bills } 1888e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1889e1f26343SJason M. Bills journalTmp, sd_journal_close); 1890e1f26343SJason M. Bills journalTmp = nullptr; 1891b01bf299SEd Tanous uint64_t entryCount = 0; 1892e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1893e85d6b16SJason M. Bills bool firstEntry = true; 1894e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1895e1f26343SJason M. Bills { 1896193ad2faSJason M. Bills entryCount++; 1897193ad2faSJason M. Bills // Handle paging using skip (number of entries to skip from the 1898193ad2faSJason M. Bills // start) and top (number of entries to display) 1899193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1900193ad2faSJason M. Bills { 1901193ad2faSJason M. Bills continue; 1902193ad2faSJason M. Bills } 1903193ad2faSJason M. Bills 190416428a1aSJason M. Bills std::string idStr; 1905e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1906e1f26343SJason M. Bills { 1907e1f26343SJason M. Bills continue; 1908e1f26343SJason M. Bills } 1909e1f26343SJason M. Bills 1910e85d6b16SJason M. Bills if (firstEntry) 1911e85d6b16SJason M. Bills { 1912e85d6b16SJason M. Bills firstEntry = false; 1913e85d6b16SJason M. Bills } 1914e85d6b16SJason M. Bills 1915e1f26343SJason M. Bills logEntryArray.push_back({}); 1916c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 1917c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 1918c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 1919e1f26343SJason M. Bills { 1920f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1921e1f26343SJason M. Bills return; 1922e1f26343SJason M. Bills } 1923e1f26343SJason M. Bills } 1924193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1925193ad2faSJason M. Bills if (skip + top < entryCount) 1926193ad2faSJason M. Bills { 1927193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 1928c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 1929193ad2faSJason M. Bills std::to_string(skip + top); 1930193ad2faSJason M. Bills } 1931e1f26343SJason M. Bills } 1932e1f26343SJason M. Bills }; 1933e1f26343SJason M. Bills 1934c4bf6374SJason M. Bills class BMCJournalLogEntry : public Node 1935e1f26343SJason M. Bills { 1936e1f26343SJason M. Bills public: 193752cc112dSEd Tanous BMCJournalLogEntry(App& app) : 1938c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/", 1939e1f26343SJason M. Bills std::string()) 1940e1f26343SJason M. Bills { 1941e1f26343SJason M. Bills entityPrivileges = { 1942e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1943e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1944e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1945e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1946e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1947e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1948e1f26343SJason M. Bills } 1949e1f26343SJason M. Bills 1950e1f26343SJason M. Bills private: 1951cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1952e1f26343SJason M. Bills const std::vector<std::string>& params) override 1953e1f26343SJason M. Bills { 1954e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1955e1f26343SJason M. Bills if (params.size() != 1) 1956e1f26343SJason M. Bills { 1957f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1958e1f26343SJason M. Bills return; 1959e1f26343SJason M. Bills } 196016428a1aSJason M. Bills const std::string& entryID = params[0]; 1961e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 1962e1f26343SJason M. Bills uint64_t ts = 0; 1963271584abSEd Tanous uint64_t index = 0; 196416428a1aSJason M. Bills if (!getTimestampFromID(asyncResp->res, entryID, ts, index)) 1965e1f26343SJason M. Bills { 196616428a1aSJason M. Bills return; 1967e1f26343SJason M. Bills } 1968e1f26343SJason M. Bills 1969e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1970e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1971e1f26343SJason M. Bills if (ret < 0) 1972e1f26343SJason M. Bills { 1973e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1974f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1975e1f26343SJason M. Bills return; 1976e1f26343SJason M. Bills } 1977e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1978e1f26343SJason M. Bills journalTmp, sd_journal_close); 1979e1f26343SJason M. Bills journalTmp = nullptr; 1980e1f26343SJason M. Bills // Go to the timestamp in the log and move to the entry at the index 1981af07e3f5SJason M. Bills // tracking the unique ID 1982af07e3f5SJason M. Bills std::string idStr; 1983af07e3f5SJason M. Bills bool firstEntry = true; 1984e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 19852056b6d1SManojkiran Eda if (ret < 0) 19862056b6d1SManojkiran Eda { 19872056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 19882056b6d1SManojkiran Eda << strerror(-ret); 19892056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 19902056b6d1SManojkiran Eda return; 19912056b6d1SManojkiran Eda } 1992271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 1993e1f26343SJason M. Bills { 1994e1f26343SJason M. Bills sd_journal_next(journal.get()); 1995af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1996af07e3f5SJason M. Bills { 1997af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 1998af07e3f5SJason M. Bills return; 1999af07e3f5SJason M. Bills } 2000af07e3f5SJason M. Bills if (firstEntry) 2001af07e3f5SJason M. Bills { 2002af07e3f5SJason M. Bills firstEntry = false; 2003af07e3f5SJason M. Bills } 2004e1f26343SJason M. Bills } 2005c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2006af07e3f5SJason M. Bills if (idStr != entryID) 2007c4bf6374SJason M. Bills { 2008c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 2009c4bf6374SJason M. Bills return; 2010c4bf6374SJason M. Bills } 2011c4bf6374SJason M. Bills 2012c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 2013e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 2014e1f26343SJason M. Bills { 2015f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2016e1f26343SJason M. Bills return; 2017e1f26343SJason M. Bills } 2018e1f26343SJason M. Bills } 2019e1f26343SJason M. Bills }; 2020e1f26343SJason M. Bills 20215cb1dd27SAsmitha Karunanithi class BMCDumpService : public Node 2022c9bb6861Sraviteja-b { 2023c9bb6861Sraviteja-b public: 202452cc112dSEd Tanous BMCDumpService(App& app) : 20255cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2026c9bb6861Sraviteja-b { 2027c9bb6861Sraviteja-b entityPrivileges = { 2028c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2029c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2030c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2031c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2032c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2033c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2034c9bb6861Sraviteja-b } 2035c9bb6861Sraviteja-b 2036c9bb6861Sraviteja-b private: 2037cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2038cb13a392SEd Tanous const std::vector<std::string>&) override 2039c9bb6861Sraviteja-b { 2040c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2041c9bb6861Sraviteja-b 2042c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 20435cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 2044c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2045c9bb6861Sraviteja-b "#LogService.v1_1_0.LogService"; 2046c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 20475cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 20485cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2049c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2050c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 20515cb1dd27SAsmitha Karunanithi {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}}; 20525cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 20535cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 20545cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 20555cb1dd27SAsmitha Karunanithi "Actions/LogService.ClearLog"}}}, 20565cb1dd27SAsmitha Karunanithi {"Oem", 20575cb1dd27SAsmitha Karunanithi {{"#OemLogService.CollectDiagnosticData", 20585cb1dd27SAsmitha Karunanithi {{"target", 20595cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 20605cb1dd27SAsmitha Karunanithi "Actions/Oem/OemLogService.CollectDiagnosticData"}}}}}}; 2061c9bb6861Sraviteja-b } 2062c9bb6861Sraviteja-b }; 2063c9bb6861Sraviteja-b 20645cb1dd27SAsmitha Karunanithi class BMCDumpEntryCollection : public Node 2065c9bb6861Sraviteja-b { 2066c9bb6861Sraviteja-b public: 206752cc112dSEd Tanous BMCDumpEntryCollection(App& app) : 20685cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2069c9bb6861Sraviteja-b { 2070c9bb6861Sraviteja-b entityPrivileges = { 2071c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2072c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2073c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2074c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2075c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2076c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2077c9bb6861Sraviteja-b } 2078c9bb6861Sraviteja-b 2079c9bb6861Sraviteja-b private: 2080c9bb6861Sraviteja-b /** 2081c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2082c9bb6861Sraviteja-b */ 2083cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2084cb13a392SEd Tanous const std::vector<std::string>&) override 2085c9bb6861Sraviteja-b { 2086c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2087c9bb6861Sraviteja-b 2088c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2089c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2090c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 20915cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 20925cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2093c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 20945cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2095c9bb6861Sraviteja-b 20965cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 2097c9bb6861Sraviteja-b } 2098c9bb6861Sraviteja-b }; 2099c9bb6861Sraviteja-b 21005cb1dd27SAsmitha Karunanithi class BMCDumpEntry : public Node 2101c9bb6861Sraviteja-b { 2102c9bb6861Sraviteja-b public: 210352cc112dSEd Tanous BMCDumpEntry(App& app) : 21045cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/", 2105c9bb6861Sraviteja-b std::string()) 2106c9bb6861Sraviteja-b { 2107c9bb6861Sraviteja-b entityPrivileges = { 2108c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2109c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2110c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2111c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2112c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2113c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2114c9bb6861Sraviteja-b } 2115c9bb6861Sraviteja-b 2116c9bb6861Sraviteja-b private: 2117cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2118c9bb6861Sraviteja-b const std::vector<std::string>& params) override 2119c9bb6861Sraviteja-b { 2120c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2121c9bb6861Sraviteja-b if (params.size() != 1) 2122c9bb6861Sraviteja-b { 2123c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2124c9bb6861Sraviteja-b return; 2125c9bb6861Sraviteja-b } 21265cb1dd27SAsmitha Karunanithi getDumpEntryById(asyncResp, params[0], "BMC"); 2127c9bb6861Sraviteja-b } 2128c9bb6861Sraviteja-b 2129cb13a392SEd Tanous void doDelete(crow::Response& res, const crow::Request&, 2130c9bb6861Sraviteja-b const std::vector<std::string>& params) override 2131c9bb6861Sraviteja-b { 21325cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2133c9bb6861Sraviteja-b if (params.size() != 1) 2134c9bb6861Sraviteja-b { 2135c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2136c9bb6861Sraviteja-b return; 2137c9bb6861Sraviteja-b } 21385cb1dd27SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, params[0]); 21395cb1dd27SAsmitha Karunanithi } 21405cb1dd27SAsmitha Karunanithi }; 2141c9bb6861Sraviteja-b 2142a43be80fSAsmitha Karunanithi class BMCDumpCreate : public Node 2143a43be80fSAsmitha Karunanithi { 2144a43be80fSAsmitha Karunanithi public: 214552cc112dSEd Tanous BMCDumpCreate(App& app) : 2146a43be80fSAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 2147a43be80fSAsmitha Karunanithi "Actions/Oem/" 2148a43be80fSAsmitha Karunanithi "OemLogService.CollectDiagnosticData/") 2149a43be80fSAsmitha Karunanithi { 2150a43be80fSAsmitha Karunanithi entityPrivileges = { 2151a43be80fSAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2152a43be80fSAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2153a43be80fSAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2154a43be80fSAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2155a43be80fSAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2156a43be80fSAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2157a43be80fSAsmitha Karunanithi } 2158a43be80fSAsmitha Karunanithi 2159a43be80fSAsmitha Karunanithi private: 2160a43be80fSAsmitha Karunanithi void doPost(crow::Response& res, const crow::Request& req, 2161cb13a392SEd Tanous const std::vector<std::string>&) override 2162a43be80fSAsmitha Karunanithi { 2163a43be80fSAsmitha Karunanithi createDump(res, req, "BMC"); 2164a43be80fSAsmitha Karunanithi } 2165a43be80fSAsmitha Karunanithi }; 2166a43be80fSAsmitha Karunanithi 2167f71882ffSAsmitha Karunanithi class BMCDumpEntryDownload : public Node 2168f71882ffSAsmitha Karunanithi { 2169f71882ffSAsmitha Karunanithi public: 217052cc112dSEd Tanous BMCDumpEntryDownload(App& app) : 2171f71882ffSAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/attachment/<str>/", 2172f71882ffSAsmitha Karunanithi std::string()) 2173f71882ffSAsmitha Karunanithi { 2174f71882ffSAsmitha Karunanithi entityPrivileges = { 2175f71882ffSAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2176f71882ffSAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2177f71882ffSAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2178f71882ffSAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2179f71882ffSAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2180f71882ffSAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2181f71882ffSAsmitha Karunanithi } 2182f71882ffSAsmitha Karunanithi 2183f71882ffSAsmitha Karunanithi private: 2184f71882ffSAsmitha Karunanithi void doGet(crow::Response& res, const crow::Request& req, 2185f71882ffSAsmitha Karunanithi const std::vector<std::string>& params) override 2186f71882ffSAsmitha Karunanithi { 2187f71882ffSAsmitha Karunanithi if (params.size() != 1) 2188f71882ffSAsmitha Karunanithi { 2189f71882ffSAsmitha Karunanithi messages::internalError(res); 2190f71882ffSAsmitha Karunanithi return; 2191f71882ffSAsmitha Karunanithi } 2192f71882ffSAsmitha Karunanithi const std::string& entryID = params[0]; 2193f71882ffSAsmitha Karunanithi crow::obmc_dump::handleDumpOffloadUrl(req, res, entryID); 2194f71882ffSAsmitha Karunanithi } 2195f71882ffSAsmitha Karunanithi }; 2196f71882ffSAsmitha Karunanithi 219780319af1SAsmitha Karunanithi class BMCDumpClear : public Node 219880319af1SAsmitha Karunanithi { 219980319af1SAsmitha Karunanithi public: 220052cc112dSEd Tanous BMCDumpClear(App& app) : 220180319af1SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 220280319af1SAsmitha Karunanithi "Actions/" 220380319af1SAsmitha Karunanithi "LogService.ClearLog/") 220480319af1SAsmitha Karunanithi { 220580319af1SAsmitha Karunanithi entityPrivileges = { 220680319af1SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 220780319af1SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 220880319af1SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 220980319af1SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 221080319af1SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 221180319af1SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 221280319af1SAsmitha Karunanithi } 221380319af1SAsmitha Karunanithi 221480319af1SAsmitha Karunanithi private: 2215cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2216cb13a392SEd Tanous const std::vector<std::string>&) override 221780319af1SAsmitha Karunanithi { 221880319af1SAsmitha Karunanithi clearDump(res, "xyz.openbmc_project.Dump.Entry.BMC"); 221980319af1SAsmitha Karunanithi } 222080319af1SAsmitha Karunanithi }; 222180319af1SAsmitha Karunanithi 22225cb1dd27SAsmitha Karunanithi class SystemDumpService : public Node 2223c9bb6861Sraviteja-b { 22245cb1dd27SAsmitha Karunanithi public: 222552cc112dSEd Tanous SystemDumpService(App& app) : 22265cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/") 22275cb1dd27SAsmitha Karunanithi { 22285cb1dd27SAsmitha Karunanithi entityPrivileges = { 22295cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 22305cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 22315cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 22325cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 22335cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 22345cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 22355cb1dd27SAsmitha Karunanithi } 22365cb1dd27SAsmitha Karunanithi 22375cb1dd27SAsmitha Karunanithi private: 2238cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2239cb13a392SEd Tanous const std::vector<std::string>&) override 22405cb1dd27SAsmitha Karunanithi { 22415cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22425cb1dd27SAsmitha Karunanithi 22435cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 22445cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 22455cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 22465cb1dd27SAsmitha Karunanithi "#LogService.v1_1_0.LogService"; 22475cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 22485cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "System Dump LogService"; 22495cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 22505cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 22515cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Entries"] = { 22525cb1dd27SAsmitha Karunanithi {"@odata.id", 22535cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"}}; 22545cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 22555cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 22565cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 22575cb1dd27SAsmitha Karunanithi "LogService.ClearLog"}}}, 22585cb1dd27SAsmitha Karunanithi {"Oem", 22595cb1dd27SAsmitha Karunanithi {{"#OemLogService.CollectDiagnosticData", 22605cb1dd27SAsmitha Karunanithi {{"target", 22615cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Actions/Oem/" 22625cb1dd27SAsmitha Karunanithi "OemLogService.CollectDiagnosticData"}}}}}}; 22635cb1dd27SAsmitha Karunanithi } 22645cb1dd27SAsmitha Karunanithi }; 22655cb1dd27SAsmitha Karunanithi 22665cb1dd27SAsmitha Karunanithi class SystemDumpEntryCollection : public Node 22675cb1dd27SAsmitha Karunanithi { 22685cb1dd27SAsmitha Karunanithi public: 226952cc112dSEd Tanous SystemDumpEntryCollection(App& app) : 22705cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 22715cb1dd27SAsmitha Karunanithi { 22725cb1dd27SAsmitha Karunanithi entityPrivileges = { 22735cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 22745cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 22755cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 22765cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 22775cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 22785cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 22795cb1dd27SAsmitha Karunanithi } 22805cb1dd27SAsmitha Karunanithi 22815cb1dd27SAsmitha Karunanithi private: 22825cb1dd27SAsmitha Karunanithi /** 22835cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 22845cb1dd27SAsmitha Karunanithi */ 2285cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2286cb13a392SEd Tanous const std::vector<std::string>&) override 22875cb1dd27SAsmitha Karunanithi { 22885cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22895cb1dd27SAsmitha Karunanithi 22905cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 22915cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 22925cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 22935cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 22945cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 22955cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 22965cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 22975cb1dd27SAsmitha Karunanithi 22985cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 22995cb1dd27SAsmitha Karunanithi } 23005cb1dd27SAsmitha Karunanithi }; 23015cb1dd27SAsmitha Karunanithi 23025cb1dd27SAsmitha Karunanithi class SystemDumpEntry : public Node 23035cb1dd27SAsmitha Karunanithi { 23045cb1dd27SAsmitha Karunanithi public: 230552cc112dSEd Tanous SystemDumpEntry(App& app) : 23065cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/", 23075cb1dd27SAsmitha Karunanithi std::string()) 23085cb1dd27SAsmitha Karunanithi { 23095cb1dd27SAsmitha Karunanithi entityPrivileges = { 23105cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 23115cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 23125cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 23135cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 23145cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 23155cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 23165cb1dd27SAsmitha Karunanithi } 23175cb1dd27SAsmitha Karunanithi 23185cb1dd27SAsmitha Karunanithi private: 2319cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 23205cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 23215cb1dd27SAsmitha Karunanithi { 23225cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 23235cb1dd27SAsmitha Karunanithi if (params.size() != 1) 23245cb1dd27SAsmitha Karunanithi { 2325c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2326c9bb6861Sraviteja-b return; 2327c9bb6861Sraviteja-b } 23285cb1dd27SAsmitha Karunanithi getDumpEntryById(asyncResp, params[0], "System"); 23295cb1dd27SAsmitha Karunanithi } 2330c9bb6861Sraviteja-b 2331cb13a392SEd Tanous void doDelete(crow::Response& res, const crow::Request&, 23325cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 2333c9bb6861Sraviteja-b { 23345cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 23355cb1dd27SAsmitha Karunanithi if (params.size() != 1) 2336c9bb6861Sraviteja-b { 23375cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 2338c9bb6861Sraviteja-b return; 2339c9bb6861Sraviteja-b } 23405cb1dd27SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, params[0]); 2341c9bb6861Sraviteja-b } 2342c9bb6861Sraviteja-b }; 2343c9bb6861Sraviteja-b 2344a43be80fSAsmitha Karunanithi class SystemDumpCreate : public Node 2345a43be80fSAsmitha Karunanithi { 2346a43be80fSAsmitha Karunanithi public: 234752cc112dSEd Tanous SystemDumpCreate(App& app) : 2348a43be80fSAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2349a43be80fSAsmitha Karunanithi "Actions/Oem/" 2350a43be80fSAsmitha Karunanithi "OemLogService.CollectDiagnosticData/") 2351a43be80fSAsmitha Karunanithi { 2352a43be80fSAsmitha Karunanithi entityPrivileges = { 2353a43be80fSAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2354a43be80fSAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2355a43be80fSAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2356a43be80fSAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2357a43be80fSAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2358a43be80fSAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2359a43be80fSAsmitha Karunanithi } 2360a43be80fSAsmitha Karunanithi 2361a43be80fSAsmitha Karunanithi private: 2362a43be80fSAsmitha Karunanithi void doPost(crow::Response& res, const crow::Request& req, 2363cb13a392SEd Tanous const std::vector<std::string>&) override 2364a43be80fSAsmitha Karunanithi { 2365a43be80fSAsmitha Karunanithi createDump(res, req, "System"); 2366a43be80fSAsmitha Karunanithi } 2367a43be80fSAsmitha Karunanithi }; 2368a43be80fSAsmitha Karunanithi 23690657843aSraviteja-b class SystemDumpEntryDownload : public Node 23700657843aSraviteja-b { 23710657843aSraviteja-b public: 237252cc112dSEd Tanous SystemDumpEntryDownload(App& app) : 23730657843aSraviteja-b Node(app, 2374f71882ffSAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/attachment/<str>/", 23750657843aSraviteja-b std::string()) 23760657843aSraviteja-b { 23770657843aSraviteja-b entityPrivileges = { 23780657843aSraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 23790657843aSraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2380f71882ffSAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2381f71882ffSAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2382f71882ffSAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 23830657843aSraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 23840657843aSraviteja-b } 23850657843aSraviteja-b 23860657843aSraviteja-b private: 2387f71882ffSAsmitha Karunanithi void doGet(crow::Response& res, const crow::Request& req, 23880657843aSraviteja-b const std::vector<std::string>& params) override 23890657843aSraviteja-b { 23900657843aSraviteja-b if (params.size() != 1) 23910657843aSraviteja-b { 23920657843aSraviteja-b messages::internalError(res); 23930657843aSraviteja-b return; 23940657843aSraviteja-b } 23950657843aSraviteja-b const std::string& entryID = params[0]; 23960657843aSraviteja-b crow::obmc_dump::handleDumpOffloadUrl(req, res, entryID); 23970657843aSraviteja-b } 23980657843aSraviteja-b }; 23990657843aSraviteja-b 2400013487e5Sraviteja-b class SystemDumpClear : public Node 2401013487e5Sraviteja-b { 2402013487e5Sraviteja-b public: 240352cc112dSEd Tanous SystemDumpClear(App& app) : 240480319af1SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2405013487e5Sraviteja-b "Actions/" 2406013487e5Sraviteja-b "LogService.ClearLog/") 2407013487e5Sraviteja-b { 2408013487e5Sraviteja-b entityPrivileges = { 2409013487e5Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2410013487e5Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 241180319af1SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 241280319af1SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 241380319af1SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2414013487e5Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2415013487e5Sraviteja-b } 2416013487e5Sraviteja-b 2417013487e5Sraviteja-b private: 2418cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2419cb13a392SEd Tanous const std::vector<std::string>&) override 2420013487e5Sraviteja-b { 242180319af1SAsmitha Karunanithi clearDump(res, "xyz.openbmc_project.Dump.Entry.System"); 2422013487e5Sraviteja-b } 2423013487e5Sraviteja-b }; 2424013487e5Sraviteja-b 2425424c4176SJason M. Bills class CrashdumpService : public Node 2426e1f26343SJason M. Bills { 2427e1f26343SJason M. Bills public: 242852cc112dSEd Tanous CrashdumpService(App& app) : 2429424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 24301da66f75SEd Tanous { 24313946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24323946028dSAppaRao Puli // method for security reasons. 24331da66f75SEd Tanous entityPrivileges = { 24343946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 24353946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2436e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2437e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2438e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2439e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 24401da66f75SEd Tanous } 24411da66f75SEd Tanous 24421da66f75SEd Tanous private: 24431da66f75SEd Tanous /** 24441da66f75SEd Tanous * Functions triggers appropriate requests on DBus 24451da66f75SEd Tanous */ 2446cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2447cb13a392SEd Tanous const std::vector<std::string>&) override 24481da66f75SEd Tanous { 2449e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 24501da66f75SEd Tanous // Copy over the static data to include the entries added by SubRoute 24510f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2452424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2453e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2454e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 24554f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 24564f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 24574f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2458e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2459e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 2460cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2461cd50aa42SJason M. Bills {"@odata.id", 2462424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 2463e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 24645b61b5e8SJason M. Bills {"#LogService.ClearLog", 24655b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 24665b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 24671da66f75SEd Tanous {"Oem", 2468424c4176SJason M. Bills {{"#Crashdump.OnDemand", 2469424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 24706eda7685SKenny L. Ku "Actions/Oem/Crashdump.OnDemand"}}}, 24716eda7685SKenny L. Ku {"#Crashdump.Telemetry", 24726eda7685SKenny L. Ku {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 24736eda7685SKenny L. Ku "Actions/Oem/Crashdump.Telemetry"}}}}}}; 24741da66f75SEd Tanous 24751da66f75SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI 2476e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"]["Oem"].push_back( 2477424c4176SJason M. Bills {"#Crashdump.SendRawPeci", 247808a4e4b5SAnthony Wilson {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 2479424c4176SJason M. Bills "Actions/Oem/Crashdump.SendRawPeci"}}}); 24801da66f75SEd Tanous #endif 24811da66f75SEd Tanous } 24821da66f75SEd Tanous }; 24831da66f75SEd Tanous 24845b61b5e8SJason M. Bills class CrashdumpClear : public Node 24855b61b5e8SJason M. Bills { 24865b61b5e8SJason M. Bills public: 248752cc112dSEd Tanous CrashdumpClear(App& app) : 24885b61b5e8SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 24895b61b5e8SJason M. Bills "LogService.ClearLog/") 24905b61b5e8SJason M. Bills { 24913946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24923946028dSAppaRao Puli // method for security reasons. 24935b61b5e8SJason M. Bills entityPrivileges = { 24943946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 24953946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 24965b61b5e8SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 24975b61b5e8SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 24985b61b5e8SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 24995b61b5e8SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 25005b61b5e8SJason M. Bills } 25015b61b5e8SJason M. Bills 25025b61b5e8SJason M. Bills private: 2503cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2504cb13a392SEd Tanous const std::vector<std::string>&) override 25055b61b5e8SJason M. Bills { 25065b61b5e8SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 25075b61b5e8SJason M. Bills 25085b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 25095b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2510cb13a392SEd Tanous const std::string&) { 25115b61b5e8SJason M. Bills if (ec) 25125b61b5e8SJason M. Bills { 25135b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 25145b61b5e8SJason M. Bills return; 25155b61b5e8SJason M. Bills } 25165b61b5e8SJason M. Bills messages::success(asyncResp->res); 25175b61b5e8SJason M. Bills }, 25185b61b5e8SJason M. Bills crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 25195b61b5e8SJason M. Bills } 25205b61b5e8SJason M. Bills }; 25215b61b5e8SJason M. Bills 2522e855dd28SJason M. Bills static void logCrashdumpEntry(std::shared_ptr<AsyncResp> asyncResp, 2523e855dd28SJason M. Bills const std::string& logID, 2524e855dd28SJason M. Bills nlohmann::json& logEntryJson) 2525e855dd28SJason M. Bills { 2526043a0536SJohnathan Mantey auto getStoredLogCallback = 2527043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 2528e855dd28SJason M. Bills const boost::system::error_code ec, 2529043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params) { 2530e855dd28SJason M. Bills if (ec) 2531e855dd28SJason M. Bills { 2532e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 25331ddcf01aSJason M. Bills if (ec.value() == 25341ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 25351ddcf01aSJason M. Bills { 2536043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2537043a0536SJohnathan Mantey logID); 25381ddcf01aSJason M. Bills } 25391ddcf01aSJason M. Bills else 25401ddcf01aSJason M. Bills { 2541e855dd28SJason M. Bills messages::internalError(asyncResp->res); 25421ddcf01aSJason M. Bills } 2543e855dd28SJason M. Bills return; 2544e855dd28SJason M. Bills } 2545043a0536SJohnathan Mantey 2546043a0536SJohnathan Mantey std::string timestamp{}; 2547043a0536SJohnathan Mantey std::string filename{}; 2548043a0536SJohnathan Mantey std::string logfile{}; 2549043a0536SJohnathan Mantey ParseCrashdumpParameters(params, filename, timestamp, logfile); 2550043a0536SJohnathan Mantey 2551043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2552e855dd28SJason M. Bills { 2553043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 2554e855dd28SJason M. Bills return; 2555e855dd28SJason M. Bills } 2556e855dd28SJason M. Bills 2557043a0536SJohnathan Mantey std::string crashdumpURI = 2558e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2559043a0536SJohnathan Mantey logID + "/" + filename; 2560043a0536SJohnathan Mantey logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 2561043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 2562043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 2563e855dd28SJason M. Bills logID}, 2564e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2565e855dd28SJason M. Bills {"Id", logID}, 2566e855dd28SJason M. Bills {"EntryType", "Oem"}, 2567e855dd28SJason M. Bills {"OemRecordFormat", "Crashdump URI"}, 2568043a0536SJohnathan Mantey {"Message", std::move(crashdumpURI)}, 2569043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2570e855dd28SJason M. Bills }; 2571e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 25725b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 25735b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2574043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2575e855dd28SJason M. Bills } 2576e855dd28SJason M. Bills 2577424c4176SJason M. Bills class CrashdumpEntryCollection : public Node 25781da66f75SEd Tanous { 25791da66f75SEd Tanous public: 258052cc112dSEd Tanous CrashdumpEntryCollection(App& app) : 2581424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 25821da66f75SEd Tanous { 25833946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25843946028dSAppaRao Puli // method for security reasons. 25851da66f75SEd Tanous entityPrivileges = { 25863946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 25873946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2588e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2589e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2590e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2591e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 25921da66f75SEd Tanous } 25931da66f75SEd Tanous 25941da66f75SEd Tanous private: 25951da66f75SEd Tanous /** 25961da66f75SEd Tanous * Functions triggers appropriate requests on DBus 25971da66f75SEd Tanous */ 2598cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2599cb13a392SEd Tanous const std::vector<std::string>&) override 26001da66f75SEd Tanous { 2601e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 26021da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 26031da66f75SEd Tanous // it has a duplicate entry for members 2604e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2605e1f26343SJason M. Bills const boost::system::error_code ec, 26061da66f75SEd Tanous const std::vector<std::string>& resp) { 26071da66f75SEd Tanous if (ec) 26081da66f75SEd Tanous { 26091da66f75SEd Tanous if (ec.value() != 26101da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 26111da66f75SEd Tanous { 26121da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 26131da66f75SEd Tanous << ec.message(); 2614f12894f8SJason M. Bills messages::internalError(asyncResp->res); 26151da66f75SEd Tanous return; 26161da66f75SEd Tanous } 26171da66f75SEd Tanous } 2618e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 26191da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 26200f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2621424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2622424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2623e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2624424c4176SJason M. Bills "Collection of Crashdump Entries"; 2625e1f26343SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2626e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2627e855dd28SJason M. Bills std::vector<std::string> logIDs; 2628e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2629e855dd28SJason M. Bills // enough to hold them 26301da66f75SEd Tanous for (const std::string& objpath : resp) 26311da66f75SEd Tanous { 2632e855dd28SJason M. Bills // Get the log ID 26334ed77cd5SEd Tanous std::size_t lastPos = objpath.rfind("/"); 2634e855dd28SJason M. Bills if (lastPos == std::string::npos) 26351da66f75SEd Tanous { 2636e855dd28SJason M. Bills continue; 26371da66f75SEd Tanous } 2638e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2639e855dd28SJason M. Bills 2640e855dd28SJason M. Bills // Add a space for the log entry to the array 2641e855dd28SJason M. Bills logEntryArray.push_back({}); 2642e855dd28SJason M. Bills } 2643e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2644e855dd28SJason M. Bills size_t index = 0; 2645e855dd28SJason M. Bills for (const std::string& logID : logIDs) 2646e855dd28SJason M. Bills { 2647e855dd28SJason M. Bills // Add the log entry to the array 2648e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 26491da66f75SEd Tanous } 2650e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2651e1f26343SJason M. Bills logEntryArray.size(); 26521da66f75SEd Tanous }; 26531da66f75SEd Tanous crow::connections::systemBus->async_method_call( 26541da66f75SEd Tanous std::move(getLogEntriesCallback), 26551da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 26561da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 26571da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 26585b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 26591da66f75SEd Tanous } 26601da66f75SEd Tanous }; 26611da66f75SEd Tanous 2662424c4176SJason M. Bills class CrashdumpEntry : public Node 26631da66f75SEd Tanous { 26641da66f75SEd Tanous public: 266552cc112dSEd Tanous CrashdumpEntry(App& app) : 2666d53dd41fSJason M. Bills Node(app, 2667424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/", 26681da66f75SEd Tanous std::string()) 26691da66f75SEd Tanous { 26703946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 26713946028dSAppaRao Puli // method for security reasons. 26721da66f75SEd Tanous entityPrivileges = { 26733946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 26743946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2675e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2676e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2677e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2678e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 26791da66f75SEd Tanous } 26801da66f75SEd Tanous 26811da66f75SEd Tanous private: 2682cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 26831da66f75SEd Tanous const std::vector<std::string>& params) override 26841da66f75SEd Tanous { 2685e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 26861da66f75SEd Tanous if (params.size() != 1) 26871da66f75SEd Tanous { 2688f12894f8SJason M. Bills messages::internalError(asyncResp->res); 26891da66f75SEd Tanous return; 26901da66f75SEd Tanous } 2691e855dd28SJason M. Bills const std::string& logID = params[0]; 2692e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 2693e855dd28SJason M. Bills } 2694e855dd28SJason M. Bills }; 2695e855dd28SJason M. Bills 2696e855dd28SJason M. Bills class CrashdumpFile : public Node 2697e855dd28SJason M. Bills { 2698e855dd28SJason M. Bills public: 269952cc112dSEd Tanous CrashdumpFile(App& app) : 2700e855dd28SJason M. Bills Node(app, 2701e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/" 2702e855dd28SJason M. Bills "<str>/", 2703e855dd28SJason M. Bills std::string(), std::string()) 2704e855dd28SJason M. Bills { 27053946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 27063946028dSAppaRao Puli // method for security reasons. 2707e855dd28SJason M. Bills entityPrivileges = { 27083946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 27093946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2710e855dd28SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2711e855dd28SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2712e855dd28SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2713e855dd28SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2714e855dd28SJason M. Bills } 2715e855dd28SJason M. Bills 2716e855dd28SJason M. Bills private: 2717cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2718e855dd28SJason M. Bills const std::vector<std::string>& params) override 2719e855dd28SJason M. Bills { 2720e855dd28SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2721e855dd28SJason M. Bills if (params.size() != 2) 2722e855dd28SJason M. Bills { 2723e855dd28SJason M. Bills messages::internalError(asyncResp->res); 2724e855dd28SJason M. Bills return; 2725e855dd28SJason M. Bills } 2726e855dd28SJason M. Bills const std::string& logID = params[0]; 2727e855dd28SJason M. Bills const std::string& fileName = params[1]; 2728e855dd28SJason M. Bills 2729043a0536SJohnathan Mantey auto getStoredLogCallback = 2730043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 2731abf2add6SEd Tanous const boost::system::error_code ec, 2732043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& resp) { 27331da66f75SEd Tanous if (ec) 27341da66f75SEd Tanous { 2735043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2736043a0536SJohnathan Mantey << ec.message(); 2737f12894f8SJason M. Bills messages::internalError(asyncResp->res); 27381da66f75SEd Tanous return; 27391da66f75SEd Tanous } 2740e855dd28SJason M. Bills 2741043a0536SJohnathan Mantey std::string dbusFilename{}; 2742043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2743043a0536SJohnathan Mantey std::string dbusFilepath{}; 2744043a0536SJohnathan Mantey 2745043a0536SJohnathan Mantey ParseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 2746043a0536SJohnathan Mantey dbusFilepath); 2747043a0536SJohnathan Mantey 2748043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2749043a0536SJohnathan Mantey dbusFilepath.empty()) 27501da66f75SEd Tanous { 2751e855dd28SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, fileName); 27521da66f75SEd Tanous return; 27531da66f75SEd Tanous } 2754e855dd28SJason M. Bills 2755043a0536SJohnathan Mantey // Verify the file name parameter is correct 2756043a0536SJohnathan Mantey if (fileName != dbusFilename) 2757043a0536SJohnathan Mantey { 2758043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2759043a0536SJohnathan Mantey return; 2760043a0536SJohnathan Mantey } 2761043a0536SJohnathan Mantey 2762043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2763043a0536SJohnathan Mantey { 2764043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2765043a0536SJohnathan Mantey return; 2766043a0536SJohnathan Mantey } 2767043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 2768043a0536SJohnathan Mantey std::ios::binary | 2769043a0536SJohnathan Mantey std::ios::ate); 2770043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 2771043a0536SJohnathan Mantey if (fileSize < 0) 2772043a0536SJohnathan Mantey { 2773043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 2774043a0536SJohnathan Mantey return; 2775043a0536SJohnathan Mantey } 2776043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 2777043a0536SJohnathan Mantey 2778043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 2779043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 2780043a0536SJohnathan Mantey 2781043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 2782043a0536SJohnathan Mantey 2783043a0536SJohnathan Mantey // The cast to std::string is intentional in order to use the 2784043a0536SJohnathan Mantey // assign() that applies move mechanics 2785043a0536SJohnathan Mantey asyncResp->res.body().assign( 2786043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 2787043a0536SJohnathan Mantey 2788043a0536SJohnathan Mantey // Configure this to be a file download when accessed from 2789043a0536SJohnathan Mantey // a browser 2790e855dd28SJason M. Bills asyncResp->res.addHeader("Content-Disposition", "attachment"); 27911da66f75SEd Tanous }; 27921da66f75SEd Tanous crow::connections::systemBus->async_method_call( 27935b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 27945b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2795043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 27961da66f75SEd Tanous } 27971da66f75SEd Tanous }; 27981da66f75SEd Tanous 2799424c4176SJason M. Bills class OnDemandCrashdump : public Node 28001da66f75SEd Tanous { 28011da66f75SEd Tanous public: 280252cc112dSEd Tanous OnDemandCrashdump(App& app) : 2803424c4176SJason M. Bills Node(app, 2804424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2805424c4176SJason M. Bills "Crashdump.OnDemand/") 28061da66f75SEd Tanous { 28073946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28083946028dSAppaRao Puli // method for security reasons. 28091da66f75SEd Tanous entityPrivileges = { 28103946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 28113946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 28123946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 28133946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 28143946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 28153946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 28161da66f75SEd Tanous } 28171da66f75SEd Tanous 28181da66f75SEd Tanous private: 28191da66f75SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 2820cb13a392SEd Tanous const std::vector<std::string>&) override 28211da66f75SEd Tanous { 2822e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 28231da66f75SEd Tanous 2824fe306728SJames Feist auto generateonDemandLogCallback = [asyncResp, 2825fe306728SJames Feist req](const boost::system::error_code 282646229577SJames Feist ec, 2827cb13a392SEd Tanous const std::string&) { 28281da66f75SEd Tanous if (ec) 28291da66f75SEd Tanous { 283046229577SJames Feist if (ec.value() == boost::system::errc::operation_not_supported) 28311da66f75SEd Tanous { 2832f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 28331da66f75SEd Tanous } 28344363d3b2SJason M. Bills else if (ec.value() == 28354363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 28364363d3b2SJason M. Bills { 28374363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 28384363d3b2SJason M. Bills "60"); 28394363d3b2SJason M. Bills } 28401da66f75SEd Tanous else 28411da66f75SEd Tanous { 2842f12894f8SJason M. Bills messages::internalError(asyncResp->res); 28431da66f75SEd Tanous } 28441da66f75SEd Tanous return; 28451da66f75SEd Tanous } 284646229577SJames Feist std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 284766afe4faSJames Feist [](boost::system::error_code err, sdbusplus::message::message&, 284866afe4faSJames Feist const std::shared_ptr<task::TaskData>& taskData) { 284966afe4faSJames Feist if (!err) 285066afe4faSJames Feist { 2851e5d5006bSJames Feist taskData->messages.emplace_back( 2852e5d5006bSJames Feist messages::taskCompletedOK( 2853e5d5006bSJames Feist std::to_string(taskData->index))); 2854831d6b09SJames Feist taskData->state = "Completed"; 285566afe4faSJames Feist } 285632898ceaSJames Feist return task::completed; 285766afe4faSJames Feist }, 285846229577SJames Feist "type='signal',interface='org.freedesktop.DBus.Properties'," 285946229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 286046229577SJames Feist "crashdump'"); 286146229577SJames Feist task->startTimer(std::chrono::minutes(5)); 286246229577SJames Feist task->populateResp(asyncResp->res); 2863fe306728SJames Feist task->payload.emplace(req); 28641da66f75SEd Tanous }; 28651da66f75SEd Tanous crow::connections::systemBus->async_method_call( 28665b61b5e8SJason M. Bills std::move(generateonDemandLogCallback), crashdumpObject, 28675b61b5e8SJason M. Bills crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog"); 28681da66f75SEd Tanous } 28691da66f75SEd Tanous }; 28701da66f75SEd Tanous 28716eda7685SKenny L. Ku class TelemetryCrashdump : public Node 28726eda7685SKenny L. Ku { 28736eda7685SKenny L. Ku public: 287452cc112dSEd Tanous TelemetryCrashdump(App& app) : 28756eda7685SKenny L. Ku Node(app, 28766eda7685SKenny L. Ku "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 28776eda7685SKenny L. Ku "Crashdump.Telemetry/") 28786eda7685SKenny L. Ku { 28796eda7685SKenny L. Ku // Note: Deviated from redfish privilege registry for GET & HEAD 28806eda7685SKenny L. Ku // method for security reasons. 28816eda7685SKenny L. Ku entityPrivileges = { 28826eda7685SKenny L. Ku {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 28836eda7685SKenny L. Ku {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 28846eda7685SKenny L. Ku {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 28856eda7685SKenny L. Ku {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 28866eda7685SKenny L. Ku {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 28876eda7685SKenny L. Ku {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 28886eda7685SKenny L. Ku } 28896eda7685SKenny L. Ku 28906eda7685SKenny L. Ku private: 28916eda7685SKenny L. Ku void doPost(crow::Response& res, const crow::Request& req, 2892cb13a392SEd Tanous const std::vector<std::string>&) override 28936eda7685SKenny L. Ku { 28946eda7685SKenny L. Ku std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 28956eda7685SKenny L. Ku 28966eda7685SKenny L. Ku auto generateTelemetryLogCallback = [asyncResp, req]( 28976eda7685SKenny L. Ku const boost::system::error_code 28986eda7685SKenny L. Ku ec, 2899cb13a392SEd Tanous const std::string&) { 29006eda7685SKenny L. Ku if (ec) 29016eda7685SKenny L. Ku { 29026eda7685SKenny L. Ku if (ec.value() == boost::system::errc::operation_not_supported) 29036eda7685SKenny L. Ku { 29046eda7685SKenny L. Ku messages::resourceInStandby(asyncResp->res); 29056eda7685SKenny L. Ku } 29066eda7685SKenny L. Ku else if (ec.value() == 29076eda7685SKenny L. Ku boost::system::errc::device_or_resource_busy) 29086eda7685SKenny L. Ku { 29096eda7685SKenny L. Ku messages::serviceTemporarilyUnavailable(asyncResp->res, 29106eda7685SKenny L. Ku "60"); 29116eda7685SKenny L. Ku } 29126eda7685SKenny L. Ku else 29136eda7685SKenny L. Ku { 29146eda7685SKenny L. Ku messages::internalError(asyncResp->res); 29156eda7685SKenny L. Ku } 29166eda7685SKenny L. Ku return; 29176eda7685SKenny L. Ku } 29186eda7685SKenny L. Ku std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 29196eda7685SKenny L. Ku [](boost::system::error_code err, sdbusplus::message::message&, 29206eda7685SKenny L. Ku const std::shared_ptr<task::TaskData>& taskData) { 29216eda7685SKenny L. Ku if (!err) 29226eda7685SKenny L. Ku { 29236eda7685SKenny L. Ku taskData->messages.emplace_back( 29246eda7685SKenny L. Ku messages::taskCompletedOK( 29256eda7685SKenny L. Ku std::to_string(taskData->index))); 29266eda7685SKenny L. Ku taskData->state = "Completed"; 29276eda7685SKenny L. Ku } 29286eda7685SKenny L. Ku return task::completed; 29296eda7685SKenny L. Ku }, 29306eda7685SKenny L. Ku "type='signal',interface='org.freedesktop.DBus.Properties'," 29316eda7685SKenny L. Ku "member='PropertiesChanged',arg0namespace='com.intel." 29326eda7685SKenny L. Ku "crashdump'"); 29336eda7685SKenny L. Ku task->startTimer(std::chrono::minutes(5)); 29346eda7685SKenny L. Ku task->populateResp(asyncResp->res); 29356eda7685SKenny L. Ku task->payload.emplace(req); 29366eda7685SKenny L. Ku }; 29376eda7685SKenny L. Ku crow::connections::systemBus->async_method_call( 29386eda7685SKenny L. Ku std::move(generateTelemetryLogCallback), crashdumpObject, 29396eda7685SKenny L. Ku crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog"); 29406eda7685SKenny L. Ku } 29416eda7685SKenny L. Ku }; 29426eda7685SKenny L. Ku 2943e1f26343SJason M. Bills class SendRawPECI : public Node 29441da66f75SEd Tanous { 29451da66f75SEd Tanous public: 294652cc112dSEd Tanous SendRawPECI(App& app) : 2947424c4176SJason M. Bills Node(app, 2948424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2949424c4176SJason M. Bills "Crashdump.SendRawPeci/") 29501da66f75SEd Tanous { 29513946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 29523946028dSAppaRao Puli // method for security reasons. 29531da66f75SEd Tanous entityPrivileges = { 29541da66f75SEd Tanous {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 29551da66f75SEd Tanous {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 29561da66f75SEd Tanous {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 29571da66f75SEd Tanous {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 29581da66f75SEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 29591da66f75SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 29601da66f75SEd Tanous } 29611da66f75SEd Tanous 29621da66f75SEd Tanous private: 29631da66f75SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 2964cb13a392SEd Tanous const std::vector<std::string>&) override 29651da66f75SEd Tanous { 2966e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 29678724c297SKarthick Sundarrajan std::vector<std::vector<uint8_t>> peciCommands; 29688724c297SKarthick Sundarrajan 29698724c297SKarthick Sundarrajan if (!json_util::readJson(req, res, "PECICommands", peciCommands)) 29708724c297SKarthick Sundarrajan { 29718724c297SKarthick Sundarrajan return; 29728724c297SKarthick Sundarrajan } 29738724c297SKarthick Sundarrajan uint32_t idx = 0; 29748724c297SKarthick Sundarrajan for (auto const& cmd : peciCommands) 29758724c297SKarthick Sundarrajan { 29768724c297SKarthick Sundarrajan if (cmd.size() < 3) 29778724c297SKarthick Sundarrajan { 29788724c297SKarthick Sundarrajan std::string s("["); 29798724c297SKarthick Sundarrajan for (auto const& val : cmd) 29808724c297SKarthick Sundarrajan { 29818724c297SKarthick Sundarrajan if (val != *cmd.begin()) 29828724c297SKarthick Sundarrajan { 29838724c297SKarthick Sundarrajan s += ","; 29848724c297SKarthick Sundarrajan } 29858724c297SKarthick Sundarrajan s += std::to_string(val); 29868724c297SKarthick Sundarrajan } 29878724c297SKarthick Sundarrajan s += "]"; 29888724c297SKarthick Sundarrajan messages::actionParameterValueFormatError( 29898724c297SKarthick Sundarrajan res, s, "PECICommands[" + std::to_string(idx) + "]", 29908724c297SKarthick Sundarrajan "SendRawPeci"); 29918724c297SKarthick Sundarrajan return; 29928724c297SKarthick Sundarrajan } 29938724c297SKarthick Sundarrajan idx++; 29948724c297SKarthick Sundarrajan } 29951da66f75SEd Tanous // Callback to return the Raw PECI response 2996e1f26343SJason M. Bills auto sendRawPECICallback = 2997e1f26343SJason M. Bills [asyncResp](const boost::system::error_code ec, 29988724c297SKarthick Sundarrajan const std::vector<std::vector<uint8_t>>& resp) { 29991da66f75SEd Tanous if (ec) 30001da66f75SEd Tanous { 30018724c297SKarthick Sundarrajan BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: " 30021da66f75SEd Tanous << ec.message(); 3003f12894f8SJason M. Bills messages::internalError(asyncResp->res); 30041da66f75SEd Tanous return; 30051da66f75SEd Tanous } 3006e1f26343SJason M. Bills asyncResp->res.jsonValue = {{"Name", "PECI Command Response"}, 30071da66f75SEd Tanous {"PECIResponse", resp}}; 30081da66f75SEd Tanous }; 30091da66f75SEd Tanous // Call the SendRawPECI command with the provided data 30101da66f75SEd Tanous crow::connections::systemBus->async_method_call( 30115b61b5e8SJason M. Bills std::move(sendRawPECICallback), crashdumpObject, crashdumpPath, 30128724c297SKarthick Sundarrajan crashdumpRawPECIInterface, "SendRawPeci", peciCommands); 30131da66f75SEd Tanous } 30141da66f75SEd Tanous }; 30151da66f75SEd Tanous 3016cb92c03bSAndrew Geissler /** 3017cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 3018cb92c03bSAndrew Geissler */ 3019cb92c03bSAndrew Geissler class DBusLogServiceActionsClear : public Node 3020cb92c03bSAndrew Geissler { 3021cb92c03bSAndrew Geissler public: 302252cc112dSEd Tanous DBusLogServiceActionsClear(App& app) : 3023cb92c03bSAndrew Geissler Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 30247af91514SGunnar Mills "LogService.ClearLog/") 3025cb92c03bSAndrew Geissler { 3026cb92c03bSAndrew Geissler entityPrivileges = { 3027cb92c03bSAndrew Geissler {boost::beast::http::verb::get, {{"Login"}}}, 3028cb92c03bSAndrew Geissler {boost::beast::http::verb::head, {{"Login"}}}, 3029cb92c03bSAndrew Geissler {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3030cb92c03bSAndrew Geissler {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3031cb92c03bSAndrew Geissler {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3032cb92c03bSAndrew Geissler {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3033cb92c03bSAndrew Geissler } 3034cb92c03bSAndrew Geissler 3035cb92c03bSAndrew Geissler private: 3036cb92c03bSAndrew Geissler /** 3037cb92c03bSAndrew Geissler * Function handles POST method request. 3038cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3039cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3040cb92c03bSAndrew Geissler */ 3041cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 3042cb13a392SEd Tanous const std::vector<std::string>&) override 3043cb92c03bSAndrew Geissler { 3044cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 3045cb92c03bSAndrew Geissler 3046cb92c03bSAndrew Geissler auto asyncResp = std::make_shared<AsyncResp>(res); 3047cb92c03bSAndrew Geissler // Process response from Logging service. 3048cb92c03bSAndrew Geissler auto resp_handler = [asyncResp](const boost::system::error_code ec) { 3049cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 3050cb92c03bSAndrew Geissler if (ec) 3051cb92c03bSAndrew Geissler { 3052cb92c03bSAndrew Geissler // TODO Handle for specific error code 3053cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 3054cb92c03bSAndrew Geissler asyncResp->res.result( 3055cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3056cb92c03bSAndrew Geissler return; 3057cb92c03bSAndrew Geissler } 3058cb92c03bSAndrew Geissler 3059cb92c03bSAndrew Geissler asyncResp->res.result(boost::beast::http::status::no_content); 3060cb92c03bSAndrew Geissler }; 3061cb92c03bSAndrew Geissler 3062cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3063cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 3064cb92c03bSAndrew Geissler resp_handler, "xyz.openbmc_project.Logging", 3065cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3066cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 3067cb92c03bSAndrew Geissler } 3068cb92c03bSAndrew Geissler }; 3069a3316fc6SZhikuiRen 3070a3316fc6SZhikuiRen /**************************************************** 3071a3316fc6SZhikuiRen * Redfish PostCode interfaces 3072a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3073a3316fc6SZhikuiRen ******************************************************/ 3074a3316fc6SZhikuiRen class PostCodesLogService : public Node 3075a3316fc6SZhikuiRen { 3076a3316fc6SZhikuiRen public: 307752cc112dSEd Tanous PostCodesLogService(App& app) : 3078a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 3079a3316fc6SZhikuiRen { 3080a3316fc6SZhikuiRen entityPrivileges = { 3081a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3082a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3083a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3084a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3085a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3086a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3087a3316fc6SZhikuiRen } 3088a3316fc6SZhikuiRen 3089a3316fc6SZhikuiRen private: 3090cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 3091cb13a392SEd Tanous const std::vector<std::string>&) override 3092a3316fc6SZhikuiRen { 3093a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3094a3316fc6SZhikuiRen 3095a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 3096a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"}, 3097a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 3098a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogService.LogService"}, 3099a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 3100a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 3101a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 3102a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 3103a3316fc6SZhikuiRen {"Entries", 3104a3316fc6SZhikuiRen {{"@odata.id", 3105a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}}; 3106a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 3107a3316fc6SZhikuiRen {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/" 3108a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 3109a3316fc6SZhikuiRen } 3110a3316fc6SZhikuiRen }; 3111a3316fc6SZhikuiRen 3112a3316fc6SZhikuiRen class PostCodesClear : public Node 3113a3316fc6SZhikuiRen { 3114a3316fc6SZhikuiRen public: 311552cc112dSEd Tanous PostCodesClear(App& app) : 3116a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 3117a3316fc6SZhikuiRen "LogService.ClearLog/") 3118a3316fc6SZhikuiRen { 3119a3316fc6SZhikuiRen entityPrivileges = { 3120a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3121a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 31223946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 31233946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 31243946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 31253946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 3126a3316fc6SZhikuiRen } 3127a3316fc6SZhikuiRen 3128a3316fc6SZhikuiRen private: 3129cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 3130cb13a392SEd Tanous const std::vector<std::string>&) override 3131a3316fc6SZhikuiRen { 3132a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3133a3316fc6SZhikuiRen 3134a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3135a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3136a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3137a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3138a3316fc6SZhikuiRen if (ec) 3139a3316fc6SZhikuiRen { 3140a3316fc6SZhikuiRen // TODO Handle for specific error code 3141a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 3142a3316fc6SZhikuiRen << "doClearPostCodes resp_handler got error " << ec; 3143a3316fc6SZhikuiRen asyncResp->res.result( 3144a3316fc6SZhikuiRen boost::beast::http::status::internal_server_error); 3145a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3146a3316fc6SZhikuiRen return; 3147a3316fc6SZhikuiRen } 3148a3316fc6SZhikuiRen }, 3149a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3150a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3151a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 3152a3316fc6SZhikuiRen } 3153a3316fc6SZhikuiRen }; 3154a3316fc6SZhikuiRen 3155a3316fc6SZhikuiRen static void fillPostCodeEntry( 3156a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> aResp, 3157a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode, 3158a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3159a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3160a3316fc6SZhikuiRen { 3161a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3162a3316fc6SZhikuiRen const message_registries::Message* message = 3163a3316fc6SZhikuiRen message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode"); 3164a3316fc6SZhikuiRen 3165a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3166a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 3167a3316fc6SZhikuiRen 3168a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 3169a3316fc6SZhikuiRen for (const std::pair<uint64_t, uint64_t>& code : postcode) 3170a3316fc6SZhikuiRen { 3171a3316fc6SZhikuiRen currentCodeIndex++; 3172a3316fc6SZhikuiRen std::string postcodeEntryID = 3173a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3174a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3175a3316fc6SZhikuiRen 3176a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3177a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3178a3316fc6SZhikuiRen 3179a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3180a3316fc6SZhikuiRen { // already incremented 3181a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3182a3316fc6SZhikuiRen } 3183a3316fc6SZhikuiRen else 3184a3316fc6SZhikuiRen { 3185a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3186a3316fc6SZhikuiRen } 3187a3316fc6SZhikuiRen 3188a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3189a3316fc6SZhikuiRen // not fall between top and skip 3190a3316fc6SZhikuiRen if ((codeIndex == 0) && 3191a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3192a3316fc6SZhikuiRen { 3193a3316fc6SZhikuiRen continue; 3194a3316fc6SZhikuiRen } 3195a3316fc6SZhikuiRen 31964e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3197a3316fc6SZhikuiRen // currentIndex 3198a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3199a3316fc6SZhikuiRen { 3200a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3201a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3202a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3203a3316fc6SZhikuiRen continue; 3204a3316fc6SZhikuiRen } 3205a3316fc6SZhikuiRen 3206a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3207a3316fc6SZhikuiRen // index 3208a3316fc6SZhikuiRen 3209a3316fc6SZhikuiRen // Get the Created time from the timestamp 3210a3316fc6SZhikuiRen std::string entryTimeStr; 32119c620e21SAsmitha Karunanithi entryTimeStr = crow::utility::getDateTime( 32129c620e21SAsmitha Karunanithi static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000)); 3213a3316fc6SZhikuiRen 3214a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3215a3316fc6SZhikuiRen std::ostringstream hexCode; 3216a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 3217a3316fc6SZhikuiRen << code.second; 3218a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3219a3316fc6SZhikuiRen // Set Fixed -Point Notation 3220a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3221a3316fc6SZhikuiRen // Set precision to 4 digits 3222a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3223a3316fc6SZhikuiRen // Add double to stream 3224a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3225a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3226a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3227a3316fc6SZhikuiRen 3228a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3229a3316fc6SZhikuiRen std::string msg; 3230a3316fc6SZhikuiRen if (message != nullptr) 3231a3316fc6SZhikuiRen { 3232a3316fc6SZhikuiRen msg = message->message; 3233a3316fc6SZhikuiRen 3234a3316fc6SZhikuiRen // fill in this post code value 3235a3316fc6SZhikuiRen int i = 0; 3236a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3237a3316fc6SZhikuiRen { 3238a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3239a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3240a3316fc6SZhikuiRen if (argPos != std::string::npos) 3241a3316fc6SZhikuiRen { 3242a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3243a3316fc6SZhikuiRen } 3244a3316fc6SZhikuiRen } 3245a3316fc6SZhikuiRen } 3246a3316fc6SZhikuiRen 3247d4342a92STim Lee // Get Severity template from message registry 3248d4342a92STim Lee std::string severity; 3249d4342a92STim Lee if (message != nullptr) 3250d4342a92STim Lee { 3251d4342a92STim Lee severity = message->severity; 3252d4342a92STim Lee } 3253d4342a92STim Lee 3254a3316fc6SZhikuiRen // add to AsyncResp 3255a3316fc6SZhikuiRen logEntryArray.push_back({}); 3256a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 3257a3316fc6SZhikuiRen bmcLogEntry = { 3258a3316fc6SZhikuiRen {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 3259a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, 3260a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 3261a3316fc6SZhikuiRen "PostCodes/Entries/" + 3262a3316fc6SZhikuiRen postcodeEntryID}, 3263a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 3264a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 3265a3316fc6SZhikuiRen {"Message", std::move(msg)}, 3266a3316fc6SZhikuiRen {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"}, 3267a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 3268a3316fc6SZhikuiRen {"EntryType", "Event"}, 3269a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 32709c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 3271a3316fc6SZhikuiRen } 3272a3316fc6SZhikuiRen } 3273a3316fc6SZhikuiRen 3274a3316fc6SZhikuiRen static void getPostCodeForEntry(std::shared_ptr<AsyncResp> aResp, 3275a3316fc6SZhikuiRen const uint16_t bootIndex, 3276a3316fc6SZhikuiRen const uint64_t codeIndex) 3277a3316fc6SZhikuiRen { 3278a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3279a3316fc6SZhikuiRen [aResp, bootIndex, codeIndex]( 3280a3316fc6SZhikuiRen const boost::system::error_code ec, 3281a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode) { 3282a3316fc6SZhikuiRen if (ec) 3283a3316fc6SZhikuiRen { 3284a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3285a3316fc6SZhikuiRen messages::internalError(aResp->res); 3286a3316fc6SZhikuiRen return; 3287a3316fc6SZhikuiRen } 3288a3316fc6SZhikuiRen 3289a3316fc6SZhikuiRen // skip the empty postcode boots 3290a3316fc6SZhikuiRen if (postcode.empty()) 3291a3316fc6SZhikuiRen { 3292a3316fc6SZhikuiRen return; 3293a3316fc6SZhikuiRen } 3294a3316fc6SZhikuiRen 3295a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3296a3316fc6SZhikuiRen 3297a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3298a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3299a3316fc6SZhikuiRen }, 3300a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3301a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3302a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3303a3316fc6SZhikuiRen bootIndex); 3304a3316fc6SZhikuiRen } 3305a3316fc6SZhikuiRen 3306a3316fc6SZhikuiRen static void getPostCodeForBoot(std::shared_ptr<AsyncResp> aResp, 3307a3316fc6SZhikuiRen const uint16_t bootIndex, 3308a3316fc6SZhikuiRen const uint16_t bootCount, 3309a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 3310a3316fc6SZhikuiRen const uint64_t top) 3311a3316fc6SZhikuiRen { 3312a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3313a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3314a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3315a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode) { 3316a3316fc6SZhikuiRen if (ec) 3317a3316fc6SZhikuiRen { 3318a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3319a3316fc6SZhikuiRen messages::internalError(aResp->res); 3320a3316fc6SZhikuiRen return; 3321a3316fc6SZhikuiRen } 3322a3316fc6SZhikuiRen 3323a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3324a3316fc6SZhikuiRen if (!postcode.empty()) 3325a3316fc6SZhikuiRen { 3326a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 3327a3316fc6SZhikuiRen 3328a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3329a3316fc6SZhikuiRen { 3330a3316fc6SZhikuiRen uint64_t thisBootSkip = 3331a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3332a3316fc6SZhikuiRen uint64_t thisBootTop = 3333a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3334a3316fc6SZhikuiRen 3335a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3336a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3337a3316fc6SZhikuiRen } 3338a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3339a3316fc6SZhikuiRen } 3340a3316fc6SZhikuiRen 3341a3316fc6SZhikuiRen // continue to previous bootIndex 3342a3316fc6SZhikuiRen if (bootIndex < bootCount) 3343a3316fc6SZhikuiRen { 3344a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3345a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3346a3316fc6SZhikuiRen } 3347a3316fc6SZhikuiRen else 3348a3316fc6SZhikuiRen { 3349a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 3350a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3351a3316fc6SZhikuiRen "Entries?$skip=" + 3352a3316fc6SZhikuiRen std::to_string(skip + top); 3353a3316fc6SZhikuiRen } 3354a3316fc6SZhikuiRen }, 3355a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3356a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3357a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3358a3316fc6SZhikuiRen bootIndex); 3359a3316fc6SZhikuiRen } 3360a3316fc6SZhikuiRen 3361a3316fc6SZhikuiRen static void getCurrentBootNumber(std::shared_ptr<AsyncResp> aResp, 3362a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3363a3316fc6SZhikuiRen { 3364a3316fc6SZhikuiRen uint64_t entryCount = 0; 3365a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3366a3316fc6SZhikuiRen [aResp, entryCount, skip, 3367a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3368a3316fc6SZhikuiRen const std::variant<uint16_t>& bootCount) { 3369a3316fc6SZhikuiRen if (ec) 3370a3316fc6SZhikuiRen { 3371a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3372a3316fc6SZhikuiRen messages::internalError(aResp->res); 3373a3316fc6SZhikuiRen return; 3374a3316fc6SZhikuiRen } 3375a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 3376a3316fc6SZhikuiRen if (pVal) 3377a3316fc6SZhikuiRen { 3378a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 3379a3316fc6SZhikuiRen } 3380a3316fc6SZhikuiRen else 3381a3316fc6SZhikuiRen { 3382a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 3383a3316fc6SZhikuiRen } 3384a3316fc6SZhikuiRen }, 3385a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3386a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3387a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 3388a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 3389a3316fc6SZhikuiRen } 3390a3316fc6SZhikuiRen 3391a3316fc6SZhikuiRen class PostCodesEntryCollection : public Node 3392a3316fc6SZhikuiRen { 3393a3316fc6SZhikuiRen public: 339452cc112dSEd Tanous PostCodesEntryCollection(App& app) : 3395a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3396a3316fc6SZhikuiRen { 3397a3316fc6SZhikuiRen entityPrivileges = { 3398a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3399a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3400a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3401a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3402a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3403a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3404a3316fc6SZhikuiRen } 3405a3316fc6SZhikuiRen 3406a3316fc6SZhikuiRen private: 3407a3316fc6SZhikuiRen void doGet(crow::Response& res, const crow::Request& req, 3408cb13a392SEd Tanous const std::vector<std::string>&) override 3409a3316fc6SZhikuiRen { 3410a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3411a3316fc6SZhikuiRen 3412a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3413a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3414a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 3415a3316fc6SZhikuiRen "/redfish/v1/" 3416a3316fc6SZhikuiRen "$metadata#LogEntryCollection.LogEntryCollection"; 3417a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3418a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3419a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3420a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3421a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3422a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3423a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3424a3316fc6SZhikuiRen 3425a3316fc6SZhikuiRen uint64_t skip = 0; 3426a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 3427a3316fc6SZhikuiRen if (!getSkipParam(asyncResp->res, req, skip)) 3428a3316fc6SZhikuiRen { 3429a3316fc6SZhikuiRen return; 3430a3316fc6SZhikuiRen } 3431a3316fc6SZhikuiRen if (!getTopParam(asyncResp->res, req, top)) 3432a3316fc6SZhikuiRen { 3433a3316fc6SZhikuiRen return; 3434a3316fc6SZhikuiRen } 3435a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 3436a3316fc6SZhikuiRen } 3437a3316fc6SZhikuiRen }; 3438a3316fc6SZhikuiRen 3439a3316fc6SZhikuiRen class PostCodesEntry : public Node 3440a3316fc6SZhikuiRen { 3441a3316fc6SZhikuiRen public: 344252cc112dSEd Tanous PostCodesEntry(App& app) : 3443a3316fc6SZhikuiRen Node(app, 3444a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/", 3445a3316fc6SZhikuiRen std::string()) 3446a3316fc6SZhikuiRen { 3447a3316fc6SZhikuiRen entityPrivileges = { 3448a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3449a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3450a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3451a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3452a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3453a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3454a3316fc6SZhikuiRen } 3455a3316fc6SZhikuiRen 3456a3316fc6SZhikuiRen private: 3457cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 3458a3316fc6SZhikuiRen const std::vector<std::string>& params) override 3459a3316fc6SZhikuiRen { 3460a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3461a3316fc6SZhikuiRen if (params.size() != 1) 3462a3316fc6SZhikuiRen { 3463a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3464a3316fc6SZhikuiRen return; 3465a3316fc6SZhikuiRen } 3466a3316fc6SZhikuiRen 3467a3316fc6SZhikuiRen const std::string& targetID = params[0]; 3468a3316fc6SZhikuiRen 3469a3316fc6SZhikuiRen size_t bootPos = targetID.find('B'); 3470a3316fc6SZhikuiRen if (bootPos == std::string::npos) 3471a3316fc6SZhikuiRen { 3472a3316fc6SZhikuiRen // Requested ID was not found 3473a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 3474a3316fc6SZhikuiRen return; 3475a3316fc6SZhikuiRen } 3476a3316fc6SZhikuiRen std::string_view bootIndexStr(targetID); 3477a3316fc6SZhikuiRen bootIndexStr.remove_prefix(bootPos + 1); 3478a3316fc6SZhikuiRen uint16_t bootIndex = 0; 3479a3316fc6SZhikuiRen uint64_t codeIndex = 0; 3480a3316fc6SZhikuiRen size_t dashPos = bootIndexStr.find('-'); 3481a3316fc6SZhikuiRen 3482a3316fc6SZhikuiRen if (dashPos == std::string::npos) 3483a3316fc6SZhikuiRen { 3484a3316fc6SZhikuiRen return; 3485a3316fc6SZhikuiRen } 3486a3316fc6SZhikuiRen std::string_view codeIndexStr(bootIndexStr); 3487a3316fc6SZhikuiRen bootIndexStr.remove_suffix(dashPos); 3488a3316fc6SZhikuiRen codeIndexStr.remove_prefix(dashPos + 1); 3489a3316fc6SZhikuiRen 3490a3316fc6SZhikuiRen bootIndex = static_cast<uint16_t>( 349123a21a1cSEd Tanous strtoul(std::string(bootIndexStr).c_str(), nullptr, 0)); 349223a21a1cSEd Tanous codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0); 3493a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3494a3316fc6SZhikuiRen { 3495a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 3496a3316fc6SZhikuiRen << params[0]; 3497a3316fc6SZhikuiRen } 3498a3316fc6SZhikuiRen 3499a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 3500a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 3501a3316fc6SZhikuiRen "/redfish/v1/$metadata#LogEntry.LogEntry"; 3502a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3503a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3504a3316fc6SZhikuiRen "Entries"; 3505a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3506a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3507a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3508a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3509a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3510a3316fc6SZhikuiRen 3511a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 3512a3316fc6SZhikuiRen } 3513a3316fc6SZhikuiRen }; 3514a3316fc6SZhikuiRen 35151da66f75SEd Tanous } // namespace redfish 3516