11da66f75SEd Tanous /* 21da66f75SEd Tanous // Copyright (c) 2018 Intel Corporation 31da66f75SEd Tanous // 41da66f75SEd Tanous // Licensed under the Apache License, Version 2.0 (the "License"); 51da66f75SEd Tanous // you may not use this file except in compliance with the License. 61da66f75SEd Tanous // You may obtain a copy of the License at 71da66f75SEd Tanous // 81da66f75SEd Tanous // http://www.apache.org/licenses/LICENSE-2.0 91da66f75SEd Tanous // 101da66f75SEd Tanous // Unless required by applicable law or agreed to in writing, software 111da66f75SEd Tanous // distributed under the License is distributed on an "AS IS" BASIS, 121da66f75SEd Tanous // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131da66f75SEd Tanous // See the License for the specific language governing permissions and 141da66f75SEd Tanous // limitations under the License. 151da66f75SEd Tanous */ 161da66f75SEd Tanous #pragma once 171da66f75SEd Tanous 181da66f75SEd Tanous #include "node.hpp" 194851d45dSJason M. Bills #include "registries.hpp" 204851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 214851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2246229577SJames Feist #include "task.hpp" 231da66f75SEd Tanous 24e1f26343SJason M. Bills #include <systemd/sd-journal.h> 25e1f26343SJason M. Bills 264851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 274851d45dSJason M. Bills #include <boost/beast/core/span.hpp> 281da66f75SEd Tanous #include <boost/container/flat_map.hpp> 291ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 300657843aSraviteja-b #include <dump_offload.hpp> 31cb92c03bSAndrew Geissler #include <error_messages.hpp> 321214b7e7SGunnar Mills 334418c7f0SJames Feist #include <filesystem> 34cd225da8SJason M. Bills #include <string_view> 35abf2add6SEd Tanous #include <variant> 361da66f75SEd Tanous 371da66f75SEd Tanous namespace redfish 381da66f75SEd Tanous { 391da66f75SEd Tanous 405b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 415b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 425b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 435b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 445b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 455b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 46424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 475b61b5e8SJason M. Bills constexpr char const* crashdumpRawPECIInterface = 48424c4176SJason M. Bills "com.intel.crashdump.SendRawPeci"; 496eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 506eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 511da66f75SEd Tanous 524851d45dSJason M. Bills namespace message_registries 534851d45dSJason M. Bills { 544851d45dSJason M. Bills static const Message* getMessageFromRegistry( 554851d45dSJason M. Bills const std::string& messageKey, 564851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 574851d45dSJason M. Bills { 584851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 594851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 604851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 614851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 624851d45dSJason M. Bills messageKey.c_str()); 634851d45dSJason M. Bills }); 644851d45dSJason M. Bills if (messageIt != registry.cend()) 654851d45dSJason M. Bills { 664851d45dSJason M. Bills return &messageIt->second; 674851d45dSJason M. Bills } 684851d45dSJason M. Bills 694851d45dSJason M. Bills return nullptr; 704851d45dSJason M. Bills } 714851d45dSJason M. Bills 724851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 734851d45dSJason M. Bills { 744851d45dSJason M. Bills // Redfish MessageIds are in the form 754851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 764851d45dSJason M. Bills // the right Message 774851d45dSJason M. Bills std::vector<std::string> fields; 784851d45dSJason M. Bills fields.reserve(4); 794851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 804851d45dSJason M. Bills std::string& registryName = fields[0]; 814851d45dSJason M. Bills std::string& messageKey = fields[3]; 824851d45dSJason M. Bills 834851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 844851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 854851d45dSJason M. Bills { 864851d45dSJason M. Bills return getMessageFromRegistry( 874851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 884851d45dSJason M. Bills } 894851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 904851d45dSJason M. Bills { 914851d45dSJason M. Bills return getMessageFromRegistry( 924851d45dSJason M. Bills messageKey, 934851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 944851d45dSJason M. Bills } 954851d45dSJason M. Bills return nullptr; 964851d45dSJason M. Bills } 974851d45dSJason M. Bills } // namespace message_registries 984851d45dSJason M. Bills 99f6150403SJames Feist namespace fs = std::filesystem; 1001da66f75SEd Tanous 101cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 10219bd78d9SPatrick Williams std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, 103cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 104cb92c03bSAndrew Geissler 105cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 106cb92c03bSAndrew Geissler sdbusplus::message::object_path, 107cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 108cb92c03bSAndrew Geissler 109cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 110cb92c03bSAndrew Geissler { 111cb92c03bSAndrew Geissler if (s == "xyz.openbmc_project.Logging.Entry.Level.Alert") 112cb92c03bSAndrew Geissler { 113cb92c03bSAndrew Geissler return "Critical"; 114cb92c03bSAndrew Geissler } 115cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") 116cb92c03bSAndrew Geissler { 117cb92c03bSAndrew Geissler return "Critical"; 118cb92c03bSAndrew Geissler } 119cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Debug") 120cb92c03bSAndrew Geissler { 121cb92c03bSAndrew Geissler return "OK"; 122cb92c03bSAndrew Geissler } 123cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") 124cb92c03bSAndrew Geissler { 125cb92c03bSAndrew Geissler return "Critical"; 126cb92c03bSAndrew Geissler } 127cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Error") 128cb92c03bSAndrew Geissler { 129cb92c03bSAndrew Geissler return "Critical"; 130cb92c03bSAndrew Geissler } 131cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") 132cb92c03bSAndrew Geissler { 133cb92c03bSAndrew Geissler return "OK"; 134cb92c03bSAndrew Geissler } 135cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Notice") 136cb92c03bSAndrew Geissler { 137cb92c03bSAndrew Geissler return "OK"; 138cb92c03bSAndrew Geissler } 139cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 140cb92c03bSAndrew Geissler { 141cb92c03bSAndrew Geissler return "Warning"; 142cb92c03bSAndrew Geissler } 143cb92c03bSAndrew Geissler return ""; 144cb92c03bSAndrew Geissler } 145cb92c03bSAndrew Geissler 14616428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal, 14739e77504SEd Tanous const std::string_view& field, 14839e77504SEd Tanous std::string_view& contents) 14916428a1aSJason M. Bills { 15016428a1aSJason M. Bills const char* data = nullptr; 15116428a1aSJason M. Bills size_t length = 0; 15216428a1aSJason M. Bills int ret = 0; 15316428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 154271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 155271584abSEd Tanous reinterpret_cast<const void**>(&data), &length); 15616428a1aSJason M. Bills if (ret < 0) 15716428a1aSJason M. Bills { 15816428a1aSJason M. Bills return ret; 15916428a1aSJason M. Bills } 16039e77504SEd Tanous contents = std::string_view(data, length); 16116428a1aSJason M. Bills // Only use the content after the "=" character. 16216428a1aSJason M. Bills contents.remove_prefix(std::min(contents.find("=") + 1, contents.size())); 16316428a1aSJason M. Bills return ret; 16416428a1aSJason M. Bills } 16516428a1aSJason M. Bills 16616428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal, 16739e77504SEd Tanous const std::string_view& field, const int& base, 168271584abSEd Tanous long int& contents) 16916428a1aSJason M. Bills { 17016428a1aSJason M. Bills int ret = 0; 17139e77504SEd Tanous std::string_view metadata; 17216428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 17316428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 17416428a1aSJason M. Bills if (ret < 0) 17516428a1aSJason M. Bills { 17616428a1aSJason M. Bills return ret; 17716428a1aSJason M. Bills } 178b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 17916428a1aSJason M. Bills return ret; 18016428a1aSJason M. Bills } 18116428a1aSJason M. Bills 182a3316fc6SZhikuiRen static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp) 183a3316fc6SZhikuiRen { 184a3316fc6SZhikuiRen int ret = 0; 185a3316fc6SZhikuiRen uint64_t timestamp = 0; 186a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 187a3316fc6SZhikuiRen if (ret < 0) 188a3316fc6SZhikuiRen { 189a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 190a3316fc6SZhikuiRen << strerror(-ret); 191a3316fc6SZhikuiRen return false; 192a3316fc6SZhikuiRen } 1939c620e21SAsmitha Karunanithi entryTimestamp = crow::utility::getDateTime( 1949c620e21SAsmitha Karunanithi static_cast<std::time_t>(timestamp / 1000 / 1000)); 1959c620e21SAsmitha Karunanithi return true; 196a3316fc6SZhikuiRen } 197a3316fc6SZhikuiRen 19816428a1aSJason M. Bills static bool getSkipParam(crow::Response& res, const crow::Request& req, 199271584abSEd Tanous uint64_t& skip) 20016428a1aSJason M. Bills { 20116428a1aSJason M. Bills char* skipParam = req.urlParams.get("$skip"); 20216428a1aSJason M. Bills if (skipParam != nullptr) 20316428a1aSJason M. Bills { 20416428a1aSJason M. Bills char* ptr = nullptr; 205271584abSEd Tanous skip = std::strtoul(skipParam, &ptr, 10); 20616428a1aSJason M. Bills if (*skipParam == '\0' || *ptr != '\0') 20716428a1aSJason M. Bills { 20816428a1aSJason M. Bills 20916428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(skipParam), 21016428a1aSJason M. Bills "$skip"); 21116428a1aSJason M. Bills return false; 21216428a1aSJason M. Bills } 21316428a1aSJason M. Bills } 21416428a1aSJason M. Bills return true; 21516428a1aSJason M. Bills } 21616428a1aSJason M. Bills 217271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 21816428a1aSJason M. Bills static bool getTopParam(crow::Response& res, const crow::Request& req, 219271584abSEd Tanous uint64_t& top) 22016428a1aSJason M. Bills { 22116428a1aSJason M. Bills char* topParam = req.urlParams.get("$top"); 22216428a1aSJason M. Bills if (topParam != nullptr) 22316428a1aSJason M. Bills { 22416428a1aSJason M. Bills char* ptr = nullptr; 225271584abSEd Tanous top = std::strtoul(topParam, &ptr, 10); 22616428a1aSJason M. Bills if (*topParam == '\0' || *ptr != '\0') 22716428a1aSJason M. Bills { 22816428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(topParam), 22916428a1aSJason M. Bills "$top"); 23016428a1aSJason M. Bills return false; 23116428a1aSJason M. Bills } 232271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 23316428a1aSJason M. Bills { 23416428a1aSJason M. Bills 23516428a1aSJason M. Bills messages::queryParameterOutOfRange( 23616428a1aSJason M. Bills res, std::to_string(top), "$top", 23716428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 23816428a1aSJason M. Bills return false; 23916428a1aSJason M. Bills } 24016428a1aSJason M. Bills } 24116428a1aSJason M. Bills return true; 24216428a1aSJason M. Bills } 24316428a1aSJason M. Bills 244e85d6b16SJason M. Bills static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 245e85d6b16SJason M. Bills const bool firstEntry = true) 24616428a1aSJason M. Bills { 24716428a1aSJason M. Bills int ret = 0; 24816428a1aSJason M. Bills static uint64_t prevTs = 0; 24916428a1aSJason M. Bills static int index = 0; 250e85d6b16SJason M. Bills if (firstEntry) 251e85d6b16SJason M. Bills { 252e85d6b16SJason M. Bills prevTs = 0; 253e85d6b16SJason M. Bills } 254e85d6b16SJason M. Bills 25516428a1aSJason M. Bills // Get the entry timestamp 25616428a1aSJason M. Bills uint64_t curTs = 0; 25716428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 25816428a1aSJason M. Bills if (ret < 0) 25916428a1aSJason M. Bills { 26016428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 26116428a1aSJason M. Bills << strerror(-ret); 26216428a1aSJason M. Bills return false; 26316428a1aSJason M. Bills } 26416428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 26516428a1aSJason M. Bills if (curTs == prevTs) 26616428a1aSJason M. Bills { 26716428a1aSJason M. Bills index++; 26816428a1aSJason M. Bills } 26916428a1aSJason M. Bills else 27016428a1aSJason M. Bills { 27116428a1aSJason M. Bills // Otherwise, reset it 27216428a1aSJason M. Bills index = 0; 27316428a1aSJason M. Bills } 27416428a1aSJason M. Bills // Save the timestamp 27516428a1aSJason M. Bills prevTs = curTs; 27616428a1aSJason M. Bills 27716428a1aSJason M. Bills entryID = std::to_string(curTs); 27816428a1aSJason M. Bills if (index > 0) 27916428a1aSJason M. Bills { 28016428a1aSJason M. Bills entryID += "_" + std::to_string(index); 28116428a1aSJason M. Bills } 28216428a1aSJason M. Bills return true; 28316428a1aSJason M. Bills } 28416428a1aSJason M. Bills 285e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 286e85d6b16SJason M. Bills const bool firstEntry = true) 28795820184SJason M. Bills { 288271584abSEd Tanous static time_t prevTs = 0; 28995820184SJason M. Bills static int index = 0; 290e85d6b16SJason M. Bills if (firstEntry) 291e85d6b16SJason M. Bills { 292e85d6b16SJason M. Bills prevTs = 0; 293e85d6b16SJason M. Bills } 294e85d6b16SJason M. Bills 29595820184SJason M. Bills // Get the entry timestamp 296271584abSEd Tanous std::time_t curTs = 0; 29795820184SJason M. Bills std::tm timeStruct = {}; 29895820184SJason M. Bills std::istringstream entryStream(logEntry); 29995820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 30095820184SJason M. Bills { 30195820184SJason M. Bills curTs = std::mktime(&timeStruct); 30295820184SJason M. Bills } 30395820184SJason M. Bills // If the timestamp isn't unique, increment the index 30495820184SJason M. Bills if (curTs == prevTs) 30595820184SJason M. Bills { 30695820184SJason M. Bills index++; 30795820184SJason M. Bills } 30895820184SJason M. Bills else 30995820184SJason M. Bills { 31095820184SJason M. Bills // Otherwise, reset it 31195820184SJason M. Bills index = 0; 31295820184SJason M. Bills } 31395820184SJason M. Bills // Save the timestamp 31495820184SJason M. Bills prevTs = curTs; 31595820184SJason M. Bills 31695820184SJason M. Bills entryID = std::to_string(curTs); 31795820184SJason M. Bills if (index > 0) 31895820184SJason M. Bills { 31995820184SJason M. Bills entryID += "_" + std::to_string(index); 32095820184SJason M. Bills } 32195820184SJason M. Bills return true; 32295820184SJason M. Bills } 32395820184SJason M. Bills 32416428a1aSJason M. Bills static bool getTimestampFromID(crow::Response& res, const std::string& entryID, 325271584abSEd Tanous uint64_t& timestamp, uint64_t& index) 32616428a1aSJason M. Bills { 32716428a1aSJason M. Bills if (entryID.empty()) 32816428a1aSJason M. Bills { 32916428a1aSJason M. Bills return false; 33016428a1aSJason M. Bills } 33116428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 33239e77504SEd Tanous std::string_view tsStr(entryID); 33316428a1aSJason M. Bills 33416428a1aSJason M. Bills auto underscorePos = tsStr.find("_"); 33516428a1aSJason M. Bills if (underscorePos != tsStr.npos) 33616428a1aSJason M. Bills { 33716428a1aSJason M. Bills // Timestamp has an index 33816428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 33939e77504SEd Tanous std::string_view indexStr(entryID); 34016428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 34116428a1aSJason M. Bills std::size_t pos; 34216428a1aSJason M. Bills try 34316428a1aSJason M. Bills { 34439e77504SEd Tanous index = std::stoul(std::string(indexStr), &pos); 34516428a1aSJason M. Bills } 346271584abSEd Tanous catch (std::invalid_argument&) 34716428a1aSJason M. Bills { 34816428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 34916428a1aSJason M. Bills return false; 35016428a1aSJason M. Bills } 351271584abSEd Tanous catch (std::out_of_range&) 35216428a1aSJason M. Bills { 35316428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 35416428a1aSJason M. Bills return false; 35516428a1aSJason M. Bills } 35616428a1aSJason M. Bills if (pos != indexStr.size()) 35716428a1aSJason M. Bills { 35816428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 35916428a1aSJason M. Bills return false; 36016428a1aSJason M. Bills } 36116428a1aSJason M. Bills } 36216428a1aSJason M. Bills // Timestamp has no index 36316428a1aSJason M. Bills std::size_t pos; 36416428a1aSJason M. Bills try 36516428a1aSJason M. Bills { 36639e77504SEd Tanous timestamp = std::stoull(std::string(tsStr), &pos); 36716428a1aSJason M. Bills } 368271584abSEd Tanous catch (std::invalid_argument&) 36916428a1aSJason M. Bills { 37016428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 37116428a1aSJason M. Bills return false; 37216428a1aSJason M. Bills } 373271584abSEd Tanous catch (std::out_of_range&) 37416428a1aSJason M. Bills { 37516428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 37616428a1aSJason M. Bills return false; 37716428a1aSJason M. Bills } 37816428a1aSJason M. Bills if (pos != tsStr.size()) 37916428a1aSJason M. Bills { 38016428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 38116428a1aSJason M. Bills return false; 38216428a1aSJason M. Bills } 38316428a1aSJason M. Bills return true; 38416428a1aSJason M. Bills } 38516428a1aSJason M. Bills 38695820184SJason M. Bills static bool 38795820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 38895820184SJason M. Bills { 38995820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 39095820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 39195820184SJason M. Bills 39295820184SJason M. Bills // Loop through the directory looking for redfish log files 39395820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 39495820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 39595820184SJason M. Bills { 39695820184SJason M. Bills // If we find a redfish log file, save the path 39795820184SJason M. Bills std::string filename = dirEnt.path().filename(); 39895820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 39995820184SJason M. Bills { 40095820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 40195820184SJason M. Bills } 40295820184SJason M. Bills } 40395820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 40495820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 40595820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 40695820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 40795820184SJason M. Bills 40895820184SJason M. Bills return !redfishLogFiles.empty(); 40995820184SJason M. Bills } 41095820184SJason M. Bills 4115cb1dd27SAsmitha Karunanithi inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp, 4125cb1dd27SAsmitha Karunanithi const std::string& dumpType) 4135cb1dd27SAsmitha Karunanithi { 4145cb1dd27SAsmitha Karunanithi std::string dumpPath; 4155cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 4165cb1dd27SAsmitha Karunanithi { 4175cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 4185cb1dd27SAsmitha Karunanithi } 4195cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 4205cb1dd27SAsmitha Karunanithi { 4215cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 4225cb1dd27SAsmitha Karunanithi } 4235cb1dd27SAsmitha Karunanithi else 4245cb1dd27SAsmitha Karunanithi { 4255cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 4265cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4275cb1dd27SAsmitha Karunanithi return; 4285cb1dd27SAsmitha Karunanithi } 4295cb1dd27SAsmitha Karunanithi 4305cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 4315cb1dd27SAsmitha Karunanithi [asyncResp, dumpPath, dumpType](const boost::system::error_code ec, 4325cb1dd27SAsmitha Karunanithi GetManagedObjectsType& resp) { 4335cb1dd27SAsmitha Karunanithi if (ec) 4345cb1dd27SAsmitha Karunanithi { 4355cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4365cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4375cb1dd27SAsmitha Karunanithi return; 4385cb1dd27SAsmitha Karunanithi } 4395cb1dd27SAsmitha Karunanithi 4405cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4415cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 4425cb1dd27SAsmitha Karunanithi 4435cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4445cb1dd27SAsmitha Karunanithi { 4455cb1dd27SAsmitha Karunanithi bool foundDumpEntry = false; 4465cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4475cb1dd27SAsmitha Karunanithi { 4485cb1dd27SAsmitha Karunanithi if (interfaceMap.first == 4495cb1dd27SAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 4505cb1dd27SAsmitha Karunanithi { 4515cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 4525cb1dd27SAsmitha Karunanithi break; 4535cb1dd27SAsmitha Karunanithi } 4545cb1dd27SAsmitha Karunanithi } 4555cb1dd27SAsmitha Karunanithi 4565cb1dd27SAsmitha Karunanithi if (foundDumpEntry == false) 4575cb1dd27SAsmitha Karunanithi { 4585cb1dd27SAsmitha Karunanithi continue; 4595cb1dd27SAsmitha Karunanithi } 4605cb1dd27SAsmitha Karunanithi std::time_t timestamp; 4615cb1dd27SAsmitha Karunanithi uint64_t size = 0; 4625cb1dd27SAsmitha Karunanithi entriesArray.push_back({}); 4635cb1dd27SAsmitha Karunanithi nlohmann::json& thisEntry = entriesArray.back(); 4645cb1dd27SAsmitha Karunanithi const std::string& path = 4655cb1dd27SAsmitha Karunanithi static_cast<const std::string&>(object.first); 4665cb1dd27SAsmitha Karunanithi std::size_t lastPos = path.rfind("/"); 4675cb1dd27SAsmitha Karunanithi if (lastPos == std::string::npos) 4685cb1dd27SAsmitha Karunanithi { 4695cb1dd27SAsmitha Karunanithi continue; 4705cb1dd27SAsmitha Karunanithi } 4715cb1dd27SAsmitha Karunanithi std::string entryID = path.substr(lastPos + 1); 4725cb1dd27SAsmitha Karunanithi 4735cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4745cb1dd27SAsmitha Karunanithi { 4755cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 4765cb1dd27SAsmitha Karunanithi { 4775cb1dd27SAsmitha Karunanithi 4785cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4795cb1dd27SAsmitha Karunanithi { 4805cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4815cb1dd27SAsmitha Karunanithi { 4825cb1dd27SAsmitha Karunanithi auto sizePtr = 4835cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4845cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4855cb1dd27SAsmitha Karunanithi { 4865cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4875cb1dd27SAsmitha Karunanithi break; 4885cb1dd27SAsmitha Karunanithi } 4895cb1dd27SAsmitha Karunanithi size = *sizePtr; 4905cb1dd27SAsmitha Karunanithi break; 4915cb1dd27SAsmitha Karunanithi } 4925cb1dd27SAsmitha Karunanithi } 4935cb1dd27SAsmitha Karunanithi } 4945cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4955cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 4965cb1dd27SAsmitha Karunanithi { 4975cb1dd27SAsmitha Karunanithi 4985cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4995cb1dd27SAsmitha Karunanithi { 5005cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 5015cb1dd27SAsmitha Karunanithi { 5025cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 5035cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5045cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 5055cb1dd27SAsmitha Karunanithi { 5065cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5075cb1dd27SAsmitha Karunanithi break; 5085cb1dd27SAsmitha Karunanithi } 5095cb1dd27SAsmitha Karunanithi timestamp = 5105cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 5115cb1dd27SAsmitha Karunanithi break; 5125cb1dd27SAsmitha Karunanithi } 5135cb1dd27SAsmitha Karunanithi } 5145cb1dd27SAsmitha Karunanithi } 5155cb1dd27SAsmitha Karunanithi } 5165cb1dd27SAsmitha Karunanithi 5175cb1dd27SAsmitha Karunanithi thisEntry["@odata.type"] = "#LogEntry.v1_5_1.LogEntry"; 5185cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 5195cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 5205cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5215cb1dd27SAsmitha Karunanithi thisEntry["Created"] = crow::utility::getDateTime(timestamp); 5225cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 5235cb1dd27SAsmitha Karunanithi 5245cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["@odata.type"] = 5255cb1dd27SAsmitha Karunanithi "#OemLogEntry.v1_0_0.OpenBmc"; 5265cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] = size; 5275cb1dd27SAsmitha Karunanithi 5285cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5295cb1dd27SAsmitha Karunanithi { 5305cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] = 5315cb1dd27SAsmitha Karunanithi "Manager"; 5325cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] = 5335cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 5345cb1dd27SAsmitha Karunanithi "attachment/" + 5355cb1dd27SAsmitha Karunanithi entryID; 5365cb1dd27SAsmitha Karunanithi } 5375cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5385cb1dd27SAsmitha Karunanithi { 5395cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] = "OEM"; 5405cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] = 5415cb1dd27SAsmitha Karunanithi "System"; 5425cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] = 5435cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/" 5445cb1dd27SAsmitha Karunanithi "attachment/" + 5455cb1dd27SAsmitha Karunanithi entryID; 5465cb1dd27SAsmitha Karunanithi } 5475cb1dd27SAsmitha Karunanithi } 5485cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 5495cb1dd27SAsmitha Karunanithi entriesArray.size(); 5505cb1dd27SAsmitha Karunanithi }, 5515cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5525cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5535cb1dd27SAsmitha Karunanithi } 5545cb1dd27SAsmitha Karunanithi 5555cb1dd27SAsmitha Karunanithi inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp, 5565cb1dd27SAsmitha Karunanithi const std::string& entryID, 5575cb1dd27SAsmitha Karunanithi const std::string& dumpType) 5585cb1dd27SAsmitha Karunanithi { 5595cb1dd27SAsmitha Karunanithi std::string dumpPath; 5605cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5615cb1dd27SAsmitha Karunanithi { 5625cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5635cb1dd27SAsmitha Karunanithi } 5645cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5655cb1dd27SAsmitha Karunanithi { 5665cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5675cb1dd27SAsmitha Karunanithi } 5685cb1dd27SAsmitha Karunanithi else 5695cb1dd27SAsmitha Karunanithi { 5705cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5715cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5725cb1dd27SAsmitha Karunanithi return; 5735cb1dd27SAsmitha Karunanithi } 5745cb1dd27SAsmitha Karunanithi 5755cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 5765cb1dd27SAsmitha Karunanithi [asyncResp, entryID, dumpPath, dumpType]( 5775cb1dd27SAsmitha Karunanithi const boost::system::error_code ec, GetManagedObjectsType& resp) { 5785cb1dd27SAsmitha Karunanithi if (ec) 5795cb1dd27SAsmitha Karunanithi { 5805cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5815cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5825cb1dd27SAsmitha Karunanithi return; 5835cb1dd27SAsmitha Karunanithi } 5845cb1dd27SAsmitha Karunanithi 5855cb1dd27SAsmitha Karunanithi for (auto& objectPath : resp) 5865cb1dd27SAsmitha Karunanithi { 5875cb1dd27SAsmitha Karunanithi if (objectPath.first.str.find( 5885cb1dd27SAsmitha Karunanithi "/xyz/openbmc_project/dump/entry/" + entryID) == 5895cb1dd27SAsmitha Karunanithi std::string::npos) 5905cb1dd27SAsmitha Karunanithi { 5915cb1dd27SAsmitha Karunanithi continue; 5925cb1dd27SAsmitha Karunanithi } 5935cb1dd27SAsmitha Karunanithi 5945cb1dd27SAsmitha Karunanithi bool foundDumpEntry = false; 5955cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 5965cb1dd27SAsmitha Karunanithi { 5975cb1dd27SAsmitha Karunanithi if (interfaceMap.first == 5985cb1dd27SAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 5995cb1dd27SAsmitha Karunanithi { 6005cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 6015cb1dd27SAsmitha Karunanithi break; 6025cb1dd27SAsmitha Karunanithi } 6035cb1dd27SAsmitha Karunanithi } 6045cb1dd27SAsmitha Karunanithi if (foundDumpEntry == false) 6055cb1dd27SAsmitha Karunanithi { 6065cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 6075cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6085cb1dd27SAsmitha Karunanithi return; 6095cb1dd27SAsmitha Karunanithi } 6105cb1dd27SAsmitha Karunanithi 6115cb1dd27SAsmitha Karunanithi std::time_t timestamp; 6125cb1dd27SAsmitha Karunanithi uint64_t size = 0; 6135cb1dd27SAsmitha Karunanithi 6145cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 6155cb1dd27SAsmitha Karunanithi { 6165cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 6175cb1dd27SAsmitha Karunanithi { 6185cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6195cb1dd27SAsmitha Karunanithi { 6205cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 6215cb1dd27SAsmitha Karunanithi { 6225cb1dd27SAsmitha Karunanithi auto sizePtr = 6235cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6245cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 6255cb1dd27SAsmitha Karunanithi { 6265cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6275cb1dd27SAsmitha Karunanithi break; 6285cb1dd27SAsmitha Karunanithi } 6295cb1dd27SAsmitha Karunanithi size = *sizePtr; 6305cb1dd27SAsmitha Karunanithi break; 6315cb1dd27SAsmitha Karunanithi } 6325cb1dd27SAsmitha Karunanithi } 6335cb1dd27SAsmitha Karunanithi } 6345cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 6355cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 6365cb1dd27SAsmitha Karunanithi { 6375cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6385cb1dd27SAsmitha Karunanithi { 6395cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 6405cb1dd27SAsmitha Karunanithi { 6415cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 6425cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6435cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 6445cb1dd27SAsmitha Karunanithi { 6455cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6465cb1dd27SAsmitha Karunanithi break; 6475cb1dd27SAsmitha Karunanithi } 6485cb1dd27SAsmitha Karunanithi timestamp = 6495cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 6505cb1dd27SAsmitha Karunanithi break; 6515cb1dd27SAsmitha Karunanithi } 6525cb1dd27SAsmitha Karunanithi } 6535cb1dd27SAsmitha Karunanithi } 6545cb1dd27SAsmitha Karunanithi } 6555cb1dd27SAsmitha Karunanithi 6565cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 6575cb1dd27SAsmitha Karunanithi "#LogEntry.v1_5_1.LogEntry"; 6585cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6595cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6605cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6615cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6625cb1dd27SAsmitha Karunanithi crow::utility::getDateTime(timestamp); 6635cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6645cb1dd27SAsmitha Karunanithi 6655cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 6665cb1dd27SAsmitha Karunanithi "#OemLogEntry.v1_0_0.OpenBmc"; 6675cb1dd27SAsmitha Karunanithi asyncResp->res 6685cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] = 6695cb1dd27SAsmitha Karunanithi size; 6705cb1dd27SAsmitha Karunanithi 6715cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6725cb1dd27SAsmitha Karunanithi { 6735cb1dd27SAsmitha Karunanithi asyncResp->res 6745cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] = 6755cb1dd27SAsmitha Karunanithi "Manager"; 6765cb1dd27SAsmitha Karunanithi asyncResp->res 6775cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] = 6785cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 6795cb1dd27SAsmitha Karunanithi "attachment/" + 6805cb1dd27SAsmitha Karunanithi entryID; 6815cb1dd27SAsmitha Karunanithi } 6825cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6835cb1dd27SAsmitha Karunanithi { 6845cb1dd27SAsmitha Karunanithi asyncResp->res 6855cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] = 6865cb1dd27SAsmitha Karunanithi "OEM"; 6875cb1dd27SAsmitha Karunanithi asyncResp->res 6885cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] = 6895cb1dd27SAsmitha Karunanithi "System"; 6905cb1dd27SAsmitha Karunanithi asyncResp->res 6915cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] = 6925cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/" 6935cb1dd27SAsmitha Karunanithi "attachment/" + 6945cb1dd27SAsmitha Karunanithi entryID; 6955cb1dd27SAsmitha Karunanithi } 6965cb1dd27SAsmitha Karunanithi } 6975cb1dd27SAsmitha Karunanithi }, 6985cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6995cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 7005cb1dd27SAsmitha Karunanithi } 7015cb1dd27SAsmitha Karunanithi 7025cb1dd27SAsmitha Karunanithi inline void deleteDumpEntry(crow::Response& res, const std::string& entryID) 7035cb1dd27SAsmitha Karunanithi { 7045cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 7055cb1dd27SAsmitha Karunanithi 7065cb1dd27SAsmitha Karunanithi auto respHandler = [asyncResp](const boost::system::error_code ec) { 7075cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 7085cb1dd27SAsmitha Karunanithi if (ec) 7095cb1dd27SAsmitha Karunanithi { 7105cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 7115cb1dd27SAsmitha Karunanithi << ec; 7125cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 7135cb1dd27SAsmitha Karunanithi return; 7145cb1dd27SAsmitha Karunanithi } 7155cb1dd27SAsmitha Karunanithi }; 7165cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 7175cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 7185cb1dd27SAsmitha Karunanithi "/xyz/openbmc_project/dump/entry/" + entryID, 7195cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 7205cb1dd27SAsmitha Karunanithi } 7215cb1dd27SAsmitha Karunanithi 722a43be80fSAsmitha Karunanithi inline void createDumpTaskCallback(const crow::Request& req, 723a43be80fSAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp, 724a43be80fSAsmitha Karunanithi const uint32_t& dumpId, 725a43be80fSAsmitha Karunanithi const std::string& dumpPath, 726a43be80fSAsmitha Karunanithi const std::string& dumpType) 727a43be80fSAsmitha Karunanithi { 728a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 729a43be80fSAsmitha Karunanithi [dumpId, dumpPath, dumpType]( 730a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 731a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 732a43be80fSAsmitha Karunanithi std::vector<std::pair< 733a43be80fSAsmitha Karunanithi std::string, 734a43be80fSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string>>>>> 735a43be80fSAsmitha Karunanithi interfacesList; 736a43be80fSAsmitha Karunanithi 737a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 738a43be80fSAsmitha Karunanithi 739a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 740a43be80fSAsmitha Karunanithi 741a43be80fSAsmitha Karunanithi for (auto& interface : interfacesList) 742a43be80fSAsmitha Karunanithi { 743a43be80fSAsmitha Karunanithi if (interface.first == 744a43be80fSAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 745a43be80fSAsmitha Karunanithi { 746a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 747a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 748a43be80fSAsmitha Karunanithi 749a43be80fSAsmitha Karunanithi std::string headerLoc = 750a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 751a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 752a43be80fSAsmitha Karunanithi std::move(headerLoc)); 753a43be80fSAsmitha Karunanithi 754a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 755a43be80fSAsmitha Karunanithi return task::completed; 756a43be80fSAsmitha Karunanithi } 757a43be80fSAsmitha Karunanithi } 758a43be80fSAsmitha Karunanithi return !task::completed; 759a43be80fSAsmitha Karunanithi }, 760a43be80fSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus." 761a43be80fSAsmitha Karunanithi "ObjectManager'," 762a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 763a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 764a43be80fSAsmitha Karunanithi 765a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 766a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 767a43be80fSAsmitha Karunanithi task->payload.emplace(req); 768a43be80fSAsmitha Karunanithi } 769a43be80fSAsmitha Karunanithi 770a43be80fSAsmitha Karunanithi inline void createDump(crow::Response& res, const crow::Request& req, 771a43be80fSAsmitha Karunanithi const std::string& dumpType) 772a43be80fSAsmitha Karunanithi { 773a43be80fSAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 774a43be80fSAsmitha Karunanithi 775a43be80fSAsmitha Karunanithi std::string dumpPath; 776a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 777a43be80fSAsmitha Karunanithi { 778a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 779a43be80fSAsmitha Karunanithi } 780a43be80fSAsmitha Karunanithi else if (dumpType == "System") 781a43be80fSAsmitha Karunanithi { 782a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 783a43be80fSAsmitha Karunanithi } 784a43be80fSAsmitha Karunanithi else 785a43be80fSAsmitha Karunanithi { 786a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 787a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 788a43be80fSAsmitha Karunanithi return; 789a43be80fSAsmitha Karunanithi } 790a43be80fSAsmitha Karunanithi 791a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 792a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 793a43be80fSAsmitha Karunanithi 794a43be80fSAsmitha Karunanithi if (!redfish::json_util::readJson( 795a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 796a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 797a43be80fSAsmitha Karunanithi { 798a43be80fSAsmitha Karunanithi return; 799a43be80fSAsmitha Karunanithi } 800a43be80fSAsmitha Karunanithi 801a43be80fSAsmitha Karunanithi if (dumpType == "System") 802a43be80fSAsmitha Karunanithi { 803a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 804a43be80fSAsmitha Karunanithi { 805a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 806a43be80fSAsmitha Karunanithi "'DiagnosticDataType'/" 807a43be80fSAsmitha Karunanithi "'OEMDiagnosticDataType' value not found!"; 808a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 809a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 810a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 811a43be80fSAsmitha Karunanithi return; 812a43be80fSAsmitha Karunanithi } 813a43be80fSAsmitha Karunanithi else if ((*oemDiagnosticDataType != "System") || 814a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 815a43be80fSAsmitha Karunanithi { 816a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 817a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 818a43be80fSAsmitha Karunanithi "System Dump creation parameters"); 819a43be80fSAsmitha Karunanithi return; 820a43be80fSAsmitha Karunanithi } 821a43be80fSAsmitha Karunanithi } 822a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 823a43be80fSAsmitha Karunanithi { 824a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 825a43be80fSAsmitha Karunanithi { 826a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 827a43be80fSAsmitha Karunanithi "'DiagnosticDataType' not found!"; 828a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 829a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 830a43be80fSAsmitha Karunanithi return; 831a43be80fSAsmitha Karunanithi } 832a43be80fSAsmitha Karunanithi else if (*diagnosticDataType != "Manager") 833a43be80fSAsmitha Karunanithi { 834a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 835a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 836a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 837a43be80fSAsmitha Karunanithi "BMC Dump creation parameters"); 838a43be80fSAsmitha Karunanithi return; 839a43be80fSAsmitha Karunanithi } 840a43be80fSAsmitha Karunanithi } 841a43be80fSAsmitha Karunanithi 842a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 843a43be80fSAsmitha Karunanithi [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec, 844a43be80fSAsmitha Karunanithi const uint32_t& dumpId) { 845a43be80fSAsmitha Karunanithi if (ec) 846a43be80fSAsmitha Karunanithi { 847a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 848a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 849a43be80fSAsmitha Karunanithi return; 850a43be80fSAsmitha Karunanithi } 851a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 852a43be80fSAsmitha Karunanithi 853a43be80fSAsmitha Karunanithi createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType); 854a43be80fSAsmitha Karunanithi }, 855a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 856a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 857a43be80fSAsmitha Karunanithi } 858a43be80fSAsmitha Karunanithi 85980319af1SAsmitha Karunanithi inline void clearDump(crow::Response& res, const std::string& dumpInterface) 86080319af1SAsmitha Karunanithi { 86180319af1SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 86280319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 86380319af1SAsmitha Karunanithi [asyncResp](const boost::system::error_code ec, 86480319af1SAsmitha Karunanithi const std::vector<std::string>& subTreePaths) { 86580319af1SAsmitha Karunanithi if (ec) 86680319af1SAsmitha Karunanithi { 86780319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 86880319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 86980319af1SAsmitha Karunanithi return; 87080319af1SAsmitha Karunanithi } 87180319af1SAsmitha Karunanithi 87280319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 87380319af1SAsmitha Karunanithi { 87480319af1SAsmitha Karunanithi std::size_t pos = path.rfind("/"); 87580319af1SAsmitha Karunanithi if (pos != std::string::npos) 87680319af1SAsmitha Karunanithi { 87780319af1SAsmitha Karunanithi std::string logID = path.substr(pos + 1); 87880319af1SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, logID); 87980319af1SAsmitha Karunanithi } 88080319af1SAsmitha Karunanithi } 88180319af1SAsmitha Karunanithi }, 88280319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 88380319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 88480319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 88580319af1SAsmitha Karunanithi "/xyz/openbmc_project/dump", 0, 88680319af1SAsmitha Karunanithi std::array<std::string, 1>{dumpInterface}); 88780319af1SAsmitha Karunanithi } 88880319af1SAsmitha Karunanithi 889043a0536SJohnathan Mantey static void ParseCrashdumpParameters( 890043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params, 891043a0536SJohnathan Mantey std::string& filename, std::string& timestamp, std::string& logfile) 892043a0536SJohnathan Mantey { 893043a0536SJohnathan Mantey for (auto property : params) 894043a0536SJohnathan Mantey { 895043a0536SJohnathan Mantey if (property.first == "Timestamp") 896043a0536SJohnathan Mantey { 897043a0536SJohnathan Mantey const std::string* value = 8988d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 899043a0536SJohnathan Mantey if (value != nullptr) 900043a0536SJohnathan Mantey { 901043a0536SJohnathan Mantey timestamp = *value; 902043a0536SJohnathan Mantey } 903043a0536SJohnathan Mantey } 904043a0536SJohnathan Mantey else if (property.first == "Filename") 905043a0536SJohnathan Mantey { 906043a0536SJohnathan Mantey const std::string* value = 9078d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 908043a0536SJohnathan Mantey if (value != nullptr) 909043a0536SJohnathan Mantey { 910043a0536SJohnathan Mantey filename = *value; 911043a0536SJohnathan Mantey } 912043a0536SJohnathan Mantey } 913043a0536SJohnathan Mantey else if (property.first == "Log") 914043a0536SJohnathan Mantey { 915043a0536SJohnathan Mantey const std::string* value = 9168d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 917043a0536SJohnathan Mantey if (value != nullptr) 918043a0536SJohnathan Mantey { 919043a0536SJohnathan Mantey logfile = *value; 920043a0536SJohnathan Mantey } 921043a0536SJohnathan Mantey } 922043a0536SJohnathan Mantey } 923043a0536SJohnathan Mantey } 924043a0536SJohnathan Mantey 925a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 926c4bf6374SJason M. Bills class SystemLogServiceCollection : public Node 9271da66f75SEd Tanous { 9281da66f75SEd Tanous public: 9291da66f75SEd Tanous template <typename CrowApp> 930c4bf6374SJason M. Bills SystemLogServiceCollection(CrowApp& app) : 931029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/") 932c4bf6374SJason M. Bills { 933c4bf6374SJason M. Bills entityPrivileges = { 934c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 935c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 936c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 937c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 938c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 939c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 940c4bf6374SJason M. Bills } 941c4bf6374SJason M. Bills 942c4bf6374SJason M. Bills private: 943c4bf6374SJason M. Bills /** 944c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 945c4bf6374SJason M. Bills */ 946c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 947c4bf6374SJason M. Bills const std::vector<std::string>& params) override 948c4bf6374SJason M. Bills { 949c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 950c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 951c4bf6374SJason M. Bills // it has a duplicate entry for members 952c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 953c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 954c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 955029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 956c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 957c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 958c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 959c4bf6374SJason M. Bills nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 960c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 961029573d4SEd Tanous logServiceArray.push_back( 962029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}}); 9635cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 964c9bb6861Sraviteja-b logServiceArray.push_back( 9655cb1dd27SAsmitha Karunanithi {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}}); 966c9bb6861Sraviteja-b #endif 967c9bb6861Sraviteja-b 968d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 969d53dd41fSJason M. Bills logServiceArray.push_back( 970cb92c03bSAndrew Geissler {{"@odata.id", 971424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 972d53dd41fSJason M. Bills #endif 973c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 974c4bf6374SJason M. Bills logServiceArray.size(); 975a3316fc6SZhikuiRen 976a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 977a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 978a3316fc6SZhikuiRen const std::vector<std::string>& subtreePath) { 979a3316fc6SZhikuiRen if (ec) 980a3316fc6SZhikuiRen { 981a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 982a3316fc6SZhikuiRen return; 983a3316fc6SZhikuiRen } 984a3316fc6SZhikuiRen 985a3316fc6SZhikuiRen for (auto& pathStr : subtreePath) 986a3316fc6SZhikuiRen { 987a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 988a3316fc6SZhikuiRen { 989a3316fc6SZhikuiRen nlohmann::json& logServiceArray = 990a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 991a3316fc6SZhikuiRen logServiceArray.push_back( 992a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 993a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 994a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 995a3316fc6SZhikuiRen logServiceArray.size(); 996a3316fc6SZhikuiRen return; 997a3316fc6SZhikuiRen } 998a3316fc6SZhikuiRen } 999a3316fc6SZhikuiRen }, 1000a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 1001a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 1002a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 1003a3316fc6SZhikuiRen std::array<const char*, 1>{postCodeIface}); 1004c4bf6374SJason M. Bills } 1005c4bf6374SJason M. Bills }; 1006c4bf6374SJason M. Bills 1007c4bf6374SJason M. Bills class EventLogService : public Node 1008c4bf6374SJason M. Bills { 1009c4bf6374SJason M. Bills public: 1010c4bf6374SJason M. Bills template <typename CrowApp> 1011c4bf6374SJason M. Bills EventLogService(CrowApp& app) : 1012029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 1013c4bf6374SJason M. Bills { 1014c4bf6374SJason M. Bills entityPrivileges = { 1015c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1016c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1017c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1018c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1019c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1020c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1021c4bf6374SJason M. Bills } 1022c4bf6374SJason M. Bills 1023c4bf6374SJason M. Bills private: 1024c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1025c4bf6374SJason M. Bills const std::vector<std::string>& params) override 1026c4bf6374SJason M. Bills { 1027c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1028c4bf6374SJason M. Bills 1029c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1030029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1031c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1032c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 1033c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 1034c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 1035c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1036c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1037c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1038c4bf6374SJason M. Bills {"@odata.id", 1039029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 1040e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1041e7d6c8b2SGunnar Mills 1042e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 1043e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 1044489640c6SJason M. Bills } 1045489640c6SJason M. Bills }; 1046489640c6SJason M. Bills 10471f56a3a6STim Lee class JournalEventLogClear : public Node 1048489640c6SJason M. Bills { 1049489640c6SJason M. Bills public: 10501f56a3a6STim Lee JournalEventLogClear(CrowApp& app) : 1051489640c6SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 1052489640c6SJason M. Bills "LogService.ClearLog/") 1053489640c6SJason M. Bills { 1054489640c6SJason M. Bills entityPrivileges = { 1055489640c6SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1056489640c6SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1057489640c6SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1058489640c6SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1059489640c6SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1060489640c6SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1061489640c6SJason M. Bills } 1062489640c6SJason M. Bills 1063489640c6SJason M. Bills private: 1064489640c6SJason M. Bills void doPost(crow::Response& res, const crow::Request& req, 1065489640c6SJason M. Bills const std::vector<std::string>& params) override 1066489640c6SJason M. Bills { 1067489640c6SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1068489640c6SJason M. Bills 1069489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1070489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1071489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1072489640c6SJason M. Bills { 1073489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1074489640c6SJason M. Bills { 1075489640c6SJason M. Bills std::error_code ec; 1076489640c6SJason M. Bills std::filesystem::remove(file, ec); 1077489640c6SJason M. Bills } 1078489640c6SJason M. Bills } 1079489640c6SJason M. Bills 1080489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1081489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1082489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1083489640c6SJason M. Bills if (ec) 1084489640c6SJason M. Bills { 1085489640c6SJason M. Bills BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 1086489640c6SJason M. Bills messages::internalError(asyncResp->res); 1087489640c6SJason M. Bills return; 1088489640c6SJason M. Bills } 1089489640c6SJason M. Bills 1090489640c6SJason M. Bills messages::success(asyncResp->res); 1091489640c6SJason M. Bills }, 1092489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1093489640c6SJason M. Bills "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1094489640c6SJason M. Bills "replace"); 1095c4bf6374SJason M. Bills } 1096c4bf6374SJason M. Bills }; 1097c4bf6374SJason M. Bills 109895820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 109995820184SJason M. Bills const std::string logEntry, 110095820184SJason M. Bills nlohmann::json& logEntryJson) 1101c4bf6374SJason M. Bills { 110295820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1103cd225da8SJason M. Bills // First get the Timestamp 1104cd225da8SJason M. Bills size_t space = logEntry.find_first_of(" "); 1105cd225da8SJason M. Bills if (space == std::string::npos) 110695820184SJason M. Bills { 110795820184SJason M. Bills return 1; 110895820184SJason M. Bills } 1109cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1110cd225da8SJason M. Bills // Then get the log contents 1111cd225da8SJason M. Bills size_t entryStart = logEntry.find_first_not_of(" ", space); 1112cd225da8SJason M. Bills if (entryStart == std::string::npos) 1113cd225da8SJason M. Bills { 1114cd225da8SJason M. Bills return 1; 1115cd225da8SJason M. Bills } 1116cd225da8SJason M. Bills std::string_view entry(logEntry); 1117cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1118cd225da8SJason M. Bills // Use split to separate the entry into its fields 1119cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1120cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1121cd225da8SJason M. Bills boost::token_compress_on); 1122cd225da8SJason M. Bills // We need at least a MessageId to be valid 1123cd225da8SJason M. Bills if (logEntryFields.size() < 1) 1124cd225da8SJason M. Bills { 1125cd225da8SJason M. Bills return 1; 1126cd225da8SJason M. Bills } 1127cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 112895820184SJason M. Bills 11294851d45dSJason M. Bills // Get the Message from the MessageRegistry 11304851d45dSJason M. Bills const message_registries::Message* message = 11314851d45dSJason M. Bills message_registries::getMessage(messageID); 1132c4bf6374SJason M. Bills 11334851d45dSJason M. Bills std::string msg; 11344851d45dSJason M. Bills std::string severity; 11354851d45dSJason M. Bills if (message != nullptr) 1136c4bf6374SJason M. Bills { 11374851d45dSJason M. Bills msg = message->message; 11384851d45dSJason M. Bills severity = message->severity; 1139c4bf6374SJason M. Bills } 1140c4bf6374SJason M. Bills 114115a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 114215a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 114315a86ff6SJason M. Bills if (logEntryFields.size() > 1) 114415a86ff6SJason M. Bills { 114515a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 114615a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 114715a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 114815a86ff6SJason M. Bills if (!messageArgsStart.empty()) 114915a86ff6SJason M. Bills { 115015a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 115115a86ff6SJason M. Bills } 115215a86ff6SJason M. Bills 115315a86ff6SJason M. Bills messageArgs = boost::beast::span(&messageArgsStart, messageArgsSize); 1154c4bf6374SJason M. Bills 11554851d45dSJason M. Bills // Fill the MessageArgs into the Message 115695820184SJason M. Bills int i = 0; 115795820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11584851d45dSJason M. Bills { 115995820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11604851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11614851d45dSJason M. Bills if (argPos != std::string::npos) 11624851d45dSJason M. Bills { 116395820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11644851d45dSJason M. Bills } 11654851d45dSJason M. Bills } 116615a86ff6SJason M. Bills } 11674851d45dSJason M. Bills 116895820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 116995820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 117095820184SJason M. Bills // between the '.' and the '+', so just remove them. 117195820184SJason M. Bills std::size_t dot = timestamp.find_first_of("."); 117295820184SJason M. Bills std::size_t plus = timestamp.find_first_of("+"); 117395820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1174c4bf6374SJason M. Bills { 117595820184SJason M. Bills timestamp.erase(dot, plus - dot); 1176c4bf6374SJason M. Bills } 1177c4bf6374SJason M. Bills 1178c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 117995820184SJason M. Bills logEntryJson = { 1180cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1181029573d4SEd Tanous {"@odata.id", 1182897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 118395820184SJason M. Bills logEntryID}, 1184c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 118595820184SJason M. Bills {"Id", logEntryID}, 118695820184SJason M. Bills {"Message", std::move(msg)}, 118795820184SJason M. Bills {"MessageId", std::move(messageID)}, 1188c4bf6374SJason M. Bills {"MessageArgs", std::move(messageArgs)}, 1189c4bf6374SJason M. Bills {"EntryType", "Event"}, 119095820184SJason M. Bills {"Severity", std::move(severity)}, 119195820184SJason M. Bills {"Created", std::move(timestamp)}}; 1192c4bf6374SJason M. Bills return 0; 1193c4bf6374SJason M. Bills } 1194c4bf6374SJason M. Bills 119527062605SAnthony Wilson class JournalEventLogEntryCollection : public Node 1196c4bf6374SJason M. Bills { 1197c4bf6374SJason M. Bills public: 1198c4bf6374SJason M. Bills template <typename CrowApp> 119927062605SAnthony Wilson JournalEventLogEntryCollection(CrowApp& app) : 1200029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1201c4bf6374SJason M. Bills { 1202c4bf6374SJason M. Bills entityPrivileges = { 1203c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1204c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1205c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1206c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1207c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1208c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1209c4bf6374SJason M. Bills } 1210c4bf6374SJason M. Bills 1211c4bf6374SJason M. Bills private: 1212c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1213c4bf6374SJason M. Bills const std::vector<std::string>& params) override 1214c4bf6374SJason M. Bills { 1215c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1216271584abSEd Tanous uint64_t skip = 0; 1217271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 1218c4bf6374SJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1219c4bf6374SJason M. Bills { 1220c4bf6374SJason M. Bills return; 1221c4bf6374SJason M. Bills } 1222c4bf6374SJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1223c4bf6374SJason M. Bills { 1224c4bf6374SJason M. Bills return; 1225c4bf6374SJason M. Bills } 1226c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 1227c4bf6374SJason M. Bills // it has a duplicate entry for members 1228c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1229c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1230c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1231029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1232c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1233c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1234c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1235cb92c03bSAndrew Geissler 1236c4bf6374SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1237c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 123895820184SJason M. Bills // Go through the log files and create a unique ID for each entry 123995820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 124095820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1241b01bf299SEd Tanous uint64_t entryCount = 0; 1242cd225da8SJason M. Bills std::string logEntry; 124395820184SJason M. Bills 124495820184SJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 1245cd225da8SJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1246cd225da8SJason M. Bills it++) 1247c4bf6374SJason M. Bills { 1248cd225da8SJason M. Bills std::ifstream logStream(*it); 124995820184SJason M. Bills if (!logStream.is_open()) 1250c4bf6374SJason M. Bills { 1251c4bf6374SJason M. Bills continue; 1252c4bf6374SJason M. Bills } 1253c4bf6374SJason M. Bills 1254e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1255e85d6b16SJason M. Bills bool firstEntry = true; 125695820184SJason M. Bills while (std::getline(logStream, logEntry)) 125795820184SJason M. Bills { 1258c4bf6374SJason M. Bills entryCount++; 1259c4bf6374SJason M. Bills // Handle paging using skip (number of entries to skip from the 1260c4bf6374SJason M. Bills // start) and top (number of entries to display) 1261c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1262c4bf6374SJason M. Bills { 1263c4bf6374SJason M. Bills continue; 1264c4bf6374SJason M. Bills } 1265c4bf6374SJason M. Bills 1266c4bf6374SJason M. Bills std::string idStr; 1267e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1268c4bf6374SJason M. Bills { 1269c4bf6374SJason M. Bills continue; 1270c4bf6374SJason M. Bills } 1271c4bf6374SJason M. Bills 1272e85d6b16SJason M. Bills if (firstEntry) 1273e85d6b16SJason M. Bills { 1274e85d6b16SJason M. Bills firstEntry = false; 1275e85d6b16SJason M. Bills } 1276e85d6b16SJason M. Bills 1277c4bf6374SJason M. Bills logEntryArray.push_back({}); 1278c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 127995820184SJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0) 1280c4bf6374SJason M. Bills { 1281c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1282c4bf6374SJason M. Bills return; 1283c4bf6374SJason M. Bills } 1284c4bf6374SJason M. Bills } 128595820184SJason M. Bills } 1286c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1287c4bf6374SJason M. Bills if (skip + top < entryCount) 1288c4bf6374SJason M. Bills { 1289c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 129095820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 129195820184SJason M. Bills "Entries?$skip=" + 1292c4bf6374SJason M. Bills std::to_string(skip + top); 1293c4bf6374SJason M. Bills } 129408a4e4b5SAnthony Wilson } 129508a4e4b5SAnthony Wilson }; 129608a4e4b5SAnthony Wilson 1297897967deSJason M. Bills class JournalEventLogEntry : public Node 1298897967deSJason M. Bills { 1299897967deSJason M. Bills public: 1300897967deSJason M. Bills JournalEventLogEntry(CrowApp& app) : 1301897967deSJason M. Bills Node(app, 1302897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1303897967deSJason M. Bills std::string()) 1304897967deSJason M. Bills { 1305897967deSJason M. Bills entityPrivileges = { 1306897967deSJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1307897967deSJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1308897967deSJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1309897967deSJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1310897967deSJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1311897967deSJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1312897967deSJason M. Bills } 1313897967deSJason M. Bills 1314897967deSJason M. Bills private: 1315897967deSJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1316897967deSJason M. Bills const std::vector<std::string>& params) override 1317897967deSJason M. Bills { 1318897967deSJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1319897967deSJason M. Bills if (params.size() != 1) 1320897967deSJason M. Bills { 1321897967deSJason M. Bills messages::internalError(asyncResp->res); 1322897967deSJason M. Bills return; 1323897967deSJason M. Bills } 1324897967deSJason M. Bills const std::string& targetID = params[0]; 1325897967deSJason M. Bills 1326897967deSJason M. Bills // Go through the log files and check the unique ID for each entry to 1327897967deSJason M. Bills // find the target entry 1328897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1329897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1330897967deSJason M. Bills std::string logEntry; 1331897967deSJason M. Bills 1332897967deSJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 1333897967deSJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1334897967deSJason M. Bills it++) 1335897967deSJason M. Bills { 1336897967deSJason M. Bills std::ifstream logStream(*it); 1337897967deSJason M. Bills if (!logStream.is_open()) 1338897967deSJason M. Bills { 1339897967deSJason M. Bills continue; 1340897967deSJason M. Bills } 1341897967deSJason M. Bills 1342897967deSJason M. Bills // Reset the unique ID on the first entry 1343897967deSJason M. Bills bool firstEntry = true; 1344897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1345897967deSJason M. Bills { 1346897967deSJason M. Bills std::string idStr; 1347897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1348897967deSJason M. Bills { 1349897967deSJason M. Bills continue; 1350897967deSJason M. Bills } 1351897967deSJason M. Bills 1352897967deSJason M. Bills if (firstEntry) 1353897967deSJason M. Bills { 1354897967deSJason M. Bills firstEntry = false; 1355897967deSJason M. Bills } 1356897967deSJason M. Bills 1357897967deSJason M. Bills if (idStr == targetID) 1358897967deSJason M. Bills { 1359897967deSJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, 1360897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1361897967deSJason M. Bills { 1362897967deSJason M. Bills messages::internalError(asyncResp->res); 1363897967deSJason M. Bills return; 1364897967deSJason M. Bills } 1365897967deSJason M. Bills return; 1366897967deSJason M. Bills } 1367897967deSJason M. Bills } 1368897967deSJason M. Bills } 1369897967deSJason M. Bills // Requested ID was not found 1370897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 1371897967deSJason M. Bills } 1372897967deSJason M. Bills }; 1373897967deSJason M. Bills 137408a4e4b5SAnthony Wilson class DBusEventLogEntryCollection : public Node 137508a4e4b5SAnthony Wilson { 137608a4e4b5SAnthony Wilson public: 137708a4e4b5SAnthony Wilson template <typename CrowApp> 137808a4e4b5SAnthony Wilson DBusEventLogEntryCollection(CrowApp& app) : 137908a4e4b5SAnthony Wilson Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 138008a4e4b5SAnthony Wilson { 138108a4e4b5SAnthony Wilson entityPrivileges = { 138208a4e4b5SAnthony Wilson {boost::beast::http::verb::get, {{"Login"}}}, 138308a4e4b5SAnthony Wilson {boost::beast::http::verb::head, {{"Login"}}}, 138408a4e4b5SAnthony Wilson {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 138508a4e4b5SAnthony Wilson {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 138608a4e4b5SAnthony Wilson {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 138708a4e4b5SAnthony Wilson {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 138808a4e4b5SAnthony Wilson } 138908a4e4b5SAnthony Wilson 139008a4e4b5SAnthony Wilson private: 139108a4e4b5SAnthony Wilson void doGet(crow::Response& res, const crow::Request& req, 139208a4e4b5SAnthony Wilson const std::vector<std::string>& params) override 139308a4e4b5SAnthony Wilson { 139408a4e4b5SAnthony Wilson std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 139508a4e4b5SAnthony Wilson 139608a4e4b5SAnthony Wilson // Collections don't include the static data added by SubRoute because 139708a4e4b5SAnthony Wilson // it has a duplicate entry for members 139808a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 139908a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 140008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 140108a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 140208a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 140308a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 140408a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 140508a4e4b5SAnthony Wilson 1406cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1407cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1408cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1409cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1410cb92c03bSAndrew Geissler GetManagedObjectsType& resp) { 1411cb92c03bSAndrew Geissler if (ec) 1412cb92c03bSAndrew Geissler { 1413cb92c03bSAndrew Geissler // TODO Handle for specific error code 1414cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1415cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1416cb92c03bSAndrew Geissler << ec; 1417cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1418cb92c03bSAndrew Geissler return; 1419cb92c03bSAndrew Geissler } 1420cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1421cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1422cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 1423cb92c03bSAndrew Geissler for (auto& objectPath : resp) 1424cb92c03bSAndrew Geissler { 1425cb92c03bSAndrew Geissler for (auto& interfaceMap : objectPath.second) 1426cb92c03bSAndrew Geissler { 1427cb92c03bSAndrew Geissler if (interfaceMap.first != 1428cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry") 1429cb92c03bSAndrew Geissler { 1430cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Bailing early on " 1431cb92c03bSAndrew Geissler << interfaceMap.first; 1432cb92c03bSAndrew Geissler continue; 1433cb92c03bSAndrew Geissler } 1434cb92c03bSAndrew Geissler entriesArray.push_back({}); 1435cb92c03bSAndrew Geissler nlohmann::json& thisEntry = entriesArray.back(); 143666664f25SEd Tanous uint32_t* id = nullptr; 143766664f25SEd Tanous std::time_t timestamp{}; 143866664f25SEd Tanous std::string* severity = nullptr; 143966664f25SEd Tanous std::string* message = nullptr; 1440cb92c03bSAndrew Geissler for (auto& propertyMap : interfaceMap.second) 1441cb92c03bSAndrew Geissler { 1442cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1443cb92c03bSAndrew Geissler { 14448d78b7a9SPatrick Williams id = std::get_if<uint32_t>(&propertyMap.second); 1445cb92c03bSAndrew Geissler if (id == nullptr) 1446cb92c03bSAndrew Geissler { 1447*0f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1448cb92c03bSAndrew Geissler } 1449cb92c03bSAndrew Geissler } 1450cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1451cb92c03bSAndrew Geissler { 1452cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1453cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1454cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1455cb92c03bSAndrew Geissler { 1456*0f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1457271584abSEd Tanous continue; 1458cb92c03bSAndrew Geissler } 1459cb92c03bSAndrew Geissler // Retrieve Created property with format: 1460cb92c03bSAndrew Geissler // yyyy-mm-ddThh:mm:ss 1461cb92c03bSAndrew Geissler std::chrono::milliseconds chronoTimeStamp( 1462cb92c03bSAndrew Geissler *millisTimeStamp); 1463271584abSEd Tanous timestamp = std::chrono::duration_cast< 1464271584abSEd Tanous std::chrono::duration<int>>( 1465271584abSEd Tanous chronoTimeStamp) 1466cb92c03bSAndrew Geissler .count(); 1467cb92c03bSAndrew Geissler } 1468cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1469cb92c03bSAndrew Geissler { 1470cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1471cb92c03bSAndrew Geissler &propertyMap.second); 1472cb92c03bSAndrew Geissler if (severity == nullptr) 1473cb92c03bSAndrew Geissler { 1474*0f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1475cb92c03bSAndrew Geissler } 1476cb92c03bSAndrew Geissler } 1477cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1478cb92c03bSAndrew Geissler { 1479cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1480cb92c03bSAndrew Geissler &propertyMap.second); 1481cb92c03bSAndrew Geissler if (message == nullptr) 1482cb92c03bSAndrew Geissler { 1483*0f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1484cb92c03bSAndrew Geissler } 1485cb92c03bSAndrew Geissler } 1486cb92c03bSAndrew Geissler } 1487cb92c03bSAndrew Geissler thisEntry = { 1488cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1489cb92c03bSAndrew Geissler {"@odata.id", 1490cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1491cb92c03bSAndrew Geissler "Entries/" + 1492cb92c03bSAndrew Geissler std::to_string(*id)}, 149327062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1494cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1495cb92c03bSAndrew Geissler {"Message", *message}, 1496cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1497cb92c03bSAndrew Geissler {"Severity", 1498cb92c03bSAndrew Geissler translateSeverityDbusToRedfish(*severity)}, 1499cb92c03bSAndrew Geissler {"Created", crow::utility::getDateTime(timestamp)}}; 1500cb92c03bSAndrew Geissler } 1501cb92c03bSAndrew Geissler } 1502cb92c03bSAndrew Geissler std::sort(entriesArray.begin(), entriesArray.end(), 1503cb92c03bSAndrew Geissler [](const nlohmann::json& left, 1504cb92c03bSAndrew Geissler const nlohmann::json& right) { 1505cb92c03bSAndrew Geissler return (left["Id"] <= right["Id"]); 1506cb92c03bSAndrew Geissler }); 1507cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members@odata.count"] = 1508cb92c03bSAndrew Geissler entriesArray.size(); 1509cb92c03bSAndrew Geissler }, 1510cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 1511cb92c03bSAndrew Geissler "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 1512c4bf6374SJason M. Bills } 1513c4bf6374SJason M. Bills }; 1514c4bf6374SJason M. Bills 151508a4e4b5SAnthony Wilson class DBusEventLogEntry : public Node 1516c4bf6374SJason M. Bills { 1517c4bf6374SJason M. Bills public: 151808a4e4b5SAnthony Wilson DBusEventLogEntry(CrowApp& app) : 1519c4bf6374SJason M. Bills Node(app, 1520029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1521029573d4SEd Tanous std::string()) 1522c4bf6374SJason M. Bills { 1523c4bf6374SJason M. Bills entityPrivileges = { 1524c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1525c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1526c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1527c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1528c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1529c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1530c4bf6374SJason M. Bills } 1531c4bf6374SJason M. Bills 1532c4bf6374SJason M. Bills private: 1533c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1534c4bf6374SJason M. Bills const std::vector<std::string>& params) override 1535c4bf6374SJason M. Bills { 1536c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1537029573d4SEd Tanous if (params.size() != 1) 1538c4bf6374SJason M. Bills { 1539c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1540c4bf6374SJason M. Bills return; 1541c4bf6374SJason M. Bills } 1542029573d4SEd Tanous const std::string& entryID = params[0]; 1543cb92c03bSAndrew Geissler 1544cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1545cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1546cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1547cb92c03bSAndrew Geissler [asyncResp, entryID](const boost::system::error_code ec, 1548cb92c03bSAndrew Geissler GetManagedPropertyType& resp) { 1549cb92c03bSAndrew Geissler if (ec) 1550cb92c03bSAndrew Geissler { 1551cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1552cb92c03bSAndrew Geissler << "EventLogEntry (DBus) resp_handler got error " << ec; 1553cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1554cb92c03bSAndrew Geissler return; 1555cb92c03bSAndrew Geissler } 155666664f25SEd Tanous uint32_t* id = nullptr; 155766664f25SEd Tanous std::time_t timestamp{}; 155866664f25SEd Tanous std::string* severity = nullptr; 155966664f25SEd Tanous std::string* message = nullptr; 1560cb92c03bSAndrew Geissler for (auto& propertyMap : resp) 1561cb92c03bSAndrew Geissler { 1562cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1563cb92c03bSAndrew Geissler { 1564cb92c03bSAndrew Geissler id = std::get_if<uint32_t>(&propertyMap.second); 1565cb92c03bSAndrew Geissler if (id == nullptr) 1566cb92c03bSAndrew Geissler { 1567*0f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1568cb92c03bSAndrew Geissler } 1569cb92c03bSAndrew Geissler } 1570cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1571cb92c03bSAndrew Geissler { 1572cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1573cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1574cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1575cb92c03bSAndrew Geissler { 1576*0f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1577271584abSEd Tanous continue; 1578cb92c03bSAndrew Geissler } 1579cb92c03bSAndrew Geissler // Retrieve Created property with format: 1580cb92c03bSAndrew Geissler // yyyy-mm-ddThh:mm:ss 1581cb92c03bSAndrew Geissler std::chrono::milliseconds chronoTimeStamp( 1582cb92c03bSAndrew Geissler *millisTimeStamp); 1583cb92c03bSAndrew Geissler timestamp = 1584271584abSEd Tanous std::chrono::duration_cast< 1585271584abSEd Tanous std::chrono::duration<int>>(chronoTimeStamp) 1586cb92c03bSAndrew Geissler .count(); 1587cb92c03bSAndrew Geissler } 1588cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1589cb92c03bSAndrew Geissler { 1590cb92c03bSAndrew Geissler severity = 1591cb92c03bSAndrew Geissler std::get_if<std::string>(&propertyMap.second); 1592cb92c03bSAndrew Geissler if (severity == nullptr) 1593cb92c03bSAndrew Geissler { 1594*0f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1595cb92c03bSAndrew Geissler } 1596cb92c03bSAndrew Geissler } 1597cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1598cb92c03bSAndrew Geissler { 1599cb92c03bSAndrew Geissler message = std::get_if<std::string>(&propertyMap.second); 1600cb92c03bSAndrew Geissler if (message == nullptr) 1601cb92c03bSAndrew Geissler { 1602*0f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1603cb92c03bSAndrew Geissler } 1604cb92c03bSAndrew Geissler } 1605cb92c03bSAndrew Geissler } 1606271584abSEd Tanous if (id == nullptr || message == nullptr || severity == nullptr) 1607271584abSEd Tanous { 1608271584abSEd Tanous return; 1609271584abSEd Tanous } 1610cb92c03bSAndrew Geissler asyncResp->res.jsonValue = { 1611cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1612cb92c03bSAndrew Geissler {"@odata.id", 1613cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1614cb92c03bSAndrew Geissler "Entries/" + 1615cb92c03bSAndrew Geissler std::to_string(*id)}, 161627062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1617cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1618cb92c03bSAndrew Geissler {"Message", *message}, 1619cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1620cb92c03bSAndrew Geissler {"Severity", translateSeverityDbusToRedfish(*severity)}, 162108a4e4b5SAnthony Wilson {"Created", crow::utility::getDateTime(timestamp)}}; 1622cb92c03bSAndrew Geissler }, 1623cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1624cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1625cb92c03bSAndrew Geissler "org.freedesktop.DBus.Properties", "GetAll", 1626cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry"); 1627c4bf6374SJason M. Bills } 1628336e96c6SChicago Duan 1629336e96c6SChicago Duan void doDelete(crow::Response& res, const crow::Request& req, 1630336e96c6SChicago Duan const std::vector<std::string>& params) override 1631336e96c6SChicago Duan { 1632336e96c6SChicago Duan 1633336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1634336e96c6SChicago Duan 1635336e96c6SChicago Duan auto asyncResp = std::make_shared<AsyncResp>(res); 1636336e96c6SChicago Duan 1637336e96c6SChicago Duan if (params.size() != 1) 1638336e96c6SChicago Duan { 1639336e96c6SChicago Duan messages::internalError(asyncResp->res); 1640336e96c6SChicago Duan return; 1641336e96c6SChicago Duan } 1642336e96c6SChicago Duan std::string entryID = params[0]; 1643336e96c6SChicago Duan 1644336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1645336e96c6SChicago Duan 1646336e96c6SChicago Duan // Process response from Logging service. 1647336e96c6SChicago Duan auto respHandler = [asyncResp](const boost::system::error_code ec) { 1648336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1649336e96c6SChicago Duan if (ec) 1650336e96c6SChicago Duan { 1651336e96c6SChicago Duan // TODO Handle for specific error code 1652336e96c6SChicago Duan BMCWEB_LOG_ERROR 1653336e96c6SChicago Duan << "EventLogEntry (DBus) doDelete respHandler got error " 1654336e96c6SChicago Duan << ec; 1655336e96c6SChicago Duan asyncResp->res.result( 1656336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1657336e96c6SChicago Duan return; 1658336e96c6SChicago Duan } 1659336e96c6SChicago Duan 1660336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1661336e96c6SChicago Duan }; 1662336e96c6SChicago Duan 1663336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1664336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1665336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1666336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1667336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 1668336e96c6SChicago Duan } 1669c4bf6374SJason M. Bills }; 1670c4bf6374SJason M. Bills 1671c4bf6374SJason M. Bills class BMCLogServiceCollection : public Node 1672c4bf6374SJason M. Bills { 1673c4bf6374SJason M. Bills public: 1674c4bf6374SJason M. Bills template <typename CrowApp> 1675c4bf6374SJason M. Bills BMCLogServiceCollection(CrowApp& app) : 16764ed77cd5SEd Tanous Node(app, "/redfish/v1/Managers/bmc/LogServices/") 16771da66f75SEd Tanous { 16781da66f75SEd Tanous entityPrivileges = { 1679e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1680e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1681e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1682e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1683e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1684e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 16851da66f75SEd Tanous } 16861da66f75SEd Tanous 16871da66f75SEd Tanous private: 16881da66f75SEd Tanous /** 16891da66f75SEd Tanous * Functions triggers appropriate requests on DBus 16901da66f75SEd Tanous */ 16911da66f75SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 16921da66f75SEd Tanous const std::vector<std::string>& params) override 16931da66f75SEd Tanous { 1694e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 16951da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 16961da66f75SEd Tanous // it has a duplicate entry for members 1697e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 16981da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1699e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1700e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 1701e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 1702e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 17031da66f75SEd Tanous "Collection of LogServices for this Manager"; 1704c4bf6374SJason M. Bills nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 1705c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 17065cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 17075cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 17085cb1dd27SAsmitha Karunanithi {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 17095cb1dd27SAsmitha Karunanithi #endif 1710c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1711c4bf6374SJason M. Bills logServiceArray.push_back( 171208a4e4b5SAnthony Wilson {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1713c4bf6374SJason M. Bills #endif 1714e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1715c4bf6374SJason M. Bills logServiceArray.size(); 17161da66f75SEd Tanous } 17171da66f75SEd Tanous }; 17181da66f75SEd Tanous 1719c4bf6374SJason M. Bills class BMCJournalLogService : public Node 17201da66f75SEd Tanous { 17211da66f75SEd Tanous public: 17221da66f75SEd Tanous template <typename CrowApp> 1723c4bf6374SJason M. Bills BMCJournalLogService(CrowApp& app) : 1724c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1725e1f26343SJason M. Bills { 1726e1f26343SJason M. Bills entityPrivileges = { 1727e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1728e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1729e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1730e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1731e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1732e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1733e1f26343SJason M. Bills } 1734e1f26343SJason M. Bills 1735e1f26343SJason M. Bills private: 1736e1f26343SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1737e1f26343SJason M. Bills const std::vector<std::string>& params) override 1738e1f26343SJason M. Bills { 1739e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1740e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1741e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 17420f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 17430f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 1744c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 1745c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 1746c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1747e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1748cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1749cd50aa42SJason M. Bills {"@odata.id", 1750086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 1751e1f26343SJason M. Bills } 1752e1f26343SJason M. Bills }; 1753e1f26343SJason M. Bills 1754c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 1755e1f26343SJason M. Bills sd_journal* journal, 1756c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 1757e1f26343SJason M. Bills { 1758e1f26343SJason M. Bills // Get the Log Entry contents 1759e1f26343SJason M. Bills int ret = 0; 1760e1f26343SJason M. Bills 176139e77504SEd Tanous std::string_view msg; 176216428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1763e1f26343SJason M. Bills if (ret < 0) 1764e1f26343SJason M. Bills { 1765e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1766e1f26343SJason M. Bills return 1; 1767e1f26343SJason M. Bills } 1768e1f26343SJason M. Bills 1769e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1770271584abSEd Tanous long int severity = 8; // Default to an invalid priority 177116428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1772e1f26343SJason M. Bills if (ret < 0) 1773e1f26343SJason M. Bills { 1774e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1775e1f26343SJason M. Bills } 1776e1f26343SJason M. Bills 1777e1f26343SJason M. Bills // Get the Created time from the timestamp 177816428a1aSJason M. Bills std::string entryTimeStr; 177916428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1780e1f26343SJason M. Bills { 178116428a1aSJason M. Bills return 1; 1782e1f26343SJason M. Bills } 1783e1f26343SJason M. Bills 1784e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1785c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 1786cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1787c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1788c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1789e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1790c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 179116428a1aSJason M. Bills {"Message", msg}, 1792e1f26343SJason M. Bills {"EntryType", "Oem"}, 1793e1f26343SJason M. Bills {"Severity", 1794b6a61a5eSJason M. Bills severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"}, 1795086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1796e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1797e1f26343SJason M. Bills return 0; 1798e1f26343SJason M. Bills } 1799e1f26343SJason M. Bills 1800c4bf6374SJason M. Bills class BMCJournalLogEntryCollection : public Node 1801e1f26343SJason M. Bills { 1802e1f26343SJason M. Bills public: 1803e1f26343SJason M. Bills template <typename CrowApp> 1804c4bf6374SJason M. Bills BMCJournalLogEntryCollection(CrowApp& app) : 1805c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1806e1f26343SJason M. Bills { 1807e1f26343SJason M. Bills entityPrivileges = { 1808e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1809e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1810e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1811e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1812e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1813e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1814e1f26343SJason M. Bills } 1815e1f26343SJason M. Bills 1816e1f26343SJason M. Bills private: 1817e1f26343SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1818e1f26343SJason M. Bills const std::vector<std::string>& params) override 1819e1f26343SJason M. Bills { 1820e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1821193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1822271584abSEd Tanous uint64_t skip = 0; 1823271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 182416428a1aSJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1825193ad2faSJason M. Bills { 1826193ad2faSJason M. Bills return; 1827193ad2faSJason M. Bills } 182816428a1aSJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1829193ad2faSJason M. Bills { 1830193ad2faSJason M. Bills return; 1831193ad2faSJason M. Bills } 1832e1f26343SJason M. Bills // Collections don't include the static data added by SubRoute because 1833e1f26343SJason M. Bills // it has a duplicate entry for members 1834e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1835e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 18360f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18370f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1838e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1839c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1840e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1841e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1842e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 18430f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18440f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries"; 1845e1f26343SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1846e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1847e1f26343SJason M. Bills 1848e1f26343SJason M. Bills // Go through the journal and use the timestamp to create a unique ID 1849e1f26343SJason M. Bills // for each entry 1850e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1851e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1852e1f26343SJason M. Bills if (ret < 0) 1853e1f26343SJason M. Bills { 1854e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1855f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1856e1f26343SJason M. Bills return; 1857e1f26343SJason M. Bills } 1858e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1859e1f26343SJason M. Bills journalTmp, sd_journal_close); 1860e1f26343SJason M. Bills journalTmp = nullptr; 1861b01bf299SEd Tanous uint64_t entryCount = 0; 1862e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1863e85d6b16SJason M. Bills bool firstEntry = true; 1864e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1865e1f26343SJason M. Bills { 1866193ad2faSJason M. Bills entryCount++; 1867193ad2faSJason M. Bills // Handle paging using skip (number of entries to skip from the 1868193ad2faSJason M. Bills // start) and top (number of entries to display) 1869193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1870193ad2faSJason M. Bills { 1871193ad2faSJason M. Bills continue; 1872193ad2faSJason M. Bills } 1873193ad2faSJason M. Bills 187416428a1aSJason M. Bills std::string idStr; 1875e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1876e1f26343SJason M. Bills { 1877e1f26343SJason M. Bills continue; 1878e1f26343SJason M. Bills } 1879e1f26343SJason M. Bills 1880e85d6b16SJason M. Bills if (firstEntry) 1881e85d6b16SJason M. Bills { 1882e85d6b16SJason M. Bills firstEntry = false; 1883e85d6b16SJason M. Bills } 1884e85d6b16SJason M. Bills 1885e1f26343SJason M. Bills logEntryArray.push_back({}); 1886c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 1887c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 1888c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 1889e1f26343SJason M. Bills { 1890f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1891e1f26343SJason M. Bills return; 1892e1f26343SJason M. Bills } 1893e1f26343SJason M. Bills } 1894193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1895193ad2faSJason M. Bills if (skip + top < entryCount) 1896193ad2faSJason M. Bills { 1897193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 1898c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 1899193ad2faSJason M. Bills std::to_string(skip + top); 1900193ad2faSJason M. Bills } 1901e1f26343SJason M. Bills } 1902e1f26343SJason M. Bills }; 1903e1f26343SJason M. Bills 1904c4bf6374SJason M. Bills class BMCJournalLogEntry : public Node 1905e1f26343SJason M. Bills { 1906e1f26343SJason M. Bills public: 1907c4bf6374SJason M. Bills BMCJournalLogEntry(CrowApp& app) : 1908c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/", 1909e1f26343SJason M. Bills std::string()) 1910e1f26343SJason M. Bills { 1911e1f26343SJason M. Bills entityPrivileges = { 1912e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1913e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1914e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1915e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1916e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1917e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1918e1f26343SJason M. Bills } 1919e1f26343SJason M. Bills 1920e1f26343SJason M. Bills private: 1921e1f26343SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1922e1f26343SJason M. Bills const std::vector<std::string>& params) override 1923e1f26343SJason M. Bills { 1924e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1925e1f26343SJason M. Bills if (params.size() != 1) 1926e1f26343SJason M. Bills { 1927f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1928e1f26343SJason M. Bills return; 1929e1f26343SJason M. Bills } 193016428a1aSJason M. Bills const std::string& entryID = params[0]; 1931e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 1932e1f26343SJason M. Bills uint64_t ts = 0; 1933271584abSEd Tanous uint64_t index = 0; 193416428a1aSJason M. Bills if (!getTimestampFromID(asyncResp->res, entryID, ts, index)) 1935e1f26343SJason M. Bills { 193616428a1aSJason M. Bills return; 1937e1f26343SJason M. Bills } 1938e1f26343SJason M. Bills 1939e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1940e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1941e1f26343SJason M. Bills if (ret < 0) 1942e1f26343SJason M. Bills { 1943e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1944f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1945e1f26343SJason M. Bills return; 1946e1f26343SJason M. Bills } 1947e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1948e1f26343SJason M. Bills journalTmp, sd_journal_close); 1949e1f26343SJason M. Bills journalTmp = nullptr; 1950e1f26343SJason M. Bills // Go to the timestamp in the log and move to the entry at the index 1951af07e3f5SJason M. Bills // tracking the unique ID 1952af07e3f5SJason M. Bills std::string idStr; 1953af07e3f5SJason M. Bills bool firstEntry = true; 1954e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 19552056b6d1SManojkiran Eda if (ret < 0) 19562056b6d1SManojkiran Eda { 19572056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 19582056b6d1SManojkiran Eda << strerror(-ret); 19592056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 19602056b6d1SManojkiran Eda return; 19612056b6d1SManojkiran Eda } 1962271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 1963e1f26343SJason M. Bills { 1964e1f26343SJason M. Bills sd_journal_next(journal.get()); 1965af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1966af07e3f5SJason M. Bills { 1967af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 1968af07e3f5SJason M. Bills return; 1969af07e3f5SJason M. Bills } 1970af07e3f5SJason M. Bills if (firstEntry) 1971af07e3f5SJason M. Bills { 1972af07e3f5SJason M. Bills firstEntry = false; 1973af07e3f5SJason M. Bills } 1974e1f26343SJason M. Bills } 1975c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 1976af07e3f5SJason M. Bills if (idStr != entryID) 1977c4bf6374SJason M. Bills { 1978c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 1979c4bf6374SJason M. Bills return; 1980c4bf6374SJason M. Bills } 1981c4bf6374SJason M. Bills 1982c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 1983e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 1984e1f26343SJason M. Bills { 1985f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1986e1f26343SJason M. Bills return; 1987e1f26343SJason M. Bills } 1988e1f26343SJason M. Bills } 1989e1f26343SJason M. Bills }; 1990e1f26343SJason M. Bills 19915cb1dd27SAsmitha Karunanithi class BMCDumpService : public Node 1992c9bb6861Sraviteja-b { 1993c9bb6861Sraviteja-b public: 1994c9bb6861Sraviteja-b template <typename CrowApp> 19955cb1dd27SAsmitha Karunanithi BMCDumpService(CrowApp& app) : 19965cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 1997c9bb6861Sraviteja-b { 1998c9bb6861Sraviteja-b entityPrivileges = { 1999c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2000c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2001c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2002c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2003c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2004c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2005c9bb6861Sraviteja-b } 2006c9bb6861Sraviteja-b 2007c9bb6861Sraviteja-b private: 2008c9bb6861Sraviteja-b void doGet(crow::Response& res, const crow::Request& req, 2009c9bb6861Sraviteja-b const std::vector<std::string>& params) override 2010c9bb6861Sraviteja-b { 2011c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2012c9bb6861Sraviteja-b 2013c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 20145cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 2015c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2016c9bb6861Sraviteja-b "#LogService.v1_1_0.LogService"; 2017c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 20185cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 20195cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2020c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2021c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 20225cb1dd27SAsmitha Karunanithi {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}}; 20235cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 20245cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 20255cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 20265cb1dd27SAsmitha Karunanithi "Actions/LogService.ClearLog"}}}, 20275cb1dd27SAsmitha Karunanithi {"Oem", 20285cb1dd27SAsmitha Karunanithi {{"#OemLogService.CollectDiagnosticData", 20295cb1dd27SAsmitha Karunanithi {{"target", 20305cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 20315cb1dd27SAsmitha Karunanithi "Actions/Oem/OemLogService.CollectDiagnosticData"}}}}}}; 2032c9bb6861Sraviteja-b } 2033c9bb6861Sraviteja-b }; 2034c9bb6861Sraviteja-b 20355cb1dd27SAsmitha Karunanithi class BMCDumpEntryCollection : public Node 2036c9bb6861Sraviteja-b { 2037c9bb6861Sraviteja-b public: 2038c9bb6861Sraviteja-b template <typename CrowApp> 20395cb1dd27SAsmitha Karunanithi BMCDumpEntryCollection(CrowApp& app) : 20405cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2041c9bb6861Sraviteja-b { 2042c9bb6861Sraviteja-b entityPrivileges = { 2043c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2044c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2045c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2046c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2047c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2048c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2049c9bb6861Sraviteja-b } 2050c9bb6861Sraviteja-b 2051c9bb6861Sraviteja-b private: 2052c9bb6861Sraviteja-b /** 2053c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2054c9bb6861Sraviteja-b */ 2055c9bb6861Sraviteja-b void doGet(crow::Response& res, const crow::Request& req, 2056c9bb6861Sraviteja-b const std::vector<std::string>& params) override 2057c9bb6861Sraviteja-b { 2058c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2059c9bb6861Sraviteja-b 2060c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2061c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2062c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 20635cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 20645cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2065c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 20665cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2067c9bb6861Sraviteja-b 20685cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 2069c9bb6861Sraviteja-b } 2070c9bb6861Sraviteja-b }; 2071c9bb6861Sraviteja-b 20725cb1dd27SAsmitha Karunanithi class BMCDumpEntry : public Node 2073c9bb6861Sraviteja-b { 2074c9bb6861Sraviteja-b public: 20755cb1dd27SAsmitha Karunanithi BMCDumpEntry(CrowApp& app) : 20765cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/", 2077c9bb6861Sraviteja-b std::string()) 2078c9bb6861Sraviteja-b { 2079c9bb6861Sraviteja-b entityPrivileges = { 2080c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2081c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2082c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2083c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2084c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2085c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2086c9bb6861Sraviteja-b } 2087c9bb6861Sraviteja-b 2088c9bb6861Sraviteja-b private: 2089c9bb6861Sraviteja-b void doGet(crow::Response& res, const crow::Request& req, 2090c9bb6861Sraviteja-b const std::vector<std::string>& params) override 2091c9bb6861Sraviteja-b { 2092c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2093c9bb6861Sraviteja-b if (params.size() != 1) 2094c9bb6861Sraviteja-b { 2095c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2096c9bb6861Sraviteja-b return; 2097c9bb6861Sraviteja-b } 20985cb1dd27SAsmitha Karunanithi getDumpEntryById(asyncResp, params[0], "BMC"); 2099c9bb6861Sraviteja-b } 2100c9bb6861Sraviteja-b 2101c9bb6861Sraviteja-b void doDelete(crow::Response& res, const crow::Request& req, 2102c9bb6861Sraviteja-b const std::vector<std::string>& params) override 2103c9bb6861Sraviteja-b { 21045cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2105c9bb6861Sraviteja-b if (params.size() != 1) 2106c9bb6861Sraviteja-b { 2107c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2108c9bb6861Sraviteja-b return; 2109c9bb6861Sraviteja-b } 21105cb1dd27SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, params[0]); 21115cb1dd27SAsmitha Karunanithi } 21125cb1dd27SAsmitha Karunanithi }; 2113c9bb6861Sraviteja-b 2114a43be80fSAsmitha Karunanithi class BMCDumpCreate : public Node 2115a43be80fSAsmitha Karunanithi { 2116a43be80fSAsmitha Karunanithi public: 2117a43be80fSAsmitha Karunanithi BMCDumpCreate(CrowApp& app) : 2118a43be80fSAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 2119a43be80fSAsmitha Karunanithi "Actions/Oem/" 2120a43be80fSAsmitha Karunanithi "OemLogService.CollectDiagnosticData/") 2121a43be80fSAsmitha Karunanithi { 2122a43be80fSAsmitha Karunanithi entityPrivileges = { 2123a43be80fSAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2124a43be80fSAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2125a43be80fSAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2126a43be80fSAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2127a43be80fSAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2128a43be80fSAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2129a43be80fSAsmitha Karunanithi } 2130a43be80fSAsmitha Karunanithi 2131a43be80fSAsmitha Karunanithi private: 2132a43be80fSAsmitha Karunanithi void doPost(crow::Response& res, const crow::Request& req, 2133a43be80fSAsmitha Karunanithi const std::vector<std::string>& params) override 2134a43be80fSAsmitha Karunanithi { 2135a43be80fSAsmitha Karunanithi createDump(res, req, "BMC"); 2136a43be80fSAsmitha Karunanithi } 2137a43be80fSAsmitha Karunanithi }; 2138a43be80fSAsmitha Karunanithi 213980319af1SAsmitha Karunanithi class BMCDumpClear : public Node 214080319af1SAsmitha Karunanithi { 214180319af1SAsmitha Karunanithi public: 214280319af1SAsmitha Karunanithi BMCDumpClear(CrowApp& app) : 214380319af1SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 214480319af1SAsmitha Karunanithi "Actions/" 214580319af1SAsmitha Karunanithi "LogService.ClearLog/") 214680319af1SAsmitha Karunanithi { 214780319af1SAsmitha Karunanithi entityPrivileges = { 214880319af1SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 214980319af1SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 215080319af1SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 215180319af1SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 215280319af1SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 215380319af1SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 215480319af1SAsmitha Karunanithi } 215580319af1SAsmitha Karunanithi 215680319af1SAsmitha Karunanithi private: 215780319af1SAsmitha Karunanithi void doPost(crow::Response& res, const crow::Request& req, 215880319af1SAsmitha Karunanithi const std::vector<std::string>& params) override 215980319af1SAsmitha Karunanithi { 216080319af1SAsmitha Karunanithi clearDump(res, "xyz.openbmc_project.Dump.Entry.BMC"); 216180319af1SAsmitha Karunanithi } 216280319af1SAsmitha Karunanithi }; 216380319af1SAsmitha Karunanithi 21645cb1dd27SAsmitha Karunanithi class SystemDumpService : public Node 2165c9bb6861Sraviteja-b { 21665cb1dd27SAsmitha Karunanithi public: 21675cb1dd27SAsmitha Karunanithi template <typename CrowApp> 21685cb1dd27SAsmitha Karunanithi SystemDumpService(CrowApp& app) : 21695cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/") 21705cb1dd27SAsmitha Karunanithi { 21715cb1dd27SAsmitha Karunanithi entityPrivileges = { 21725cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 21735cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 21745cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 21755cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 21765cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 21775cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 21785cb1dd27SAsmitha Karunanithi } 21795cb1dd27SAsmitha Karunanithi 21805cb1dd27SAsmitha Karunanithi private: 21815cb1dd27SAsmitha Karunanithi void doGet(crow::Response& res, const crow::Request& req, 21825cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 21835cb1dd27SAsmitha Karunanithi { 21845cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 21855cb1dd27SAsmitha Karunanithi 21865cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 21875cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 21885cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 21895cb1dd27SAsmitha Karunanithi "#LogService.v1_1_0.LogService"; 21905cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 21915cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "System Dump LogService"; 21925cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 21935cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 21945cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Entries"] = { 21955cb1dd27SAsmitha Karunanithi {"@odata.id", 21965cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"}}; 21975cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 21985cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 21995cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 22005cb1dd27SAsmitha Karunanithi "LogService.ClearLog"}}}, 22015cb1dd27SAsmitha Karunanithi {"Oem", 22025cb1dd27SAsmitha Karunanithi {{"#OemLogService.CollectDiagnosticData", 22035cb1dd27SAsmitha Karunanithi {{"target", 22045cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Actions/Oem/" 22055cb1dd27SAsmitha Karunanithi "OemLogService.CollectDiagnosticData"}}}}}}; 22065cb1dd27SAsmitha Karunanithi } 22075cb1dd27SAsmitha Karunanithi }; 22085cb1dd27SAsmitha Karunanithi 22095cb1dd27SAsmitha Karunanithi class SystemDumpEntryCollection : public Node 22105cb1dd27SAsmitha Karunanithi { 22115cb1dd27SAsmitha Karunanithi public: 22125cb1dd27SAsmitha Karunanithi template <typename CrowApp> 22135cb1dd27SAsmitha Karunanithi SystemDumpEntryCollection(CrowApp& app) : 22145cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 22155cb1dd27SAsmitha Karunanithi { 22165cb1dd27SAsmitha Karunanithi entityPrivileges = { 22175cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 22185cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 22195cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 22205cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 22215cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 22225cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 22235cb1dd27SAsmitha Karunanithi } 22245cb1dd27SAsmitha Karunanithi 22255cb1dd27SAsmitha Karunanithi private: 22265cb1dd27SAsmitha Karunanithi /** 22275cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 22285cb1dd27SAsmitha Karunanithi */ 22295cb1dd27SAsmitha Karunanithi void doGet(crow::Response& res, const crow::Request& req, 22305cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 22315cb1dd27SAsmitha Karunanithi { 22325cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22335cb1dd27SAsmitha Karunanithi 22345cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 22355cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 22365cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 22375cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 22385cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 22395cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 22405cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 22415cb1dd27SAsmitha Karunanithi 22425cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 22435cb1dd27SAsmitha Karunanithi } 22445cb1dd27SAsmitha Karunanithi }; 22455cb1dd27SAsmitha Karunanithi 22465cb1dd27SAsmitha Karunanithi class SystemDumpEntry : public Node 22475cb1dd27SAsmitha Karunanithi { 22485cb1dd27SAsmitha Karunanithi public: 22495cb1dd27SAsmitha Karunanithi SystemDumpEntry(CrowApp& app) : 22505cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/", 22515cb1dd27SAsmitha Karunanithi std::string()) 22525cb1dd27SAsmitha Karunanithi { 22535cb1dd27SAsmitha Karunanithi entityPrivileges = { 22545cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 22555cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 22565cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 22575cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 22585cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 22595cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 22605cb1dd27SAsmitha Karunanithi } 22615cb1dd27SAsmitha Karunanithi 22625cb1dd27SAsmitha Karunanithi private: 22635cb1dd27SAsmitha Karunanithi void doGet(crow::Response& res, const crow::Request& req, 22645cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 22655cb1dd27SAsmitha Karunanithi { 22665cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22675cb1dd27SAsmitha Karunanithi if (params.size() != 1) 22685cb1dd27SAsmitha Karunanithi { 2269c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2270c9bb6861Sraviteja-b return; 2271c9bb6861Sraviteja-b } 22725cb1dd27SAsmitha Karunanithi getDumpEntryById(asyncResp, params[0], "System"); 22735cb1dd27SAsmitha Karunanithi } 2274c9bb6861Sraviteja-b 22755cb1dd27SAsmitha Karunanithi void doDelete(crow::Response& res, const crow::Request& req, 22765cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 2277c9bb6861Sraviteja-b { 22785cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22795cb1dd27SAsmitha Karunanithi if (params.size() != 1) 2280c9bb6861Sraviteja-b { 22815cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 2282c9bb6861Sraviteja-b return; 2283c9bb6861Sraviteja-b } 22845cb1dd27SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, params[0]); 2285c9bb6861Sraviteja-b } 2286c9bb6861Sraviteja-b }; 2287c9bb6861Sraviteja-b 2288a43be80fSAsmitha Karunanithi class SystemDumpCreate : public Node 2289a43be80fSAsmitha Karunanithi { 2290a43be80fSAsmitha Karunanithi public: 2291a43be80fSAsmitha Karunanithi SystemDumpCreate(CrowApp& app) : 2292a43be80fSAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2293a43be80fSAsmitha Karunanithi "Actions/Oem/" 2294a43be80fSAsmitha Karunanithi "OemLogService.CollectDiagnosticData/") 2295a43be80fSAsmitha Karunanithi { 2296a43be80fSAsmitha Karunanithi entityPrivileges = { 2297a43be80fSAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2298a43be80fSAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2299a43be80fSAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2300a43be80fSAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2301a43be80fSAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2302a43be80fSAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2303a43be80fSAsmitha Karunanithi } 2304a43be80fSAsmitha Karunanithi 2305a43be80fSAsmitha Karunanithi private: 2306a43be80fSAsmitha Karunanithi void doPost(crow::Response& res, const crow::Request& req, 2307a43be80fSAsmitha Karunanithi const std::vector<std::string>& params) override 2308a43be80fSAsmitha Karunanithi { 2309a43be80fSAsmitha Karunanithi createDump(res, req, "System"); 2310a43be80fSAsmitha Karunanithi } 2311a43be80fSAsmitha Karunanithi }; 2312a43be80fSAsmitha Karunanithi 23130657843aSraviteja-b class SystemDumpEntryDownload : public Node 23140657843aSraviteja-b { 23150657843aSraviteja-b public: 23160657843aSraviteja-b SystemDumpEntryDownload(CrowApp& app) : 23170657843aSraviteja-b Node(app, 23180657843aSraviteja-b "/redfish/v1/Systems/system/LogServices/System/Entries/<str>/" 23190657843aSraviteja-b "Actions/" 23200657843aSraviteja-b "LogEntry.DownloadLog/", 23210657843aSraviteja-b std::string()) 23220657843aSraviteja-b { 23230657843aSraviteja-b entityPrivileges = { 23240657843aSraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 23250657843aSraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 23260657843aSraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 23270657843aSraviteja-b } 23280657843aSraviteja-b 23290657843aSraviteja-b private: 23300657843aSraviteja-b void doPost(crow::Response& res, const crow::Request& req, 23310657843aSraviteja-b const std::vector<std::string>& params) override 23320657843aSraviteja-b { 23330657843aSraviteja-b if (params.size() != 1) 23340657843aSraviteja-b { 23350657843aSraviteja-b messages::internalError(res); 23360657843aSraviteja-b return; 23370657843aSraviteja-b } 23380657843aSraviteja-b const std::string& entryID = params[0]; 23390657843aSraviteja-b crow::obmc_dump::handleDumpOffloadUrl(req, res, entryID); 23400657843aSraviteja-b } 23410657843aSraviteja-b }; 23420657843aSraviteja-b 2343013487e5Sraviteja-b class SystemDumpClear : public Node 2344013487e5Sraviteja-b { 2345013487e5Sraviteja-b public: 2346013487e5Sraviteja-b SystemDumpClear(CrowApp& app) : 234780319af1SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2348013487e5Sraviteja-b "Actions/" 2349013487e5Sraviteja-b "LogService.ClearLog/") 2350013487e5Sraviteja-b { 2351013487e5Sraviteja-b entityPrivileges = { 2352013487e5Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2353013487e5Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 235480319af1SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 235580319af1SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 235680319af1SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2357013487e5Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2358013487e5Sraviteja-b } 2359013487e5Sraviteja-b 2360013487e5Sraviteja-b private: 2361013487e5Sraviteja-b void doPost(crow::Response& res, const crow::Request& req, 2362013487e5Sraviteja-b const std::vector<std::string>& params) override 2363013487e5Sraviteja-b { 236480319af1SAsmitha Karunanithi clearDump(res, "xyz.openbmc_project.Dump.Entry.System"); 2365013487e5Sraviteja-b } 2366013487e5Sraviteja-b }; 2367013487e5Sraviteja-b 2368424c4176SJason M. Bills class CrashdumpService : public Node 2369e1f26343SJason M. Bills { 2370e1f26343SJason M. Bills public: 2371e1f26343SJason M. Bills template <typename CrowApp> 2372424c4176SJason M. Bills CrashdumpService(CrowApp& app) : 2373424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 23741da66f75SEd Tanous { 23753946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 23763946028dSAppaRao Puli // method for security reasons. 23771da66f75SEd Tanous entityPrivileges = { 23783946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 23793946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2380e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2381e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2382e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2383e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 23841da66f75SEd Tanous } 23851da66f75SEd Tanous 23861da66f75SEd Tanous private: 23871da66f75SEd Tanous /** 23881da66f75SEd Tanous * Functions triggers appropriate requests on DBus 23891da66f75SEd Tanous */ 23901da66f75SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 23911da66f75SEd Tanous const std::vector<std::string>& params) override 23921da66f75SEd Tanous { 2393e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 23941da66f75SEd Tanous // Copy over the static data to include the entries added by SubRoute 23950f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2396424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2397e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2398e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 23994f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 24004f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 24014f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2402e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2403e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 2404cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2405cd50aa42SJason M. Bills {"@odata.id", 2406424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 2407e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 24085b61b5e8SJason M. Bills {"#LogService.ClearLog", 24095b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 24105b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 24111da66f75SEd Tanous {"Oem", 2412424c4176SJason M. Bills {{"#Crashdump.OnDemand", 2413424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 24146eda7685SKenny L. Ku "Actions/Oem/Crashdump.OnDemand"}}}, 24156eda7685SKenny L. Ku {"#Crashdump.Telemetry", 24166eda7685SKenny L. Ku {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 24176eda7685SKenny L. Ku "Actions/Oem/Crashdump.Telemetry"}}}}}}; 24181da66f75SEd Tanous 24191da66f75SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI 2420e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"]["Oem"].push_back( 2421424c4176SJason M. Bills {"#Crashdump.SendRawPeci", 242208a4e4b5SAnthony Wilson {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 2423424c4176SJason M. Bills "Actions/Oem/Crashdump.SendRawPeci"}}}); 24241da66f75SEd Tanous #endif 24251da66f75SEd Tanous } 24261da66f75SEd Tanous }; 24271da66f75SEd Tanous 24285b61b5e8SJason M. Bills class CrashdumpClear : public Node 24295b61b5e8SJason M. Bills { 24305b61b5e8SJason M. Bills public: 24315b61b5e8SJason M. Bills CrashdumpClear(CrowApp& app) : 24325b61b5e8SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 24335b61b5e8SJason M. Bills "LogService.ClearLog/") 24345b61b5e8SJason M. Bills { 24353946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24363946028dSAppaRao Puli // method for security reasons. 24375b61b5e8SJason M. Bills entityPrivileges = { 24383946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 24393946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 24405b61b5e8SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 24415b61b5e8SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 24425b61b5e8SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 24435b61b5e8SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 24445b61b5e8SJason M. Bills } 24455b61b5e8SJason M. Bills 24465b61b5e8SJason M. Bills private: 24475b61b5e8SJason M. Bills void doPost(crow::Response& res, const crow::Request& req, 24485b61b5e8SJason M. Bills const std::vector<std::string>& params) override 24495b61b5e8SJason M. Bills { 24505b61b5e8SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 24515b61b5e8SJason M. Bills 24525b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 24535b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 24545b61b5e8SJason M. Bills const std::string& resp) { 24555b61b5e8SJason M. Bills if (ec) 24565b61b5e8SJason M. Bills { 24575b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 24585b61b5e8SJason M. Bills return; 24595b61b5e8SJason M. Bills } 24605b61b5e8SJason M. Bills messages::success(asyncResp->res); 24615b61b5e8SJason M. Bills }, 24625b61b5e8SJason M. Bills crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 24635b61b5e8SJason M. Bills } 24645b61b5e8SJason M. Bills }; 24655b61b5e8SJason M. Bills 2466e855dd28SJason M. Bills static void logCrashdumpEntry(std::shared_ptr<AsyncResp> asyncResp, 2467e855dd28SJason M. Bills const std::string& logID, 2468e855dd28SJason M. Bills nlohmann::json& logEntryJson) 2469e855dd28SJason M. Bills { 2470043a0536SJohnathan Mantey auto getStoredLogCallback = 2471043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 2472e855dd28SJason M. Bills const boost::system::error_code ec, 2473043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params) { 2474e855dd28SJason M. Bills if (ec) 2475e855dd28SJason M. Bills { 2476e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 24771ddcf01aSJason M. Bills if (ec.value() == 24781ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 24791ddcf01aSJason M. Bills { 2480043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2481043a0536SJohnathan Mantey logID); 24821ddcf01aSJason M. Bills } 24831ddcf01aSJason M. Bills else 24841ddcf01aSJason M. Bills { 2485e855dd28SJason M. Bills messages::internalError(asyncResp->res); 24861ddcf01aSJason M. Bills } 2487e855dd28SJason M. Bills return; 2488e855dd28SJason M. Bills } 2489043a0536SJohnathan Mantey 2490043a0536SJohnathan Mantey std::string timestamp{}; 2491043a0536SJohnathan Mantey std::string filename{}; 2492043a0536SJohnathan Mantey std::string logfile{}; 2493043a0536SJohnathan Mantey ParseCrashdumpParameters(params, filename, timestamp, logfile); 2494043a0536SJohnathan Mantey 2495043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2496e855dd28SJason M. Bills { 2497043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 2498e855dd28SJason M. Bills return; 2499e855dd28SJason M. Bills } 2500e855dd28SJason M. Bills 2501043a0536SJohnathan Mantey std::string crashdumpURI = 2502e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2503043a0536SJohnathan Mantey logID + "/" + filename; 2504043a0536SJohnathan Mantey logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 2505043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 2506043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 2507e855dd28SJason M. Bills logID}, 2508e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2509e855dd28SJason M. Bills {"Id", logID}, 2510e855dd28SJason M. Bills {"EntryType", "Oem"}, 2511e855dd28SJason M. Bills {"OemRecordFormat", "Crashdump URI"}, 2512043a0536SJohnathan Mantey {"Message", std::move(crashdumpURI)}, 2513043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2514e855dd28SJason M. Bills }; 2515e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 25165b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 25175b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2518043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2519e855dd28SJason M. Bills } 2520e855dd28SJason M. Bills 2521424c4176SJason M. Bills class CrashdumpEntryCollection : public Node 25221da66f75SEd Tanous { 25231da66f75SEd Tanous public: 25241da66f75SEd Tanous template <typename CrowApp> 2525424c4176SJason M. Bills CrashdumpEntryCollection(CrowApp& app) : 2526424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 25271da66f75SEd Tanous { 25283946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25293946028dSAppaRao Puli // method for security reasons. 25301da66f75SEd Tanous entityPrivileges = { 25313946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 25323946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2533e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2534e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2535e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2536e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 25371da66f75SEd Tanous } 25381da66f75SEd Tanous 25391da66f75SEd Tanous private: 25401da66f75SEd Tanous /** 25411da66f75SEd Tanous * Functions triggers appropriate requests on DBus 25421da66f75SEd Tanous */ 25431da66f75SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 25441da66f75SEd Tanous const std::vector<std::string>& params) override 25451da66f75SEd Tanous { 2546e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 25471da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 25481da66f75SEd Tanous // it has a duplicate entry for members 2549e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2550e1f26343SJason M. Bills const boost::system::error_code ec, 25511da66f75SEd Tanous const std::vector<std::string>& resp) { 25521da66f75SEd Tanous if (ec) 25531da66f75SEd Tanous { 25541da66f75SEd Tanous if (ec.value() != 25551da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 25561da66f75SEd Tanous { 25571da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 25581da66f75SEd Tanous << ec.message(); 2559f12894f8SJason M. Bills messages::internalError(asyncResp->res); 25601da66f75SEd Tanous return; 25611da66f75SEd Tanous } 25621da66f75SEd Tanous } 2563e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 25641da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 25650f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2566424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2567424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2568e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2569424c4176SJason M. Bills "Collection of Crashdump Entries"; 2570e1f26343SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2571e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2572e855dd28SJason M. Bills std::vector<std::string> logIDs; 2573e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2574e855dd28SJason M. Bills // enough to hold them 25751da66f75SEd Tanous for (const std::string& objpath : resp) 25761da66f75SEd Tanous { 2577e855dd28SJason M. Bills // Get the log ID 25784ed77cd5SEd Tanous std::size_t lastPos = objpath.rfind("/"); 2579e855dd28SJason M. Bills if (lastPos == std::string::npos) 25801da66f75SEd Tanous { 2581e855dd28SJason M. Bills continue; 25821da66f75SEd Tanous } 2583e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2584e855dd28SJason M. Bills 2585e855dd28SJason M. Bills // Add a space for the log entry to the array 2586e855dd28SJason M. Bills logEntryArray.push_back({}); 2587e855dd28SJason M. Bills } 2588e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2589e855dd28SJason M. Bills size_t index = 0; 2590e855dd28SJason M. Bills for (const std::string& logID : logIDs) 2591e855dd28SJason M. Bills { 2592e855dd28SJason M. Bills // Add the log entry to the array 2593e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 25941da66f75SEd Tanous } 2595e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2596e1f26343SJason M. Bills logEntryArray.size(); 25971da66f75SEd Tanous }; 25981da66f75SEd Tanous crow::connections::systemBus->async_method_call( 25991da66f75SEd Tanous std::move(getLogEntriesCallback), 26001da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 26011da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 26021da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 26035b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 26041da66f75SEd Tanous } 26051da66f75SEd Tanous }; 26061da66f75SEd Tanous 2607424c4176SJason M. Bills class CrashdumpEntry : public Node 26081da66f75SEd Tanous { 26091da66f75SEd Tanous public: 2610424c4176SJason M. Bills CrashdumpEntry(CrowApp& app) : 2611d53dd41fSJason M. Bills Node(app, 2612424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/", 26131da66f75SEd Tanous std::string()) 26141da66f75SEd Tanous { 26153946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 26163946028dSAppaRao Puli // method for security reasons. 26171da66f75SEd Tanous entityPrivileges = { 26183946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 26193946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2620e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2621e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2622e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2623e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 26241da66f75SEd Tanous } 26251da66f75SEd Tanous 26261da66f75SEd Tanous private: 26271da66f75SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 26281da66f75SEd Tanous const std::vector<std::string>& params) override 26291da66f75SEd Tanous { 2630e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 26311da66f75SEd Tanous if (params.size() != 1) 26321da66f75SEd Tanous { 2633f12894f8SJason M. Bills messages::internalError(asyncResp->res); 26341da66f75SEd Tanous return; 26351da66f75SEd Tanous } 2636e855dd28SJason M. Bills const std::string& logID = params[0]; 2637e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 2638e855dd28SJason M. Bills } 2639e855dd28SJason M. Bills }; 2640e855dd28SJason M. Bills 2641e855dd28SJason M. Bills class CrashdumpFile : public Node 2642e855dd28SJason M. Bills { 2643e855dd28SJason M. Bills public: 2644e855dd28SJason M. Bills CrashdumpFile(CrowApp& app) : 2645e855dd28SJason M. Bills Node(app, 2646e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/" 2647e855dd28SJason M. Bills "<str>/", 2648e855dd28SJason M. Bills std::string(), std::string()) 2649e855dd28SJason M. Bills { 26503946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 26513946028dSAppaRao Puli // method for security reasons. 2652e855dd28SJason M. Bills entityPrivileges = { 26533946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 26543946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2655e855dd28SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2656e855dd28SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2657e855dd28SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2658e855dd28SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2659e855dd28SJason M. Bills } 2660e855dd28SJason M. Bills 2661e855dd28SJason M. Bills private: 2662e855dd28SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 2663e855dd28SJason M. Bills const std::vector<std::string>& params) override 2664e855dd28SJason M. Bills { 2665e855dd28SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2666e855dd28SJason M. Bills if (params.size() != 2) 2667e855dd28SJason M. Bills { 2668e855dd28SJason M. Bills messages::internalError(asyncResp->res); 2669e855dd28SJason M. Bills return; 2670e855dd28SJason M. Bills } 2671e855dd28SJason M. Bills const std::string& logID = params[0]; 2672e855dd28SJason M. Bills const std::string& fileName = params[1]; 2673e855dd28SJason M. Bills 2674043a0536SJohnathan Mantey auto getStoredLogCallback = 2675043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 2676abf2add6SEd Tanous const boost::system::error_code ec, 2677043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& resp) { 26781da66f75SEd Tanous if (ec) 26791da66f75SEd Tanous { 2680043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2681043a0536SJohnathan Mantey << ec.message(); 2682f12894f8SJason M. Bills messages::internalError(asyncResp->res); 26831da66f75SEd Tanous return; 26841da66f75SEd Tanous } 2685e855dd28SJason M. Bills 2686043a0536SJohnathan Mantey std::string dbusFilename{}; 2687043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2688043a0536SJohnathan Mantey std::string dbusFilepath{}; 2689043a0536SJohnathan Mantey 2690043a0536SJohnathan Mantey ParseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 2691043a0536SJohnathan Mantey dbusFilepath); 2692043a0536SJohnathan Mantey 2693043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2694043a0536SJohnathan Mantey dbusFilepath.empty()) 26951da66f75SEd Tanous { 2696e855dd28SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, fileName); 26971da66f75SEd Tanous return; 26981da66f75SEd Tanous } 2699e855dd28SJason M. Bills 2700043a0536SJohnathan Mantey // Verify the file name parameter is correct 2701043a0536SJohnathan Mantey if (fileName != dbusFilename) 2702043a0536SJohnathan Mantey { 2703043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2704043a0536SJohnathan Mantey return; 2705043a0536SJohnathan Mantey } 2706043a0536SJohnathan Mantey 2707043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2708043a0536SJohnathan Mantey { 2709043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2710043a0536SJohnathan Mantey return; 2711043a0536SJohnathan Mantey } 2712043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 2713043a0536SJohnathan Mantey std::ios::binary | 2714043a0536SJohnathan Mantey std::ios::ate); 2715043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 2716043a0536SJohnathan Mantey if (fileSize < 0) 2717043a0536SJohnathan Mantey { 2718043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 2719043a0536SJohnathan Mantey return; 2720043a0536SJohnathan Mantey } 2721043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 2722043a0536SJohnathan Mantey 2723043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 2724043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 2725043a0536SJohnathan Mantey 2726043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 2727043a0536SJohnathan Mantey 2728043a0536SJohnathan Mantey // The cast to std::string is intentional in order to use the 2729043a0536SJohnathan Mantey // assign() that applies move mechanics 2730043a0536SJohnathan Mantey asyncResp->res.body().assign( 2731043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 2732043a0536SJohnathan Mantey 2733043a0536SJohnathan Mantey // Configure this to be a file download when accessed from 2734043a0536SJohnathan Mantey // a browser 2735e855dd28SJason M. Bills asyncResp->res.addHeader("Content-Disposition", "attachment"); 27361da66f75SEd Tanous }; 27371da66f75SEd Tanous crow::connections::systemBus->async_method_call( 27385b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 27395b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2740043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 27411da66f75SEd Tanous } 27421da66f75SEd Tanous }; 27431da66f75SEd Tanous 2744424c4176SJason M. Bills class OnDemandCrashdump : public Node 27451da66f75SEd Tanous { 27461da66f75SEd Tanous public: 2747424c4176SJason M. Bills OnDemandCrashdump(CrowApp& app) : 2748424c4176SJason M. Bills Node(app, 2749424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2750424c4176SJason M. Bills "Crashdump.OnDemand/") 27511da66f75SEd Tanous { 27523946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 27533946028dSAppaRao Puli // method for security reasons. 27541da66f75SEd Tanous entityPrivileges = { 27553946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 27563946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 27573946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 27583946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 27593946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 27603946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 27611da66f75SEd Tanous } 27621da66f75SEd Tanous 27631da66f75SEd Tanous private: 27641da66f75SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 27651da66f75SEd Tanous const std::vector<std::string>& params) override 27661da66f75SEd Tanous { 2767e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 27681da66f75SEd Tanous 2769fe306728SJames Feist auto generateonDemandLogCallback = [asyncResp, 2770fe306728SJames Feist req](const boost::system::error_code 277146229577SJames Feist ec, 27721da66f75SEd Tanous const std::string& resp) { 27731da66f75SEd Tanous if (ec) 27741da66f75SEd Tanous { 277546229577SJames Feist if (ec.value() == boost::system::errc::operation_not_supported) 27761da66f75SEd Tanous { 2777f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 27781da66f75SEd Tanous } 27794363d3b2SJason M. Bills else if (ec.value() == 27804363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 27814363d3b2SJason M. Bills { 27824363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 27834363d3b2SJason M. Bills "60"); 27844363d3b2SJason M. Bills } 27851da66f75SEd Tanous else 27861da66f75SEd Tanous { 2787f12894f8SJason M. Bills messages::internalError(asyncResp->res); 27881da66f75SEd Tanous } 27891da66f75SEd Tanous return; 27901da66f75SEd Tanous } 279146229577SJames Feist std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 279266afe4faSJames Feist [](boost::system::error_code err, sdbusplus::message::message&, 279366afe4faSJames Feist const std::shared_ptr<task::TaskData>& taskData) { 279466afe4faSJames Feist if (!err) 279566afe4faSJames Feist { 2796e5d5006bSJames Feist taskData->messages.emplace_back( 2797e5d5006bSJames Feist messages::taskCompletedOK( 2798e5d5006bSJames Feist std::to_string(taskData->index))); 2799831d6b09SJames Feist taskData->state = "Completed"; 280066afe4faSJames Feist } 280132898ceaSJames Feist return task::completed; 280266afe4faSJames Feist }, 280346229577SJames Feist "type='signal',interface='org.freedesktop.DBus.Properties'," 280446229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 280546229577SJames Feist "crashdump'"); 280646229577SJames Feist task->startTimer(std::chrono::minutes(5)); 280746229577SJames Feist task->populateResp(asyncResp->res); 2808fe306728SJames Feist task->payload.emplace(req); 28091da66f75SEd Tanous }; 28101da66f75SEd Tanous crow::connections::systemBus->async_method_call( 28115b61b5e8SJason M. Bills std::move(generateonDemandLogCallback), crashdumpObject, 28125b61b5e8SJason M. Bills crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog"); 28131da66f75SEd Tanous } 28141da66f75SEd Tanous }; 28151da66f75SEd Tanous 28166eda7685SKenny L. Ku class TelemetryCrashdump : public Node 28176eda7685SKenny L. Ku { 28186eda7685SKenny L. Ku public: 28196eda7685SKenny L. Ku TelemetryCrashdump(CrowApp& app) : 28206eda7685SKenny L. Ku Node(app, 28216eda7685SKenny L. Ku "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 28226eda7685SKenny L. Ku "Crashdump.Telemetry/") 28236eda7685SKenny L. Ku { 28246eda7685SKenny L. Ku // Note: Deviated from redfish privilege registry for GET & HEAD 28256eda7685SKenny L. Ku // method for security reasons. 28266eda7685SKenny L. Ku entityPrivileges = { 28276eda7685SKenny L. Ku {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 28286eda7685SKenny L. Ku {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 28296eda7685SKenny L. Ku {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 28306eda7685SKenny L. Ku {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 28316eda7685SKenny L. Ku {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 28326eda7685SKenny L. Ku {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 28336eda7685SKenny L. Ku } 28346eda7685SKenny L. Ku 28356eda7685SKenny L. Ku private: 28366eda7685SKenny L. Ku void doPost(crow::Response& res, const crow::Request& req, 28376eda7685SKenny L. Ku const std::vector<std::string>& params) override 28386eda7685SKenny L. Ku { 28396eda7685SKenny L. Ku std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 28406eda7685SKenny L. Ku 28416eda7685SKenny L. Ku auto generateTelemetryLogCallback = [asyncResp, req]( 28426eda7685SKenny L. Ku const boost::system::error_code 28436eda7685SKenny L. Ku ec, 28446eda7685SKenny L. Ku const std::string& resp) { 28456eda7685SKenny L. Ku if (ec) 28466eda7685SKenny L. Ku { 28476eda7685SKenny L. Ku if (ec.value() == boost::system::errc::operation_not_supported) 28486eda7685SKenny L. Ku { 28496eda7685SKenny L. Ku messages::resourceInStandby(asyncResp->res); 28506eda7685SKenny L. Ku } 28516eda7685SKenny L. Ku else if (ec.value() == 28526eda7685SKenny L. Ku boost::system::errc::device_or_resource_busy) 28536eda7685SKenny L. Ku { 28546eda7685SKenny L. Ku messages::serviceTemporarilyUnavailable(asyncResp->res, 28556eda7685SKenny L. Ku "60"); 28566eda7685SKenny L. Ku } 28576eda7685SKenny L. Ku else 28586eda7685SKenny L. Ku { 28596eda7685SKenny L. Ku messages::internalError(asyncResp->res); 28606eda7685SKenny L. Ku } 28616eda7685SKenny L. Ku return; 28626eda7685SKenny L. Ku } 28636eda7685SKenny L. Ku std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 28646eda7685SKenny L. Ku [](boost::system::error_code err, sdbusplus::message::message&, 28656eda7685SKenny L. Ku const std::shared_ptr<task::TaskData>& taskData) { 28666eda7685SKenny L. Ku if (!err) 28676eda7685SKenny L. Ku { 28686eda7685SKenny L. Ku taskData->messages.emplace_back( 28696eda7685SKenny L. Ku messages::taskCompletedOK( 28706eda7685SKenny L. Ku std::to_string(taskData->index))); 28716eda7685SKenny L. Ku taskData->state = "Completed"; 28726eda7685SKenny L. Ku } 28736eda7685SKenny L. Ku return task::completed; 28746eda7685SKenny L. Ku }, 28756eda7685SKenny L. Ku "type='signal',interface='org.freedesktop.DBus.Properties'," 28766eda7685SKenny L. Ku "member='PropertiesChanged',arg0namespace='com.intel." 28776eda7685SKenny L. Ku "crashdump'"); 28786eda7685SKenny L. Ku task->startTimer(std::chrono::minutes(5)); 28796eda7685SKenny L. Ku task->populateResp(asyncResp->res); 28806eda7685SKenny L. Ku task->payload.emplace(req); 28816eda7685SKenny L. Ku }; 28826eda7685SKenny L. Ku crow::connections::systemBus->async_method_call( 28836eda7685SKenny L. Ku std::move(generateTelemetryLogCallback), crashdumpObject, 28846eda7685SKenny L. Ku crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog"); 28856eda7685SKenny L. Ku } 28866eda7685SKenny L. Ku }; 28876eda7685SKenny L. Ku 2888e1f26343SJason M. Bills class SendRawPECI : public Node 28891da66f75SEd Tanous { 28901da66f75SEd Tanous public: 2891e1f26343SJason M. Bills SendRawPECI(CrowApp& app) : 2892424c4176SJason M. Bills Node(app, 2893424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2894424c4176SJason M. Bills "Crashdump.SendRawPeci/") 28951da66f75SEd Tanous { 28963946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28973946028dSAppaRao Puli // method for security reasons. 28981da66f75SEd Tanous entityPrivileges = { 28991da66f75SEd Tanous {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 29001da66f75SEd Tanous {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 29011da66f75SEd Tanous {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 29021da66f75SEd Tanous {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 29031da66f75SEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 29041da66f75SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 29051da66f75SEd Tanous } 29061da66f75SEd Tanous 29071da66f75SEd Tanous private: 29081da66f75SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 29091da66f75SEd Tanous const std::vector<std::string>& params) override 29101da66f75SEd Tanous { 2911e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 29128724c297SKarthick Sundarrajan std::vector<std::vector<uint8_t>> peciCommands; 29138724c297SKarthick Sundarrajan 29148724c297SKarthick Sundarrajan nlohmann::json reqJson = 29158724c297SKarthick Sundarrajan nlohmann::json::parse(req.body, nullptr, false); 29168724c297SKarthick Sundarrajan if (reqJson.find("PECICommands") != reqJson.end()) 29178724c297SKarthick Sundarrajan { 29188724c297SKarthick Sundarrajan if (!json_util::readJson(req, res, "PECICommands", peciCommands)) 29198724c297SKarthick Sundarrajan { 29208724c297SKarthick Sundarrajan return; 29218724c297SKarthick Sundarrajan } 29228724c297SKarthick Sundarrajan uint32_t idx = 0; 29238724c297SKarthick Sundarrajan for (auto const& cmd : peciCommands) 29248724c297SKarthick Sundarrajan { 29258724c297SKarthick Sundarrajan if (cmd.size() < 3) 29268724c297SKarthick Sundarrajan { 29278724c297SKarthick Sundarrajan std::string s("["); 29288724c297SKarthick Sundarrajan for (auto const& val : cmd) 29298724c297SKarthick Sundarrajan { 29308724c297SKarthick Sundarrajan if (val != *cmd.begin()) 29318724c297SKarthick Sundarrajan { 29328724c297SKarthick Sundarrajan s += ","; 29338724c297SKarthick Sundarrajan } 29348724c297SKarthick Sundarrajan s += std::to_string(val); 29358724c297SKarthick Sundarrajan } 29368724c297SKarthick Sundarrajan s += "]"; 29378724c297SKarthick Sundarrajan messages::actionParameterValueFormatError( 29388724c297SKarthick Sundarrajan res, s, "PECICommands[" + std::to_string(idx) + "]", 29398724c297SKarthick Sundarrajan "SendRawPeci"); 29408724c297SKarthick Sundarrajan return; 29418724c297SKarthick Sundarrajan } 29428724c297SKarthick Sundarrajan idx++; 29438724c297SKarthick Sundarrajan } 29448724c297SKarthick Sundarrajan } 29458724c297SKarthick Sundarrajan else 29468724c297SKarthick Sundarrajan { 29478724c297SKarthick Sundarrajan /* This interface is deprecated */ 2948b1556427SEd Tanous uint8_t clientAddress = 0; 2949b1556427SEd Tanous uint8_t readLength = 0; 29501da66f75SEd Tanous std::vector<uint8_t> peciCommand; 2951b1556427SEd Tanous if (!json_util::readJson(req, res, "ClientAddress", clientAddress, 2952b1556427SEd Tanous "ReadLength", readLength, "PECICommand", 2953b1556427SEd Tanous peciCommand)) 29541da66f75SEd Tanous { 29551da66f75SEd Tanous return; 29561da66f75SEd Tanous } 29578724c297SKarthick Sundarrajan peciCommands.push_back({clientAddress, 0, readLength}); 29588724c297SKarthick Sundarrajan peciCommands[0].insert(peciCommands[0].end(), peciCommand.begin(), 29598724c297SKarthick Sundarrajan peciCommand.end()); 29608724c297SKarthick Sundarrajan } 29611da66f75SEd Tanous // Callback to return the Raw PECI response 2962e1f26343SJason M. Bills auto sendRawPECICallback = 2963e1f26343SJason M. Bills [asyncResp](const boost::system::error_code ec, 29648724c297SKarthick Sundarrajan const std::vector<std::vector<uint8_t>>& resp) { 29651da66f75SEd Tanous if (ec) 29661da66f75SEd Tanous { 29678724c297SKarthick Sundarrajan BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: " 29681da66f75SEd Tanous << ec.message(); 2969f12894f8SJason M. Bills messages::internalError(asyncResp->res); 29701da66f75SEd Tanous return; 29711da66f75SEd Tanous } 2972e1f26343SJason M. Bills asyncResp->res.jsonValue = {{"Name", "PECI Command Response"}, 29731da66f75SEd Tanous {"PECIResponse", resp}}; 29741da66f75SEd Tanous }; 29751da66f75SEd Tanous // Call the SendRawPECI command with the provided data 29761da66f75SEd Tanous crow::connections::systemBus->async_method_call( 29775b61b5e8SJason M. Bills std::move(sendRawPECICallback), crashdumpObject, crashdumpPath, 29788724c297SKarthick Sundarrajan crashdumpRawPECIInterface, "SendRawPeci", peciCommands); 29791da66f75SEd Tanous } 29801da66f75SEd Tanous }; 29811da66f75SEd Tanous 2982cb92c03bSAndrew Geissler /** 2983cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2984cb92c03bSAndrew Geissler */ 2985cb92c03bSAndrew Geissler class DBusLogServiceActionsClear : public Node 2986cb92c03bSAndrew Geissler { 2987cb92c03bSAndrew Geissler public: 2988cb92c03bSAndrew Geissler DBusLogServiceActionsClear(CrowApp& app) : 2989cb92c03bSAndrew Geissler Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 29907af91514SGunnar Mills "LogService.ClearLog/") 2991cb92c03bSAndrew Geissler { 2992cb92c03bSAndrew Geissler entityPrivileges = { 2993cb92c03bSAndrew Geissler {boost::beast::http::verb::get, {{"Login"}}}, 2994cb92c03bSAndrew Geissler {boost::beast::http::verb::head, {{"Login"}}}, 2995cb92c03bSAndrew Geissler {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2996cb92c03bSAndrew Geissler {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2997cb92c03bSAndrew Geissler {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2998cb92c03bSAndrew Geissler {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2999cb92c03bSAndrew Geissler } 3000cb92c03bSAndrew Geissler 3001cb92c03bSAndrew Geissler private: 3002cb92c03bSAndrew Geissler /** 3003cb92c03bSAndrew Geissler * Function handles POST method request. 3004cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 3005cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 3006cb92c03bSAndrew Geissler */ 3007cb92c03bSAndrew Geissler void doPost(crow::Response& res, const crow::Request& req, 3008cb92c03bSAndrew Geissler const std::vector<std::string>& params) override 3009cb92c03bSAndrew Geissler { 3010cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 3011cb92c03bSAndrew Geissler 3012cb92c03bSAndrew Geissler auto asyncResp = std::make_shared<AsyncResp>(res); 3013cb92c03bSAndrew Geissler // Process response from Logging service. 3014cb92c03bSAndrew Geissler auto resp_handler = [asyncResp](const boost::system::error_code ec) { 3015cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 3016cb92c03bSAndrew Geissler if (ec) 3017cb92c03bSAndrew Geissler { 3018cb92c03bSAndrew Geissler // TODO Handle for specific error code 3019cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 3020cb92c03bSAndrew Geissler asyncResp->res.result( 3021cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 3022cb92c03bSAndrew Geissler return; 3023cb92c03bSAndrew Geissler } 3024cb92c03bSAndrew Geissler 3025cb92c03bSAndrew Geissler asyncResp->res.result(boost::beast::http::status::no_content); 3026cb92c03bSAndrew Geissler }; 3027cb92c03bSAndrew Geissler 3028cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 3029cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 3030cb92c03bSAndrew Geissler resp_handler, "xyz.openbmc_project.Logging", 3031cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 3032cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 3033cb92c03bSAndrew Geissler } 3034cb92c03bSAndrew Geissler }; 3035a3316fc6SZhikuiRen 3036a3316fc6SZhikuiRen /**************************************************** 3037a3316fc6SZhikuiRen * Redfish PostCode interfaces 3038a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 3039a3316fc6SZhikuiRen ******************************************************/ 3040a3316fc6SZhikuiRen class PostCodesLogService : public Node 3041a3316fc6SZhikuiRen { 3042a3316fc6SZhikuiRen public: 3043a3316fc6SZhikuiRen PostCodesLogService(CrowApp& app) : 3044a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 3045a3316fc6SZhikuiRen { 3046a3316fc6SZhikuiRen entityPrivileges = { 3047a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3048a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3049a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3050a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3051a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3052a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3053a3316fc6SZhikuiRen } 3054a3316fc6SZhikuiRen 3055a3316fc6SZhikuiRen private: 3056a3316fc6SZhikuiRen void doGet(crow::Response& res, const crow::Request& req, 3057a3316fc6SZhikuiRen const std::vector<std::string>& params) override 3058a3316fc6SZhikuiRen { 3059a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3060a3316fc6SZhikuiRen 3061a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 3062a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"}, 3063a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 3064a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogService.LogService"}, 3065a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 3066a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 3067a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 3068a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 3069a3316fc6SZhikuiRen {"Entries", 3070a3316fc6SZhikuiRen {{"@odata.id", 3071a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}}; 3072a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 3073a3316fc6SZhikuiRen {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/" 3074a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 3075a3316fc6SZhikuiRen } 3076a3316fc6SZhikuiRen }; 3077a3316fc6SZhikuiRen 3078a3316fc6SZhikuiRen class PostCodesClear : public Node 3079a3316fc6SZhikuiRen { 3080a3316fc6SZhikuiRen public: 3081a3316fc6SZhikuiRen PostCodesClear(CrowApp& app) : 3082a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 3083a3316fc6SZhikuiRen "LogService.ClearLog/") 3084a3316fc6SZhikuiRen { 3085a3316fc6SZhikuiRen entityPrivileges = { 3086a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3087a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 30883946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 30893946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 30903946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 30913946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 3092a3316fc6SZhikuiRen } 3093a3316fc6SZhikuiRen 3094a3316fc6SZhikuiRen private: 3095a3316fc6SZhikuiRen void doPost(crow::Response& res, const crow::Request& req, 3096a3316fc6SZhikuiRen const std::vector<std::string>& params) override 3097a3316fc6SZhikuiRen { 3098a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3099a3316fc6SZhikuiRen 3100a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3101a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3102a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3103a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3104a3316fc6SZhikuiRen if (ec) 3105a3316fc6SZhikuiRen { 3106a3316fc6SZhikuiRen // TODO Handle for specific error code 3107a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 3108a3316fc6SZhikuiRen << "doClearPostCodes resp_handler got error " << ec; 3109a3316fc6SZhikuiRen asyncResp->res.result( 3110a3316fc6SZhikuiRen boost::beast::http::status::internal_server_error); 3111a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3112a3316fc6SZhikuiRen return; 3113a3316fc6SZhikuiRen } 3114a3316fc6SZhikuiRen }, 3115a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3116a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3117a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 3118a3316fc6SZhikuiRen } 3119a3316fc6SZhikuiRen }; 3120a3316fc6SZhikuiRen 3121a3316fc6SZhikuiRen static void fillPostCodeEntry( 3122a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> aResp, 3123a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode, 3124a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3125a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3126a3316fc6SZhikuiRen { 3127a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3128a3316fc6SZhikuiRen const message_registries::Message* message = 3129a3316fc6SZhikuiRen message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode"); 3130a3316fc6SZhikuiRen 3131a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3132a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 3133a3316fc6SZhikuiRen 3134a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 3135a3316fc6SZhikuiRen for (const std::pair<uint64_t, uint64_t>& code : postcode) 3136a3316fc6SZhikuiRen { 3137a3316fc6SZhikuiRen currentCodeIndex++; 3138a3316fc6SZhikuiRen std::string postcodeEntryID = 3139a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3140a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3141a3316fc6SZhikuiRen 3142a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3143a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3144a3316fc6SZhikuiRen 3145a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3146a3316fc6SZhikuiRen { // already incremented 3147a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3148a3316fc6SZhikuiRen } 3149a3316fc6SZhikuiRen else 3150a3316fc6SZhikuiRen { 3151a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3152a3316fc6SZhikuiRen } 3153a3316fc6SZhikuiRen 3154a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3155a3316fc6SZhikuiRen // not fall between top and skip 3156a3316fc6SZhikuiRen if ((codeIndex == 0) && 3157a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3158a3316fc6SZhikuiRen { 3159a3316fc6SZhikuiRen continue; 3160a3316fc6SZhikuiRen } 3161a3316fc6SZhikuiRen 31624e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3163a3316fc6SZhikuiRen // currentIndex 3164a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3165a3316fc6SZhikuiRen { 3166a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3167a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3168a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3169a3316fc6SZhikuiRen continue; 3170a3316fc6SZhikuiRen } 3171a3316fc6SZhikuiRen 3172a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3173a3316fc6SZhikuiRen // index 3174a3316fc6SZhikuiRen 3175a3316fc6SZhikuiRen // Get the Created time from the timestamp 3176a3316fc6SZhikuiRen std::string entryTimeStr; 31779c620e21SAsmitha Karunanithi entryTimeStr = crow::utility::getDateTime( 31789c620e21SAsmitha Karunanithi static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000)); 3179a3316fc6SZhikuiRen 3180a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3181a3316fc6SZhikuiRen std::ostringstream hexCode; 3182a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 3183a3316fc6SZhikuiRen << code.second; 3184a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3185a3316fc6SZhikuiRen // Set Fixed -Point Notation 3186a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3187a3316fc6SZhikuiRen // Set precision to 4 digits 3188a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3189a3316fc6SZhikuiRen // Add double to stream 3190a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3191a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3192a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3193a3316fc6SZhikuiRen 3194a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3195a3316fc6SZhikuiRen std::string msg; 3196a3316fc6SZhikuiRen if (message != nullptr) 3197a3316fc6SZhikuiRen { 3198a3316fc6SZhikuiRen msg = message->message; 3199a3316fc6SZhikuiRen 3200a3316fc6SZhikuiRen // fill in this post code value 3201a3316fc6SZhikuiRen int i = 0; 3202a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3203a3316fc6SZhikuiRen { 3204a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3205a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3206a3316fc6SZhikuiRen if (argPos != std::string::npos) 3207a3316fc6SZhikuiRen { 3208a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3209a3316fc6SZhikuiRen } 3210a3316fc6SZhikuiRen } 3211a3316fc6SZhikuiRen } 3212a3316fc6SZhikuiRen 3213d4342a92STim Lee // Get Severity template from message registry 3214d4342a92STim Lee std::string severity; 3215d4342a92STim Lee if (message != nullptr) 3216d4342a92STim Lee { 3217d4342a92STim Lee severity = message->severity; 3218d4342a92STim Lee } 3219d4342a92STim Lee 3220a3316fc6SZhikuiRen // add to AsyncResp 3221a3316fc6SZhikuiRen logEntryArray.push_back({}); 3222a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 3223a3316fc6SZhikuiRen bmcLogEntry = { 3224a3316fc6SZhikuiRen {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 3225a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, 3226a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 3227a3316fc6SZhikuiRen "PostCodes/Entries/" + 3228a3316fc6SZhikuiRen postcodeEntryID}, 3229a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 3230a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 3231a3316fc6SZhikuiRen {"Message", std::move(msg)}, 3232a3316fc6SZhikuiRen {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"}, 3233a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 3234a3316fc6SZhikuiRen {"EntryType", "Event"}, 3235a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 32369c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 3237a3316fc6SZhikuiRen } 3238a3316fc6SZhikuiRen } 3239a3316fc6SZhikuiRen 3240a3316fc6SZhikuiRen static void getPostCodeForEntry(std::shared_ptr<AsyncResp> aResp, 3241a3316fc6SZhikuiRen const uint16_t bootIndex, 3242a3316fc6SZhikuiRen const uint64_t codeIndex) 3243a3316fc6SZhikuiRen { 3244a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3245a3316fc6SZhikuiRen [aResp, bootIndex, codeIndex]( 3246a3316fc6SZhikuiRen const boost::system::error_code ec, 3247a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode) { 3248a3316fc6SZhikuiRen if (ec) 3249a3316fc6SZhikuiRen { 3250a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3251a3316fc6SZhikuiRen messages::internalError(aResp->res); 3252a3316fc6SZhikuiRen return; 3253a3316fc6SZhikuiRen } 3254a3316fc6SZhikuiRen 3255a3316fc6SZhikuiRen // skip the empty postcode boots 3256a3316fc6SZhikuiRen if (postcode.empty()) 3257a3316fc6SZhikuiRen { 3258a3316fc6SZhikuiRen return; 3259a3316fc6SZhikuiRen } 3260a3316fc6SZhikuiRen 3261a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3262a3316fc6SZhikuiRen 3263a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3264a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3265a3316fc6SZhikuiRen }, 3266a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3267a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3268a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3269a3316fc6SZhikuiRen bootIndex); 3270a3316fc6SZhikuiRen } 3271a3316fc6SZhikuiRen 3272a3316fc6SZhikuiRen static void getPostCodeForBoot(std::shared_ptr<AsyncResp> aResp, 3273a3316fc6SZhikuiRen const uint16_t bootIndex, 3274a3316fc6SZhikuiRen const uint16_t bootCount, 3275a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 3276a3316fc6SZhikuiRen const uint64_t top) 3277a3316fc6SZhikuiRen { 3278a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3279a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3280a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3281a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode) { 3282a3316fc6SZhikuiRen if (ec) 3283a3316fc6SZhikuiRen { 3284a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3285a3316fc6SZhikuiRen messages::internalError(aResp->res); 3286a3316fc6SZhikuiRen return; 3287a3316fc6SZhikuiRen } 3288a3316fc6SZhikuiRen 3289a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3290a3316fc6SZhikuiRen if (!postcode.empty()) 3291a3316fc6SZhikuiRen { 3292a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 3293a3316fc6SZhikuiRen 3294a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3295a3316fc6SZhikuiRen { 3296a3316fc6SZhikuiRen uint64_t thisBootSkip = 3297a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3298a3316fc6SZhikuiRen uint64_t thisBootTop = 3299a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3300a3316fc6SZhikuiRen 3301a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3302a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3303a3316fc6SZhikuiRen } 3304a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3305a3316fc6SZhikuiRen } 3306a3316fc6SZhikuiRen 3307a3316fc6SZhikuiRen // continue to previous bootIndex 3308a3316fc6SZhikuiRen if (bootIndex < bootCount) 3309a3316fc6SZhikuiRen { 3310a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3311a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3312a3316fc6SZhikuiRen } 3313a3316fc6SZhikuiRen else 3314a3316fc6SZhikuiRen { 3315a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 3316a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3317a3316fc6SZhikuiRen "Entries?$skip=" + 3318a3316fc6SZhikuiRen std::to_string(skip + top); 3319a3316fc6SZhikuiRen } 3320a3316fc6SZhikuiRen }, 3321a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3322a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3323a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3324a3316fc6SZhikuiRen bootIndex); 3325a3316fc6SZhikuiRen } 3326a3316fc6SZhikuiRen 3327a3316fc6SZhikuiRen static void getCurrentBootNumber(std::shared_ptr<AsyncResp> aResp, 3328a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3329a3316fc6SZhikuiRen { 3330a3316fc6SZhikuiRen uint64_t entryCount = 0; 3331a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3332a3316fc6SZhikuiRen [aResp, entryCount, skip, 3333a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3334a3316fc6SZhikuiRen const std::variant<uint16_t>& bootCount) { 3335a3316fc6SZhikuiRen if (ec) 3336a3316fc6SZhikuiRen { 3337a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3338a3316fc6SZhikuiRen messages::internalError(aResp->res); 3339a3316fc6SZhikuiRen return; 3340a3316fc6SZhikuiRen } 3341a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 3342a3316fc6SZhikuiRen if (pVal) 3343a3316fc6SZhikuiRen { 3344a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 3345a3316fc6SZhikuiRen } 3346a3316fc6SZhikuiRen else 3347a3316fc6SZhikuiRen { 3348a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 3349a3316fc6SZhikuiRen } 3350a3316fc6SZhikuiRen }, 3351a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3352a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3353a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 3354a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 3355a3316fc6SZhikuiRen } 3356a3316fc6SZhikuiRen 3357a3316fc6SZhikuiRen class PostCodesEntryCollection : public Node 3358a3316fc6SZhikuiRen { 3359a3316fc6SZhikuiRen public: 3360a3316fc6SZhikuiRen template <typename CrowApp> 3361a3316fc6SZhikuiRen PostCodesEntryCollection(CrowApp& app) : 3362a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3363a3316fc6SZhikuiRen { 3364a3316fc6SZhikuiRen entityPrivileges = { 3365a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3366a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3367a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3368a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3369a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3370a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3371a3316fc6SZhikuiRen } 3372a3316fc6SZhikuiRen 3373a3316fc6SZhikuiRen private: 3374a3316fc6SZhikuiRen void doGet(crow::Response& res, const crow::Request& req, 3375a3316fc6SZhikuiRen const std::vector<std::string>& params) override 3376a3316fc6SZhikuiRen { 3377a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3378a3316fc6SZhikuiRen 3379a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3380a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3381a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 3382a3316fc6SZhikuiRen "/redfish/v1/" 3383a3316fc6SZhikuiRen "$metadata#LogEntryCollection.LogEntryCollection"; 3384a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3385a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3386a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3387a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3388a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3389a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3390a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3391a3316fc6SZhikuiRen 3392a3316fc6SZhikuiRen uint64_t skip = 0; 3393a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 3394a3316fc6SZhikuiRen if (!getSkipParam(asyncResp->res, req, skip)) 3395a3316fc6SZhikuiRen { 3396a3316fc6SZhikuiRen return; 3397a3316fc6SZhikuiRen } 3398a3316fc6SZhikuiRen if (!getTopParam(asyncResp->res, req, top)) 3399a3316fc6SZhikuiRen { 3400a3316fc6SZhikuiRen return; 3401a3316fc6SZhikuiRen } 3402a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 3403a3316fc6SZhikuiRen } 3404a3316fc6SZhikuiRen }; 3405a3316fc6SZhikuiRen 3406a3316fc6SZhikuiRen class PostCodesEntry : public Node 3407a3316fc6SZhikuiRen { 3408a3316fc6SZhikuiRen public: 3409a3316fc6SZhikuiRen PostCodesEntry(CrowApp& app) : 3410a3316fc6SZhikuiRen Node(app, 3411a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/", 3412a3316fc6SZhikuiRen std::string()) 3413a3316fc6SZhikuiRen { 3414a3316fc6SZhikuiRen entityPrivileges = { 3415a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3416a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3417a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3418a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3419a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3420a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3421a3316fc6SZhikuiRen } 3422a3316fc6SZhikuiRen 3423a3316fc6SZhikuiRen private: 3424a3316fc6SZhikuiRen void doGet(crow::Response& res, const crow::Request& req, 3425a3316fc6SZhikuiRen const std::vector<std::string>& params) override 3426a3316fc6SZhikuiRen { 3427a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3428a3316fc6SZhikuiRen if (params.size() != 1) 3429a3316fc6SZhikuiRen { 3430a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3431a3316fc6SZhikuiRen return; 3432a3316fc6SZhikuiRen } 3433a3316fc6SZhikuiRen 3434a3316fc6SZhikuiRen const std::string& targetID = params[0]; 3435a3316fc6SZhikuiRen 3436a3316fc6SZhikuiRen size_t bootPos = targetID.find('B'); 3437a3316fc6SZhikuiRen if (bootPos == std::string::npos) 3438a3316fc6SZhikuiRen { 3439a3316fc6SZhikuiRen // Requested ID was not found 3440a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 3441a3316fc6SZhikuiRen return; 3442a3316fc6SZhikuiRen } 3443a3316fc6SZhikuiRen std::string_view bootIndexStr(targetID); 3444a3316fc6SZhikuiRen bootIndexStr.remove_prefix(bootPos + 1); 3445a3316fc6SZhikuiRen uint16_t bootIndex = 0; 3446a3316fc6SZhikuiRen uint64_t codeIndex = 0; 3447a3316fc6SZhikuiRen size_t dashPos = bootIndexStr.find('-'); 3448a3316fc6SZhikuiRen 3449a3316fc6SZhikuiRen if (dashPos == std::string::npos) 3450a3316fc6SZhikuiRen { 3451a3316fc6SZhikuiRen return; 3452a3316fc6SZhikuiRen } 3453a3316fc6SZhikuiRen std::string_view codeIndexStr(bootIndexStr); 3454a3316fc6SZhikuiRen bootIndexStr.remove_suffix(dashPos); 3455a3316fc6SZhikuiRen codeIndexStr.remove_prefix(dashPos + 1); 3456a3316fc6SZhikuiRen 3457a3316fc6SZhikuiRen bootIndex = static_cast<uint16_t>( 3458a3316fc6SZhikuiRen strtoul(std::string(bootIndexStr).c_str(), NULL, 0)); 3459a3316fc6SZhikuiRen codeIndex = strtoul(std::string(codeIndexStr).c_str(), NULL, 0); 3460a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3461a3316fc6SZhikuiRen { 3462a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 3463a3316fc6SZhikuiRen << params[0]; 3464a3316fc6SZhikuiRen } 3465a3316fc6SZhikuiRen 3466a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 3467a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 3468a3316fc6SZhikuiRen "/redfish/v1/$metadata#LogEntry.LogEntry"; 3469a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3470a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3471a3316fc6SZhikuiRen "Entries"; 3472a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3473a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3474a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3475a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3476a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3477a3316fc6SZhikuiRen 3478a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 3479a3316fc6SZhikuiRen } 3480a3316fc6SZhikuiRen }; 3481a3316fc6SZhikuiRen 34821da66f75SEd Tanous } // namespace redfish 3483