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> 30cb92c03bSAndrew Geissler #include <error_messages.hpp> 311214b7e7SGunnar Mills 324418c7f0SJames Feist #include <filesystem> 33cd225da8SJason M. Bills #include <string_view> 34abf2add6SEd Tanous #include <variant> 351da66f75SEd Tanous 361da66f75SEd Tanous namespace redfish 371da66f75SEd Tanous { 381da66f75SEd Tanous 395b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 405b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 415b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 425b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 435b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 445b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 45424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 465b61b5e8SJason M. Bills constexpr char const* crashdumpRawPECIInterface = 47424c4176SJason M. Bills "com.intel.crashdump.SendRawPeci"; 486eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 496eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 501da66f75SEd Tanous 514851d45dSJason M. Bills namespace message_registries 524851d45dSJason M. Bills { 534851d45dSJason M. Bills static const Message* getMessageFromRegistry( 544851d45dSJason M. Bills const std::string& messageKey, 554851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 564851d45dSJason M. Bills { 574851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 584851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 594851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 604851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 614851d45dSJason M. Bills messageKey.c_str()); 624851d45dSJason M. Bills }); 634851d45dSJason M. Bills if (messageIt != registry.cend()) 644851d45dSJason M. Bills { 654851d45dSJason M. Bills return &messageIt->second; 664851d45dSJason M. Bills } 674851d45dSJason M. Bills 684851d45dSJason M. Bills return nullptr; 694851d45dSJason M. Bills } 704851d45dSJason M. Bills 714851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 724851d45dSJason M. Bills { 734851d45dSJason M. Bills // Redfish MessageIds are in the form 744851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 754851d45dSJason M. Bills // the right Message 764851d45dSJason M. Bills std::vector<std::string> fields; 774851d45dSJason M. Bills fields.reserve(4); 784851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 794851d45dSJason M. Bills std::string& registryName = fields[0]; 804851d45dSJason M. Bills std::string& messageKey = fields[3]; 814851d45dSJason M. Bills 824851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 834851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 844851d45dSJason M. Bills { 854851d45dSJason M. Bills return getMessageFromRegistry( 864851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 874851d45dSJason M. Bills } 884851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 894851d45dSJason M. Bills { 904851d45dSJason M. Bills return getMessageFromRegistry( 914851d45dSJason M. Bills messageKey, 924851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 934851d45dSJason M. Bills } 944851d45dSJason M. Bills return nullptr; 954851d45dSJason M. Bills } 964851d45dSJason M. Bills } // namespace message_registries 974851d45dSJason M. Bills 98f6150403SJames Feist namespace fs = std::filesystem; 991da66f75SEd Tanous 100cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 10119bd78d9SPatrick Williams std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, 102cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 103cb92c03bSAndrew Geissler 104cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 105cb92c03bSAndrew Geissler sdbusplus::message::object_path, 106cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 107cb92c03bSAndrew Geissler 108cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 109cb92c03bSAndrew Geissler { 110cb92c03bSAndrew Geissler if (s == "xyz.openbmc_project.Logging.Entry.Level.Alert") 111cb92c03bSAndrew Geissler { 112cb92c03bSAndrew Geissler return "Critical"; 113cb92c03bSAndrew Geissler } 114cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") 115cb92c03bSAndrew Geissler { 116cb92c03bSAndrew Geissler return "Critical"; 117cb92c03bSAndrew Geissler } 118cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Debug") 119cb92c03bSAndrew Geissler { 120cb92c03bSAndrew Geissler return "OK"; 121cb92c03bSAndrew Geissler } 122cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") 123cb92c03bSAndrew Geissler { 124cb92c03bSAndrew Geissler return "Critical"; 125cb92c03bSAndrew Geissler } 126cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Error") 127cb92c03bSAndrew Geissler { 128cb92c03bSAndrew Geissler return "Critical"; 129cb92c03bSAndrew Geissler } 130cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") 131cb92c03bSAndrew Geissler { 132cb92c03bSAndrew Geissler return "OK"; 133cb92c03bSAndrew Geissler } 134cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Notice") 135cb92c03bSAndrew Geissler { 136cb92c03bSAndrew Geissler return "OK"; 137cb92c03bSAndrew Geissler } 138cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 139cb92c03bSAndrew Geissler { 140cb92c03bSAndrew Geissler return "Warning"; 141cb92c03bSAndrew Geissler } 142cb92c03bSAndrew Geissler return ""; 143cb92c03bSAndrew Geissler } 144cb92c03bSAndrew Geissler 14516428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal, 14639e77504SEd Tanous const std::string_view& field, 14739e77504SEd Tanous std::string_view& contents) 14816428a1aSJason M. Bills { 14916428a1aSJason M. Bills const char* data = nullptr; 15016428a1aSJason M. Bills size_t length = 0; 15116428a1aSJason M. Bills int ret = 0; 15216428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 153271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 154271584abSEd Tanous reinterpret_cast<const void**>(&data), &length); 15516428a1aSJason M. Bills if (ret < 0) 15616428a1aSJason M. Bills { 15716428a1aSJason M. Bills return ret; 15816428a1aSJason M. Bills } 15939e77504SEd Tanous contents = std::string_view(data, length); 16016428a1aSJason M. Bills // Only use the content after the "=" character. 16116428a1aSJason M. Bills contents.remove_prefix(std::min(contents.find("=") + 1, contents.size())); 16216428a1aSJason M. Bills return ret; 16316428a1aSJason M. Bills } 16416428a1aSJason M. Bills 16516428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal, 16639e77504SEd Tanous const std::string_view& field, const int& base, 167271584abSEd Tanous long int& contents) 16816428a1aSJason M. Bills { 16916428a1aSJason M. Bills int ret = 0; 17039e77504SEd Tanous std::string_view metadata; 17116428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 17216428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 17316428a1aSJason M. Bills if (ret < 0) 17416428a1aSJason M. Bills { 17516428a1aSJason M. Bills return ret; 17616428a1aSJason M. Bills } 177b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 17816428a1aSJason M. Bills return ret; 17916428a1aSJason M. Bills } 18016428a1aSJason M. Bills 181a3316fc6SZhikuiRen static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp) 182a3316fc6SZhikuiRen { 183a3316fc6SZhikuiRen int ret = 0; 184a3316fc6SZhikuiRen uint64_t timestamp = 0; 185a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 186a3316fc6SZhikuiRen if (ret < 0) 187a3316fc6SZhikuiRen { 188a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 189a3316fc6SZhikuiRen << strerror(-ret); 190a3316fc6SZhikuiRen return false; 191a3316fc6SZhikuiRen } 1929c620e21SAsmitha Karunanithi entryTimestamp = crow::utility::getDateTime( 1939c620e21SAsmitha Karunanithi static_cast<std::time_t>(timestamp / 1000 / 1000)); 1949c620e21SAsmitha Karunanithi return true; 195a3316fc6SZhikuiRen } 196a3316fc6SZhikuiRen 19716428a1aSJason M. Bills static bool getSkipParam(crow::Response& res, const crow::Request& req, 198271584abSEd Tanous uint64_t& skip) 19916428a1aSJason M. Bills { 2005a7e877eSJames Feist boost::urls::url_view::params_type::iterator it = 2015a7e877eSJames Feist req.urlParams.find("$skip"); 2025a7e877eSJames Feist if (it != req.urlParams.end()) 20316428a1aSJason M. Bills { 2045a7e877eSJames Feist std::string skipParam = it->value(); 20516428a1aSJason M. Bills char* ptr = nullptr; 2065a7e877eSJames Feist skip = std::strtoul(skipParam.c_str(), &ptr, 10); 2075a7e877eSJames Feist if (skipParam.empty() || *ptr != '\0') 20816428a1aSJason M. Bills { 20916428a1aSJason M. Bills 21016428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(skipParam), 21116428a1aSJason M. Bills "$skip"); 21216428a1aSJason M. Bills return false; 21316428a1aSJason M. Bills } 21416428a1aSJason M. Bills } 21516428a1aSJason M. Bills return true; 21616428a1aSJason M. Bills } 21716428a1aSJason M. Bills 218271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 21916428a1aSJason M. Bills static bool getTopParam(crow::Response& res, const crow::Request& req, 220271584abSEd Tanous uint64_t& top) 22116428a1aSJason M. Bills { 2225a7e877eSJames Feist boost::urls::url_view::params_type::iterator it = 2235a7e877eSJames Feist req.urlParams.find("$top"); 2245a7e877eSJames Feist if (it != req.urlParams.end()) 22516428a1aSJason M. Bills { 2265a7e877eSJames Feist std::string topParam = it->value(); 22716428a1aSJason M. Bills char* ptr = nullptr; 2285a7e877eSJames Feist top = std::strtoul(topParam.c_str(), &ptr, 10); 2295a7e877eSJames Feist if (topParam.empty() || *ptr != '\0') 23016428a1aSJason M. Bills { 23116428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(topParam), 23216428a1aSJason M. Bills "$top"); 23316428a1aSJason M. Bills return false; 23416428a1aSJason M. Bills } 235271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 23616428a1aSJason M. Bills { 23716428a1aSJason M. Bills 23816428a1aSJason M. Bills messages::queryParameterOutOfRange( 23916428a1aSJason M. Bills res, std::to_string(top), "$top", 24016428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 24116428a1aSJason M. Bills return false; 24216428a1aSJason M. Bills } 24316428a1aSJason M. Bills } 24416428a1aSJason M. Bills return true; 24516428a1aSJason M. Bills } 24616428a1aSJason M. Bills 247e85d6b16SJason M. Bills static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 248e85d6b16SJason M. Bills const bool firstEntry = true) 24916428a1aSJason M. Bills { 25016428a1aSJason M. Bills int ret = 0; 25116428a1aSJason M. Bills static uint64_t prevTs = 0; 25216428a1aSJason M. Bills static int index = 0; 253e85d6b16SJason M. Bills if (firstEntry) 254e85d6b16SJason M. Bills { 255e85d6b16SJason M. Bills prevTs = 0; 256e85d6b16SJason M. Bills } 257e85d6b16SJason M. Bills 25816428a1aSJason M. Bills // Get the entry timestamp 25916428a1aSJason M. Bills uint64_t curTs = 0; 26016428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 26116428a1aSJason M. Bills if (ret < 0) 26216428a1aSJason M. Bills { 26316428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 26416428a1aSJason M. Bills << strerror(-ret); 26516428a1aSJason M. Bills return false; 26616428a1aSJason M. Bills } 26716428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 26816428a1aSJason M. Bills if (curTs == prevTs) 26916428a1aSJason M. Bills { 27016428a1aSJason M. Bills index++; 27116428a1aSJason M. Bills } 27216428a1aSJason M. Bills else 27316428a1aSJason M. Bills { 27416428a1aSJason M. Bills // Otherwise, reset it 27516428a1aSJason M. Bills index = 0; 27616428a1aSJason M. Bills } 27716428a1aSJason M. Bills // Save the timestamp 27816428a1aSJason M. Bills prevTs = curTs; 27916428a1aSJason M. Bills 28016428a1aSJason M. Bills entryID = std::to_string(curTs); 28116428a1aSJason M. Bills if (index > 0) 28216428a1aSJason M. Bills { 28316428a1aSJason M. Bills entryID += "_" + std::to_string(index); 28416428a1aSJason M. Bills } 28516428a1aSJason M. Bills return true; 28616428a1aSJason M. Bills } 28716428a1aSJason M. Bills 288e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 289e85d6b16SJason M. Bills const bool firstEntry = true) 29095820184SJason M. Bills { 291271584abSEd Tanous static time_t prevTs = 0; 29295820184SJason M. Bills static int index = 0; 293e85d6b16SJason M. Bills if (firstEntry) 294e85d6b16SJason M. Bills { 295e85d6b16SJason M. Bills prevTs = 0; 296e85d6b16SJason M. Bills } 297e85d6b16SJason M. Bills 29895820184SJason M. Bills // Get the entry timestamp 299271584abSEd Tanous std::time_t curTs = 0; 30095820184SJason M. Bills std::tm timeStruct = {}; 30195820184SJason M. Bills std::istringstream entryStream(logEntry); 30295820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 30395820184SJason M. Bills { 30495820184SJason M. Bills curTs = std::mktime(&timeStruct); 30595820184SJason M. Bills } 30695820184SJason M. Bills // If the timestamp isn't unique, increment the index 30795820184SJason M. Bills if (curTs == prevTs) 30895820184SJason M. Bills { 30995820184SJason M. Bills index++; 31095820184SJason M. Bills } 31195820184SJason M. Bills else 31295820184SJason M. Bills { 31395820184SJason M. Bills // Otherwise, reset it 31495820184SJason M. Bills index = 0; 31595820184SJason M. Bills } 31695820184SJason M. Bills // Save the timestamp 31795820184SJason M. Bills prevTs = curTs; 31895820184SJason M. Bills 31995820184SJason M. Bills entryID = std::to_string(curTs); 32095820184SJason M. Bills if (index > 0) 32195820184SJason M. Bills { 32295820184SJason M. Bills entryID += "_" + std::to_string(index); 32395820184SJason M. Bills } 32495820184SJason M. Bills return true; 32595820184SJason M. Bills } 32695820184SJason M. Bills 32716428a1aSJason M. Bills static bool getTimestampFromID(crow::Response& res, const std::string& entryID, 328271584abSEd Tanous uint64_t& timestamp, uint64_t& index) 32916428a1aSJason M. Bills { 33016428a1aSJason M. Bills if (entryID.empty()) 33116428a1aSJason M. Bills { 33216428a1aSJason M. Bills return false; 33316428a1aSJason M. Bills } 33416428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 33539e77504SEd Tanous std::string_view tsStr(entryID); 33616428a1aSJason M. Bills 33716428a1aSJason M. Bills auto underscorePos = tsStr.find("_"); 33816428a1aSJason M. Bills if (underscorePos != tsStr.npos) 33916428a1aSJason M. Bills { 34016428a1aSJason M. Bills // Timestamp has an index 34116428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 34239e77504SEd Tanous std::string_view indexStr(entryID); 34316428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 34416428a1aSJason M. Bills std::size_t pos; 34516428a1aSJason M. Bills try 34616428a1aSJason M. Bills { 34739e77504SEd Tanous index = std::stoul(std::string(indexStr), &pos); 34816428a1aSJason M. Bills } 349271584abSEd Tanous catch (std::invalid_argument&) 35016428a1aSJason M. Bills { 35116428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 35216428a1aSJason M. Bills return false; 35316428a1aSJason M. Bills } 354271584abSEd Tanous catch (std::out_of_range&) 35516428a1aSJason M. Bills { 35616428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 35716428a1aSJason M. Bills return false; 35816428a1aSJason M. Bills } 35916428a1aSJason M. Bills if (pos != indexStr.size()) 36016428a1aSJason M. Bills { 36116428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 36216428a1aSJason M. Bills return false; 36316428a1aSJason M. Bills } 36416428a1aSJason M. Bills } 36516428a1aSJason M. Bills // Timestamp has no index 36616428a1aSJason M. Bills std::size_t pos; 36716428a1aSJason M. Bills try 36816428a1aSJason M. Bills { 36939e77504SEd Tanous timestamp = std::stoull(std::string(tsStr), &pos); 37016428a1aSJason M. Bills } 371271584abSEd Tanous catch (std::invalid_argument&) 37216428a1aSJason M. Bills { 37316428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 37416428a1aSJason M. Bills return false; 37516428a1aSJason M. Bills } 376271584abSEd Tanous catch (std::out_of_range&) 37716428a1aSJason M. Bills { 37816428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 37916428a1aSJason M. Bills return false; 38016428a1aSJason M. Bills } 38116428a1aSJason M. Bills if (pos != tsStr.size()) 38216428a1aSJason M. Bills { 38316428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 38416428a1aSJason M. Bills return false; 38516428a1aSJason M. Bills } 38616428a1aSJason M. Bills return true; 38716428a1aSJason M. Bills } 38816428a1aSJason M. Bills 38995820184SJason M. Bills static bool 39095820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 39195820184SJason M. Bills { 39295820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 39395820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 39495820184SJason M. Bills 39595820184SJason M. Bills // Loop through the directory looking for redfish log files 39695820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 39795820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 39895820184SJason M. Bills { 39995820184SJason M. Bills // If we find a redfish log file, save the path 40095820184SJason M. Bills std::string filename = dirEnt.path().filename(); 40195820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 40295820184SJason M. Bills { 40395820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 40495820184SJason M. Bills } 40595820184SJason M. Bills } 40695820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 40795820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 40895820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 40995820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 41095820184SJason M. Bills 41195820184SJason M. Bills return !redfishLogFiles.empty(); 41295820184SJason M. Bills } 41395820184SJason M. Bills 4145cb1dd27SAsmitha Karunanithi inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp, 4155cb1dd27SAsmitha Karunanithi const std::string& dumpType) 4165cb1dd27SAsmitha Karunanithi { 4175cb1dd27SAsmitha Karunanithi std::string dumpPath; 4185cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 4195cb1dd27SAsmitha Karunanithi { 4205cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 4215cb1dd27SAsmitha Karunanithi } 4225cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 4235cb1dd27SAsmitha Karunanithi { 4245cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 4255cb1dd27SAsmitha Karunanithi } 4265cb1dd27SAsmitha Karunanithi else 4275cb1dd27SAsmitha Karunanithi { 4285cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 4295cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4305cb1dd27SAsmitha Karunanithi return; 4315cb1dd27SAsmitha Karunanithi } 4325cb1dd27SAsmitha Karunanithi 4335cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 4345cb1dd27SAsmitha Karunanithi [asyncResp, dumpPath, dumpType](const boost::system::error_code ec, 4355cb1dd27SAsmitha Karunanithi GetManagedObjectsType& resp) { 4365cb1dd27SAsmitha Karunanithi if (ec) 4375cb1dd27SAsmitha Karunanithi { 4385cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4395cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4405cb1dd27SAsmitha Karunanithi return; 4415cb1dd27SAsmitha Karunanithi } 4425cb1dd27SAsmitha Karunanithi 4435cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4445cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 4455cb1dd27SAsmitha Karunanithi 4465cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4475cb1dd27SAsmitha Karunanithi { 4485cb1dd27SAsmitha Karunanithi bool foundDumpEntry = false; 4495cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4505cb1dd27SAsmitha Karunanithi { 4515cb1dd27SAsmitha Karunanithi if (interfaceMap.first == 4525cb1dd27SAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 4535cb1dd27SAsmitha Karunanithi { 4545cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 4555cb1dd27SAsmitha Karunanithi break; 4565cb1dd27SAsmitha Karunanithi } 4575cb1dd27SAsmitha Karunanithi } 4585cb1dd27SAsmitha Karunanithi 4595cb1dd27SAsmitha Karunanithi if (foundDumpEntry == false) 4605cb1dd27SAsmitha Karunanithi { 4615cb1dd27SAsmitha Karunanithi continue; 4625cb1dd27SAsmitha Karunanithi } 4635cb1dd27SAsmitha Karunanithi std::time_t timestamp; 4645cb1dd27SAsmitha Karunanithi uint64_t size = 0; 4655cb1dd27SAsmitha Karunanithi entriesArray.push_back({}); 4665cb1dd27SAsmitha Karunanithi nlohmann::json& thisEntry = entriesArray.back(); 4675cb1dd27SAsmitha Karunanithi const std::string& path = 4685cb1dd27SAsmitha Karunanithi static_cast<const std::string&>(object.first); 4695cb1dd27SAsmitha Karunanithi std::size_t lastPos = path.rfind("/"); 4705cb1dd27SAsmitha Karunanithi if (lastPos == std::string::npos) 4715cb1dd27SAsmitha Karunanithi { 4725cb1dd27SAsmitha Karunanithi continue; 4735cb1dd27SAsmitha Karunanithi } 4745cb1dd27SAsmitha Karunanithi std::string entryID = path.substr(lastPos + 1); 4755cb1dd27SAsmitha Karunanithi 4765cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4775cb1dd27SAsmitha Karunanithi { 4785cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 4795cb1dd27SAsmitha Karunanithi { 4805cb1dd27SAsmitha Karunanithi 4815cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4825cb1dd27SAsmitha Karunanithi { 4835cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4845cb1dd27SAsmitha Karunanithi { 4855cb1dd27SAsmitha Karunanithi auto sizePtr = 4865cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4875cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4885cb1dd27SAsmitha Karunanithi { 4895cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4905cb1dd27SAsmitha Karunanithi break; 4915cb1dd27SAsmitha Karunanithi } 4925cb1dd27SAsmitha Karunanithi size = *sizePtr; 4935cb1dd27SAsmitha Karunanithi break; 4945cb1dd27SAsmitha Karunanithi } 4955cb1dd27SAsmitha Karunanithi } 4965cb1dd27SAsmitha Karunanithi } 4975cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4985cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 4995cb1dd27SAsmitha Karunanithi { 5005cb1dd27SAsmitha Karunanithi 5015cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 5025cb1dd27SAsmitha Karunanithi { 5035cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 5045cb1dd27SAsmitha Karunanithi { 5055cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 5065cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5075cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 5085cb1dd27SAsmitha Karunanithi { 5095cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5105cb1dd27SAsmitha Karunanithi break; 5115cb1dd27SAsmitha Karunanithi } 5125cb1dd27SAsmitha Karunanithi timestamp = 5135cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 5145cb1dd27SAsmitha Karunanithi break; 5155cb1dd27SAsmitha Karunanithi } 5165cb1dd27SAsmitha Karunanithi } 5175cb1dd27SAsmitha Karunanithi } 5185cb1dd27SAsmitha Karunanithi } 5195cb1dd27SAsmitha Karunanithi 520*d337bb72SAsmitha Karunanithi thisEntry["@odata.type"] = "#LogEntry.v1_7_0.LogEntry"; 5215cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 5225cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 5235cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5245cb1dd27SAsmitha Karunanithi thisEntry["Created"] = crow::utility::getDateTime(timestamp); 5255cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 5265cb1dd27SAsmitha Karunanithi 527*d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataSizeBytes"] = size; 5285cb1dd27SAsmitha Karunanithi 5295cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5305cb1dd27SAsmitha Karunanithi { 531*d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 532*d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 533*d337bb72SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 534*d337bb72SAsmitha Karunanithi "attachment/" + 535*d337bb72SAsmitha Karunanithi entryID; 5365cb1dd27SAsmitha Karunanithi } 5375cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5385cb1dd27SAsmitha Karunanithi { 539*d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 540*d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 541*d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 542*d337bb72SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/" 543*d337bb72SAsmitha Karunanithi "attachment/" + 544*d337bb72SAsmitha Karunanithi entryID; 5455cb1dd27SAsmitha Karunanithi } 5465cb1dd27SAsmitha Karunanithi } 5475cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 5485cb1dd27SAsmitha Karunanithi entriesArray.size(); 5495cb1dd27SAsmitha Karunanithi }, 5505cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5515cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5525cb1dd27SAsmitha Karunanithi } 5535cb1dd27SAsmitha Karunanithi 5545cb1dd27SAsmitha Karunanithi inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp, 5555cb1dd27SAsmitha Karunanithi const std::string& entryID, 5565cb1dd27SAsmitha Karunanithi const std::string& dumpType) 5575cb1dd27SAsmitha Karunanithi { 5585cb1dd27SAsmitha Karunanithi std::string dumpPath; 5595cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5605cb1dd27SAsmitha Karunanithi { 5615cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5625cb1dd27SAsmitha Karunanithi } 5635cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5645cb1dd27SAsmitha Karunanithi { 5655cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5665cb1dd27SAsmitha Karunanithi } 5675cb1dd27SAsmitha Karunanithi else 5685cb1dd27SAsmitha Karunanithi { 5695cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5705cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5715cb1dd27SAsmitha Karunanithi return; 5725cb1dd27SAsmitha Karunanithi } 5735cb1dd27SAsmitha Karunanithi 5745cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 5755cb1dd27SAsmitha Karunanithi [asyncResp, entryID, dumpPath, dumpType]( 5765cb1dd27SAsmitha Karunanithi const boost::system::error_code ec, GetManagedObjectsType& resp) { 5775cb1dd27SAsmitha Karunanithi if (ec) 5785cb1dd27SAsmitha Karunanithi { 5795cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5805cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5815cb1dd27SAsmitha Karunanithi return; 5825cb1dd27SAsmitha Karunanithi } 5835cb1dd27SAsmitha Karunanithi 5845cb1dd27SAsmitha Karunanithi for (auto& objectPath : resp) 5855cb1dd27SAsmitha Karunanithi { 5865cb1dd27SAsmitha Karunanithi if (objectPath.first.str.find( 5875cb1dd27SAsmitha Karunanithi "/xyz/openbmc_project/dump/entry/" + entryID) == 5885cb1dd27SAsmitha Karunanithi std::string::npos) 5895cb1dd27SAsmitha Karunanithi { 5905cb1dd27SAsmitha Karunanithi continue; 5915cb1dd27SAsmitha Karunanithi } 5925cb1dd27SAsmitha Karunanithi 5935cb1dd27SAsmitha Karunanithi bool foundDumpEntry = false; 5945cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 5955cb1dd27SAsmitha Karunanithi { 5965cb1dd27SAsmitha Karunanithi if (interfaceMap.first == 5975cb1dd27SAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 5985cb1dd27SAsmitha Karunanithi { 5995cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 6005cb1dd27SAsmitha Karunanithi break; 6015cb1dd27SAsmitha Karunanithi } 6025cb1dd27SAsmitha Karunanithi } 6035cb1dd27SAsmitha Karunanithi if (foundDumpEntry == false) 6045cb1dd27SAsmitha Karunanithi { 6055cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 6065cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6075cb1dd27SAsmitha Karunanithi return; 6085cb1dd27SAsmitha Karunanithi } 6095cb1dd27SAsmitha Karunanithi 6105cb1dd27SAsmitha Karunanithi std::time_t timestamp; 6115cb1dd27SAsmitha Karunanithi uint64_t size = 0; 6125cb1dd27SAsmitha Karunanithi 6135cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 6145cb1dd27SAsmitha Karunanithi { 6155cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 6165cb1dd27SAsmitha Karunanithi { 6175cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6185cb1dd27SAsmitha Karunanithi { 6195cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 6205cb1dd27SAsmitha Karunanithi { 6215cb1dd27SAsmitha Karunanithi auto sizePtr = 6225cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6235cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 6245cb1dd27SAsmitha Karunanithi { 6255cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6265cb1dd27SAsmitha Karunanithi break; 6275cb1dd27SAsmitha Karunanithi } 6285cb1dd27SAsmitha Karunanithi size = *sizePtr; 6295cb1dd27SAsmitha Karunanithi break; 6305cb1dd27SAsmitha Karunanithi } 6315cb1dd27SAsmitha Karunanithi } 6325cb1dd27SAsmitha Karunanithi } 6335cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 6345cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 6355cb1dd27SAsmitha Karunanithi { 6365cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6375cb1dd27SAsmitha Karunanithi { 6385cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 6395cb1dd27SAsmitha Karunanithi { 6405cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 6415cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6425cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 6435cb1dd27SAsmitha Karunanithi { 6445cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6455cb1dd27SAsmitha Karunanithi break; 6465cb1dd27SAsmitha Karunanithi } 6475cb1dd27SAsmitha Karunanithi timestamp = 6485cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 6495cb1dd27SAsmitha Karunanithi break; 6505cb1dd27SAsmitha Karunanithi } 6515cb1dd27SAsmitha Karunanithi } 6525cb1dd27SAsmitha Karunanithi } 6535cb1dd27SAsmitha Karunanithi } 6545cb1dd27SAsmitha Karunanithi 6555cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 656*d337bb72SAsmitha Karunanithi "#LogEntry.v1_7_0.LogEntry"; 6575cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6585cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6595cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6605cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6615cb1dd27SAsmitha Karunanithi crow::utility::getDateTime(timestamp); 6625cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6635cb1dd27SAsmitha Karunanithi 664*d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6655cb1dd27SAsmitha Karunanithi 6665cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6675cb1dd27SAsmitha Karunanithi { 668*d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 669*d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 6705cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 6715cb1dd27SAsmitha Karunanithi "attachment/" + 6725cb1dd27SAsmitha Karunanithi entryID; 6735cb1dd27SAsmitha Karunanithi } 6745cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6755cb1dd27SAsmitha Karunanithi { 676*d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 677*d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["OEMDiagnosticDataType"] = 6785cb1dd27SAsmitha Karunanithi "System"; 679*d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 6805cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/" 6815cb1dd27SAsmitha Karunanithi "attachment/" + 6825cb1dd27SAsmitha Karunanithi entryID; 6835cb1dd27SAsmitha Karunanithi } 6845cb1dd27SAsmitha Karunanithi } 6855cb1dd27SAsmitha Karunanithi }, 6865cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6875cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6885cb1dd27SAsmitha Karunanithi } 6895cb1dd27SAsmitha Karunanithi 6905cb1dd27SAsmitha Karunanithi inline void deleteDumpEntry(crow::Response& res, const std::string& entryID) 6915cb1dd27SAsmitha Karunanithi { 6925cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 6935cb1dd27SAsmitha Karunanithi 6945cb1dd27SAsmitha Karunanithi auto respHandler = [asyncResp](const boost::system::error_code ec) { 6955cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6965cb1dd27SAsmitha Karunanithi if (ec) 6975cb1dd27SAsmitha Karunanithi { 6985cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 6995cb1dd27SAsmitha Karunanithi << ec; 7005cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 7015cb1dd27SAsmitha Karunanithi return; 7025cb1dd27SAsmitha Karunanithi } 7035cb1dd27SAsmitha Karunanithi }; 7045cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 7055cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 7065cb1dd27SAsmitha Karunanithi "/xyz/openbmc_project/dump/entry/" + entryID, 7075cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 7085cb1dd27SAsmitha Karunanithi } 7095cb1dd27SAsmitha Karunanithi 710a43be80fSAsmitha Karunanithi inline void createDumpTaskCallback(const crow::Request& req, 711a43be80fSAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp, 712a43be80fSAsmitha Karunanithi const uint32_t& dumpId, 713a43be80fSAsmitha Karunanithi const std::string& dumpPath, 714a43be80fSAsmitha Karunanithi const std::string& dumpType) 715a43be80fSAsmitha Karunanithi { 716a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 717cb13a392SEd Tanous [dumpId, dumpPath, dumpType, asyncResp]( 718a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 719a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 720cb13a392SEd Tanous if (err) 721cb13a392SEd Tanous { 722cb13a392SEd Tanous messages::internalError(asyncResp->res); 723cb13a392SEd Tanous return false; 724cb13a392SEd Tanous } 725a43be80fSAsmitha Karunanithi std::vector<std::pair< 726a43be80fSAsmitha Karunanithi std::string, 727a43be80fSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string>>>>> 728a43be80fSAsmitha Karunanithi interfacesList; 729a43be80fSAsmitha Karunanithi 730a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 731a43be80fSAsmitha Karunanithi 732a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 733a43be80fSAsmitha Karunanithi 734a43be80fSAsmitha Karunanithi for (auto& interface : interfacesList) 735a43be80fSAsmitha Karunanithi { 736a43be80fSAsmitha Karunanithi if (interface.first == 737a43be80fSAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 738a43be80fSAsmitha Karunanithi { 739a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 740a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 741a43be80fSAsmitha Karunanithi 742a43be80fSAsmitha Karunanithi std::string headerLoc = 743a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 744a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 745a43be80fSAsmitha Karunanithi std::move(headerLoc)); 746a43be80fSAsmitha Karunanithi 747a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 748a43be80fSAsmitha Karunanithi return task::completed; 749a43be80fSAsmitha Karunanithi } 750a43be80fSAsmitha Karunanithi } 751a43be80fSAsmitha Karunanithi return !task::completed; 752a43be80fSAsmitha Karunanithi }, 753a43be80fSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus." 754a43be80fSAsmitha Karunanithi "ObjectManager'," 755a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 756a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 757a43be80fSAsmitha Karunanithi 758a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 759a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 760a43be80fSAsmitha Karunanithi task->payload.emplace(req); 761a43be80fSAsmitha Karunanithi } 762a43be80fSAsmitha Karunanithi 763a43be80fSAsmitha Karunanithi inline void createDump(crow::Response& res, const crow::Request& req, 764a43be80fSAsmitha Karunanithi const std::string& dumpType) 765a43be80fSAsmitha Karunanithi { 766a43be80fSAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 767a43be80fSAsmitha Karunanithi 768a43be80fSAsmitha Karunanithi std::string dumpPath; 769a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 770a43be80fSAsmitha Karunanithi { 771a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 772a43be80fSAsmitha Karunanithi } 773a43be80fSAsmitha Karunanithi else if (dumpType == "System") 774a43be80fSAsmitha Karunanithi { 775a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 776a43be80fSAsmitha Karunanithi } 777a43be80fSAsmitha Karunanithi else 778a43be80fSAsmitha Karunanithi { 779a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 780a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 781a43be80fSAsmitha Karunanithi return; 782a43be80fSAsmitha Karunanithi } 783a43be80fSAsmitha Karunanithi 784a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 785a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 786a43be80fSAsmitha Karunanithi 787a43be80fSAsmitha Karunanithi if (!redfish::json_util::readJson( 788a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 789a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 790a43be80fSAsmitha Karunanithi { 791a43be80fSAsmitha Karunanithi return; 792a43be80fSAsmitha Karunanithi } 793a43be80fSAsmitha Karunanithi 794a43be80fSAsmitha Karunanithi if (dumpType == "System") 795a43be80fSAsmitha Karunanithi { 796a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 797a43be80fSAsmitha Karunanithi { 798a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 799a43be80fSAsmitha Karunanithi "'DiagnosticDataType'/" 800a43be80fSAsmitha Karunanithi "'OEMDiagnosticDataType' value not found!"; 801a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 802a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 803a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 804a43be80fSAsmitha Karunanithi return; 805a43be80fSAsmitha Karunanithi } 806a43be80fSAsmitha Karunanithi else if ((*oemDiagnosticDataType != "System") || 807a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 808a43be80fSAsmitha Karunanithi { 809a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 810a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 811a43be80fSAsmitha Karunanithi "System Dump creation parameters"); 812a43be80fSAsmitha Karunanithi return; 813a43be80fSAsmitha Karunanithi } 814a43be80fSAsmitha Karunanithi } 815a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 816a43be80fSAsmitha Karunanithi { 817a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 818a43be80fSAsmitha Karunanithi { 819a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 820a43be80fSAsmitha Karunanithi "'DiagnosticDataType' not found!"; 821a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 822a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 823a43be80fSAsmitha Karunanithi return; 824a43be80fSAsmitha Karunanithi } 825a43be80fSAsmitha Karunanithi else if (*diagnosticDataType != "Manager") 826a43be80fSAsmitha Karunanithi { 827a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 828a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 829a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 830a43be80fSAsmitha Karunanithi "BMC Dump creation parameters"); 831a43be80fSAsmitha Karunanithi return; 832a43be80fSAsmitha Karunanithi } 833a43be80fSAsmitha Karunanithi } 834a43be80fSAsmitha Karunanithi 835a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 836a43be80fSAsmitha Karunanithi [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec, 837a43be80fSAsmitha Karunanithi const uint32_t& dumpId) { 838a43be80fSAsmitha Karunanithi if (ec) 839a43be80fSAsmitha Karunanithi { 840a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 841a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 842a43be80fSAsmitha Karunanithi return; 843a43be80fSAsmitha Karunanithi } 844a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 845a43be80fSAsmitha Karunanithi 846a43be80fSAsmitha Karunanithi createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType); 847a43be80fSAsmitha Karunanithi }, 848a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 849a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 850a43be80fSAsmitha Karunanithi } 851a43be80fSAsmitha Karunanithi 85280319af1SAsmitha Karunanithi inline void clearDump(crow::Response& res, const std::string& dumpInterface) 85380319af1SAsmitha Karunanithi { 85480319af1SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 85580319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 85680319af1SAsmitha Karunanithi [asyncResp](const boost::system::error_code ec, 85780319af1SAsmitha Karunanithi const std::vector<std::string>& subTreePaths) { 85880319af1SAsmitha Karunanithi if (ec) 85980319af1SAsmitha Karunanithi { 86080319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 86180319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 86280319af1SAsmitha Karunanithi return; 86380319af1SAsmitha Karunanithi } 86480319af1SAsmitha Karunanithi 86580319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 86680319af1SAsmitha Karunanithi { 86780319af1SAsmitha Karunanithi std::size_t pos = path.rfind("/"); 86880319af1SAsmitha Karunanithi if (pos != std::string::npos) 86980319af1SAsmitha Karunanithi { 87080319af1SAsmitha Karunanithi std::string logID = path.substr(pos + 1); 87180319af1SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, logID); 87280319af1SAsmitha Karunanithi } 87380319af1SAsmitha Karunanithi } 87480319af1SAsmitha Karunanithi }, 87580319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 87680319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 87780319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 87880319af1SAsmitha Karunanithi "/xyz/openbmc_project/dump", 0, 87980319af1SAsmitha Karunanithi std::array<std::string, 1>{dumpInterface}); 88080319af1SAsmitha Karunanithi } 88180319af1SAsmitha Karunanithi 882043a0536SJohnathan Mantey static void ParseCrashdumpParameters( 883043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params, 884043a0536SJohnathan Mantey std::string& filename, std::string& timestamp, std::string& logfile) 885043a0536SJohnathan Mantey { 886043a0536SJohnathan Mantey for (auto property : params) 887043a0536SJohnathan Mantey { 888043a0536SJohnathan Mantey if (property.first == "Timestamp") 889043a0536SJohnathan Mantey { 890043a0536SJohnathan Mantey const std::string* value = 8918d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 892043a0536SJohnathan Mantey if (value != nullptr) 893043a0536SJohnathan Mantey { 894043a0536SJohnathan Mantey timestamp = *value; 895043a0536SJohnathan Mantey } 896043a0536SJohnathan Mantey } 897043a0536SJohnathan Mantey else if (property.first == "Filename") 898043a0536SJohnathan Mantey { 899043a0536SJohnathan Mantey const std::string* value = 9008d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 901043a0536SJohnathan Mantey if (value != nullptr) 902043a0536SJohnathan Mantey { 903043a0536SJohnathan Mantey filename = *value; 904043a0536SJohnathan Mantey } 905043a0536SJohnathan Mantey } 906043a0536SJohnathan Mantey else if (property.first == "Log") 907043a0536SJohnathan Mantey { 908043a0536SJohnathan Mantey const std::string* value = 9098d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 910043a0536SJohnathan Mantey if (value != nullptr) 911043a0536SJohnathan Mantey { 912043a0536SJohnathan Mantey logfile = *value; 913043a0536SJohnathan Mantey } 914043a0536SJohnathan Mantey } 915043a0536SJohnathan Mantey } 916043a0536SJohnathan Mantey } 917043a0536SJohnathan Mantey 918a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 919c4bf6374SJason M. Bills class SystemLogServiceCollection : public Node 9201da66f75SEd Tanous { 9211da66f75SEd Tanous public: 92252cc112dSEd Tanous SystemLogServiceCollection(App& app) : 923029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/") 924c4bf6374SJason M. Bills { 925c4bf6374SJason M. Bills entityPrivileges = { 926c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 927c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 928c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 929c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 930c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 931c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 932c4bf6374SJason M. Bills } 933c4bf6374SJason M. Bills 934c4bf6374SJason M. Bills private: 935c4bf6374SJason M. Bills /** 936c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 937c4bf6374SJason M. Bills */ 938cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 939cb13a392SEd Tanous const std::vector<std::string>&) override 940c4bf6374SJason M. Bills { 941c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 942c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 943c4bf6374SJason M. Bills // it has a duplicate entry for members 944c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 945c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 946c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 947029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 948c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 949c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 950c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 951c4bf6374SJason M. Bills nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 952c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 953029573d4SEd Tanous logServiceArray.push_back( 954029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}}); 9555cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 956c9bb6861Sraviteja-b logServiceArray.push_back( 9575cb1dd27SAsmitha Karunanithi {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}}); 958c9bb6861Sraviteja-b #endif 959c9bb6861Sraviteja-b 960d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 961d53dd41fSJason M. Bills logServiceArray.push_back( 962cb92c03bSAndrew Geissler {{"@odata.id", 963424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 964d53dd41fSJason M. Bills #endif 965c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 966c4bf6374SJason M. Bills logServiceArray.size(); 967a3316fc6SZhikuiRen 968a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 969a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 970a3316fc6SZhikuiRen const std::vector<std::string>& subtreePath) { 971a3316fc6SZhikuiRen if (ec) 972a3316fc6SZhikuiRen { 973a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 974a3316fc6SZhikuiRen return; 975a3316fc6SZhikuiRen } 976a3316fc6SZhikuiRen 977a3316fc6SZhikuiRen for (auto& pathStr : subtreePath) 978a3316fc6SZhikuiRen { 979a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 980a3316fc6SZhikuiRen { 98123a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 982a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 98323a21a1cSEd Tanous logServiceArrayLocal.push_back( 984a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 985a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 986a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 98723a21a1cSEd Tanous logServiceArrayLocal.size(); 988a3316fc6SZhikuiRen return; 989a3316fc6SZhikuiRen } 990a3316fc6SZhikuiRen } 991a3316fc6SZhikuiRen }, 992a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 993a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 994a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 995a3316fc6SZhikuiRen std::array<const char*, 1>{postCodeIface}); 996c4bf6374SJason M. Bills } 997c4bf6374SJason M. Bills }; 998c4bf6374SJason M. Bills 999c4bf6374SJason M. Bills class EventLogService : public Node 1000c4bf6374SJason M. Bills { 1001c4bf6374SJason M. Bills public: 100252cc112dSEd Tanous EventLogService(App& app) : 1003029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 1004c4bf6374SJason M. Bills { 1005c4bf6374SJason M. Bills entityPrivileges = { 1006c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1007c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1008c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1009c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1010c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1011c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1012c4bf6374SJason M. Bills } 1013c4bf6374SJason M. Bills 1014c4bf6374SJason M. Bills private: 1015cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1016cb13a392SEd Tanous const std::vector<std::string>&) override 1017c4bf6374SJason M. Bills { 1018c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1019c4bf6374SJason M. Bills 1020c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1021029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1022c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1023c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 1024c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 1025c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 1026c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1027c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1028c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1029c4bf6374SJason M. Bills {"@odata.id", 1030029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 1031e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1032e7d6c8b2SGunnar Mills 1033e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 1034e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 1035489640c6SJason M. Bills } 1036489640c6SJason M. Bills }; 1037489640c6SJason M. Bills 10381f56a3a6STim Lee class JournalEventLogClear : public Node 1039489640c6SJason M. Bills { 1040489640c6SJason M. Bills public: 104152cc112dSEd Tanous JournalEventLogClear(App& app) : 1042489640c6SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 1043489640c6SJason M. Bills "LogService.ClearLog/") 1044489640c6SJason M. Bills { 1045489640c6SJason M. Bills entityPrivileges = { 1046489640c6SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1047489640c6SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1048489640c6SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1049489640c6SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1050489640c6SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1051489640c6SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1052489640c6SJason M. Bills } 1053489640c6SJason M. Bills 1054489640c6SJason M. Bills private: 1055cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 1056cb13a392SEd Tanous const std::vector<std::string>&) override 1057489640c6SJason M. Bills { 1058489640c6SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1059489640c6SJason M. Bills 1060489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1061489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1062489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1063489640c6SJason M. Bills { 1064489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1065489640c6SJason M. Bills { 1066489640c6SJason M. Bills std::error_code ec; 1067489640c6SJason M. Bills std::filesystem::remove(file, ec); 1068489640c6SJason M. Bills } 1069489640c6SJason M. Bills } 1070489640c6SJason M. Bills 1071489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1072489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1073489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1074489640c6SJason M. Bills if (ec) 1075489640c6SJason M. Bills { 1076489640c6SJason M. Bills BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 1077489640c6SJason M. Bills messages::internalError(asyncResp->res); 1078489640c6SJason M. Bills return; 1079489640c6SJason M. Bills } 1080489640c6SJason M. Bills 1081489640c6SJason M. Bills messages::success(asyncResp->res); 1082489640c6SJason M. Bills }, 1083489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1084489640c6SJason M. Bills "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1085489640c6SJason M. Bills "replace"); 1086c4bf6374SJason M. Bills } 1087c4bf6374SJason M. Bills }; 1088c4bf6374SJason M. Bills 108995820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 109095820184SJason M. Bills const std::string logEntry, 109195820184SJason M. Bills nlohmann::json& logEntryJson) 1092c4bf6374SJason M. Bills { 109395820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1094cd225da8SJason M. Bills // First get the Timestamp 1095cd225da8SJason M. Bills size_t space = logEntry.find_first_of(" "); 1096cd225da8SJason M. Bills if (space == std::string::npos) 109795820184SJason M. Bills { 109895820184SJason M. Bills return 1; 109995820184SJason M. Bills } 1100cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1101cd225da8SJason M. Bills // Then get the log contents 1102cd225da8SJason M. Bills size_t entryStart = logEntry.find_first_not_of(" ", space); 1103cd225da8SJason M. Bills if (entryStart == std::string::npos) 1104cd225da8SJason M. Bills { 1105cd225da8SJason M. Bills return 1; 1106cd225da8SJason M. Bills } 1107cd225da8SJason M. Bills std::string_view entry(logEntry); 1108cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1109cd225da8SJason M. Bills // Use split to separate the entry into its fields 1110cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1111cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1112cd225da8SJason M. Bills boost::token_compress_on); 1113cd225da8SJason M. Bills // We need at least a MessageId to be valid 1114cd225da8SJason M. Bills if (logEntryFields.size() < 1) 1115cd225da8SJason M. Bills { 1116cd225da8SJason M. Bills return 1; 1117cd225da8SJason M. Bills } 1118cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 111995820184SJason M. Bills 11204851d45dSJason M. Bills // Get the Message from the MessageRegistry 11214851d45dSJason M. Bills const message_registries::Message* message = 11224851d45dSJason M. Bills message_registries::getMessage(messageID); 1123c4bf6374SJason M. Bills 11244851d45dSJason M. Bills std::string msg; 11254851d45dSJason M. Bills std::string severity; 11264851d45dSJason M. Bills if (message != nullptr) 1127c4bf6374SJason M. Bills { 11284851d45dSJason M. Bills msg = message->message; 11294851d45dSJason M. Bills severity = message->severity; 1130c4bf6374SJason M. Bills } 1131c4bf6374SJason M. Bills 113215a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 113315a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 113415a86ff6SJason M. Bills if (logEntryFields.size() > 1) 113515a86ff6SJason M. Bills { 113615a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 113715a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 113815a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 113915a86ff6SJason M. Bills if (!messageArgsStart.empty()) 114015a86ff6SJason M. Bills { 114115a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 114215a86ff6SJason M. Bills } 114315a86ff6SJason M. Bills 114423a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1145c4bf6374SJason M. Bills 11464851d45dSJason M. Bills // Fill the MessageArgs into the Message 114795820184SJason M. Bills int i = 0; 114895820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11494851d45dSJason M. Bills { 115095820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11514851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11524851d45dSJason M. Bills if (argPos != std::string::npos) 11534851d45dSJason M. Bills { 115495820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11554851d45dSJason M. Bills } 11564851d45dSJason M. Bills } 115715a86ff6SJason M. Bills } 11584851d45dSJason M. Bills 115995820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 116095820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 116195820184SJason M. Bills // between the '.' and the '+', so just remove them. 116295820184SJason M. Bills std::size_t dot = timestamp.find_first_of("."); 116395820184SJason M. Bills std::size_t plus = timestamp.find_first_of("+"); 116495820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1165c4bf6374SJason M. Bills { 116695820184SJason M. Bills timestamp.erase(dot, plus - dot); 1167c4bf6374SJason M. Bills } 1168c4bf6374SJason M. Bills 1169c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 117095820184SJason M. Bills logEntryJson = { 1171cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1172029573d4SEd Tanous {"@odata.id", 1173897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 117495820184SJason M. Bills logEntryID}, 1175c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 117695820184SJason M. Bills {"Id", logEntryID}, 117795820184SJason M. Bills {"Message", std::move(msg)}, 117895820184SJason M. Bills {"MessageId", std::move(messageID)}, 1179c4bf6374SJason M. Bills {"MessageArgs", std::move(messageArgs)}, 1180c4bf6374SJason M. Bills {"EntryType", "Event"}, 118195820184SJason M. Bills {"Severity", std::move(severity)}, 118295820184SJason M. Bills {"Created", std::move(timestamp)}}; 1183c4bf6374SJason M. Bills return 0; 1184c4bf6374SJason M. Bills } 1185c4bf6374SJason M. Bills 118627062605SAnthony Wilson class JournalEventLogEntryCollection : public Node 1187c4bf6374SJason M. Bills { 1188c4bf6374SJason M. Bills public: 118952cc112dSEd Tanous JournalEventLogEntryCollection(App& app) : 1190029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1191c4bf6374SJason M. Bills { 1192c4bf6374SJason M. Bills entityPrivileges = { 1193c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1194c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1195c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1196c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1197c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1198c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1199c4bf6374SJason M. Bills } 1200c4bf6374SJason M. Bills 1201c4bf6374SJason M. Bills private: 1202c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1203cb13a392SEd Tanous const std::vector<std::string>&) override 1204c4bf6374SJason M. Bills { 1205c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1206271584abSEd Tanous uint64_t skip = 0; 1207271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 1208c4bf6374SJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1209c4bf6374SJason M. Bills { 1210c4bf6374SJason M. Bills return; 1211c4bf6374SJason M. Bills } 1212c4bf6374SJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1213c4bf6374SJason M. Bills { 1214c4bf6374SJason M. Bills return; 1215c4bf6374SJason M. Bills } 1216c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 1217c4bf6374SJason M. Bills // it has a duplicate entry for members 1218c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1219c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1220c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1221029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1222c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1223c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1224c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1225cb92c03bSAndrew Geissler 1226c4bf6374SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1227c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 122895820184SJason M. Bills // Go through the log files and create a unique ID for each entry 122995820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 123095820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1231b01bf299SEd Tanous uint64_t entryCount = 0; 1232cd225da8SJason M. Bills std::string logEntry; 123395820184SJason M. Bills 123495820184SJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 1235cd225da8SJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1236cd225da8SJason M. Bills it++) 1237c4bf6374SJason M. Bills { 1238cd225da8SJason M. Bills std::ifstream logStream(*it); 123995820184SJason M. Bills if (!logStream.is_open()) 1240c4bf6374SJason M. Bills { 1241c4bf6374SJason M. Bills continue; 1242c4bf6374SJason M. Bills } 1243c4bf6374SJason M. Bills 1244e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1245e85d6b16SJason M. Bills bool firstEntry = true; 124695820184SJason M. Bills while (std::getline(logStream, logEntry)) 124795820184SJason M. Bills { 1248c4bf6374SJason M. Bills entryCount++; 1249c4bf6374SJason M. Bills // Handle paging using skip (number of entries to skip from the 1250c4bf6374SJason M. Bills // start) and top (number of entries to display) 1251c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1252c4bf6374SJason M. Bills { 1253c4bf6374SJason M. Bills continue; 1254c4bf6374SJason M. Bills } 1255c4bf6374SJason M. Bills 1256c4bf6374SJason M. Bills std::string idStr; 1257e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1258c4bf6374SJason M. Bills { 1259c4bf6374SJason M. Bills continue; 1260c4bf6374SJason M. Bills } 1261c4bf6374SJason M. Bills 1262e85d6b16SJason M. Bills if (firstEntry) 1263e85d6b16SJason M. Bills { 1264e85d6b16SJason M. Bills firstEntry = false; 1265e85d6b16SJason M. Bills } 1266e85d6b16SJason M. Bills 1267c4bf6374SJason M. Bills logEntryArray.push_back({}); 1268c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 126995820184SJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0) 1270c4bf6374SJason M. Bills { 1271c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1272c4bf6374SJason M. Bills return; 1273c4bf6374SJason M. Bills } 1274c4bf6374SJason M. Bills } 127595820184SJason M. Bills } 1276c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1277c4bf6374SJason M. Bills if (skip + top < entryCount) 1278c4bf6374SJason M. Bills { 1279c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 128095820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 128195820184SJason M. Bills "Entries?$skip=" + 1282c4bf6374SJason M. Bills std::to_string(skip + top); 1283c4bf6374SJason M. Bills } 128408a4e4b5SAnthony Wilson } 128508a4e4b5SAnthony Wilson }; 128608a4e4b5SAnthony Wilson 1287897967deSJason M. Bills class JournalEventLogEntry : public Node 1288897967deSJason M. Bills { 1289897967deSJason M. Bills public: 129052cc112dSEd Tanous JournalEventLogEntry(App& app) : 1291897967deSJason M. Bills Node(app, 1292897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1293897967deSJason M. Bills std::string()) 1294897967deSJason M. Bills { 1295897967deSJason M. Bills entityPrivileges = { 1296897967deSJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1297897967deSJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1298897967deSJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1299897967deSJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1300897967deSJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1301897967deSJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1302897967deSJason M. Bills } 1303897967deSJason M. Bills 1304897967deSJason M. Bills private: 1305cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1306897967deSJason M. Bills const std::vector<std::string>& params) override 1307897967deSJason M. Bills { 1308897967deSJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1309897967deSJason M. Bills if (params.size() != 1) 1310897967deSJason M. Bills { 1311897967deSJason M. Bills messages::internalError(asyncResp->res); 1312897967deSJason M. Bills return; 1313897967deSJason M. Bills } 1314897967deSJason M. Bills const std::string& targetID = params[0]; 1315897967deSJason M. Bills 1316897967deSJason M. Bills // Go through the log files and check the unique ID for each entry to 1317897967deSJason M. Bills // find the target entry 1318897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1319897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1320897967deSJason M. Bills std::string logEntry; 1321897967deSJason M. Bills 1322897967deSJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 1323897967deSJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1324897967deSJason M. Bills it++) 1325897967deSJason M. Bills { 1326897967deSJason M. Bills std::ifstream logStream(*it); 1327897967deSJason M. Bills if (!logStream.is_open()) 1328897967deSJason M. Bills { 1329897967deSJason M. Bills continue; 1330897967deSJason M. Bills } 1331897967deSJason M. Bills 1332897967deSJason M. Bills // Reset the unique ID on the first entry 1333897967deSJason M. Bills bool firstEntry = true; 1334897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1335897967deSJason M. Bills { 1336897967deSJason M. Bills std::string idStr; 1337897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1338897967deSJason M. Bills { 1339897967deSJason M. Bills continue; 1340897967deSJason M. Bills } 1341897967deSJason M. Bills 1342897967deSJason M. Bills if (firstEntry) 1343897967deSJason M. Bills { 1344897967deSJason M. Bills firstEntry = false; 1345897967deSJason M. Bills } 1346897967deSJason M. Bills 1347897967deSJason M. Bills if (idStr == targetID) 1348897967deSJason M. Bills { 1349897967deSJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, 1350897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1351897967deSJason M. Bills { 1352897967deSJason M. Bills messages::internalError(asyncResp->res); 1353897967deSJason M. Bills return; 1354897967deSJason M. Bills } 1355897967deSJason M. Bills return; 1356897967deSJason M. Bills } 1357897967deSJason M. Bills } 1358897967deSJason M. Bills } 1359897967deSJason M. Bills // Requested ID was not found 1360897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 1361897967deSJason M. Bills } 1362897967deSJason M. Bills }; 1363897967deSJason M. Bills 136408a4e4b5SAnthony Wilson class DBusEventLogEntryCollection : public Node 136508a4e4b5SAnthony Wilson { 136608a4e4b5SAnthony Wilson public: 136752cc112dSEd Tanous DBusEventLogEntryCollection(App& app) : 136808a4e4b5SAnthony Wilson Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 136908a4e4b5SAnthony Wilson { 137008a4e4b5SAnthony Wilson entityPrivileges = { 137108a4e4b5SAnthony Wilson {boost::beast::http::verb::get, {{"Login"}}}, 137208a4e4b5SAnthony Wilson {boost::beast::http::verb::head, {{"Login"}}}, 137308a4e4b5SAnthony Wilson {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 137408a4e4b5SAnthony Wilson {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 137508a4e4b5SAnthony Wilson {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 137608a4e4b5SAnthony Wilson {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 137708a4e4b5SAnthony Wilson } 137808a4e4b5SAnthony Wilson 137908a4e4b5SAnthony Wilson private: 1380cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1381cb13a392SEd Tanous const std::vector<std::string>&) override 138208a4e4b5SAnthony Wilson { 138308a4e4b5SAnthony Wilson std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 138408a4e4b5SAnthony Wilson 138508a4e4b5SAnthony Wilson // Collections don't include the static data added by SubRoute because 138608a4e4b5SAnthony Wilson // it has a duplicate entry for members 138708a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 138808a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 138908a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 139008a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 139108a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 139208a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 139308a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 139408a4e4b5SAnthony Wilson 1395cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1396cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1397cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1398cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1399cb92c03bSAndrew Geissler GetManagedObjectsType& resp) { 1400cb92c03bSAndrew Geissler if (ec) 1401cb92c03bSAndrew Geissler { 1402cb92c03bSAndrew Geissler // TODO Handle for specific error code 1403cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1404cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1405cb92c03bSAndrew Geissler << ec; 1406cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1407cb92c03bSAndrew Geissler return; 1408cb92c03bSAndrew Geissler } 1409cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1410cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1411cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 1412cb92c03bSAndrew Geissler for (auto& objectPath : resp) 1413cb92c03bSAndrew Geissler { 1414cb92c03bSAndrew Geissler for (auto& interfaceMap : objectPath.second) 1415cb92c03bSAndrew Geissler { 1416cb92c03bSAndrew Geissler if (interfaceMap.first != 1417cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry") 1418cb92c03bSAndrew Geissler { 1419cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Bailing early on " 1420cb92c03bSAndrew Geissler << interfaceMap.first; 1421cb92c03bSAndrew Geissler continue; 1422cb92c03bSAndrew Geissler } 1423cb92c03bSAndrew Geissler entriesArray.push_back({}); 1424cb92c03bSAndrew Geissler nlohmann::json& thisEntry = entriesArray.back(); 142566664f25SEd Tanous uint32_t* id = nullptr; 142666664f25SEd Tanous std::time_t timestamp{}; 1427d139c236SGeorge Liu std::time_t updateTimestamp{}; 142866664f25SEd Tanous std::string* severity = nullptr; 142966664f25SEd Tanous std::string* message = nullptr; 1430d139c236SGeorge Liu 1431cb92c03bSAndrew Geissler for (auto& propertyMap : interfaceMap.second) 1432cb92c03bSAndrew Geissler { 1433cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1434cb92c03bSAndrew Geissler { 14358d78b7a9SPatrick Williams id = std::get_if<uint32_t>(&propertyMap.second); 1436cb92c03bSAndrew Geissler if (id == nullptr) 1437cb92c03bSAndrew Geissler { 14380f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1439cb92c03bSAndrew Geissler } 1440cb92c03bSAndrew Geissler } 1441cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1442cb92c03bSAndrew Geissler { 1443cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1444cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1445cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1446cb92c03bSAndrew Geissler { 14470f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1448cb92c03bSAndrew Geissler } 1449ebd45906SGeorge Liu else 1450ebd45906SGeorge Liu { 1451d139c236SGeorge Liu timestamp = crow::utility::getTimestamp( 1452cb92c03bSAndrew Geissler *millisTimeStamp); 1453d139c236SGeorge Liu } 1454ebd45906SGeorge Liu } 1455d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1456d139c236SGeorge Liu { 1457d139c236SGeorge Liu const uint64_t* millisTimeStamp = 1458d139c236SGeorge Liu std::get_if<uint64_t>(&propertyMap.second); 1459d139c236SGeorge Liu if (millisTimeStamp == nullptr) 1460d139c236SGeorge Liu { 1461d139c236SGeorge Liu messages::internalError(asyncResp->res); 1462d139c236SGeorge Liu } 1463ebd45906SGeorge Liu else 1464ebd45906SGeorge Liu { 1465ebd45906SGeorge Liu updateTimestamp = 1466ebd45906SGeorge Liu crow::utility::getTimestamp( 1467d139c236SGeorge Liu *millisTimeStamp); 1468cb92c03bSAndrew Geissler } 1469ebd45906SGeorge Liu } 1470cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1471cb92c03bSAndrew Geissler { 1472cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1473cb92c03bSAndrew Geissler &propertyMap.second); 1474cb92c03bSAndrew Geissler if (severity == nullptr) 1475cb92c03bSAndrew Geissler { 14760f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1477cb92c03bSAndrew Geissler } 1478cb92c03bSAndrew Geissler } 1479cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1480cb92c03bSAndrew Geissler { 1481cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1482cb92c03bSAndrew Geissler &propertyMap.second); 1483cb92c03bSAndrew Geissler if (message == nullptr) 1484cb92c03bSAndrew Geissler { 14850f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1486cb92c03bSAndrew Geissler } 1487cb92c03bSAndrew Geissler } 1488cb92c03bSAndrew Geissler } 1489cb92c03bSAndrew Geissler thisEntry = { 1490d139c236SGeorge Liu {"@odata.type", "#LogEntry.v1_6_0.LogEntry"}, 1491cb92c03bSAndrew Geissler {"@odata.id", 1492cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1493cb92c03bSAndrew Geissler "Entries/" + 1494cb92c03bSAndrew Geissler std::to_string(*id)}, 149527062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1496cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1497cb92c03bSAndrew Geissler {"Message", *message}, 1498cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1499cb92c03bSAndrew Geissler {"Severity", 1500cb92c03bSAndrew Geissler translateSeverityDbusToRedfish(*severity)}, 1501d139c236SGeorge Liu {"Created", crow::utility::getDateTime(timestamp)}, 1502d139c236SGeorge Liu {"Modified", 1503d139c236SGeorge Liu crow::utility::getDateTime(updateTimestamp)}}; 1504cb92c03bSAndrew Geissler } 1505cb92c03bSAndrew Geissler } 1506cb92c03bSAndrew Geissler std::sort(entriesArray.begin(), entriesArray.end(), 1507cb92c03bSAndrew Geissler [](const nlohmann::json& left, 1508cb92c03bSAndrew Geissler const nlohmann::json& right) { 1509cb92c03bSAndrew Geissler return (left["Id"] <= right["Id"]); 1510cb92c03bSAndrew Geissler }); 1511cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members@odata.count"] = 1512cb92c03bSAndrew Geissler entriesArray.size(); 1513cb92c03bSAndrew Geissler }, 1514cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 1515cb92c03bSAndrew Geissler "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 1516c4bf6374SJason M. Bills } 1517c4bf6374SJason M. Bills }; 1518c4bf6374SJason M. Bills 151908a4e4b5SAnthony Wilson class DBusEventLogEntry : public Node 1520c4bf6374SJason M. Bills { 1521c4bf6374SJason M. Bills public: 152252cc112dSEd Tanous DBusEventLogEntry(App& app) : 1523c4bf6374SJason M. Bills Node(app, 1524029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1525029573d4SEd Tanous std::string()) 1526c4bf6374SJason M. Bills { 1527c4bf6374SJason M. Bills entityPrivileges = { 1528c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1529c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1530c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1531c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1532c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1533c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1534c4bf6374SJason M. Bills } 1535c4bf6374SJason M. Bills 1536c4bf6374SJason M. Bills private: 1537cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1538c4bf6374SJason M. Bills const std::vector<std::string>& params) override 1539c4bf6374SJason M. Bills { 1540c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1541029573d4SEd Tanous if (params.size() != 1) 1542c4bf6374SJason M. Bills { 1543c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1544c4bf6374SJason M. Bills return; 1545c4bf6374SJason M. Bills } 1546029573d4SEd Tanous const std::string& entryID = params[0]; 1547cb92c03bSAndrew Geissler 1548cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1549cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1550cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1551cb92c03bSAndrew Geissler [asyncResp, entryID](const boost::system::error_code ec, 1552cb92c03bSAndrew Geissler GetManagedPropertyType& resp) { 1553cb92c03bSAndrew Geissler if (ec) 1554cb92c03bSAndrew Geissler { 1555cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1556cb92c03bSAndrew Geissler << "EventLogEntry (DBus) resp_handler got error " << ec; 1557cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1558cb92c03bSAndrew Geissler return; 1559cb92c03bSAndrew Geissler } 156066664f25SEd Tanous uint32_t* id = nullptr; 156166664f25SEd Tanous std::time_t timestamp{}; 1562d139c236SGeorge Liu std::time_t updateTimestamp{}; 156366664f25SEd Tanous std::string* severity = nullptr; 156466664f25SEd Tanous std::string* message = nullptr; 1565d139c236SGeorge Liu 1566cb92c03bSAndrew Geissler for (auto& propertyMap : resp) 1567cb92c03bSAndrew Geissler { 1568cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1569cb92c03bSAndrew Geissler { 1570cb92c03bSAndrew Geissler id = std::get_if<uint32_t>(&propertyMap.second); 1571cb92c03bSAndrew Geissler if (id == nullptr) 1572cb92c03bSAndrew Geissler { 15730f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1574cb92c03bSAndrew Geissler } 1575cb92c03bSAndrew Geissler } 1576cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1577cb92c03bSAndrew Geissler { 1578cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1579cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1580cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1581cb92c03bSAndrew Geissler { 15820f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1583cb92c03bSAndrew Geissler } 1584ebd45906SGeorge Liu else 1585ebd45906SGeorge Liu { 1586cb92c03bSAndrew Geissler timestamp = 1587d139c236SGeorge Liu crow::utility::getTimestamp(*millisTimeStamp); 1588d139c236SGeorge Liu } 1589ebd45906SGeorge Liu } 1590d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1591d139c236SGeorge Liu { 1592d139c236SGeorge Liu const uint64_t* millisTimeStamp = 1593d139c236SGeorge Liu std::get_if<uint64_t>(&propertyMap.second); 1594d139c236SGeorge Liu if (millisTimeStamp == nullptr) 1595d139c236SGeorge Liu { 1596d139c236SGeorge Liu messages::internalError(asyncResp->res); 1597d139c236SGeorge Liu } 1598ebd45906SGeorge Liu else 1599ebd45906SGeorge Liu { 1600d139c236SGeorge Liu updateTimestamp = 1601d139c236SGeorge Liu crow::utility::getTimestamp(*millisTimeStamp); 1602cb92c03bSAndrew Geissler } 1603ebd45906SGeorge Liu } 1604cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1605cb92c03bSAndrew Geissler { 1606cb92c03bSAndrew Geissler severity = 1607cb92c03bSAndrew Geissler std::get_if<std::string>(&propertyMap.second); 1608cb92c03bSAndrew Geissler if (severity == nullptr) 1609cb92c03bSAndrew Geissler { 16100f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1611cb92c03bSAndrew Geissler } 1612cb92c03bSAndrew Geissler } 1613cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1614cb92c03bSAndrew Geissler { 1615cb92c03bSAndrew Geissler message = std::get_if<std::string>(&propertyMap.second); 1616cb92c03bSAndrew Geissler if (message == nullptr) 1617cb92c03bSAndrew Geissler { 16180f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1619cb92c03bSAndrew Geissler } 1620cb92c03bSAndrew Geissler } 1621cb92c03bSAndrew Geissler } 1622271584abSEd Tanous if (id == nullptr || message == nullptr || severity == nullptr) 1623271584abSEd Tanous { 1624271584abSEd Tanous return; 1625271584abSEd Tanous } 1626cb92c03bSAndrew Geissler asyncResp->res.jsonValue = { 1627d139c236SGeorge Liu {"@odata.type", "#LogEntry.v1_6_0.LogEntry"}, 1628cb92c03bSAndrew Geissler {"@odata.id", 1629cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1630cb92c03bSAndrew Geissler "Entries/" + 1631cb92c03bSAndrew Geissler std::to_string(*id)}, 163227062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1633cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1634cb92c03bSAndrew Geissler {"Message", *message}, 1635cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1636cb92c03bSAndrew Geissler {"Severity", translateSeverityDbusToRedfish(*severity)}, 1637d139c236SGeorge Liu {"Created", crow::utility::getDateTime(timestamp)}, 1638d139c236SGeorge Liu {"Modified", crow::utility::getDateTime(updateTimestamp)}}; 1639cb92c03bSAndrew Geissler }, 1640cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1641cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1642cb92c03bSAndrew Geissler "org.freedesktop.DBus.Properties", "GetAll", 1643cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry"); 1644c4bf6374SJason M. Bills } 1645336e96c6SChicago Duan 1646cb13a392SEd Tanous void doDelete(crow::Response& res, const crow::Request&, 1647336e96c6SChicago Duan const std::vector<std::string>& params) override 1648336e96c6SChicago Duan { 1649336e96c6SChicago Duan 1650336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1651336e96c6SChicago Duan 1652336e96c6SChicago Duan auto asyncResp = std::make_shared<AsyncResp>(res); 1653336e96c6SChicago Duan 1654336e96c6SChicago Duan if (params.size() != 1) 1655336e96c6SChicago Duan { 1656336e96c6SChicago Duan messages::internalError(asyncResp->res); 1657336e96c6SChicago Duan return; 1658336e96c6SChicago Duan } 1659336e96c6SChicago Duan std::string entryID = params[0]; 1660336e96c6SChicago Duan 1661336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1662336e96c6SChicago Duan 1663336e96c6SChicago Duan // Process response from Logging service. 1664336e96c6SChicago Duan auto respHandler = [asyncResp](const boost::system::error_code ec) { 1665336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1666336e96c6SChicago Duan if (ec) 1667336e96c6SChicago Duan { 1668336e96c6SChicago Duan // TODO Handle for specific error code 1669336e96c6SChicago Duan BMCWEB_LOG_ERROR 1670336e96c6SChicago Duan << "EventLogEntry (DBus) doDelete respHandler got error " 1671336e96c6SChicago Duan << ec; 1672336e96c6SChicago Duan asyncResp->res.result( 1673336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1674336e96c6SChicago Duan return; 1675336e96c6SChicago Duan } 1676336e96c6SChicago Duan 1677336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1678336e96c6SChicago Duan }; 1679336e96c6SChicago Duan 1680336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1681336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1682336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1683336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1684336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 1685336e96c6SChicago Duan } 1686c4bf6374SJason M. Bills }; 1687c4bf6374SJason M. Bills 1688c4bf6374SJason M. Bills class BMCLogServiceCollection : public Node 1689c4bf6374SJason M. Bills { 1690c4bf6374SJason M. Bills public: 169152cc112dSEd Tanous BMCLogServiceCollection(App& app) : 16924ed77cd5SEd Tanous Node(app, "/redfish/v1/Managers/bmc/LogServices/") 16931da66f75SEd Tanous { 16941da66f75SEd Tanous entityPrivileges = { 1695e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1696e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1697e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1698e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1699e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1700e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 17011da66f75SEd Tanous } 17021da66f75SEd Tanous 17031da66f75SEd Tanous private: 17041da66f75SEd Tanous /** 17051da66f75SEd Tanous * Functions triggers appropriate requests on DBus 17061da66f75SEd Tanous */ 1707cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1708cb13a392SEd Tanous const std::vector<std::string>&) override 17091da66f75SEd Tanous { 1710e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 17111da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 17121da66f75SEd Tanous // it has a duplicate entry for members 1713e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 17141da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1715e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1716e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 1717e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 1718e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 17191da66f75SEd Tanous "Collection of LogServices for this Manager"; 1720c4bf6374SJason M. Bills nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 1721c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 17225cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 17235cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 17245cb1dd27SAsmitha Karunanithi {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 17255cb1dd27SAsmitha Karunanithi #endif 1726c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1727c4bf6374SJason M. Bills logServiceArray.push_back( 172808a4e4b5SAnthony Wilson {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1729c4bf6374SJason M. Bills #endif 1730e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1731c4bf6374SJason M. Bills logServiceArray.size(); 17321da66f75SEd Tanous } 17331da66f75SEd Tanous }; 17341da66f75SEd Tanous 1735c4bf6374SJason M. Bills class BMCJournalLogService : public Node 17361da66f75SEd Tanous { 17371da66f75SEd Tanous public: 173852cc112dSEd Tanous BMCJournalLogService(App& app) : 1739c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1740e1f26343SJason M. Bills { 1741e1f26343SJason M. Bills entityPrivileges = { 1742e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1743e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1744e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1745e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1746e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1747e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1748e1f26343SJason M. Bills } 1749e1f26343SJason M. Bills 1750e1f26343SJason M. Bills private: 1751cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1752cb13a392SEd Tanous const std::vector<std::string>&) override 1753e1f26343SJason M. Bills { 1754e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1755e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1756e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 17570f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 17580f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 1759c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 1760c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 1761c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1762e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1763cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1764cd50aa42SJason M. Bills {"@odata.id", 1765086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 1766e1f26343SJason M. Bills } 1767e1f26343SJason M. Bills }; 1768e1f26343SJason M. Bills 1769c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 1770e1f26343SJason M. Bills sd_journal* journal, 1771c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 1772e1f26343SJason M. Bills { 1773e1f26343SJason M. Bills // Get the Log Entry contents 1774e1f26343SJason M. Bills int ret = 0; 1775e1f26343SJason M. Bills 177639e77504SEd Tanous std::string_view msg; 177716428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1778e1f26343SJason M. Bills if (ret < 0) 1779e1f26343SJason M. Bills { 1780e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1781e1f26343SJason M. Bills return 1; 1782e1f26343SJason M. Bills } 1783e1f26343SJason M. Bills 1784e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1785271584abSEd Tanous long int severity = 8; // Default to an invalid priority 178616428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1787e1f26343SJason M. Bills if (ret < 0) 1788e1f26343SJason M. Bills { 1789e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1790e1f26343SJason M. Bills } 1791e1f26343SJason M. Bills 1792e1f26343SJason M. Bills // Get the Created time from the timestamp 179316428a1aSJason M. Bills std::string entryTimeStr; 179416428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1795e1f26343SJason M. Bills { 179616428a1aSJason M. Bills return 1; 1797e1f26343SJason M. Bills } 1798e1f26343SJason M. Bills 1799e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1800c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 1801cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1802c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1803c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1804e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1805c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 180616428a1aSJason M. Bills {"Message", msg}, 1807e1f26343SJason M. Bills {"EntryType", "Oem"}, 1808e1f26343SJason M. Bills {"Severity", 1809b6a61a5eSJason M. Bills severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"}, 1810086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1811e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1812e1f26343SJason M. Bills return 0; 1813e1f26343SJason M. Bills } 1814e1f26343SJason M. Bills 1815c4bf6374SJason M. Bills class BMCJournalLogEntryCollection : public Node 1816e1f26343SJason M. Bills { 1817e1f26343SJason M. Bills public: 181852cc112dSEd Tanous BMCJournalLogEntryCollection(App& app) : 1819c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1820e1f26343SJason M. Bills { 1821e1f26343SJason M. Bills entityPrivileges = { 1822e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1823e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1824e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1825e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1826e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1827e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1828e1f26343SJason M. Bills } 1829e1f26343SJason M. Bills 1830e1f26343SJason M. Bills private: 1831e1f26343SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1832cb13a392SEd Tanous const std::vector<std::string>&) override 1833e1f26343SJason M. Bills { 1834e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1835193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1836271584abSEd Tanous uint64_t skip = 0; 1837271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 183816428a1aSJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1839193ad2faSJason M. Bills { 1840193ad2faSJason M. Bills return; 1841193ad2faSJason M. Bills } 184216428a1aSJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1843193ad2faSJason M. Bills { 1844193ad2faSJason M. Bills return; 1845193ad2faSJason M. Bills } 1846e1f26343SJason M. Bills // Collections don't include the static data added by SubRoute because 1847e1f26343SJason M. Bills // it has a duplicate entry for members 1848e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1849e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 18500f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18510f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1852e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1853c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1854e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1855e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1856e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 18570f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18580f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries"; 1859e1f26343SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1860e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1861e1f26343SJason M. Bills 1862e1f26343SJason M. Bills // Go through the journal and use the timestamp to create a unique ID 1863e1f26343SJason M. Bills // for each entry 1864e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1865e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1866e1f26343SJason M. Bills if (ret < 0) 1867e1f26343SJason M. Bills { 1868e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1869f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1870e1f26343SJason M. Bills return; 1871e1f26343SJason M. Bills } 1872e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1873e1f26343SJason M. Bills journalTmp, sd_journal_close); 1874e1f26343SJason M. Bills journalTmp = nullptr; 1875b01bf299SEd Tanous uint64_t entryCount = 0; 1876e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1877e85d6b16SJason M. Bills bool firstEntry = true; 1878e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1879e1f26343SJason M. Bills { 1880193ad2faSJason M. Bills entryCount++; 1881193ad2faSJason M. Bills // Handle paging using skip (number of entries to skip from the 1882193ad2faSJason M. Bills // start) and top (number of entries to display) 1883193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1884193ad2faSJason M. Bills { 1885193ad2faSJason M. Bills continue; 1886193ad2faSJason M. Bills } 1887193ad2faSJason M. Bills 188816428a1aSJason M. Bills std::string idStr; 1889e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1890e1f26343SJason M. Bills { 1891e1f26343SJason M. Bills continue; 1892e1f26343SJason M. Bills } 1893e1f26343SJason M. Bills 1894e85d6b16SJason M. Bills if (firstEntry) 1895e85d6b16SJason M. Bills { 1896e85d6b16SJason M. Bills firstEntry = false; 1897e85d6b16SJason M. Bills } 1898e85d6b16SJason M. Bills 1899e1f26343SJason M. Bills logEntryArray.push_back({}); 1900c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 1901c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 1902c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 1903e1f26343SJason M. Bills { 1904f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1905e1f26343SJason M. Bills return; 1906e1f26343SJason M. Bills } 1907e1f26343SJason M. Bills } 1908193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1909193ad2faSJason M. Bills if (skip + top < entryCount) 1910193ad2faSJason M. Bills { 1911193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 1912c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 1913193ad2faSJason M. Bills std::to_string(skip + top); 1914193ad2faSJason M. Bills } 1915e1f26343SJason M. Bills } 1916e1f26343SJason M. Bills }; 1917e1f26343SJason M. Bills 1918c4bf6374SJason M. Bills class BMCJournalLogEntry : public Node 1919e1f26343SJason M. Bills { 1920e1f26343SJason M. Bills public: 192152cc112dSEd Tanous BMCJournalLogEntry(App& app) : 1922c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/", 1923e1f26343SJason M. Bills std::string()) 1924e1f26343SJason M. Bills { 1925e1f26343SJason M. Bills entityPrivileges = { 1926e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1927e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1928e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1929e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1930e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1931e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1932e1f26343SJason M. Bills } 1933e1f26343SJason M. Bills 1934e1f26343SJason M. Bills private: 1935cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1936e1f26343SJason M. Bills const std::vector<std::string>& params) override 1937e1f26343SJason M. Bills { 1938e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1939e1f26343SJason M. Bills if (params.size() != 1) 1940e1f26343SJason M. Bills { 1941f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1942e1f26343SJason M. Bills return; 1943e1f26343SJason M. Bills } 194416428a1aSJason M. Bills const std::string& entryID = params[0]; 1945e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 1946e1f26343SJason M. Bills uint64_t ts = 0; 1947271584abSEd Tanous uint64_t index = 0; 194816428a1aSJason M. Bills if (!getTimestampFromID(asyncResp->res, entryID, ts, index)) 1949e1f26343SJason M. Bills { 195016428a1aSJason M. Bills return; 1951e1f26343SJason M. Bills } 1952e1f26343SJason M. Bills 1953e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1954e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1955e1f26343SJason M. Bills if (ret < 0) 1956e1f26343SJason M. Bills { 1957e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1958f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1959e1f26343SJason M. Bills return; 1960e1f26343SJason M. Bills } 1961e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1962e1f26343SJason M. Bills journalTmp, sd_journal_close); 1963e1f26343SJason M. Bills journalTmp = nullptr; 1964e1f26343SJason M. Bills // Go to the timestamp in the log and move to the entry at the index 1965af07e3f5SJason M. Bills // tracking the unique ID 1966af07e3f5SJason M. Bills std::string idStr; 1967af07e3f5SJason M. Bills bool firstEntry = true; 1968e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 19692056b6d1SManojkiran Eda if (ret < 0) 19702056b6d1SManojkiran Eda { 19712056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 19722056b6d1SManojkiran Eda << strerror(-ret); 19732056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 19742056b6d1SManojkiran Eda return; 19752056b6d1SManojkiran Eda } 1976271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 1977e1f26343SJason M. Bills { 1978e1f26343SJason M. Bills sd_journal_next(journal.get()); 1979af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1980af07e3f5SJason M. Bills { 1981af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 1982af07e3f5SJason M. Bills return; 1983af07e3f5SJason M. Bills } 1984af07e3f5SJason M. Bills if (firstEntry) 1985af07e3f5SJason M. Bills { 1986af07e3f5SJason M. Bills firstEntry = false; 1987af07e3f5SJason M. Bills } 1988e1f26343SJason M. Bills } 1989c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 1990af07e3f5SJason M. Bills if (idStr != entryID) 1991c4bf6374SJason M. Bills { 1992c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 1993c4bf6374SJason M. Bills return; 1994c4bf6374SJason M. Bills } 1995c4bf6374SJason M. Bills 1996c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 1997e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 1998e1f26343SJason M. Bills { 1999f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2000e1f26343SJason M. Bills return; 2001e1f26343SJason M. Bills } 2002e1f26343SJason M. Bills } 2003e1f26343SJason M. Bills }; 2004e1f26343SJason M. Bills 20055cb1dd27SAsmitha Karunanithi class BMCDumpService : public Node 2006c9bb6861Sraviteja-b { 2007c9bb6861Sraviteja-b public: 200852cc112dSEd Tanous BMCDumpService(App& app) : 20095cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2010c9bb6861Sraviteja-b { 2011c9bb6861Sraviteja-b entityPrivileges = { 2012c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2013c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2014c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2015c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2016c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2017c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2018c9bb6861Sraviteja-b } 2019c9bb6861Sraviteja-b 2020c9bb6861Sraviteja-b private: 2021cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2022cb13a392SEd Tanous const std::vector<std::string>&) override 2023c9bb6861Sraviteja-b { 2024c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2025c9bb6861Sraviteja-b 2026c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 20275cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 2028c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2029*d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 2030c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 20315cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 20325cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2033c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2034c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 20355cb1dd27SAsmitha Karunanithi {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}}; 20365cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 20375cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 20385cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 20395cb1dd27SAsmitha Karunanithi "Actions/LogService.ClearLog"}}}, 2040*d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 2041*d337bb72SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 2042*d337bb72SAsmitha Karunanithi "Actions/LogService.CollectDiagnosticData"}}}}; 2043c9bb6861Sraviteja-b } 2044c9bb6861Sraviteja-b }; 2045c9bb6861Sraviteja-b 20465cb1dd27SAsmitha Karunanithi class BMCDumpEntryCollection : public Node 2047c9bb6861Sraviteja-b { 2048c9bb6861Sraviteja-b public: 204952cc112dSEd Tanous BMCDumpEntryCollection(App& app) : 20505cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2051c9bb6861Sraviteja-b { 2052c9bb6861Sraviteja-b entityPrivileges = { 2053c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2054c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2055c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2056c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2057c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2058c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2059c9bb6861Sraviteja-b } 2060c9bb6861Sraviteja-b 2061c9bb6861Sraviteja-b private: 2062c9bb6861Sraviteja-b /** 2063c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2064c9bb6861Sraviteja-b */ 2065cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2066cb13a392SEd Tanous const std::vector<std::string>&) override 2067c9bb6861Sraviteja-b { 2068c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2069c9bb6861Sraviteja-b 2070c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2071c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2072c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 20735cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 20745cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2075c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 20765cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2077c9bb6861Sraviteja-b 20785cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 2079c9bb6861Sraviteja-b } 2080c9bb6861Sraviteja-b }; 2081c9bb6861Sraviteja-b 20825cb1dd27SAsmitha Karunanithi class BMCDumpEntry : public Node 2083c9bb6861Sraviteja-b { 2084c9bb6861Sraviteja-b public: 208552cc112dSEd Tanous BMCDumpEntry(App& app) : 20865cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/", 2087c9bb6861Sraviteja-b std::string()) 2088c9bb6861Sraviteja-b { 2089c9bb6861Sraviteja-b entityPrivileges = { 2090c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2091c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2092c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2093c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2094c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2095c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2096c9bb6861Sraviteja-b } 2097c9bb6861Sraviteja-b 2098c9bb6861Sraviteja-b private: 2099cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2100c9bb6861Sraviteja-b const std::vector<std::string>& params) override 2101c9bb6861Sraviteja-b { 2102c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2103c9bb6861Sraviteja-b if (params.size() != 1) 2104c9bb6861Sraviteja-b { 2105c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2106c9bb6861Sraviteja-b return; 2107c9bb6861Sraviteja-b } 21085cb1dd27SAsmitha Karunanithi getDumpEntryById(asyncResp, params[0], "BMC"); 2109c9bb6861Sraviteja-b } 2110c9bb6861Sraviteja-b 2111cb13a392SEd Tanous void doDelete(crow::Response& res, const crow::Request&, 2112c9bb6861Sraviteja-b const std::vector<std::string>& params) override 2113c9bb6861Sraviteja-b { 21145cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2115c9bb6861Sraviteja-b if (params.size() != 1) 2116c9bb6861Sraviteja-b { 2117c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2118c9bb6861Sraviteja-b return; 2119c9bb6861Sraviteja-b } 21205cb1dd27SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, params[0]); 21215cb1dd27SAsmitha Karunanithi } 21225cb1dd27SAsmitha Karunanithi }; 2123c9bb6861Sraviteja-b 2124a43be80fSAsmitha Karunanithi class BMCDumpCreate : public Node 2125a43be80fSAsmitha Karunanithi { 2126a43be80fSAsmitha Karunanithi public: 212752cc112dSEd Tanous BMCDumpCreate(App& app) : 2128a43be80fSAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 2129*d337bb72SAsmitha Karunanithi "Actions/" 2130*d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2131a43be80fSAsmitha Karunanithi { 2132a43be80fSAsmitha Karunanithi entityPrivileges = { 2133a43be80fSAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2134a43be80fSAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2135a43be80fSAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2136a43be80fSAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2137a43be80fSAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2138a43be80fSAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2139a43be80fSAsmitha Karunanithi } 2140a43be80fSAsmitha Karunanithi 2141a43be80fSAsmitha Karunanithi private: 2142a43be80fSAsmitha Karunanithi void doPost(crow::Response& res, const crow::Request& req, 2143cb13a392SEd Tanous const std::vector<std::string>&) override 2144a43be80fSAsmitha Karunanithi { 2145a43be80fSAsmitha Karunanithi createDump(res, req, "BMC"); 2146a43be80fSAsmitha Karunanithi } 2147a43be80fSAsmitha Karunanithi }; 2148a43be80fSAsmitha Karunanithi 214980319af1SAsmitha Karunanithi class BMCDumpClear : public Node 215080319af1SAsmitha Karunanithi { 215180319af1SAsmitha Karunanithi public: 215252cc112dSEd Tanous BMCDumpClear(App& app) : 215380319af1SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 215480319af1SAsmitha Karunanithi "Actions/" 215580319af1SAsmitha Karunanithi "LogService.ClearLog/") 215680319af1SAsmitha Karunanithi { 215780319af1SAsmitha Karunanithi entityPrivileges = { 215880319af1SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 215980319af1SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 216080319af1SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 216180319af1SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 216280319af1SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 216380319af1SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 216480319af1SAsmitha Karunanithi } 216580319af1SAsmitha Karunanithi 216680319af1SAsmitha Karunanithi private: 2167cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2168cb13a392SEd Tanous const std::vector<std::string>&) override 216980319af1SAsmitha Karunanithi { 217080319af1SAsmitha Karunanithi clearDump(res, "xyz.openbmc_project.Dump.Entry.BMC"); 217180319af1SAsmitha Karunanithi } 217280319af1SAsmitha Karunanithi }; 217380319af1SAsmitha Karunanithi 21745cb1dd27SAsmitha Karunanithi class SystemDumpService : public Node 2175c9bb6861Sraviteja-b { 21765cb1dd27SAsmitha Karunanithi public: 217752cc112dSEd Tanous SystemDumpService(App& app) : 21785cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/") 21795cb1dd27SAsmitha Karunanithi { 21805cb1dd27SAsmitha Karunanithi entityPrivileges = { 21815cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 21825cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 21835cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 21845cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 21855cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 21865cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 21875cb1dd27SAsmitha Karunanithi } 21885cb1dd27SAsmitha Karunanithi 21895cb1dd27SAsmitha Karunanithi private: 2190cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2191cb13a392SEd Tanous const std::vector<std::string>&) override 21925cb1dd27SAsmitha Karunanithi { 21935cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 21945cb1dd27SAsmitha Karunanithi 21955cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 21965cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 21975cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2198*d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 21995cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 22005cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "System Dump LogService"; 22015cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 22025cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 22035cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Entries"] = { 22045cb1dd27SAsmitha Karunanithi {"@odata.id", 22055cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"}}; 22065cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 22075cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 22085cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 22095cb1dd27SAsmitha Karunanithi "LogService.ClearLog"}}}, 2210*d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 2211*d337bb72SAsmitha Karunanithi {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 2212*d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData"}}}}; 22135cb1dd27SAsmitha Karunanithi } 22145cb1dd27SAsmitha Karunanithi }; 22155cb1dd27SAsmitha Karunanithi 22165cb1dd27SAsmitha Karunanithi class SystemDumpEntryCollection : public Node 22175cb1dd27SAsmitha Karunanithi { 22185cb1dd27SAsmitha Karunanithi public: 221952cc112dSEd Tanous SystemDumpEntryCollection(App& app) : 22205cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 22215cb1dd27SAsmitha Karunanithi { 22225cb1dd27SAsmitha Karunanithi entityPrivileges = { 22235cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 22245cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 22255cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 22265cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 22275cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 22285cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 22295cb1dd27SAsmitha Karunanithi } 22305cb1dd27SAsmitha Karunanithi 22315cb1dd27SAsmitha Karunanithi private: 22325cb1dd27SAsmitha Karunanithi /** 22335cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 22345cb1dd27SAsmitha Karunanithi */ 2235cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2236cb13a392SEd Tanous const std::vector<std::string>&) override 22375cb1dd27SAsmitha Karunanithi { 22385cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22395cb1dd27SAsmitha Karunanithi 22405cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 22415cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 22425cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 22435cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 22445cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 22455cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 22465cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 22475cb1dd27SAsmitha Karunanithi 22485cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 22495cb1dd27SAsmitha Karunanithi } 22505cb1dd27SAsmitha Karunanithi }; 22515cb1dd27SAsmitha Karunanithi 22525cb1dd27SAsmitha Karunanithi class SystemDumpEntry : public Node 22535cb1dd27SAsmitha Karunanithi { 22545cb1dd27SAsmitha Karunanithi public: 225552cc112dSEd Tanous SystemDumpEntry(App& app) : 22565cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/", 22575cb1dd27SAsmitha Karunanithi std::string()) 22585cb1dd27SAsmitha Karunanithi { 22595cb1dd27SAsmitha Karunanithi entityPrivileges = { 22605cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 22615cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 22625cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 22635cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 22645cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 22655cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 22665cb1dd27SAsmitha Karunanithi } 22675cb1dd27SAsmitha Karunanithi 22685cb1dd27SAsmitha Karunanithi private: 2269cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 22705cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 22715cb1dd27SAsmitha Karunanithi { 22725cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22735cb1dd27SAsmitha Karunanithi if (params.size() != 1) 22745cb1dd27SAsmitha Karunanithi { 2275c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2276c9bb6861Sraviteja-b return; 2277c9bb6861Sraviteja-b } 22785cb1dd27SAsmitha Karunanithi getDumpEntryById(asyncResp, params[0], "System"); 22795cb1dd27SAsmitha Karunanithi } 2280c9bb6861Sraviteja-b 2281cb13a392SEd Tanous void doDelete(crow::Response& res, const crow::Request&, 22825cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 2283c9bb6861Sraviteja-b { 22845cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22855cb1dd27SAsmitha Karunanithi if (params.size() != 1) 2286c9bb6861Sraviteja-b { 22875cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 2288c9bb6861Sraviteja-b return; 2289c9bb6861Sraviteja-b } 22905cb1dd27SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, params[0]); 2291c9bb6861Sraviteja-b } 2292c9bb6861Sraviteja-b }; 2293c9bb6861Sraviteja-b 2294a43be80fSAsmitha Karunanithi class SystemDumpCreate : public Node 2295a43be80fSAsmitha Karunanithi { 2296a43be80fSAsmitha Karunanithi public: 229752cc112dSEd Tanous SystemDumpCreate(App& app) : 2298a43be80fSAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2299*d337bb72SAsmitha Karunanithi "Actions/" 2300*d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2301a43be80fSAsmitha Karunanithi { 2302a43be80fSAsmitha Karunanithi entityPrivileges = { 2303a43be80fSAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2304a43be80fSAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2305a43be80fSAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2306a43be80fSAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2307a43be80fSAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2308a43be80fSAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2309a43be80fSAsmitha Karunanithi } 2310a43be80fSAsmitha Karunanithi 2311a43be80fSAsmitha Karunanithi private: 2312a43be80fSAsmitha Karunanithi void doPost(crow::Response& res, const crow::Request& req, 2313cb13a392SEd Tanous const std::vector<std::string>&) override 2314a43be80fSAsmitha Karunanithi { 2315a43be80fSAsmitha Karunanithi createDump(res, req, "System"); 2316a43be80fSAsmitha Karunanithi } 2317a43be80fSAsmitha Karunanithi }; 2318a43be80fSAsmitha Karunanithi 2319013487e5Sraviteja-b class SystemDumpClear : public Node 2320013487e5Sraviteja-b { 2321013487e5Sraviteja-b public: 232252cc112dSEd Tanous SystemDumpClear(App& app) : 232380319af1SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2324013487e5Sraviteja-b "Actions/" 2325013487e5Sraviteja-b "LogService.ClearLog/") 2326013487e5Sraviteja-b { 2327013487e5Sraviteja-b entityPrivileges = { 2328013487e5Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2329013487e5Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 233080319af1SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 233180319af1SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 233280319af1SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2333013487e5Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2334013487e5Sraviteja-b } 2335013487e5Sraviteja-b 2336013487e5Sraviteja-b private: 2337cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2338cb13a392SEd Tanous const std::vector<std::string>&) override 2339013487e5Sraviteja-b { 234080319af1SAsmitha Karunanithi clearDump(res, "xyz.openbmc_project.Dump.Entry.System"); 2341013487e5Sraviteja-b } 2342013487e5Sraviteja-b }; 2343013487e5Sraviteja-b 2344424c4176SJason M. Bills class CrashdumpService : public Node 2345e1f26343SJason M. Bills { 2346e1f26343SJason M. Bills public: 234752cc112dSEd Tanous CrashdumpService(App& app) : 2348424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 23491da66f75SEd Tanous { 23503946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 23513946028dSAppaRao Puli // method for security reasons. 23521da66f75SEd Tanous entityPrivileges = { 23533946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 23543946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2355e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2356e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2357e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2358e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 23591da66f75SEd Tanous } 23601da66f75SEd Tanous 23611da66f75SEd Tanous private: 23621da66f75SEd Tanous /** 23631da66f75SEd Tanous * Functions triggers appropriate requests on DBus 23641da66f75SEd Tanous */ 2365cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2366cb13a392SEd Tanous const std::vector<std::string>&) override 23671da66f75SEd Tanous { 2368e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 23691da66f75SEd Tanous // Copy over the static data to include the entries added by SubRoute 23700f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2371424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2372e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2373e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 23744f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 23754f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 23764f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2377e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2378e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 2379cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2380cd50aa42SJason M. Bills {"@odata.id", 2381424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 2382e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 23835b61b5e8SJason M. Bills {"#LogService.ClearLog", 23845b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 23855b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 23861da66f75SEd Tanous {"Oem", 2387424c4176SJason M. Bills {{"#Crashdump.OnDemand", 2388424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 23896eda7685SKenny L. Ku "Actions/Oem/Crashdump.OnDemand"}}}, 23906eda7685SKenny L. Ku {"#Crashdump.Telemetry", 23916eda7685SKenny L. Ku {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 23926eda7685SKenny L. Ku "Actions/Oem/Crashdump.Telemetry"}}}}}}; 23931da66f75SEd Tanous 23941da66f75SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI 2395e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"]["Oem"].push_back( 2396424c4176SJason M. Bills {"#Crashdump.SendRawPeci", 239708a4e4b5SAnthony Wilson {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 2398424c4176SJason M. Bills "Actions/Oem/Crashdump.SendRawPeci"}}}); 23991da66f75SEd Tanous #endif 24001da66f75SEd Tanous } 24011da66f75SEd Tanous }; 24021da66f75SEd Tanous 24035b61b5e8SJason M. Bills class CrashdumpClear : public Node 24045b61b5e8SJason M. Bills { 24055b61b5e8SJason M. Bills public: 240652cc112dSEd Tanous CrashdumpClear(App& app) : 24075b61b5e8SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 24085b61b5e8SJason M. Bills "LogService.ClearLog/") 24095b61b5e8SJason M. Bills { 24103946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24113946028dSAppaRao Puli // method for security reasons. 24125b61b5e8SJason M. Bills entityPrivileges = { 24133946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 24143946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 24155b61b5e8SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 24165b61b5e8SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 24175b61b5e8SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 24185b61b5e8SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 24195b61b5e8SJason M. Bills } 24205b61b5e8SJason M. Bills 24215b61b5e8SJason M. Bills private: 2422cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2423cb13a392SEd Tanous const std::vector<std::string>&) override 24245b61b5e8SJason M. Bills { 24255b61b5e8SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 24265b61b5e8SJason M. Bills 24275b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 24285b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2429cb13a392SEd Tanous const std::string&) { 24305b61b5e8SJason M. Bills if (ec) 24315b61b5e8SJason M. Bills { 24325b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 24335b61b5e8SJason M. Bills return; 24345b61b5e8SJason M. Bills } 24355b61b5e8SJason M. Bills messages::success(asyncResp->res); 24365b61b5e8SJason M. Bills }, 24375b61b5e8SJason M. Bills crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 24385b61b5e8SJason M. Bills } 24395b61b5e8SJason M. Bills }; 24405b61b5e8SJason M. Bills 2441e855dd28SJason M. Bills static void logCrashdumpEntry(std::shared_ptr<AsyncResp> asyncResp, 2442e855dd28SJason M. Bills const std::string& logID, 2443e855dd28SJason M. Bills nlohmann::json& logEntryJson) 2444e855dd28SJason M. Bills { 2445043a0536SJohnathan Mantey auto getStoredLogCallback = 2446043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 2447e855dd28SJason M. Bills const boost::system::error_code ec, 2448043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params) { 2449e855dd28SJason M. Bills if (ec) 2450e855dd28SJason M. Bills { 2451e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 24521ddcf01aSJason M. Bills if (ec.value() == 24531ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 24541ddcf01aSJason M. Bills { 2455043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2456043a0536SJohnathan Mantey logID); 24571ddcf01aSJason M. Bills } 24581ddcf01aSJason M. Bills else 24591ddcf01aSJason M. Bills { 2460e855dd28SJason M. Bills messages::internalError(asyncResp->res); 24611ddcf01aSJason M. Bills } 2462e855dd28SJason M. Bills return; 2463e855dd28SJason M. Bills } 2464043a0536SJohnathan Mantey 2465043a0536SJohnathan Mantey std::string timestamp{}; 2466043a0536SJohnathan Mantey std::string filename{}; 2467043a0536SJohnathan Mantey std::string logfile{}; 2468043a0536SJohnathan Mantey ParseCrashdumpParameters(params, filename, timestamp, logfile); 2469043a0536SJohnathan Mantey 2470043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2471e855dd28SJason M. Bills { 2472043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 2473e855dd28SJason M. Bills return; 2474e855dd28SJason M. Bills } 2475e855dd28SJason M. Bills 2476043a0536SJohnathan Mantey std::string crashdumpURI = 2477e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2478043a0536SJohnathan Mantey logID + "/" + filename; 2479043a0536SJohnathan Mantey logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 2480043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 2481043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 2482e855dd28SJason M. Bills logID}, 2483e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2484e855dd28SJason M. Bills {"Id", logID}, 2485e855dd28SJason M. Bills {"EntryType", "Oem"}, 2486e855dd28SJason M. Bills {"OemRecordFormat", "Crashdump URI"}, 2487043a0536SJohnathan Mantey {"Message", std::move(crashdumpURI)}, 2488043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2489e855dd28SJason M. Bills }; 2490e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 24915b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 24925b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2493043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2494e855dd28SJason M. Bills } 2495e855dd28SJason M. Bills 2496424c4176SJason M. Bills class CrashdumpEntryCollection : public Node 24971da66f75SEd Tanous { 24981da66f75SEd Tanous public: 249952cc112dSEd Tanous CrashdumpEntryCollection(App& app) : 2500424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 25011da66f75SEd Tanous { 25023946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25033946028dSAppaRao Puli // method for security reasons. 25041da66f75SEd Tanous entityPrivileges = { 25053946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 25063946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2507e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2508e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2509e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2510e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 25111da66f75SEd Tanous } 25121da66f75SEd Tanous 25131da66f75SEd Tanous private: 25141da66f75SEd Tanous /** 25151da66f75SEd Tanous * Functions triggers appropriate requests on DBus 25161da66f75SEd Tanous */ 2517cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2518cb13a392SEd Tanous const std::vector<std::string>&) override 25191da66f75SEd Tanous { 2520e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 25211da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 25221da66f75SEd Tanous // it has a duplicate entry for members 2523e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2524e1f26343SJason M. Bills const boost::system::error_code ec, 25251da66f75SEd Tanous const std::vector<std::string>& resp) { 25261da66f75SEd Tanous if (ec) 25271da66f75SEd Tanous { 25281da66f75SEd Tanous if (ec.value() != 25291da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 25301da66f75SEd Tanous { 25311da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 25321da66f75SEd Tanous << ec.message(); 2533f12894f8SJason M. Bills messages::internalError(asyncResp->res); 25341da66f75SEd Tanous return; 25351da66f75SEd Tanous } 25361da66f75SEd Tanous } 2537e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 25381da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 25390f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2540424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2541424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2542e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2543424c4176SJason M. Bills "Collection of Crashdump Entries"; 2544e1f26343SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2545e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2546e855dd28SJason M. Bills std::vector<std::string> logIDs; 2547e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2548e855dd28SJason M. Bills // enough to hold them 25491da66f75SEd Tanous for (const std::string& objpath : resp) 25501da66f75SEd Tanous { 2551e855dd28SJason M. Bills // Get the log ID 25524ed77cd5SEd Tanous std::size_t lastPos = objpath.rfind("/"); 2553e855dd28SJason M. Bills if (lastPos == std::string::npos) 25541da66f75SEd Tanous { 2555e855dd28SJason M. Bills continue; 25561da66f75SEd Tanous } 2557e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2558e855dd28SJason M. Bills 2559e855dd28SJason M. Bills // Add a space for the log entry to the array 2560e855dd28SJason M. Bills logEntryArray.push_back({}); 2561e855dd28SJason M. Bills } 2562e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2563e855dd28SJason M. Bills size_t index = 0; 2564e855dd28SJason M. Bills for (const std::string& logID : logIDs) 2565e855dd28SJason M. Bills { 2566e855dd28SJason M. Bills // Add the log entry to the array 2567e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 25681da66f75SEd Tanous } 2569e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2570e1f26343SJason M. Bills logEntryArray.size(); 25711da66f75SEd Tanous }; 25721da66f75SEd Tanous crow::connections::systemBus->async_method_call( 25731da66f75SEd Tanous std::move(getLogEntriesCallback), 25741da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 25751da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 25761da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 25775b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 25781da66f75SEd Tanous } 25791da66f75SEd Tanous }; 25801da66f75SEd Tanous 2581424c4176SJason M. Bills class CrashdumpEntry : public Node 25821da66f75SEd Tanous { 25831da66f75SEd Tanous public: 258452cc112dSEd Tanous CrashdumpEntry(App& app) : 2585d53dd41fSJason M. Bills Node(app, 2586424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/", 25871da66f75SEd Tanous std::string()) 25881da66f75SEd Tanous { 25893946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25903946028dSAppaRao Puli // method for security reasons. 25911da66f75SEd Tanous entityPrivileges = { 25923946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 25933946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2594e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2595e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2596e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2597e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 25981da66f75SEd Tanous } 25991da66f75SEd Tanous 26001da66f75SEd Tanous private: 2601cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 26021da66f75SEd Tanous const std::vector<std::string>& params) override 26031da66f75SEd Tanous { 2604e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 26051da66f75SEd Tanous if (params.size() != 1) 26061da66f75SEd Tanous { 2607f12894f8SJason M. Bills messages::internalError(asyncResp->res); 26081da66f75SEd Tanous return; 26091da66f75SEd Tanous } 2610e855dd28SJason M. Bills const std::string& logID = params[0]; 2611e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 2612e855dd28SJason M. Bills } 2613e855dd28SJason M. Bills }; 2614e855dd28SJason M. Bills 2615e855dd28SJason M. Bills class CrashdumpFile : public Node 2616e855dd28SJason M. Bills { 2617e855dd28SJason M. Bills public: 261852cc112dSEd Tanous CrashdumpFile(App& app) : 2619e855dd28SJason M. Bills Node(app, 2620e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/" 2621e855dd28SJason M. Bills "<str>/", 2622e855dd28SJason M. Bills std::string(), std::string()) 2623e855dd28SJason M. Bills { 26243946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 26253946028dSAppaRao Puli // method for security reasons. 2626e855dd28SJason M. Bills entityPrivileges = { 26273946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 26283946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2629e855dd28SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2630e855dd28SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2631e855dd28SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2632e855dd28SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2633e855dd28SJason M. Bills } 2634e855dd28SJason M. Bills 2635e855dd28SJason M. Bills private: 2636cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2637e855dd28SJason M. Bills const std::vector<std::string>& params) override 2638e855dd28SJason M. Bills { 2639e855dd28SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2640e855dd28SJason M. Bills if (params.size() != 2) 2641e855dd28SJason M. Bills { 2642e855dd28SJason M. Bills messages::internalError(asyncResp->res); 2643e855dd28SJason M. Bills return; 2644e855dd28SJason M. Bills } 2645e855dd28SJason M. Bills const std::string& logID = params[0]; 2646e855dd28SJason M. Bills const std::string& fileName = params[1]; 2647e855dd28SJason M. Bills 2648043a0536SJohnathan Mantey auto getStoredLogCallback = 2649043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 2650abf2add6SEd Tanous const boost::system::error_code ec, 2651043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& resp) { 26521da66f75SEd Tanous if (ec) 26531da66f75SEd Tanous { 2654043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2655043a0536SJohnathan Mantey << ec.message(); 2656f12894f8SJason M. Bills messages::internalError(asyncResp->res); 26571da66f75SEd Tanous return; 26581da66f75SEd Tanous } 2659e855dd28SJason M. Bills 2660043a0536SJohnathan Mantey std::string dbusFilename{}; 2661043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2662043a0536SJohnathan Mantey std::string dbusFilepath{}; 2663043a0536SJohnathan Mantey 2664043a0536SJohnathan Mantey ParseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 2665043a0536SJohnathan Mantey dbusFilepath); 2666043a0536SJohnathan Mantey 2667043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2668043a0536SJohnathan Mantey dbusFilepath.empty()) 26691da66f75SEd Tanous { 2670e855dd28SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, fileName); 26711da66f75SEd Tanous return; 26721da66f75SEd Tanous } 2673e855dd28SJason M. Bills 2674043a0536SJohnathan Mantey // Verify the file name parameter is correct 2675043a0536SJohnathan Mantey if (fileName != dbusFilename) 2676043a0536SJohnathan Mantey { 2677043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2678043a0536SJohnathan Mantey return; 2679043a0536SJohnathan Mantey } 2680043a0536SJohnathan Mantey 2681043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2682043a0536SJohnathan Mantey { 2683043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2684043a0536SJohnathan Mantey return; 2685043a0536SJohnathan Mantey } 2686043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 2687043a0536SJohnathan Mantey std::ios::binary | 2688043a0536SJohnathan Mantey std::ios::ate); 2689043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 2690043a0536SJohnathan Mantey if (fileSize < 0) 2691043a0536SJohnathan Mantey { 2692043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 2693043a0536SJohnathan Mantey return; 2694043a0536SJohnathan Mantey } 2695043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 2696043a0536SJohnathan Mantey 2697043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 2698043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 2699043a0536SJohnathan Mantey 2700043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 2701043a0536SJohnathan Mantey 2702043a0536SJohnathan Mantey // The cast to std::string is intentional in order to use the 2703043a0536SJohnathan Mantey // assign() that applies move mechanics 2704043a0536SJohnathan Mantey asyncResp->res.body().assign( 2705043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 2706043a0536SJohnathan Mantey 2707043a0536SJohnathan Mantey // Configure this to be a file download when accessed from 2708043a0536SJohnathan Mantey // a browser 2709e855dd28SJason M. Bills asyncResp->res.addHeader("Content-Disposition", "attachment"); 27101da66f75SEd Tanous }; 27111da66f75SEd Tanous crow::connections::systemBus->async_method_call( 27125b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 27135b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2714043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 27151da66f75SEd Tanous } 27161da66f75SEd Tanous }; 27171da66f75SEd Tanous 2718424c4176SJason M. Bills class OnDemandCrashdump : public Node 27191da66f75SEd Tanous { 27201da66f75SEd Tanous public: 272152cc112dSEd Tanous OnDemandCrashdump(App& app) : 2722424c4176SJason M. Bills Node(app, 2723424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2724424c4176SJason M. Bills "Crashdump.OnDemand/") 27251da66f75SEd Tanous { 27263946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 27273946028dSAppaRao Puli // method for security reasons. 27281da66f75SEd Tanous entityPrivileges = { 27293946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 27303946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 27313946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 27323946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 27333946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 27343946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 27351da66f75SEd Tanous } 27361da66f75SEd Tanous 27371da66f75SEd Tanous private: 27381da66f75SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 2739cb13a392SEd Tanous const std::vector<std::string>&) override 27401da66f75SEd Tanous { 2741e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 27421da66f75SEd Tanous 2743fe306728SJames Feist auto generateonDemandLogCallback = [asyncResp, 2744fe306728SJames Feist req](const boost::system::error_code 274546229577SJames Feist ec, 2746cb13a392SEd Tanous const std::string&) { 27471da66f75SEd Tanous if (ec) 27481da66f75SEd Tanous { 274946229577SJames Feist if (ec.value() == boost::system::errc::operation_not_supported) 27501da66f75SEd Tanous { 2751f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 27521da66f75SEd Tanous } 27534363d3b2SJason M. Bills else if (ec.value() == 27544363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 27554363d3b2SJason M. Bills { 27564363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 27574363d3b2SJason M. Bills "60"); 27584363d3b2SJason M. Bills } 27591da66f75SEd Tanous else 27601da66f75SEd Tanous { 2761f12894f8SJason M. Bills messages::internalError(asyncResp->res); 27621da66f75SEd Tanous } 27631da66f75SEd Tanous return; 27641da66f75SEd Tanous } 276546229577SJames Feist std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 276666afe4faSJames Feist [](boost::system::error_code err, sdbusplus::message::message&, 276766afe4faSJames Feist const std::shared_ptr<task::TaskData>& taskData) { 276866afe4faSJames Feist if (!err) 276966afe4faSJames Feist { 2770e5d5006bSJames Feist taskData->messages.emplace_back( 2771e5d5006bSJames Feist messages::taskCompletedOK( 2772e5d5006bSJames Feist std::to_string(taskData->index))); 2773831d6b09SJames Feist taskData->state = "Completed"; 277466afe4faSJames Feist } 277532898ceaSJames Feist return task::completed; 277666afe4faSJames Feist }, 277746229577SJames Feist "type='signal',interface='org.freedesktop.DBus.Properties'," 277846229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 277946229577SJames Feist "crashdump'"); 278046229577SJames Feist task->startTimer(std::chrono::minutes(5)); 278146229577SJames Feist task->populateResp(asyncResp->res); 2782fe306728SJames Feist task->payload.emplace(req); 27831da66f75SEd Tanous }; 27841da66f75SEd Tanous crow::connections::systemBus->async_method_call( 27855b61b5e8SJason M. Bills std::move(generateonDemandLogCallback), crashdumpObject, 27865b61b5e8SJason M. Bills crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog"); 27871da66f75SEd Tanous } 27881da66f75SEd Tanous }; 27891da66f75SEd Tanous 27906eda7685SKenny L. Ku class TelemetryCrashdump : public Node 27916eda7685SKenny L. Ku { 27926eda7685SKenny L. Ku public: 279352cc112dSEd Tanous TelemetryCrashdump(App& app) : 27946eda7685SKenny L. Ku Node(app, 27956eda7685SKenny L. Ku "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 27966eda7685SKenny L. Ku "Crashdump.Telemetry/") 27976eda7685SKenny L. Ku { 27986eda7685SKenny L. Ku // Note: Deviated from redfish privilege registry for GET & HEAD 27996eda7685SKenny L. Ku // method for security reasons. 28006eda7685SKenny L. Ku entityPrivileges = { 28016eda7685SKenny L. Ku {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 28026eda7685SKenny L. Ku {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 28036eda7685SKenny L. Ku {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 28046eda7685SKenny L. Ku {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 28056eda7685SKenny L. Ku {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 28066eda7685SKenny L. Ku {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 28076eda7685SKenny L. Ku } 28086eda7685SKenny L. Ku 28096eda7685SKenny L. Ku private: 28106eda7685SKenny L. Ku void doPost(crow::Response& res, const crow::Request& req, 2811cb13a392SEd Tanous const std::vector<std::string>&) override 28126eda7685SKenny L. Ku { 28136eda7685SKenny L. Ku std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 28146eda7685SKenny L. Ku 28156eda7685SKenny L. Ku auto generateTelemetryLogCallback = [asyncResp, req]( 28166eda7685SKenny L. Ku const boost::system::error_code 28176eda7685SKenny L. Ku ec, 2818cb13a392SEd Tanous const std::string&) { 28196eda7685SKenny L. Ku if (ec) 28206eda7685SKenny L. Ku { 28216eda7685SKenny L. Ku if (ec.value() == boost::system::errc::operation_not_supported) 28226eda7685SKenny L. Ku { 28236eda7685SKenny L. Ku messages::resourceInStandby(asyncResp->res); 28246eda7685SKenny L. Ku } 28256eda7685SKenny L. Ku else if (ec.value() == 28266eda7685SKenny L. Ku boost::system::errc::device_or_resource_busy) 28276eda7685SKenny L. Ku { 28286eda7685SKenny L. Ku messages::serviceTemporarilyUnavailable(asyncResp->res, 28296eda7685SKenny L. Ku "60"); 28306eda7685SKenny L. Ku } 28316eda7685SKenny L. Ku else 28326eda7685SKenny L. Ku { 28336eda7685SKenny L. Ku messages::internalError(asyncResp->res); 28346eda7685SKenny L. Ku } 28356eda7685SKenny L. Ku return; 28366eda7685SKenny L. Ku } 28376eda7685SKenny L. Ku std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 28386eda7685SKenny L. Ku [](boost::system::error_code err, sdbusplus::message::message&, 28396eda7685SKenny L. Ku const std::shared_ptr<task::TaskData>& taskData) { 28406eda7685SKenny L. Ku if (!err) 28416eda7685SKenny L. Ku { 28426eda7685SKenny L. Ku taskData->messages.emplace_back( 28436eda7685SKenny L. Ku messages::taskCompletedOK( 28446eda7685SKenny L. Ku std::to_string(taskData->index))); 28456eda7685SKenny L. Ku taskData->state = "Completed"; 28466eda7685SKenny L. Ku } 28476eda7685SKenny L. Ku return task::completed; 28486eda7685SKenny L. Ku }, 28496eda7685SKenny L. Ku "type='signal',interface='org.freedesktop.DBus.Properties'," 28506eda7685SKenny L. Ku "member='PropertiesChanged',arg0namespace='com.intel." 28516eda7685SKenny L. Ku "crashdump'"); 28526eda7685SKenny L. Ku task->startTimer(std::chrono::minutes(5)); 28536eda7685SKenny L. Ku task->populateResp(asyncResp->res); 28546eda7685SKenny L. Ku task->payload.emplace(req); 28556eda7685SKenny L. Ku }; 28566eda7685SKenny L. Ku crow::connections::systemBus->async_method_call( 28576eda7685SKenny L. Ku std::move(generateTelemetryLogCallback), crashdumpObject, 28586eda7685SKenny L. Ku crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog"); 28596eda7685SKenny L. Ku } 28606eda7685SKenny L. Ku }; 28616eda7685SKenny L. Ku 2862e1f26343SJason M. Bills class SendRawPECI : public Node 28631da66f75SEd Tanous { 28641da66f75SEd Tanous public: 286552cc112dSEd Tanous SendRawPECI(App& app) : 2866424c4176SJason M. Bills Node(app, 2867424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2868424c4176SJason M. Bills "Crashdump.SendRawPeci/") 28691da66f75SEd Tanous { 28703946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28713946028dSAppaRao Puli // method for security reasons. 28721da66f75SEd Tanous entityPrivileges = { 28731da66f75SEd Tanous {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 28741da66f75SEd Tanous {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 28751da66f75SEd Tanous {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 28761da66f75SEd Tanous {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 28771da66f75SEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 28781da66f75SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 28791da66f75SEd Tanous } 28801da66f75SEd Tanous 28811da66f75SEd Tanous private: 28821da66f75SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 2883cb13a392SEd Tanous const std::vector<std::string>&) override 28841da66f75SEd Tanous { 2885e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 28868724c297SKarthick Sundarrajan std::vector<std::vector<uint8_t>> peciCommands; 28878724c297SKarthick Sundarrajan 28888724c297SKarthick Sundarrajan if (!json_util::readJson(req, res, "PECICommands", peciCommands)) 28898724c297SKarthick Sundarrajan { 28908724c297SKarthick Sundarrajan return; 28918724c297SKarthick Sundarrajan } 28928724c297SKarthick Sundarrajan uint32_t idx = 0; 28938724c297SKarthick Sundarrajan for (auto const& cmd : peciCommands) 28948724c297SKarthick Sundarrajan { 28958724c297SKarthick Sundarrajan if (cmd.size() < 3) 28968724c297SKarthick Sundarrajan { 28978724c297SKarthick Sundarrajan std::string s("["); 28988724c297SKarthick Sundarrajan for (auto const& val : cmd) 28998724c297SKarthick Sundarrajan { 29008724c297SKarthick Sundarrajan if (val != *cmd.begin()) 29018724c297SKarthick Sundarrajan { 29028724c297SKarthick Sundarrajan s += ","; 29038724c297SKarthick Sundarrajan } 29048724c297SKarthick Sundarrajan s += std::to_string(val); 29058724c297SKarthick Sundarrajan } 29068724c297SKarthick Sundarrajan s += "]"; 29078724c297SKarthick Sundarrajan messages::actionParameterValueFormatError( 29088724c297SKarthick Sundarrajan res, s, "PECICommands[" + std::to_string(idx) + "]", 29098724c297SKarthick Sundarrajan "SendRawPeci"); 29108724c297SKarthick Sundarrajan return; 29118724c297SKarthick Sundarrajan } 29128724c297SKarthick Sundarrajan idx++; 29138724c297SKarthick Sundarrajan } 29141da66f75SEd Tanous // Callback to return the Raw PECI response 2915e1f26343SJason M. Bills auto sendRawPECICallback = 2916e1f26343SJason M. Bills [asyncResp](const boost::system::error_code ec, 29178724c297SKarthick Sundarrajan const std::vector<std::vector<uint8_t>>& resp) { 29181da66f75SEd Tanous if (ec) 29191da66f75SEd Tanous { 29208724c297SKarthick Sundarrajan BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: " 29211da66f75SEd Tanous << ec.message(); 2922f12894f8SJason M. Bills messages::internalError(asyncResp->res); 29231da66f75SEd Tanous return; 29241da66f75SEd Tanous } 2925e1f26343SJason M. Bills asyncResp->res.jsonValue = {{"Name", "PECI Command Response"}, 29261da66f75SEd Tanous {"PECIResponse", resp}}; 29271da66f75SEd Tanous }; 29281da66f75SEd Tanous // Call the SendRawPECI command with the provided data 29291da66f75SEd Tanous crow::connections::systemBus->async_method_call( 29305b61b5e8SJason M. Bills std::move(sendRawPECICallback), crashdumpObject, crashdumpPath, 29318724c297SKarthick Sundarrajan crashdumpRawPECIInterface, "SendRawPeci", peciCommands); 29321da66f75SEd Tanous } 29331da66f75SEd Tanous }; 29341da66f75SEd Tanous 2935cb92c03bSAndrew Geissler /** 2936cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2937cb92c03bSAndrew Geissler */ 2938cb92c03bSAndrew Geissler class DBusLogServiceActionsClear : public Node 2939cb92c03bSAndrew Geissler { 2940cb92c03bSAndrew Geissler public: 294152cc112dSEd Tanous DBusLogServiceActionsClear(App& app) : 2942cb92c03bSAndrew Geissler Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 29437af91514SGunnar Mills "LogService.ClearLog/") 2944cb92c03bSAndrew Geissler { 2945cb92c03bSAndrew Geissler entityPrivileges = { 2946cb92c03bSAndrew Geissler {boost::beast::http::verb::get, {{"Login"}}}, 2947cb92c03bSAndrew Geissler {boost::beast::http::verb::head, {{"Login"}}}, 2948cb92c03bSAndrew Geissler {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2949cb92c03bSAndrew Geissler {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2950cb92c03bSAndrew Geissler {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2951cb92c03bSAndrew Geissler {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2952cb92c03bSAndrew Geissler } 2953cb92c03bSAndrew Geissler 2954cb92c03bSAndrew Geissler private: 2955cb92c03bSAndrew Geissler /** 2956cb92c03bSAndrew Geissler * Function handles POST method request. 2957cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 2958cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 2959cb92c03bSAndrew Geissler */ 2960cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2961cb13a392SEd Tanous const std::vector<std::string>&) override 2962cb92c03bSAndrew Geissler { 2963cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 2964cb92c03bSAndrew Geissler 2965cb92c03bSAndrew Geissler auto asyncResp = std::make_shared<AsyncResp>(res); 2966cb92c03bSAndrew Geissler // Process response from Logging service. 2967cb92c03bSAndrew Geissler auto resp_handler = [asyncResp](const boost::system::error_code ec) { 2968cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 2969cb92c03bSAndrew Geissler if (ec) 2970cb92c03bSAndrew Geissler { 2971cb92c03bSAndrew Geissler // TODO Handle for specific error code 2972cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 2973cb92c03bSAndrew Geissler asyncResp->res.result( 2974cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 2975cb92c03bSAndrew Geissler return; 2976cb92c03bSAndrew Geissler } 2977cb92c03bSAndrew Geissler 2978cb92c03bSAndrew Geissler asyncResp->res.result(boost::beast::http::status::no_content); 2979cb92c03bSAndrew Geissler }; 2980cb92c03bSAndrew Geissler 2981cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 2982cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 2983cb92c03bSAndrew Geissler resp_handler, "xyz.openbmc_project.Logging", 2984cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 2985cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 2986cb92c03bSAndrew Geissler } 2987cb92c03bSAndrew Geissler }; 2988a3316fc6SZhikuiRen 2989a3316fc6SZhikuiRen /**************************************************** 2990a3316fc6SZhikuiRen * Redfish PostCode interfaces 2991a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 2992a3316fc6SZhikuiRen ******************************************************/ 2993a3316fc6SZhikuiRen class PostCodesLogService : public Node 2994a3316fc6SZhikuiRen { 2995a3316fc6SZhikuiRen public: 299652cc112dSEd Tanous PostCodesLogService(App& app) : 2997a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 2998a3316fc6SZhikuiRen { 2999a3316fc6SZhikuiRen entityPrivileges = { 3000a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3001a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3002a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3003a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3004a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3005a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3006a3316fc6SZhikuiRen } 3007a3316fc6SZhikuiRen 3008a3316fc6SZhikuiRen private: 3009cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 3010cb13a392SEd Tanous const std::vector<std::string>&) override 3011a3316fc6SZhikuiRen { 3012a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3013a3316fc6SZhikuiRen 3014a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 3015a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"}, 3016a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 3017a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogService.LogService"}, 3018a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 3019a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 3020a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 3021a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 3022a3316fc6SZhikuiRen {"Entries", 3023a3316fc6SZhikuiRen {{"@odata.id", 3024a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}}; 3025a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 3026a3316fc6SZhikuiRen {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/" 3027a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 3028a3316fc6SZhikuiRen } 3029a3316fc6SZhikuiRen }; 3030a3316fc6SZhikuiRen 3031a3316fc6SZhikuiRen class PostCodesClear : public Node 3032a3316fc6SZhikuiRen { 3033a3316fc6SZhikuiRen public: 303452cc112dSEd Tanous PostCodesClear(App& app) : 3035a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 3036a3316fc6SZhikuiRen "LogService.ClearLog/") 3037a3316fc6SZhikuiRen { 3038a3316fc6SZhikuiRen entityPrivileges = { 3039a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3040a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 30413946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 30423946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 30433946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 30443946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 3045a3316fc6SZhikuiRen } 3046a3316fc6SZhikuiRen 3047a3316fc6SZhikuiRen private: 3048cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 3049cb13a392SEd Tanous const std::vector<std::string>&) override 3050a3316fc6SZhikuiRen { 3051a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3052a3316fc6SZhikuiRen 3053a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3054a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3055a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3056a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3057a3316fc6SZhikuiRen if (ec) 3058a3316fc6SZhikuiRen { 3059a3316fc6SZhikuiRen // TODO Handle for specific error code 3060a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 3061a3316fc6SZhikuiRen << "doClearPostCodes resp_handler got error " << ec; 3062a3316fc6SZhikuiRen asyncResp->res.result( 3063a3316fc6SZhikuiRen boost::beast::http::status::internal_server_error); 3064a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3065a3316fc6SZhikuiRen return; 3066a3316fc6SZhikuiRen } 3067a3316fc6SZhikuiRen }, 3068a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3069a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3070a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 3071a3316fc6SZhikuiRen } 3072a3316fc6SZhikuiRen }; 3073a3316fc6SZhikuiRen 3074a3316fc6SZhikuiRen static void fillPostCodeEntry( 3075a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> aResp, 3076a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode, 3077a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3078a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3079a3316fc6SZhikuiRen { 3080a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3081a3316fc6SZhikuiRen const message_registries::Message* message = 3082a3316fc6SZhikuiRen message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode"); 3083a3316fc6SZhikuiRen 3084a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3085a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 3086a3316fc6SZhikuiRen 3087a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 3088a3316fc6SZhikuiRen for (const std::pair<uint64_t, uint64_t>& code : postcode) 3089a3316fc6SZhikuiRen { 3090a3316fc6SZhikuiRen currentCodeIndex++; 3091a3316fc6SZhikuiRen std::string postcodeEntryID = 3092a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3093a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3094a3316fc6SZhikuiRen 3095a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3096a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3097a3316fc6SZhikuiRen 3098a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3099a3316fc6SZhikuiRen { // already incremented 3100a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3101a3316fc6SZhikuiRen } 3102a3316fc6SZhikuiRen else 3103a3316fc6SZhikuiRen { 3104a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3105a3316fc6SZhikuiRen } 3106a3316fc6SZhikuiRen 3107a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3108a3316fc6SZhikuiRen // not fall between top and skip 3109a3316fc6SZhikuiRen if ((codeIndex == 0) && 3110a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3111a3316fc6SZhikuiRen { 3112a3316fc6SZhikuiRen continue; 3113a3316fc6SZhikuiRen } 3114a3316fc6SZhikuiRen 31154e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3116a3316fc6SZhikuiRen // currentIndex 3117a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3118a3316fc6SZhikuiRen { 3119a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3120a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3121a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3122a3316fc6SZhikuiRen continue; 3123a3316fc6SZhikuiRen } 3124a3316fc6SZhikuiRen 3125a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3126a3316fc6SZhikuiRen // index 3127a3316fc6SZhikuiRen 3128a3316fc6SZhikuiRen // Get the Created time from the timestamp 3129a3316fc6SZhikuiRen std::string entryTimeStr; 31309c620e21SAsmitha Karunanithi entryTimeStr = crow::utility::getDateTime( 31319c620e21SAsmitha Karunanithi static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000)); 3132a3316fc6SZhikuiRen 3133a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3134a3316fc6SZhikuiRen std::ostringstream hexCode; 3135a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 3136a3316fc6SZhikuiRen << code.second; 3137a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3138a3316fc6SZhikuiRen // Set Fixed -Point Notation 3139a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3140a3316fc6SZhikuiRen // Set precision to 4 digits 3141a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3142a3316fc6SZhikuiRen // Add double to stream 3143a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3144a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3145a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3146a3316fc6SZhikuiRen 3147a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3148a3316fc6SZhikuiRen std::string msg; 3149a3316fc6SZhikuiRen if (message != nullptr) 3150a3316fc6SZhikuiRen { 3151a3316fc6SZhikuiRen msg = message->message; 3152a3316fc6SZhikuiRen 3153a3316fc6SZhikuiRen // fill in this post code value 3154a3316fc6SZhikuiRen int i = 0; 3155a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3156a3316fc6SZhikuiRen { 3157a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3158a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3159a3316fc6SZhikuiRen if (argPos != std::string::npos) 3160a3316fc6SZhikuiRen { 3161a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3162a3316fc6SZhikuiRen } 3163a3316fc6SZhikuiRen } 3164a3316fc6SZhikuiRen } 3165a3316fc6SZhikuiRen 3166d4342a92STim Lee // Get Severity template from message registry 3167d4342a92STim Lee std::string severity; 3168d4342a92STim Lee if (message != nullptr) 3169d4342a92STim Lee { 3170d4342a92STim Lee severity = message->severity; 3171d4342a92STim Lee } 3172d4342a92STim Lee 3173a3316fc6SZhikuiRen // add to AsyncResp 3174a3316fc6SZhikuiRen logEntryArray.push_back({}); 3175a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 3176a3316fc6SZhikuiRen bmcLogEntry = { 3177a3316fc6SZhikuiRen {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 3178a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, 3179a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 3180a3316fc6SZhikuiRen "PostCodes/Entries/" + 3181a3316fc6SZhikuiRen postcodeEntryID}, 3182a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 3183a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 3184a3316fc6SZhikuiRen {"Message", std::move(msg)}, 3185a3316fc6SZhikuiRen {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"}, 3186a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 3187a3316fc6SZhikuiRen {"EntryType", "Event"}, 3188a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 31899c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 3190a3316fc6SZhikuiRen } 3191a3316fc6SZhikuiRen } 3192a3316fc6SZhikuiRen 3193a3316fc6SZhikuiRen static void getPostCodeForEntry(std::shared_ptr<AsyncResp> aResp, 3194a3316fc6SZhikuiRen const uint16_t bootIndex, 3195a3316fc6SZhikuiRen const uint64_t codeIndex) 3196a3316fc6SZhikuiRen { 3197a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3198a3316fc6SZhikuiRen [aResp, bootIndex, codeIndex]( 3199a3316fc6SZhikuiRen const boost::system::error_code ec, 3200a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode) { 3201a3316fc6SZhikuiRen if (ec) 3202a3316fc6SZhikuiRen { 3203a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3204a3316fc6SZhikuiRen messages::internalError(aResp->res); 3205a3316fc6SZhikuiRen return; 3206a3316fc6SZhikuiRen } 3207a3316fc6SZhikuiRen 3208a3316fc6SZhikuiRen // skip the empty postcode boots 3209a3316fc6SZhikuiRen if (postcode.empty()) 3210a3316fc6SZhikuiRen { 3211a3316fc6SZhikuiRen return; 3212a3316fc6SZhikuiRen } 3213a3316fc6SZhikuiRen 3214a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3215a3316fc6SZhikuiRen 3216a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3217a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3218a3316fc6SZhikuiRen }, 3219a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3220a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3221a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3222a3316fc6SZhikuiRen bootIndex); 3223a3316fc6SZhikuiRen } 3224a3316fc6SZhikuiRen 3225a3316fc6SZhikuiRen static void getPostCodeForBoot(std::shared_ptr<AsyncResp> aResp, 3226a3316fc6SZhikuiRen const uint16_t bootIndex, 3227a3316fc6SZhikuiRen const uint16_t bootCount, 3228a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 3229a3316fc6SZhikuiRen const uint64_t top) 3230a3316fc6SZhikuiRen { 3231a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3232a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3233a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3234a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode) { 3235a3316fc6SZhikuiRen if (ec) 3236a3316fc6SZhikuiRen { 3237a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3238a3316fc6SZhikuiRen messages::internalError(aResp->res); 3239a3316fc6SZhikuiRen return; 3240a3316fc6SZhikuiRen } 3241a3316fc6SZhikuiRen 3242a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3243a3316fc6SZhikuiRen if (!postcode.empty()) 3244a3316fc6SZhikuiRen { 3245a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 3246a3316fc6SZhikuiRen 3247a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3248a3316fc6SZhikuiRen { 3249a3316fc6SZhikuiRen uint64_t thisBootSkip = 3250a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3251a3316fc6SZhikuiRen uint64_t thisBootTop = 3252a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3253a3316fc6SZhikuiRen 3254a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3255a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3256a3316fc6SZhikuiRen } 3257a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3258a3316fc6SZhikuiRen } 3259a3316fc6SZhikuiRen 3260a3316fc6SZhikuiRen // continue to previous bootIndex 3261a3316fc6SZhikuiRen if (bootIndex < bootCount) 3262a3316fc6SZhikuiRen { 3263a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3264a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3265a3316fc6SZhikuiRen } 3266a3316fc6SZhikuiRen else 3267a3316fc6SZhikuiRen { 3268a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 3269a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3270a3316fc6SZhikuiRen "Entries?$skip=" + 3271a3316fc6SZhikuiRen std::to_string(skip + top); 3272a3316fc6SZhikuiRen } 3273a3316fc6SZhikuiRen }, 3274a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3275a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3276a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3277a3316fc6SZhikuiRen bootIndex); 3278a3316fc6SZhikuiRen } 3279a3316fc6SZhikuiRen 3280a3316fc6SZhikuiRen static void getCurrentBootNumber(std::shared_ptr<AsyncResp> aResp, 3281a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3282a3316fc6SZhikuiRen { 3283a3316fc6SZhikuiRen uint64_t entryCount = 0; 3284a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3285a3316fc6SZhikuiRen [aResp, entryCount, skip, 3286a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3287a3316fc6SZhikuiRen const std::variant<uint16_t>& bootCount) { 3288a3316fc6SZhikuiRen if (ec) 3289a3316fc6SZhikuiRen { 3290a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3291a3316fc6SZhikuiRen messages::internalError(aResp->res); 3292a3316fc6SZhikuiRen return; 3293a3316fc6SZhikuiRen } 3294a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 3295a3316fc6SZhikuiRen if (pVal) 3296a3316fc6SZhikuiRen { 3297a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 3298a3316fc6SZhikuiRen } 3299a3316fc6SZhikuiRen else 3300a3316fc6SZhikuiRen { 3301a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 3302a3316fc6SZhikuiRen } 3303a3316fc6SZhikuiRen }, 3304a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3305a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3306a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 3307a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 3308a3316fc6SZhikuiRen } 3309a3316fc6SZhikuiRen 3310a3316fc6SZhikuiRen class PostCodesEntryCollection : public Node 3311a3316fc6SZhikuiRen { 3312a3316fc6SZhikuiRen public: 331352cc112dSEd Tanous PostCodesEntryCollection(App& app) : 3314a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3315a3316fc6SZhikuiRen { 3316a3316fc6SZhikuiRen entityPrivileges = { 3317a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3318a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3319a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3320a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3321a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3322a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3323a3316fc6SZhikuiRen } 3324a3316fc6SZhikuiRen 3325a3316fc6SZhikuiRen private: 3326a3316fc6SZhikuiRen void doGet(crow::Response& res, const crow::Request& req, 3327cb13a392SEd Tanous const std::vector<std::string>&) override 3328a3316fc6SZhikuiRen { 3329a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3330a3316fc6SZhikuiRen 3331a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3332a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3333a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 3334a3316fc6SZhikuiRen "/redfish/v1/" 3335a3316fc6SZhikuiRen "$metadata#LogEntryCollection.LogEntryCollection"; 3336a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3337a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3338a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3339a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3340a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3341a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3342a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3343a3316fc6SZhikuiRen 3344a3316fc6SZhikuiRen uint64_t skip = 0; 3345a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 3346a3316fc6SZhikuiRen if (!getSkipParam(asyncResp->res, req, skip)) 3347a3316fc6SZhikuiRen { 3348a3316fc6SZhikuiRen return; 3349a3316fc6SZhikuiRen } 3350a3316fc6SZhikuiRen if (!getTopParam(asyncResp->res, req, top)) 3351a3316fc6SZhikuiRen { 3352a3316fc6SZhikuiRen return; 3353a3316fc6SZhikuiRen } 3354a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 3355a3316fc6SZhikuiRen } 3356a3316fc6SZhikuiRen }; 3357a3316fc6SZhikuiRen 3358a3316fc6SZhikuiRen class PostCodesEntry : public Node 3359a3316fc6SZhikuiRen { 3360a3316fc6SZhikuiRen public: 336152cc112dSEd Tanous PostCodesEntry(App& app) : 3362a3316fc6SZhikuiRen Node(app, 3363a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/", 3364a3316fc6SZhikuiRen std::string()) 3365a3316fc6SZhikuiRen { 3366a3316fc6SZhikuiRen entityPrivileges = { 3367a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3368a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3369a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3370a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3371a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3372a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3373a3316fc6SZhikuiRen } 3374a3316fc6SZhikuiRen 3375a3316fc6SZhikuiRen private: 3376cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 3377a3316fc6SZhikuiRen const std::vector<std::string>& params) override 3378a3316fc6SZhikuiRen { 3379a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3380a3316fc6SZhikuiRen if (params.size() != 1) 3381a3316fc6SZhikuiRen { 3382a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3383a3316fc6SZhikuiRen return; 3384a3316fc6SZhikuiRen } 3385a3316fc6SZhikuiRen 3386a3316fc6SZhikuiRen const std::string& targetID = params[0]; 3387a3316fc6SZhikuiRen 3388a3316fc6SZhikuiRen size_t bootPos = targetID.find('B'); 3389a3316fc6SZhikuiRen if (bootPos == std::string::npos) 3390a3316fc6SZhikuiRen { 3391a3316fc6SZhikuiRen // Requested ID was not found 3392a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 3393a3316fc6SZhikuiRen return; 3394a3316fc6SZhikuiRen } 3395a3316fc6SZhikuiRen std::string_view bootIndexStr(targetID); 3396a3316fc6SZhikuiRen bootIndexStr.remove_prefix(bootPos + 1); 3397a3316fc6SZhikuiRen uint16_t bootIndex = 0; 3398a3316fc6SZhikuiRen uint64_t codeIndex = 0; 3399a3316fc6SZhikuiRen size_t dashPos = bootIndexStr.find('-'); 3400a3316fc6SZhikuiRen 3401a3316fc6SZhikuiRen if (dashPos == std::string::npos) 3402a3316fc6SZhikuiRen { 3403a3316fc6SZhikuiRen return; 3404a3316fc6SZhikuiRen } 3405a3316fc6SZhikuiRen std::string_view codeIndexStr(bootIndexStr); 3406a3316fc6SZhikuiRen bootIndexStr.remove_suffix(dashPos); 3407a3316fc6SZhikuiRen codeIndexStr.remove_prefix(dashPos + 1); 3408a3316fc6SZhikuiRen 3409a3316fc6SZhikuiRen bootIndex = static_cast<uint16_t>( 341023a21a1cSEd Tanous strtoul(std::string(bootIndexStr).c_str(), nullptr, 0)); 341123a21a1cSEd Tanous codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0); 3412a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3413a3316fc6SZhikuiRen { 3414a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 3415a3316fc6SZhikuiRen << params[0]; 3416a3316fc6SZhikuiRen } 3417a3316fc6SZhikuiRen 3418a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 3419a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 3420a3316fc6SZhikuiRen "/redfish/v1/$metadata#LogEntry.LogEntry"; 3421a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3422a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3423a3316fc6SZhikuiRen "Entries"; 3424a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3425a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3426a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3427a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3428a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3429a3316fc6SZhikuiRen 3430a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 3431a3316fc6SZhikuiRen } 3432a3316fc6SZhikuiRen }; 3433a3316fc6SZhikuiRen 34341da66f75SEd Tanous } // namespace redfish 3435