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 18*af61db10SGeorge Liu #include "http_utility.hpp" 194851d45dSJason M. Bills #include "registries.hpp" 204851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 214851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2246229577SJames Feist #include "task.hpp" 231da66f75SEd Tanous 24e1f26343SJason M. Bills #include <systemd/sd-journal.h> 25400fd1fbSAdriana Kobylak #include <unistd.h> 26e1f26343SJason M. Bills 277e860f15SJohn Edward Broadbent #include <app.hpp> 28400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 294851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 304851d45dSJason M. Bills #include <boost/beast/core/span.hpp> 31400fd1fbSAdriana Kobylak #include <boost/beast/http.hpp> 321da66f75SEd Tanous #include <boost/container/flat_map.hpp> 331ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 34cb92c03bSAndrew Geissler #include <error_messages.hpp> 351214b7e7SGunnar Mills 36*af61db10SGeorge Liu #include <charconv> 374418c7f0SJames Feist #include <filesystem> 3875710de2SXiaochao Ma #include <optional> 39cd225da8SJason M. Bills #include <string_view> 40abf2add6SEd Tanous #include <variant> 411da66f75SEd Tanous 421da66f75SEd Tanous namespace redfish 431da66f75SEd Tanous { 441da66f75SEd Tanous 455b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 465b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 475b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 485b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 495b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 505b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 51424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 526eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 536eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 541da66f75SEd Tanous 554851d45dSJason M. Bills namespace message_registries 564851d45dSJason M. Bills { 574851d45dSJason M. Bills static const Message* getMessageFromRegistry( 584851d45dSJason M. Bills const std::string& messageKey, 594851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 604851d45dSJason M. Bills { 614851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 624851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 634851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 644851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 654851d45dSJason M. Bills messageKey.c_str()); 664851d45dSJason M. Bills }); 674851d45dSJason M. Bills if (messageIt != registry.cend()) 684851d45dSJason M. Bills { 694851d45dSJason M. Bills return &messageIt->second; 704851d45dSJason M. Bills } 714851d45dSJason M. Bills 724851d45dSJason M. Bills return nullptr; 734851d45dSJason M. Bills } 744851d45dSJason M. Bills 754851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 764851d45dSJason M. Bills { 774851d45dSJason M. Bills // Redfish MessageIds are in the form 784851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 794851d45dSJason M. Bills // the right Message 804851d45dSJason M. Bills std::vector<std::string> fields; 814851d45dSJason M. Bills fields.reserve(4); 824851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 834851d45dSJason M. Bills std::string& registryName = fields[0]; 844851d45dSJason M. Bills std::string& messageKey = fields[3]; 854851d45dSJason M. Bills 864851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 874851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 884851d45dSJason M. Bills { 894851d45dSJason M. Bills return getMessageFromRegistry( 904851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 914851d45dSJason M. Bills } 924851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 934851d45dSJason M. Bills { 944851d45dSJason M. Bills return getMessageFromRegistry( 954851d45dSJason M. Bills messageKey, 964851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 974851d45dSJason M. Bills } 984851d45dSJason M. Bills return nullptr; 994851d45dSJason M. Bills } 1004851d45dSJason M. Bills } // namespace message_registries 1014851d45dSJason M. Bills 102f6150403SJames Feist namespace fs = std::filesystem; 1031da66f75SEd Tanous 104cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 10519bd78d9SPatrick Williams std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, 106cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 107cb92c03bSAndrew Geissler 108cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 109cb92c03bSAndrew Geissler sdbusplus::message::object_path, 110cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 111cb92c03bSAndrew Geissler 112cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 113cb92c03bSAndrew Geissler { 114d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 115d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 116d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 117d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 118cb92c03bSAndrew Geissler { 119cb92c03bSAndrew Geissler return "Critical"; 120cb92c03bSAndrew Geissler } 1213174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 122d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 123d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 124cb92c03bSAndrew Geissler { 125cb92c03bSAndrew Geissler return "OK"; 126cb92c03bSAndrew Geissler } 1273174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 128cb92c03bSAndrew Geissler { 129cb92c03bSAndrew Geissler return "Warning"; 130cb92c03bSAndrew Geissler } 131cb92c03bSAndrew Geissler return ""; 132cb92c03bSAndrew Geissler } 133cb92c03bSAndrew Geissler 1347e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 13539e77504SEd Tanous const std::string_view& field, 13639e77504SEd Tanous std::string_view& contents) 13716428a1aSJason M. Bills { 13816428a1aSJason M. Bills const char* data = nullptr; 13916428a1aSJason M. Bills size_t length = 0; 14016428a1aSJason M. Bills int ret = 0; 14116428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 142271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 143271584abSEd Tanous reinterpret_cast<const void**>(&data), &length); 14416428a1aSJason M. Bills if (ret < 0) 14516428a1aSJason M. Bills { 14616428a1aSJason M. Bills return ret; 14716428a1aSJason M. Bills } 14839e77504SEd Tanous contents = std::string_view(data, length); 14916428a1aSJason M. Bills // Only use the content after the "=" character. 15081ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 15116428a1aSJason M. Bills return ret; 15216428a1aSJason M. Bills } 15316428a1aSJason M. Bills 1547e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 1557e860f15SJohn Edward Broadbent const std::string_view& field, 1567e860f15SJohn Edward Broadbent const int& base, long int& contents) 15716428a1aSJason M. Bills { 15816428a1aSJason M. Bills int ret = 0; 15939e77504SEd Tanous std::string_view metadata; 16016428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 16116428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 16216428a1aSJason M. Bills if (ret < 0) 16316428a1aSJason M. Bills { 16416428a1aSJason M. Bills return ret; 16516428a1aSJason M. Bills } 166b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 16716428a1aSJason M. Bills return ret; 16816428a1aSJason M. Bills } 16916428a1aSJason M. Bills 1707e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1717e860f15SJohn Edward Broadbent std::string& entryTimestamp) 172a3316fc6SZhikuiRen { 173a3316fc6SZhikuiRen int ret = 0; 174a3316fc6SZhikuiRen uint64_t timestamp = 0; 175a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 176a3316fc6SZhikuiRen if (ret < 0) 177a3316fc6SZhikuiRen { 178a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 179a3316fc6SZhikuiRen << strerror(-ret); 180a3316fc6SZhikuiRen return false; 181a3316fc6SZhikuiRen } 1829c620e21SAsmitha Karunanithi entryTimestamp = crow::utility::getDateTime( 1839c620e21SAsmitha Karunanithi static_cast<std::time_t>(timestamp / 1000 / 1000)); 1849c620e21SAsmitha Karunanithi return true; 185a3316fc6SZhikuiRen } 186a3316fc6SZhikuiRen 1878d1b46d7Szhanghch05 static bool getSkipParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1888d1b46d7Szhanghch05 const crow::Request& req, uint64_t& skip) 18916428a1aSJason M. Bills { 1905a7e877eSJames Feist boost::urls::url_view::params_type::iterator it = 1915a7e877eSJames Feist req.urlParams.find("$skip"); 1925a7e877eSJames Feist if (it != req.urlParams.end()) 19316428a1aSJason M. Bills { 1945a7e877eSJames Feist std::string skipParam = it->value(); 19516428a1aSJason M. Bills char* ptr = nullptr; 1965a7e877eSJames Feist skip = std::strtoul(skipParam.c_str(), &ptr, 10); 1975a7e877eSJames Feist if (skipParam.empty() || *ptr != '\0') 19816428a1aSJason M. Bills { 19916428a1aSJason M. Bills 2008d1b46d7Szhanghch05 messages::queryParameterValueTypeError( 2018d1b46d7Szhanghch05 asyncResp->res, std::string(skipParam), "$skip"); 20216428a1aSJason M. Bills return false; 20316428a1aSJason M. Bills } 20416428a1aSJason M. Bills } 20516428a1aSJason M. Bills return true; 20616428a1aSJason M. Bills } 20716428a1aSJason M. Bills 208271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 2098d1b46d7Szhanghch05 static bool getTopParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2108d1b46d7Szhanghch05 const crow::Request& req, uint64_t& top) 21116428a1aSJason M. Bills { 2125a7e877eSJames Feist boost::urls::url_view::params_type::iterator it = 2135a7e877eSJames Feist req.urlParams.find("$top"); 2145a7e877eSJames Feist if (it != req.urlParams.end()) 21516428a1aSJason M. Bills { 2165a7e877eSJames Feist std::string topParam = it->value(); 21716428a1aSJason M. Bills char* ptr = nullptr; 2185a7e877eSJames Feist top = std::strtoul(topParam.c_str(), &ptr, 10); 2195a7e877eSJames Feist if (topParam.empty() || *ptr != '\0') 22016428a1aSJason M. Bills { 2218d1b46d7Szhanghch05 messages::queryParameterValueTypeError( 2228d1b46d7Szhanghch05 asyncResp->res, std::string(topParam), "$top"); 22316428a1aSJason M. Bills return false; 22416428a1aSJason M. Bills } 225271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 22616428a1aSJason M. Bills { 22716428a1aSJason M. Bills 22816428a1aSJason M. Bills messages::queryParameterOutOfRange( 2298d1b46d7Szhanghch05 asyncResp->res, std::to_string(top), "$top", 23016428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 23116428a1aSJason M. Bills return false; 23216428a1aSJason M. Bills } 23316428a1aSJason M. Bills } 23416428a1aSJason M. Bills return true; 23516428a1aSJason M. Bills } 23616428a1aSJason M. Bills 2377e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 238e85d6b16SJason M. Bills const bool firstEntry = true) 23916428a1aSJason M. Bills { 24016428a1aSJason M. Bills int ret = 0; 24116428a1aSJason M. Bills static uint64_t prevTs = 0; 24216428a1aSJason M. Bills static int index = 0; 243e85d6b16SJason M. Bills if (firstEntry) 244e85d6b16SJason M. Bills { 245e85d6b16SJason M. Bills prevTs = 0; 246e85d6b16SJason M. Bills } 247e85d6b16SJason M. Bills 24816428a1aSJason M. Bills // Get the entry timestamp 24916428a1aSJason M. Bills uint64_t curTs = 0; 25016428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 25116428a1aSJason M. Bills if (ret < 0) 25216428a1aSJason M. Bills { 25316428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 25416428a1aSJason M. Bills << strerror(-ret); 25516428a1aSJason M. Bills return false; 25616428a1aSJason M. Bills } 25716428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 25816428a1aSJason M. Bills if (curTs == prevTs) 25916428a1aSJason M. Bills { 26016428a1aSJason M. Bills index++; 26116428a1aSJason M. Bills } 26216428a1aSJason M. Bills else 26316428a1aSJason M. Bills { 26416428a1aSJason M. Bills // Otherwise, reset it 26516428a1aSJason M. Bills index = 0; 26616428a1aSJason M. Bills } 26716428a1aSJason M. Bills // Save the timestamp 26816428a1aSJason M. Bills prevTs = curTs; 26916428a1aSJason M. Bills 27016428a1aSJason M. Bills entryID = std::to_string(curTs); 27116428a1aSJason M. Bills if (index > 0) 27216428a1aSJason M. Bills { 27316428a1aSJason M. Bills entryID += "_" + std::to_string(index); 27416428a1aSJason M. Bills } 27516428a1aSJason M. Bills return true; 27616428a1aSJason M. Bills } 27716428a1aSJason M. Bills 278e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 279e85d6b16SJason M. Bills const bool firstEntry = true) 28095820184SJason M. Bills { 281271584abSEd Tanous static time_t prevTs = 0; 28295820184SJason M. Bills static int index = 0; 283e85d6b16SJason M. Bills if (firstEntry) 284e85d6b16SJason M. Bills { 285e85d6b16SJason M. Bills prevTs = 0; 286e85d6b16SJason M. Bills } 287e85d6b16SJason M. Bills 28895820184SJason M. Bills // Get the entry timestamp 289271584abSEd Tanous std::time_t curTs = 0; 29095820184SJason M. Bills std::tm timeStruct = {}; 29195820184SJason M. Bills std::istringstream entryStream(logEntry); 29295820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 29395820184SJason M. Bills { 29495820184SJason M. Bills curTs = std::mktime(&timeStruct); 29595820184SJason M. Bills } 29695820184SJason M. Bills // If the timestamp isn't unique, increment the index 29795820184SJason M. Bills if (curTs == prevTs) 29895820184SJason M. Bills { 29995820184SJason M. Bills index++; 30095820184SJason M. Bills } 30195820184SJason M. Bills else 30295820184SJason M. Bills { 30395820184SJason M. Bills // Otherwise, reset it 30495820184SJason M. Bills index = 0; 30595820184SJason M. Bills } 30695820184SJason M. Bills // Save the timestamp 30795820184SJason M. Bills prevTs = curTs; 30895820184SJason M. Bills 30995820184SJason M. Bills entryID = std::to_string(curTs); 31095820184SJason M. Bills if (index > 0) 31195820184SJason M. Bills { 31295820184SJason M. Bills entryID += "_" + std::to_string(index); 31395820184SJason M. Bills } 31495820184SJason M. Bills return true; 31595820184SJason M. Bills } 31695820184SJason M. Bills 3177e860f15SJohn Edward Broadbent inline static bool 3188d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3198d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 3208d1b46d7Szhanghch05 uint64_t& index) 32116428a1aSJason M. Bills { 32216428a1aSJason M. Bills if (entryID.empty()) 32316428a1aSJason M. Bills { 32416428a1aSJason M. Bills return false; 32516428a1aSJason M. Bills } 32616428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 32739e77504SEd Tanous std::string_view tsStr(entryID); 32816428a1aSJason M. Bills 32981ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 33016428a1aSJason M. Bills if (underscorePos != tsStr.npos) 33116428a1aSJason M. Bills { 33216428a1aSJason M. Bills // Timestamp has an index 33316428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 33439e77504SEd Tanous std::string_view indexStr(entryID); 33516428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 33616428a1aSJason M. Bills std::size_t pos; 33716428a1aSJason M. Bills try 33816428a1aSJason M. Bills { 33939e77504SEd Tanous index = std::stoul(std::string(indexStr), &pos); 34016428a1aSJason M. Bills } 341271584abSEd Tanous catch (std::invalid_argument&) 34216428a1aSJason M. Bills { 3438d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 34416428a1aSJason M. Bills return false; 34516428a1aSJason M. Bills } 346271584abSEd Tanous catch (std::out_of_range&) 34716428a1aSJason M. Bills { 3488d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 34916428a1aSJason M. Bills return false; 35016428a1aSJason M. Bills } 35116428a1aSJason M. Bills if (pos != indexStr.size()) 35216428a1aSJason M. Bills { 3538d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 35416428a1aSJason M. Bills return false; 35516428a1aSJason M. Bills } 35616428a1aSJason M. Bills } 35716428a1aSJason M. Bills // Timestamp has no index 35816428a1aSJason M. Bills std::size_t pos; 35916428a1aSJason M. Bills try 36016428a1aSJason M. Bills { 36139e77504SEd Tanous timestamp = std::stoull(std::string(tsStr), &pos); 36216428a1aSJason M. Bills } 363271584abSEd Tanous catch (std::invalid_argument&) 36416428a1aSJason M. Bills { 3658d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 36616428a1aSJason M. Bills return false; 36716428a1aSJason M. Bills } 368271584abSEd Tanous catch (std::out_of_range&) 36916428a1aSJason M. Bills { 3708d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 37116428a1aSJason M. Bills return false; 37216428a1aSJason M. Bills } 37316428a1aSJason M. Bills if (pos != tsStr.size()) 37416428a1aSJason M. Bills { 3758d1b46d7Szhanghch05 messages::resourceMissingAtURI(asyncResp->res, entryID); 37616428a1aSJason M. Bills return false; 37716428a1aSJason M. Bills } 37816428a1aSJason M. Bills return true; 37916428a1aSJason M. Bills } 38016428a1aSJason M. Bills 38195820184SJason M. Bills static bool 38295820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 38395820184SJason M. Bills { 38495820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 38595820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 38695820184SJason M. Bills 38795820184SJason M. Bills // Loop through the directory looking for redfish log files 38895820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 38995820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 39095820184SJason M. Bills { 39195820184SJason M. Bills // If we find a redfish log file, save the path 39295820184SJason M. Bills std::string filename = dirEnt.path().filename(); 39395820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 39495820184SJason M. Bills { 39595820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 39695820184SJason M. Bills } 39795820184SJason M. Bills } 39895820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 39995820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 40095820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 40195820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 40295820184SJason M. Bills 40395820184SJason M. Bills return !redfishLogFiles.empty(); 40495820184SJason M. Bills } 40595820184SJason M. Bills 4068d1b46d7Szhanghch05 inline void 4078d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4085cb1dd27SAsmitha Karunanithi const std::string& dumpType) 4095cb1dd27SAsmitha Karunanithi { 4105cb1dd27SAsmitha Karunanithi std::string dumpPath; 4115cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 4125cb1dd27SAsmitha Karunanithi { 4135cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 4145cb1dd27SAsmitha Karunanithi } 4155cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 4165cb1dd27SAsmitha Karunanithi { 4175cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 4185cb1dd27SAsmitha Karunanithi } 4195cb1dd27SAsmitha Karunanithi else 4205cb1dd27SAsmitha Karunanithi { 4215cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 4225cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4235cb1dd27SAsmitha Karunanithi return; 4245cb1dd27SAsmitha Karunanithi } 4255cb1dd27SAsmitha Karunanithi 4265cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 4275cb1dd27SAsmitha Karunanithi [asyncResp, dumpPath, dumpType](const boost::system::error_code ec, 4285cb1dd27SAsmitha Karunanithi GetManagedObjectsType& resp) { 4295cb1dd27SAsmitha Karunanithi if (ec) 4305cb1dd27SAsmitha Karunanithi { 4315cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4325cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4335cb1dd27SAsmitha Karunanithi return; 4345cb1dd27SAsmitha Karunanithi } 4355cb1dd27SAsmitha Karunanithi 4365cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4375cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 438b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 439b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 440b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 441b47452b2SAsmitha Karunanithi "/entry/"; 4425cb1dd27SAsmitha Karunanithi 4435cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4445cb1dd27SAsmitha Karunanithi { 445b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 4465cb1dd27SAsmitha Karunanithi { 4475cb1dd27SAsmitha Karunanithi continue; 4485cb1dd27SAsmitha Karunanithi } 4495cb1dd27SAsmitha Karunanithi std::time_t timestamp; 4505cb1dd27SAsmitha Karunanithi uint64_t size = 0; 4515cb1dd27SAsmitha Karunanithi entriesArray.push_back({}); 4525cb1dd27SAsmitha Karunanithi nlohmann::json& thisEntry = entriesArray.back(); 4532dfd18efSEd Tanous 4542dfd18efSEd Tanous std::string entryID = object.first.filename(); 4552dfd18efSEd Tanous if (entryID.empty()) 4565cb1dd27SAsmitha Karunanithi { 4575cb1dd27SAsmitha Karunanithi continue; 4585cb1dd27SAsmitha Karunanithi } 4595cb1dd27SAsmitha Karunanithi 4605cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4615cb1dd27SAsmitha Karunanithi { 4625cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 4635cb1dd27SAsmitha Karunanithi { 4645cb1dd27SAsmitha Karunanithi 4655cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4665cb1dd27SAsmitha Karunanithi { 4675cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4685cb1dd27SAsmitha Karunanithi { 4695cb1dd27SAsmitha Karunanithi auto sizePtr = 4705cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4715cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4725cb1dd27SAsmitha Karunanithi { 4735cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4745cb1dd27SAsmitha Karunanithi break; 4755cb1dd27SAsmitha Karunanithi } 4765cb1dd27SAsmitha Karunanithi size = *sizePtr; 4775cb1dd27SAsmitha Karunanithi break; 4785cb1dd27SAsmitha Karunanithi } 4795cb1dd27SAsmitha Karunanithi } 4805cb1dd27SAsmitha Karunanithi } 4815cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4825cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 4835cb1dd27SAsmitha Karunanithi { 4845cb1dd27SAsmitha Karunanithi 4855cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4865cb1dd27SAsmitha Karunanithi { 4875cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 4885cb1dd27SAsmitha Karunanithi { 4895cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 4905cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4915cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 4925cb1dd27SAsmitha Karunanithi { 4935cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4945cb1dd27SAsmitha Karunanithi break; 4955cb1dd27SAsmitha Karunanithi } 4965cb1dd27SAsmitha Karunanithi timestamp = 4975cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 4985cb1dd27SAsmitha Karunanithi break; 4995cb1dd27SAsmitha Karunanithi } 5005cb1dd27SAsmitha Karunanithi } 5015cb1dd27SAsmitha Karunanithi } 5025cb1dd27SAsmitha Karunanithi } 5035cb1dd27SAsmitha Karunanithi 5040ef217f4SGeorge Liu thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 5055cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 5065cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 5075cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5085cb1dd27SAsmitha Karunanithi thisEntry["Created"] = crow::utility::getDateTime(timestamp); 5095cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 5105cb1dd27SAsmitha Karunanithi 511d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataSizeBytes"] = size; 5125cb1dd27SAsmitha Karunanithi 5135cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5145cb1dd27SAsmitha Karunanithi { 515d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 516d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 517de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 518de8d94a3SAbhishek Patel entryID + "/attachment"; 5195cb1dd27SAsmitha Karunanithi } 5205cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5215cb1dd27SAsmitha Karunanithi { 522d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 523d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 524d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 525de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 526de8d94a3SAbhishek Patel entryID + "/attachment"; 5275cb1dd27SAsmitha Karunanithi } 5285cb1dd27SAsmitha Karunanithi } 5295cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 5305cb1dd27SAsmitha Karunanithi entriesArray.size(); 5315cb1dd27SAsmitha Karunanithi }, 5325cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5335cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5345cb1dd27SAsmitha Karunanithi } 5355cb1dd27SAsmitha Karunanithi 5368d1b46d7Szhanghch05 inline void 5378d1b46d7Szhanghch05 getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5388d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 5395cb1dd27SAsmitha Karunanithi { 5405cb1dd27SAsmitha Karunanithi std::string dumpPath; 5415cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5425cb1dd27SAsmitha Karunanithi { 5435cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5445cb1dd27SAsmitha Karunanithi } 5455cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5465cb1dd27SAsmitha Karunanithi { 5475cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5485cb1dd27SAsmitha Karunanithi } 5495cb1dd27SAsmitha Karunanithi else 5505cb1dd27SAsmitha Karunanithi { 5515cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5525cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5535cb1dd27SAsmitha Karunanithi return; 5545cb1dd27SAsmitha Karunanithi } 5555cb1dd27SAsmitha Karunanithi 5565cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 5575cb1dd27SAsmitha Karunanithi [asyncResp, entryID, dumpPath, dumpType]( 5585cb1dd27SAsmitha Karunanithi const boost::system::error_code ec, GetManagedObjectsType& resp) { 5595cb1dd27SAsmitha Karunanithi if (ec) 5605cb1dd27SAsmitha Karunanithi { 5615cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5625cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5635cb1dd27SAsmitha Karunanithi return; 5645cb1dd27SAsmitha Karunanithi } 5655cb1dd27SAsmitha Karunanithi 566b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 567b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 568b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 569b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 570b47452b2SAsmitha Karunanithi "/entry/"; 571b47452b2SAsmitha Karunanithi 5725cb1dd27SAsmitha Karunanithi for (auto& objectPath : resp) 5735cb1dd27SAsmitha Karunanithi { 574b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5755cb1dd27SAsmitha Karunanithi { 5765cb1dd27SAsmitha Karunanithi continue; 5775cb1dd27SAsmitha Karunanithi } 5785cb1dd27SAsmitha Karunanithi 5795cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 5805cb1dd27SAsmitha Karunanithi std::time_t timestamp; 5815cb1dd27SAsmitha Karunanithi uint64_t size = 0; 5825cb1dd27SAsmitha Karunanithi 5835cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 5845cb1dd27SAsmitha Karunanithi { 5855cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 5865cb1dd27SAsmitha Karunanithi { 5875cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 5885cb1dd27SAsmitha Karunanithi { 5895cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 5905cb1dd27SAsmitha Karunanithi { 5915cb1dd27SAsmitha Karunanithi auto sizePtr = 5925cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 5935cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 5945cb1dd27SAsmitha Karunanithi { 5955cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5965cb1dd27SAsmitha Karunanithi break; 5975cb1dd27SAsmitha Karunanithi } 5985cb1dd27SAsmitha Karunanithi size = *sizePtr; 5995cb1dd27SAsmitha Karunanithi break; 6005cb1dd27SAsmitha Karunanithi } 6015cb1dd27SAsmitha Karunanithi } 6025cb1dd27SAsmitha Karunanithi } 6035cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 6045cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 6055cb1dd27SAsmitha Karunanithi { 6065cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 6075cb1dd27SAsmitha Karunanithi { 6085cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 6095cb1dd27SAsmitha Karunanithi { 6105cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 6115cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6125cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 6135cb1dd27SAsmitha Karunanithi { 6145cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6155cb1dd27SAsmitha Karunanithi break; 6165cb1dd27SAsmitha Karunanithi } 6175cb1dd27SAsmitha Karunanithi timestamp = 6185cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 6195cb1dd27SAsmitha Karunanithi break; 6205cb1dd27SAsmitha Karunanithi } 6215cb1dd27SAsmitha Karunanithi } 6225cb1dd27SAsmitha Karunanithi } 6235cb1dd27SAsmitha Karunanithi } 6245cb1dd27SAsmitha Karunanithi 6255cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 6260ef217f4SGeorge Liu "#LogEntry.v1_8_0.LogEntry"; 6275cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6285cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6295cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6305cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6315cb1dd27SAsmitha Karunanithi crow::utility::getDateTime(timestamp); 6325cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6335cb1dd27SAsmitha Karunanithi 634d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6355cb1dd27SAsmitha Karunanithi 6365cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6375cb1dd27SAsmitha Karunanithi { 638d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 639d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 640de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 641de8d94a3SAbhishek Patel entryID + "/attachment"; 6425cb1dd27SAsmitha Karunanithi } 6435cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6445cb1dd27SAsmitha Karunanithi { 645d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 646d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["OEMDiagnosticDataType"] = 6475cb1dd27SAsmitha Karunanithi "System"; 648d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 649de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 650de8d94a3SAbhishek Patel entryID + "/attachment"; 6515cb1dd27SAsmitha Karunanithi } 6525cb1dd27SAsmitha Karunanithi } 653b47452b2SAsmitha Karunanithi if (foundDumpEntry == false) 654b47452b2SAsmitha Karunanithi { 655b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 656b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 657b47452b2SAsmitha Karunanithi return; 658b47452b2SAsmitha Karunanithi } 6595cb1dd27SAsmitha Karunanithi }, 6605cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6615cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6625cb1dd27SAsmitha Karunanithi } 6635cb1dd27SAsmitha Karunanithi 6648d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6659878256fSStanley Chu const std::string& entryID, 666b47452b2SAsmitha Karunanithi const std::string& dumpType) 6675cb1dd27SAsmitha Karunanithi { 6683de8d8baSGeorge Liu auto respHandler = [asyncResp, 6693de8d8baSGeorge Liu entryID](const boost::system::error_code ec) { 6705cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6715cb1dd27SAsmitha Karunanithi if (ec) 6725cb1dd27SAsmitha Karunanithi { 6733de8d8baSGeorge Liu if (ec.value() == EBADR) 6743de8d8baSGeorge Liu { 6753de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 6763de8d8baSGeorge Liu return; 6773de8d8baSGeorge Liu } 6785cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 6795cb1dd27SAsmitha Karunanithi << ec; 6805cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6815cb1dd27SAsmitha Karunanithi return; 6825cb1dd27SAsmitha Karunanithi } 6835cb1dd27SAsmitha Karunanithi }; 6845cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 6855cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 686b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 687b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 688b47452b2SAsmitha Karunanithi entryID, 6895cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 6905cb1dd27SAsmitha Karunanithi } 6915cb1dd27SAsmitha Karunanithi 6928d1b46d7Szhanghch05 inline void 6938d1b46d7Szhanghch05 createDumpTaskCallback(const crow::Request& req, 6948d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6958d1b46d7Szhanghch05 const uint32_t& dumpId, const std::string& dumpPath, 696a43be80fSAsmitha Karunanithi const std::string& dumpType) 697a43be80fSAsmitha Karunanithi { 698a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 6996145ed6fSAsmitha Karunanithi [dumpId, dumpPath, dumpType]( 700a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 701a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 702cb13a392SEd Tanous if (err) 703cb13a392SEd Tanous { 7046145ed6fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Error in creating a dump"; 7056145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 7066145ed6fSAsmitha Karunanithi return task::completed; 707cb13a392SEd Tanous } 708a43be80fSAsmitha Karunanithi std::vector<std::pair< 709a43be80fSAsmitha Karunanithi std::string, 710a43be80fSAsmitha Karunanithi std::vector<std::pair<std::string, std::variant<std::string>>>>> 711a43be80fSAsmitha Karunanithi interfacesList; 712a43be80fSAsmitha Karunanithi 713a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 714a43be80fSAsmitha Karunanithi 715a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 716a43be80fSAsmitha Karunanithi 717b47452b2SAsmitha Karunanithi if (objPath.str == 718b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 719b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 720b47452b2SAsmitha Karunanithi "/entry/" + std::to_string(dumpId)) 721a43be80fSAsmitha Karunanithi { 722a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 723a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 724a43be80fSAsmitha Karunanithi 725a43be80fSAsmitha Karunanithi std::string headerLoc = 726a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 727a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 728a43be80fSAsmitha Karunanithi std::move(headerLoc)); 729a43be80fSAsmitha Karunanithi 730a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 731b47452b2SAsmitha Karunanithi return task::completed; 7326145ed6fSAsmitha Karunanithi } 733a43be80fSAsmitha Karunanithi return task::completed; 734a43be80fSAsmitha Karunanithi }, 735a43be80fSAsmitha Karunanithi "type='signal',interface='org.freedesktop.DBus." 736a43be80fSAsmitha Karunanithi "ObjectManager'," 737a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 738a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 739a43be80fSAsmitha Karunanithi 740a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 741a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 742a43be80fSAsmitha Karunanithi task->payload.emplace(req); 743a43be80fSAsmitha Karunanithi } 744a43be80fSAsmitha Karunanithi 7458d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7468d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 747a43be80fSAsmitha Karunanithi { 748a43be80fSAsmitha Karunanithi 749a43be80fSAsmitha Karunanithi std::string dumpPath; 750a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 751a43be80fSAsmitha Karunanithi { 752a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 753a43be80fSAsmitha Karunanithi } 754a43be80fSAsmitha Karunanithi else if (dumpType == "System") 755a43be80fSAsmitha Karunanithi { 756a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 757a43be80fSAsmitha Karunanithi } 758a43be80fSAsmitha Karunanithi else 759a43be80fSAsmitha Karunanithi { 760a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 761a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 762a43be80fSAsmitha Karunanithi return; 763a43be80fSAsmitha Karunanithi } 764a43be80fSAsmitha Karunanithi 765a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 766a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 767a43be80fSAsmitha Karunanithi 768a43be80fSAsmitha Karunanithi if (!redfish::json_util::readJson( 769a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 770a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 771a43be80fSAsmitha Karunanithi { 772a43be80fSAsmitha Karunanithi return; 773a43be80fSAsmitha Karunanithi } 774a43be80fSAsmitha Karunanithi 775a43be80fSAsmitha Karunanithi if (dumpType == "System") 776a43be80fSAsmitha Karunanithi { 777a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 778a43be80fSAsmitha Karunanithi { 779a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 780a43be80fSAsmitha Karunanithi "'DiagnosticDataType'/" 781a43be80fSAsmitha Karunanithi "'OEMDiagnosticDataType' value not found!"; 782a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 783a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 784a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 785a43be80fSAsmitha Karunanithi return; 786a43be80fSAsmitha Karunanithi } 7873174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 788a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 789a43be80fSAsmitha Karunanithi { 790a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 791a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 792a43be80fSAsmitha Karunanithi "System Dump creation parameters"); 793a43be80fSAsmitha Karunanithi return; 794a43be80fSAsmitha Karunanithi } 795a43be80fSAsmitha Karunanithi } 796a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 797a43be80fSAsmitha Karunanithi { 798a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 799a43be80fSAsmitha Karunanithi { 800a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump action parameter " 801a43be80fSAsmitha Karunanithi "'DiagnosticDataType' not found!"; 802a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 803a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 804a43be80fSAsmitha Karunanithi return; 805a43be80fSAsmitha Karunanithi } 8063174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 807a43be80fSAsmitha Karunanithi { 808a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 809a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 810a43be80fSAsmitha Karunanithi messages::invalidObject(asyncResp->res, 811a43be80fSAsmitha Karunanithi "BMC Dump creation parameters"); 812a43be80fSAsmitha Karunanithi return; 813a43be80fSAsmitha Karunanithi } 814a43be80fSAsmitha Karunanithi } 815a43be80fSAsmitha Karunanithi 816a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 817a43be80fSAsmitha Karunanithi [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec, 818a43be80fSAsmitha Karunanithi const uint32_t& dumpId) { 819a43be80fSAsmitha Karunanithi if (ec) 820a43be80fSAsmitha Karunanithi { 821a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 822a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 823a43be80fSAsmitha Karunanithi return; 824a43be80fSAsmitha Karunanithi } 825a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 826a43be80fSAsmitha Karunanithi 827a43be80fSAsmitha Karunanithi createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType); 828a43be80fSAsmitha Karunanithi }, 829b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 830b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 831b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 832a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 833a43be80fSAsmitha Karunanithi } 834a43be80fSAsmitha Karunanithi 8358d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8368d1b46d7Szhanghch05 const std::string& dumpType) 83780319af1SAsmitha Karunanithi { 838b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 839b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 8408d1b46d7Szhanghch05 84180319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 842b47452b2SAsmitha Karunanithi [asyncResp, dumpType](const boost::system::error_code ec, 84380319af1SAsmitha Karunanithi const std::vector<std::string>& subTreePaths) { 84480319af1SAsmitha Karunanithi if (ec) 84580319af1SAsmitha Karunanithi { 84680319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 84780319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 84880319af1SAsmitha Karunanithi return; 84980319af1SAsmitha Karunanithi } 85080319af1SAsmitha Karunanithi 85180319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 85280319af1SAsmitha Karunanithi { 8532dfd18efSEd Tanous sdbusplus::message::object_path objPath(path); 8542dfd18efSEd Tanous std::string logID = objPath.filename(); 8552dfd18efSEd Tanous if (logID.empty()) 85680319af1SAsmitha Karunanithi { 8572dfd18efSEd Tanous continue; 85880319af1SAsmitha Karunanithi } 8592dfd18efSEd Tanous deleteDumpEntry(asyncResp, logID, dumpType); 86080319af1SAsmitha Karunanithi } 86180319af1SAsmitha Karunanithi }, 86280319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 86380319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 86480319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 865b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, 866b47452b2SAsmitha Karunanithi std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." + 867b47452b2SAsmitha Karunanithi dumpType}); 86880319af1SAsmitha Karunanithi } 86980319af1SAsmitha Karunanithi 8707e860f15SJohn Edward Broadbent inline static void parseCrashdumpParameters( 871043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params, 872043a0536SJohnathan Mantey std::string& filename, std::string& timestamp, std::string& logfile) 873043a0536SJohnathan Mantey { 874043a0536SJohnathan Mantey for (auto property : params) 875043a0536SJohnathan Mantey { 876043a0536SJohnathan Mantey if (property.first == "Timestamp") 877043a0536SJohnathan Mantey { 878043a0536SJohnathan Mantey const std::string* value = 8798d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 880043a0536SJohnathan Mantey if (value != nullptr) 881043a0536SJohnathan Mantey { 882043a0536SJohnathan Mantey timestamp = *value; 883043a0536SJohnathan Mantey } 884043a0536SJohnathan Mantey } 885043a0536SJohnathan Mantey else if (property.first == "Filename") 886043a0536SJohnathan Mantey { 887043a0536SJohnathan Mantey const std::string* value = 8888d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 889043a0536SJohnathan Mantey if (value != nullptr) 890043a0536SJohnathan Mantey { 891043a0536SJohnathan Mantey filename = *value; 892043a0536SJohnathan Mantey } 893043a0536SJohnathan Mantey } 894043a0536SJohnathan Mantey else if (property.first == "Log") 895043a0536SJohnathan Mantey { 896043a0536SJohnathan Mantey const std::string* value = 8978d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 898043a0536SJohnathan Mantey if (value != nullptr) 899043a0536SJohnathan Mantey { 900043a0536SJohnathan Mantey logfile = *value; 901043a0536SJohnathan Mantey } 902043a0536SJohnathan Mantey } 903043a0536SJohnathan Mantey } 904043a0536SJohnathan Mantey } 905043a0536SJohnathan Mantey 906a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 9077e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 9081da66f75SEd Tanous { 909c4bf6374SJason M. Bills /** 910c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 911c4bf6374SJason M. Bills */ 9127e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/") 913432a890cSEd Tanous .privileges({{"Login"}}) 9147e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 9157e860f15SJohn Edward Broadbent [](const crow::Request&, 9167e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 9177e860f15SJohn Edward Broadbent 918c4bf6374SJason M. Bills { 9197e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 9207e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 921c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 922c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 923c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 924029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 9257e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 9267e860f15SJohn Edward Broadbent "System Log Services Collection"; 927c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 928c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 9297e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 9307e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 931c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 932029573d4SEd Tanous logServiceArray.push_back( 9337e860f15SJohn Edward Broadbent {{"@odata.id", 9347e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog"}}); 9355cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 936c9bb6861Sraviteja-b logServiceArray.push_back( 9377e860f15SJohn Edward Broadbent {{"@odata.id", 9387e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump"}}); 939c9bb6861Sraviteja-b #endif 940c9bb6861Sraviteja-b 941d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 942d53dd41fSJason M. Bills logServiceArray.push_back( 943cb92c03bSAndrew Geissler {{"@odata.id", 944424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 945d53dd41fSJason M. Bills #endif 946c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 947c4bf6374SJason M. Bills logServiceArray.size(); 948a3316fc6SZhikuiRen 949a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 950a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 951a3316fc6SZhikuiRen const std::vector<std::string>& subtreePath) { 952a3316fc6SZhikuiRen if (ec) 953a3316fc6SZhikuiRen { 954a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 955a3316fc6SZhikuiRen return; 956a3316fc6SZhikuiRen } 957a3316fc6SZhikuiRen 958a3316fc6SZhikuiRen for (auto& pathStr : subtreePath) 959a3316fc6SZhikuiRen { 960a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 961a3316fc6SZhikuiRen { 96223a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 963a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 96423a21a1cSEd Tanous logServiceArrayLocal.push_back( 965a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 966a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 9677e860f15SJohn Edward Broadbent asyncResp->res 9687e860f15SJohn Edward Broadbent .jsonValue["Members@odata.count"] = 96923a21a1cSEd Tanous logServiceArrayLocal.size(); 970a3316fc6SZhikuiRen return; 971a3316fc6SZhikuiRen } 972a3316fc6SZhikuiRen } 973a3316fc6SZhikuiRen }, 974a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 975a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 9767e860f15SJohn Edward Broadbent "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 9777e860f15SJohn Edward Broadbent 0, std::array<const char*, 1>{postCodeIface}); 9787e860f15SJohn Edward Broadbent }); 979c4bf6374SJason M. Bills } 980c4bf6374SJason M. Bills 9817e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 982c4bf6374SJason M. Bills { 9837e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 984432a890cSEd Tanous .privileges({{"Login"}}) 9857e860f15SJohn Edward Broadbent .methods( 9867e860f15SJohn Edward Broadbent boost::beast::http::verb:: 9877e860f15SJohn Edward Broadbent get)([](const crow::Request&, 9887e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 989c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 990029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 991c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 992c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 993c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 9947e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 9957e860f15SJohn Edward Broadbent "System Event Log Service"; 996c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 997c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 998c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 999c4bf6374SJason M. Bills {"@odata.id", 1000029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 1001e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1002e7d6c8b2SGunnar Mills 1003e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 1004e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 10057e860f15SJohn Edward Broadbent }); 1006489640c6SJason M. Bills } 1007489640c6SJason M. Bills 10087e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1009489640c6SJason M. Bills { 10107e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 1011489640c6SJason M. Bills "LogService.ClearLog/") 1012432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 10137e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 10147e860f15SJohn Edward Broadbent [](const crow::Request&, 10157e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1016489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1017489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1018489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1019489640c6SJason M. Bills { 1020489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1021489640c6SJason M. Bills { 1022489640c6SJason M. Bills std::error_code ec; 1023489640c6SJason M. Bills std::filesystem::remove(file, ec); 1024489640c6SJason M. Bills } 1025489640c6SJason M. Bills } 1026489640c6SJason M. Bills 1027489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1028489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1029489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1030489640c6SJason M. Bills if (ec) 1031489640c6SJason M. Bills { 10327e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " 10337e860f15SJohn Edward Broadbent << ec; 1034489640c6SJason M. Bills messages::internalError(asyncResp->res); 1035489640c6SJason M. Bills return; 1036489640c6SJason M. Bills } 1037489640c6SJason M. Bills 1038489640c6SJason M. Bills messages::success(asyncResp->res); 1039489640c6SJason M. Bills }, 1040489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 10417e860f15SJohn Edward Broadbent "org.freedesktop.systemd1.Manager", "ReloadUnit", 10427e860f15SJohn Edward Broadbent "rsyslog.service", "replace"); 10437e860f15SJohn Edward Broadbent }); 1044c4bf6374SJason M. Bills } 1045c4bf6374SJason M. Bills 104695820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 1047b5a76932SEd Tanous const std::string& logEntry, 104895820184SJason M. Bills nlohmann::json& logEntryJson) 1049c4bf6374SJason M. Bills { 105095820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1051cd225da8SJason M. Bills // First get the Timestamp 1052f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1053cd225da8SJason M. Bills if (space == std::string::npos) 105495820184SJason M. Bills { 105595820184SJason M. Bills return 1; 105695820184SJason M. Bills } 1057cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1058cd225da8SJason M. Bills // Then get the log contents 1059f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1060cd225da8SJason M. Bills if (entryStart == std::string::npos) 1061cd225da8SJason M. Bills { 1062cd225da8SJason M. Bills return 1; 1063cd225da8SJason M. Bills } 1064cd225da8SJason M. Bills std::string_view entry(logEntry); 1065cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1066cd225da8SJason M. Bills // Use split to separate the entry into its fields 1067cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1068cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1069cd225da8SJason M. Bills boost::token_compress_on); 1070cd225da8SJason M. Bills // We need at least a MessageId to be valid 1071cd225da8SJason M. Bills if (logEntryFields.size() < 1) 1072cd225da8SJason M. Bills { 1073cd225da8SJason M. Bills return 1; 1074cd225da8SJason M. Bills } 1075cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 107695820184SJason M. Bills 10774851d45dSJason M. Bills // Get the Message from the MessageRegistry 10784851d45dSJason M. Bills const message_registries::Message* message = 10794851d45dSJason M. Bills message_registries::getMessage(messageID); 1080c4bf6374SJason M. Bills 10814851d45dSJason M. Bills std::string msg; 10824851d45dSJason M. Bills std::string severity; 10834851d45dSJason M. Bills if (message != nullptr) 1084c4bf6374SJason M. Bills { 10854851d45dSJason M. Bills msg = message->message; 10864851d45dSJason M. Bills severity = message->severity; 1087c4bf6374SJason M. Bills } 1088c4bf6374SJason M. Bills 108915a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 109015a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 109115a86ff6SJason M. Bills if (logEntryFields.size() > 1) 109215a86ff6SJason M. Bills { 109315a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 109415a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 109515a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 109615a86ff6SJason M. Bills if (!messageArgsStart.empty()) 109715a86ff6SJason M. Bills { 109815a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 109915a86ff6SJason M. Bills } 110015a86ff6SJason M. Bills 110123a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1102c4bf6374SJason M. Bills 11034851d45dSJason M. Bills // Fill the MessageArgs into the Message 110495820184SJason M. Bills int i = 0; 110595820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11064851d45dSJason M. Bills { 110795820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11084851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11094851d45dSJason M. Bills if (argPos != std::string::npos) 11104851d45dSJason M. Bills { 111195820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11124851d45dSJason M. Bills } 11134851d45dSJason M. Bills } 111415a86ff6SJason M. Bills } 11154851d45dSJason M. Bills 111695820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 111795820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 111895820184SJason M. Bills // between the '.' and the '+', so just remove them. 1119f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1120f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 112195820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1122c4bf6374SJason M. Bills { 112395820184SJason M. Bills timestamp.erase(dot, plus - dot); 1124c4bf6374SJason M. Bills } 1125c4bf6374SJason M. Bills 1126c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 112795820184SJason M. Bills logEntryJson = { 11280ef217f4SGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 1129029573d4SEd Tanous {"@odata.id", 1130897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 113195820184SJason M. Bills logEntryID}, 1132c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 113395820184SJason M. Bills {"Id", logEntryID}, 113495820184SJason M. Bills {"Message", std::move(msg)}, 113595820184SJason M. Bills {"MessageId", std::move(messageID)}, 1136f23b7296SEd Tanous {"MessageArgs", messageArgs}, 1137c4bf6374SJason M. Bills {"EntryType", "Event"}, 113895820184SJason M. Bills {"Severity", std::move(severity)}, 113995820184SJason M. Bills {"Created", std::move(timestamp)}}; 1140c4bf6374SJason M. Bills return 0; 1141c4bf6374SJason M. Bills } 1142c4bf6374SJason M. Bills 11437e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1144c4bf6374SJason M. Bills { 11457e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 11467e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1147432a890cSEd Tanous .privileges({{"Login"}}) 11487e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 11497e860f15SJohn Edward Broadbent [](const crow::Request& req, 11507e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1151271584abSEd Tanous uint64_t skip = 0; 1152271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 11538d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 1154c4bf6374SJason M. Bills { 1155c4bf6374SJason M. Bills return; 1156c4bf6374SJason M. Bills } 11578d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 1158c4bf6374SJason M. Bills { 1159c4bf6374SJason M. Bills return; 1160c4bf6374SJason M. Bills } 11617e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 11627e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1163c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1164c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1165c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1166029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1167c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1168c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1169c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1170cb92c03bSAndrew Geissler 11717e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 11727e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 1173c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 11747e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 11757e860f15SJohn Edward Broadbent // entry 117695820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 117795820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1178b01bf299SEd Tanous uint64_t entryCount = 0; 1179cd225da8SJason M. Bills std::string logEntry; 118095820184SJason M. Bills 11817e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 11827e860f15SJohn Edward Broadbent // backwards 11837e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 11847e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1185c4bf6374SJason M. Bills { 1186cd225da8SJason M. Bills std::ifstream logStream(*it); 118795820184SJason M. Bills if (!logStream.is_open()) 1188c4bf6374SJason M. Bills { 1189c4bf6374SJason M. Bills continue; 1190c4bf6374SJason M. Bills } 1191c4bf6374SJason M. Bills 1192e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1193e85d6b16SJason M. Bills bool firstEntry = true; 119495820184SJason M. Bills while (std::getline(logStream, logEntry)) 119595820184SJason M. Bills { 1196c4bf6374SJason M. Bills entryCount++; 11977e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip 11987e860f15SJohn Edward Broadbent // from the start) and top (number of entries to 11997e860f15SJohn Edward Broadbent // display) 1200c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1201c4bf6374SJason M. Bills { 1202c4bf6374SJason M. Bills continue; 1203c4bf6374SJason M. Bills } 1204c4bf6374SJason M. Bills 1205c4bf6374SJason M. Bills std::string idStr; 1206e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1207c4bf6374SJason M. Bills { 1208c4bf6374SJason M. Bills continue; 1209c4bf6374SJason M. Bills } 1210c4bf6374SJason M. Bills 1211e85d6b16SJason M. Bills if (firstEntry) 1212e85d6b16SJason M. Bills { 1213e85d6b16SJason M. Bills firstEntry = false; 1214e85d6b16SJason M. Bills } 1215e85d6b16SJason M. Bills 1216c4bf6374SJason M. Bills logEntryArray.push_back({}); 1217c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 12187e860f15SJohn Edward Broadbent if (fillEventLogEntryJson(idStr, logEntry, 12197e860f15SJohn Edward Broadbent bmcLogEntry) != 0) 1220c4bf6374SJason M. Bills { 1221c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1222c4bf6374SJason M. Bills return; 1223c4bf6374SJason M. Bills } 1224c4bf6374SJason M. Bills } 122595820184SJason M. Bills } 1226c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1227c4bf6374SJason M. Bills if (skip + top < entryCount) 1228c4bf6374SJason M. Bills { 1229c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 123095820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 123195820184SJason M. Bills "Entries?$skip=" + 1232c4bf6374SJason M. Bills std::to_string(skip + top); 1233c4bf6374SJason M. Bills } 12347e860f15SJohn Edward Broadbent }); 1235897967deSJason M. Bills } 1236897967deSJason M. Bills 12377e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1238897967deSJason M. Bills { 12397e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 12407e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1241432a890cSEd Tanous .privileges({{"Login"}}) 12427e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 12437e860f15SJohn Edward Broadbent [](const crow::Request&, 12447e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12457e860f15SJohn Edward Broadbent const std::string& param) { 12467e860f15SJohn Edward Broadbent const std::string& targetID = param; 12478d1b46d7Szhanghch05 12487e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 12497e860f15SJohn Edward Broadbent // entry to find the target entry 1250897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1251897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1252897967deSJason M. Bills std::string logEntry; 1253897967deSJason M. Bills 12547e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12557e860f15SJohn Edward Broadbent // backwards 12567e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 12577e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1258897967deSJason M. Bills { 1259897967deSJason M. Bills std::ifstream logStream(*it); 1260897967deSJason M. Bills if (!logStream.is_open()) 1261897967deSJason M. Bills { 1262897967deSJason M. Bills continue; 1263897967deSJason M. Bills } 1264897967deSJason M. Bills 1265897967deSJason M. Bills // Reset the unique ID on the first entry 1266897967deSJason M. Bills bool firstEntry = true; 1267897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1268897967deSJason M. Bills { 1269897967deSJason M. Bills std::string idStr; 1270897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1271897967deSJason M. Bills { 1272897967deSJason M. Bills continue; 1273897967deSJason M. Bills } 1274897967deSJason M. Bills 1275897967deSJason M. Bills if (firstEntry) 1276897967deSJason M. Bills { 1277897967deSJason M. Bills firstEntry = false; 1278897967deSJason M. Bills } 1279897967deSJason M. Bills 1280897967deSJason M. Bills if (idStr == targetID) 1281897967deSJason M. Bills { 12827e860f15SJohn Edward Broadbent if (fillEventLogEntryJson( 12837e860f15SJohn Edward Broadbent idStr, logEntry, 1284897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1285897967deSJason M. Bills { 1286897967deSJason M. Bills messages::internalError(asyncResp->res); 1287897967deSJason M. Bills return; 1288897967deSJason M. Bills } 1289897967deSJason M. Bills return; 1290897967deSJason M. Bills } 1291897967deSJason M. Bills } 1292897967deSJason M. Bills } 1293897967deSJason M. Bills // Requested ID was not found 1294897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 12957e860f15SJohn Edward Broadbent }); 129608a4e4b5SAnthony Wilson } 129708a4e4b5SAnthony Wilson 12987e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 129908a4e4b5SAnthony Wilson { 13007e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 13017e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1302432a890cSEd Tanous .privileges({{"Login"}}) 13037e860f15SJohn Edward Broadbent .methods( 13047e860f15SJohn Edward Broadbent boost::beast::http::verb:: 13057e860f15SJohn Edward Broadbent get)([](const crow::Request&, 13067e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 13077e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 13087e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 130908a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 131008a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 131108a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 131208a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 131308a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 131408a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 131508a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 131608a4e4b5SAnthony Wilson 1317cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1318cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1319cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1320cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1321cb92c03bSAndrew Geissler GetManagedObjectsType& resp) { 1322cb92c03bSAndrew Geissler if (ec) 1323cb92c03bSAndrew Geissler { 1324cb92c03bSAndrew Geissler // TODO Handle for specific error code 1325cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1326cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1327cb92c03bSAndrew Geissler << ec; 1328cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1329cb92c03bSAndrew Geissler return; 1330cb92c03bSAndrew Geissler } 1331cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1332cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1333cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 1334cb92c03bSAndrew Geissler for (auto& objectPath : resp) 1335cb92c03bSAndrew Geissler { 133666664f25SEd Tanous uint32_t* id = nullptr; 133766664f25SEd Tanous std::time_t timestamp{}; 1338d139c236SGeorge Liu std::time_t updateTimestamp{}; 133966664f25SEd Tanous std::string* severity = nullptr; 134066664f25SEd Tanous std::string* message = nullptr; 1341f86bb901SAdriana Kobylak std::string* filePath = nullptr; 134275710de2SXiaochao Ma bool resolved = false; 1343f86bb901SAdriana Kobylak for (auto& interfaceMap : objectPath.second) 1344f86bb901SAdriana Kobylak { 1345f86bb901SAdriana Kobylak if (interfaceMap.first == 1346f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1347f86bb901SAdriana Kobylak { 1348cb92c03bSAndrew Geissler for (auto& propertyMap : interfaceMap.second) 1349cb92c03bSAndrew Geissler { 1350cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1351cb92c03bSAndrew Geissler { 1352f86bb901SAdriana Kobylak id = std::get_if<uint32_t>( 1353f86bb901SAdriana Kobylak &propertyMap.second); 1354cb92c03bSAndrew Geissler } 1355cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1356cb92c03bSAndrew Geissler { 1357cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1358f86bb901SAdriana Kobylak std::get_if<uint64_t>( 1359f86bb901SAdriana Kobylak &propertyMap.second); 1360ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1361ebd45906SGeorge Liu { 13627e860f15SJohn Edward Broadbent timestamp = 13637e860f15SJohn Edward Broadbent crow::utility::getTimestamp( 13647e860f15SJohn Edward Broadbent *millisTimeStamp); 13657e860f15SJohn Edward Broadbent } 13667e860f15SJohn Edward Broadbent } 13677e860f15SJohn Edward Broadbent else if (propertyMap.first == 13687e860f15SJohn Edward Broadbent "UpdateTimestamp") 13697e860f15SJohn Edward Broadbent { 13707e860f15SJohn Edward Broadbent const uint64_t* millisTimeStamp = 13717e860f15SJohn Edward Broadbent std::get_if<uint64_t>( 13727e860f15SJohn Edward Broadbent &propertyMap.second); 13737e860f15SJohn Edward Broadbent if (millisTimeStamp != nullptr) 13747e860f15SJohn Edward Broadbent { 13757e860f15SJohn Edward Broadbent updateTimestamp = 13767e860f15SJohn Edward Broadbent crow::utility::getTimestamp( 13777e860f15SJohn Edward Broadbent *millisTimeStamp); 13787e860f15SJohn Edward Broadbent } 13797e860f15SJohn Edward Broadbent } 13807e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 13817e860f15SJohn Edward Broadbent { 13827e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 13837e860f15SJohn Edward Broadbent &propertyMap.second); 13847e860f15SJohn Edward Broadbent } 13857e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 13867e860f15SJohn Edward Broadbent { 13877e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 13887e860f15SJohn Edward Broadbent &propertyMap.second); 13897e860f15SJohn Edward Broadbent } 13907e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 13917e860f15SJohn Edward Broadbent { 13927e860f15SJohn Edward Broadbent bool* resolveptr = std::get_if<bool>( 13937e860f15SJohn Edward Broadbent &propertyMap.second); 13947e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 13957e860f15SJohn Edward Broadbent { 13967e860f15SJohn Edward Broadbent messages::internalError( 13977e860f15SJohn Edward Broadbent asyncResp->res); 13987e860f15SJohn Edward Broadbent return; 13997e860f15SJohn Edward Broadbent } 14007e860f15SJohn Edward Broadbent resolved = *resolveptr; 14017e860f15SJohn Edward Broadbent } 14027e860f15SJohn Edward Broadbent } 14037e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14047e860f15SJohn Edward Broadbent severity == nullptr) 14057e860f15SJohn Edward Broadbent { 14067e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 14077e860f15SJohn Edward Broadbent return; 14087e860f15SJohn Edward Broadbent } 14097e860f15SJohn Edward Broadbent } 14107e860f15SJohn Edward Broadbent else if (interfaceMap.first == 14117e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 14127e860f15SJohn Edward Broadbent { 14137e860f15SJohn Edward Broadbent for (auto& propertyMap : interfaceMap.second) 14147e860f15SJohn Edward Broadbent { 14157e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 14167e860f15SJohn Edward Broadbent { 14177e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 14187e860f15SJohn Edward Broadbent &propertyMap.second); 14197e860f15SJohn Edward Broadbent } 14207e860f15SJohn Edward Broadbent } 14217e860f15SJohn Edward Broadbent } 14227e860f15SJohn Edward Broadbent } 14237e860f15SJohn Edward Broadbent // Object path without the 14247e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 14257e860f15SJohn Edward Broadbent // and continue. 14267e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14277e860f15SJohn Edward Broadbent severity == nullptr) 14287e860f15SJohn Edward Broadbent { 14297e860f15SJohn Edward Broadbent continue; 14307e860f15SJohn Edward Broadbent } 14317e860f15SJohn Edward Broadbent entriesArray.push_back({}); 14327e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 14337e860f15SJohn Edward Broadbent thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 14347e860f15SJohn Edward Broadbent thisEntry["@odata.id"] = 14357e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/" 14367e860f15SJohn Edward Broadbent "LogServices/EventLog/Entries/" + 14377e860f15SJohn Edward Broadbent std::to_string(*id); 14387e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 14397e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 14407e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 14417e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 14427e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 14437e860f15SJohn Edward Broadbent thisEntry["Severity"] = 14447e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 14457e860f15SJohn Edward Broadbent thisEntry["Created"] = 14467e860f15SJohn Edward Broadbent crow::utility::getDateTime(timestamp); 14477e860f15SJohn Edward Broadbent thisEntry["Modified"] = 14487e860f15SJohn Edward Broadbent crow::utility::getDateTime(updateTimestamp); 14497e860f15SJohn Edward Broadbent if (filePath != nullptr) 14507e860f15SJohn Edward Broadbent { 14517e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 14527e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/" 14537e860f15SJohn Edward Broadbent "EventLog/" 14547e860f15SJohn Edward Broadbent "Entries/" + 14557e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 14567e860f15SJohn Edward Broadbent } 14577e860f15SJohn Edward Broadbent } 14587e860f15SJohn Edward Broadbent std::sort(entriesArray.begin(), entriesArray.end(), 14597e860f15SJohn Edward Broadbent [](const nlohmann::json& left, 14607e860f15SJohn Edward Broadbent const nlohmann::json& right) { 14617e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 14627e860f15SJohn Edward Broadbent }); 14637e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 14647e860f15SJohn Edward Broadbent entriesArray.size(); 14657e860f15SJohn Edward Broadbent }, 14667e860f15SJohn Edward Broadbent "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 14677e860f15SJohn Edward Broadbent "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 14687e860f15SJohn Edward Broadbent }); 14697e860f15SJohn Edward Broadbent } 14707e860f15SJohn Edward Broadbent 14717e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 14727e860f15SJohn Edward Broadbent { 14737e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 14747e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1475432a890cSEd Tanous .privileges({{"Login"}}) 14767e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 14777e860f15SJohn Edward Broadbent [](const crow::Request&, 14787e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 14797e860f15SJohn Edward Broadbent const std::string& param) 14807e860f15SJohn Edward Broadbent 14817e860f15SJohn Edward Broadbent { 14827e860f15SJohn Edward Broadbent std::string entryID = param; 14837e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 14847e860f15SJohn Edward Broadbent 14857e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 14867e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 14877e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 14887e860f15SJohn Edward Broadbent [asyncResp, entryID](const boost::system::error_code ec, 14897e860f15SJohn Edward Broadbent GetManagedPropertyType& resp) { 14907e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 14917e860f15SJohn Edward Broadbent { 14927e860f15SJohn Edward Broadbent messages::resourceNotFound( 14937e860f15SJohn Edward Broadbent asyncResp->res, "EventLogEntry", entryID); 14947e860f15SJohn Edward Broadbent return; 14957e860f15SJohn Edward Broadbent } 14967e860f15SJohn Edward Broadbent if (ec) 14977e860f15SJohn Edward Broadbent { 14987e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "EventLogEntry (DBus) " 14997e860f15SJohn Edward Broadbent "resp_handler got error " 15007e860f15SJohn Edward Broadbent << ec; 15017e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 15027e860f15SJohn Edward Broadbent return; 15037e860f15SJohn Edward Broadbent } 15047e860f15SJohn Edward Broadbent uint32_t* id = nullptr; 15057e860f15SJohn Edward Broadbent std::time_t timestamp{}; 15067e860f15SJohn Edward Broadbent std::time_t updateTimestamp{}; 15077e860f15SJohn Edward Broadbent std::string* severity = nullptr; 15087e860f15SJohn Edward Broadbent std::string* message = nullptr; 15097e860f15SJohn Edward Broadbent std::string* filePath = nullptr; 15107e860f15SJohn Edward Broadbent bool resolved = false; 15117e860f15SJohn Edward Broadbent 15127e860f15SJohn Edward Broadbent for (auto& propertyMap : resp) 15137e860f15SJohn Edward Broadbent { 15147e860f15SJohn Edward Broadbent if (propertyMap.first == "Id") 15157e860f15SJohn Edward Broadbent { 15167e860f15SJohn Edward Broadbent id = std::get_if<uint32_t>(&propertyMap.second); 15177e860f15SJohn Edward Broadbent } 15187e860f15SJohn Edward Broadbent else if (propertyMap.first == "Timestamp") 15197e860f15SJohn Edward Broadbent { 15207e860f15SJohn Edward Broadbent const uint64_t* millisTimeStamp = 15217e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 15227e860f15SJohn Edward Broadbent if (millisTimeStamp != nullptr) 15237e860f15SJohn Edward Broadbent { 1524d139c236SGeorge Liu timestamp = crow::utility::getTimestamp( 1525cb92c03bSAndrew Geissler *millisTimeStamp); 1526d139c236SGeorge Liu } 1527ebd45906SGeorge Liu } 1528d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1529d139c236SGeorge Liu { 1530d139c236SGeorge Liu const uint64_t* millisTimeStamp = 15317e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 1532ae34c8e8SAdriana Kobylak if (millisTimeStamp != nullptr) 1533ebd45906SGeorge Liu { 1534ebd45906SGeorge Liu updateTimestamp = 1535ebd45906SGeorge Liu crow::utility::getTimestamp( 1536d139c236SGeorge Liu *millisTimeStamp); 1537cb92c03bSAndrew Geissler } 1538ebd45906SGeorge Liu } 1539cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1540cb92c03bSAndrew Geissler { 1541cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1542cb92c03bSAndrew Geissler &propertyMap.second); 1543cb92c03bSAndrew Geissler } 1544cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1545cb92c03bSAndrew Geissler { 1546cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1547cb92c03bSAndrew Geissler &propertyMap.second); 1548ae34c8e8SAdriana Kobylak } 154975710de2SXiaochao Ma else if (propertyMap.first == "Resolved") 155075710de2SXiaochao Ma { 155175710de2SXiaochao Ma bool* resolveptr = 155275710de2SXiaochao Ma std::get_if<bool>(&propertyMap.second); 155375710de2SXiaochao Ma if (resolveptr == nullptr) 155475710de2SXiaochao Ma { 155575710de2SXiaochao Ma messages::internalError(asyncResp->res); 155675710de2SXiaochao Ma return; 155775710de2SXiaochao Ma } 155875710de2SXiaochao Ma resolved = *resolveptr; 155975710de2SXiaochao Ma } 15607e860f15SJohn Edward Broadbent else if (propertyMap.first == "Path") 1561f86bb901SAdriana Kobylak { 1562f86bb901SAdriana Kobylak filePath = std::get_if<std::string>( 1563f86bb901SAdriana Kobylak &propertyMap.second); 1564f86bb901SAdriana Kobylak } 1565f86bb901SAdriana Kobylak } 1566f86bb901SAdriana Kobylak if (id == nullptr || message == nullptr || 1567f86bb901SAdriana Kobylak severity == nullptr) 1568f86bb901SAdriana Kobylak { 1569ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1570271584abSEd Tanous return; 1571271584abSEd Tanous } 1572f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 1573f86bb901SAdriana Kobylak "#LogEntry.v1_8_0.LogEntry"; 1574f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.id"] = 15757e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/" 15767e860f15SJohn Edward Broadbent "Entries/" + 1577f86bb901SAdriana Kobylak std::to_string(*id); 15787e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 15797e860f15SJohn Edward Broadbent "System Event Log Entry"; 1580f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1581f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1582f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 1583f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1584f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1585f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1586f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 1587f86bb901SAdriana Kobylak crow::utility::getDateTime(timestamp); 1588f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 1589f86bb901SAdriana Kobylak crow::utility::getDateTime(updateTimestamp); 1590f86bb901SAdriana Kobylak if (filePath != nullptr) 1591f86bb901SAdriana Kobylak { 1592f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 15937e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/" 15947e860f15SJohn Edward Broadbent "EventLog/" 15957e860f15SJohn Edward Broadbent "attachment/" + 15967e860f15SJohn Edward Broadbent std::to_string(*id); 1597f86bb901SAdriana Kobylak } 1598cb92c03bSAndrew Geissler }, 1599cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1600cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1601f86bb901SAdriana Kobylak "org.freedesktop.DBus.Properties", "GetAll", ""); 16027e860f15SJohn Edward Broadbent }); 1603336e96c6SChicago Duan 16047e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16057e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1606432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 16077e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 16087e860f15SJohn Edward Broadbent [](const crow::Request& req, 16097e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16107e860f15SJohn Edward Broadbent const std::string& entryId) { 161175710de2SXiaochao Ma std::optional<bool> resolved; 161275710de2SXiaochao Ma 16137e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "Resolved", 16147e860f15SJohn Edward Broadbent resolved)) 161575710de2SXiaochao Ma { 161675710de2SXiaochao Ma return; 161775710de2SXiaochao Ma } 161875710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 161975710de2SXiaochao Ma 162075710de2SXiaochao Ma crow::connections::systemBus->async_method_call( 162175710de2SXiaochao Ma [asyncResp, resolved, 162275710de2SXiaochao Ma entryId](const boost::system::error_code ec) { 162375710de2SXiaochao Ma if (ec) 162475710de2SXiaochao Ma { 162575710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 162675710de2SXiaochao Ma messages::internalError(asyncResp->res); 162775710de2SXiaochao Ma return; 162875710de2SXiaochao Ma } 162975710de2SXiaochao Ma }, 163075710de2SXiaochao Ma "xyz.openbmc_project.Logging", 163175710de2SXiaochao Ma "/xyz/openbmc_project/logging/entry/" + entryId, 163275710de2SXiaochao Ma "org.freedesktop.DBus.Properties", "Set", 163375710de2SXiaochao Ma "xyz.openbmc_project.Logging.Entry", "Resolved", 163475710de2SXiaochao Ma std::variant<bool>(*resolved)); 16357e860f15SJohn Edward Broadbent }); 163675710de2SXiaochao Ma 16377e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16387e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1639432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 16407e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 16417e860f15SJohn Edward Broadbent [](const crow::Request&, 16427e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16437e860f15SJohn Edward Broadbent const std::string& param) 16447e860f15SJohn Edward Broadbent 1645336e96c6SChicago Duan { 1646336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1647336e96c6SChicago Duan 16487e860f15SJohn Edward Broadbent std::string entryID = param; 1649336e96c6SChicago Duan 1650336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1651336e96c6SChicago Duan 1652336e96c6SChicago Duan // Process response from Logging service. 16537e860f15SJohn Edward Broadbent auto respHandler = [asyncResp, entryID]( 16547e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 16557e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 16567e860f15SJohn Edward Broadbent << "EventLogEntry (DBus) doDelete callback: Done"; 1657336e96c6SChicago Duan if (ec) 1658336e96c6SChicago Duan { 16593de8d8baSGeorge Liu if (ec.value() == EBADR) 16603de8d8baSGeorge Liu { 16617e860f15SJohn Edward Broadbent messages::resourceNotFound(asyncResp->res, 16627e860f15SJohn Edward Broadbent "LogEntry", entryID); 16633de8d8baSGeorge Liu return; 16643de8d8baSGeorge Liu } 1665336e96c6SChicago Duan // TODO Handle for specific error code 16667e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "EventLogEntry (DBus) doDelete " 16677e860f15SJohn Edward Broadbent "respHandler got error " 1668336e96c6SChicago Duan << ec; 1669336e96c6SChicago Duan asyncResp->res.result( 1670336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1671336e96c6SChicago Duan return; 1672336e96c6SChicago Duan } 1673336e96c6SChicago Duan 1674336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1675336e96c6SChicago Duan }; 1676336e96c6SChicago Duan 1677336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1678336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1679336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1680336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1681336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 16827e860f15SJohn Edward Broadbent }); 1683400fd1fbSAdriana Kobylak } 1684400fd1fbSAdriana Kobylak 16857e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1686400fd1fbSAdriana Kobylak { 16877e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" 16887e860f15SJohn Edward Broadbent "<str>/attachment") 1689432a890cSEd Tanous .privileges({{"Login"}}) 16907e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 16917e860f15SJohn Edward Broadbent [](const crow::Request& req, 16927e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16937e860f15SJohn Edward Broadbent const std::string& param) 1694400fd1fbSAdriana Kobylak 16957e860f15SJohn Edward Broadbent { 1696*af61db10SGeorge Liu if (!http_helpers::isOctetAccepted(req)) 1697400fd1fbSAdriana Kobylak { 16987e860f15SJohn Edward Broadbent asyncResp->res.result( 16997e860f15SJohn Edward Broadbent boost::beast::http::status::bad_request); 1700400fd1fbSAdriana Kobylak return; 1701400fd1fbSAdriana Kobylak } 1702400fd1fbSAdriana Kobylak 17037e860f15SJohn Edward Broadbent std::string entryID = param; 1704400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1705400fd1fbSAdriana Kobylak 1706400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 17077e860f15SJohn Edward Broadbent [asyncResp, 17087e860f15SJohn Edward Broadbent entryID](const boost::system::error_code ec, 1709400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 1710400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 1711400fd1fbSAdriana Kobylak { 17127e860f15SJohn Edward Broadbent messages::resourceNotFound( 17137e860f15SJohn Edward Broadbent asyncResp->res, "EventLogAttachment", entryID); 1714400fd1fbSAdriana Kobylak return; 1715400fd1fbSAdriana Kobylak } 1716400fd1fbSAdriana Kobylak if (ec) 1717400fd1fbSAdriana Kobylak { 1718400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1719400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1720400fd1fbSAdriana Kobylak return; 1721400fd1fbSAdriana Kobylak } 1722400fd1fbSAdriana Kobylak 1723400fd1fbSAdriana Kobylak int fd = -1; 1724400fd1fbSAdriana Kobylak fd = dup(unixfd); 1725400fd1fbSAdriana Kobylak if (fd == -1) 1726400fd1fbSAdriana Kobylak { 1727400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1728400fd1fbSAdriana Kobylak return; 1729400fd1fbSAdriana Kobylak } 1730400fd1fbSAdriana Kobylak 1731400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 1732400fd1fbSAdriana Kobylak if (size == -1) 1733400fd1fbSAdriana Kobylak { 1734400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1735400fd1fbSAdriana Kobylak return; 1736400fd1fbSAdriana Kobylak } 1737400fd1fbSAdriana Kobylak 1738400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 1739400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 1740400fd1fbSAdriana Kobylak if (size > maxFileSize) 1741400fd1fbSAdriana Kobylak { 1742400fd1fbSAdriana Kobylak BMCWEB_LOG_ERROR 1743400fd1fbSAdriana Kobylak << "File size exceeds maximum allowed size of " 1744400fd1fbSAdriana Kobylak << maxFileSize; 1745400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1746400fd1fbSAdriana Kobylak return; 1747400fd1fbSAdriana Kobylak } 1748400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 1749400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 1750400fd1fbSAdriana Kobylak if (rc == -1) 1751400fd1fbSAdriana Kobylak { 1752400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1753400fd1fbSAdriana Kobylak return; 1754400fd1fbSAdriana Kobylak } 1755400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 1756400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 1757400fd1fbSAdriana Kobylak { 1758400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1759400fd1fbSAdriana Kobylak return; 1760400fd1fbSAdriana Kobylak } 1761400fd1fbSAdriana Kobylak close(fd); 1762400fd1fbSAdriana Kobylak 1763400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 17647e860f15SJohn Edward Broadbent std::string output = 17657e860f15SJohn Edward Broadbent crow::utility::base64encode(strData); 1766400fd1fbSAdriana Kobylak 1767400fd1fbSAdriana Kobylak asyncResp->res.addHeader("Content-Type", 1768400fd1fbSAdriana Kobylak "application/octet-stream"); 17697e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Transfer-Encoding", 17707e860f15SJohn Edward Broadbent "Base64"); 1771400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 1772400fd1fbSAdriana Kobylak }, 1773400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 1774400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 1775400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 17767e860f15SJohn Edward Broadbent }); 17771da66f75SEd Tanous } 17781da66f75SEd Tanous 17797e860f15SJohn Edward Broadbent inline void requestRoutesBMCLogServiceCollection(App& app) 17801da66f75SEd Tanous { 17817e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 1782432a890cSEd Tanous .privileges({{"Login"}}) 17837e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 17847e860f15SJohn Edward Broadbent [](const crow::Request&, 17857e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 17867e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 17877e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1788e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 17891da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1790e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1791e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 17927e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 17937e860f15SJohn Edward Broadbent "Open BMC Log Services Collection"; 1794e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 17951da66f75SEd Tanous "Collection of LogServices for this Manager"; 17967e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 17977e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 1798c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 17995cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 18005cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 18017e860f15SJohn Edward Broadbent {{"@odata.id", 18027e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 18035cb1dd27SAsmitha Karunanithi #endif 1804c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1805c4bf6374SJason M. Bills logServiceArray.push_back( 18067e860f15SJohn Edward Broadbent {{"@odata.id", 18077e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1808c4bf6374SJason M. Bills #endif 1809e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1810c4bf6374SJason M. Bills logServiceArray.size(); 18117e860f15SJohn Edward Broadbent }); 1812e1f26343SJason M. Bills } 1813e1f26343SJason M. Bills 18147e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 1815e1f26343SJason M. Bills { 18167e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1817432a890cSEd Tanous .privileges({{"Login"}}) 18187e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 18197e860f15SJohn Edward Broadbent [](const crow::Request&, 18207e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 18218d1b46d7Szhanghch05 18227e860f15SJohn Edward Broadbent { 1823e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1824e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 18250f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 18260f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 18277e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 18287e860f15SJohn Edward Broadbent "Open BMC Journal Log Service"; 18297e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 18307e860f15SJohn Edward Broadbent "BMC Journal Log Service"; 1831c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1832e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1833cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1834cd50aa42SJason M. Bills {"@odata.id", 1835086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 18367e860f15SJohn Edward Broadbent }); 1837e1f26343SJason M. Bills } 1838e1f26343SJason M. Bills 1839c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 1840e1f26343SJason M. Bills sd_journal* journal, 1841c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 1842e1f26343SJason M. Bills { 1843e1f26343SJason M. Bills // Get the Log Entry contents 1844e1f26343SJason M. Bills int ret = 0; 1845e1f26343SJason M. Bills 1846a8fe54f0SJason M. Bills std::string message; 1847a8fe54f0SJason M. Bills std::string_view syslogID; 1848a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 1849a8fe54f0SJason M. Bills if (ret < 0) 1850a8fe54f0SJason M. Bills { 1851a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 1852a8fe54f0SJason M. Bills << strerror(-ret); 1853a8fe54f0SJason M. Bills } 1854a8fe54f0SJason M. Bills if (!syslogID.empty()) 1855a8fe54f0SJason M. Bills { 1856a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 1857a8fe54f0SJason M. Bills } 1858a8fe54f0SJason M. Bills 185939e77504SEd Tanous std::string_view msg; 186016428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1861e1f26343SJason M. Bills if (ret < 0) 1862e1f26343SJason M. Bills { 1863e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1864e1f26343SJason M. Bills return 1; 1865e1f26343SJason M. Bills } 1866a8fe54f0SJason M. Bills message += std::string(msg); 1867e1f26343SJason M. Bills 1868e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1869271584abSEd Tanous long int severity = 8; // Default to an invalid priority 187016428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1871e1f26343SJason M. Bills if (ret < 0) 1872e1f26343SJason M. Bills { 1873e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1874e1f26343SJason M. Bills } 1875e1f26343SJason M. Bills 1876e1f26343SJason M. Bills // Get the Created time from the timestamp 187716428a1aSJason M. Bills std::string entryTimeStr; 187816428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1879e1f26343SJason M. Bills { 188016428a1aSJason M. Bills return 1; 1881e1f26343SJason M. Bills } 1882e1f26343SJason M. Bills 1883e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1884c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 18850ef217f4SGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 1886c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1887c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1888e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1889c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 1890a8fe54f0SJason M. Bills {"Message", std::move(message)}, 1891e1f26343SJason M. Bills {"EntryType", "Oem"}, 1892738c1e61SPatrick Williams {"Severity", severity <= 2 ? "Critical" 1893738c1e61SPatrick Williams : severity <= 4 ? "Warning" 1894738c1e61SPatrick Williams : "OK"}, 1895086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1896e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1897e1f26343SJason M. Bills return 0; 1898e1f26343SJason M. Bills } 1899e1f26343SJason M. Bills 19007e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 1901e1f26343SJason M. Bills { 19027e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1903432a890cSEd Tanous .privileges({{"Login"}}) 19047e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 19057e860f15SJohn Edward Broadbent [](const crow::Request& req, 19067e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1907193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1908271584abSEd Tanous uint64_t skip = 0; 1909271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 19108d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 1911193ad2faSJason M. Bills { 1912193ad2faSJason M. Bills return; 1913193ad2faSJason M. Bills } 19148d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 1915193ad2faSJason M. Bills { 1916193ad2faSJason M. Bills return; 1917193ad2faSJason M. Bills } 19187e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 19197e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1920e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1921e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 19220f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 19230f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1924e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1925e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1926e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 19277e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 19287e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 1929e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1930e1f26343SJason M. Bills 19317e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 19327e860f15SJohn Edward Broadbent // unique ID for each entry 1933e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1934e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1935e1f26343SJason M. Bills if (ret < 0) 1936e1f26343SJason M. Bills { 19377e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 19387e860f15SJohn Edward Broadbent << strerror(-ret); 1939f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1940e1f26343SJason M. Bills return; 1941e1f26343SJason M. Bills } 19427e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 19437e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 1944e1f26343SJason M. Bills journalTmp = nullptr; 1945b01bf299SEd Tanous uint64_t entryCount = 0; 1946e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1947e85d6b16SJason M. Bills bool firstEntry = true; 1948e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1949e1f26343SJason M. Bills { 1950193ad2faSJason M. Bills entryCount++; 19517e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 19527e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 1953193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1954193ad2faSJason M. Bills { 1955193ad2faSJason M. Bills continue; 1956193ad2faSJason M. Bills } 1957193ad2faSJason M. Bills 195816428a1aSJason M. Bills std::string idStr; 1959e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1960e1f26343SJason M. Bills { 1961e1f26343SJason M. Bills continue; 1962e1f26343SJason M. Bills } 1963e1f26343SJason M. Bills 1964e85d6b16SJason M. Bills if (firstEntry) 1965e85d6b16SJason M. Bills { 1966e85d6b16SJason M. Bills firstEntry = false; 1967e85d6b16SJason M. Bills } 1968e85d6b16SJason M. Bills 1969e1f26343SJason M. Bills logEntryArray.push_back({}); 1970c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 1971c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 1972c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 1973e1f26343SJason M. Bills { 1974f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1975e1f26343SJason M. Bills return; 1976e1f26343SJason M. Bills } 1977e1f26343SJason M. Bills } 1978193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1979193ad2faSJason M. Bills if (skip + top < entryCount) 1980193ad2faSJason M. Bills { 1981193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 19827e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/" 19837e860f15SJohn Edward Broadbent "Entries?$skip=" + 1984193ad2faSJason M. Bills std::to_string(skip + top); 1985193ad2faSJason M. Bills } 19867e860f15SJohn Edward Broadbent }); 1987e1f26343SJason M. Bills } 1988e1f26343SJason M. Bills 19897e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 1990e1f26343SJason M. Bills { 19917e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 19927e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 1993432a890cSEd Tanous .privileges({{"Login"}}) 19947e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 19957e860f15SJohn Edward Broadbent [](const crow::Request&, 19967e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 19977e860f15SJohn Edward Broadbent const std::string& entryID) { 1998e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 1999e1f26343SJason M. Bills uint64_t ts = 0; 2000271584abSEd Tanous uint64_t index = 0; 20018d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2002e1f26343SJason M. Bills { 200316428a1aSJason M. Bills return; 2004e1f26343SJason M. Bills } 2005e1f26343SJason M. Bills 2006e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2007e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2008e1f26343SJason M. Bills if (ret < 0) 2009e1f26343SJason M. Bills { 20107e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 20117e860f15SJohn Edward Broadbent << strerror(-ret); 2012f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2013e1f26343SJason M. Bills return; 2014e1f26343SJason M. Bills } 20157e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 20167e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 2017e1f26343SJason M. Bills journalTmp = nullptr; 20187e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 20197e860f15SJohn Edward Broadbent // index tracking the unique ID 2020af07e3f5SJason M. Bills std::string idStr; 2021af07e3f5SJason M. Bills bool firstEntry = true; 2022e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 20232056b6d1SManojkiran Eda if (ret < 0) 20242056b6d1SManojkiran Eda { 20252056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 20262056b6d1SManojkiran Eda << strerror(-ret); 20272056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 20282056b6d1SManojkiran Eda return; 20292056b6d1SManojkiran Eda } 2030271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2031e1f26343SJason M. Bills { 2032e1f26343SJason M. Bills sd_journal_next(journal.get()); 2033af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2034af07e3f5SJason M. Bills { 2035af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2036af07e3f5SJason M. Bills return; 2037af07e3f5SJason M. Bills } 2038af07e3f5SJason M. Bills if (firstEntry) 2039af07e3f5SJason M. Bills { 2040af07e3f5SJason M. Bills firstEntry = false; 2041af07e3f5SJason M. Bills } 2042e1f26343SJason M. Bills } 2043c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2044af07e3f5SJason M. Bills if (idStr != entryID) 2045c4bf6374SJason M. Bills { 2046c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 2047c4bf6374SJason M. Bills return; 2048c4bf6374SJason M. Bills } 2049c4bf6374SJason M. Bills 2050c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 2051e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 2052e1f26343SJason M. Bills { 2053f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2054e1f26343SJason M. Bills return; 2055e1f26343SJason M. Bills } 20567e860f15SJohn Edward Broadbent }); 2057c9bb6861Sraviteja-b } 2058c9bb6861Sraviteja-b 20597e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpService(App& app) 2060c9bb6861Sraviteja-b { 20617e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2062432a890cSEd Tanous .privileges({{"Login"}}) 20637e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 20647e860f15SJohn Edward Broadbent [](const crow::Request&, 20657e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2066c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 20675cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 2068c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2069d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 2070c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 20715cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 20725cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2073c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2074c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 20757e860f15SJohn Edward Broadbent {"@odata.id", 20767e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}}; 20775cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 20785cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 20795cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 20805cb1dd27SAsmitha Karunanithi "Actions/LogService.ClearLog"}}}, 2081d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 2082d337bb72SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 2083d337bb72SAsmitha Karunanithi "Actions/LogService.CollectDiagnosticData"}}}}; 20847e860f15SJohn Edward Broadbent }); 2085c9bb6861Sraviteja-b } 2086c9bb6861Sraviteja-b 20877e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntryCollection(App& app) 20887e860f15SJohn Edward Broadbent { 20897e860f15SJohn Edward Broadbent 2090c9bb6861Sraviteja-b /** 2091c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2092c9bb6861Sraviteja-b */ 20937e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2094432a890cSEd Tanous .privileges({{"Login"}}) 20957e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 20967e860f15SJohn Edward Broadbent [](const crow::Request&, 20977e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2098c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2099c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2100c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 21015cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 21025cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2103c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 21045cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2105c9bb6861Sraviteja-b 21065cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 21077e860f15SJohn Edward Broadbent }); 2108c9bb6861Sraviteja-b } 2109c9bb6861Sraviteja-b 21107e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2111c9bb6861Sraviteja-b { 21127e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 21137e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2114432a890cSEd Tanous .privileges({{"Login"}}) 21157e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 21167e860f15SJohn Edward Broadbent [](const crow::Request&, 21177e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 21187e860f15SJohn Edward Broadbent const std::string& param) { 21197e860f15SJohn Edward Broadbent getDumpEntryById(asyncResp, param, "BMC"); 21207e860f15SJohn Edward Broadbent }); 21217e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 21227e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2123432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 21247e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 21257e860f15SJohn Edward Broadbent [](const crow::Request&, 21267e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 21277e860f15SJohn Edward Broadbent const std::string& param) { 21287e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "bmc"); 21297e860f15SJohn Edward Broadbent }); 2130c9bb6861Sraviteja-b } 2131c9bb6861Sraviteja-b 21327e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2133c9bb6861Sraviteja-b { 21348d1b46d7Szhanghch05 21357e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 2136d337bb72SAsmitha Karunanithi "Actions/" 2137d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2138432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 21397e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 21407e860f15SJohn Edward Broadbent [](const crow::Request& req, 21417e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 21428d1b46d7Szhanghch05 createDump(asyncResp, req, "BMC"); 21437e860f15SJohn Edward Broadbent }); 2144a43be80fSAsmitha Karunanithi } 2145a43be80fSAsmitha Karunanithi 21467e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 214780319af1SAsmitha Karunanithi { 21487e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/" 214980319af1SAsmitha Karunanithi "Actions/" 215080319af1SAsmitha Karunanithi "LogService.ClearLog/") 2151432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 21527e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 21537e860f15SJohn Edward Broadbent [](const crow::Request&, 21547e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 21558d1b46d7Szhanghch05 clearDump(asyncResp, "BMC"); 21567e860f15SJohn Edward Broadbent }); 21575cb1dd27SAsmitha Karunanithi } 21585cb1dd27SAsmitha Karunanithi 21597e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 21605cb1dd27SAsmitha Karunanithi { 21617e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/") 2162432a890cSEd Tanous .privileges({{"Login"}}) 21637e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 21647e860f15SJohn Edward Broadbent [](const crow::Request&, 21657e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 21665cb1dd27SAsmitha Karunanithi 21677e860f15SJohn Edward Broadbent { 21685cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 21695cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 21705cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2171d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 21725cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 21737e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 21747e860f15SJohn Edward Broadbent "System Dump LogService"; 21755cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 21765cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 21775cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Entries"] = { 21785cb1dd27SAsmitha Karunanithi {"@odata.id", 21795cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"}}; 21805cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 21815cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 21827e860f15SJohn Edward Broadbent {{"target", 21837e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 21845cb1dd27SAsmitha Karunanithi "LogService.ClearLog"}}}, 2185d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 21867e860f15SJohn Edward Broadbent {{"target", 21877e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 2188d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData"}}}}; 21897e860f15SJohn Edward Broadbent }); 21905cb1dd27SAsmitha Karunanithi } 21915cb1dd27SAsmitha Karunanithi 21927e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 21937e860f15SJohn Edward Broadbent { 21947e860f15SJohn Edward Broadbent 21955cb1dd27SAsmitha Karunanithi /** 21965cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 21975cb1dd27SAsmitha Karunanithi */ 2198f9a6708cSCharles Boyer BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 2199432a890cSEd Tanous .privileges({{"Login"}}) 22007e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22017e860f15SJohn Edward Broadbent [](const crow::Request&, 2202864d6a17SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22035cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 22045cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 22055cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 22065cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 22075cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 22085cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 22095cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 22105cb1dd27SAsmitha Karunanithi 22115cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 22127e860f15SJohn Edward Broadbent }); 22135cb1dd27SAsmitha Karunanithi } 22145cb1dd27SAsmitha Karunanithi 22157e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 22165cb1dd27SAsmitha Karunanithi { 22177e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2218864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2219432a890cSEd Tanous .privileges({{"Login"}}) 22207e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22217e860f15SJohn Edward Broadbent [](const crow::Request&, 22227e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22237e860f15SJohn Edward Broadbent const std::string& param) { 22247e860f15SJohn Edward Broadbent getDumpEntryById(asyncResp, param, "System"); 22257e860f15SJohn Edward Broadbent }); 22268d1b46d7Szhanghch05 22277e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2228864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2229432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 22307e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 22317e860f15SJohn Edward Broadbent [](const crow::Request&, 22327e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22337e860f15SJohn Edward Broadbent const std::string& param) { 22347e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "system"); 22357e860f15SJohn Edward Broadbent }); 22365cb1dd27SAsmitha Karunanithi } 2237c9bb6861Sraviteja-b 22387e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2239c9bb6861Sraviteja-b { 22407e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2241d337bb72SAsmitha Karunanithi "Actions/" 2242d337bb72SAsmitha Karunanithi "LogService.CollectDiagnosticData/") 2243432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 22447e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 22457e860f15SJohn Edward Broadbent [](const crow::Request& req, 22467e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 22477e860f15SJohn Edward Broadbent 22487e860f15SJohn Edward Broadbent { createDump(asyncResp, req, "System"); }); 2249a43be80fSAsmitha Karunanithi } 2250a43be80fSAsmitha Karunanithi 22517e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2252a43be80fSAsmitha Karunanithi { 22537e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/" 2254013487e5Sraviteja-b "Actions/" 2255013487e5Sraviteja-b "LogService.ClearLog/") 2256432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 22577e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 22587e860f15SJohn Edward Broadbent [](const crow::Request&, 22597e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 22607e860f15SJohn Edward Broadbent 22617e860f15SJohn Edward Broadbent { clearDump(asyncResp, "System"); }); 2262013487e5Sraviteja-b } 2263013487e5Sraviteja-b 22647e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 22651da66f75SEd Tanous { 22663946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 22673946028dSAppaRao Puli // method for security reasons. 22681da66f75SEd Tanous /** 22691da66f75SEd Tanous * Functions triggers appropriate requests on DBus 22701da66f75SEd Tanous */ 22717e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 2272432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 22737e860f15SJohn Edward Broadbent .methods( 22747e860f15SJohn Edward Broadbent boost::beast::http::verb:: 22757e860f15SJohn Edward Broadbent get)([](const crow::Request&, 22767e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22777e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 22787e860f15SJohn Edward Broadbent // SubRoute 22790f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2280424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2281e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 22828e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 22834f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 22844f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 22854f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2286e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2287e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 2288cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2289cd50aa42SJason M. Bills {"@odata.id", 2290424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 2291e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 22925b61b5e8SJason M. Bills {"#LogService.ClearLog", 22935b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 22945b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 22958e6c099aSJason M. Bills {"#LogService.CollectDiagnosticData", 2296424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 22978e6c099aSJason M. Bills "Actions/LogService.CollectDiagnosticData"}}}}; 22987e860f15SJohn Edward Broadbent }); 22991da66f75SEd Tanous } 23001da66f75SEd Tanous 23017e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 23025b61b5e8SJason M. Bills { 23037e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 23047e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 23055b61b5e8SJason M. Bills "LogService.ClearLog/") 2306432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 23077e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 23087e860f15SJohn Edward Broadbent [](const crow::Request&, 23097e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 23105b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 23115b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2312cb13a392SEd Tanous const std::string&) { 23135b61b5e8SJason M. Bills if (ec) 23145b61b5e8SJason M. Bills { 23155b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 23165b61b5e8SJason M. Bills return; 23175b61b5e8SJason M. Bills } 23185b61b5e8SJason M. Bills messages::success(asyncResp->res); 23195b61b5e8SJason M. Bills }, 23207e860f15SJohn Edward Broadbent crashdumpObject, crashdumpPath, deleteAllInterface, 23217e860f15SJohn Edward Broadbent "DeleteAll"); 23227e860f15SJohn Edward Broadbent }); 23235b61b5e8SJason M. Bills } 23245b61b5e8SJason M. Bills 23258d1b46d7Szhanghch05 static void 23268d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 23278d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 2328e855dd28SJason M. Bills { 2329043a0536SJohnathan Mantey auto getStoredLogCallback = 2330043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 2331e855dd28SJason M. Bills const boost::system::error_code ec, 2332043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params) { 2333e855dd28SJason M. Bills if (ec) 2334e855dd28SJason M. Bills { 2335e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 23361ddcf01aSJason M. Bills if (ec.value() == 23371ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 23381ddcf01aSJason M. Bills { 2339043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2340043a0536SJohnathan Mantey logID); 23411ddcf01aSJason M. Bills } 23421ddcf01aSJason M. Bills else 23431ddcf01aSJason M. Bills { 2344e855dd28SJason M. Bills messages::internalError(asyncResp->res); 23451ddcf01aSJason M. Bills } 2346e855dd28SJason M. Bills return; 2347e855dd28SJason M. Bills } 2348043a0536SJohnathan Mantey 2349043a0536SJohnathan Mantey std::string timestamp{}; 2350043a0536SJohnathan Mantey std::string filename{}; 2351043a0536SJohnathan Mantey std::string logfile{}; 23522c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2353043a0536SJohnathan Mantey 2354043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2355e855dd28SJason M. Bills { 2356043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 2357e855dd28SJason M. Bills return; 2358e855dd28SJason M. Bills } 2359e855dd28SJason M. Bills 2360043a0536SJohnathan Mantey std::string crashdumpURI = 2361e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2362043a0536SJohnathan Mantey logID + "/" + filename; 23630ef217f4SGeorge Liu logEntryJson = {{"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 2364043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 2365043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 2366e855dd28SJason M. Bills logID}, 2367e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2368e855dd28SJason M. Bills {"Id", logID}, 2369e855dd28SJason M. Bills {"EntryType", "Oem"}, 23708e6c099aSJason M. Bills {"AdditionalDataURI", std::move(crashdumpURI)}, 23718e6c099aSJason M. Bills {"DiagnosticDataType", "OEM"}, 23728e6c099aSJason M. Bills {"OEMDiagnosticDataType", "PECICrashdump"}, 2373043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2374e855dd28SJason M. Bills }; 2375e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 23765b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 23775b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2378043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2379e855dd28SJason M. Bills } 2380e855dd28SJason M. Bills 23817e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 23821da66f75SEd Tanous { 23833946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 23843946028dSAppaRao Puli // method for security reasons. 23851da66f75SEd Tanous /** 23861da66f75SEd Tanous * Functions triggers appropriate requests on DBus 23871da66f75SEd Tanous */ 23887e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 23897e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 2390432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 23917e860f15SJohn Edward Broadbent .methods( 23927e860f15SJohn Edward Broadbent boost::beast::http::verb:: 23937e860f15SJohn Edward Broadbent get)([](const crow::Request&, 23947e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 23957e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 23967e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2397e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2398e1f26343SJason M. Bills const boost::system::error_code ec, 23997e860f15SJohn Edward Broadbent const std::vector<std::string>& 24007e860f15SJohn Edward Broadbent resp) { 24011da66f75SEd Tanous if (ec) 24021da66f75SEd Tanous { 24031da66f75SEd Tanous if (ec.value() != 24041da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 24051da66f75SEd Tanous { 24061da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 24071da66f75SEd Tanous << ec.message(); 2408f12894f8SJason M. Bills messages::internalError(asyncResp->res); 24091da66f75SEd Tanous return; 24101da66f75SEd Tanous } 24111da66f75SEd Tanous } 2412e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 24131da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 24140f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2415424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2416424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2417e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2418424c4176SJason M. Bills "Collection of Crashdump Entries"; 24197e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 24207e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 2421e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2422e855dd28SJason M. Bills std::vector<std::string> logIDs; 2423e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2424e855dd28SJason M. Bills // enough to hold them 24251da66f75SEd Tanous for (const std::string& objpath : resp) 24261da66f75SEd Tanous { 2427e855dd28SJason M. Bills // Get the log ID 2428f23b7296SEd Tanous std::size_t lastPos = objpath.rfind('/'); 2429e855dd28SJason M. Bills if (lastPos == std::string::npos) 24301da66f75SEd Tanous { 2431e855dd28SJason M. Bills continue; 24321da66f75SEd Tanous } 2433e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2434e855dd28SJason M. Bills 2435e855dd28SJason M. Bills // Add a space for the log entry to the array 2436e855dd28SJason M. Bills logEntryArray.push_back({}); 2437e855dd28SJason M. Bills } 2438e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2439e855dd28SJason M. Bills size_t index = 0; 2440e855dd28SJason M. Bills for (const std::string& logID : logIDs) 2441e855dd28SJason M. Bills { 2442e855dd28SJason M. Bills // Add the log entry to the array 2443e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 24441da66f75SEd Tanous } 2445e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2446e1f26343SJason M. Bills logEntryArray.size(); 24471da66f75SEd Tanous }; 24481da66f75SEd Tanous crow::connections::systemBus->async_method_call( 24491da66f75SEd Tanous std::move(getLogEntriesCallback), 24501da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 24511da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 24521da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 24535b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 24547e860f15SJohn Edward Broadbent }); 24551da66f75SEd Tanous } 24561da66f75SEd Tanous 24577e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 24581da66f75SEd Tanous { 24593946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24603946028dSAppaRao Puli // method for security reasons. 24611da66f75SEd Tanous 24627e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 24637e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/") 2464432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 24657e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24667e860f15SJohn Edward Broadbent [](const crow::Request&, 24677e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24687e860f15SJohn Edward Broadbent const std::string& param) { 24697e860f15SJohn Edward Broadbent const std::string& logID = param; 2470e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 24717e860f15SJohn Edward Broadbent }); 2472e855dd28SJason M. Bills } 2473e855dd28SJason M. Bills 24747e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 2475e855dd28SJason M. Bills { 24763946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24773946028dSAppaRao Puli // method for security reasons. 24787e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 24797e860f15SJohn Edward Broadbent app, 24807e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/") 2481432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 24827e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24837e860f15SJohn Edward Broadbent [](const crow::Request&, 24847e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24857e860f15SJohn Edward Broadbent const std::string& logID, const std::string& fileName) { 2486043a0536SJohnathan Mantey auto getStoredLogCallback = 2487043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 2488abf2add6SEd Tanous const boost::system::error_code ec, 24897e860f15SJohn Edward Broadbent const std::vector<std::pair<std::string, VariantType>>& 24907e860f15SJohn Edward Broadbent resp) { 24911da66f75SEd Tanous if (ec) 24921da66f75SEd Tanous { 2493043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2494043a0536SJohnathan Mantey << ec.message(); 2495f12894f8SJason M. Bills messages::internalError(asyncResp->res); 24961da66f75SEd Tanous return; 24971da66f75SEd Tanous } 2498e855dd28SJason M. Bills 2499043a0536SJohnathan Mantey std::string dbusFilename{}; 2500043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2501043a0536SJohnathan Mantey std::string dbusFilepath{}; 2502043a0536SJohnathan Mantey 25037e860f15SJohn Edward Broadbent parseCrashdumpParameters(resp, dbusFilename, 25047e860f15SJohn Edward Broadbent dbusTimestamp, dbusFilepath); 2505043a0536SJohnathan Mantey 2506043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2507043a0536SJohnathan Mantey dbusFilepath.empty()) 25081da66f75SEd Tanous { 25097e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 25107e860f15SJohn Edward Broadbent fileName); 25111da66f75SEd Tanous return; 25121da66f75SEd Tanous } 2513e855dd28SJason M. Bills 2514043a0536SJohnathan Mantey // Verify the file name parameter is correct 2515043a0536SJohnathan Mantey if (fileName != dbusFilename) 2516043a0536SJohnathan Mantey { 25177e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 25187e860f15SJohn Edward Broadbent fileName); 2519043a0536SJohnathan Mantey return; 2520043a0536SJohnathan Mantey } 2521043a0536SJohnathan Mantey 2522043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2523043a0536SJohnathan Mantey { 25247e860f15SJohn Edward Broadbent messages::resourceMissingAtURI(asyncResp->res, 25257e860f15SJohn Edward Broadbent fileName); 2526043a0536SJohnathan Mantey return; 2527043a0536SJohnathan Mantey } 2528043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 2529043a0536SJohnathan Mantey std::ios::binary | 2530043a0536SJohnathan Mantey std::ios::ate); 2531043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 2532043a0536SJohnathan Mantey if (fileSize < 0) 2533043a0536SJohnathan Mantey { 2534043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 2535043a0536SJohnathan Mantey return; 2536043a0536SJohnathan Mantey } 2537043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 2538043a0536SJohnathan Mantey 2539043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 2540043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 2541043a0536SJohnathan Mantey 2542043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 2543043a0536SJohnathan Mantey 25447e860f15SJohn Edward Broadbent // The cast to std::string is intentional in order to 25457e860f15SJohn Edward Broadbent // use the assign() that applies move mechanics 2546043a0536SJohnathan Mantey asyncResp->res.body().assign( 2547043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 2548043a0536SJohnathan Mantey 25497e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 25507e860f15SJohn Edward Broadbent // from a browser 25517e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Disposition", 25527e860f15SJohn Edward Broadbent "attachment"); 25531da66f75SEd Tanous }; 25541da66f75SEd Tanous crow::connections::systemBus->async_method_call( 25555b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 25565b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 25577e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 25587e860f15SJohn Edward Broadbent crashdumpInterface); 25597e860f15SJohn Edward Broadbent }); 25601da66f75SEd Tanous } 25611da66f75SEd Tanous 25627e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 25631da66f75SEd Tanous { 25643946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25653946028dSAppaRao Puli // method for security reasons. 25667e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/" 25677e860f15SJohn Edward Broadbent "Actions/LogService.CollectDiagnosticData/") 2568432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 25697e860f15SJohn Edward Broadbent .methods( 25707e860f15SJohn Edward Broadbent boost::beast::http::verb:: 25717e860f15SJohn Edward Broadbent post)([](const crow::Request& req, 25727e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 25738e6c099aSJason M. Bills std::string diagnosticDataType; 25748e6c099aSJason M. Bills std::string oemDiagnosticDataType; 25758e6c099aSJason M. Bills if (!redfish::json_util::readJson( 25767e860f15SJohn Edward Broadbent req, asyncResp->res, "DiagnosticDataType", 25777e860f15SJohn Edward Broadbent diagnosticDataType, "OEMDiagnosticDataType", 25787e860f15SJohn Edward Broadbent oemDiagnosticDataType)) 25798e6c099aSJason M. Bills { 25808e6c099aSJason M. Bills return; 25818e6c099aSJason M. Bills } 25828e6c099aSJason M. Bills 25838e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 25848e6c099aSJason M. Bills { 25858e6c099aSJason M. Bills BMCWEB_LOG_ERROR 25868e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 25878e6c099aSJason M. Bills messages::actionParameterValueFormatError( 25888e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 25898e6c099aSJason M. Bills "CollectDiagnosticData"); 25908e6c099aSJason M. Bills return; 25918e6c099aSJason M. Bills } 25928e6c099aSJason M. Bills 25938e6c099aSJason M. Bills auto collectCrashdumpCallback = [asyncResp, req]( 25947e860f15SJohn Edward Broadbent const boost::system::error_code 25957e860f15SJohn Edward Broadbent ec, 2596cb13a392SEd Tanous const std::string&) { 25971da66f75SEd Tanous if (ec) 25981da66f75SEd Tanous { 25997e860f15SJohn Edward Broadbent if (ec.value() == 26007e860f15SJohn Edward Broadbent boost::system::errc::operation_not_supported) 26011da66f75SEd Tanous { 2602f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 26031da66f75SEd Tanous } 26044363d3b2SJason M. Bills else if (ec.value() == 26054363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 26064363d3b2SJason M. Bills { 26074363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 26084363d3b2SJason M. Bills "60"); 26094363d3b2SJason M. Bills } 26101da66f75SEd Tanous else 26111da66f75SEd Tanous { 2612f12894f8SJason M. Bills messages::internalError(asyncResp->res); 26131da66f75SEd Tanous } 26141da66f75SEd Tanous return; 26151da66f75SEd Tanous } 26167e860f15SJohn Edward Broadbent std::shared_ptr<task::TaskData> task = 26177e860f15SJohn Edward Broadbent task::TaskData::createTask( 26187e860f15SJohn Edward Broadbent [](boost::system::error_code err, 26197e860f15SJohn Edward Broadbent sdbusplus::message::message&, 262066afe4faSJames Feist const std::shared_ptr<task::TaskData>& taskData) { 262166afe4faSJames Feist if (!err) 262266afe4faSJames Feist { 2623e5d5006bSJames Feist taskData->messages.emplace_back( 2624e5d5006bSJames Feist messages::taskCompletedOK( 2625e5d5006bSJames Feist std::to_string(taskData->index))); 2626831d6b09SJames Feist taskData->state = "Completed"; 262766afe4faSJames Feist } 262832898ceaSJames Feist return task::completed; 262966afe4faSJames Feist }, 26307e860f15SJohn Edward Broadbent "type='signal',interface='org.freedesktop.DBus." 26317e860f15SJohn Edward Broadbent "Properties'," 263246229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 263346229577SJames Feist "crashdump'"); 263446229577SJames Feist task->startTimer(std::chrono::minutes(5)); 263546229577SJames Feist task->populateResp(asyncResp->res); 2636fe306728SJames Feist task->payload.emplace(req); 26371da66f75SEd Tanous }; 26388e6c099aSJason M. Bills 26398e6c099aSJason M. Bills if (oemDiagnosticDataType == "OnDemand") 26408e6c099aSJason M. Bills { 26411da66f75SEd Tanous crow::connections::systemBus->async_method_call( 26428e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 26438e6c099aSJason M. Bills crashdumpPath, crashdumpOnDemandInterface, 26448e6c099aSJason M. Bills "GenerateOnDemandLog"); 26451da66f75SEd Tanous } 26468e6c099aSJason M. Bills else if (oemDiagnosticDataType == "Telemetry") 26476eda7685SKenny L. Ku { 26488e6c099aSJason M. Bills crow::connections::systemBus->async_method_call( 26498e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 26508e6c099aSJason M. Bills crashdumpPath, crashdumpTelemetryInterface, 26518e6c099aSJason M. Bills "GenerateTelemetryLog"); 26526eda7685SKenny L. Ku } 26536eda7685SKenny L. Ku else 26546eda7685SKenny L. Ku { 26558e6c099aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 26568e6c099aSJason M. Bills << oemDiagnosticDataType; 26578e6c099aSJason M. Bills messages::actionParameterValueFormatError( 26587e860f15SJohn Edward Broadbent asyncResp->res, oemDiagnosticDataType, 26597e860f15SJohn Edward Broadbent "OEMDiagnosticDataType", "CollectDiagnosticData"); 26606eda7685SKenny L. Ku return; 26616eda7685SKenny L. Ku } 26627e860f15SJohn Edward Broadbent }); 26636eda7685SKenny L. Ku } 26646eda7685SKenny L. Ku 2665cb92c03bSAndrew Geissler /** 2666cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2667cb92c03bSAndrew Geissler */ 26687e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 2669cb92c03bSAndrew Geissler { 2670cb92c03bSAndrew Geissler /** 2671cb92c03bSAndrew Geissler * Function handles POST method request. 2672cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 2673cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 2674cb92c03bSAndrew Geissler */ 26757e860f15SJohn Edward Broadbent 26767e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 26777e860f15SJohn Edward Broadbent "LogService.ClearLog/") 2678432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 26797e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 26807e860f15SJohn Edward Broadbent [](const crow::Request&, 26817e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2682cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 2683cb92c03bSAndrew Geissler 2684cb92c03bSAndrew Geissler // Process response from Logging service. 26857e860f15SJohn Edward Broadbent auto respHandler = [asyncResp]( 26867e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 26877e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 26887e860f15SJohn Edward Broadbent << "doClearLog resp_handler callback: Done"; 2689cb92c03bSAndrew Geissler if (ec) 2690cb92c03bSAndrew Geissler { 2691cb92c03bSAndrew Geissler // TODO Handle for specific error code 26927e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " 26937e860f15SJohn Edward Broadbent << ec; 2694cb92c03bSAndrew Geissler asyncResp->res.result( 2695cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 2696cb92c03bSAndrew Geissler return; 2697cb92c03bSAndrew Geissler } 2698cb92c03bSAndrew Geissler 26997e860f15SJohn Edward Broadbent asyncResp->res.result( 27007e860f15SJohn Edward Broadbent boost::beast::http::status::no_content); 2701cb92c03bSAndrew Geissler }; 2702cb92c03bSAndrew Geissler 2703cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 2704cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 27052c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 2706cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 2707cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 27087e860f15SJohn Edward Broadbent }); 2709cb92c03bSAndrew Geissler } 2710a3316fc6SZhikuiRen 2711a3316fc6SZhikuiRen /**************************************************** 2712a3316fc6SZhikuiRen * Redfish PostCode interfaces 2713a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 2714a3316fc6SZhikuiRen ******************************************************/ 27157e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 2716a3316fc6SZhikuiRen { 27177e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 2718432a890cSEd Tanous .privileges({{"Login"}}) 27197e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 27207e860f15SJohn Edward Broadbent [](const crow::Request&, 27217e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2722a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 27237e860f15SJohn Edward Broadbent {"@odata.id", 27247e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes"}, 2725a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 2726a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 2727a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 2728a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 2729a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 2730a3316fc6SZhikuiRen {"Entries", 27317e860f15SJohn Edward Broadbent {{"@odata.id", "/redfish/v1/Systems/system/LogServices/" 27327e860f15SJohn Edward Broadbent "PostCodes/Entries"}}}}; 2733a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 27347e860f15SJohn Edward Broadbent {"target", 27357e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/" 2736a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 27377e860f15SJohn Edward Broadbent }); 2738a3316fc6SZhikuiRen } 2739a3316fc6SZhikuiRen 27407e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 2741a3316fc6SZhikuiRen { 27427e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 27437e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 2744a3316fc6SZhikuiRen "LogService.ClearLog/") 2745432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 27467e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 27477e860f15SJohn Edward Broadbent [](const crow::Request&, 27487e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2749a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 2750a3316fc6SZhikuiRen 2751a3316fc6SZhikuiRen // Make call to post-code service to request clear all 2752a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2753a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 2754a3316fc6SZhikuiRen if (ec) 2755a3316fc6SZhikuiRen { 2756a3316fc6SZhikuiRen // TODO Handle for specific error code 2757a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 27587e860f15SJohn Edward Broadbent << "doClearPostCodes resp_handler got error " 27597e860f15SJohn Edward Broadbent << ec; 27607e860f15SJohn Edward Broadbent asyncResp->res.result(boost::beast::http::status:: 27617e860f15SJohn Edward Broadbent internal_server_error); 2762a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 2763a3316fc6SZhikuiRen return; 2764a3316fc6SZhikuiRen } 2765a3316fc6SZhikuiRen }, 276615124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 276715124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 2768a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 27697e860f15SJohn Edward Broadbent }); 2770a3316fc6SZhikuiRen } 2771a3316fc6SZhikuiRen 2772a3316fc6SZhikuiRen static void fillPostCodeEntry( 27738d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 27746c9a279eSManojkiran Eda const boost::container::flat_map< 27756c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 2776a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 2777a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 2778a3316fc6SZhikuiRen { 2779a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 2780a3316fc6SZhikuiRen const message_registries::Message* message = 27814a0bf539SManojkiran Eda message_registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 2782a3316fc6SZhikuiRen 2783a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 2784a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 2785a3316fc6SZhikuiRen 2786a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 27876c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 27886c9a279eSManojkiran Eda code : postcode) 2789a3316fc6SZhikuiRen { 2790a3316fc6SZhikuiRen currentCodeIndex++; 2791a3316fc6SZhikuiRen std::string postcodeEntryID = 2792a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 2793a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 2794a3316fc6SZhikuiRen 2795a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 2796a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 2797a3316fc6SZhikuiRen 2798a3316fc6SZhikuiRen if (1 == currentCodeIndex) 2799a3316fc6SZhikuiRen { // already incremented 2800a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 2801a3316fc6SZhikuiRen } 2802a3316fc6SZhikuiRen else 2803a3316fc6SZhikuiRen { 2804a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 2805a3316fc6SZhikuiRen } 2806a3316fc6SZhikuiRen 2807a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 2808a3316fc6SZhikuiRen // not fall between top and skip 2809a3316fc6SZhikuiRen if ((codeIndex == 0) && 2810a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 2811a3316fc6SZhikuiRen { 2812a3316fc6SZhikuiRen continue; 2813a3316fc6SZhikuiRen } 2814a3316fc6SZhikuiRen 28154e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 2816a3316fc6SZhikuiRen // currentIndex 2817a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 2818a3316fc6SZhikuiRen { 2819a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 2820a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 2821a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 2822a3316fc6SZhikuiRen continue; 2823a3316fc6SZhikuiRen } 2824a3316fc6SZhikuiRen 2825a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 2826a3316fc6SZhikuiRen // index 2827a3316fc6SZhikuiRen 2828a3316fc6SZhikuiRen // Get the Created time from the timestamp 2829a3316fc6SZhikuiRen std::string entryTimeStr; 28309c620e21SAsmitha Karunanithi entryTimeStr = crow::utility::getDateTime( 28319c620e21SAsmitha Karunanithi static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000)); 2832a3316fc6SZhikuiRen 2833a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 2834a3316fc6SZhikuiRen std::ostringstream hexCode; 2835a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 28366c9a279eSManojkiran Eda << std::get<0>(code.second); 2837a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 2838a3316fc6SZhikuiRen // Set Fixed -Point Notation 2839a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 2840a3316fc6SZhikuiRen // Set precision to 4 digits 2841a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 2842a3316fc6SZhikuiRen // Add double to stream 2843a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 2844a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 2845a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 2846a3316fc6SZhikuiRen 2847a3316fc6SZhikuiRen // Get MessageArgs template from message registry 2848a3316fc6SZhikuiRen std::string msg; 2849a3316fc6SZhikuiRen if (message != nullptr) 2850a3316fc6SZhikuiRen { 2851a3316fc6SZhikuiRen msg = message->message; 2852a3316fc6SZhikuiRen 2853a3316fc6SZhikuiRen // fill in this post code value 2854a3316fc6SZhikuiRen int i = 0; 2855a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 2856a3316fc6SZhikuiRen { 2857a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 2858a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 2859a3316fc6SZhikuiRen if (argPos != std::string::npos) 2860a3316fc6SZhikuiRen { 2861a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 2862a3316fc6SZhikuiRen } 2863a3316fc6SZhikuiRen } 2864a3316fc6SZhikuiRen } 2865a3316fc6SZhikuiRen 2866d4342a92STim Lee // Get Severity template from message registry 2867d4342a92STim Lee std::string severity; 2868d4342a92STim Lee if (message != nullptr) 2869d4342a92STim Lee { 2870d4342a92STim Lee severity = message->severity; 2871d4342a92STim Lee } 2872d4342a92STim Lee 2873a3316fc6SZhikuiRen // add to AsyncResp 2874a3316fc6SZhikuiRen logEntryArray.push_back({}); 2875a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 28760ef217f4SGeorge Liu bmcLogEntry = {{"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 2877a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 2878a3316fc6SZhikuiRen "PostCodes/Entries/" + 2879a3316fc6SZhikuiRen postcodeEntryID}, 2880a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 2881a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 2882a3316fc6SZhikuiRen {"Message", std::move(msg)}, 28834a0bf539SManojkiran Eda {"MessageId", "OpenBMC.0.2.BIOSPOSTCode"}, 2884a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 2885a3316fc6SZhikuiRen {"EntryType", "Event"}, 2886a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 28879c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 28880ef217f4SGeorge Liu 28890ef217f4SGeorge Liu if (std::get<std::vector<uint8_t>>(code.second).size()) 28900ef217f4SGeorge Liu { 28910ef217f4SGeorge Liu bmcLogEntry["AdditionalDataURI"] = 28920ef217f4SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 28930ef217f4SGeorge Liu postcodeEntryID + "/attachment"; 28940ef217f4SGeorge Liu } 2895a3316fc6SZhikuiRen } 2896a3316fc6SZhikuiRen } 2897a3316fc6SZhikuiRen 28988d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2899a3316fc6SZhikuiRen const uint16_t bootIndex, 2900a3316fc6SZhikuiRen const uint64_t codeIndex) 2901a3316fc6SZhikuiRen { 2902a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 29036c9a279eSManojkiran Eda [aResp, bootIndex, 29046c9a279eSManojkiran Eda codeIndex](const boost::system::error_code ec, 29056c9a279eSManojkiran Eda const boost::container::flat_map< 29066c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 29076c9a279eSManojkiran Eda postcode) { 2908a3316fc6SZhikuiRen if (ec) 2909a3316fc6SZhikuiRen { 2910a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 2911a3316fc6SZhikuiRen messages::internalError(aResp->res); 2912a3316fc6SZhikuiRen return; 2913a3316fc6SZhikuiRen } 2914a3316fc6SZhikuiRen 2915a3316fc6SZhikuiRen // skip the empty postcode boots 2916a3316fc6SZhikuiRen if (postcode.empty()) 2917a3316fc6SZhikuiRen { 2918a3316fc6SZhikuiRen return; 2919a3316fc6SZhikuiRen } 2920a3316fc6SZhikuiRen 2921a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 2922a3316fc6SZhikuiRen 2923a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 2924a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 2925a3316fc6SZhikuiRen }, 292615124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 292715124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 2928a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 2929a3316fc6SZhikuiRen bootIndex); 2930a3316fc6SZhikuiRen } 2931a3316fc6SZhikuiRen 29328d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2933a3316fc6SZhikuiRen const uint16_t bootIndex, 2934a3316fc6SZhikuiRen const uint16_t bootCount, 2935a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 2936a3316fc6SZhikuiRen const uint64_t top) 2937a3316fc6SZhikuiRen { 2938a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2939a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 2940a3316fc6SZhikuiRen top](const boost::system::error_code ec, 29416c9a279eSManojkiran Eda const boost::container::flat_map< 29426c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 29436c9a279eSManojkiran Eda postcode) { 2944a3316fc6SZhikuiRen if (ec) 2945a3316fc6SZhikuiRen { 2946a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 2947a3316fc6SZhikuiRen messages::internalError(aResp->res); 2948a3316fc6SZhikuiRen return; 2949a3316fc6SZhikuiRen } 2950a3316fc6SZhikuiRen 2951a3316fc6SZhikuiRen uint64_t endCount = entryCount; 2952a3316fc6SZhikuiRen if (!postcode.empty()) 2953a3316fc6SZhikuiRen { 2954a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 2955a3316fc6SZhikuiRen 2956a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 2957a3316fc6SZhikuiRen { 2958a3316fc6SZhikuiRen uint64_t thisBootSkip = 2959a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 2960a3316fc6SZhikuiRen uint64_t thisBootTop = 2961a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 2962a3316fc6SZhikuiRen 2963a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 2964a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 2965a3316fc6SZhikuiRen } 2966a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 2967a3316fc6SZhikuiRen } 2968a3316fc6SZhikuiRen 2969a3316fc6SZhikuiRen // continue to previous bootIndex 2970a3316fc6SZhikuiRen if (bootIndex < bootCount) 2971a3316fc6SZhikuiRen { 2972a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 2973a3316fc6SZhikuiRen bootCount, endCount, skip, top); 2974a3316fc6SZhikuiRen } 2975a3316fc6SZhikuiRen else 2976a3316fc6SZhikuiRen { 2977a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 2978a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 2979a3316fc6SZhikuiRen "Entries?$skip=" + 2980a3316fc6SZhikuiRen std::to_string(skip + top); 2981a3316fc6SZhikuiRen } 2982a3316fc6SZhikuiRen }, 298315124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 298415124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 2985a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 2986a3316fc6SZhikuiRen bootIndex); 2987a3316fc6SZhikuiRen } 2988a3316fc6SZhikuiRen 29898d1b46d7Szhanghch05 static void 29908d1b46d7Szhanghch05 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2991a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 2992a3316fc6SZhikuiRen { 2993a3316fc6SZhikuiRen uint64_t entryCount = 0; 2994a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2995a3316fc6SZhikuiRen [aResp, entryCount, skip, 2996a3316fc6SZhikuiRen top](const boost::system::error_code ec, 2997a3316fc6SZhikuiRen const std::variant<uint16_t>& bootCount) { 2998a3316fc6SZhikuiRen if (ec) 2999a3316fc6SZhikuiRen { 3000a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3001a3316fc6SZhikuiRen messages::internalError(aResp->res); 3002a3316fc6SZhikuiRen return; 3003a3316fc6SZhikuiRen } 3004a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 3005a3316fc6SZhikuiRen if (pVal) 3006a3316fc6SZhikuiRen { 3007a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 3008a3316fc6SZhikuiRen } 3009a3316fc6SZhikuiRen else 3010a3316fc6SZhikuiRen { 3011a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 3012a3316fc6SZhikuiRen } 3013a3316fc6SZhikuiRen }, 301415124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 301515124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3016a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 3017a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 3018a3316fc6SZhikuiRen } 3019a3316fc6SZhikuiRen 3020*af61db10SGeorge Liu inline static bool parsePostCode(std::string postCodeID, uint64_t& currentValue, 3021*af61db10SGeorge Liu uint16_t& index) 3022*af61db10SGeorge Liu { 3023*af61db10SGeorge Liu // postCodeID = B1-1 3024*af61db10SGeorge Liu std::vector<std::string> split; 3025*af61db10SGeorge Liu boost::algorithm::split(split, postCodeID, boost::is_any_of("-")); 3026*af61db10SGeorge Liu if (split.size() != 2 || split[0].length() < 2) 3027*af61db10SGeorge Liu { 3028*af61db10SGeorge Liu return false; 3029*af61db10SGeorge Liu } 3030*af61db10SGeorge Liu 3031*af61db10SGeorge Liu const char* start = split[0].data() + 1; 3032*af61db10SGeorge Liu const char* end = split[0].data() + split[0].size(); 3033*af61db10SGeorge Liu auto [ptrIndex, ecIndex] = std::from_chars(start, end, index); 3034*af61db10SGeorge Liu 3035*af61db10SGeorge Liu if (ptrIndex != end || ecIndex != std::errc() || !index) 3036*af61db10SGeorge Liu { 3037*af61db10SGeorge Liu return false; 3038*af61db10SGeorge Liu } 3039*af61db10SGeorge Liu 3040*af61db10SGeorge Liu start = split[1].data(); 3041*af61db10SGeorge Liu end = split[1].data() + split[1].size(); 3042*af61db10SGeorge Liu auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue); 3043*af61db10SGeorge Liu if (ptrValue != end || ecValue != std::errc() || !currentValue) 3044*af61db10SGeorge Liu { 3045*af61db10SGeorge Liu return false; 3046*af61db10SGeorge Liu } 3047*af61db10SGeorge Liu 3048*af61db10SGeorge Liu return true; 3049*af61db10SGeorge Liu } 3050*af61db10SGeorge Liu 3051*af61db10SGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3052*af61db10SGeorge Liu { 3053*af61db10SGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/" 3054*af61db10SGeorge Liu "Entries/<str>/attachment/") 3055*af61db10SGeorge Liu .privileges({"Login"}) 3056*af61db10SGeorge Liu .methods(boost::beast::http::verb::get)( 3057*af61db10SGeorge Liu [](const crow::Request& req, 3058*af61db10SGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3059*af61db10SGeorge Liu const std::string& postCodeID) { 3060*af61db10SGeorge Liu if (!http_helpers::isOctetAccepted(req)) 3061*af61db10SGeorge Liu { 3062*af61db10SGeorge Liu asyncResp->res.result( 3063*af61db10SGeorge Liu boost::beast::http::status::bad_request); 3064*af61db10SGeorge Liu return; 3065*af61db10SGeorge Liu } 3066*af61db10SGeorge Liu 3067*af61db10SGeorge Liu uint64_t currentValue = 0; 3068*af61db10SGeorge Liu uint16_t index = 0; 3069*af61db10SGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 3070*af61db10SGeorge Liu { 3071*af61db10SGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", 3072*af61db10SGeorge Liu postCodeID); 3073*af61db10SGeorge Liu return; 3074*af61db10SGeorge Liu } 3075*af61db10SGeorge Liu 3076*af61db10SGeorge Liu crow::connections::systemBus->async_method_call( 3077*af61db10SGeorge Liu [asyncResp, postCodeID, currentValue]( 3078*af61db10SGeorge Liu const boost::system::error_code ec, 3079*af61db10SGeorge Liu const std::vector<std::tuple< 3080*af61db10SGeorge Liu uint64_t, std::vector<uint8_t>>>& postcodes) { 3081*af61db10SGeorge Liu if (ec.value() == EBADR) 3082*af61db10SGeorge Liu { 3083*af61db10SGeorge Liu messages::resourceNotFound(asyncResp->res, 3084*af61db10SGeorge Liu "LogEntry", postCodeID); 3085*af61db10SGeorge Liu return; 3086*af61db10SGeorge Liu } 3087*af61db10SGeorge Liu if (ec) 3088*af61db10SGeorge Liu { 3089*af61db10SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3090*af61db10SGeorge Liu messages::internalError(asyncResp->res); 3091*af61db10SGeorge Liu return; 3092*af61db10SGeorge Liu } 3093*af61db10SGeorge Liu 3094*af61db10SGeorge Liu if (currentValue < 1 || 3095*af61db10SGeorge Liu postcodes.size() <= currentValue) 3096*af61db10SGeorge Liu { 3097*af61db10SGeorge Liu BMCWEB_LOG_ERROR << "Wrong currentValue value"; 3098*af61db10SGeorge Liu messages::resourceNotFound(asyncResp->res, 3099*af61db10SGeorge Liu "LogEntry", postCodeID); 3100*af61db10SGeorge Liu return; 3101*af61db10SGeorge Liu } 3102*af61db10SGeorge Liu 3103*af61db10SGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 3104*af61db10SGeorge Liu auto& [tID, code] = postcodes[value]; 3105*af61db10SGeorge Liu 3106*af61db10SGeorge Liu if (code.size() == 0) 3107*af61db10SGeorge Liu { 3108*af61db10SGeorge Liu BMCWEB_LOG_INFO << "No found post code data"; 3109*af61db10SGeorge Liu messages::internalError(asyncResp->res); 3110*af61db10SGeorge Liu return; 3111*af61db10SGeorge Liu } 3112*af61db10SGeorge Liu 3113*af61db10SGeorge Liu std::string_view strData( 3114*af61db10SGeorge Liu reinterpret_cast<const char*>(code.data()), 3115*af61db10SGeorge Liu code.size()); 3116*af61db10SGeorge Liu 3117*af61db10SGeorge Liu asyncResp->res.addHeader("Content-Type", 3118*af61db10SGeorge Liu "application/octet-stream"); 3119*af61db10SGeorge Liu asyncResp->res.addHeader("Content-Transfer-Encoding", 3120*af61db10SGeorge Liu "Base64"); 3121*af61db10SGeorge Liu asyncResp->res.body() = 3122*af61db10SGeorge Liu std::move(crow::utility::base64encode(strData)); 3123*af61db10SGeorge Liu }, 3124*af61db10SGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 3125*af61db10SGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 3126*af61db10SGeorge Liu "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", 3127*af61db10SGeorge Liu index); 3128*af61db10SGeorge Liu }); 3129*af61db10SGeorge Liu } 3130*af61db10SGeorge Liu 31317e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3132a3316fc6SZhikuiRen { 31337e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 31347e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3135432a890cSEd Tanous .privileges({{"Login"}}) 31367e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 31377e860f15SJohn Edward Broadbent [](const crow::Request& req, 31387e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3139a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3140a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3141a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3142a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3143a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3144a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3145a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3146a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3147a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3148a3316fc6SZhikuiRen 3149a3316fc6SZhikuiRen uint64_t skip = 0; 3150a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 31518d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 3152a3316fc6SZhikuiRen { 3153a3316fc6SZhikuiRen return; 3154a3316fc6SZhikuiRen } 31558d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 3156a3316fc6SZhikuiRen { 3157a3316fc6SZhikuiRen return; 3158a3316fc6SZhikuiRen } 3159a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 31607e860f15SJohn Edward Broadbent }); 3161a3316fc6SZhikuiRen } 3162a3316fc6SZhikuiRen 31637e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 3164a3316fc6SZhikuiRen { 31657e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 31667e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/") 3167432a890cSEd Tanous .privileges({{"Login"}}) 31687e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 31697e860f15SJohn Edward Broadbent [](const crow::Request&, 31707e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 31717e860f15SJohn Edward Broadbent const std::string& targetID) { 3172a3316fc6SZhikuiRen size_t bootPos = targetID.find('B'); 3173a3316fc6SZhikuiRen if (bootPos == std::string::npos) 3174a3316fc6SZhikuiRen { 3175a3316fc6SZhikuiRen // Requested ID was not found 3176a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 3177a3316fc6SZhikuiRen return; 3178a3316fc6SZhikuiRen } 3179a3316fc6SZhikuiRen std::string_view bootIndexStr(targetID); 3180a3316fc6SZhikuiRen bootIndexStr.remove_prefix(bootPos + 1); 3181a3316fc6SZhikuiRen uint16_t bootIndex = 0; 3182a3316fc6SZhikuiRen uint64_t codeIndex = 0; 3183a3316fc6SZhikuiRen size_t dashPos = bootIndexStr.find('-'); 3184a3316fc6SZhikuiRen 3185a3316fc6SZhikuiRen if (dashPos == std::string::npos) 3186a3316fc6SZhikuiRen { 3187a3316fc6SZhikuiRen return; 3188a3316fc6SZhikuiRen } 3189a3316fc6SZhikuiRen std::string_view codeIndexStr(bootIndexStr); 3190a3316fc6SZhikuiRen bootIndexStr.remove_suffix(dashPos); 3191a3316fc6SZhikuiRen codeIndexStr.remove_prefix(dashPos + 1); 3192a3316fc6SZhikuiRen 3193a3316fc6SZhikuiRen bootIndex = static_cast<uint16_t>( 319423a21a1cSEd Tanous strtoul(std::string(bootIndexStr).c_str(), nullptr, 0)); 31957e860f15SJohn Edward Broadbent codeIndex = 31967e860f15SJohn Edward Broadbent strtoul(std::string(codeIndexStr).c_str(), nullptr, 0); 3197a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3198a3316fc6SZhikuiRen { 3199a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 32007e860f15SJohn Edward Broadbent << targetID; 3201a3316fc6SZhikuiRen } 3202a3316fc6SZhikuiRen 32037e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = 32047e860f15SJohn Edward Broadbent "#LogEntry.v1_4_0.LogEntry"; 3205a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3206a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3207a3316fc6SZhikuiRen "Entries"; 3208a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3209a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3210a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3211a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3212a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3213a3316fc6SZhikuiRen 3214a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 32157e860f15SJohn Edward Broadbent }); 3216a3316fc6SZhikuiRen } 3217a3316fc6SZhikuiRen 32181da66f75SEd Tanous } // namespace redfish 3219