11da66f75SEd Tanous /* 21da66f75SEd Tanous // Copyright (c) 2018 Intel Corporation 31da66f75SEd Tanous // 41da66f75SEd Tanous // Licensed under the Apache License, Version 2.0 (the "License"); 51da66f75SEd Tanous // you may not use this file except in compliance with the License. 61da66f75SEd Tanous // You may obtain a copy of the License at 71da66f75SEd Tanous // 81da66f75SEd Tanous // http://www.apache.org/licenses/LICENSE-2.0 91da66f75SEd Tanous // 101da66f75SEd Tanous // Unless required by applicable law or agreed to in writing, software 111da66f75SEd Tanous // distributed under the License is distributed on an "AS IS" BASIS, 121da66f75SEd Tanous // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131da66f75SEd Tanous // See the License for the specific language governing permissions and 141da66f75SEd Tanous // limitations under the License. 151da66f75SEd Tanous */ 161da66f75SEd Tanous #pragma once 171da66f75SEd Tanous 181da66f75SEd Tanous #include "node.hpp" 194851d45dSJason M. Bills #include "registries.hpp" 204851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 214851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2246229577SJames Feist #include "task.hpp" 231da66f75SEd Tanous 24e1f26343SJason M. Bills #include <systemd/sd-journal.h> 25e1f26343SJason M. Bills 264851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 274851d45dSJason M. Bills #include <boost/beast/core/span.hpp> 281da66f75SEd Tanous #include <boost/container/flat_map.hpp> 291ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 30cb92c03bSAndrew Geissler #include <error_messages.hpp> 311214b7e7SGunnar Mills 324418c7f0SJames Feist #include <filesystem> 33cd225da8SJason M. Bills #include <string_view> 34abf2add6SEd Tanous #include <variant> 351da66f75SEd Tanous 361da66f75SEd Tanous namespace redfish 371da66f75SEd Tanous { 381da66f75SEd Tanous 395b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 405b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 415b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 425b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 435b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 445b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 45424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 465b61b5e8SJason M. Bills constexpr char const* crashdumpRawPECIInterface = 47424c4176SJason M. Bills "com.intel.crashdump.SendRawPeci"; 486eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 496eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 501da66f75SEd Tanous 514851d45dSJason M. Bills namespace message_registries 524851d45dSJason M. Bills { 534851d45dSJason M. Bills static const Message* getMessageFromRegistry( 544851d45dSJason M. Bills const std::string& messageKey, 554851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 564851d45dSJason M. Bills { 574851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 584851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 594851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 604851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 614851d45dSJason M. Bills messageKey.c_str()); 624851d45dSJason M. Bills }); 634851d45dSJason M. Bills if (messageIt != registry.cend()) 644851d45dSJason M. Bills { 654851d45dSJason M. Bills return &messageIt->second; 664851d45dSJason M. Bills } 674851d45dSJason M. Bills 684851d45dSJason M. Bills return nullptr; 694851d45dSJason M. Bills } 704851d45dSJason M. Bills 714851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 724851d45dSJason M. Bills { 734851d45dSJason M. Bills // Redfish MessageIds are in the form 744851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 754851d45dSJason M. Bills // the right Message 764851d45dSJason M. Bills std::vector<std::string> fields; 774851d45dSJason M. Bills fields.reserve(4); 784851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 794851d45dSJason M. Bills std::string& registryName = fields[0]; 804851d45dSJason M. Bills std::string& messageKey = fields[3]; 814851d45dSJason M. Bills 824851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 834851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 844851d45dSJason M. Bills { 854851d45dSJason M. Bills return getMessageFromRegistry( 864851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 874851d45dSJason M. Bills } 884851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 894851d45dSJason M. Bills { 904851d45dSJason M. Bills return getMessageFromRegistry( 914851d45dSJason M. Bills messageKey, 924851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 934851d45dSJason M. Bills } 944851d45dSJason M. Bills return nullptr; 954851d45dSJason M. Bills } 964851d45dSJason M. Bills } // namespace message_registries 974851d45dSJason M. Bills 98f6150403SJames Feist namespace fs = std::filesystem; 991da66f75SEd Tanous 100cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 10119bd78d9SPatrick Williams std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, 102cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 103cb92c03bSAndrew Geissler 104cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 105cb92c03bSAndrew Geissler sdbusplus::message::object_path, 106cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 107cb92c03bSAndrew Geissler 108cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 109cb92c03bSAndrew Geissler { 110d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 111d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 112d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 113d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 114cb92c03bSAndrew Geissler { 115cb92c03bSAndrew Geissler return "Critical"; 116cb92c03bSAndrew Geissler } 1173174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 118d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 119d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 120cb92c03bSAndrew Geissler { 121cb92c03bSAndrew Geissler return "OK"; 122cb92c03bSAndrew Geissler } 1233174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 124cb92c03bSAndrew Geissler { 125cb92c03bSAndrew Geissler return "Warning"; 126cb92c03bSAndrew Geissler } 127cb92c03bSAndrew Geissler return ""; 128cb92c03bSAndrew Geissler } 129cb92c03bSAndrew Geissler 13016428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal, 13139e77504SEd Tanous const std::string_view& field, 13239e77504SEd Tanous std::string_view& contents) 13316428a1aSJason M. Bills { 13416428a1aSJason M. Bills const char* data = nullptr; 13516428a1aSJason M. Bills size_t length = 0; 13616428a1aSJason M. Bills int ret = 0; 13716428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 138271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 139271584abSEd Tanous reinterpret_cast<const void**>(&data), &length); 14016428a1aSJason M. Bills if (ret < 0) 14116428a1aSJason M. Bills { 14216428a1aSJason M. Bills return ret; 14316428a1aSJason M. Bills } 14439e77504SEd Tanous contents = std::string_view(data, length); 14516428a1aSJason M. Bills // Only use the content after the "=" character. 14681ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 14716428a1aSJason M. Bills return ret; 14816428a1aSJason M. Bills } 14916428a1aSJason M. Bills 15016428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal, 15139e77504SEd Tanous const std::string_view& field, const int& base, 152271584abSEd Tanous long int& contents) 15316428a1aSJason M. Bills { 15416428a1aSJason M. Bills int ret = 0; 15539e77504SEd Tanous std::string_view metadata; 15616428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 15716428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 15816428a1aSJason M. Bills if (ret < 0) 15916428a1aSJason M. Bills { 16016428a1aSJason M. Bills return ret; 16116428a1aSJason M. Bills } 162b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 16316428a1aSJason M. Bills return ret; 16416428a1aSJason M. Bills } 16516428a1aSJason M. Bills 166a3316fc6SZhikuiRen static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp) 167a3316fc6SZhikuiRen { 168a3316fc6SZhikuiRen int ret = 0; 169a3316fc6SZhikuiRen uint64_t timestamp = 0; 170a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 171a3316fc6SZhikuiRen if (ret < 0) 172a3316fc6SZhikuiRen { 173a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 174a3316fc6SZhikuiRen << strerror(-ret); 175a3316fc6SZhikuiRen return false; 176a3316fc6SZhikuiRen } 1779c620e21SAsmitha Karunanithi entryTimestamp = crow::utility::getDateTime( 1789c620e21SAsmitha Karunanithi static_cast<std::time_t>(timestamp / 1000 / 1000)); 1799c620e21SAsmitha Karunanithi return true; 180a3316fc6SZhikuiRen } 181a3316fc6SZhikuiRen 18216428a1aSJason M. Bills static bool getSkipParam(crow::Response& res, const crow::Request& req, 183271584abSEd Tanous uint64_t& skip) 18416428a1aSJason M. Bills { 1855a7e877eSJames Feist boost::urls::url_view::params_type::iterator it = 1865a7e877eSJames Feist req.urlParams.find("$skip"); 1875a7e877eSJames Feist if (it != req.urlParams.end()) 18816428a1aSJason M. Bills { 1895a7e877eSJames Feist std::string skipParam = it->value(); 19016428a1aSJason M. Bills char* ptr = nullptr; 1915a7e877eSJames Feist skip = std::strtoul(skipParam.c_str(), &ptr, 10); 1925a7e877eSJames Feist if (skipParam.empty() || *ptr != '\0') 19316428a1aSJason M. Bills { 19416428a1aSJason M. Bills 19516428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(skipParam), 19616428a1aSJason M. Bills "$skip"); 19716428a1aSJason M. Bills return false; 19816428a1aSJason M. Bills } 19916428a1aSJason M. Bills } 20016428a1aSJason M. Bills return true; 20116428a1aSJason M. Bills } 20216428a1aSJason M. Bills 203271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 20416428a1aSJason M. Bills static bool getTopParam(crow::Response& res, const crow::Request& req, 205271584abSEd Tanous uint64_t& top) 20616428a1aSJason M. Bills { 2075a7e877eSJames Feist boost::urls::url_view::params_type::iterator it = 2085a7e877eSJames Feist req.urlParams.find("$top"); 2095a7e877eSJames Feist if (it != req.urlParams.end()) 21016428a1aSJason M. Bills { 2115a7e877eSJames Feist std::string topParam = it->value(); 21216428a1aSJason M. Bills char* ptr = nullptr; 2135a7e877eSJames Feist top = std::strtoul(topParam.c_str(), &ptr, 10); 2145a7e877eSJames Feist if (topParam.empty() || *ptr != '\0') 21516428a1aSJason M. Bills { 21616428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(topParam), 21716428a1aSJason M. Bills "$top"); 21816428a1aSJason M. Bills return false; 21916428a1aSJason M. Bills } 220271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 22116428a1aSJason M. Bills { 22216428a1aSJason M. Bills 22316428a1aSJason M. Bills messages::queryParameterOutOfRange( 22416428a1aSJason M. Bills res, std::to_string(top), "$top", 22516428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 22616428a1aSJason M. Bills return false; 22716428a1aSJason M. Bills } 22816428a1aSJason M. Bills } 22916428a1aSJason M. Bills return true; 23016428a1aSJason M. Bills } 23116428a1aSJason M. Bills 232e85d6b16SJason M. Bills static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 233e85d6b16SJason M. Bills const bool firstEntry = true) 23416428a1aSJason M. Bills { 23516428a1aSJason M. Bills int ret = 0; 23616428a1aSJason M. Bills static uint64_t prevTs = 0; 23716428a1aSJason M. Bills static int index = 0; 238e85d6b16SJason M. Bills if (firstEntry) 239e85d6b16SJason M. Bills { 240e85d6b16SJason M. Bills prevTs = 0; 241e85d6b16SJason M. Bills } 242e85d6b16SJason M. Bills 24316428a1aSJason M. Bills // Get the entry timestamp 24416428a1aSJason M. Bills uint64_t curTs = 0; 24516428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 24616428a1aSJason M. Bills if (ret < 0) 24716428a1aSJason M. Bills { 24816428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 24916428a1aSJason M. Bills << strerror(-ret); 25016428a1aSJason M. Bills return false; 25116428a1aSJason M. Bills } 25216428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 25316428a1aSJason M. Bills if (curTs == prevTs) 25416428a1aSJason M. Bills { 25516428a1aSJason M. Bills index++; 25616428a1aSJason M. Bills } 25716428a1aSJason M. Bills else 25816428a1aSJason M. Bills { 25916428a1aSJason M. Bills // Otherwise, reset it 26016428a1aSJason M. Bills index = 0; 26116428a1aSJason M. Bills } 26216428a1aSJason M. Bills // Save the timestamp 26316428a1aSJason M. Bills prevTs = curTs; 26416428a1aSJason M. Bills 26516428a1aSJason M. Bills entryID = std::to_string(curTs); 26616428a1aSJason M. Bills if (index > 0) 26716428a1aSJason M. Bills { 26816428a1aSJason M. Bills entryID += "_" + std::to_string(index); 26916428a1aSJason M. Bills } 27016428a1aSJason M. Bills return true; 27116428a1aSJason M. Bills } 27216428a1aSJason M. Bills 273e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 274e85d6b16SJason M. Bills const bool firstEntry = true) 27595820184SJason M. Bills { 276271584abSEd Tanous static time_t prevTs = 0; 27795820184SJason M. Bills static int index = 0; 278e85d6b16SJason M. Bills if (firstEntry) 279e85d6b16SJason M. Bills { 280e85d6b16SJason M. Bills prevTs = 0; 281e85d6b16SJason M. Bills } 282e85d6b16SJason M. Bills 28395820184SJason M. Bills // Get the entry timestamp 284271584abSEd Tanous std::time_t curTs = 0; 28595820184SJason M. Bills std::tm timeStruct = {}; 28695820184SJason M. Bills std::istringstream entryStream(logEntry); 28795820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 28895820184SJason M. Bills { 28995820184SJason M. Bills curTs = std::mktime(&timeStruct); 29095820184SJason M. Bills } 29195820184SJason M. Bills // If the timestamp isn't unique, increment the index 29295820184SJason M. Bills if (curTs == prevTs) 29395820184SJason M. Bills { 29495820184SJason M. Bills index++; 29595820184SJason M. Bills } 29695820184SJason M. Bills else 29795820184SJason M. Bills { 29895820184SJason M. Bills // Otherwise, reset it 29995820184SJason M. Bills index = 0; 30095820184SJason M. Bills } 30195820184SJason M. Bills // Save the timestamp 30295820184SJason M. Bills prevTs = curTs; 30395820184SJason M. Bills 30495820184SJason M. Bills entryID = std::to_string(curTs); 30595820184SJason M. Bills if (index > 0) 30695820184SJason M. Bills { 30795820184SJason M. Bills entryID += "_" + std::to_string(index); 30895820184SJason M. Bills } 30995820184SJason M. Bills return true; 31095820184SJason M. Bills } 31195820184SJason M. Bills 31216428a1aSJason M. Bills static bool getTimestampFromID(crow::Response& res, const std::string& entryID, 313271584abSEd Tanous uint64_t& timestamp, uint64_t& index) 31416428a1aSJason M. Bills { 31516428a1aSJason M. Bills if (entryID.empty()) 31616428a1aSJason M. Bills { 31716428a1aSJason M. Bills return false; 31816428a1aSJason M. Bills } 31916428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 32039e77504SEd Tanous std::string_view tsStr(entryID); 32116428a1aSJason M. Bills 32281ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 32316428a1aSJason M. Bills if (underscorePos != tsStr.npos) 32416428a1aSJason M. Bills { 32516428a1aSJason M. Bills // Timestamp has an index 32616428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 32739e77504SEd Tanous std::string_view indexStr(entryID); 32816428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 32916428a1aSJason M. Bills std::size_t pos; 33016428a1aSJason M. Bills try 33116428a1aSJason M. Bills { 33239e77504SEd Tanous index = std::stoul(std::string(indexStr), &pos); 33316428a1aSJason M. Bills } 334271584abSEd Tanous catch (std::invalid_argument&) 33516428a1aSJason M. Bills { 33616428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 33716428a1aSJason M. Bills return false; 33816428a1aSJason M. Bills } 339271584abSEd Tanous catch (std::out_of_range&) 34016428a1aSJason M. Bills { 34116428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 34216428a1aSJason M. Bills return false; 34316428a1aSJason M. Bills } 34416428a1aSJason M. Bills if (pos != indexStr.size()) 34516428a1aSJason M. Bills { 34616428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 34716428a1aSJason M. Bills return false; 34816428a1aSJason M. Bills } 34916428a1aSJason M. Bills } 35016428a1aSJason M. Bills // Timestamp has no index 35116428a1aSJason M. Bills std::size_t pos; 35216428a1aSJason M. Bills try 35316428a1aSJason M. Bills { 35439e77504SEd Tanous timestamp = std::stoull(std::string(tsStr), &pos); 35516428a1aSJason M. Bills } 356271584abSEd Tanous catch (std::invalid_argument&) 35716428a1aSJason M. Bills { 35816428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 35916428a1aSJason M. Bills return false; 36016428a1aSJason M. Bills } 361271584abSEd Tanous catch (std::out_of_range&) 36216428a1aSJason M. Bills { 36316428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 36416428a1aSJason M. Bills return false; 36516428a1aSJason M. Bills } 36616428a1aSJason M. Bills if (pos != tsStr.size()) 36716428a1aSJason M. Bills { 36816428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 36916428a1aSJason M. Bills return false; 37016428a1aSJason M. Bills } 37116428a1aSJason M. Bills return true; 37216428a1aSJason M. Bills } 37316428a1aSJason M. Bills 37495820184SJason M. Bills static bool 37595820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 37695820184SJason M. Bills { 37795820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 37895820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 37995820184SJason M. Bills 38095820184SJason M. Bills // Loop through the directory looking for redfish log files 38195820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 38295820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 38395820184SJason M. Bills { 38495820184SJason M. Bills // If we find a redfish log file, save the path 38595820184SJason M. Bills std::string filename = dirEnt.path().filename(); 38695820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 38795820184SJason M. Bills { 38895820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 38995820184SJason M. Bills } 39095820184SJason M. Bills } 39195820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 39295820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 39395820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 39495820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 39595820184SJason M. Bills 39695820184SJason M. Bills return !redfishLogFiles.empty(); 39795820184SJason M. Bills } 39895820184SJason M. Bills 3995cb1dd27SAsmitha Karunanithi inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp, 4005cb1dd27SAsmitha Karunanithi const std::string& dumpType) 4015cb1dd27SAsmitha Karunanithi { 4025cb1dd27SAsmitha Karunanithi std::string dumpPath; 4035cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 4045cb1dd27SAsmitha Karunanithi { 4055cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 4065cb1dd27SAsmitha Karunanithi } 4075cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 4085cb1dd27SAsmitha Karunanithi { 4095cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 4105cb1dd27SAsmitha Karunanithi } 4115cb1dd27SAsmitha Karunanithi else 4125cb1dd27SAsmitha Karunanithi { 4135cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 4145cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4155cb1dd27SAsmitha Karunanithi return; 4165cb1dd27SAsmitha Karunanithi } 4175cb1dd27SAsmitha Karunanithi 4185cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 4195cb1dd27SAsmitha Karunanithi [asyncResp, dumpPath, dumpType](const boost::system::error_code ec, 4205cb1dd27SAsmitha Karunanithi GetManagedObjectsType& resp) { 4215cb1dd27SAsmitha Karunanithi if (ec) 4225cb1dd27SAsmitha Karunanithi { 4235cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4245cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4255cb1dd27SAsmitha Karunanithi return; 4265cb1dd27SAsmitha Karunanithi } 4275cb1dd27SAsmitha Karunanithi 4285cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4295cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 430b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 431b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 432b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 433b47452b2SAsmitha Karunanithi "/entry/"; 4345cb1dd27SAsmitha Karunanithi 4355cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4365cb1dd27SAsmitha Karunanithi { 437b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 4385cb1dd27SAsmitha Karunanithi { 4395cb1dd27SAsmitha Karunanithi continue; 4405cb1dd27SAsmitha Karunanithi } 4415cb1dd27SAsmitha Karunanithi std::time_t timestamp; 4425cb1dd27SAsmitha Karunanithi uint64_t size = 0; 4435cb1dd27SAsmitha Karunanithi entriesArray.push_back({}); 4445cb1dd27SAsmitha Karunanithi nlohmann::json& thisEntry = entriesArray.back(); 4452dfd18efSEd Tanous 4462dfd18efSEd Tanous std::string entryID = object.first.filename(); 4472dfd18efSEd Tanous if (entryID.empty()) 4485cb1dd27SAsmitha Karunanithi { 4495cb1dd27SAsmitha Karunanithi continue; 4505cb1dd27SAsmitha Karunanithi } 4515cb1dd27SAsmitha Karunanithi 4525cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4535cb1dd27SAsmitha Karunanithi { 4545cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 4555cb1dd27SAsmitha Karunanithi { 4565cb1dd27SAsmitha Karunanithi 4575cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4585cb1dd27SAsmitha Karunanithi { 4595cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4605cb1dd27SAsmitha Karunanithi { 4615cb1dd27SAsmitha Karunanithi auto sizePtr = 4625cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4635cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4645cb1dd27SAsmitha Karunanithi { 4655cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4665cb1dd27SAsmitha Karunanithi break; 4675cb1dd27SAsmitha Karunanithi } 4685cb1dd27SAsmitha Karunanithi size = *sizePtr; 4695cb1dd27SAsmitha Karunanithi break; 4705cb1dd27SAsmitha Karunanithi } 4715cb1dd27SAsmitha Karunanithi } 4725cb1dd27SAsmitha Karunanithi } 4735cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4745cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 4755cb1dd27SAsmitha Karunanithi { 4765cb1dd27SAsmitha Karunanithi 4775cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4785cb1dd27SAsmitha Karunanithi { 4795cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 4805cb1dd27SAsmitha Karunanithi { 4815cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 4825cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4835cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 4845cb1dd27SAsmitha Karunanithi { 4855cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4865cb1dd27SAsmitha Karunanithi break; 4875cb1dd27SAsmitha Karunanithi } 4885cb1dd27SAsmitha Karunanithi timestamp = 4895cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 4905cb1dd27SAsmitha Karunanithi break; 4915cb1dd27SAsmitha Karunanithi } 4925cb1dd27SAsmitha Karunanithi } 4935cb1dd27SAsmitha Karunanithi } 4945cb1dd27SAsmitha Karunanithi } 4955cb1dd27SAsmitha Karunanithi 496d337bb72SAsmitha Karunanithi thisEntry["@odata.type"] = "#LogEntry.v1_7_0.LogEntry"; 4975cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 4985cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 4995cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5005cb1dd27SAsmitha Karunanithi thisEntry["Created"] = crow::utility::getDateTime(timestamp); 5015cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 5025cb1dd27SAsmitha Karunanithi 503d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataSizeBytes"] = size; 5045cb1dd27SAsmitha Karunanithi 5055cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5065cb1dd27SAsmitha Karunanithi { 507d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 508d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 509d337bb72SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 510d337bb72SAsmitha Karunanithi "attachment/" + 511d337bb72SAsmitha Karunanithi entryID; 5125cb1dd27SAsmitha Karunanithi } 5135cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5145cb1dd27SAsmitha Karunanithi { 515d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 516d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 517d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 518d337bb72SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/" 519d337bb72SAsmitha Karunanithi "attachment/" + 520d337bb72SAsmitha Karunanithi entryID; 5215cb1dd27SAsmitha Karunanithi } 5225cb1dd27SAsmitha Karunanithi } 5235cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 5245cb1dd27SAsmitha Karunanithi entriesArray.size(); 5255cb1dd27SAsmitha Karunanithi }, 5265cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5275cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5285cb1dd27SAsmitha Karunanithi } 5295cb1dd27SAsmitha Karunanithi 5305cb1dd27SAsmitha Karunanithi inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp, 5315cb1dd27SAsmitha Karunanithi const std::string& entryID, 5325cb1dd27SAsmitha Karunanithi const std::string& dumpType) 5335cb1dd27SAsmitha Karunanithi { 5345cb1dd27SAsmitha Karunanithi std::string dumpPath; 5355cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5365cb1dd27SAsmitha Karunanithi { 5375cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5385cb1dd27SAsmitha Karunanithi } 5395cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5405cb1dd27SAsmitha Karunanithi { 5415cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5425cb1dd27SAsmitha Karunanithi } 5435cb1dd27SAsmitha Karunanithi else 5445cb1dd27SAsmitha Karunanithi { 5455cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5465cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5475cb1dd27SAsmitha Karunanithi return; 5485cb1dd27SAsmitha Karunanithi } 5495cb1dd27SAsmitha Karunanithi 5505cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 5515cb1dd27SAsmitha Karunanithi [asyncResp, entryID, dumpPath, dumpType]( 5525cb1dd27SAsmitha Karunanithi const boost::system::error_code ec, GetManagedObjectsType& resp) { 5535cb1dd27SAsmitha Karunanithi if (ec) 5545cb1dd27SAsmitha Karunanithi { 5555cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5565cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5575cb1dd27SAsmitha Karunanithi return; 5585cb1dd27SAsmitha Karunanithi } 5595cb1dd27SAsmitha Karunanithi 560b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 561b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 562b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 563b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 564b47452b2SAsmitha Karunanithi "/entry/"; 565b47452b2SAsmitha Karunanithi 5665cb1dd27SAsmitha Karunanithi for (auto& objectPath : resp) 5675cb1dd27SAsmitha Karunanithi { 568b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5695cb1dd27SAsmitha Karunanithi { 5705cb1dd27SAsmitha Karunanithi continue; 5715cb1dd27SAsmitha Karunanithi } 5725cb1dd27SAsmitha Karunanithi 5735cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 5745cb1dd27SAsmitha Karunanithi std::time_t timestamp; 5755cb1dd27SAsmitha Karunanithi uint64_t size = 0; 5765cb1dd27SAsmitha Karunanithi 5775cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 5785cb1dd27SAsmitha Karunanithi { 5795cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 5805cb1dd27SAsmitha Karunanithi { 5815cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 5825cb1dd27SAsmitha Karunanithi { 5835cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 5845cb1dd27SAsmitha Karunanithi { 5855cb1dd27SAsmitha Karunanithi auto sizePtr = 5865cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5875cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 5885cb1dd27SAsmitha Karunanithi { 5895cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5905cb1dd27SAsmitha Karunanithi break; 5915cb1dd27SAsmitha Karunanithi } 5925cb1dd27SAsmitha Karunanithi size = *sizePtr; 5935cb1dd27SAsmitha Karunanithi break; 5945cb1dd27SAsmitha Karunanithi } 5955cb1dd27SAsmitha Karunanithi } 5965cb1dd27SAsmitha Karunanithi } 5975cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 5985cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 5995cb1dd27SAsmitha Karunanithi { 6005cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6015cb1dd27SAsmitha Karunanithi { 6025cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 6035cb1dd27SAsmitha Karunanithi { 6045cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 6055cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6065cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 6075cb1dd27SAsmitha Karunanithi { 6085cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6095cb1dd27SAsmitha Karunanithi break; 6105cb1dd27SAsmitha Karunanithi } 6115cb1dd27SAsmitha Karunanithi timestamp = 6125cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 6135cb1dd27SAsmitha Karunanithi break; 6145cb1dd27SAsmitha Karunanithi } 6155cb1dd27SAsmitha Karunanithi } 6165cb1dd27SAsmitha Karunanithi } 6175cb1dd27SAsmitha Karunanithi } 6185cb1dd27SAsmitha Karunanithi 6195cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 620d337bb72SAsmitha Karunanithi "#LogEntry.v1_7_0.LogEntry"; 6215cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6225cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6235cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6245cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6255cb1dd27SAsmitha Karunanithi crow::utility::getDateTime(timestamp); 6265cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6275cb1dd27SAsmitha Karunanithi 628d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6295cb1dd27SAsmitha Karunanithi 6305cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6315cb1dd27SAsmitha Karunanithi { 632d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 633d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 6345cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 6355cb1dd27SAsmitha Karunanithi "attachment/" + 6365cb1dd27SAsmitha Karunanithi entryID; 6375cb1dd27SAsmitha Karunanithi } 6385cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6395cb1dd27SAsmitha Karunanithi { 640d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 641d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["OEMDiagnosticDataType"] = 6425cb1dd27SAsmitha Karunanithi "System"; 643d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 6445cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/" 6455cb1dd27SAsmitha Karunanithi "attachment/" + 6465cb1dd27SAsmitha Karunanithi entryID; 6475cb1dd27SAsmitha Karunanithi } 6485cb1dd27SAsmitha Karunanithi } 649b47452b2SAsmitha Karunanithi if (foundDumpEntry == false) 650b47452b2SAsmitha Karunanithi { 651b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 652b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 653b47452b2SAsmitha Karunanithi return; 654b47452b2SAsmitha Karunanithi } 6555cb1dd27SAsmitha Karunanithi }, 6565cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6575cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6585cb1dd27SAsmitha Karunanithi } 6595cb1dd27SAsmitha Karunanithi 6609878256fSStanley Chu inline void deleteDumpEntry(const std::shared_ptr<AsyncResp>& asyncResp, 6619878256fSStanley Chu const std::string& entryID, 662b47452b2SAsmitha Karunanithi const std::string& dumpType) 6635cb1dd27SAsmitha Karunanithi { 6645cb1dd27SAsmitha Karunanithi auto respHandler = [asyncResp](const boost::system::error_code ec) { 6655cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6665cb1dd27SAsmitha Karunanithi if (ec) 6675cb1dd27SAsmitha Karunanithi { 6685cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 6695cb1dd27SAsmitha Karunanithi << ec; 6705cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6715cb1dd27SAsmitha Karunanithi return; 6725cb1dd27SAsmitha Karunanithi } 6735cb1dd27SAsmitha Karunanithi }; 6745cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 6755cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 676b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 677b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 678b47452b2SAsmitha Karunanithi entryID, 6795cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 6805cb1dd27SAsmitha Karunanithi } 6815cb1dd27SAsmitha Karunanithi 682a43be80fSAsmitha Karunanithi inline void createDumpTaskCallback(const crow::Request& req, 683b5a76932SEd Tanous const std::shared_ptr<AsyncResp>& asyncResp, 684a43be80fSAsmitha Karunanithi const uint32_t& dumpId, 685a43be80fSAsmitha Karunanithi const std::string& dumpPath, 686a43be80fSAsmitha Karunanithi const std::string& dumpType) 687a43be80fSAsmitha Karunanithi { 688a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 6896145ed6fSAsmitha Karunanithi [dumpId, dumpPath, dumpType]( 690a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 691a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 692cb13a392SEd Tanous if (err) 693cb13a392SEd Tanous { 6946145ed6fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Error in creating a dump"; 6956145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 6966145ed6fSAsmitha Karunanithi return task::completed; 697cb13a392SEd Tanous } 698a43be80fSAsmitha Karunanithi std::vector<std::pair< 699a43be80fSAsmitha Karunanithi std::string, 700a43be80fSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string>>>>> 701a43be80fSAsmitha Karunanithi interfacesList; 702a43be80fSAsmitha Karunanithi 703a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 704a43be80fSAsmitha Karunanithi 705a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 706a43be80fSAsmitha Karunanithi 707b47452b2SAsmitha Karunanithi if (objPath.str == 708b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 709b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 710b47452b2SAsmitha Karunanithi "/entry/" + std::to_string(dumpId)) 711a43be80fSAsmitha Karunanithi { 712a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 713a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 714a43be80fSAsmitha Karunanithi 715a43be80fSAsmitha Karunanithi std::string headerLoc = 716a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 717a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 718a43be80fSAsmitha Karunanithi std::move(headerLoc)); 719a43be80fSAsmitha Karunanithi 720a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 721b47452b2SAsmitha Karunanithi return task::completed; 7226145ed6fSAsmitha Karunanithi } 723a43be80fSAsmitha Karunanithi return task::completed; 724a43be80fSAsmitha Karunanithi }, 725a43be80fSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus." 726a43be80fSAsmitha Karunanithi "ObjectManager'," 727a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 728a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 729a43be80fSAsmitha Karunanithi 730a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 731a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 732a43be80fSAsmitha Karunanithi task->payload.emplace(req); 733a43be80fSAsmitha Karunanithi } 734a43be80fSAsmitha Karunanithi 735a43be80fSAsmitha Karunanithi inline void createDump(crow::Response& res, const crow::Request& req, 736a43be80fSAsmitha Karunanithi const std::string& dumpType) 737a43be80fSAsmitha Karunanithi { 738a43be80fSAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 739a43be80fSAsmitha Karunanithi 740a43be80fSAsmitha Karunanithi std::string dumpPath; 741a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 742a43be80fSAsmitha Karunanithi { 743a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 744a43be80fSAsmitha Karunanithi } 745a43be80fSAsmitha Karunanithi else if (dumpType == "System") 746a43be80fSAsmitha Karunanithi { 747a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 748a43be80fSAsmitha Karunanithi } 749a43be80fSAsmitha Karunanithi else 750a43be80fSAsmitha Karunanithi { 751a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 752a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 753a43be80fSAsmitha Karunanithi return; 754a43be80fSAsmitha Karunanithi } 755a43be80fSAsmitha Karunanithi 756a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 757a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 758a43be80fSAsmitha Karunanithi 759a43be80fSAsmitha Karunanithi if (!redfish::json_util::readJson( 760a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 761a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 762a43be80fSAsmitha Karunanithi { 763a43be80fSAsmitha Karunanithi return; 764a43be80fSAsmitha Karunanithi } 765a43be80fSAsmitha Karunanithi 766a43be80fSAsmitha Karunanithi if (dumpType == "System") 767a43be80fSAsmitha Karunanithi { 768a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 769a43be80fSAsmitha Karunanithi { 770a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 771a43be80fSAsmitha Karunanithi "'DiagnosticDataType'/" 772a43be80fSAsmitha Karunanithi "'OEMDiagnosticDataType' value not found!"; 773a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 774a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 775a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 776a43be80fSAsmitha Karunanithi return; 777a43be80fSAsmitha Karunanithi } 7783174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 779a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 780a43be80fSAsmitha Karunanithi { 781a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 782a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 783a43be80fSAsmitha Karunanithi "System Dump creation parameters"); 784a43be80fSAsmitha Karunanithi return; 785a43be80fSAsmitha Karunanithi } 786a43be80fSAsmitha Karunanithi } 787a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 788a43be80fSAsmitha Karunanithi { 789a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 790a43be80fSAsmitha Karunanithi { 791a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 792a43be80fSAsmitha Karunanithi "'DiagnosticDataType' not found!"; 793a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 794a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 795a43be80fSAsmitha Karunanithi return; 796a43be80fSAsmitha Karunanithi } 7973174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 798a43be80fSAsmitha Karunanithi { 799a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 800a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 801a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 802a43be80fSAsmitha Karunanithi "BMC Dump creation parameters"); 803a43be80fSAsmitha Karunanithi return; 804a43be80fSAsmitha Karunanithi } 805a43be80fSAsmitha Karunanithi } 806a43be80fSAsmitha Karunanithi 807a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 808a43be80fSAsmitha Karunanithi [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec, 809a43be80fSAsmitha Karunanithi const uint32_t& dumpId) { 810a43be80fSAsmitha Karunanithi if (ec) 811a43be80fSAsmitha Karunanithi { 812a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 813a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 814a43be80fSAsmitha Karunanithi return; 815a43be80fSAsmitha Karunanithi } 816a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 817a43be80fSAsmitha Karunanithi 818a43be80fSAsmitha Karunanithi createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType); 819a43be80fSAsmitha Karunanithi }, 820b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 821b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 822b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 823a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 824a43be80fSAsmitha Karunanithi } 825a43be80fSAsmitha Karunanithi 826b47452b2SAsmitha Karunanithi inline void clearDump(crow::Response& res, const std::string& dumpType) 82780319af1SAsmitha Karunanithi { 828b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 829b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 83080319af1SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 83180319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 832b47452b2SAsmitha Karunanithi [asyncResp, dumpType](const boost::system::error_code ec, 83380319af1SAsmitha Karunanithi const std::vector<std::string>& subTreePaths) { 83480319af1SAsmitha Karunanithi if (ec) 83580319af1SAsmitha Karunanithi { 83680319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 83780319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 83880319af1SAsmitha Karunanithi return; 83980319af1SAsmitha Karunanithi } 84080319af1SAsmitha Karunanithi 84180319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 84280319af1SAsmitha Karunanithi { 8432dfd18efSEd Tanous sdbusplus::message::object_path objPath(path); 8442dfd18efSEd Tanous std::string logID = objPath.filename(); 8452dfd18efSEd Tanous if (logID.empty()) 84680319af1SAsmitha Karunanithi { 8472dfd18efSEd Tanous continue; 84880319af1SAsmitha Karunanithi } 8492dfd18efSEd Tanous deleteDumpEntry(asyncResp, logID, dumpType); 85080319af1SAsmitha Karunanithi } 85180319af1SAsmitha Karunanithi }, 85280319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 85380319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 85480319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 855b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, 856b47452b2SAsmitha Karunanithi std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." + 857b47452b2SAsmitha Karunanithi dumpType}); 85880319af1SAsmitha Karunanithi } 85980319af1SAsmitha Karunanithi 8602c70f800SEd Tanous static void parseCrashdumpParameters( 861043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params, 862043a0536SJohnathan Mantey std::string& filename, std::string& timestamp, std::string& logfile) 863043a0536SJohnathan Mantey { 864043a0536SJohnathan Mantey for (auto property : params) 865043a0536SJohnathan Mantey { 866043a0536SJohnathan Mantey if (property.first == "Timestamp") 867043a0536SJohnathan Mantey { 868043a0536SJohnathan Mantey const std::string* value = 8698d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 870043a0536SJohnathan Mantey if (value != nullptr) 871043a0536SJohnathan Mantey { 872043a0536SJohnathan Mantey timestamp = *value; 873043a0536SJohnathan Mantey } 874043a0536SJohnathan Mantey } 875043a0536SJohnathan Mantey else if (property.first == "Filename") 876043a0536SJohnathan Mantey { 877043a0536SJohnathan Mantey const std::string* value = 8788d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 879043a0536SJohnathan Mantey if (value != nullptr) 880043a0536SJohnathan Mantey { 881043a0536SJohnathan Mantey filename = *value; 882043a0536SJohnathan Mantey } 883043a0536SJohnathan Mantey } 884043a0536SJohnathan Mantey else if (property.first == "Log") 885043a0536SJohnathan Mantey { 886043a0536SJohnathan Mantey const std::string* value = 8878d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 888043a0536SJohnathan Mantey if (value != nullptr) 889043a0536SJohnathan Mantey { 890043a0536SJohnathan Mantey logfile = *value; 891043a0536SJohnathan Mantey } 892043a0536SJohnathan Mantey } 893043a0536SJohnathan Mantey } 894043a0536SJohnathan Mantey } 895043a0536SJohnathan Mantey 896a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 897c4bf6374SJason M. Bills class SystemLogServiceCollection : public Node 8981da66f75SEd Tanous { 8991da66f75SEd Tanous public: 90052cc112dSEd Tanous SystemLogServiceCollection(App& app) : 901029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/") 902c4bf6374SJason M. Bills { 903c4bf6374SJason M. Bills entityPrivileges = { 904c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 905c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 906c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 907c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 908c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 909c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 910c4bf6374SJason M. Bills } 911c4bf6374SJason M. Bills 912c4bf6374SJason M. Bills private: 913c4bf6374SJason M. Bills /** 914c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 915c4bf6374SJason M. Bills */ 916cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 917cb13a392SEd Tanous const std::vector<std::string>&) override 918c4bf6374SJason M. Bills { 919c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 920c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 921c4bf6374SJason M. Bills // it has a duplicate entry for members 922c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 923c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 924c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 925029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 926c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 927c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 928c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 929c4bf6374SJason M. Bills nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 930c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 931029573d4SEd Tanous logServiceArray.push_back( 932029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}}); 9335cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 934c9bb6861Sraviteja-b logServiceArray.push_back( 9355cb1dd27SAsmitha Karunanithi {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}}); 936c9bb6861Sraviteja-b #endif 937c9bb6861Sraviteja-b 938d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 939d53dd41fSJason M. Bills logServiceArray.push_back( 940cb92c03bSAndrew Geissler {{"@odata.id", 941424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 942d53dd41fSJason M. Bills #endif 943c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 944c4bf6374SJason M. Bills logServiceArray.size(); 945a3316fc6SZhikuiRen 946a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 947a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 948a3316fc6SZhikuiRen const std::vector<std::string>& subtreePath) { 949a3316fc6SZhikuiRen if (ec) 950a3316fc6SZhikuiRen { 951a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 952a3316fc6SZhikuiRen return; 953a3316fc6SZhikuiRen } 954a3316fc6SZhikuiRen 955a3316fc6SZhikuiRen for (auto& pathStr : subtreePath) 956a3316fc6SZhikuiRen { 957a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 958a3316fc6SZhikuiRen { 95923a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 960a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 96123a21a1cSEd Tanous logServiceArrayLocal.push_back( 962a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 963a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 964a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 96523a21a1cSEd Tanous logServiceArrayLocal.size(); 966a3316fc6SZhikuiRen return; 967a3316fc6SZhikuiRen } 968a3316fc6SZhikuiRen } 969a3316fc6SZhikuiRen }, 970a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 971a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 972a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 973a3316fc6SZhikuiRen std::array<const char*, 1>{postCodeIface}); 974c4bf6374SJason M. Bills } 975c4bf6374SJason M. Bills }; 976c4bf6374SJason M. Bills 977c4bf6374SJason M. Bills class EventLogService : public Node 978c4bf6374SJason M. Bills { 979c4bf6374SJason M. Bills public: 98052cc112dSEd Tanous EventLogService(App& app) : 981029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 982c4bf6374SJason M. Bills { 983c4bf6374SJason M. Bills entityPrivileges = { 984c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 985c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 986c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 987c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 988c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 989c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 990c4bf6374SJason M. Bills } 991c4bf6374SJason M. Bills 992c4bf6374SJason M. Bills private: 993cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 994cb13a392SEd Tanous const std::vector<std::string>&) override 995c4bf6374SJason M. Bills { 996c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 997c4bf6374SJason M. Bills 998c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 999029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1000c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1001c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 1002c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 1003c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 1004c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1005c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1006c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1007c4bf6374SJason M. Bills {"@odata.id", 1008029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 1009e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1010e7d6c8b2SGunnar Mills 1011e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 1012e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 1013489640c6SJason M. Bills } 1014489640c6SJason M. Bills }; 1015489640c6SJason M. Bills 10161f56a3a6STim Lee class JournalEventLogClear : public Node 1017489640c6SJason M. Bills { 1018489640c6SJason M. Bills public: 101952cc112dSEd Tanous JournalEventLogClear(App& app) : 1020489640c6SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 1021489640c6SJason M. Bills "LogService.ClearLog/") 1022489640c6SJason M. Bills { 1023489640c6SJason M. Bills entityPrivileges = { 1024489640c6SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1025489640c6SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1026489640c6SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1027489640c6SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1028489640c6SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1029489640c6SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1030489640c6SJason M. Bills } 1031489640c6SJason M. Bills 1032489640c6SJason M. Bills private: 1033cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 1034cb13a392SEd Tanous const std::vector<std::string>&) override 1035489640c6SJason M. Bills { 1036489640c6SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1037489640c6SJason M. Bills 1038489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1039489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1040489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1041489640c6SJason M. Bills { 1042489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1043489640c6SJason M. Bills { 1044489640c6SJason M. Bills std::error_code ec; 1045489640c6SJason M. Bills std::filesystem::remove(file, ec); 1046489640c6SJason M. Bills } 1047489640c6SJason M. Bills } 1048489640c6SJason M. Bills 1049489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1050489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1051489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1052489640c6SJason M. Bills if (ec) 1053489640c6SJason M. Bills { 1054489640c6SJason M. Bills BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 1055489640c6SJason M. Bills messages::internalError(asyncResp->res); 1056489640c6SJason M. Bills return; 1057489640c6SJason M. Bills } 1058489640c6SJason M. Bills 1059489640c6SJason M. Bills messages::success(asyncResp->res); 1060489640c6SJason M. Bills }, 1061489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 1062489640c6SJason M. Bills "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 1063489640c6SJason M. Bills "replace"); 1064c4bf6374SJason M. Bills } 1065c4bf6374SJason M. Bills }; 1066c4bf6374SJason M. Bills 106795820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 1068b5a76932SEd Tanous const std::string& logEntry, 106995820184SJason M. Bills nlohmann::json& logEntryJson) 1070c4bf6374SJason M. Bills { 107195820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1072cd225da8SJason M. Bills // First get the Timestamp 1073f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1074cd225da8SJason M. Bills if (space == std::string::npos) 107595820184SJason M. Bills { 107695820184SJason M. Bills return 1; 107795820184SJason M. Bills } 1078cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1079cd225da8SJason M. Bills // Then get the log contents 1080f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1081cd225da8SJason M. Bills if (entryStart == std::string::npos) 1082cd225da8SJason M. Bills { 1083cd225da8SJason M. Bills return 1; 1084cd225da8SJason M. Bills } 1085cd225da8SJason M. Bills std::string_view entry(logEntry); 1086cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1087cd225da8SJason M. Bills // Use split to separate the entry into its fields 1088cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1089cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1090cd225da8SJason M. Bills boost::token_compress_on); 1091cd225da8SJason M. Bills // We need at least a MessageId to be valid 1092cd225da8SJason M. Bills if (logEntryFields.size() < 1) 1093cd225da8SJason M. Bills { 1094cd225da8SJason M. Bills return 1; 1095cd225da8SJason M. Bills } 1096cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 109795820184SJason M. Bills 10984851d45dSJason M. Bills // Get the Message from the MessageRegistry 10994851d45dSJason M. Bills const message_registries::Message* message = 11004851d45dSJason M. Bills message_registries::getMessage(messageID); 1101c4bf6374SJason M. Bills 11024851d45dSJason M. Bills std::string msg; 11034851d45dSJason M. Bills std::string severity; 11044851d45dSJason M. Bills if (message != nullptr) 1105c4bf6374SJason M. Bills { 11064851d45dSJason M. Bills msg = message->message; 11074851d45dSJason M. Bills severity = message->severity; 1108c4bf6374SJason M. Bills } 1109c4bf6374SJason M. Bills 111015a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 111115a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 111215a86ff6SJason M. Bills if (logEntryFields.size() > 1) 111315a86ff6SJason M. Bills { 111415a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 111515a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 111615a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 111715a86ff6SJason M. Bills if (!messageArgsStart.empty()) 111815a86ff6SJason M. Bills { 111915a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 112015a86ff6SJason M. Bills } 112115a86ff6SJason M. Bills 112223a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1123c4bf6374SJason M. Bills 11244851d45dSJason M. Bills // Fill the MessageArgs into the Message 112595820184SJason M. Bills int i = 0; 112695820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11274851d45dSJason M. Bills { 112895820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11294851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11304851d45dSJason M. Bills if (argPos != std::string::npos) 11314851d45dSJason M. Bills { 113295820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11334851d45dSJason M. Bills } 11344851d45dSJason M. Bills } 113515a86ff6SJason M. Bills } 11364851d45dSJason M. Bills 113795820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 113895820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 113995820184SJason M. Bills // between the '.' and the '+', so just remove them. 1140f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1141f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 114295820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1143c4bf6374SJason M. Bills { 114495820184SJason M. Bills timestamp.erase(dot, plus - dot); 1145c4bf6374SJason M. Bills } 1146c4bf6374SJason M. Bills 1147c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 114895820184SJason M. Bills logEntryJson = { 1149cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1150029573d4SEd Tanous {"@odata.id", 1151897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 115295820184SJason M. Bills logEntryID}, 1153c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 115495820184SJason M. Bills {"Id", logEntryID}, 115595820184SJason M. Bills {"Message", std::move(msg)}, 115695820184SJason M. Bills {"MessageId", std::move(messageID)}, 1157f23b7296SEd Tanous {"MessageArgs", messageArgs}, 1158c4bf6374SJason M. Bills {"EntryType", "Event"}, 115995820184SJason M. Bills {"Severity", std::move(severity)}, 116095820184SJason M. Bills {"Created", std::move(timestamp)}}; 1161c4bf6374SJason M. Bills return 0; 1162c4bf6374SJason M. Bills } 1163c4bf6374SJason M. Bills 116427062605SAnthony Wilson class JournalEventLogEntryCollection : public Node 1165c4bf6374SJason M. Bills { 1166c4bf6374SJason M. Bills public: 116752cc112dSEd Tanous JournalEventLogEntryCollection(App& app) : 1168029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1169c4bf6374SJason M. Bills { 1170c4bf6374SJason M. Bills entityPrivileges = { 1171c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1172c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1173c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1174c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1175c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1176c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1177c4bf6374SJason M. Bills } 1178c4bf6374SJason M. Bills 1179c4bf6374SJason M. Bills private: 1180c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1181cb13a392SEd Tanous const std::vector<std::string>&) override 1182c4bf6374SJason M. Bills { 1183c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1184271584abSEd Tanous uint64_t skip = 0; 1185271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 1186c4bf6374SJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1187c4bf6374SJason M. Bills { 1188c4bf6374SJason M. Bills return; 1189c4bf6374SJason M. Bills } 1190c4bf6374SJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1191c4bf6374SJason M. Bills { 1192c4bf6374SJason M. Bills return; 1193c4bf6374SJason M. Bills } 1194c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 1195c4bf6374SJason M. Bills // it has a duplicate entry for members 1196c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1197c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1198c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1199029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1200c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1201c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1202c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1203cb92c03bSAndrew Geissler 1204c4bf6374SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1205c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 120695820184SJason M. Bills // Go through the log files and create a unique ID for each entry 120795820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 120895820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1209b01bf299SEd Tanous uint64_t entryCount = 0; 1210cd225da8SJason M. Bills std::string logEntry; 121195820184SJason M. Bills 121295820184SJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 1213cd225da8SJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1214cd225da8SJason M. Bills it++) 1215c4bf6374SJason M. Bills { 1216cd225da8SJason M. Bills std::ifstream logStream(*it); 121795820184SJason M. Bills if (!logStream.is_open()) 1218c4bf6374SJason M. Bills { 1219c4bf6374SJason M. Bills continue; 1220c4bf6374SJason M. Bills } 1221c4bf6374SJason M. Bills 1222e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1223e85d6b16SJason M. Bills bool firstEntry = true; 122495820184SJason M. Bills while (std::getline(logStream, logEntry)) 122595820184SJason M. Bills { 1226c4bf6374SJason M. Bills entryCount++; 1227c4bf6374SJason M. Bills // Handle paging using skip (number of entries to skip from the 1228c4bf6374SJason M. Bills // start) and top (number of entries to display) 1229c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1230c4bf6374SJason M. Bills { 1231c4bf6374SJason M. Bills continue; 1232c4bf6374SJason M. Bills } 1233c4bf6374SJason M. Bills 1234c4bf6374SJason M. Bills std::string idStr; 1235e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1236c4bf6374SJason M. Bills { 1237c4bf6374SJason M. Bills continue; 1238c4bf6374SJason M. Bills } 1239c4bf6374SJason M. Bills 1240e85d6b16SJason M. Bills if (firstEntry) 1241e85d6b16SJason M. Bills { 1242e85d6b16SJason M. Bills firstEntry = false; 1243e85d6b16SJason M. Bills } 1244e85d6b16SJason M. Bills 1245c4bf6374SJason M. Bills logEntryArray.push_back({}); 1246c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 124795820184SJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0) 1248c4bf6374SJason M. Bills { 1249c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1250c4bf6374SJason M. Bills return; 1251c4bf6374SJason M. Bills } 1252c4bf6374SJason M. Bills } 125395820184SJason M. Bills } 1254c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1255c4bf6374SJason M. Bills if (skip + top < entryCount) 1256c4bf6374SJason M. Bills { 1257c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 125895820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 125995820184SJason M. Bills "Entries?$skip=" + 1260c4bf6374SJason M. Bills std::to_string(skip + top); 1261c4bf6374SJason M. Bills } 126208a4e4b5SAnthony Wilson } 126308a4e4b5SAnthony Wilson }; 126408a4e4b5SAnthony Wilson 1265897967deSJason M. Bills class JournalEventLogEntry : public Node 1266897967deSJason M. Bills { 1267897967deSJason M. Bills public: 126852cc112dSEd Tanous JournalEventLogEntry(App& app) : 1269897967deSJason M. Bills Node(app, 1270897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1271897967deSJason M. Bills std::string()) 1272897967deSJason M. Bills { 1273897967deSJason M. Bills entityPrivileges = { 1274897967deSJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1275897967deSJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1276897967deSJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1277897967deSJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1278897967deSJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1279897967deSJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1280897967deSJason M. Bills } 1281897967deSJason M. Bills 1282897967deSJason M. Bills private: 1283cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1284897967deSJason M. Bills const std::vector<std::string>& params) override 1285897967deSJason M. Bills { 1286897967deSJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1287897967deSJason M. Bills if (params.size() != 1) 1288897967deSJason M. Bills { 1289897967deSJason M. Bills messages::internalError(asyncResp->res); 1290897967deSJason M. Bills return; 1291897967deSJason M. Bills } 1292897967deSJason M. Bills const std::string& targetID = params[0]; 1293897967deSJason M. Bills 1294897967deSJason M. Bills // Go through the log files and check the unique ID for each entry to 1295897967deSJason M. Bills // find the target entry 1296897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1297897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1298897967deSJason M. Bills std::string logEntry; 1299897967deSJason M. Bills 1300897967deSJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 1301897967deSJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1302897967deSJason M. Bills it++) 1303897967deSJason M. Bills { 1304897967deSJason M. Bills std::ifstream logStream(*it); 1305897967deSJason M. Bills if (!logStream.is_open()) 1306897967deSJason M. Bills { 1307897967deSJason M. Bills continue; 1308897967deSJason M. Bills } 1309897967deSJason M. Bills 1310897967deSJason M. Bills // Reset the unique ID on the first entry 1311897967deSJason M. Bills bool firstEntry = true; 1312897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1313897967deSJason M. Bills { 1314897967deSJason M. Bills std::string idStr; 1315897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1316897967deSJason M. Bills { 1317897967deSJason M. Bills continue; 1318897967deSJason M. Bills } 1319897967deSJason M. Bills 1320897967deSJason M. Bills if (firstEntry) 1321897967deSJason M. Bills { 1322897967deSJason M. Bills firstEntry = false; 1323897967deSJason M. Bills } 1324897967deSJason M. Bills 1325897967deSJason M. Bills if (idStr == targetID) 1326897967deSJason M. Bills { 1327897967deSJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, 1328897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1329897967deSJason M. Bills { 1330897967deSJason M. Bills messages::internalError(asyncResp->res); 1331897967deSJason M. Bills return; 1332897967deSJason M. Bills } 1333897967deSJason M. Bills return; 1334897967deSJason M. Bills } 1335897967deSJason M. Bills } 1336897967deSJason M. Bills } 1337897967deSJason M. Bills // Requested ID was not found 1338897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 1339897967deSJason M. Bills } 1340897967deSJason M. Bills }; 1341897967deSJason M. Bills 134208a4e4b5SAnthony Wilson class DBusEventLogEntryCollection : public Node 134308a4e4b5SAnthony Wilson { 134408a4e4b5SAnthony Wilson public: 134552cc112dSEd Tanous DBusEventLogEntryCollection(App& app) : 134608a4e4b5SAnthony Wilson Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 134708a4e4b5SAnthony Wilson { 134808a4e4b5SAnthony Wilson entityPrivileges = { 134908a4e4b5SAnthony Wilson {boost::beast::http::verb::get, {{"Login"}}}, 135008a4e4b5SAnthony Wilson {boost::beast::http::verb::head, {{"Login"}}}, 135108a4e4b5SAnthony Wilson {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 135208a4e4b5SAnthony Wilson {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 135308a4e4b5SAnthony Wilson {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 135408a4e4b5SAnthony Wilson {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 135508a4e4b5SAnthony Wilson } 135608a4e4b5SAnthony Wilson 135708a4e4b5SAnthony Wilson private: 1358cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1359cb13a392SEd Tanous const std::vector<std::string>&) override 136008a4e4b5SAnthony Wilson { 136108a4e4b5SAnthony Wilson std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 136208a4e4b5SAnthony Wilson 136308a4e4b5SAnthony Wilson // Collections don't include the static data added by SubRoute because 136408a4e4b5SAnthony Wilson // it has a duplicate entry for members 136508a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 136608a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 136708a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 136808a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 136908a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 137008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 137108a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 137208a4e4b5SAnthony Wilson 1373cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1374cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1375cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1376cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1377cb92c03bSAndrew Geissler GetManagedObjectsType& resp) { 1378cb92c03bSAndrew Geissler if (ec) 1379cb92c03bSAndrew Geissler { 1380cb92c03bSAndrew Geissler // TODO Handle for specific error code 1381cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1382cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1383cb92c03bSAndrew Geissler << ec; 1384cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1385cb92c03bSAndrew Geissler return; 1386cb92c03bSAndrew Geissler } 1387cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1388cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1389cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 1390cb92c03bSAndrew Geissler for (auto& objectPath : resp) 1391cb92c03bSAndrew Geissler { 1392cb92c03bSAndrew Geissler for (auto& interfaceMap : objectPath.second) 1393cb92c03bSAndrew Geissler { 1394cb92c03bSAndrew Geissler if (interfaceMap.first != 1395cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry") 1396cb92c03bSAndrew Geissler { 1397cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Bailing early on " 1398cb92c03bSAndrew Geissler << interfaceMap.first; 1399cb92c03bSAndrew Geissler continue; 1400cb92c03bSAndrew Geissler } 1401cb92c03bSAndrew Geissler entriesArray.push_back({}); 1402cb92c03bSAndrew Geissler nlohmann::json& thisEntry = entriesArray.back(); 140366664f25SEd Tanous uint32_t* id = nullptr; 140466664f25SEd Tanous std::time_t timestamp{}; 1405d139c236SGeorge Liu std::time_t updateTimestamp{}; 140666664f25SEd Tanous std::string* severity = nullptr; 140766664f25SEd Tanous std::string* message = nullptr; 1408d139c236SGeorge Liu 1409cb92c03bSAndrew Geissler for (auto& propertyMap : interfaceMap.second) 1410cb92c03bSAndrew Geissler { 1411cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1412cb92c03bSAndrew Geissler { 14138d78b7a9SPatrick Williams id = std::get_if<uint32_t>(&propertyMap.second); 1414cb92c03bSAndrew Geissler } 1415cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1416cb92c03bSAndrew Geissler { 1417cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1418cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1419ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1420ebd45906SGeorge Liu { 1421d139c236SGeorge Liu timestamp = crow::utility::getTimestamp( 1422cb92c03bSAndrew Geissler *millisTimeStamp); 1423d139c236SGeorge Liu } 1424ebd45906SGeorge Liu } 1425d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1426d139c236SGeorge Liu { 1427d139c236SGeorge Liu const uint64_t* millisTimeStamp = 1428d139c236SGeorge Liu std::get_if<uint64_t>(&propertyMap.second); 1429ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1430ebd45906SGeorge Liu { 1431ebd45906SGeorge Liu updateTimestamp = 1432ebd45906SGeorge Liu crow::utility::getTimestamp( 1433d139c236SGeorge Liu *millisTimeStamp); 1434cb92c03bSAndrew Geissler } 1435ebd45906SGeorge Liu } 1436cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1437cb92c03bSAndrew Geissler { 1438cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1439cb92c03bSAndrew Geissler &propertyMap.second); 1440cb92c03bSAndrew Geissler } 1441cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1442cb92c03bSAndrew Geissler { 1443cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1444cb92c03bSAndrew Geissler &propertyMap.second); 1445ae34c8e8SAdriana Kobylak } 1446ae34c8e8SAdriana Kobylak } 1447ae34c8e8SAdriana Kobylak if (id == nullptr || message == nullptr || 1448ae34c8e8SAdriana Kobylak severity == nullptr) 1449cb92c03bSAndrew Geissler { 14500f1d8ed9SAsmitha Karunanithi messages::internalError(asyncResp->res); 1451ae34c8e8SAdriana Kobylak return; 1452cb92c03bSAndrew Geissler } 1453cb92c03bSAndrew Geissler thisEntry = { 1454d139c236SGeorge Liu {"@odata.type", "#LogEntry.v1_6_0.LogEntry"}, 1455cb92c03bSAndrew Geissler {"@odata.id", 1456cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1457cb92c03bSAndrew Geissler "Entries/" + 1458cb92c03bSAndrew Geissler std::to_string(*id)}, 145927062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1460cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1461cb92c03bSAndrew Geissler {"Message", *message}, 1462cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1463cb92c03bSAndrew Geissler {"Severity", 1464cb92c03bSAndrew Geissler translateSeverityDbusToRedfish(*severity)}, 1465d139c236SGeorge Liu {"Created", crow::utility::getDateTime(timestamp)}, 1466d139c236SGeorge Liu {"Modified", 1467d139c236SGeorge Liu crow::utility::getDateTime(updateTimestamp)}}; 1468cb92c03bSAndrew Geissler } 1469cb92c03bSAndrew Geissler } 1470cb92c03bSAndrew Geissler std::sort(entriesArray.begin(), entriesArray.end(), 1471cb92c03bSAndrew Geissler [](const nlohmann::json& left, 1472cb92c03bSAndrew Geissler const nlohmann::json& right) { 1473cb92c03bSAndrew Geissler return (left["Id"] <= right["Id"]); 1474cb92c03bSAndrew Geissler }); 1475cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members@odata.count"] = 1476cb92c03bSAndrew Geissler entriesArray.size(); 1477cb92c03bSAndrew Geissler }, 1478cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 1479cb92c03bSAndrew Geissler "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 1480c4bf6374SJason M. Bills } 1481c4bf6374SJason M. Bills }; 1482c4bf6374SJason M. Bills 148308a4e4b5SAnthony Wilson class DBusEventLogEntry : public Node 1484c4bf6374SJason M. Bills { 1485c4bf6374SJason M. Bills public: 148652cc112dSEd Tanous DBusEventLogEntry(App& app) : 1487c4bf6374SJason M. Bills Node(app, 1488029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1489029573d4SEd Tanous std::string()) 1490c4bf6374SJason M. Bills { 1491c4bf6374SJason M. Bills entityPrivileges = { 1492c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1493c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1494c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1495c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1496c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1497c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1498c4bf6374SJason M. Bills } 1499c4bf6374SJason M. Bills 1500c4bf6374SJason M. Bills private: 1501cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1502c4bf6374SJason M. Bills const std::vector<std::string>& params) override 1503c4bf6374SJason M. Bills { 1504c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1505029573d4SEd Tanous if (params.size() != 1) 1506c4bf6374SJason M. Bills { 1507c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1508c4bf6374SJason M. Bills return; 1509c4bf6374SJason M. Bills } 1510ae34c8e8SAdriana Kobylak std::string entryID = params[0]; 1511ae34c8e8SAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1512cb92c03bSAndrew Geissler 1513cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1514cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1515cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1516cb92c03bSAndrew Geissler [asyncResp, entryID](const boost::system::error_code ec, 1517cb92c03bSAndrew Geissler GetManagedPropertyType& resp) { 1518ae34c8e8SAdriana Kobylak if (ec.value() == EBADR) 1519ae34c8e8SAdriana Kobylak { 1520ae34c8e8SAdriana Kobylak messages::resourceNotFound(asyncResp->res, "EventLogEntry", 1521ae34c8e8SAdriana Kobylak entryID); 1522ae34c8e8SAdriana Kobylak return; 1523ae34c8e8SAdriana Kobylak } 1524cb92c03bSAndrew Geissler if (ec) 1525cb92c03bSAndrew Geissler { 1526cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1527cb92c03bSAndrew Geissler << "EventLogEntry (DBus) resp_handler got error " << ec; 1528cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1529cb92c03bSAndrew Geissler return; 1530cb92c03bSAndrew Geissler } 153166664f25SEd Tanous uint32_t* id = nullptr; 153266664f25SEd Tanous std::time_t timestamp{}; 1533d139c236SGeorge Liu std::time_t updateTimestamp{}; 153466664f25SEd Tanous std::string* severity = nullptr; 153566664f25SEd Tanous std::string* message = nullptr; 1536d139c236SGeorge Liu 1537cb92c03bSAndrew Geissler for (auto& propertyMap : resp) 1538cb92c03bSAndrew Geissler { 1539cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1540cb92c03bSAndrew Geissler { 1541cb92c03bSAndrew Geissler id = std::get_if<uint32_t>(&propertyMap.second); 1542cb92c03bSAndrew Geissler } 1543cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1544cb92c03bSAndrew Geissler { 1545cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1546cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1547ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1548ebd45906SGeorge Liu { 1549cb92c03bSAndrew Geissler timestamp = 1550d139c236SGeorge Liu crow::utility::getTimestamp(*millisTimeStamp); 1551d139c236SGeorge Liu } 1552ebd45906SGeorge Liu } 1553d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1554d139c236SGeorge Liu { 1555d139c236SGeorge Liu const uint64_t* millisTimeStamp = 1556d139c236SGeorge Liu std::get_if<uint64_t>(&propertyMap.second); 1557ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1558ebd45906SGeorge Liu { 1559d139c236SGeorge Liu updateTimestamp = 1560d139c236SGeorge Liu crow::utility::getTimestamp(*millisTimeStamp); 1561cb92c03bSAndrew Geissler } 1562ebd45906SGeorge Liu } 1563cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1564cb92c03bSAndrew Geissler { 1565cb92c03bSAndrew Geissler severity = 1566cb92c03bSAndrew Geissler std::get_if<std::string>(&propertyMap.second); 1567cb92c03bSAndrew Geissler } 1568cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1569cb92c03bSAndrew Geissler { 1570cb92c03bSAndrew Geissler message = std::get_if<std::string>(&propertyMap.second); 1571cb92c03bSAndrew Geissler } 1572cb92c03bSAndrew Geissler } 1573271584abSEd Tanous if (id == nullptr || message == nullptr || severity == nullptr) 1574271584abSEd Tanous { 1575ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1576271584abSEd Tanous return; 1577271584abSEd Tanous } 1578cb92c03bSAndrew Geissler asyncResp->res.jsonValue = { 1579d139c236SGeorge Liu {"@odata.type", "#LogEntry.v1_6_0.LogEntry"}, 1580cb92c03bSAndrew Geissler {"@odata.id", 1581cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1582cb92c03bSAndrew Geissler "Entries/" + 1583cb92c03bSAndrew Geissler std::to_string(*id)}, 158427062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1585cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1586cb92c03bSAndrew Geissler {"Message", *message}, 1587cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1588cb92c03bSAndrew Geissler {"Severity", translateSeverityDbusToRedfish(*severity)}, 1589d139c236SGeorge Liu {"Created", crow::utility::getDateTime(timestamp)}, 1590d139c236SGeorge Liu {"Modified", crow::utility::getDateTime(updateTimestamp)}}; 1591cb92c03bSAndrew Geissler }, 1592cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1593cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1594cb92c03bSAndrew Geissler "org.freedesktop.DBus.Properties", "GetAll", 1595cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry"); 1596c4bf6374SJason M. Bills } 1597336e96c6SChicago Duan 1598cb13a392SEd Tanous void doDelete(crow::Response& res, const crow::Request&, 1599336e96c6SChicago Duan const std::vector<std::string>& params) override 1600336e96c6SChicago Duan { 1601336e96c6SChicago Duan 1602336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1603336e96c6SChicago Duan 1604336e96c6SChicago Duan auto asyncResp = std::make_shared<AsyncResp>(res); 1605336e96c6SChicago Duan 1606336e96c6SChicago Duan if (params.size() != 1) 1607336e96c6SChicago Duan { 1608336e96c6SChicago Duan messages::internalError(asyncResp->res); 1609336e96c6SChicago Duan return; 1610336e96c6SChicago Duan } 1611336e96c6SChicago Duan std::string entryID = params[0]; 1612336e96c6SChicago Duan 1613336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1614336e96c6SChicago Duan 1615336e96c6SChicago Duan // Process response from Logging service. 1616336e96c6SChicago Duan auto respHandler = [asyncResp](const boost::system::error_code ec) { 1617336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1618336e96c6SChicago Duan if (ec) 1619336e96c6SChicago Duan { 1620336e96c6SChicago Duan // TODO Handle for specific error code 1621336e96c6SChicago Duan BMCWEB_LOG_ERROR 1622336e96c6SChicago Duan << "EventLogEntry (DBus) doDelete respHandler got error " 1623336e96c6SChicago Duan << ec; 1624336e96c6SChicago Duan asyncResp->res.result( 1625336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1626336e96c6SChicago Duan return; 1627336e96c6SChicago Duan } 1628336e96c6SChicago Duan 1629336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1630336e96c6SChicago Duan }; 1631336e96c6SChicago Duan 1632336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1633336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1634336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1635336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1636336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 1637336e96c6SChicago Duan } 1638c4bf6374SJason M. Bills }; 1639c4bf6374SJason M. Bills 1640c4bf6374SJason M. Bills class BMCLogServiceCollection : public Node 1641c4bf6374SJason M. Bills { 1642c4bf6374SJason M. Bills public: 164352cc112dSEd Tanous BMCLogServiceCollection(App& app) : 16444ed77cd5SEd Tanous Node(app, "/redfish/v1/Managers/bmc/LogServices/") 16451da66f75SEd Tanous { 16461da66f75SEd Tanous entityPrivileges = { 1647e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1648e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1649e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1650e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1651e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1652e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 16531da66f75SEd Tanous } 16541da66f75SEd Tanous 16551da66f75SEd Tanous private: 16561da66f75SEd Tanous /** 16571da66f75SEd Tanous * Functions triggers appropriate requests on DBus 16581da66f75SEd Tanous */ 1659cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1660cb13a392SEd Tanous const std::vector<std::string>&) override 16611da66f75SEd Tanous { 1662e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 16631da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 16641da66f75SEd Tanous // it has a duplicate entry for members 1665e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 16661da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1667e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1668e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 1669e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 1670e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 16711da66f75SEd Tanous "Collection of LogServices for this Manager"; 1672c4bf6374SJason M. Bills nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 1673c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 16745cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 16755cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 16765cb1dd27SAsmitha Karunanithi {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 16775cb1dd27SAsmitha Karunanithi #endif 1678c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1679c4bf6374SJason M. Bills logServiceArray.push_back( 168008a4e4b5SAnthony Wilson {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1681c4bf6374SJason M. Bills #endif 1682e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1683c4bf6374SJason M. Bills logServiceArray.size(); 16841da66f75SEd Tanous } 16851da66f75SEd Tanous }; 16861da66f75SEd Tanous 1687c4bf6374SJason M. Bills class BMCJournalLogService : public Node 16881da66f75SEd Tanous { 16891da66f75SEd Tanous public: 169052cc112dSEd Tanous BMCJournalLogService(App& app) : 1691c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1692e1f26343SJason M. Bills { 1693e1f26343SJason M. Bills entityPrivileges = { 1694e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1695e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1696e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1697e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1698e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1699e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1700e1f26343SJason M. Bills } 1701e1f26343SJason M. Bills 1702e1f26343SJason M. Bills private: 1703cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1704cb13a392SEd Tanous const std::vector<std::string>&) override 1705e1f26343SJason M. Bills { 1706e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1707e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1708e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 17090f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 17100f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 1711c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 1712c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 1713c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1714e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1715cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1716cd50aa42SJason M. Bills {"@odata.id", 1717086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 1718e1f26343SJason M. Bills } 1719e1f26343SJason M. Bills }; 1720e1f26343SJason M. Bills 1721c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 1722e1f26343SJason M. Bills sd_journal* journal, 1723c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 1724e1f26343SJason M. Bills { 1725e1f26343SJason M. Bills // Get the Log Entry contents 1726e1f26343SJason M. Bills int ret = 0; 1727e1f26343SJason M. Bills 1728a8fe54f0SJason M. Bills std::string message; 1729a8fe54f0SJason M. Bills std::string_view syslogID; 1730a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 1731a8fe54f0SJason M. Bills if (ret < 0) 1732a8fe54f0SJason M. Bills { 1733a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 1734a8fe54f0SJason M. Bills << strerror(-ret); 1735a8fe54f0SJason M. Bills } 1736a8fe54f0SJason M. Bills if (!syslogID.empty()) 1737a8fe54f0SJason M. Bills { 1738a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 1739a8fe54f0SJason M. Bills } 1740a8fe54f0SJason M. Bills 174139e77504SEd Tanous std::string_view msg; 174216428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1743e1f26343SJason M. Bills if (ret < 0) 1744e1f26343SJason M. Bills { 1745e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1746e1f26343SJason M. Bills return 1; 1747e1f26343SJason M. Bills } 1748a8fe54f0SJason M. Bills message += std::string(msg); 1749e1f26343SJason M. Bills 1750e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1751271584abSEd Tanous long int severity = 8; // Default to an invalid priority 175216428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1753e1f26343SJason M. Bills if (ret < 0) 1754e1f26343SJason M. Bills { 1755e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1756e1f26343SJason M. Bills } 1757e1f26343SJason M. Bills 1758e1f26343SJason M. Bills // Get the Created time from the timestamp 175916428a1aSJason M. Bills std::string entryTimeStr; 176016428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1761e1f26343SJason M. Bills { 176216428a1aSJason M. Bills return 1; 1763e1f26343SJason M. Bills } 1764e1f26343SJason M. Bills 1765e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1766c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 1767cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1768c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1769c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1770e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1771c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 1772a8fe54f0SJason M. Bills {"Message", std::move(message)}, 1773e1f26343SJason M. Bills {"EntryType", "Oem"}, 1774*738c1e61SPatrick Williams {"Severity", severity <= 2 ? "Critical" 1775*738c1e61SPatrick Williams : severity <= 4 ? "Warning" 1776*738c1e61SPatrick Williams : "OK"}, 1777086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1778e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1779e1f26343SJason M. Bills return 0; 1780e1f26343SJason M. Bills } 1781e1f26343SJason M. Bills 1782c4bf6374SJason M. Bills class BMCJournalLogEntryCollection : public Node 1783e1f26343SJason M. Bills { 1784e1f26343SJason M. Bills public: 178552cc112dSEd Tanous BMCJournalLogEntryCollection(App& app) : 1786c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1787e1f26343SJason M. Bills { 1788e1f26343SJason M. Bills entityPrivileges = { 1789e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1790e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1791e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1792e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1793e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1794e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1795e1f26343SJason M. Bills } 1796e1f26343SJason M. Bills 1797e1f26343SJason M. Bills private: 1798e1f26343SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1799cb13a392SEd Tanous const std::vector<std::string>&) override 1800e1f26343SJason M. Bills { 1801e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1802193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1803271584abSEd Tanous uint64_t skip = 0; 1804271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 180516428a1aSJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1806193ad2faSJason M. Bills { 1807193ad2faSJason M. Bills return; 1808193ad2faSJason M. Bills } 180916428a1aSJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1810193ad2faSJason M. Bills { 1811193ad2faSJason M. Bills return; 1812193ad2faSJason M. Bills } 1813e1f26343SJason M. Bills // Collections don't include the static data added by SubRoute because 1814e1f26343SJason M. Bills // it has a duplicate entry for members 1815e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1816e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 18170f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18180f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1819e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1820c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1821e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1822e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1823e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 18240f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18250f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries"; 1826e1f26343SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1827e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1828e1f26343SJason M. Bills 1829e1f26343SJason M. Bills // Go through the journal and use the timestamp to create a unique ID 1830e1f26343SJason M. Bills // for each entry 1831e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1832e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1833e1f26343SJason M. Bills if (ret < 0) 1834e1f26343SJason M. Bills { 1835e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1836f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1837e1f26343SJason M. Bills return; 1838e1f26343SJason M. Bills } 1839e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1840e1f26343SJason M. Bills journalTmp, sd_journal_close); 1841e1f26343SJason M. Bills journalTmp = nullptr; 1842b01bf299SEd Tanous uint64_t entryCount = 0; 1843e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1844e85d6b16SJason M. Bills bool firstEntry = true; 1845e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1846e1f26343SJason M. Bills { 1847193ad2faSJason M. Bills entryCount++; 1848193ad2faSJason M. Bills // Handle paging using skip (number of entries to skip from the 1849193ad2faSJason M. Bills // start) and top (number of entries to display) 1850193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1851193ad2faSJason M. Bills { 1852193ad2faSJason M. Bills continue; 1853193ad2faSJason M. Bills } 1854193ad2faSJason M. Bills 185516428a1aSJason M. Bills std::string idStr; 1856e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1857e1f26343SJason M. Bills { 1858e1f26343SJason M. Bills continue; 1859e1f26343SJason M. Bills } 1860e1f26343SJason M. Bills 1861e85d6b16SJason M. Bills if (firstEntry) 1862e85d6b16SJason M. Bills { 1863e85d6b16SJason M. Bills firstEntry = false; 1864e85d6b16SJason M. Bills } 1865e85d6b16SJason M. Bills 1866e1f26343SJason M. Bills logEntryArray.push_back({}); 1867c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 1868c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 1869c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 1870e1f26343SJason M. Bills { 1871f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1872e1f26343SJason M. Bills return; 1873e1f26343SJason M. Bills } 1874e1f26343SJason M. Bills } 1875193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1876193ad2faSJason M. Bills if (skip + top < entryCount) 1877193ad2faSJason M. Bills { 1878193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 1879c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 1880193ad2faSJason M. Bills std::to_string(skip + top); 1881193ad2faSJason M. Bills } 1882e1f26343SJason M. Bills } 1883e1f26343SJason M. Bills }; 1884e1f26343SJason M. Bills 1885c4bf6374SJason M. Bills class BMCJournalLogEntry : public Node 1886e1f26343SJason M. Bills { 1887e1f26343SJason M. Bills public: 188852cc112dSEd Tanous BMCJournalLogEntry(App& app) : 1889c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/", 1890e1f26343SJason M. Bills std::string()) 1891e1f26343SJason M. Bills { 1892e1f26343SJason M. Bills entityPrivileges = { 1893e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1894e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1895e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1896e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1897e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1898e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1899e1f26343SJason M. Bills } 1900e1f26343SJason M. Bills 1901e1f26343SJason M. Bills private: 1902cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1903e1f26343SJason M. Bills const std::vector<std::string>& params) override 1904e1f26343SJason M. Bills { 1905e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1906e1f26343SJason M. Bills if (params.size() != 1) 1907e1f26343SJason M. Bills { 1908f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1909e1f26343SJason M. Bills return; 1910e1f26343SJason M. Bills } 191116428a1aSJason M. Bills const std::string& entryID = params[0]; 1912e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 1913e1f26343SJason M. Bills uint64_t ts = 0; 1914271584abSEd Tanous uint64_t index = 0; 191516428a1aSJason M. Bills if (!getTimestampFromID(asyncResp->res, entryID, ts, index)) 1916e1f26343SJason M. Bills { 191716428a1aSJason M. Bills return; 1918e1f26343SJason M. Bills } 1919e1f26343SJason M. Bills 1920e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1921e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1922e1f26343SJason M. Bills if (ret < 0) 1923e1f26343SJason M. Bills { 1924e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1925f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1926e1f26343SJason M. Bills return; 1927e1f26343SJason M. Bills } 1928e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1929e1f26343SJason M. Bills journalTmp, sd_journal_close); 1930e1f26343SJason M. Bills journalTmp = nullptr; 1931e1f26343SJason M. Bills // Go to the timestamp in the log and move to the entry at the index 1932af07e3f5SJason M. Bills // tracking the unique ID 1933af07e3f5SJason M. Bills std::string idStr; 1934af07e3f5SJason M. Bills bool firstEntry = true; 1935e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 19362056b6d1SManojkiran Eda if (ret < 0) 19372056b6d1SManojkiran Eda { 19382056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 19392056b6d1SManojkiran Eda << strerror(-ret); 19402056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 19412056b6d1SManojkiran Eda return; 19422056b6d1SManojkiran Eda } 1943271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 1944e1f26343SJason M. Bills { 1945e1f26343SJason M. Bills sd_journal_next(journal.get()); 1946af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1947af07e3f5SJason M. Bills { 1948af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 1949af07e3f5SJason M. Bills return; 1950af07e3f5SJason M. Bills } 1951af07e3f5SJason M. Bills if (firstEntry) 1952af07e3f5SJason M. Bills { 1953af07e3f5SJason M. Bills firstEntry = false; 1954af07e3f5SJason M. Bills } 1955e1f26343SJason M. Bills } 1956c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 1957af07e3f5SJason M. Bills if (idStr != entryID) 1958c4bf6374SJason M. Bills { 1959c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 1960c4bf6374SJason M. Bills return; 1961c4bf6374SJason M. Bills } 1962c4bf6374SJason M. Bills 1963c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 1964e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 1965e1f26343SJason M. Bills { 1966f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1967e1f26343SJason M. Bills return; 1968e1f26343SJason M. Bills } 1969e1f26343SJason M. Bills } 1970e1f26343SJason M. Bills }; 1971e1f26343SJason M. Bills 19725cb1dd27SAsmitha Karunanithi class BMCDumpService : public Node 1973c9bb6861Sraviteja-b { 1974c9bb6861Sraviteja-b public: 197552cc112dSEd Tanous BMCDumpService(App& app) : 19765cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 1977c9bb6861Sraviteja-b { 1978c9bb6861Sraviteja-b entityPrivileges = { 1979c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 1980c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 1981c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1982c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1983c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1984c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1985c9bb6861Sraviteja-b } 1986c9bb6861Sraviteja-b 1987c9bb6861Sraviteja-b private: 1988cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1989cb13a392SEd Tanous const std::vector<std::string>&) override 1990c9bb6861Sraviteja-b { 1991c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1992c9bb6861Sraviteja-b 1993c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 19945cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 1995c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 1996d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 1997c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 19985cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 19995cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2000c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2001c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 20025cb1dd27SAsmitha Karunanithi {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}}; 20035cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 20045cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 20055cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 20065cb1dd27SAsmitha Karunanithi "Actions/LogService.ClearLog"}}}, 2007d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 2008d337bb72SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 2009d337bb72SAsmitha Karunanithi "Actions/LogService.CollectDiagnosticData"}}}}; 2010c9bb6861Sraviteja-b } 2011c9bb6861Sraviteja-b }; 2012c9bb6861Sraviteja-b 20135cb1dd27SAsmitha Karunanithi class BMCDumpEntryCollection : public Node 2014c9bb6861Sraviteja-b { 2015c9bb6861Sraviteja-b public: 201652cc112dSEd Tanous BMCDumpEntryCollection(App& app) : 20175cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2018c9bb6861Sraviteja-b { 2019c9bb6861Sraviteja-b entityPrivileges = { 2020c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2021c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2022c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2023c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2024c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2025c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2026c9bb6861Sraviteja-b } 2027c9bb6861Sraviteja-b 2028c9bb6861Sraviteja-b private: 2029c9bb6861Sraviteja-b /** 2030c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2031c9bb6861Sraviteja-b */ 2032cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2033cb13a392SEd Tanous const std::vector<std::string>&) override 2034c9bb6861Sraviteja-b { 2035c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2036c9bb6861Sraviteja-b 2037c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2038c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2039c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 20405cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 20415cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2042c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 20435cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2044c9bb6861Sraviteja-b 20455cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 2046c9bb6861Sraviteja-b } 2047c9bb6861Sraviteja-b }; 2048c9bb6861Sraviteja-b 20495cb1dd27SAsmitha Karunanithi class BMCDumpEntry : public Node 2050c9bb6861Sraviteja-b { 2051c9bb6861Sraviteja-b public: 205252cc112dSEd Tanous BMCDumpEntry(App& app) : 20535cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/", 2054c9bb6861Sraviteja-b std::string()) 2055c9bb6861Sraviteja-b { 2056c9bb6861Sraviteja-b entityPrivileges = { 2057c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2058c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2059c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2060c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2061c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2062c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2063c9bb6861Sraviteja-b } 2064c9bb6861Sraviteja-b 2065c9bb6861Sraviteja-b private: 2066cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2067c9bb6861Sraviteja-b const std::vector<std::string>& params) override 2068c9bb6861Sraviteja-b { 2069c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2070c9bb6861Sraviteja-b if (params.size() != 1) 2071c9bb6861Sraviteja-b { 2072c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2073c9bb6861Sraviteja-b return; 2074c9bb6861Sraviteja-b } 20755cb1dd27SAsmitha Karunanithi getDumpEntryById(asyncResp, params[0], "BMC"); 2076c9bb6861Sraviteja-b } 2077c9bb6861Sraviteja-b 2078cb13a392SEd Tanous void doDelete(crow::Response& res, const crow::Request&, 2079c9bb6861Sraviteja-b const std::vector<std::string>& params) override 2080c9bb6861Sraviteja-b { 20815cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2082c9bb6861Sraviteja-b if (params.size() != 1) 2083c9bb6861Sraviteja-b { 2084c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2085c9bb6861Sraviteja-b return; 2086c9bb6861Sraviteja-b } 20879878256fSStanley Chu deleteDumpEntry(asyncResp, params[0], "bmc"); 20885cb1dd27SAsmitha Karunanithi } 20895cb1dd27SAsmitha Karunanithi }; 2090c9bb6861Sraviteja-b 2091a43be80fSAsmitha Karunanithi class BMCDumpCreate : public Node 2092a43be80fSAsmitha Karunanithi { 2093a43be80fSAsmitha Karunanithi public: 209452cc112dSEd Tanous BMCDumpCreate(App& app) : 2095a43be80fSAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 2096d337bb72SAsmitha Karunanithi "Actions/" 2097d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2098a43be80fSAsmitha Karunanithi { 2099a43be80fSAsmitha Karunanithi entityPrivileges = { 2100a43be80fSAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2101a43be80fSAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2102a43be80fSAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2103a43be80fSAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2104a43be80fSAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2105a43be80fSAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2106a43be80fSAsmitha Karunanithi } 2107a43be80fSAsmitha Karunanithi 2108a43be80fSAsmitha Karunanithi private: 2109a43be80fSAsmitha Karunanithi void doPost(crow::Response& res, const crow::Request& req, 2110cb13a392SEd Tanous const std::vector<std::string>&) override 2111a43be80fSAsmitha Karunanithi { 2112a43be80fSAsmitha Karunanithi createDump(res, req, "BMC"); 2113a43be80fSAsmitha Karunanithi } 2114a43be80fSAsmitha Karunanithi }; 2115a43be80fSAsmitha Karunanithi 211680319af1SAsmitha Karunanithi class BMCDumpClear : public Node 211780319af1SAsmitha Karunanithi { 211880319af1SAsmitha Karunanithi public: 211952cc112dSEd Tanous BMCDumpClear(App& app) : 212080319af1SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 212180319af1SAsmitha Karunanithi "Actions/" 212280319af1SAsmitha Karunanithi "LogService.ClearLog/") 212380319af1SAsmitha Karunanithi { 212480319af1SAsmitha Karunanithi entityPrivileges = { 212580319af1SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 212680319af1SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 212780319af1SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 212880319af1SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 212980319af1SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 213080319af1SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 213180319af1SAsmitha Karunanithi } 213280319af1SAsmitha Karunanithi 213380319af1SAsmitha Karunanithi private: 2134cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2135cb13a392SEd Tanous const std::vector<std::string>&) override 213680319af1SAsmitha Karunanithi { 2137b47452b2SAsmitha Karunanithi clearDump(res, "BMC"); 213880319af1SAsmitha Karunanithi } 213980319af1SAsmitha Karunanithi }; 214080319af1SAsmitha Karunanithi 21415cb1dd27SAsmitha Karunanithi class SystemDumpService : public Node 2142c9bb6861Sraviteja-b { 21435cb1dd27SAsmitha Karunanithi public: 214452cc112dSEd Tanous SystemDumpService(App& app) : 21455cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/") 21465cb1dd27SAsmitha Karunanithi { 21475cb1dd27SAsmitha Karunanithi entityPrivileges = { 21485cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 21495cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 21505cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 21515cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 21525cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 21535cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 21545cb1dd27SAsmitha Karunanithi } 21555cb1dd27SAsmitha Karunanithi 21565cb1dd27SAsmitha Karunanithi private: 2157cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2158cb13a392SEd Tanous const std::vector<std::string>&) override 21595cb1dd27SAsmitha Karunanithi { 21605cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 21615cb1dd27SAsmitha Karunanithi 21625cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 21635cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 21645cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2165d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 21665cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 21675cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "System Dump LogService"; 21685cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 21695cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 21705cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Entries"] = { 21715cb1dd27SAsmitha Karunanithi {"@odata.id", 21725cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"}}; 21735cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 21745cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 21755cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 21765cb1dd27SAsmitha Karunanithi "LogService.ClearLog"}}}, 2177d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 2178d337bb72SAsmitha Karunanithi {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 2179d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData"}}}}; 21805cb1dd27SAsmitha Karunanithi } 21815cb1dd27SAsmitha Karunanithi }; 21825cb1dd27SAsmitha Karunanithi 21835cb1dd27SAsmitha Karunanithi class SystemDumpEntryCollection : public Node 21845cb1dd27SAsmitha Karunanithi { 21855cb1dd27SAsmitha Karunanithi public: 218652cc112dSEd Tanous SystemDumpEntryCollection(App& app) : 21875cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 21885cb1dd27SAsmitha Karunanithi { 21895cb1dd27SAsmitha Karunanithi entityPrivileges = { 21905cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 21915cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 21925cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 21935cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 21945cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 21955cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 21965cb1dd27SAsmitha Karunanithi } 21975cb1dd27SAsmitha Karunanithi 21985cb1dd27SAsmitha Karunanithi private: 21995cb1dd27SAsmitha Karunanithi /** 22005cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 22015cb1dd27SAsmitha Karunanithi */ 2202cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2203cb13a392SEd Tanous const std::vector<std::string>&) override 22045cb1dd27SAsmitha Karunanithi { 22055cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22065cb1dd27SAsmitha Karunanithi 22075cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 22085cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 22095cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 22105cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 22115cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 22125cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 22135cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 22145cb1dd27SAsmitha Karunanithi 22155cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 22165cb1dd27SAsmitha Karunanithi } 22175cb1dd27SAsmitha Karunanithi }; 22185cb1dd27SAsmitha Karunanithi 22195cb1dd27SAsmitha Karunanithi class SystemDumpEntry : public Node 22205cb1dd27SAsmitha Karunanithi { 22215cb1dd27SAsmitha Karunanithi public: 222252cc112dSEd Tanous SystemDumpEntry(App& app) : 22235cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/", 22245cb1dd27SAsmitha Karunanithi std::string()) 22255cb1dd27SAsmitha Karunanithi { 22265cb1dd27SAsmitha Karunanithi entityPrivileges = { 22275cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 22285cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 22295cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 22305cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 22315cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 22325cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 22335cb1dd27SAsmitha Karunanithi } 22345cb1dd27SAsmitha Karunanithi 22355cb1dd27SAsmitha Karunanithi private: 2236cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 22375cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 22385cb1dd27SAsmitha Karunanithi { 22395cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22405cb1dd27SAsmitha Karunanithi if (params.size() != 1) 22415cb1dd27SAsmitha Karunanithi { 2242c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2243c9bb6861Sraviteja-b return; 2244c9bb6861Sraviteja-b } 22455cb1dd27SAsmitha Karunanithi getDumpEntryById(asyncResp, params[0], "System"); 22465cb1dd27SAsmitha Karunanithi } 2247c9bb6861Sraviteja-b 2248cb13a392SEd Tanous void doDelete(crow::Response& res, const crow::Request&, 22495cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 2250c9bb6861Sraviteja-b { 22515cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22525cb1dd27SAsmitha Karunanithi if (params.size() != 1) 2253c9bb6861Sraviteja-b { 22545cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 2255c9bb6861Sraviteja-b return; 2256c9bb6861Sraviteja-b } 22579878256fSStanley Chu deleteDumpEntry(asyncResp, params[0], "system"); 2258c9bb6861Sraviteja-b } 2259c9bb6861Sraviteja-b }; 2260c9bb6861Sraviteja-b 2261a43be80fSAsmitha Karunanithi class SystemDumpCreate : public Node 2262a43be80fSAsmitha Karunanithi { 2263a43be80fSAsmitha Karunanithi public: 226452cc112dSEd Tanous SystemDumpCreate(App& app) : 2265a43be80fSAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2266d337bb72SAsmitha Karunanithi "Actions/" 2267d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2268a43be80fSAsmitha Karunanithi { 2269a43be80fSAsmitha Karunanithi entityPrivileges = { 2270a43be80fSAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2271a43be80fSAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2272a43be80fSAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2273a43be80fSAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2274a43be80fSAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2275a43be80fSAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2276a43be80fSAsmitha Karunanithi } 2277a43be80fSAsmitha Karunanithi 2278a43be80fSAsmitha Karunanithi private: 2279a43be80fSAsmitha Karunanithi void doPost(crow::Response& res, const crow::Request& req, 2280cb13a392SEd Tanous const std::vector<std::string>&) override 2281a43be80fSAsmitha Karunanithi { 2282a43be80fSAsmitha Karunanithi createDump(res, req, "System"); 2283a43be80fSAsmitha Karunanithi } 2284a43be80fSAsmitha Karunanithi }; 2285a43be80fSAsmitha Karunanithi 2286013487e5Sraviteja-b class SystemDumpClear : public Node 2287013487e5Sraviteja-b { 2288013487e5Sraviteja-b public: 228952cc112dSEd Tanous SystemDumpClear(App& app) : 229080319af1SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2291013487e5Sraviteja-b "Actions/" 2292013487e5Sraviteja-b "LogService.ClearLog/") 2293013487e5Sraviteja-b { 2294013487e5Sraviteja-b entityPrivileges = { 2295013487e5Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2296013487e5Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 229780319af1SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 229880319af1SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 229980319af1SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2300013487e5Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2301013487e5Sraviteja-b } 2302013487e5Sraviteja-b 2303013487e5Sraviteja-b private: 2304cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2305cb13a392SEd Tanous const std::vector<std::string>&) override 2306013487e5Sraviteja-b { 2307b47452b2SAsmitha Karunanithi clearDump(res, "System"); 2308013487e5Sraviteja-b } 2309013487e5Sraviteja-b }; 2310013487e5Sraviteja-b 2311424c4176SJason M. Bills class CrashdumpService : public Node 2312e1f26343SJason M. Bills { 2313e1f26343SJason M. Bills public: 231452cc112dSEd Tanous CrashdumpService(App& app) : 2315424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 23161da66f75SEd Tanous { 23173946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 23183946028dSAppaRao Puli // method for security reasons. 23191da66f75SEd Tanous entityPrivileges = { 23203946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 23213946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2322e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2323e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2324e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2325e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 23261da66f75SEd Tanous } 23271da66f75SEd Tanous 23281da66f75SEd Tanous private: 23291da66f75SEd Tanous /** 23301da66f75SEd Tanous * Functions triggers appropriate requests on DBus 23311da66f75SEd Tanous */ 2332cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2333cb13a392SEd Tanous const std::vector<std::string>&) override 23341da66f75SEd Tanous { 2335e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 23361da66f75SEd Tanous // Copy over the static data to include the entries added by SubRoute 23370f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2338424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2339e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2340e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 23414f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 23424f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 23434f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2344e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2345e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 2346cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2347cd50aa42SJason M. Bills {"@odata.id", 2348424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 2349e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 23505b61b5e8SJason M. Bills {"#LogService.ClearLog", 23515b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 23525b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 23531da66f75SEd Tanous {"Oem", 2354424c4176SJason M. Bills {{"#Crashdump.OnDemand", 2355424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 23566eda7685SKenny L. Ku "Actions/Oem/Crashdump.OnDemand"}}}, 23576eda7685SKenny L. Ku {"#Crashdump.Telemetry", 23586eda7685SKenny L. Ku {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 23596eda7685SKenny L. Ku "Actions/Oem/Crashdump.Telemetry"}}}}}}; 23601da66f75SEd Tanous 23611da66f75SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI 2362e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"]["Oem"].push_back( 2363424c4176SJason M. Bills {"#Crashdump.SendRawPeci", 236408a4e4b5SAnthony Wilson {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 2365424c4176SJason M. Bills "Actions/Oem/Crashdump.SendRawPeci"}}}); 23661da66f75SEd Tanous #endif 23671da66f75SEd Tanous } 23681da66f75SEd Tanous }; 23691da66f75SEd Tanous 23705b61b5e8SJason M. Bills class CrashdumpClear : public Node 23715b61b5e8SJason M. Bills { 23725b61b5e8SJason M. Bills public: 237352cc112dSEd Tanous CrashdumpClear(App& app) : 23745b61b5e8SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 23755b61b5e8SJason M. Bills "LogService.ClearLog/") 23765b61b5e8SJason M. Bills { 23773946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 23783946028dSAppaRao Puli // method for security reasons. 23795b61b5e8SJason M. Bills entityPrivileges = { 23803946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 23813946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 23825b61b5e8SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 23835b61b5e8SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 23845b61b5e8SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 23855b61b5e8SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 23865b61b5e8SJason M. Bills } 23875b61b5e8SJason M. Bills 23885b61b5e8SJason M. Bills private: 2389cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2390cb13a392SEd Tanous const std::vector<std::string>&) override 23915b61b5e8SJason M. Bills { 23925b61b5e8SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 23935b61b5e8SJason M. Bills 23945b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 23955b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2396cb13a392SEd Tanous const std::string&) { 23975b61b5e8SJason M. Bills if (ec) 23985b61b5e8SJason M. Bills { 23995b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 24005b61b5e8SJason M. Bills return; 24015b61b5e8SJason M. Bills } 24025b61b5e8SJason M. Bills messages::success(asyncResp->res); 24035b61b5e8SJason M. Bills }, 24045b61b5e8SJason M. Bills crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 24055b61b5e8SJason M. Bills } 24065b61b5e8SJason M. Bills }; 24075b61b5e8SJason M. Bills 2408b5a76932SEd Tanous static void logCrashdumpEntry(const std::shared_ptr<AsyncResp>& asyncResp, 2409e855dd28SJason M. Bills const std::string& logID, 2410e855dd28SJason M. Bills nlohmann::json& logEntryJson) 2411e855dd28SJason M. Bills { 2412043a0536SJohnathan Mantey auto getStoredLogCallback = 2413043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 2414e855dd28SJason M. Bills const boost::system::error_code ec, 2415043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params) { 2416e855dd28SJason M. Bills if (ec) 2417e855dd28SJason M. Bills { 2418e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 24191ddcf01aSJason M. Bills if (ec.value() == 24201ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 24211ddcf01aSJason M. Bills { 2422043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2423043a0536SJohnathan Mantey logID); 24241ddcf01aSJason M. Bills } 24251ddcf01aSJason M. Bills else 24261ddcf01aSJason M. Bills { 2427e855dd28SJason M. Bills messages::internalError(asyncResp->res); 24281ddcf01aSJason M. Bills } 2429e855dd28SJason M. Bills return; 2430e855dd28SJason M. Bills } 2431043a0536SJohnathan Mantey 2432043a0536SJohnathan Mantey std::string timestamp{}; 2433043a0536SJohnathan Mantey std::string filename{}; 2434043a0536SJohnathan Mantey std::string logfile{}; 24352c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2436043a0536SJohnathan Mantey 2437043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2438e855dd28SJason M. Bills { 2439043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 2440e855dd28SJason M. Bills return; 2441e855dd28SJason M. Bills } 2442e855dd28SJason M. Bills 2443043a0536SJohnathan Mantey std::string crashdumpURI = 2444e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2445043a0536SJohnathan Mantey logID + "/" + filename; 2446043a0536SJohnathan Mantey logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 2447043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 2448043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 2449e855dd28SJason M. Bills logID}, 2450e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2451e855dd28SJason M. Bills {"Id", logID}, 2452e855dd28SJason M. Bills {"EntryType", "Oem"}, 2453e855dd28SJason M. Bills {"OemRecordFormat", "Crashdump URI"}, 2454043a0536SJohnathan Mantey {"Message", std::move(crashdumpURI)}, 2455043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2456e855dd28SJason M. Bills }; 2457e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 24585b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 24595b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2460043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2461e855dd28SJason M. Bills } 2462e855dd28SJason M. Bills 2463424c4176SJason M. Bills class CrashdumpEntryCollection : public Node 24641da66f75SEd Tanous { 24651da66f75SEd Tanous public: 246652cc112dSEd Tanous CrashdumpEntryCollection(App& app) : 2467424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 24681da66f75SEd Tanous { 24693946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24703946028dSAppaRao Puli // method for security reasons. 24711da66f75SEd Tanous entityPrivileges = { 24723946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 24733946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2474e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2475e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2476e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2477e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 24781da66f75SEd Tanous } 24791da66f75SEd Tanous 24801da66f75SEd Tanous private: 24811da66f75SEd Tanous /** 24821da66f75SEd Tanous * Functions triggers appropriate requests on DBus 24831da66f75SEd Tanous */ 2484cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2485cb13a392SEd Tanous const std::vector<std::string>&) override 24861da66f75SEd Tanous { 2487e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 24881da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 24891da66f75SEd Tanous // it has a duplicate entry for members 2490e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2491e1f26343SJason M. Bills const boost::system::error_code ec, 24921da66f75SEd Tanous const std::vector<std::string>& resp) { 24931da66f75SEd Tanous if (ec) 24941da66f75SEd Tanous { 24951da66f75SEd Tanous if (ec.value() != 24961da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 24971da66f75SEd Tanous { 24981da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 24991da66f75SEd Tanous << ec.message(); 2500f12894f8SJason M. Bills messages::internalError(asyncResp->res); 25011da66f75SEd Tanous return; 25021da66f75SEd Tanous } 25031da66f75SEd Tanous } 2504e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 25051da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 25060f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2507424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2508424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2509e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2510424c4176SJason M. Bills "Collection of Crashdump Entries"; 2511e1f26343SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2512e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2513e855dd28SJason M. Bills std::vector<std::string> logIDs; 2514e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2515e855dd28SJason M. Bills // enough to hold them 25161da66f75SEd Tanous for (const std::string& objpath : resp) 25171da66f75SEd Tanous { 2518e855dd28SJason M. Bills // Get the log ID 2519f23b7296SEd Tanous std::size_t lastPos = objpath.rfind('/'); 2520e855dd28SJason M. Bills if (lastPos == std::string::npos) 25211da66f75SEd Tanous { 2522e855dd28SJason M. Bills continue; 25231da66f75SEd Tanous } 2524e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2525e855dd28SJason M. Bills 2526e855dd28SJason M. Bills // Add a space for the log entry to the array 2527e855dd28SJason M. Bills logEntryArray.push_back({}); 2528e855dd28SJason M. Bills } 2529e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2530e855dd28SJason M. Bills size_t index = 0; 2531e855dd28SJason M. Bills for (const std::string& logID : logIDs) 2532e855dd28SJason M. Bills { 2533e855dd28SJason M. Bills // Add the log entry to the array 2534e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 25351da66f75SEd Tanous } 2536e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2537e1f26343SJason M. Bills logEntryArray.size(); 25381da66f75SEd Tanous }; 25391da66f75SEd Tanous crow::connections::systemBus->async_method_call( 25401da66f75SEd Tanous std::move(getLogEntriesCallback), 25411da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 25421da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 25431da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 25445b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 25451da66f75SEd Tanous } 25461da66f75SEd Tanous }; 25471da66f75SEd Tanous 2548424c4176SJason M. Bills class CrashdumpEntry : public Node 25491da66f75SEd Tanous { 25501da66f75SEd Tanous public: 255152cc112dSEd Tanous CrashdumpEntry(App& app) : 2552d53dd41fSJason M. Bills Node(app, 2553424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/", 25541da66f75SEd Tanous std::string()) 25551da66f75SEd Tanous { 25563946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25573946028dSAppaRao Puli // method for security reasons. 25581da66f75SEd Tanous entityPrivileges = { 25593946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 25603946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2561e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2562e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2563e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2564e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 25651da66f75SEd Tanous } 25661da66f75SEd Tanous 25671da66f75SEd Tanous private: 2568cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 25691da66f75SEd Tanous const std::vector<std::string>& params) override 25701da66f75SEd Tanous { 2571e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 25721da66f75SEd Tanous if (params.size() != 1) 25731da66f75SEd Tanous { 2574f12894f8SJason M. Bills messages::internalError(asyncResp->res); 25751da66f75SEd Tanous return; 25761da66f75SEd Tanous } 2577e855dd28SJason M. Bills const std::string& logID = params[0]; 2578e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 2579e855dd28SJason M. Bills } 2580e855dd28SJason M. Bills }; 2581e855dd28SJason M. Bills 2582e855dd28SJason M. Bills class CrashdumpFile : public Node 2583e855dd28SJason M. Bills { 2584e855dd28SJason M. Bills public: 258552cc112dSEd Tanous CrashdumpFile(App& app) : 2586e855dd28SJason M. Bills Node(app, 2587e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/" 2588e855dd28SJason M. Bills "<str>/", 2589e855dd28SJason M. Bills std::string(), std::string()) 2590e855dd28SJason M. Bills { 25913946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25923946028dSAppaRao Puli // method for security reasons. 2593e855dd28SJason M. Bills entityPrivileges = { 25943946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 25953946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2596e855dd28SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2597e855dd28SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2598e855dd28SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2599e855dd28SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2600e855dd28SJason M. Bills } 2601e855dd28SJason M. Bills 2602e855dd28SJason M. Bills private: 2603cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2604e855dd28SJason M. Bills const std::vector<std::string>& params) override 2605e855dd28SJason M. Bills { 2606e855dd28SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2607e855dd28SJason M. Bills if (params.size() != 2) 2608e855dd28SJason M. Bills { 2609e855dd28SJason M. Bills messages::internalError(asyncResp->res); 2610e855dd28SJason M. Bills return; 2611e855dd28SJason M. Bills } 2612e855dd28SJason M. Bills const std::string& logID = params[0]; 2613e855dd28SJason M. Bills const std::string& fileName = params[1]; 2614e855dd28SJason M. Bills 2615043a0536SJohnathan Mantey auto getStoredLogCallback = 2616043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 2617abf2add6SEd Tanous const boost::system::error_code ec, 2618043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& resp) { 26191da66f75SEd Tanous if (ec) 26201da66f75SEd Tanous { 2621043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2622043a0536SJohnathan Mantey << ec.message(); 2623f12894f8SJason M. Bills messages::internalError(asyncResp->res); 26241da66f75SEd Tanous return; 26251da66f75SEd Tanous } 2626e855dd28SJason M. Bills 2627043a0536SJohnathan Mantey std::string dbusFilename{}; 2628043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2629043a0536SJohnathan Mantey std::string dbusFilepath{}; 2630043a0536SJohnathan Mantey 26312c70f800SEd Tanous parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 2632043a0536SJohnathan Mantey dbusFilepath); 2633043a0536SJohnathan Mantey 2634043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2635043a0536SJohnathan Mantey dbusFilepath.empty()) 26361da66f75SEd Tanous { 2637e855dd28SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, fileName); 26381da66f75SEd Tanous return; 26391da66f75SEd Tanous } 2640e855dd28SJason M. Bills 2641043a0536SJohnathan Mantey // Verify the file name parameter is correct 2642043a0536SJohnathan Mantey if (fileName != dbusFilename) 2643043a0536SJohnathan Mantey { 2644043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2645043a0536SJohnathan Mantey return; 2646043a0536SJohnathan Mantey } 2647043a0536SJohnathan Mantey 2648043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2649043a0536SJohnathan Mantey { 2650043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2651043a0536SJohnathan Mantey return; 2652043a0536SJohnathan Mantey } 2653043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 2654043a0536SJohnathan Mantey std::ios::binary | 2655043a0536SJohnathan Mantey std::ios::ate); 2656043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 2657043a0536SJohnathan Mantey if (fileSize < 0) 2658043a0536SJohnathan Mantey { 2659043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 2660043a0536SJohnathan Mantey return; 2661043a0536SJohnathan Mantey } 2662043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 2663043a0536SJohnathan Mantey 2664043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 2665043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 2666043a0536SJohnathan Mantey 2667043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 2668043a0536SJohnathan Mantey 2669043a0536SJohnathan Mantey // The cast to std::string is intentional in order to use the 2670043a0536SJohnathan Mantey // assign() that applies move mechanics 2671043a0536SJohnathan Mantey asyncResp->res.body().assign( 2672043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 2673043a0536SJohnathan Mantey 2674043a0536SJohnathan Mantey // Configure this to be a file download when accessed from 2675043a0536SJohnathan Mantey // a browser 2676e855dd28SJason M. Bills asyncResp->res.addHeader("Content-Disposition", "attachment"); 26771da66f75SEd Tanous }; 26781da66f75SEd Tanous crow::connections::systemBus->async_method_call( 26795b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 26805b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2681043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 26821da66f75SEd Tanous } 26831da66f75SEd Tanous }; 26841da66f75SEd Tanous 2685424c4176SJason M. Bills class OnDemandCrashdump : public Node 26861da66f75SEd Tanous { 26871da66f75SEd Tanous public: 268852cc112dSEd Tanous OnDemandCrashdump(App& app) : 2689424c4176SJason M. Bills Node(app, 2690424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2691424c4176SJason M. Bills "Crashdump.OnDemand/") 26921da66f75SEd Tanous { 26933946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 26943946028dSAppaRao Puli // method for security reasons. 26951da66f75SEd Tanous entityPrivileges = { 26963946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 26973946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 26983946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 26993946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 27003946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 27013946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 27021da66f75SEd Tanous } 27031da66f75SEd Tanous 27041da66f75SEd Tanous private: 27051da66f75SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 2706cb13a392SEd Tanous const std::vector<std::string>&) override 27071da66f75SEd Tanous { 2708e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 27091da66f75SEd Tanous 2710fe306728SJames Feist auto generateonDemandLogCallback = [asyncResp, 2711fe306728SJames Feist req](const boost::system::error_code 271246229577SJames Feist ec, 2713cb13a392SEd Tanous const std::string&) { 27141da66f75SEd Tanous if (ec) 27151da66f75SEd Tanous { 271646229577SJames Feist if (ec.value() == boost::system::errc::operation_not_supported) 27171da66f75SEd Tanous { 2718f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 27191da66f75SEd Tanous } 27204363d3b2SJason M. Bills else if (ec.value() == 27214363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 27224363d3b2SJason M. Bills { 27234363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 27244363d3b2SJason M. Bills "60"); 27254363d3b2SJason M. Bills } 27261da66f75SEd Tanous else 27271da66f75SEd Tanous { 2728f12894f8SJason M. Bills messages::internalError(asyncResp->res); 27291da66f75SEd Tanous } 27301da66f75SEd Tanous return; 27311da66f75SEd Tanous } 273246229577SJames Feist std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 273366afe4faSJames Feist [](boost::system::error_code err, sdbusplus::message::message&, 273466afe4faSJames Feist const std::shared_ptr<task::TaskData>& taskData) { 273566afe4faSJames Feist if (!err) 273666afe4faSJames Feist { 2737e5d5006bSJames Feist taskData->messages.emplace_back( 2738e5d5006bSJames Feist messages::taskCompletedOK( 2739e5d5006bSJames Feist std::to_string(taskData->index))); 2740831d6b09SJames Feist taskData->state = "Completed"; 274166afe4faSJames Feist } 274232898ceaSJames Feist return task::completed; 274366afe4faSJames Feist }, 274446229577SJames Feist "type='signal',interface='org.freedesktop.DBus.Properties'," 274546229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 274646229577SJames Feist "crashdump'"); 274746229577SJames Feist task->startTimer(std::chrono::minutes(5)); 274846229577SJames Feist task->populateResp(asyncResp->res); 2749fe306728SJames Feist task->payload.emplace(req); 27501da66f75SEd Tanous }; 27511da66f75SEd Tanous crow::connections::systemBus->async_method_call( 27525b61b5e8SJason M. Bills std::move(generateonDemandLogCallback), crashdumpObject, 27535b61b5e8SJason M. Bills crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog"); 27541da66f75SEd Tanous } 27551da66f75SEd Tanous }; 27561da66f75SEd Tanous 27576eda7685SKenny L. Ku class TelemetryCrashdump : public Node 27586eda7685SKenny L. Ku { 27596eda7685SKenny L. Ku public: 276052cc112dSEd Tanous TelemetryCrashdump(App& app) : 27616eda7685SKenny L. Ku Node(app, 27626eda7685SKenny L. Ku "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 27636eda7685SKenny L. Ku "Crashdump.Telemetry/") 27646eda7685SKenny L. Ku { 27656eda7685SKenny L. Ku // Note: Deviated from redfish privilege registry for GET & HEAD 27666eda7685SKenny L. Ku // method for security reasons. 27676eda7685SKenny L. Ku entityPrivileges = { 27686eda7685SKenny L. Ku {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 27696eda7685SKenny L. Ku {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 27706eda7685SKenny L. Ku {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 27716eda7685SKenny L. Ku {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 27726eda7685SKenny L. Ku {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 27736eda7685SKenny L. Ku {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 27746eda7685SKenny L. Ku } 27756eda7685SKenny L. Ku 27766eda7685SKenny L. Ku private: 27776eda7685SKenny L. Ku void doPost(crow::Response& res, const crow::Request& req, 2778cb13a392SEd Tanous const std::vector<std::string>&) override 27796eda7685SKenny L. Ku { 27806eda7685SKenny L. Ku std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 27816eda7685SKenny L. Ku 27826eda7685SKenny L. Ku auto generateTelemetryLogCallback = [asyncResp, req]( 27836eda7685SKenny L. Ku const boost::system::error_code 27846eda7685SKenny L. Ku ec, 2785cb13a392SEd Tanous const std::string&) { 27866eda7685SKenny L. Ku if (ec) 27876eda7685SKenny L. Ku { 27886eda7685SKenny L. Ku if (ec.value() == boost::system::errc::operation_not_supported) 27896eda7685SKenny L. Ku { 27906eda7685SKenny L. Ku messages::resourceInStandby(asyncResp->res); 27916eda7685SKenny L. Ku } 27926eda7685SKenny L. Ku else if (ec.value() == 27936eda7685SKenny L. Ku boost::system::errc::device_or_resource_busy) 27946eda7685SKenny L. Ku { 27956eda7685SKenny L. Ku messages::serviceTemporarilyUnavailable(asyncResp->res, 27966eda7685SKenny L. Ku "60"); 27976eda7685SKenny L. Ku } 27986eda7685SKenny L. Ku else 27996eda7685SKenny L. Ku { 28006eda7685SKenny L. Ku messages::internalError(asyncResp->res); 28016eda7685SKenny L. Ku } 28026eda7685SKenny L. Ku return; 28036eda7685SKenny L. Ku } 28046eda7685SKenny L. Ku std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 28056eda7685SKenny L. Ku [](boost::system::error_code err, sdbusplus::message::message&, 28066eda7685SKenny L. Ku const std::shared_ptr<task::TaskData>& taskData) { 28076eda7685SKenny L. Ku if (!err) 28086eda7685SKenny L. Ku { 28096eda7685SKenny L. Ku taskData->messages.emplace_back( 28106eda7685SKenny L. Ku messages::taskCompletedOK( 28116eda7685SKenny L. Ku std::to_string(taskData->index))); 28126eda7685SKenny L. Ku taskData->state = "Completed"; 28136eda7685SKenny L. Ku } 28146eda7685SKenny L. Ku return task::completed; 28156eda7685SKenny L. Ku }, 28166eda7685SKenny L. Ku "type='signal',interface='org.freedesktop.DBus.Properties'," 28176eda7685SKenny L. Ku "member='PropertiesChanged',arg0namespace='com.intel." 28186eda7685SKenny L. Ku "crashdump'"); 28196eda7685SKenny L. Ku task->startTimer(std::chrono::minutes(5)); 28206eda7685SKenny L. Ku task->populateResp(asyncResp->res); 28216eda7685SKenny L. Ku task->payload.emplace(req); 28226eda7685SKenny L. Ku }; 28236eda7685SKenny L. Ku crow::connections::systemBus->async_method_call( 28246eda7685SKenny L. Ku std::move(generateTelemetryLogCallback), crashdumpObject, 28256eda7685SKenny L. Ku crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog"); 28266eda7685SKenny L. Ku } 28276eda7685SKenny L. Ku }; 28286eda7685SKenny L. Ku 2829e1f26343SJason M. Bills class SendRawPECI : public Node 28301da66f75SEd Tanous { 28311da66f75SEd Tanous public: 283252cc112dSEd Tanous SendRawPECI(App& app) : 2833424c4176SJason M. Bills Node(app, 2834424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2835424c4176SJason M. Bills "Crashdump.SendRawPeci/") 28361da66f75SEd Tanous { 28373946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28383946028dSAppaRao Puli // method for security reasons. 28391da66f75SEd Tanous entityPrivileges = { 28401da66f75SEd Tanous {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 28411da66f75SEd Tanous {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 28421da66f75SEd Tanous {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 28431da66f75SEd Tanous {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 28441da66f75SEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 28451da66f75SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 28461da66f75SEd Tanous } 28471da66f75SEd Tanous 28481da66f75SEd Tanous private: 28491da66f75SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 2850cb13a392SEd Tanous const std::vector<std::string>&) override 28511da66f75SEd Tanous { 2852e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 28538724c297SKarthick Sundarrajan std::vector<std::vector<uint8_t>> peciCommands; 28548724c297SKarthick Sundarrajan 28558724c297SKarthick Sundarrajan if (!json_util::readJson(req, res, "PECICommands", peciCommands)) 28568724c297SKarthick Sundarrajan { 28578724c297SKarthick Sundarrajan return; 28588724c297SKarthick Sundarrajan } 28598724c297SKarthick Sundarrajan uint32_t idx = 0; 28608724c297SKarthick Sundarrajan for (auto const& cmd : peciCommands) 28618724c297SKarthick Sundarrajan { 28628724c297SKarthick Sundarrajan if (cmd.size() < 3) 28638724c297SKarthick Sundarrajan { 28648724c297SKarthick Sundarrajan std::string s("["); 28658724c297SKarthick Sundarrajan for (auto const& val : cmd) 28668724c297SKarthick Sundarrajan { 28678724c297SKarthick Sundarrajan if (val != *cmd.begin()) 28688724c297SKarthick Sundarrajan { 28698724c297SKarthick Sundarrajan s += ","; 28708724c297SKarthick Sundarrajan } 28718724c297SKarthick Sundarrajan s += std::to_string(val); 28728724c297SKarthick Sundarrajan } 28738724c297SKarthick Sundarrajan s += "]"; 28748724c297SKarthick Sundarrajan messages::actionParameterValueFormatError( 28758724c297SKarthick Sundarrajan res, s, "PECICommands[" + std::to_string(idx) + "]", 28768724c297SKarthick Sundarrajan "SendRawPeci"); 28778724c297SKarthick Sundarrajan return; 28788724c297SKarthick Sundarrajan } 28798724c297SKarthick Sundarrajan idx++; 28808724c297SKarthick Sundarrajan } 28811da66f75SEd Tanous // Callback to return the Raw PECI response 2882e1f26343SJason M. Bills auto sendRawPECICallback = 2883e1f26343SJason M. Bills [asyncResp](const boost::system::error_code ec, 28848724c297SKarthick Sundarrajan const std::vector<std::vector<uint8_t>>& resp) { 28851da66f75SEd Tanous if (ec) 28861da66f75SEd Tanous { 28878724c297SKarthick Sundarrajan BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: " 28881da66f75SEd Tanous << ec.message(); 2889f12894f8SJason M. Bills messages::internalError(asyncResp->res); 28901da66f75SEd Tanous return; 28911da66f75SEd Tanous } 2892e1f26343SJason M. Bills asyncResp->res.jsonValue = {{"Name", "PECI Command Response"}, 28931da66f75SEd Tanous {"PECIResponse", resp}}; 28941da66f75SEd Tanous }; 28951da66f75SEd Tanous // Call the SendRawPECI command with the provided data 28961da66f75SEd Tanous crow::connections::systemBus->async_method_call( 28975b61b5e8SJason M. Bills std::move(sendRawPECICallback), crashdumpObject, crashdumpPath, 28988724c297SKarthick Sundarrajan crashdumpRawPECIInterface, "SendRawPeci", peciCommands); 28991da66f75SEd Tanous } 29001da66f75SEd Tanous }; 29011da66f75SEd Tanous 2902cb92c03bSAndrew Geissler /** 2903cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2904cb92c03bSAndrew Geissler */ 2905cb92c03bSAndrew Geissler class DBusLogServiceActionsClear : public Node 2906cb92c03bSAndrew Geissler { 2907cb92c03bSAndrew Geissler public: 290852cc112dSEd Tanous DBusLogServiceActionsClear(App& app) : 2909cb92c03bSAndrew Geissler Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 29107af91514SGunnar Mills "LogService.ClearLog/") 2911cb92c03bSAndrew Geissler { 2912cb92c03bSAndrew Geissler entityPrivileges = { 2913cb92c03bSAndrew Geissler {boost::beast::http::verb::get, {{"Login"}}}, 2914cb92c03bSAndrew Geissler {boost::beast::http::verb::head, {{"Login"}}}, 2915cb92c03bSAndrew Geissler {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2916cb92c03bSAndrew Geissler {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2917cb92c03bSAndrew Geissler {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2918cb92c03bSAndrew Geissler {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2919cb92c03bSAndrew Geissler } 2920cb92c03bSAndrew Geissler 2921cb92c03bSAndrew Geissler private: 2922cb92c03bSAndrew Geissler /** 2923cb92c03bSAndrew Geissler * Function handles POST method request. 2924cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 2925cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 2926cb92c03bSAndrew Geissler */ 2927cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 2928cb13a392SEd Tanous const std::vector<std::string>&) override 2929cb92c03bSAndrew Geissler { 2930cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 2931cb92c03bSAndrew Geissler 2932cb92c03bSAndrew Geissler auto asyncResp = std::make_shared<AsyncResp>(res); 2933cb92c03bSAndrew Geissler // Process response from Logging service. 29342c70f800SEd Tanous auto respHandler = [asyncResp](const boost::system::error_code ec) { 2935cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 2936cb92c03bSAndrew Geissler if (ec) 2937cb92c03bSAndrew Geissler { 2938cb92c03bSAndrew Geissler // TODO Handle for specific error code 2939cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 2940cb92c03bSAndrew Geissler asyncResp->res.result( 2941cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 2942cb92c03bSAndrew Geissler return; 2943cb92c03bSAndrew Geissler } 2944cb92c03bSAndrew Geissler 2945cb92c03bSAndrew Geissler asyncResp->res.result(boost::beast::http::status::no_content); 2946cb92c03bSAndrew Geissler }; 2947cb92c03bSAndrew Geissler 2948cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 2949cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 29502c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 2951cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 2952cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 2953cb92c03bSAndrew Geissler } 2954cb92c03bSAndrew Geissler }; 2955a3316fc6SZhikuiRen 2956a3316fc6SZhikuiRen /**************************************************** 2957a3316fc6SZhikuiRen * Redfish PostCode interfaces 2958a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 2959a3316fc6SZhikuiRen ******************************************************/ 2960a3316fc6SZhikuiRen class PostCodesLogService : public Node 2961a3316fc6SZhikuiRen { 2962a3316fc6SZhikuiRen public: 296352cc112dSEd Tanous PostCodesLogService(App& app) : 2964a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 2965a3316fc6SZhikuiRen { 2966a3316fc6SZhikuiRen entityPrivileges = { 2967a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2968a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 2969a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2970a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2971a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2972a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2973a3316fc6SZhikuiRen } 2974a3316fc6SZhikuiRen 2975a3316fc6SZhikuiRen private: 2976cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2977cb13a392SEd Tanous const std::vector<std::string>&) override 2978a3316fc6SZhikuiRen { 2979a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2980a3316fc6SZhikuiRen 2981a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 2982a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"}, 2983a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 2984a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 2985a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 2986a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 2987a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 2988a3316fc6SZhikuiRen {"Entries", 2989a3316fc6SZhikuiRen {{"@odata.id", 2990a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}}; 2991a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 2992a3316fc6SZhikuiRen {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/" 2993a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 2994a3316fc6SZhikuiRen } 2995a3316fc6SZhikuiRen }; 2996a3316fc6SZhikuiRen 2997a3316fc6SZhikuiRen class PostCodesClear : public Node 2998a3316fc6SZhikuiRen { 2999a3316fc6SZhikuiRen public: 300052cc112dSEd Tanous PostCodesClear(App& app) : 3001a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 3002a3316fc6SZhikuiRen "LogService.ClearLog/") 3003a3316fc6SZhikuiRen { 3004a3316fc6SZhikuiRen entityPrivileges = { 3005a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3006a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 30073946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 30083946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 30093946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 30103946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 3011a3316fc6SZhikuiRen } 3012a3316fc6SZhikuiRen 3013a3316fc6SZhikuiRen private: 3014cb13a392SEd Tanous void doPost(crow::Response& res, const crow::Request&, 3015cb13a392SEd Tanous const std::vector<std::string>&) override 3016a3316fc6SZhikuiRen { 3017a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3018a3316fc6SZhikuiRen 3019a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3020a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3021a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3022a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3023a3316fc6SZhikuiRen if (ec) 3024a3316fc6SZhikuiRen { 3025a3316fc6SZhikuiRen // TODO Handle for specific error code 3026a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 3027a3316fc6SZhikuiRen << "doClearPostCodes resp_handler got error " << ec; 3028a3316fc6SZhikuiRen asyncResp->res.result( 3029a3316fc6SZhikuiRen boost::beast::http::status::internal_server_error); 3030a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3031a3316fc6SZhikuiRen return; 3032a3316fc6SZhikuiRen } 3033a3316fc6SZhikuiRen }, 3034a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3035a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3036a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 3037a3316fc6SZhikuiRen } 3038a3316fc6SZhikuiRen }; 3039a3316fc6SZhikuiRen 3040a3316fc6SZhikuiRen static void fillPostCodeEntry( 3041b5a76932SEd Tanous const std::shared_ptr<AsyncResp>& aResp, 3042a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode, 3043a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3044a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3045a3316fc6SZhikuiRen { 3046a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3047a3316fc6SZhikuiRen const message_registries::Message* message = 3048a3316fc6SZhikuiRen message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode"); 3049a3316fc6SZhikuiRen 3050a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3051a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 3052a3316fc6SZhikuiRen 3053a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 3054a3316fc6SZhikuiRen for (const std::pair<uint64_t, uint64_t>& code : postcode) 3055a3316fc6SZhikuiRen { 3056a3316fc6SZhikuiRen currentCodeIndex++; 3057a3316fc6SZhikuiRen std::string postcodeEntryID = 3058a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3059a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3060a3316fc6SZhikuiRen 3061a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3062a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3063a3316fc6SZhikuiRen 3064a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3065a3316fc6SZhikuiRen { // already incremented 3066a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3067a3316fc6SZhikuiRen } 3068a3316fc6SZhikuiRen else 3069a3316fc6SZhikuiRen { 3070a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3071a3316fc6SZhikuiRen } 3072a3316fc6SZhikuiRen 3073a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3074a3316fc6SZhikuiRen // not fall between top and skip 3075a3316fc6SZhikuiRen if ((codeIndex == 0) && 3076a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3077a3316fc6SZhikuiRen { 3078a3316fc6SZhikuiRen continue; 3079a3316fc6SZhikuiRen } 3080a3316fc6SZhikuiRen 30814e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3082a3316fc6SZhikuiRen // currentIndex 3083a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3084a3316fc6SZhikuiRen { 3085a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3086a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3087a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3088a3316fc6SZhikuiRen continue; 3089a3316fc6SZhikuiRen } 3090a3316fc6SZhikuiRen 3091a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3092a3316fc6SZhikuiRen // index 3093a3316fc6SZhikuiRen 3094a3316fc6SZhikuiRen // Get the Created time from the timestamp 3095a3316fc6SZhikuiRen std::string entryTimeStr; 30969c620e21SAsmitha Karunanithi entryTimeStr = crow::utility::getDateTime( 30979c620e21SAsmitha Karunanithi static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000)); 3098a3316fc6SZhikuiRen 3099a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3100a3316fc6SZhikuiRen std::ostringstream hexCode; 3101a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 3102a3316fc6SZhikuiRen << code.second; 3103a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3104a3316fc6SZhikuiRen // Set Fixed -Point Notation 3105a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3106a3316fc6SZhikuiRen // Set precision to 4 digits 3107a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3108a3316fc6SZhikuiRen // Add double to stream 3109a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3110a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3111a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3112a3316fc6SZhikuiRen 3113a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3114a3316fc6SZhikuiRen std::string msg; 3115a3316fc6SZhikuiRen if (message != nullptr) 3116a3316fc6SZhikuiRen { 3117a3316fc6SZhikuiRen msg = message->message; 3118a3316fc6SZhikuiRen 3119a3316fc6SZhikuiRen // fill in this post code value 3120a3316fc6SZhikuiRen int i = 0; 3121a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3122a3316fc6SZhikuiRen { 3123a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3124a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3125a3316fc6SZhikuiRen if (argPos != std::string::npos) 3126a3316fc6SZhikuiRen { 3127a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3128a3316fc6SZhikuiRen } 3129a3316fc6SZhikuiRen } 3130a3316fc6SZhikuiRen } 3131a3316fc6SZhikuiRen 3132d4342a92STim Lee // Get Severity template from message registry 3133d4342a92STim Lee std::string severity; 3134d4342a92STim Lee if (message != nullptr) 3135d4342a92STim Lee { 3136d4342a92STim Lee severity = message->severity; 3137d4342a92STim Lee } 3138d4342a92STim Lee 3139a3316fc6SZhikuiRen // add to AsyncResp 3140a3316fc6SZhikuiRen logEntryArray.push_back({}); 3141a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 3142743e9a1fSGunnar Mills bmcLogEntry = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 3143a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 3144a3316fc6SZhikuiRen "PostCodes/Entries/" + 3145a3316fc6SZhikuiRen postcodeEntryID}, 3146a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 3147a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 3148a3316fc6SZhikuiRen {"Message", std::move(msg)}, 3149a3316fc6SZhikuiRen {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"}, 3150a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 3151a3316fc6SZhikuiRen {"EntryType", "Event"}, 3152a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 31539c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 3154a3316fc6SZhikuiRen } 3155a3316fc6SZhikuiRen } 3156a3316fc6SZhikuiRen 3157b5a76932SEd Tanous static void getPostCodeForEntry(const std::shared_ptr<AsyncResp>& aResp, 3158a3316fc6SZhikuiRen const uint16_t bootIndex, 3159a3316fc6SZhikuiRen const uint64_t codeIndex) 3160a3316fc6SZhikuiRen { 3161a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3162a3316fc6SZhikuiRen [aResp, bootIndex, codeIndex]( 3163a3316fc6SZhikuiRen const boost::system::error_code ec, 3164a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode) { 3165a3316fc6SZhikuiRen if (ec) 3166a3316fc6SZhikuiRen { 3167a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3168a3316fc6SZhikuiRen messages::internalError(aResp->res); 3169a3316fc6SZhikuiRen return; 3170a3316fc6SZhikuiRen } 3171a3316fc6SZhikuiRen 3172a3316fc6SZhikuiRen // skip the empty postcode boots 3173a3316fc6SZhikuiRen if (postcode.empty()) 3174a3316fc6SZhikuiRen { 3175a3316fc6SZhikuiRen return; 3176a3316fc6SZhikuiRen } 3177a3316fc6SZhikuiRen 3178a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3179a3316fc6SZhikuiRen 3180a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3181a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3182a3316fc6SZhikuiRen }, 3183a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3184a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3185a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3186a3316fc6SZhikuiRen bootIndex); 3187a3316fc6SZhikuiRen } 3188a3316fc6SZhikuiRen 3189b5a76932SEd Tanous static void getPostCodeForBoot(const std::shared_ptr<AsyncResp>& aResp, 3190a3316fc6SZhikuiRen const uint16_t bootIndex, 3191a3316fc6SZhikuiRen const uint16_t bootCount, 3192a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 3193a3316fc6SZhikuiRen const uint64_t top) 3194a3316fc6SZhikuiRen { 3195a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3196a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3197a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3198a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode) { 3199a3316fc6SZhikuiRen if (ec) 3200a3316fc6SZhikuiRen { 3201a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3202a3316fc6SZhikuiRen messages::internalError(aResp->res); 3203a3316fc6SZhikuiRen return; 3204a3316fc6SZhikuiRen } 3205a3316fc6SZhikuiRen 3206a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3207a3316fc6SZhikuiRen if (!postcode.empty()) 3208a3316fc6SZhikuiRen { 3209a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 3210a3316fc6SZhikuiRen 3211a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3212a3316fc6SZhikuiRen { 3213a3316fc6SZhikuiRen uint64_t thisBootSkip = 3214a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3215a3316fc6SZhikuiRen uint64_t thisBootTop = 3216a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3217a3316fc6SZhikuiRen 3218a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3219a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3220a3316fc6SZhikuiRen } 3221a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3222a3316fc6SZhikuiRen } 3223a3316fc6SZhikuiRen 3224a3316fc6SZhikuiRen // continue to previous bootIndex 3225a3316fc6SZhikuiRen if (bootIndex < bootCount) 3226a3316fc6SZhikuiRen { 3227a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3228a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3229a3316fc6SZhikuiRen } 3230a3316fc6SZhikuiRen else 3231a3316fc6SZhikuiRen { 3232a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 3233a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3234a3316fc6SZhikuiRen "Entries?$skip=" + 3235a3316fc6SZhikuiRen std::to_string(skip + top); 3236a3316fc6SZhikuiRen } 3237a3316fc6SZhikuiRen }, 3238a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3239a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3240a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3241a3316fc6SZhikuiRen bootIndex); 3242a3316fc6SZhikuiRen } 3243a3316fc6SZhikuiRen 3244b5a76932SEd Tanous static void getCurrentBootNumber(const std::shared_ptr<AsyncResp>& aResp, 3245a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3246a3316fc6SZhikuiRen { 3247a3316fc6SZhikuiRen uint64_t entryCount = 0; 3248a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3249a3316fc6SZhikuiRen [aResp, entryCount, skip, 3250a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3251a3316fc6SZhikuiRen const std::variant<uint16_t>& bootCount) { 3252a3316fc6SZhikuiRen if (ec) 3253a3316fc6SZhikuiRen { 3254a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3255a3316fc6SZhikuiRen messages::internalError(aResp->res); 3256a3316fc6SZhikuiRen return; 3257a3316fc6SZhikuiRen } 3258a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 3259a3316fc6SZhikuiRen if (pVal) 3260a3316fc6SZhikuiRen { 3261a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 3262a3316fc6SZhikuiRen } 3263a3316fc6SZhikuiRen else 3264a3316fc6SZhikuiRen { 3265a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 3266a3316fc6SZhikuiRen } 3267a3316fc6SZhikuiRen }, 3268a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3269a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3270a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 3271a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 3272a3316fc6SZhikuiRen } 3273a3316fc6SZhikuiRen 3274a3316fc6SZhikuiRen class PostCodesEntryCollection : public Node 3275a3316fc6SZhikuiRen { 3276a3316fc6SZhikuiRen public: 327752cc112dSEd Tanous PostCodesEntryCollection(App& app) : 3278a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3279a3316fc6SZhikuiRen { 3280a3316fc6SZhikuiRen entityPrivileges = { 3281a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3282a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3283a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3284a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3285a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3286a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3287a3316fc6SZhikuiRen } 3288a3316fc6SZhikuiRen 3289a3316fc6SZhikuiRen private: 3290a3316fc6SZhikuiRen void doGet(crow::Response& res, const crow::Request& req, 3291cb13a392SEd Tanous const std::vector<std::string>&) override 3292a3316fc6SZhikuiRen { 3293a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3294a3316fc6SZhikuiRen 3295a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3296a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3297a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3298a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3299a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3300a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3301a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3302a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3303a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3304a3316fc6SZhikuiRen 3305a3316fc6SZhikuiRen uint64_t skip = 0; 3306a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 3307a3316fc6SZhikuiRen if (!getSkipParam(asyncResp->res, req, skip)) 3308a3316fc6SZhikuiRen { 3309a3316fc6SZhikuiRen return; 3310a3316fc6SZhikuiRen } 3311a3316fc6SZhikuiRen if (!getTopParam(asyncResp->res, req, top)) 3312a3316fc6SZhikuiRen { 3313a3316fc6SZhikuiRen return; 3314a3316fc6SZhikuiRen } 3315a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 3316a3316fc6SZhikuiRen } 3317a3316fc6SZhikuiRen }; 3318a3316fc6SZhikuiRen 3319a3316fc6SZhikuiRen class PostCodesEntry : public Node 3320a3316fc6SZhikuiRen { 3321a3316fc6SZhikuiRen public: 332252cc112dSEd Tanous PostCodesEntry(App& app) : 3323a3316fc6SZhikuiRen Node(app, 3324a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/", 3325a3316fc6SZhikuiRen std::string()) 3326a3316fc6SZhikuiRen { 3327a3316fc6SZhikuiRen entityPrivileges = { 3328a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3329a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3330a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3331a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3332a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3333a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3334a3316fc6SZhikuiRen } 3335a3316fc6SZhikuiRen 3336a3316fc6SZhikuiRen private: 3337cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 3338a3316fc6SZhikuiRen const std::vector<std::string>& params) override 3339a3316fc6SZhikuiRen { 3340a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3341a3316fc6SZhikuiRen if (params.size() != 1) 3342a3316fc6SZhikuiRen { 3343a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3344a3316fc6SZhikuiRen return; 3345a3316fc6SZhikuiRen } 3346a3316fc6SZhikuiRen 3347a3316fc6SZhikuiRen const std::string& targetID = params[0]; 3348a3316fc6SZhikuiRen 3349a3316fc6SZhikuiRen size_t bootPos = targetID.find('B'); 3350a3316fc6SZhikuiRen if (bootPos == std::string::npos) 3351a3316fc6SZhikuiRen { 3352a3316fc6SZhikuiRen // Requested ID was not found 3353a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 3354a3316fc6SZhikuiRen return; 3355a3316fc6SZhikuiRen } 3356a3316fc6SZhikuiRen std::string_view bootIndexStr(targetID); 3357a3316fc6SZhikuiRen bootIndexStr.remove_prefix(bootPos + 1); 3358a3316fc6SZhikuiRen uint16_t bootIndex = 0; 3359a3316fc6SZhikuiRen uint64_t codeIndex = 0; 3360a3316fc6SZhikuiRen size_t dashPos = bootIndexStr.find('-'); 3361a3316fc6SZhikuiRen 3362a3316fc6SZhikuiRen if (dashPos == std::string::npos) 3363a3316fc6SZhikuiRen { 3364a3316fc6SZhikuiRen return; 3365a3316fc6SZhikuiRen } 3366a3316fc6SZhikuiRen std::string_view codeIndexStr(bootIndexStr); 3367a3316fc6SZhikuiRen bootIndexStr.remove_suffix(dashPos); 3368a3316fc6SZhikuiRen codeIndexStr.remove_prefix(dashPos + 1); 3369a3316fc6SZhikuiRen 3370a3316fc6SZhikuiRen bootIndex = static_cast<uint16_t>( 337123a21a1cSEd Tanous strtoul(std::string(bootIndexStr).c_str(), nullptr, 0)); 337223a21a1cSEd Tanous codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0); 3373a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3374a3316fc6SZhikuiRen { 3375a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 3376a3316fc6SZhikuiRen << params[0]; 3377a3316fc6SZhikuiRen } 3378a3316fc6SZhikuiRen 3379a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 3380a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3381a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3382a3316fc6SZhikuiRen "Entries"; 3383a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3384a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3385a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3386a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3387a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3388a3316fc6SZhikuiRen 3389a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 3390a3316fc6SZhikuiRen } 3391a3316fc6SZhikuiRen }; 3392a3316fc6SZhikuiRen 33931da66f75SEd Tanous } // namespace redfish 3394