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 18b7028ebfSSpencer Ku #include "gzfile.hpp" 19647b3cdcSGeorge Liu #include "http_utility.hpp" 20b7028ebfSSpencer Ku #include "human_sort.hpp" 214851d45dSJason M. Bills #include "registries.hpp" 224851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 234851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2446229577SJames Feist #include "task.hpp" 251da66f75SEd Tanous 26e1f26343SJason M. Bills #include <systemd/sd-journal.h> 27400fd1fbSAdriana Kobylak #include <unistd.h> 28e1f26343SJason M. Bills 297e860f15SJohn Edward Broadbent #include <app.hpp> 30400fd1fbSAdriana Kobylak #include <boost/algorithm/string/replace.hpp> 314851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 32400fd1fbSAdriana Kobylak #include <boost/beast/http.hpp> 331da66f75SEd Tanous #include <boost/container/flat_map.hpp> 341ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 35168e20c1SEd Tanous #include <dbus_utility.hpp> 36cb92c03bSAndrew Geissler #include <error_messages.hpp> 37ed398213SEd Tanous #include <registries/privilege_registry.hpp> 381214b7e7SGunnar Mills 39647b3cdcSGeorge Liu #include <charconv> 404418c7f0SJames Feist #include <filesystem> 4175710de2SXiaochao Ma #include <optional> 4226702d01SEd Tanous #include <span> 43cd225da8SJason M. Bills #include <string_view> 44abf2add6SEd Tanous #include <variant> 451da66f75SEd Tanous 461da66f75SEd Tanous namespace redfish 471da66f75SEd Tanous { 481da66f75SEd Tanous 495b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 505b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 515b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 525b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 535b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 545b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 55424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 566eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 576eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 581da66f75SEd Tanous 594851d45dSJason M. Bills namespace message_registries 604851d45dSJason M. Bills { 6126702d01SEd Tanous static const Message* 6226702d01SEd Tanous getMessageFromRegistry(const std::string& messageKey, 6326702d01SEd Tanous const std::span<const MessageEntry> registry) 644851d45dSJason M. Bills { 6526702d01SEd Tanous std::span<const MessageEntry>::iterator messageIt = std::find_if( 6626702d01SEd Tanous registry.begin(), registry.end(), 674851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 68e662eae8SEd Tanous return std::strcmp(messageEntry.first, messageKey.c_str()) == 0; 694851d45dSJason M. Bills }); 7026702d01SEd Tanous if (messageIt != registry.end()) 714851d45dSJason M. Bills { 724851d45dSJason M. Bills return &messageIt->second; 734851d45dSJason M. Bills } 744851d45dSJason M. Bills 754851d45dSJason M. Bills return nullptr; 764851d45dSJason M. Bills } 774851d45dSJason M. Bills 784851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 794851d45dSJason M. Bills { 804851d45dSJason M. Bills // Redfish MessageIds are in the form 814851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 824851d45dSJason M. Bills // the right Message 834851d45dSJason M. Bills std::vector<std::string> fields; 844851d45dSJason M. Bills fields.reserve(4); 854851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 864851d45dSJason M. Bills std::string& registryName = fields[0]; 874851d45dSJason M. Bills std::string& messageKey = fields[3]; 884851d45dSJason M. Bills 894851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 904851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 914851d45dSJason M. Bills { 924851d45dSJason M. Bills return getMessageFromRegistry( 9326702d01SEd Tanous messageKey, std::span<const MessageEntry>(base::registry)); 944851d45dSJason M. Bills } 954851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 964851d45dSJason M. Bills { 974851d45dSJason M. Bills return getMessageFromRegistry( 9826702d01SEd Tanous messageKey, std::span<const MessageEntry>(openbmc::registry)); 994851d45dSJason M. Bills } 1004851d45dSJason M. Bills return nullptr; 1014851d45dSJason M. Bills } 1024851d45dSJason M. Bills } // namespace message_registries 1034851d45dSJason M. Bills 104f6150403SJames Feist namespace fs = std::filesystem; 1051da66f75SEd Tanous 106168e20c1SEd Tanous using GetManagedPropertyType = 107168e20c1SEd Tanous boost::container::flat_map<std::string, dbus::utility::DbusVariantType>; 108cb92c03bSAndrew Geissler 109cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 110cb92c03bSAndrew Geissler { 111d4d25793SEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") || 112d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") || 113d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") || 114d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Error")) 115cb92c03bSAndrew Geissler { 116cb92c03bSAndrew Geissler return "Critical"; 117cb92c03bSAndrew Geissler } 1183174e4dfSEd Tanous if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") || 119d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") || 120d4d25793SEd Tanous (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")) 121cb92c03bSAndrew Geissler { 122cb92c03bSAndrew Geissler return "OK"; 123cb92c03bSAndrew Geissler } 1243174e4dfSEd Tanous if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 125cb92c03bSAndrew Geissler { 126cb92c03bSAndrew Geissler return "Warning"; 127cb92c03bSAndrew Geissler } 128cb92c03bSAndrew Geissler return ""; 129cb92c03bSAndrew Geissler } 130cb92c03bSAndrew Geissler 1317e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 13239e77504SEd Tanous const std::string_view& field, 13339e77504SEd Tanous std::string_view& contents) 13416428a1aSJason M. Bills { 13516428a1aSJason M. Bills const char* data = nullptr; 13616428a1aSJason M. Bills size_t length = 0; 13716428a1aSJason M. Bills int ret = 0; 13816428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 13946ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 14046ff87baSEd Tanous const void** dataVoid = reinterpret_cast<const void**>(&data); 14146ff87baSEd Tanous 14246ff87baSEd Tanous ret = sd_journal_get_data(journal, field.data(), dataVoid, &length); 14316428a1aSJason M. Bills if (ret < 0) 14416428a1aSJason M. Bills { 14516428a1aSJason M. Bills return ret; 14616428a1aSJason M. Bills } 14739e77504SEd Tanous contents = std::string_view(data, length); 14816428a1aSJason M. Bills // Only use the content after the "=" character. 14981ce609eSEd Tanous contents.remove_prefix(std::min(contents.find('=') + 1, contents.size())); 15016428a1aSJason M. Bills return ret; 15116428a1aSJason M. Bills } 15216428a1aSJason M. Bills 1537e860f15SJohn Edward Broadbent inline static int getJournalMetadata(sd_journal* journal, 1547e860f15SJohn Edward Broadbent const std::string_view& field, 1557e860f15SJohn Edward Broadbent const int& base, long int& contents) 15616428a1aSJason M. Bills { 15716428a1aSJason M. Bills int ret = 0; 15839e77504SEd Tanous std::string_view metadata; 15916428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 16016428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 16116428a1aSJason M. Bills if (ret < 0) 16216428a1aSJason M. Bills { 16316428a1aSJason M. Bills return ret; 16416428a1aSJason M. Bills } 165b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 16616428a1aSJason M. Bills return ret; 16716428a1aSJason M. Bills } 16816428a1aSJason M. Bills 1697e860f15SJohn Edward Broadbent inline static bool getEntryTimestamp(sd_journal* journal, 1707e860f15SJohn Edward Broadbent std::string& entryTimestamp) 171a3316fc6SZhikuiRen { 172a3316fc6SZhikuiRen int ret = 0; 173a3316fc6SZhikuiRen uint64_t timestamp = 0; 174a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 175a3316fc6SZhikuiRen if (ret < 0) 176a3316fc6SZhikuiRen { 177a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 178a3316fc6SZhikuiRen << strerror(-ret); 179a3316fc6SZhikuiRen return false; 180a3316fc6SZhikuiRen } 1811d8782e7SNan Zhou entryTimestamp = crow::utility::getDateTimeUint(timestamp / 1000 / 1000); 1829c620e21SAsmitha Karunanithi return true; 183a3316fc6SZhikuiRen } 18450b8a43aSEd Tanous 18567df073bSEd Tanous static bool getSkipParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 18667df073bSEd Tanous const crow::Request& req, uint64_t& skip) 18767df073bSEd Tanous { 18867df073bSEd Tanous boost::urls::params_view::iterator it = req.urlView.params().find("$skip"); 18967df073bSEd Tanous if (it != req.urlView.params().end()) 19067df073bSEd Tanous { 19167df073bSEd Tanous std::from_chars_result r = std::from_chars( 19267df073bSEd Tanous (*it).value.data(), (*it).value.data() + (*it).value.size(), skip); 19367df073bSEd Tanous if (r.ec != std::errc()) 19467df073bSEd Tanous { 19567df073bSEd Tanous messages::queryParameterValueTypeError(asyncResp->res, "", "$skip"); 19667df073bSEd Tanous return false; 19767df073bSEd Tanous } 19867df073bSEd Tanous } 19967df073bSEd Tanous return true; 20067df073bSEd Tanous } 20167df073bSEd Tanous 20267df073bSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 20367df073bSEd Tanous static bool getTopParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 20467df073bSEd Tanous const crow::Request& req, uint64_t& top) 20567df073bSEd Tanous { 20667df073bSEd Tanous boost::urls::params_view::iterator it = req.urlView.params().find("$top"); 20767df073bSEd Tanous if (it != req.urlView.params().end()) 20867df073bSEd Tanous { 20967df073bSEd Tanous std::from_chars_result r = std::from_chars( 21067df073bSEd Tanous (*it).value.data(), (*it).value.data() + (*it).value.size(), top); 21167df073bSEd Tanous if (r.ec != std::errc()) 21267df073bSEd Tanous { 21367df073bSEd Tanous messages::queryParameterValueTypeError(asyncResp->res, "", "$top"); 21467df073bSEd Tanous return false; 21567df073bSEd Tanous } 21667df073bSEd Tanous if (top < 1U || top > maxEntriesPerPage) 21767df073bSEd Tanous { 21867df073bSEd Tanous 21967df073bSEd Tanous messages::queryParameterOutOfRange( 22067df073bSEd Tanous asyncResp->res, std::to_string(top), "$top", 22167df073bSEd Tanous "1-" + std::to_string(maxEntriesPerPage)); 22267df073bSEd Tanous return false; 22367df073bSEd Tanous } 22467df073bSEd Tanous } 22567df073bSEd Tanous return true; 22667df073bSEd Tanous } 22767df073bSEd Tanous 2287e860f15SJohn Edward Broadbent inline static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 229e85d6b16SJason M. Bills const bool firstEntry = true) 23016428a1aSJason M. Bills { 23116428a1aSJason M. Bills int ret = 0; 23216428a1aSJason M. Bills static uint64_t prevTs = 0; 23316428a1aSJason M. Bills static int index = 0; 234e85d6b16SJason M. Bills if (firstEntry) 235e85d6b16SJason M. Bills { 236e85d6b16SJason M. Bills prevTs = 0; 237e85d6b16SJason M. Bills } 238e85d6b16SJason M. Bills 23916428a1aSJason M. Bills // Get the entry timestamp 24016428a1aSJason M. Bills uint64_t curTs = 0; 24116428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 24216428a1aSJason M. Bills if (ret < 0) 24316428a1aSJason M. Bills { 24416428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 24516428a1aSJason M. Bills << strerror(-ret); 24616428a1aSJason M. Bills return false; 24716428a1aSJason M. Bills } 24816428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 24916428a1aSJason M. Bills if (curTs == prevTs) 25016428a1aSJason M. Bills { 25116428a1aSJason M. Bills index++; 25216428a1aSJason M. Bills } 25316428a1aSJason M. Bills else 25416428a1aSJason M. Bills { 25516428a1aSJason M. Bills // Otherwise, reset it 25616428a1aSJason M. Bills index = 0; 25716428a1aSJason M. Bills } 25816428a1aSJason M. Bills // Save the timestamp 25916428a1aSJason M. Bills prevTs = curTs; 26016428a1aSJason M. Bills 26116428a1aSJason M. Bills entryID = std::to_string(curTs); 26216428a1aSJason M. Bills if (index > 0) 26316428a1aSJason M. Bills { 26416428a1aSJason M. Bills entryID += "_" + std::to_string(index); 26516428a1aSJason M. Bills } 26616428a1aSJason M. Bills return true; 26716428a1aSJason M. Bills } 26816428a1aSJason M. Bills 269e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 270e85d6b16SJason M. Bills const bool firstEntry = true) 27195820184SJason M. Bills { 272271584abSEd Tanous static time_t prevTs = 0; 27395820184SJason M. Bills static int index = 0; 274e85d6b16SJason M. Bills if (firstEntry) 275e85d6b16SJason M. Bills { 276e85d6b16SJason M. Bills prevTs = 0; 277e85d6b16SJason M. Bills } 278e85d6b16SJason M. Bills 27995820184SJason M. Bills // Get the entry timestamp 280271584abSEd Tanous std::time_t curTs = 0; 28195820184SJason M. Bills std::tm timeStruct = {}; 28295820184SJason M. Bills std::istringstream entryStream(logEntry); 28395820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 28495820184SJason M. Bills { 28595820184SJason M. Bills curTs = std::mktime(&timeStruct); 28695820184SJason M. Bills } 28795820184SJason M. Bills // If the timestamp isn't unique, increment the index 28895820184SJason M. Bills if (curTs == prevTs) 28995820184SJason M. Bills { 29095820184SJason M. Bills index++; 29195820184SJason M. Bills } 29295820184SJason M. Bills else 29395820184SJason M. Bills { 29495820184SJason M. Bills // Otherwise, reset it 29595820184SJason M. Bills index = 0; 29695820184SJason M. Bills } 29795820184SJason M. Bills // Save the timestamp 29895820184SJason M. Bills prevTs = curTs; 29995820184SJason M. Bills 30095820184SJason M. Bills entryID = std::to_string(curTs); 30195820184SJason M. Bills if (index > 0) 30295820184SJason M. Bills { 30395820184SJason M. Bills entryID += "_" + std::to_string(index); 30495820184SJason M. Bills } 30595820184SJason M. Bills return true; 30695820184SJason M. Bills } 30795820184SJason M. Bills 3087e860f15SJohn Edward Broadbent inline static bool 3098d1b46d7Szhanghch05 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3108d1b46d7Szhanghch05 const std::string& entryID, uint64_t& timestamp, 3118d1b46d7Szhanghch05 uint64_t& index) 31216428a1aSJason M. Bills { 31316428a1aSJason M. Bills if (entryID.empty()) 31416428a1aSJason M. Bills { 31516428a1aSJason M. Bills return false; 31616428a1aSJason M. Bills } 31716428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 31839e77504SEd Tanous std::string_view tsStr(entryID); 31916428a1aSJason M. Bills 32081ce609eSEd Tanous auto underscorePos = tsStr.find('_'); 32171d5d8dbSEd Tanous if (underscorePos != std::string_view::npos) 32216428a1aSJason M. Bills { 32316428a1aSJason M. Bills // Timestamp has an index 32416428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 32539e77504SEd Tanous std::string_view indexStr(entryID); 32616428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 327c0bd5e4bSEd Tanous auto [ptr, ec] = std::from_chars( 328c0bd5e4bSEd Tanous indexStr.data(), indexStr.data() + indexStr.size(), index); 329c0bd5e4bSEd Tanous if (ec != std::errc()) 33016428a1aSJason M. Bills { 331*ace85d60SEd Tanous messages::resourceMissingAtURI( 332*ace85d60SEd Tanous asyncResp->res, crow::utility::urlFromPieces(entryID)); 33316428a1aSJason M. Bills return false; 33416428a1aSJason M. Bills } 33516428a1aSJason M. Bills } 33616428a1aSJason M. Bills // Timestamp has no index 337c0bd5e4bSEd Tanous auto [ptr, ec] = 338c0bd5e4bSEd Tanous std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp); 339c0bd5e4bSEd Tanous if (ec != std::errc()) 34016428a1aSJason M. Bills { 341*ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, 342*ace85d60SEd Tanous crow::utility::urlFromPieces(entryID)); 34316428a1aSJason M. Bills return false; 34416428a1aSJason M. Bills } 34516428a1aSJason M. Bills return true; 34616428a1aSJason M. Bills } 34716428a1aSJason M. Bills 34895820184SJason M. Bills static bool 34995820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 35095820184SJason M. Bills { 35195820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 35295820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 35395820184SJason M. Bills 35495820184SJason M. Bills // Loop through the directory looking for redfish log files 35595820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 35695820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 35795820184SJason M. Bills { 35895820184SJason M. Bills // If we find a redfish log file, save the path 35995820184SJason M. Bills std::string filename = dirEnt.path().filename(); 36095820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 36195820184SJason M. Bills { 36295820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 36395820184SJason M. Bills } 36495820184SJason M. Bills } 36595820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 36695820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 36795820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 36895820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 36995820184SJason M. Bills 37095820184SJason M. Bills return !redfishLogFiles.empty(); 37195820184SJason M. Bills } 37295820184SJason M. Bills 3738d1b46d7Szhanghch05 inline void 3748d1b46d7Szhanghch05 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3755cb1dd27SAsmitha Karunanithi const std::string& dumpType) 3765cb1dd27SAsmitha Karunanithi { 3775cb1dd27SAsmitha Karunanithi std::string dumpPath; 3785cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 3795cb1dd27SAsmitha Karunanithi { 3805cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 3815cb1dd27SAsmitha Karunanithi } 3825cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 3835cb1dd27SAsmitha Karunanithi { 3845cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 3855cb1dd27SAsmitha Karunanithi } 3865cb1dd27SAsmitha Karunanithi else 3875cb1dd27SAsmitha Karunanithi { 3885cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 3895cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 3905cb1dd27SAsmitha Karunanithi return; 3915cb1dd27SAsmitha Karunanithi } 3925cb1dd27SAsmitha Karunanithi 3935cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 394711ac7a9SEd Tanous [asyncResp, dumpPath, 395711ac7a9SEd Tanous dumpType](const boost::system::error_code ec, 396711ac7a9SEd Tanous dbus::utility::ManagedObjectType& resp) { 3975cb1dd27SAsmitha Karunanithi if (ec) 3985cb1dd27SAsmitha Karunanithi { 3995cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 4005cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4015cb1dd27SAsmitha Karunanithi return; 4025cb1dd27SAsmitha Karunanithi } 4035cb1dd27SAsmitha Karunanithi 4045cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 4055cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 406b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 407b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 408b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 409b47452b2SAsmitha Karunanithi "/entry/"; 4105cb1dd27SAsmitha Karunanithi 4115cb1dd27SAsmitha Karunanithi for (auto& object : resp) 4125cb1dd27SAsmitha Karunanithi { 413b47452b2SAsmitha Karunanithi if (object.first.str.find(dumpEntryPath) == std::string::npos) 4145cb1dd27SAsmitha Karunanithi { 4155cb1dd27SAsmitha Karunanithi continue; 4165cb1dd27SAsmitha Karunanithi } 4171d8782e7SNan Zhou uint64_t timestamp = 0; 4185cb1dd27SAsmitha Karunanithi uint64_t size = 0; 41935440d18SAsmitha Karunanithi std::string dumpStatus; 42035440d18SAsmitha Karunanithi nlohmann::json thisEntry; 4212dfd18efSEd Tanous 4222dfd18efSEd Tanous std::string entryID = object.first.filename(); 4232dfd18efSEd Tanous if (entryID.empty()) 4245cb1dd27SAsmitha Karunanithi { 4255cb1dd27SAsmitha Karunanithi continue; 4265cb1dd27SAsmitha Karunanithi } 4275cb1dd27SAsmitha Karunanithi 4285cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 4295cb1dd27SAsmitha Karunanithi { 43035440d18SAsmitha Karunanithi if (interfaceMap.first == 43135440d18SAsmitha Karunanithi "xyz.openbmc_project.Common.Progress") 43235440d18SAsmitha Karunanithi { 4339eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 43435440d18SAsmitha Karunanithi { 43535440d18SAsmitha Karunanithi if (propertyMap.first == "Status") 43635440d18SAsmitha Karunanithi { 43735440d18SAsmitha Karunanithi auto status = std::get_if<std::string>( 43835440d18SAsmitha Karunanithi &propertyMap.second); 43935440d18SAsmitha Karunanithi if (status == nullptr) 44035440d18SAsmitha Karunanithi { 44135440d18SAsmitha Karunanithi messages::internalError(asyncResp->res); 44235440d18SAsmitha Karunanithi break; 44335440d18SAsmitha Karunanithi } 44435440d18SAsmitha Karunanithi dumpStatus = *status; 44535440d18SAsmitha Karunanithi } 44635440d18SAsmitha Karunanithi } 44735440d18SAsmitha Karunanithi } 44835440d18SAsmitha Karunanithi else if (interfaceMap.first == 44935440d18SAsmitha Karunanithi "xyz.openbmc_project.Dump.Entry") 4505cb1dd27SAsmitha Karunanithi { 4515cb1dd27SAsmitha Karunanithi 4525cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 4535cb1dd27SAsmitha Karunanithi { 4545cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 4555cb1dd27SAsmitha Karunanithi { 4565cb1dd27SAsmitha Karunanithi auto sizePtr = 4575cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4585cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 4595cb1dd27SAsmitha Karunanithi { 4605cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4615cb1dd27SAsmitha Karunanithi break; 4625cb1dd27SAsmitha Karunanithi } 4635cb1dd27SAsmitha Karunanithi size = *sizePtr; 4645cb1dd27SAsmitha Karunanithi break; 4655cb1dd27SAsmitha Karunanithi } 4665cb1dd27SAsmitha Karunanithi } 4675cb1dd27SAsmitha Karunanithi } 4685cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 4695cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 4705cb1dd27SAsmitha Karunanithi { 4715cb1dd27SAsmitha Karunanithi 4729eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 4735cb1dd27SAsmitha Karunanithi { 4745cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 4755cb1dd27SAsmitha Karunanithi { 4765cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 4775cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 4785cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 4795cb1dd27SAsmitha Karunanithi { 4805cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 4815cb1dd27SAsmitha Karunanithi break; 4825cb1dd27SAsmitha Karunanithi } 4831d8782e7SNan Zhou timestamp = (*usecsTimeStamp / 1000 / 1000); 4845cb1dd27SAsmitha Karunanithi break; 4855cb1dd27SAsmitha Karunanithi } 4865cb1dd27SAsmitha Karunanithi } 4875cb1dd27SAsmitha Karunanithi } 4885cb1dd27SAsmitha Karunanithi } 4895cb1dd27SAsmitha Karunanithi 4900fda0f12SGeorge Liu if (dumpStatus != 4910fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 49235440d18SAsmitha Karunanithi !dumpStatus.empty()) 49335440d18SAsmitha Karunanithi { 49435440d18SAsmitha Karunanithi // Dump status is not Complete, no need to enumerate 49535440d18SAsmitha Karunanithi continue; 49635440d18SAsmitha Karunanithi } 49735440d18SAsmitha Karunanithi 498647b3cdcSGeorge Liu thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 4995cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 5005cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 5015cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 5021d8782e7SNan Zhou thisEntry["Created"] = 5031d8782e7SNan Zhou crow::utility::getDateTimeUint(timestamp); 5045cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 5055cb1dd27SAsmitha Karunanithi 506d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataSizeBytes"] = size; 5075cb1dd27SAsmitha Karunanithi 5085cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5095cb1dd27SAsmitha Karunanithi { 510d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "Manager"; 511d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 512de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 513de8d94a3SAbhishek Patel entryID + "/attachment"; 5145cb1dd27SAsmitha Karunanithi } 5155cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5165cb1dd27SAsmitha Karunanithi { 517d337bb72SAsmitha Karunanithi thisEntry["DiagnosticDataType"] = "OEM"; 518d337bb72SAsmitha Karunanithi thisEntry["OEMDiagnosticDataType"] = "System"; 519d337bb72SAsmitha Karunanithi thisEntry["AdditionalDataURI"] = 520de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 521de8d94a3SAbhishek Patel entryID + "/attachment"; 5225cb1dd27SAsmitha Karunanithi } 52335440d18SAsmitha Karunanithi entriesArray.push_back(std::move(thisEntry)); 5245cb1dd27SAsmitha Karunanithi } 5255cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 5265cb1dd27SAsmitha Karunanithi entriesArray.size(); 5275cb1dd27SAsmitha Karunanithi }, 5285cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 5295cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 5305cb1dd27SAsmitha Karunanithi } 5315cb1dd27SAsmitha Karunanithi 5328d1b46d7Szhanghch05 inline void 5338d1b46d7Szhanghch05 getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 5348d1b46d7Szhanghch05 const std::string& entryID, const std::string& dumpType) 5355cb1dd27SAsmitha Karunanithi { 5365cb1dd27SAsmitha Karunanithi std::string dumpPath; 5375cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 5385cb1dd27SAsmitha Karunanithi { 5395cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 5405cb1dd27SAsmitha Karunanithi } 5415cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 5425cb1dd27SAsmitha Karunanithi { 5435cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 5445cb1dd27SAsmitha Karunanithi } 5455cb1dd27SAsmitha Karunanithi else 5465cb1dd27SAsmitha Karunanithi { 5475cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 5485cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5495cb1dd27SAsmitha Karunanithi return; 5505cb1dd27SAsmitha Karunanithi } 5515cb1dd27SAsmitha Karunanithi 5525cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 553711ac7a9SEd Tanous [asyncResp, entryID, dumpPath, 554711ac7a9SEd Tanous dumpType](const boost::system::error_code ec, 555711ac7a9SEd Tanous dbus::utility::ManagedObjectType& resp) { 5565cb1dd27SAsmitha Karunanithi if (ec) 5575cb1dd27SAsmitha Karunanithi { 5585cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 5595cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 5605cb1dd27SAsmitha Karunanithi return; 5615cb1dd27SAsmitha Karunanithi } 5625cb1dd27SAsmitha Karunanithi 563b47452b2SAsmitha Karunanithi bool foundDumpEntry = false; 564b47452b2SAsmitha Karunanithi std::string dumpEntryPath = 565b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 566b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 567b47452b2SAsmitha Karunanithi "/entry/"; 568b47452b2SAsmitha Karunanithi 5699eb808c1SEd Tanous for (const auto& objectPath : resp) 5705cb1dd27SAsmitha Karunanithi { 571b47452b2SAsmitha Karunanithi if (objectPath.first.str != dumpEntryPath + entryID) 5725cb1dd27SAsmitha Karunanithi { 5735cb1dd27SAsmitha Karunanithi continue; 5745cb1dd27SAsmitha Karunanithi } 5755cb1dd27SAsmitha Karunanithi 5765cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 5771d8782e7SNan Zhou uint64_t timestamp = 0; 5785cb1dd27SAsmitha Karunanithi uint64_t size = 0; 57935440d18SAsmitha Karunanithi std::string dumpStatus; 5805cb1dd27SAsmitha Karunanithi 5819eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 5825cb1dd27SAsmitha Karunanithi { 58335440d18SAsmitha Karunanithi if (interfaceMap.first == 58435440d18SAsmitha Karunanithi "xyz.openbmc_project.Common.Progress") 58535440d18SAsmitha Karunanithi { 5869eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 58735440d18SAsmitha Karunanithi { 58835440d18SAsmitha Karunanithi if (propertyMap.first == "Status") 58935440d18SAsmitha Karunanithi { 5909eb808c1SEd Tanous const std::string* status = 5919eb808c1SEd Tanous std::get_if<std::string>( 59235440d18SAsmitha Karunanithi &propertyMap.second); 59335440d18SAsmitha Karunanithi if (status == nullptr) 59435440d18SAsmitha Karunanithi { 59535440d18SAsmitha Karunanithi messages::internalError(asyncResp->res); 59635440d18SAsmitha Karunanithi break; 59735440d18SAsmitha Karunanithi } 59835440d18SAsmitha Karunanithi dumpStatus = *status; 59935440d18SAsmitha Karunanithi } 60035440d18SAsmitha Karunanithi } 60135440d18SAsmitha Karunanithi } 60235440d18SAsmitha Karunanithi else if (interfaceMap.first == 60335440d18SAsmitha Karunanithi "xyz.openbmc_project.Dump.Entry") 6045cb1dd27SAsmitha Karunanithi { 6059eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 6065cb1dd27SAsmitha Karunanithi { 6075cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 6085cb1dd27SAsmitha Karunanithi { 6099eb808c1SEd Tanous const uint64_t* sizePtr = 6105cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6115cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 6125cb1dd27SAsmitha Karunanithi { 6135cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6145cb1dd27SAsmitha Karunanithi break; 6155cb1dd27SAsmitha Karunanithi } 6165cb1dd27SAsmitha Karunanithi size = *sizePtr; 6175cb1dd27SAsmitha Karunanithi break; 6185cb1dd27SAsmitha Karunanithi } 6195cb1dd27SAsmitha Karunanithi } 6205cb1dd27SAsmitha Karunanithi } 6215cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 6225cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 6235cb1dd27SAsmitha Karunanithi { 6249eb808c1SEd Tanous for (const auto& propertyMap : interfaceMap.second) 6255cb1dd27SAsmitha Karunanithi { 6265cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 6275cb1dd27SAsmitha Karunanithi { 6285cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 6295cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 6305cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 6315cb1dd27SAsmitha Karunanithi { 6325cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 6335cb1dd27SAsmitha Karunanithi break; 6345cb1dd27SAsmitha Karunanithi } 6351d8782e7SNan Zhou timestamp = *usecsTimeStamp / 1000 / 1000; 6365cb1dd27SAsmitha Karunanithi break; 6375cb1dd27SAsmitha Karunanithi } 6385cb1dd27SAsmitha Karunanithi } 6395cb1dd27SAsmitha Karunanithi } 6405cb1dd27SAsmitha Karunanithi } 6415cb1dd27SAsmitha Karunanithi 6420fda0f12SGeorge Liu if (dumpStatus != 6430fda0f12SGeorge Liu "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && 64435440d18SAsmitha Karunanithi !dumpStatus.empty()) 64535440d18SAsmitha Karunanithi { 64635440d18SAsmitha Karunanithi // Dump status is not Complete 64735440d18SAsmitha Karunanithi // return not found until status is changed to Completed 64835440d18SAsmitha Karunanithi messages::resourceNotFound(asyncResp->res, 64935440d18SAsmitha Karunanithi dumpType + " dump", entryID); 65035440d18SAsmitha Karunanithi return; 65135440d18SAsmitha Karunanithi } 65235440d18SAsmitha Karunanithi 6535cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 654647b3cdcSGeorge Liu "#LogEntry.v1_8_0.LogEntry"; 6555cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 6565cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 6575cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 6585cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 6591d8782e7SNan Zhou crow::utility::getDateTimeUint(timestamp); 6605cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 6615cb1dd27SAsmitha Karunanithi 662d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size; 6635cb1dd27SAsmitha Karunanithi 6645cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 6655cb1dd27SAsmitha Karunanithi { 666d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager"; 667d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 668de8d94a3SAbhishek Patel "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" + 669de8d94a3SAbhishek Patel entryID + "/attachment"; 6705cb1dd27SAsmitha Karunanithi } 6715cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 6725cb1dd27SAsmitha Karunanithi { 673d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM"; 674d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["OEMDiagnosticDataType"] = 6755cb1dd27SAsmitha Karunanithi "System"; 676d337bb72SAsmitha Karunanithi asyncResp->res.jsonValue["AdditionalDataURI"] = 677de8d94a3SAbhishek Patel "/redfish/v1/Systems/system/LogServices/Dump/Entries/" + 678de8d94a3SAbhishek Patel entryID + "/attachment"; 6795cb1dd27SAsmitha Karunanithi } 6805cb1dd27SAsmitha Karunanithi } 681e05aec50SEd Tanous if (!foundDumpEntry) 682b47452b2SAsmitha Karunanithi { 683b47452b2SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 684b47452b2SAsmitha Karunanithi messages::internalError(asyncResp->res); 685b47452b2SAsmitha Karunanithi return; 686b47452b2SAsmitha Karunanithi } 6875cb1dd27SAsmitha Karunanithi }, 6885cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 6895cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 6905cb1dd27SAsmitha Karunanithi } 6915cb1dd27SAsmitha Karunanithi 6928d1b46d7Szhanghch05 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6939878256fSStanley Chu const std::string& entryID, 694b47452b2SAsmitha Karunanithi const std::string& dumpType) 6955cb1dd27SAsmitha Karunanithi { 6963de8d8baSGeorge Liu auto respHandler = [asyncResp, 6973de8d8baSGeorge Liu entryID](const boost::system::error_code ec) { 6985cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 6995cb1dd27SAsmitha Karunanithi if (ec) 7005cb1dd27SAsmitha Karunanithi { 7013de8d8baSGeorge Liu if (ec.value() == EBADR) 7023de8d8baSGeorge Liu { 7033de8d8baSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); 7043de8d8baSGeorge Liu return; 7053de8d8baSGeorge Liu } 7065cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 7075cb1dd27SAsmitha Karunanithi << ec; 7085cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 7095cb1dd27SAsmitha Karunanithi return; 7105cb1dd27SAsmitha Karunanithi } 7115cb1dd27SAsmitha Karunanithi }; 7125cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 7135cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 714b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 715b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" + 716b47452b2SAsmitha Karunanithi entryID, 7175cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 7185cb1dd27SAsmitha Karunanithi } 7195cb1dd27SAsmitha Karunanithi 7208d1b46d7Szhanghch05 inline void 72198be3e39SEd Tanous createDumpTaskCallback(task::Payload&& payload, 7228d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7238d1b46d7Szhanghch05 const uint32_t& dumpId, const std::string& dumpPath, 724a43be80fSAsmitha Karunanithi const std::string& dumpType) 725a43be80fSAsmitha Karunanithi { 726a43be80fSAsmitha Karunanithi std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 7276145ed6fSAsmitha Karunanithi [dumpId, dumpPath, dumpType]( 728a43be80fSAsmitha Karunanithi boost::system::error_code err, sdbusplus::message::message& m, 729a43be80fSAsmitha Karunanithi const std::shared_ptr<task::TaskData>& taskData) { 730cb13a392SEd Tanous if (err) 731cb13a392SEd Tanous { 7326145ed6fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Error in creating a dump"; 7336145ed6fSAsmitha Karunanithi taskData->state = "Cancelled"; 7346145ed6fSAsmitha Karunanithi return task::completed; 735cb13a392SEd Tanous } 736a43be80fSAsmitha Karunanithi std::vector<std::pair< 737168e20c1SEd Tanous std::string, std::vector<std::pair< 738168e20c1SEd Tanous std::string, dbus::utility::DbusVariantType>>>> 739a43be80fSAsmitha Karunanithi interfacesList; 740a43be80fSAsmitha Karunanithi 741a43be80fSAsmitha Karunanithi sdbusplus::message::object_path objPath; 742a43be80fSAsmitha Karunanithi 743a43be80fSAsmitha Karunanithi m.read(objPath, interfacesList); 744a43be80fSAsmitha Karunanithi 745b47452b2SAsmitha Karunanithi if (objPath.str == 746b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 747b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)) + 748b47452b2SAsmitha Karunanithi "/entry/" + std::to_string(dumpId)) 749a43be80fSAsmitha Karunanithi { 750a43be80fSAsmitha Karunanithi nlohmann::json retMessage = messages::success(); 751a43be80fSAsmitha Karunanithi taskData->messages.emplace_back(retMessage); 752a43be80fSAsmitha Karunanithi 753a43be80fSAsmitha Karunanithi std::string headerLoc = 754a43be80fSAsmitha Karunanithi "Location: " + dumpPath + std::to_string(dumpId); 755a43be80fSAsmitha Karunanithi taskData->payload->httpHeaders.emplace_back( 756a43be80fSAsmitha Karunanithi std::move(headerLoc)); 757a43be80fSAsmitha Karunanithi 758a43be80fSAsmitha Karunanithi taskData->state = "Completed"; 759b47452b2SAsmitha Karunanithi return task::completed; 7606145ed6fSAsmitha Karunanithi } 761a43be80fSAsmitha Karunanithi return task::completed; 762a43be80fSAsmitha Karunanithi }, 7634978b63fSJason M. Bills "type='signal',interface='org.freedesktop.DBus.ObjectManager'," 764a43be80fSAsmitha Karunanithi "member='InterfacesAdded', " 765a43be80fSAsmitha Karunanithi "path='/xyz/openbmc_project/dump'"); 766a43be80fSAsmitha Karunanithi 767a43be80fSAsmitha Karunanithi task->startTimer(std::chrono::minutes(3)); 768a43be80fSAsmitha Karunanithi task->populateResp(asyncResp->res); 76998be3e39SEd Tanous task->payload.emplace(std::move(payload)); 770a43be80fSAsmitha Karunanithi } 771a43be80fSAsmitha Karunanithi 7728d1b46d7Szhanghch05 inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7738d1b46d7Szhanghch05 const crow::Request& req, const std::string& dumpType) 774a43be80fSAsmitha Karunanithi { 775a43be80fSAsmitha Karunanithi 776a43be80fSAsmitha Karunanithi std::string dumpPath; 777a43be80fSAsmitha Karunanithi if (dumpType == "BMC") 778a43be80fSAsmitha Karunanithi { 779a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 780a43be80fSAsmitha Karunanithi } 781a43be80fSAsmitha Karunanithi else if (dumpType == "System") 782a43be80fSAsmitha Karunanithi { 783a43be80fSAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 784a43be80fSAsmitha Karunanithi } 785a43be80fSAsmitha Karunanithi else 786a43be80fSAsmitha Karunanithi { 787a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType; 788a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 789a43be80fSAsmitha Karunanithi return; 790a43be80fSAsmitha Karunanithi } 791a43be80fSAsmitha Karunanithi 792a43be80fSAsmitha Karunanithi std::optional<std::string> diagnosticDataType; 793a43be80fSAsmitha Karunanithi std::optional<std::string> oemDiagnosticDataType; 794a43be80fSAsmitha Karunanithi 79515ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 796a43be80fSAsmitha Karunanithi req, asyncResp->res, "DiagnosticDataType", diagnosticDataType, 797a43be80fSAsmitha Karunanithi "OEMDiagnosticDataType", oemDiagnosticDataType)) 798a43be80fSAsmitha Karunanithi { 799a43be80fSAsmitha Karunanithi return; 800a43be80fSAsmitha Karunanithi } 801a43be80fSAsmitha Karunanithi 802a43be80fSAsmitha Karunanithi if (dumpType == "System") 803a43be80fSAsmitha Karunanithi { 804a43be80fSAsmitha Karunanithi if (!oemDiagnosticDataType || !diagnosticDataType) 805a43be80fSAsmitha Karunanithi { 8064978b63fSJason M. Bills BMCWEB_LOG_ERROR 8074978b63fSJason M. Bills << "CreateDump action parameter 'DiagnosticDataType'/'OEMDiagnosticDataType' value not found!"; 808a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 809a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", 810a43be80fSAsmitha Karunanithi "DiagnosticDataType & OEMDiagnosticDataType"); 811a43be80fSAsmitha Karunanithi return; 812a43be80fSAsmitha Karunanithi } 8133174e4dfSEd Tanous if ((*oemDiagnosticDataType != "System") || 814a43be80fSAsmitha Karunanithi (*diagnosticDataType != "OEM")) 815a43be80fSAsmitha Karunanithi { 816a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "Wrong parameter values passed"; 817*ace85d60SEd Tanous messages::internalError(asyncResp->res); 818a43be80fSAsmitha Karunanithi return; 819a43be80fSAsmitha Karunanithi } 820a43be80fSAsmitha Karunanithi } 821a43be80fSAsmitha Karunanithi else if (dumpType == "BMC") 822a43be80fSAsmitha Karunanithi { 823a43be80fSAsmitha Karunanithi if (!diagnosticDataType) 824a43be80fSAsmitha Karunanithi { 8250fda0f12SGeorge Liu BMCWEB_LOG_ERROR 8260fda0f12SGeorge Liu << "CreateDump action parameter 'DiagnosticDataType' not found!"; 827a43be80fSAsmitha Karunanithi messages::actionParameterMissing( 828a43be80fSAsmitha Karunanithi asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType"); 829a43be80fSAsmitha Karunanithi return; 830a43be80fSAsmitha Karunanithi } 8313174e4dfSEd Tanous if (*diagnosticDataType != "Manager") 832a43be80fSAsmitha Karunanithi { 833a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR 834a43be80fSAsmitha Karunanithi << "Wrong parameter value passed for 'DiagnosticDataType'"; 835*ace85d60SEd Tanous messages::internalError(asyncResp->res); 836a43be80fSAsmitha Karunanithi return; 837a43be80fSAsmitha Karunanithi } 838a43be80fSAsmitha Karunanithi } 839a43be80fSAsmitha Karunanithi 840a43be80fSAsmitha Karunanithi crow::connections::systemBus->async_method_call( 84198be3e39SEd Tanous [asyncResp, payload(task::Payload(req)), dumpPath, 84298be3e39SEd Tanous dumpType](const boost::system::error_code ec, 84398be3e39SEd Tanous const uint32_t& dumpId) mutable { 844a43be80fSAsmitha Karunanithi if (ec) 845a43be80fSAsmitha Karunanithi { 846a43be80fSAsmitha Karunanithi BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec; 847a43be80fSAsmitha Karunanithi messages::internalError(asyncResp->res); 848a43be80fSAsmitha Karunanithi return; 849a43be80fSAsmitha Karunanithi } 850a43be80fSAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId; 851a43be80fSAsmitha Karunanithi 85298be3e39SEd Tanous createDumpTaskCallback(std::move(payload), asyncResp, dumpId, 85398be3e39SEd Tanous dumpPath, dumpType); 854a43be80fSAsmitha Karunanithi }, 855b47452b2SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", 856b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + 857b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)), 858a43be80fSAsmitha Karunanithi "xyz.openbmc_project.Dump.Create", "CreateDump"); 859a43be80fSAsmitha Karunanithi } 860a43be80fSAsmitha Karunanithi 8618d1b46d7Szhanghch05 inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8628d1b46d7Szhanghch05 const std::string& dumpType) 86380319af1SAsmitha Karunanithi { 864b47452b2SAsmitha Karunanithi std::string dumpTypeLowerCopy = 865b47452b2SAsmitha Karunanithi std::string(boost::algorithm::to_lower_copy(dumpType)); 8668d1b46d7Szhanghch05 86780319af1SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 868b47452b2SAsmitha Karunanithi [asyncResp, dumpType](const boost::system::error_code ec, 86980319af1SAsmitha Karunanithi const std::vector<std::string>& subTreePaths) { 87080319af1SAsmitha Karunanithi if (ec) 87180319af1SAsmitha Karunanithi { 87280319af1SAsmitha Karunanithi BMCWEB_LOG_ERROR << "resp_handler got error " << ec; 87380319af1SAsmitha Karunanithi messages::internalError(asyncResp->res); 87480319af1SAsmitha Karunanithi return; 87580319af1SAsmitha Karunanithi } 87680319af1SAsmitha Karunanithi 87780319af1SAsmitha Karunanithi for (const std::string& path : subTreePaths) 87880319af1SAsmitha Karunanithi { 8792dfd18efSEd Tanous sdbusplus::message::object_path objPath(path); 8802dfd18efSEd Tanous std::string logID = objPath.filename(); 8812dfd18efSEd Tanous if (logID.empty()) 88280319af1SAsmitha Karunanithi { 8832dfd18efSEd Tanous continue; 88480319af1SAsmitha Karunanithi } 8852dfd18efSEd Tanous deleteDumpEntry(asyncResp, logID, dumpType); 88680319af1SAsmitha Karunanithi } 88780319af1SAsmitha Karunanithi }, 88880319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", 88980319af1SAsmitha Karunanithi "/xyz/openbmc_project/object_mapper", 89080319af1SAsmitha Karunanithi "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 891b47452b2SAsmitha Karunanithi "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, 892b47452b2SAsmitha Karunanithi std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." + 893b47452b2SAsmitha Karunanithi dumpType}); 89480319af1SAsmitha Karunanithi } 89580319af1SAsmitha Karunanithi 8967e860f15SJohn Edward Broadbent inline static void parseCrashdumpParameters( 897168e20c1SEd Tanous const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& 898168e20c1SEd Tanous params, 899043a0536SJohnathan Mantey std::string& filename, std::string& timestamp, std::string& logfile) 900043a0536SJohnathan Mantey { 901043a0536SJohnathan Mantey for (auto property : params) 902043a0536SJohnathan Mantey { 903043a0536SJohnathan Mantey if (property.first == "Timestamp") 904043a0536SJohnathan Mantey { 905043a0536SJohnathan Mantey const std::string* value = 9068d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 907043a0536SJohnathan Mantey if (value != nullptr) 908043a0536SJohnathan Mantey { 909043a0536SJohnathan Mantey timestamp = *value; 910043a0536SJohnathan Mantey } 911043a0536SJohnathan Mantey } 912043a0536SJohnathan Mantey else if (property.first == "Filename") 913043a0536SJohnathan Mantey { 914043a0536SJohnathan Mantey const std::string* value = 9158d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 916043a0536SJohnathan Mantey if (value != nullptr) 917043a0536SJohnathan Mantey { 918043a0536SJohnathan Mantey filename = *value; 919043a0536SJohnathan Mantey } 920043a0536SJohnathan Mantey } 921043a0536SJohnathan Mantey else if (property.first == "Log") 922043a0536SJohnathan Mantey { 923043a0536SJohnathan Mantey const std::string* value = 9248d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 925043a0536SJohnathan Mantey if (value != nullptr) 926043a0536SJohnathan Mantey { 927043a0536SJohnathan Mantey logfile = *value; 928043a0536SJohnathan Mantey } 929043a0536SJohnathan Mantey } 930043a0536SJohnathan Mantey } 931043a0536SJohnathan Mantey } 932043a0536SJohnathan Mantey 933a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 9347e860f15SJohn Edward Broadbent inline void requestRoutesSystemLogServiceCollection(App& app) 9351da66f75SEd Tanous { 936c4bf6374SJason M. Bills /** 937c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 938c4bf6374SJason M. Bills */ 9397e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/") 940ed398213SEd Tanous .privileges(redfish::privileges::getLogServiceCollection) 9417e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 9427e860f15SJohn Edward Broadbent [](const crow::Request&, 9437e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 9447e860f15SJohn Edward Broadbent 945c4bf6374SJason M. Bills { 9467e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 9477e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 948c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 949c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 950c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 951029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 9527e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 9537e860f15SJohn Edward Broadbent "System Log Services Collection"; 954c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 955c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 9567e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 9577e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 958c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 959029573d4SEd Tanous logServiceArray.push_back( 9607e860f15SJohn Edward Broadbent {{"@odata.id", 9617e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog"}}); 9625cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 963c9bb6861Sraviteja-b logServiceArray.push_back( 9647e860f15SJohn Edward Broadbent {{"@odata.id", 9657e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump"}}); 966c9bb6861Sraviteja-b #endif 967c9bb6861Sraviteja-b 968d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 969d53dd41fSJason M. Bills logServiceArray.push_back( 970cb92c03bSAndrew Geissler {{"@odata.id", 971424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 972d53dd41fSJason M. Bills #endif 973b7028ebfSSpencer Ku 974b7028ebfSSpencer Ku #ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER 975b7028ebfSSpencer Ku logServiceArray.push_back( 976b7028ebfSSpencer Ku {{"@odata.id", 977b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"}}); 978b7028ebfSSpencer Ku #endif 979c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 980c4bf6374SJason M. Bills logServiceArray.size(); 981a3316fc6SZhikuiRen 982a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 983a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 984a3316fc6SZhikuiRen const std::vector<std::string>& subtreePath) { 985a3316fc6SZhikuiRen if (ec) 986a3316fc6SZhikuiRen { 987a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 988a3316fc6SZhikuiRen return; 989a3316fc6SZhikuiRen } 990a3316fc6SZhikuiRen 991a3316fc6SZhikuiRen for (auto& pathStr : subtreePath) 992a3316fc6SZhikuiRen { 993a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 994a3316fc6SZhikuiRen { 99523a21a1cSEd Tanous nlohmann::json& logServiceArrayLocal = 996a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 99723a21a1cSEd Tanous logServiceArrayLocal.push_back( 9980fda0f12SGeorge Liu {{"@odata.id", 9990fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes"}}); 10007e860f15SJohn Edward Broadbent asyncResp->res 10017e860f15SJohn Edward Broadbent .jsonValue["Members@odata.count"] = 100223a21a1cSEd Tanous logServiceArrayLocal.size(); 1003a3316fc6SZhikuiRen return; 1004a3316fc6SZhikuiRen } 1005a3316fc6SZhikuiRen } 1006a3316fc6SZhikuiRen }, 1007a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 1008a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 10097e860f15SJohn Edward Broadbent "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 10107e860f15SJohn Edward Broadbent 0, std::array<const char*, 1>{postCodeIface}); 10117e860f15SJohn Edward Broadbent }); 1012c4bf6374SJason M. Bills } 1013c4bf6374SJason M. Bills 10147e860f15SJohn Edward Broadbent inline void requestRoutesEventLogService(App& app) 1015c4bf6374SJason M. Bills { 10167e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 1017ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 10187e860f15SJohn Edward Broadbent .methods( 10197e860f15SJohn Edward Broadbent boost::beast::http::verb:: 10207e860f15SJohn Edward Broadbent get)([](const crow::Request&, 10217e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1022c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1023029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 1024c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1025c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 1026c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 10277e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 10287e860f15SJohn Edward Broadbent "System Event Log Service"; 1029c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 1030c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 10317c8c4058STejas Patil 10327c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 10337c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 10347c8c4058STejas Patil 10357c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 10367c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 10377c8c4058STejas Patil redfishDateTimeOffset.second; 10387c8c4058STejas Patil 1039c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1040c4bf6374SJason M. Bills {"@odata.id", 1041029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 1042e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1043e7d6c8b2SGunnar Mills 10440fda0f12SGeorge Liu {"target", 10450fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog"}}; 10467e860f15SJohn Edward Broadbent }); 1047489640c6SJason M. Bills } 1048489640c6SJason M. Bills 10497e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogClear(App& app) 1050489640c6SJason M. Bills { 10514978b63fSJason M. Bills BMCWEB_ROUTE( 10524978b63fSJason M. Bills app, 10534978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/") 1054432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 10557e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 10567e860f15SJohn Edward Broadbent [](const crow::Request&, 10577e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1058489640c6SJason M. Bills // Clear the EventLog by deleting the log files 1059489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1060489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 1061489640c6SJason M. Bills { 1062489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 1063489640c6SJason M. Bills { 1064489640c6SJason M. Bills std::error_code ec; 1065489640c6SJason M. Bills std::filesystem::remove(file, ec); 1066489640c6SJason M. Bills } 1067489640c6SJason M. Bills } 1068489640c6SJason M. Bills 1069489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 1070489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 1071489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 1072489640c6SJason M. Bills if (ec) 1073489640c6SJason M. Bills { 10747e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " 10757e860f15SJohn Edward Broadbent << ec; 1076489640c6SJason M. Bills messages::internalError(asyncResp->res); 1077489640c6SJason M. Bills return; 1078489640c6SJason M. Bills } 1079489640c6SJason M. Bills 1080489640c6SJason M. Bills messages::success(asyncResp->res); 1081489640c6SJason M. Bills }, 1082489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 10837e860f15SJohn Edward Broadbent "org.freedesktop.systemd1.Manager", "ReloadUnit", 10847e860f15SJohn Edward Broadbent "rsyslog.service", "replace"); 10857e860f15SJohn Edward Broadbent }); 1086c4bf6374SJason M. Bills } 1087c4bf6374SJason M. Bills 108895820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 1089b5a76932SEd Tanous const std::string& logEntry, 109095820184SJason M. Bills nlohmann::json& logEntryJson) 1091c4bf6374SJason M. Bills { 109295820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 1093cd225da8SJason M. Bills // First get the Timestamp 1094f23b7296SEd Tanous size_t space = logEntry.find_first_of(' '); 1095cd225da8SJason M. Bills if (space == std::string::npos) 109695820184SJason M. Bills { 109795820184SJason M. Bills return 1; 109895820184SJason M. Bills } 1099cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 1100cd225da8SJason M. Bills // Then get the log contents 1101f23b7296SEd Tanous size_t entryStart = logEntry.find_first_not_of(' ', space); 1102cd225da8SJason M. Bills if (entryStart == std::string::npos) 1103cd225da8SJason M. Bills { 1104cd225da8SJason M. Bills return 1; 1105cd225da8SJason M. Bills } 1106cd225da8SJason M. Bills std::string_view entry(logEntry); 1107cd225da8SJason M. Bills entry.remove_prefix(entryStart); 1108cd225da8SJason M. Bills // Use split to separate the entry into its fields 1109cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 1110cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 1111cd225da8SJason M. Bills boost::token_compress_on); 1112cd225da8SJason M. Bills // We need at least a MessageId to be valid 111326f6976fSEd Tanous if (logEntryFields.empty()) 1114cd225da8SJason M. Bills { 1115cd225da8SJason M. Bills return 1; 1116cd225da8SJason M. Bills } 1117cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 111895820184SJason M. Bills 11194851d45dSJason M. Bills // Get the Message from the MessageRegistry 11204851d45dSJason M. Bills const message_registries::Message* message = 11214851d45dSJason M. Bills message_registries::getMessage(messageID); 1122c4bf6374SJason M. Bills 11234851d45dSJason M. Bills std::string msg; 11244851d45dSJason M. Bills std::string severity; 11254851d45dSJason M. Bills if (message != nullptr) 1126c4bf6374SJason M. Bills { 11274851d45dSJason M. Bills msg = message->message; 11284851d45dSJason M. Bills severity = message->severity; 1129c4bf6374SJason M. Bills } 1130c4bf6374SJason M. Bills 113115a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 113226702d01SEd Tanous std::span<std::string> messageArgs; 113315a86ff6SJason M. Bills if (logEntryFields.size() > 1) 113415a86ff6SJason M. Bills { 113515a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 113615a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 113715a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 113815a86ff6SJason M. Bills if (!messageArgsStart.empty()) 113915a86ff6SJason M. Bills { 114015a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 114115a86ff6SJason M. Bills } 114215a86ff6SJason M. Bills 114323a21a1cSEd Tanous messageArgs = {&messageArgsStart, messageArgsSize}; 1144c4bf6374SJason M. Bills 11454851d45dSJason M. Bills // Fill the MessageArgs into the Message 114695820184SJason M. Bills int i = 0; 114795820184SJason M. Bills for (const std::string& messageArg : messageArgs) 11484851d45dSJason M. Bills { 114995820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 11504851d45dSJason M. Bills size_t argPos = msg.find(argStr); 11514851d45dSJason M. Bills if (argPos != std::string::npos) 11524851d45dSJason M. Bills { 115395820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 11544851d45dSJason M. Bills } 11554851d45dSJason M. Bills } 115615a86ff6SJason M. Bills } 11574851d45dSJason M. Bills 115895820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 115995820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 116095820184SJason M. Bills // between the '.' and the '+', so just remove them. 1161f23b7296SEd Tanous std::size_t dot = timestamp.find_first_of('.'); 1162f23b7296SEd Tanous std::size_t plus = timestamp.find_first_of('+'); 116395820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1164c4bf6374SJason M. Bills { 116595820184SJason M. Bills timestamp.erase(dot, plus - dot); 1166c4bf6374SJason M. Bills } 1167c4bf6374SJason M. Bills 1168c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 116995820184SJason M. Bills logEntryJson = { 1170647b3cdcSGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 1171029573d4SEd Tanous {"@odata.id", 1172897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 117395820184SJason M. Bills logEntryID}, 1174c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 117595820184SJason M. Bills {"Id", logEntryID}, 117695820184SJason M. Bills {"Message", std::move(msg)}, 117795820184SJason M. Bills {"MessageId", std::move(messageID)}, 1178f23b7296SEd Tanous {"MessageArgs", messageArgs}, 1179c4bf6374SJason M. Bills {"EntryType", "Event"}, 118095820184SJason M. Bills {"Severity", std::move(severity)}, 118195820184SJason M. Bills {"Created", std::move(timestamp)}}; 1182c4bf6374SJason M. Bills return 0; 1183c4bf6374SJason M. Bills } 1184c4bf6374SJason M. Bills 11857e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntryCollection(App& app) 1186c4bf6374SJason M. Bills { 11877e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 11887e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 11898b6a35f0SGunnar Mills .privileges(redfish::privileges::getLogEntryCollection) 11904978b63fSJason M. Bills .methods( 11914978b63fSJason M. Bills boost::beast::http::verb:: 11924978b63fSJason M. Bills get)([](const crow::Request& req, 11937e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1194271584abSEd Tanous uint64_t skip = 0; 1195271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 11968d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 1197c4bf6374SJason M. Bills { 1198c4bf6374SJason M. Bills return; 1199c4bf6374SJason M. Bills } 12008d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 1201c4bf6374SJason M. Bills { 1202c4bf6374SJason M. Bills return; 1203c4bf6374SJason M. Bills } 12047e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 12057e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 1206c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1207c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1208c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1209029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1210c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1211c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1212c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1213cb92c03bSAndrew Geissler 12144978b63fSJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1215c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 12167e860f15SJohn Edward Broadbent // Go through the log files and create a unique ID for each 12177e860f15SJohn Edward Broadbent // entry 121895820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 121995820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1220b01bf299SEd Tanous uint64_t entryCount = 0; 1221cd225da8SJason M. Bills std::string logEntry; 122295820184SJason M. Bills 12237e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12247e860f15SJohn Edward Broadbent // backwards 12257e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 12267e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1227c4bf6374SJason M. Bills { 1228cd225da8SJason M. Bills std::ifstream logStream(*it); 122995820184SJason M. Bills if (!logStream.is_open()) 1230c4bf6374SJason M. Bills { 1231c4bf6374SJason M. Bills continue; 1232c4bf6374SJason M. Bills } 1233c4bf6374SJason M. Bills 1234e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1235e85d6b16SJason M. Bills bool firstEntry = true; 123695820184SJason M. Bills while (std::getline(logStream, logEntry)) 123795820184SJason M. Bills { 1238c4bf6374SJason M. Bills entryCount++; 12397e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip 12407e860f15SJohn Edward Broadbent // from the start) and top (number of entries to 12417e860f15SJohn Edward Broadbent // display) 1242c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1243c4bf6374SJason M. Bills { 1244c4bf6374SJason M. Bills continue; 1245c4bf6374SJason M. Bills } 1246c4bf6374SJason M. Bills 1247c4bf6374SJason M. Bills std::string idStr; 1248e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1249c4bf6374SJason M. Bills { 1250c4bf6374SJason M. Bills continue; 1251c4bf6374SJason M. Bills } 1252c4bf6374SJason M. Bills 1253e85d6b16SJason M. Bills if (firstEntry) 1254e85d6b16SJason M. Bills { 1255e85d6b16SJason M. Bills firstEntry = false; 1256e85d6b16SJason M. Bills } 1257e85d6b16SJason M. Bills 1258c4bf6374SJason M. Bills logEntryArray.push_back({}); 1259c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 12604978b63fSJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 12614978b63fSJason M. Bills 0) 1262c4bf6374SJason M. Bills { 1263c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1264c4bf6374SJason M. Bills return; 1265c4bf6374SJason M. Bills } 1266c4bf6374SJason M. Bills } 126795820184SJason M. Bills } 1268c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1269c4bf6374SJason M. Bills if (skip + top < entryCount) 1270c4bf6374SJason M. Bills { 1271c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 12724978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries?$skip=" + 1273c4bf6374SJason M. Bills std::to_string(skip + top); 1274c4bf6374SJason M. Bills } 12757e860f15SJohn Edward Broadbent }); 1276897967deSJason M. Bills } 1277897967deSJason M. Bills 12787e860f15SJohn Edward Broadbent inline void requestRoutesJournalEventLogEntry(App& app) 1279897967deSJason M. Bills { 12807e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 12817e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1282ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 12837e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 12847e860f15SJohn Edward Broadbent [](const crow::Request&, 12857e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12867e860f15SJohn Edward Broadbent const std::string& param) { 12877e860f15SJohn Edward Broadbent const std::string& targetID = param; 12888d1b46d7Szhanghch05 12897e860f15SJohn Edward Broadbent // Go through the log files and check the unique ID for each 12907e860f15SJohn Edward Broadbent // entry to find the target entry 1291897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1292897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1293897967deSJason M. Bills std::string logEntry; 1294897967deSJason M. Bills 12957e860f15SJohn Edward Broadbent // Oldest logs are in the last file, so start there and loop 12967e860f15SJohn Edward Broadbent // backwards 12977e860f15SJohn Edward Broadbent for (auto it = redfishLogFiles.rbegin(); 12987e860f15SJohn Edward Broadbent it < redfishLogFiles.rend(); it++) 1299897967deSJason M. Bills { 1300897967deSJason M. Bills std::ifstream logStream(*it); 1301897967deSJason M. Bills if (!logStream.is_open()) 1302897967deSJason M. Bills { 1303897967deSJason M. Bills continue; 1304897967deSJason M. Bills } 1305897967deSJason M. Bills 1306897967deSJason M. Bills // Reset the unique ID on the first entry 1307897967deSJason M. Bills bool firstEntry = true; 1308897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1309897967deSJason M. Bills { 1310897967deSJason M. Bills std::string idStr; 1311897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1312897967deSJason M. Bills { 1313897967deSJason M. Bills continue; 1314897967deSJason M. Bills } 1315897967deSJason M. Bills 1316897967deSJason M. Bills if (firstEntry) 1317897967deSJason M. Bills { 1318897967deSJason M. Bills firstEntry = false; 1319897967deSJason M. Bills } 1320897967deSJason M. Bills 1321897967deSJason M. Bills if (idStr == targetID) 1322897967deSJason M. Bills { 13237e860f15SJohn Edward Broadbent if (fillEventLogEntryJson( 13247e860f15SJohn Edward Broadbent idStr, logEntry, 1325897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1326897967deSJason M. Bills { 1327897967deSJason M. Bills messages::internalError(asyncResp->res); 1328897967deSJason M. Bills return; 1329897967deSJason M. Bills } 1330897967deSJason M. Bills return; 1331897967deSJason M. Bills } 1332897967deSJason M. Bills } 1333897967deSJason M. Bills } 1334897967deSJason M. Bills // Requested ID was not found 1335*ace85d60SEd Tanous messages::resourceMissingAtURI( 1336*ace85d60SEd Tanous asyncResp->res, crow::utility::urlFromPieces(targetID)); 13377e860f15SJohn Edward Broadbent }); 133808a4e4b5SAnthony Wilson } 133908a4e4b5SAnthony Wilson 13407e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryCollection(App& app) 134108a4e4b5SAnthony Wilson { 13427e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 13437e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1344ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 13457e860f15SJohn Edward Broadbent .methods( 13467e860f15SJohn Edward Broadbent boost::beast::http::verb:: 13477e860f15SJohn Edward Broadbent get)([](const crow::Request&, 13487e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 13497e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 13507e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 135108a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 135208a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 135308a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 135408a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 135508a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 135608a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 135708a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 135808a4e4b5SAnthony Wilson 1359cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1360cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1361cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1362cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1363914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& resp) { 1364cb92c03bSAndrew Geissler if (ec) 1365cb92c03bSAndrew Geissler { 1366cb92c03bSAndrew Geissler // TODO Handle for specific error code 1367cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1368cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1369cb92c03bSAndrew Geissler << ec; 1370cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1371cb92c03bSAndrew Geissler return; 1372cb92c03bSAndrew Geissler } 1373cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1374cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1375cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 13769eb808c1SEd Tanous for (const auto& objectPath : resp) 1377cb92c03bSAndrew Geissler { 1378914e2d5dSEd Tanous const uint32_t* id = nullptr; 1379c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1380c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1381914e2d5dSEd Tanous const std::string* severity = nullptr; 1382914e2d5dSEd Tanous const std::string* message = nullptr; 1383914e2d5dSEd Tanous const std::string* filePath = nullptr; 138475710de2SXiaochao Ma bool resolved = false; 13859eb808c1SEd Tanous for (const auto& interfaceMap : objectPath.second) 1386f86bb901SAdriana Kobylak { 1387f86bb901SAdriana Kobylak if (interfaceMap.first == 1388f86bb901SAdriana Kobylak "xyz.openbmc_project.Logging.Entry") 1389f86bb901SAdriana Kobylak { 13909eb808c1SEd Tanous for (const auto& propertyMap : 13919eb808c1SEd Tanous interfaceMap.second) 1392cb92c03bSAndrew Geissler { 1393cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1394cb92c03bSAndrew Geissler { 1395f86bb901SAdriana Kobylak id = std::get_if<uint32_t>( 1396f86bb901SAdriana Kobylak &propertyMap.second); 1397cb92c03bSAndrew Geissler } 1398cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1399cb92c03bSAndrew Geissler { 1400c419c759SEd Tanous timestamp = std::get_if<uint64_t>( 1401f86bb901SAdriana Kobylak &propertyMap.second); 14027e860f15SJohn Edward Broadbent } 14037e860f15SJohn Edward Broadbent else if (propertyMap.first == 14047e860f15SJohn Edward Broadbent "UpdateTimestamp") 14057e860f15SJohn Edward Broadbent { 1406c419c759SEd Tanous updateTimestamp = std::get_if<uint64_t>( 14077e860f15SJohn Edward Broadbent &propertyMap.second); 14087e860f15SJohn Edward Broadbent } 14097e860f15SJohn Edward Broadbent else if (propertyMap.first == "Severity") 14107e860f15SJohn Edward Broadbent { 14117e860f15SJohn Edward Broadbent severity = std::get_if<std::string>( 14127e860f15SJohn Edward Broadbent &propertyMap.second); 14137e860f15SJohn Edward Broadbent } 14147e860f15SJohn Edward Broadbent else if (propertyMap.first == "Message") 14157e860f15SJohn Edward Broadbent { 14167e860f15SJohn Edward Broadbent message = std::get_if<std::string>( 14177e860f15SJohn Edward Broadbent &propertyMap.second); 14187e860f15SJohn Edward Broadbent } 14197e860f15SJohn Edward Broadbent else if (propertyMap.first == "Resolved") 14207e860f15SJohn Edward Broadbent { 1421914e2d5dSEd Tanous const bool* resolveptr = 1422914e2d5dSEd Tanous std::get_if<bool>( 14237e860f15SJohn Edward Broadbent &propertyMap.second); 14247e860f15SJohn Edward Broadbent if (resolveptr == nullptr) 14257e860f15SJohn Edward Broadbent { 14267e860f15SJohn Edward Broadbent messages::internalError( 14277e860f15SJohn Edward Broadbent asyncResp->res); 14287e860f15SJohn Edward Broadbent return; 14297e860f15SJohn Edward Broadbent } 14307e860f15SJohn Edward Broadbent resolved = *resolveptr; 14317e860f15SJohn Edward Broadbent } 14327e860f15SJohn Edward Broadbent } 14337e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 14347e860f15SJohn Edward Broadbent severity == nullptr) 14357e860f15SJohn Edward Broadbent { 14367e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 14377e860f15SJohn Edward Broadbent return; 14387e860f15SJohn Edward Broadbent } 14397e860f15SJohn Edward Broadbent } 14407e860f15SJohn Edward Broadbent else if (interfaceMap.first == 14417e860f15SJohn Edward Broadbent "xyz.openbmc_project.Common.FilePath") 14427e860f15SJohn Edward Broadbent { 14439eb808c1SEd Tanous for (const auto& propertyMap : 14449eb808c1SEd Tanous interfaceMap.second) 14457e860f15SJohn Edward Broadbent { 14467e860f15SJohn Edward Broadbent if (propertyMap.first == "Path") 14477e860f15SJohn Edward Broadbent { 14487e860f15SJohn Edward Broadbent filePath = std::get_if<std::string>( 14497e860f15SJohn Edward Broadbent &propertyMap.second); 14507e860f15SJohn Edward Broadbent } 14517e860f15SJohn Edward Broadbent } 14527e860f15SJohn Edward Broadbent } 14537e860f15SJohn Edward Broadbent } 14547e860f15SJohn Edward Broadbent // Object path without the 14557e860f15SJohn Edward Broadbent // xyz.openbmc_project.Logging.Entry interface, ignore 14567e860f15SJohn Edward Broadbent // and continue. 14577e860f15SJohn Edward Broadbent if (id == nullptr || message == nullptr || 1458c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1459c419c759SEd Tanous updateTimestamp == nullptr) 14607e860f15SJohn Edward Broadbent { 14617e860f15SJohn Edward Broadbent continue; 14627e860f15SJohn Edward Broadbent } 14637e860f15SJohn Edward Broadbent entriesArray.push_back({}); 14647e860f15SJohn Edward Broadbent nlohmann::json& thisEntry = entriesArray.back(); 14657e860f15SJohn Edward Broadbent thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry"; 14667e860f15SJohn Edward Broadbent thisEntry["@odata.id"] = 14670fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 14687e860f15SJohn Edward Broadbent std::to_string(*id); 14697e860f15SJohn Edward Broadbent thisEntry["Name"] = "System Event Log Entry"; 14707e860f15SJohn Edward Broadbent thisEntry["Id"] = std::to_string(*id); 14717e860f15SJohn Edward Broadbent thisEntry["Message"] = *message; 14727e860f15SJohn Edward Broadbent thisEntry["Resolved"] = resolved; 14737e860f15SJohn Edward Broadbent thisEntry["EntryType"] = "Event"; 14747e860f15SJohn Edward Broadbent thisEntry["Severity"] = 14757e860f15SJohn Edward Broadbent translateSeverityDbusToRedfish(*severity); 14767e860f15SJohn Edward Broadbent thisEntry["Created"] = 1477c419c759SEd Tanous crow::utility::getDateTimeUintMs(*timestamp); 14787e860f15SJohn Edward Broadbent thisEntry["Modified"] = 1479c419c759SEd Tanous crow::utility::getDateTimeUintMs(*updateTimestamp); 14807e860f15SJohn Edward Broadbent if (filePath != nullptr) 14817e860f15SJohn Edward Broadbent { 14827e860f15SJohn Edward Broadbent thisEntry["AdditionalDataURI"] = 14830fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 14847e860f15SJohn Edward Broadbent std::to_string(*id) + "/attachment"; 14857e860f15SJohn Edward Broadbent } 14867e860f15SJohn Edward Broadbent } 14877e860f15SJohn Edward Broadbent std::sort(entriesArray.begin(), entriesArray.end(), 14887e860f15SJohn Edward Broadbent [](const nlohmann::json& left, 14897e860f15SJohn Edward Broadbent const nlohmann::json& right) { 14907e860f15SJohn Edward Broadbent return (left["Id"] <= right["Id"]); 14917e860f15SJohn Edward Broadbent }); 14927e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = 14937e860f15SJohn Edward Broadbent entriesArray.size(); 14947e860f15SJohn Edward Broadbent }, 14957e860f15SJohn Edward Broadbent "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 14967e860f15SJohn Edward Broadbent "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 14977e860f15SJohn Edward Broadbent }); 14987e860f15SJohn Edward Broadbent } 14997e860f15SJohn Edward Broadbent 15007e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntry(App& app) 15017e860f15SJohn Edward Broadbent { 15027e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 15037e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1504ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 15057e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 15067e860f15SJohn Edward Broadbent [](const crow::Request&, 15077e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 15087e860f15SJohn Edward Broadbent const std::string& param) 15097e860f15SJohn Edward Broadbent 15107e860f15SJohn Edward Broadbent { 15117e860f15SJohn Edward Broadbent std::string entryID = param; 15127e860f15SJohn Edward Broadbent dbus::utility::escapePathForDbus(entryID); 15137e860f15SJohn Edward Broadbent 15147e860f15SJohn Edward Broadbent // DBus implementation of EventLog/Entries 15157e860f15SJohn Edward Broadbent // Make call to Logging Service to find all log entry objects 15167e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 15177e860f15SJohn Edward Broadbent [asyncResp, entryID](const boost::system::error_code ec, 1518914e2d5dSEd Tanous const GetManagedPropertyType& resp) { 15197e860f15SJohn Edward Broadbent if (ec.value() == EBADR) 15207e860f15SJohn Edward Broadbent { 15217e860f15SJohn Edward Broadbent messages::resourceNotFound( 15227e860f15SJohn Edward Broadbent asyncResp->res, "EventLogEntry", entryID); 15237e860f15SJohn Edward Broadbent return; 15247e860f15SJohn Edward Broadbent } 15257e860f15SJohn Edward Broadbent if (ec) 15267e860f15SJohn Edward Broadbent { 15270fda0f12SGeorge Liu BMCWEB_LOG_ERROR 15280fda0f12SGeorge Liu << "EventLogEntry (DBus) resp_handler got error " 15297e860f15SJohn Edward Broadbent << ec; 15307e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 15317e860f15SJohn Edward Broadbent return; 15327e860f15SJohn Edward Broadbent } 1533914e2d5dSEd Tanous const uint32_t* id = nullptr; 1534c419c759SEd Tanous const uint64_t* timestamp = nullptr; 1535c419c759SEd Tanous const uint64_t* updateTimestamp = nullptr; 1536914e2d5dSEd Tanous const std::string* severity = nullptr; 1537914e2d5dSEd Tanous const std::string* message = nullptr; 1538914e2d5dSEd Tanous const std::string* filePath = nullptr; 15397e860f15SJohn Edward Broadbent bool resolved = false; 15407e860f15SJohn Edward Broadbent 15419eb808c1SEd Tanous for (const auto& propertyMap : resp) 15427e860f15SJohn Edward Broadbent { 15437e860f15SJohn Edward Broadbent if (propertyMap.first == "Id") 15447e860f15SJohn Edward Broadbent { 15457e860f15SJohn Edward Broadbent id = std::get_if<uint32_t>(&propertyMap.second); 15467e860f15SJohn Edward Broadbent } 15477e860f15SJohn Edward Broadbent else if (propertyMap.first == "Timestamp") 15487e860f15SJohn Edward Broadbent { 1549c419c759SEd Tanous timestamp = 15507e860f15SJohn Edward Broadbent std::get_if<uint64_t>(&propertyMap.second); 1551ebd45906SGeorge Liu } 1552d139c236SGeorge Liu else if (propertyMap.first == "UpdateTimestamp") 1553d139c236SGeorge Liu { 1554ebd45906SGeorge Liu updateTimestamp = 1555c419c759SEd Tanous std::get_if<uint64_t>(&propertyMap.second); 1556ebd45906SGeorge Liu } 1557cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1558cb92c03bSAndrew Geissler { 1559cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1560cb92c03bSAndrew Geissler &propertyMap.second); 1561cb92c03bSAndrew Geissler } 1562cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1563cb92c03bSAndrew Geissler { 1564cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1565cb92c03bSAndrew Geissler &propertyMap.second); 1566ae34c8e8SAdriana Kobylak } 156775710de2SXiaochao Ma else if (propertyMap.first == "Resolved") 156875710de2SXiaochao Ma { 1569914e2d5dSEd Tanous const bool* resolveptr = 157075710de2SXiaochao Ma std::get_if<bool>(&propertyMap.second); 157175710de2SXiaochao Ma if (resolveptr == nullptr) 157275710de2SXiaochao Ma { 157375710de2SXiaochao Ma messages::internalError(asyncResp->res); 157475710de2SXiaochao Ma return; 157575710de2SXiaochao Ma } 157675710de2SXiaochao Ma resolved = *resolveptr; 157775710de2SXiaochao Ma } 15787e860f15SJohn Edward Broadbent else if (propertyMap.first == "Path") 1579f86bb901SAdriana Kobylak { 1580f86bb901SAdriana Kobylak filePath = std::get_if<std::string>( 1581f86bb901SAdriana Kobylak &propertyMap.second); 1582f86bb901SAdriana Kobylak } 1583f86bb901SAdriana Kobylak } 1584f86bb901SAdriana Kobylak if (id == nullptr || message == nullptr || 1585c419c759SEd Tanous severity == nullptr || timestamp == nullptr || 1586c419c759SEd Tanous updateTimestamp == nullptr) 1587f86bb901SAdriana Kobylak { 1588ae34c8e8SAdriana Kobylak messages::internalError(asyncResp->res); 1589271584abSEd Tanous return; 1590271584abSEd Tanous } 1591f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.type"] = 1592f86bb901SAdriana Kobylak "#LogEntry.v1_8_0.LogEntry"; 1593f86bb901SAdriana Kobylak asyncResp->res.jsonValue["@odata.id"] = 15940fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 1595f86bb901SAdriana Kobylak std::to_string(*id); 15967e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 15977e860f15SJohn Edward Broadbent "System Event Log Entry"; 1598f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Id"] = std::to_string(*id); 1599f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Message"] = *message; 1600f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Resolved"] = resolved; 1601f86bb901SAdriana Kobylak asyncResp->res.jsonValue["EntryType"] = "Event"; 1602f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Severity"] = 1603f86bb901SAdriana Kobylak translateSeverityDbusToRedfish(*severity); 1604f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Created"] = 1605c419c759SEd Tanous crow::utility::getDateTimeUintMs(*timestamp); 1606f86bb901SAdriana Kobylak asyncResp->res.jsonValue["Modified"] = 1607c419c759SEd Tanous crow::utility::getDateTimeUintMs(*updateTimestamp); 1608f86bb901SAdriana Kobylak if (filePath != nullptr) 1609f86bb901SAdriana Kobylak { 1610f86bb901SAdriana Kobylak asyncResp->res.jsonValue["AdditionalDataURI"] = 16110fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/attachment/" + 16127e860f15SJohn Edward Broadbent std::to_string(*id); 1613f86bb901SAdriana Kobylak } 1614cb92c03bSAndrew Geissler }, 1615cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1616cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1617f86bb901SAdriana Kobylak "org.freedesktop.DBus.Properties", "GetAll", ""); 16187e860f15SJohn Edward Broadbent }); 1619336e96c6SChicago Duan 16207e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16217e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1622ed398213SEd Tanous .privileges(redfish::privileges::patchLogEntry) 16237e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 16247e860f15SJohn Edward Broadbent [](const crow::Request& req, 16257e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16267e860f15SJohn Edward Broadbent const std::string& entryId) { 162775710de2SXiaochao Ma std::optional<bool> resolved; 162875710de2SXiaochao Ma 162915ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved", 16307e860f15SJohn Edward Broadbent resolved)) 163175710de2SXiaochao Ma { 163275710de2SXiaochao Ma return; 163375710de2SXiaochao Ma } 163475710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "Set Resolved"; 163575710de2SXiaochao Ma 163675710de2SXiaochao Ma crow::connections::systemBus->async_method_call( 16374f48d5f6SEd Tanous [asyncResp, entryId](const boost::system::error_code ec) { 163875710de2SXiaochao Ma if (ec) 163975710de2SXiaochao Ma { 164075710de2SXiaochao Ma BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 164175710de2SXiaochao Ma messages::internalError(asyncResp->res); 164275710de2SXiaochao Ma return; 164375710de2SXiaochao Ma } 164475710de2SXiaochao Ma }, 164575710de2SXiaochao Ma "xyz.openbmc_project.Logging", 164675710de2SXiaochao Ma "/xyz/openbmc_project/logging/entry/" + entryId, 164775710de2SXiaochao Ma "org.freedesktop.DBus.Properties", "Set", 164875710de2SXiaochao Ma "xyz.openbmc_project.Logging.Entry", "Resolved", 1649168e20c1SEd Tanous dbus::utility::DbusVariantType(*resolved)); 16507e860f15SJohn Edward Broadbent }); 165175710de2SXiaochao Ma 16527e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 16537e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/") 1654ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 1655ed398213SEd Tanous 16567e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 16577e860f15SJohn Edward Broadbent [](const crow::Request&, 16587e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16597e860f15SJohn Edward Broadbent const std::string& param) 16607e860f15SJohn Edward Broadbent 1661336e96c6SChicago Duan { 1662336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1663336e96c6SChicago Duan 16647e860f15SJohn Edward Broadbent std::string entryID = param; 1665336e96c6SChicago Duan 1666336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1667336e96c6SChicago Duan 1668336e96c6SChicago Duan // Process response from Logging service. 16697e860f15SJohn Edward Broadbent auto respHandler = [asyncResp, entryID]( 16707e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 16717e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 16727e860f15SJohn Edward Broadbent << "EventLogEntry (DBus) doDelete callback: Done"; 1673336e96c6SChicago Duan if (ec) 1674336e96c6SChicago Duan { 16753de8d8baSGeorge Liu if (ec.value() == EBADR) 16763de8d8baSGeorge Liu { 16777e860f15SJohn Edward Broadbent messages::resourceNotFound(asyncResp->res, 16787e860f15SJohn Edward Broadbent "LogEntry", entryID); 16793de8d8baSGeorge Liu return; 16803de8d8baSGeorge Liu } 1681336e96c6SChicago Duan // TODO Handle for specific error code 16820fda0f12SGeorge Liu BMCWEB_LOG_ERROR 16830fda0f12SGeorge Liu << "EventLogEntry (DBus) doDelete respHandler got error " 1684336e96c6SChicago Duan << ec; 1685336e96c6SChicago Duan asyncResp->res.result( 1686336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1687336e96c6SChicago Duan return; 1688336e96c6SChicago Duan } 1689336e96c6SChicago Duan 1690336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1691336e96c6SChicago Duan }; 1692336e96c6SChicago Duan 1693336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1694336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1695336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1696336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1697336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 16987e860f15SJohn Edward Broadbent }); 1699400fd1fbSAdriana Kobylak } 1700400fd1fbSAdriana Kobylak 17017e860f15SJohn Edward Broadbent inline void requestRoutesDBusEventLogEntryDownload(App& app) 1702400fd1fbSAdriana Kobylak { 17030fda0f12SGeorge Liu BMCWEB_ROUTE( 17040fda0f12SGeorge Liu app, 17050fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/attachment") 1706ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 17077e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 17087e860f15SJohn Edward Broadbent [](const crow::Request& req, 17097e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 17107e860f15SJohn Edward Broadbent const std::string& param) 1711400fd1fbSAdriana Kobylak 17127e860f15SJohn Edward Broadbent { 1713647b3cdcSGeorge Liu if (!http_helpers::isOctetAccepted( 1714647b3cdcSGeorge Liu req.getHeaderValue("Accept"))) 1715400fd1fbSAdriana Kobylak { 17167e860f15SJohn Edward Broadbent asyncResp->res.result( 17177e860f15SJohn Edward Broadbent boost::beast::http::status::bad_request); 1718400fd1fbSAdriana Kobylak return; 1719400fd1fbSAdriana Kobylak } 1720400fd1fbSAdriana Kobylak 17217e860f15SJohn Edward Broadbent std::string entryID = param; 1722400fd1fbSAdriana Kobylak dbus::utility::escapePathForDbus(entryID); 1723400fd1fbSAdriana Kobylak 1724400fd1fbSAdriana Kobylak crow::connections::systemBus->async_method_call( 17257e860f15SJohn Edward Broadbent [asyncResp, 17267e860f15SJohn Edward Broadbent entryID](const boost::system::error_code ec, 1727400fd1fbSAdriana Kobylak const sdbusplus::message::unix_fd& unixfd) { 1728400fd1fbSAdriana Kobylak if (ec.value() == EBADR) 1729400fd1fbSAdriana Kobylak { 17307e860f15SJohn Edward Broadbent messages::resourceNotFound( 17317e860f15SJohn Edward Broadbent asyncResp->res, "EventLogAttachment", entryID); 1732400fd1fbSAdriana Kobylak return; 1733400fd1fbSAdriana Kobylak } 1734400fd1fbSAdriana Kobylak if (ec) 1735400fd1fbSAdriana Kobylak { 1736400fd1fbSAdriana Kobylak BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1737400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1738400fd1fbSAdriana Kobylak return; 1739400fd1fbSAdriana Kobylak } 1740400fd1fbSAdriana Kobylak 1741400fd1fbSAdriana Kobylak int fd = -1; 1742400fd1fbSAdriana Kobylak fd = dup(unixfd); 1743400fd1fbSAdriana Kobylak if (fd == -1) 1744400fd1fbSAdriana Kobylak { 1745400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1746400fd1fbSAdriana Kobylak return; 1747400fd1fbSAdriana Kobylak } 1748400fd1fbSAdriana Kobylak 1749400fd1fbSAdriana Kobylak long long int size = lseek(fd, 0, SEEK_END); 1750400fd1fbSAdriana Kobylak if (size == -1) 1751400fd1fbSAdriana Kobylak { 1752400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1753400fd1fbSAdriana Kobylak return; 1754400fd1fbSAdriana Kobylak } 1755400fd1fbSAdriana Kobylak 1756400fd1fbSAdriana Kobylak // Arbitrary max size of 64kb 1757400fd1fbSAdriana Kobylak constexpr int maxFileSize = 65536; 1758400fd1fbSAdriana Kobylak if (size > maxFileSize) 1759400fd1fbSAdriana Kobylak { 1760400fd1fbSAdriana Kobylak BMCWEB_LOG_ERROR 1761400fd1fbSAdriana Kobylak << "File size exceeds maximum allowed size of " 1762400fd1fbSAdriana Kobylak << maxFileSize; 1763400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1764400fd1fbSAdriana Kobylak return; 1765400fd1fbSAdriana Kobylak } 1766400fd1fbSAdriana Kobylak std::vector<char> data(static_cast<size_t>(size)); 1767400fd1fbSAdriana Kobylak long long int rc = lseek(fd, 0, SEEK_SET); 1768400fd1fbSAdriana Kobylak if (rc == -1) 1769400fd1fbSAdriana Kobylak { 1770400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1771400fd1fbSAdriana Kobylak return; 1772400fd1fbSAdriana Kobylak } 1773400fd1fbSAdriana Kobylak rc = read(fd, data.data(), data.size()); 1774400fd1fbSAdriana Kobylak if ((rc == -1) || (rc != size)) 1775400fd1fbSAdriana Kobylak { 1776400fd1fbSAdriana Kobylak messages::internalError(asyncResp->res); 1777400fd1fbSAdriana Kobylak return; 1778400fd1fbSAdriana Kobylak } 1779400fd1fbSAdriana Kobylak close(fd); 1780400fd1fbSAdriana Kobylak 1781400fd1fbSAdriana Kobylak std::string_view strData(data.data(), data.size()); 17827e860f15SJohn Edward Broadbent std::string output = 17837e860f15SJohn Edward Broadbent crow::utility::base64encode(strData); 1784400fd1fbSAdriana Kobylak 1785400fd1fbSAdriana Kobylak asyncResp->res.addHeader("Content-Type", 1786400fd1fbSAdriana Kobylak "application/octet-stream"); 17877e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Transfer-Encoding", 17887e860f15SJohn Edward Broadbent "Base64"); 1789400fd1fbSAdriana Kobylak asyncResp->res.body() = std::move(output); 1790400fd1fbSAdriana Kobylak }, 1791400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging", 1792400fd1fbSAdriana Kobylak "/xyz/openbmc_project/logging/entry/" + entryID, 1793400fd1fbSAdriana Kobylak "xyz.openbmc_project.Logging.Entry", "GetEntry"); 17947e860f15SJohn Edward Broadbent }); 17951da66f75SEd Tanous } 17961da66f75SEd Tanous 1797b7028ebfSSpencer Ku constexpr const char* hostLoggerFolderPath = "/var/log/console"; 1798b7028ebfSSpencer Ku 1799b7028ebfSSpencer Ku inline bool 1800b7028ebfSSpencer Ku getHostLoggerFiles(const std::string& hostLoggerFilePath, 1801b7028ebfSSpencer Ku std::vector<std::filesystem::path>& hostLoggerFiles) 1802b7028ebfSSpencer Ku { 1803b7028ebfSSpencer Ku std::error_code ec; 1804b7028ebfSSpencer Ku std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec); 1805b7028ebfSSpencer Ku if (ec) 1806b7028ebfSSpencer Ku { 1807b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << ec.message(); 1808b7028ebfSSpencer Ku return false; 1809b7028ebfSSpencer Ku } 1810b7028ebfSSpencer Ku for (const std::filesystem::directory_entry& it : logPath) 1811b7028ebfSSpencer Ku { 1812b7028ebfSSpencer Ku std::string filename = it.path().filename(); 1813b7028ebfSSpencer Ku // Prefix of each log files is "log". Find the file and save the 1814b7028ebfSSpencer Ku // path 1815b7028ebfSSpencer Ku if (boost::starts_with(filename, "log")) 1816b7028ebfSSpencer Ku { 1817b7028ebfSSpencer Ku hostLoggerFiles.emplace_back(it.path()); 1818b7028ebfSSpencer Ku } 1819b7028ebfSSpencer Ku } 1820b7028ebfSSpencer Ku // As the log files rotate, they are appended with a ".#" that is higher for 1821b7028ebfSSpencer Ku // the older logs. Since we start from oldest logs, sort the name in 1822b7028ebfSSpencer Ku // descending order. 1823b7028ebfSSpencer Ku std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(), 1824b7028ebfSSpencer Ku AlphanumLess<std::string>()); 1825b7028ebfSSpencer Ku 1826b7028ebfSSpencer Ku return true; 1827b7028ebfSSpencer Ku } 1828b7028ebfSSpencer Ku 1829b7028ebfSSpencer Ku inline bool 1830b7028ebfSSpencer Ku getHostLoggerEntries(std::vector<std::filesystem::path>& hostLoggerFiles, 1831b7028ebfSSpencer Ku uint64_t& skip, uint64_t& top, 1832b7028ebfSSpencer Ku std::vector<std::string>& logEntries, size_t& logCount) 1833b7028ebfSSpencer Ku { 1834b7028ebfSSpencer Ku GzFileReader logFile; 1835b7028ebfSSpencer Ku 1836b7028ebfSSpencer Ku // Go though all log files and expose host logs. 1837b7028ebfSSpencer Ku for (const std::filesystem::path& it : hostLoggerFiles) 1838b7028ebfSSpencer Ku { 1839b7028ebfSSpencer Ku if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount)) 1840b7028ebfSSpencer Ku { 1841b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to expose host logs"; 1842b7028ebfSSpencer Ku return false; 1843b7028ebfSSpencer Ku } 1844b7028ebfSSpencer Ku } 1845b7028ebfSSpencer Ku // Get lastMessage from constructor by getter 1846b7028ebfSSpencer Ku std::string lastMessage = logFile.getLastMessage(); 1847b7028ebfSSpencer Ku if (!lastMessage.empty()) 1848b7028ebfSSpencer Ku { 1849b7028ebfSSpencer Ku logCount++; 1850b7028ebfSSpencer Ku if (logCount > skip && logCount <= (skip + top)) 1851b7028ebfSSpencer Ku { 1852b7028ebfSSpencer Ku logEntries.push_back(lastMessage); 1853b7028ebfSSpencer Ku } 1854b7028ebfSSpencer Ku } 1855b7028ebfSSpencer Ku return true; 1856b7028ebfSSpencer Ku } 1857b7028ebfSSpencer Ku 1858b7028ebfSSpencer Ku inline void fillHostLoggerEntryJson(const std::string& logEntryID, 1859b7028ebfSSpencer Ku const std::string& msg, 1860b7028ebfSSpencer Ku nlohmann::json& logEntryJson) 1861b7028ebfSSpencer Ku { 1862b7028ebfSSpencer Ku // Fill in the log entry with the gathered data. 1863b7028ebfSSpencer Ku logEntryJson = { 1864b7028ebfSSpencer Ku {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1865b7028ebfSSpencer Ku {"@odata.id", 1866b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/" + 1867b7028ebfSSpencer Ku logEntryID}, 1868b7028ebfSSpencer Ku {"Name", "Host Logger Entry"}, 1869b7028ebfSSpencer Ku {"Id", logEntryID}, 1870b7028ebfSSpencer Ku {"Message", msg}, 1871b7028ebfSSpencer Ku {"EntryType", "Oem"}, 1872b7028ebfSSpencer Ku {"Severity", "OK"}, 1873b7028ebfSSpencer Ku {"OemRecordFormat", "Host Logger Entry"}}; 1874b7028ebfSSpencer Ku } 1875b7028ebfSSpencer Ku 1876b7028ebfSSpencer Ku inline void requestRoutesSystemHostLogger(App& app) 1877b7028ebfSSpencer Ku { 1878b7028ebfSSpencer Ku BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/HostLogger/") 1879b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogService) 18800fda0f12SGeorge Liu .methods( 18810fda0f12SGeorge Liu boost::beast::http::verb:: 18820fda0f12SGeorge Liu get)([](const crow::Request&, 1883b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1884b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1885b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger"; 1886b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1887b7028ebfSSpencer Ku "#LogService.v1_1_0.LogService"; 1888b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "Host Logger Service"; 1889b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = "Host Logger Service"; 1890b7028ebfSSpencer Ku asyncResp->res.jsonValue["Id"] = "HostLogger"; 1891b7028ebfSSpencer Ku asyncResp->res.jsonValue["Entries"] = { 18920fda0f12SGeorge Liu {"@odata.id", 18930fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"}}; 1894b7028ebfSSpencer Ku }); 1895b7028ebfSSpencer Ku } 1896b7028ebfSSpencer Ku 1897b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerCollection(App& app) 1898b7028ebfSSpencer Ku { 1899b7028ebfSSpencer Ku BMCWEB_ROUTE(app, 1900b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/") 1901b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 19020fda0f12SGeorge Liu .methods( 19030fda0f12SGeorge Liu boost::beast::http::verb:: 19040fda0f12SGeorge Liu get)([](const crow::Request& req, 1905b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1906b7028ebfSSpencer Ku uint64_t skip = 0; 1907b7028ebfSSpencer Ku uint64_t top = maxEntriesPerPage; // Show max 1000 entries by 1908b7028ebfSSpencer Ku // default, allow range 1 to 1909b7028ebfSSpencer Ku // 1000 entries per page. 1910b7028ebfSSpencer Ku if (!getSkipParam(asyncResp, req, skip)) 1911b7028ebfSSpencer Ku { 1912b7028ebfSSpencer Ku return; 1913b7028ebfSSpencer Ku } 1914b7028ebfSSpencer Ku if (!getTopParam(asyncResp, req, top)) 1915b7028ebfSSpencer Ku { 1916b7028ebfSSpencer Ku return; 1917b7028ebfSSpencer Ku } 1918b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.id"] = 1919b7028ebfSSpencer Ku "/redfish/v1/Systems/system/LogServices/HostLogger/Entries"; 1920b7028ebfSSpencer Ku asyncResp->res.jsonValue["@odata.type"] = 1921b7028ebfSSpencer Ku "#LogEntryCollection.LogEntryCollection"; 1922b7028ebfSSpencer Ku asyncResp->res.jsonValue["Name"] = "HostLogger Entries"; 1923b7028ebfSSpencer Ku asyncResp->res.jsonValue["Description"] = 1924b7028ebfSSpencer Ku "Collection of HostLogger Entries"; 19250fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1926b7028ebfSSpencer Ku logEntryArray = nlohmann::json::array(); 1927b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = 0; 1928b7028ebfSSpencer Ku 1929b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 1930b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 1931b7028ebfSSpencer Ku { 1932b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 1933b7028ebfSSpencer Ku return; 1934b7028ebfSSpencer Ku } 1935b7028ebfSSpencer Ku 1936b7028ebfSSpencer Ku size_t logCount = 0; 1937b7028ebfSSpencer Ku // This vector only store the entries we want to expose that 1938b7028ebfSSpencer Ku // control by skip and top. 1939b7028ebfSSpencer Ku std::vector<std::string> logEntries; 19400fda0f12SGeorge Liu if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries, 19410fda0f12SGeorge Liu logCount)) 1942b7028ebfSSpencer Ku { 1943b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 1944b7028ebfSSpencer Ku return; 1945b7028ebfSSpencer Ku } 1946b7028ebfSSpencer Ku // If vector is empty, that means skip value larger than total 1947b7028ebfSSpencer Ku // log count 194826f6976fSEd Tanous if (logEntries.empty()) 1949b7028ebfSSpencer Ku { 1950b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 1951b7028ebfSSpencer Ku return; 1952b7028ebfSSpencer Ku } 195326f6976fSEd Tanous if (!logEntries.empty()) 1954b7028ebfSSpencer Ku { 1955b7028ebfSSpencer Ku for (size_t i = 0; i < logEntries.size(); i++) 1956b7028ebfSSpencer Ku { 1957b7028ebfSSpencer Ku logEntryArray.push_back({}); 1958b7028ebfSSpencer Ku nlohmann::json& hostLogEntry = logEntryArray.back(); 1959b7028ebfSSpencer Ku fillHostLoggerEntryJson(std::to_string(skip + i), 1960b7028ebfSSpencer Ku logEntries[i], hostLogEntry); 1961b7028ebfSSpencer Ku } 1962b7028ebfSSpencer Ku 1963b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.count"] = logCount; 1964b7028ebfSSpencer Ku if (skip + top < logCount) 1965b7028ebfSSpencer Ku { 1966b7028ebfSSpencer Ku asyncResp->res.jsonValue["Members@odata.nextLink"] = 19670fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/HostLogger/Entries?$skip=" + 1968b7028ebfSSpencer Ku std::to_string(skip + top); 1969b7028ebfSSpencer Ku } 1970b7028ebfSSpencer Ku } 1971b7028ebfSSpencer Ku }); 1972b7028ebfSSpencer Ku } 1973b7028ebfSSpencer Ku 1974b7028ebfSSpencer Ku inline void requestRoutesSystemHostLoggerLogEntry(App& app) 1975b7028ebfSSpencer Ku { 1976b7028ebfSSpencer Ku BMCWEB_ROUTE( 1977b7028ebfSSpencer Ku app, "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/<str>/") 1978b7028ebfSSpencer Ku .privileges(redfish::privileges::getLogEntry) 1979b7028ebfSSpencer Ku .methods(boost::beast::http::verb::get)( 1980*ace85d60SEd Tanous [](const crow::Request& req, 1981b7028ebfSSpencer Ku const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1982b7028ebfSSpencer Ku const std::string& param) { 1983b7028ebfSSpencer Ku const std::string& targetID = param; 1984b7028ebfSSpencer Ku 1985b7028ebfSSpencer Ku uint64_t idInt = 0; 1986ca45aa3cSEd Tanous 1987ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 1988ca45aa3cSEd Tanous const char* end = targetID.data() + targetID.size(); 1989ca45aa3cSEd Tanous 1990ca45aa3cSEd Tanous auto [ptr, ec] = std::from_chars(targetID.data(), end, idInt); 1991b7028ebfSSpencer Ku if (ec == std::errc::invalid_argument) 1992b7028ebfSSpencer Ku { 1993*ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 1994b7028ebfSSpencer Ku return; 1995b7028ebfSSpencer Ku } 1996b7028ebfSSpencer Ku if (ec == std::errc::result_out_of_range) 1997b7028ebfSSpencer Ku { 1998*ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 1999b7028ebfSSpencer Ku return; 2000b7028ebfSSpencer Ku } 2001b7028ebfSSpencer Ku 2002b7028ebfSSpencer Ku std::vector<std::filesystem::path> hostLoggerFiles; 2003b7028ebfSSpencer Ku if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles)) 2004b7028ebfSSpencer Ku { 2005b7028ebfSSpencer Ku BMCWEB_LOG_ERROR << "fail to get host log file path"; 2006b7028ebfSSpencer Ku return; 2007b7028ebfSSpencer Ku } 2008b7028ebfSSpencer Ku 2009b7028ebfSSpencer Ku size_t logCount = 0; 2010b7028ebfSSpencer Ku uint64_t top = 1; 2011b7028ebfSSpencer Ku std::vector<std::string> logEntries; 2012b7028ebfSSpencer Ku // We can get specific entry by skip and top. For example, if we 2013b7028ebfSSpencer Ku // want to get nth entry, we can set skip = n-1 and top = 1 to 2014b7028ebfSSpencer Ku // get that entry 2015b7028ebfSSpencer Ku if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, 2016b7028ebfSSpencer Ku logEntries, logCount)) 2017b7028ebfSSpencer Ku { 2018b7028ebfSSpencer Ku messages::internalError(asyncResp->res); 2019b7028ebfSSpencer Ku return; 2020b7028ebfSSpencer Ku } 2021b7028ebfSSpencer Ku 2022b7028ebfSSpencer Ku if (!logEntries.empty()) 2023b7028ebfSSpencer Ku { 2024b7028ebfSSpencer Ku fillHostLoggerEntryJson(targetID, logEntries[0], 2025b7028ebfSSpencer Ku asyncResp->res.jsonValue); 2026b7028ebfSSpencer Ku return; 2027b7028ebfSSpencer Ku } 2028b7028ebfSSpencer Ku 2029b7028ebfSSpencer Ku // Requested ID was not found 2030*ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2031b7028ebfSSpencer Ku }); 2032b7028ebfSSpencer Ku } 2033b7028ebfSSpencer Ku 20347e860f15SJohn Edward Broadbent inline void requestRoutesBMCLogServiceCollection(App& app) 20351da66f75SEd Tanous { 20367e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/") 2037ad89dcf0SGunnar Mills .privileges(redfish::privileges::getLogServiceCollection) 20387e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 20397e860f15SJohn Edward Broadbent [](const crow::Request&, 20407e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 20417e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 20427e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2043e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 20441da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 2045e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 2046e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 20477e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 20487e860f15SJohn Edward Broadbent "Open BMC Log Services Collection"; 2049e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 20501da66f75SEd Tanous "Collection of LogServices for this Manager"; 20517e860f15SJohn Edward Broadbent nlohmann::json& logServiceArray = 20527e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 2053c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 20545cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 20555cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 20567e860f15SJohn Edward Broadbent {{"@odata.id", 20577e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 20585cb1dd27SAsmitha Karunanithi #endif 2059c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 2060c4bf6374SJason M. Bills logServiceArray.push_back( 20617e860f15SJohn Edward Broadbent {{"@odata.id", 20627e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 2063c4bf6374SJason M. Bills #endif 2064e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2065c4bf6374SJason M. Bills logServiceArray.size(); 20667e860f15SJohn Edward Broadbent }); 2067e1f26343SJason M. Bills } 2068e1f26343SJason M. Bills 20697e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogService(App& app) 2070e1f26343SJason M. Bills { 20717e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 2072ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 20737e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 20747e860f15SJohn Edward Broadbent [](const crow::Request&, 20757e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 20768d1b46d7Szhanghch05 20777e860f15SJohn Edward Broadbent { 2078e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2079e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 20800f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 20810f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 20827e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = 20837e860f15SJohn Edward Broadbent "Open BMC Journal Log Service"; 20847e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 20857e860f15SJohn Edward Broadbent "BMC Journal Log Service"; 2086c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 2087e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 20887c8c4058STejas Patil 20897c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 20907c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 20917c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 20927c8c4058STejas Patil redfishDateTimeOffset.first; 20937c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 20947c8c4058STejas Patil redfishDateTimeOffset.second; 20957c8c4058STejas Patil 2096cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2097cd50aa42SJason M. Bills {"@odata.id", 2098086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 20997e860f15SJohn Edward Broadbent }); 2100e1f26343SJason M. Bills } 2101e1f26343SJason M. Bills 2102c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 2103e1f26343SJason M. Bills sd_journal* journal, 2104c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 2105e1f26343SJason M. Bills { 2106e1f26343SJason M. Bills // Get the Log Entry contents 2107e1f26343SJason M. Bills int ret = 0; 2108e1f26343SJason M. Bills 2109a8fe54f0SJason M. Bills std::string message; 2110a8fe54f0SJason M. Bills std::string_view syslogID; 2111a8fe54f0SJason M. Bills ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID); 2112a8fe54f0SJason M. Bills if (ret < 0) 2113a8fe54f0SJason M. Bills { 2114a8fe54f0SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: " 2115a8fe54f0SJason M. Bills << strerror(-ret); 2116a8fe54f0SJason M. Bills } 2117a8fe54f0SJason M. Bills if (!syslogID.empty()) 2118a8fe54f0SJason M. Bills { 2119a8fe54f0SJason M. Bills message += std::string(syslogID) + ": "; 2120a8fe54f0SJason M. Bills } 2121a8fe54f0SJason M. Bills 212239e77504SEd Tanous std::string_view msg; 212316428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 2124e1f26343SJason M. Bills if (ret < 0) 2125e1f26343SJason M. Bills { 2126e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 2127e1f26343SJason M. Bills return 1; 2128e1f26343SJason M. Bills } 2129a8fe54f0SJason M. Bills message += std::string(msg); 2130e1f26343SJason M. Bills 2131e1f26343SJason M. Bills // Get the severity from the PRIORITY field 2132271584abSEd Tanous long int severity = 8; // Default to an invalid priority 213316428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 2134e1f26343SJason M. Bills if (ret < 0) 2135e1f26343SJason M. Bills { 2136e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 2137e1f26343SJason M. Bills } 2138e1f26343SJason M. Bills 2139e1f26343SJason M. Bills // Get the Created time from the timestamp 214016428a1aSJason M. Bills std::string entryTimeStr; 214116428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 2142e1f26343SJason M. Bills { 214316428a1aSJason M. Bills return 1; 2144e1f26343SJason M. Bills } 2145e1f26343SJason M. Bills 2146e1f26343SJason M. Bills // Fill in the log entry with the gathered data 2147c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 2148647b3cdcSGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 2149c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 2150c4bf6374SJason M. Bills bmcJournalLogEntryID}, 2151e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 2152c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 2153a8fe54f0SJason M. Bills {"Message", std::move(message)}, 2154e1f26343SJason M. Bills {"EntryType", "Oem"}, 2155738c1e61SPatrick Williams {"Severity", severity <= 2 ? "Critical" 2156738c1e61SPatrick Williams : severity <= 4 ? "Warning" 2157738c1e61SPatrick Williams : "OK"}, 2158086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 2159e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 2160e1f26343SJason M. Bills return 0; 2161e1f26343SJason M. Bills } 2162e1f26343SJason M. Bills 21637e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntryCollection(App& app) 2164e1f26343SJason M. Bills { 21657e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 2166ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 21670fda0f12SGeorge Liu .methods( 21680fda0f12SGeorge Liu boost::beast::http::verb:: 21690fda0f12SGeorge Liu get)([](const crow::Request& req, 21707e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2171193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 2172271584abSEd Tanous uint64_t skip = 0; 2173271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 21748d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 2175193ad2faSJason M. Bills { 2176193ad2faSJason M. Bills return; 2177193ad2faSJason M. Bills } 21788d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 2179193ad2faSJason M. Bills { 2180193ad2faSJason M. Bills return; 2181193ad2faSJason M. Bills } 21827e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 21837e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2184e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2185e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 21860f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 21870f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 2188e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 2189e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2190e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 21910fda0f12SGeorge Liu nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2192e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2193e1f26343SJason M. Bills 21947e860f15SJohn Edward Broadbent // Go through the journal and use the timestamp to create a 21957e860f15SJohn Edward Broadbent // unique ID for each entry 2196e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2197e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2198e1f26343SJason M. Bills if (ret < 0) 2199e1f26343SJason M. Bills { 22007e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 22017e860f15SJohn Edward Broadbent << strerror(-ret); 2202f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2203e1f26343SJason M. Bills return; 2204e1f26343SJason M. Bills } 22050fda0f12SGeorge Liu std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 22060fda0f12SGeorge Liu journalTmp, sd_journal_close); 2207e1f26343SJason M. Bills journalTmp = nullptr; 2208b01bf299SEd Tanous uint64_t entryCount = 0; 2209e85d6b16SJason M. Bills // Reset the unique ID on the first entry 2210e85d6b16SJason M. Bills bool firstEntry = true; 2211e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 2212e1f26343SJason M. Bills { 2213193ad2faSJason M. Bills entryCount++; 22147e860f15SJohn Edward Broadbent // Handle paging using skip (number of entries to skip from 22157e860f15SJohn Edward Broadbent // the start) and top (number of entries to display) 2216193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 2217193ad2faSJason M. Bills { 2218193ad2faSJason M. Bills continue; 2219193ad2faSJason M. Bills } 2220193ad2faSJason M. Bills 222116428a1aSJason M. Bills std::string idStr; 2222e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2223e1f26343SJason M. Bills { 2224e1f26343SJason M. Bills continue; 2225e1f26343SJason M. Bills } 2226e1f26343SJason M. Bills 2227e85d6b16SJason M. Bills if (firstEntry) 2228e85d6b16SJason M. Bills { 2229e85d6b16SJason M. Bills firstEntry = false; 2230e85d6b16SJason M. Bills } 2231e85d6b16SJason M. Bills 2232e1f26343SJason M. Bills logEntryArray.push_back({}); 2233c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 2234c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 2235c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 2236e1f26343SJason M. Bills { 2237f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2238e1f26343SJason M. Bills return; 2239e1f26343SJason M. Bills } 2240e1f26343SJason M. Bills } 2241193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 2242193ad2faSJason M. Bills if (skip + top < entryCount) 2243193ad2faSJason M. Bills { 2244193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 22450fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 2246193ad2faSJason M. Bills std::to_string(skip + top); 2247193ad2faSJason M. Bills } 22487e860f15SJohn Edward Broadbent }); 2249e1f26343SJason M. Bills } 2250e1f26343SJason M. Bills 22517e860f15SJohn Edward Broadbent inline void requestRoutesBMCJournalLogEntry(App& app) 2252e1f26343SJason M. Bills { 22537e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 22547e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/") 2255ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 22567e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 2257*ace85d60SEd Tanous [](const crow::Request& req, 22587e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22597e860f15SJohn Edward Broadbent const std::string& entryID) { 2260e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 2261e1f26343SJason M. Bills uint64_t ts = 0; 2262271584abSEd Tanous uint64_t index = 0; 22638d1b46d7Szhanghch05 if (!getTimestampFromID(asyncResp, entryID, ts, index)) 2264e1f26343SJason M. Bills { 226516428a1aSJason M. Bills return; 2266e1f26343SJason M. Bills } 2267e1f26343SJason M. Bills 2268e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 2269e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 2270e1f26343SJason M. Bills if (ret < 0) 2271e1f26343SJason M. Bills { 22727e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "failed to open journal: " 22737e860f15SJohn Edward Broadbent << strerror(-ret); 2274f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2275e1f26343SJason M. Bills return; 2276e1f26343SJason M. Bills } 22777e860f15SJohn Edward Broadbent std::unique_ptr<sd_journal, decltype(&sd_journal_close)> 22787e860f15SJohn Edward Broadbent journal(journalTmp, sd_journal_close); 2279e1f26343SJason M. Bills journalTmp = nullptr; 22807e860f15SJohn Edward Broadbent // Go to the timestamp in the log and move to the entry at the 22817e860f15SJohn Edward Broadbent // index tracking the unique ID 2282af07e3f5SJason M. Bills std::string idStr; 2283af07e3f5SJason M. Bills bool firstEntry = true; 2284e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 22852056b6d1SManojkiran Eda if (ret < 0) 22862056b6d1SManojkiran Eda { 22872056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 22882056b6d1SManojkiran Eda << strerror(-ret); 22892056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 22902056b6d1SManojkiran Eda return; 22912056b6d1SManojkiran Eda } 2292271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 2293e1f26343SJason M. Bills { 2294e1f26343SJason M. Bills sd_journal_next(journal.get()); 2295af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 2296af07e3f5SJason M. Bills { 2297af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 2298af07e3f5SJason M. Bills return; 2299af07e3f5SJason M. Bills } 2300af07e3f5SJason M. Bills if (firstEntry) 2301af07e3f5SJason M. Bills { 2302af07e3f5SJason M. Bills firstEntry = false; 2303af07e3f5SJason M. Bills } 2304e1f26343SJason M. Bills } 2305c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 2306af07e3f5SJason M. Bills if (idStr != entryID) 2307c4bf6374SJason M. Bills { 2308*ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 2309c4bf6374SJason M. Bills return; 2310c4bf6374SJason M. Bills } 2311c4bf6374SJason M. Bills 2312c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 2313e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 2314e1f26343SJason M. Bills { 2315f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2316e1f26343SJason M. Bills return; 2317e1f26343SJason M. Bills } 23187e860f15SJohn Edward Broadbent }); 2319c9bb6861Sraviteja-b } 2320c9bb6861Sraviteja-b 23217e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpService(App& app) 2322c9bb6861Sraviteja-b { 23237e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 2324ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 23250fda0f12SGeorge Liu .methods( 23260fda0f12SGeorge Liu boost::beast::http::verb:: 23270fda0f12SGeorge Liu get)([](const crow::Request&, 23287e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2329c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 23305cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 2331c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2332d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 2333c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 23345cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 23355cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2336c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 23377c8c4058STejas Patil 23387c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 23397c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 23400fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 23417c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 23427c8c4058STejas Patil redfishDateTimeOffset.second; 23437c8c4058STejas Patil 2344c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 23457e860f15SJohn Edward Broadbent {"@odata.id", 23467e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}}; 23475cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 23485cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 23490fda0f12SGeorge Liu {{"target", 23500fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog"}}}, 2351d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 23520fda0f12SGeorge Liu {{"target", 23530fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData"}}}}; 23547e860f15SJohn Edward Broadbent }); 2355c9bb6861Sraviteja-b } 2356c9bb6861Sraviteja-b 23577e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntryCollection(App& app) 23587e860f15SJohn Edward Broadbent { 23597e860f15SJohn Edward Broadbent 2360c9bb6861Sraviteja-b /** 2361c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 2362c9bb6861Sraviteja-b */ 23637e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 2364ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 23657e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 23667e860f15SJohn Edward Broadbent [](const crow::Request&, 23677e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2368c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 2369c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 2370c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 23715cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 23725cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 2373c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 23745cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 2375c9bb6861Sraviteja-b 23765cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 23777e860f15SJohn Edward Broadbent }); 2378c9bb6861Sraviteja-b } 2379c9bb6861Sraviteja-b 23807e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpEntry(App& app) 2381c9bb6861Sraviteja-b { 23827e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 23837e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2384ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 23857e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 23867e860f15SJohn Edward Broadbent [](const crow::Request&, 23877e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 23887e860f15SJohn Edward Broadbent const std::string& param) { 23897e860f15SJohn Edward Broadbent getDumpEntryById(asyncResp, param, "BMC"); 23907e860f15SJohn Edward Broadbent }); 23917e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 23927e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/") 2393ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 23947e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 23957e860f15SJohn Edward Broadbent [](const crow::Request&, 23967e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 23977e860f15SJohn Edward Broadbent const std::string& param) { 23987e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "bmc"); 23997e860f15SJohn Edward Broadbent }); 2400c9bb6861Sraviteja-b } 2401c9bb6861Sraviteja-b 24027e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpCreate(App& app) 2403c9bb6861Sraviteja-b { 24048d1b46d7Szhanghch05 24050fda0f12SGeorge Liu BMCWEB_ROUTE( 24060fda0f12SGeorge Liu app, 24070fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2408ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 24097e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 24107e860f15SJohn Edward Broadbent [](const crow::Request& req, 24117e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24128d1b46d7Szhanghch05 createDump(asyncResp, req, "BMC"); 24137e860f15SJohn Edward Broadbent }); 2414a43be80fSAsmitha Karunanithi } 2415a43be80fSAsmitha Karunanithi 24167e860f15SJohn Edward Broadbent inline void requestRoutesBMCDumpClear(App& app) 241780319af1SAsmitha Karunanithi { 24180fda0f12SGeorge Liu BMCWEB_ROUTE( 24190fda0f12SGeorge Liu app, 24200fda0f12SGeorge Liu "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog/") 2421ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 24227e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 24237e860f15SJohn Edward Broadbent [](const crow::Request&, 24247e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24258d1b46d7Szhanghch05 clearDump(asyncResp, "BMC"); 24267e860f15SJohn Edward Broadbent }); 24275cb1dd27SAsmitha Karunanithi } 24285cb1dd27SAsmitha Karunanithi 24297e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpService(App& app) 24305cb1dd27SAsmitha Karunanithi { 24317e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/") 2432ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 24337e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24347e860f15SJohn Edward Broadbent [](const crow::Request&, 24357e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 24365cb1dd27SAsmitha Karunanithi 24377e860f15SJohn Edward Broadbent { 24385cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 24395cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 24405cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2441d337bb72SAsmitha Karunanithi "#LogService.v1_2_0.LogService"; 24425cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 24437e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 24447e860f15SJohn Edward Broadbent "System Dump LogService"; 24455cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 24465cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 24477c8c4058STejas Patil 24487c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 24497c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 24507c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = 24517c8c4058STejas Patil redfishDateTimeOffset.first; 24527c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 24537c8c4058STejas Patil redfishDateTimeOffset.second; 24547c8c4058STejas Patil 24555cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Entries"] = { 24565cb1dd27SAsmitha Karunanithi {"@odata.id", 24575cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"}}; 24585cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 24595cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 24607e860f15SJohn Edward Broadbent {{"target", 24610fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog"}}}, 2462d337bb72SAsmitha Karunanithi {"#LogService.CollectDiagnosticData", 24637e860f15SJohn Edward Broadbent {{"target", 24640fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData"}}}}; 24657e860f15SJohn Edward Broadbent }); 24665cb1dd27SAsmitha Karunanithi } 24675cb1dd27SAsmitha Karunanithi 24687e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntryCollection(App& app) 24697e860f15SJohn Edward Broadbent { 24707e860f15SJohn Edward Broadbent 24715cb1dd27SAsmitha Karunanithi /** 24725cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 24735cb1dd27SAsmitha Karunanithi */ 2474b2a3289dSAsmitha Karunanithi BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 2475ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 24767e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24777e860f15SJohn Edward Broadbent [](const crow::Request&, 2478864d6a17SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24795cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 24805cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 24815cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 24825cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 24835cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 24845cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 24855cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 24865cb1dd27SAsmitha Karunanithi 24875cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 24887e860f15SJohn Edward Broadbent }); 24895cb1dd27SAsmitha Karunanithi } 24905cb1dd27SAsmitha Karunanithi 24917e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpEntry(App& app) 24925cb1dd27SAsmitha Karunanithi { 24937e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2494864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2495ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 2496ed398213SEd Tanous 24977e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24987e860f15SJohn Edward Broadbent [](const crow::Request&, 24997e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25007e860f15SJohn Edward Broadbent const std::string& param) { 25017e860f15SJohn Edward Broadbent getDumpEntryById(asyncResp, param, "System"); 25027e860f15SJohn Edward Broadbent }); 25038d1b46d7Szhanghch05 25047e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 2505864d6a17SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") 2506ed398213SEd Tanous .privileges(redfish::privileges::deleteLogEntry) 25077e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 25087e860f15SJohn Edward Broadbent [](const crow::Request&, 25097e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25107e860f15SJohn Edward Broadbent const std::string& param) { 25117e860f15SJohn Edward Broadbent deleteDumpEntry(asyncResp, param, "system"); 25127e860f15SJohn Edward Broadbent }); 25135cb1dd27SAsmitha Karunanithi } 2514c9bb6861Sraviteja-b 25157e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpCreate(App& app) 2516c9bb6861Sraviteja-b { 25170fda0f12SGeorge Liu BMCWEB_ROUTE( 25180fda0f12SGeorge Liu app, 25190fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") 2520ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 25217e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 25227e860f15SJohn Edward Broadbent [](const crow::Request& req, 25237e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 25247e860f15SJohn Edward Broadbent 25257e860f15SJohn Edward Broadbent { createDump(asyncResp, req, "System"); }); 2526a43be80fSAsmitha Karunanithi } 2527a43be80fSAsmitha Karunanithi 25287e860f15SJohn Edward Broadbent inline void requestRoutesSystemDumpClear(App& app) 2529a43be80fSAsmitha Karunanithi { 25300fda0f12SGeorge Liu BMCWEB_ROUTE( 25310fda0f12SGeorge Liu app, 25320fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog/") 2533ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 25347e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 25357e860f15SJohn Edward Broadbent [](const crow::Request&, 25367e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 25377e860f15SJohn Edward Broadbent 25387e860f15SJohn Edward Broadbent { clearDump(asyncResp, "System"); }); 2539013487e5Sraviteja-b } 2540013487e5Sraviteja-b 25417e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpService(App& app) 25421da66f75SEd Tanous { 25433946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25443946028dSAppaRao Puli // method for security reasons. 25451da66f75SEd Tanous /** 25461da66f75SEd Tanous * Functions triggers appropriate requests on DBus 25471da66f75SEd Tanous */ 25487e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 2549ed398213SEd Tanous // This is incorrect, should be: 2550ed398213SEd Tanous //.privileges(redfish::privileges::getLogService) 2551432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 25527e860f15SJohn Edward Broadbent .methods( 25537e860f15SJohn Edward Broadbent boost::beast::http::verb:: 25547e860f15SJohn Edward Broadbent get)([](const crow::Request&, 25557e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 25567e860f15SJohn Edward Broadbent // Copy over the static data to include the entries added by 25577e860f15SJohn Edward Broadbent // SubRoute 25580f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2559424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2560e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 25618e6c099aSJason M. Bills "#LogService.v1_2_0.LogService"; 25624f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 25634f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 25644f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2565e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2566e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 25677c8c4058STejas Patil 25687c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 25697c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 25707c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 25717c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 25727c8c4058STejas Patil redfishDateTimeOffset.second; 25737c8c4058STejas Patil 2574cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2575cd50aa42SJason M. Bills {"@odata.id", 2576424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 2577e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 25785b61b5e8SJason M. Bills {"#LogService.ClearLog", 25790fda0f12SGeorge Liu {{"target", 25800fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog"}}}, 25818e6c099aSJason M. Bills {"#LogService.CollectDiagnosticData", 25820fda0f12SGeorge Liu {{"target", 25830fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData"}}}}; 25847e860f15SJohn Edward Broadbent }); 25851da66f75SEd Tanous } 25861da66f75SEd Tanous 25877e860f15SJohn Edward Broadbent void inline requestRoutesCrashdumpClear(App& app) 25885b61b5e8SJason M. Bills { 25890fda0f12SGeorge Liu BMCWEB_ROUTE( 25900fda0f12SGeorge Liu app, 25910fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog/") 2592ed398213SEd Tanous // This is incorrect, should be: 2593ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2594432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 25957e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 25967e860f15SJohn Edward Broadbent [](const crow::Request&, 25977e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 25985b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 25995b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 2600cb13a392SEd Tanous const std::string&) { 26015b61b5e8SJason M. Bills if (ec) 26025b61b5e8SJason M. Bills { 26035b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 26045b61b5e8SJason M. Bills return; 26055b61b5e8SJason M. Bills } 26065b61b5e8SJason M. Bills messages::success(asyncResp->res); 26075b61b5e8SJason M. Bills }, 26087e860f15SJohn Edward Broadbent crashdumpObject, crashdumpPath, deleteAllInterface, 26097e860f15SJohn Edward Broadbent "DeleteAll"); 26107e860f15SJohn Edward Broadbent }); 26115b61b5e8SJason M. Bills } 26125b61b5e8SJason M. Bills 26138d1b46d7Szhanghch05 static void 26148d1b46d7Szhanghch05 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 26158d1b46d7Szhanghch05 const std::string& logID, nlohmann::json& logEntryJson) 2616e855dd28SJason M. Bills { 2617043a0536SJohnathan Mantey auto getStoredLogCallback = 2618043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 2619e855dd28SJason M. Bills const boost::system::error_code ec, 2620168e20c1SEd Tanous const std::vector< 2621168e20c1SEd Tanous std::pair<std::string, dbus::utility::DbusVariantType>>& 2622168e20c1SEd Tanous params) { 2623e855dd28SJason M. Bills if (ec) 2624e855dd28SJason M. Bills { 2625e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 26261ddcf01aSJason M. Bills if (ec.value() == 26271ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 26281ddcf01aSJason M. Bills { 2629043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2630043a0536SJohnathan Mantey logID); 26311ddcf01aSJason M. Bills } 26321ddcf01aSJason M. Bills else 26331ddcf01aSJason M. Bills { 2634e855dd28SJason M. Bills messages::internalError(asyncResp->res); 26351ddcf01aSJason M. Bills } 2636e855dd28SJason M. Bills return; 2637e855dd28SJason M. Bills } 2638043a0536SJohnathan Mantey 2639043a0536SJohnathan Mantey std::string timestamp{}; 2640043a0536SJohnathan Mantey std::string filename{}; 2641043a0536SJohnathan Mantey std::string logfile{}; 26422c70f800SEd Tanous parseCrashdumpParameters(params, filename, timestamp, logfile); 2643043a0536SJohnathan Mantey 2644043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2645e855dd28SJason M. Bills { 2646*ace85d60SEd Tanous messages::resourceMissingAtURI( 2647*ace85d60SEd Tanous asyncResp->res, crow::utility::urlFromPieces(logID)); 2648e855dd28SJason M. Bills return; 2649e855dd28SJason M. Bills } 2650e855dd28SJason M. Bills 2651043a0536SJohnathan Mantey std::string crashdumpURI = 2652e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2653043a0536SJohnathan Mantey logID + "/" + filename; 26544978b63fSJason M. Bills logEntryJson = { 26554978b63fSJason M. Bills {"@odata.type", "#LogEntry.v1_7_0.LogEntry"}, 26564978b63fSJason M. Bills {"@odata.id", 26574978b63fSJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2658e855dd28SJason M. Bills logID}, 2659e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2660e855dd28SJason M. Bills {"Id", logID}, 2661e855dd28SJason M. Bills {"EntryType", "Oem"}, 26628e6c099aSJason M. Bills {"AdditionalDataURI", std::move(crashdumpURI)}, 26638e6c099aSJason M. Bills {"DiagnosticDataType", "OEM"}, 26648e6c099aSJason M. Bills {"OEMDiagnosticDataType", "PECICrashdump"}, 2665043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2666e855dd28SJason M. Bills }; 2667e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 26685b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 26695b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2670043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2671e855dd28SJason M. Bills } 2672e855dd28SJason M. Bills 26737e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntryCollection(App& app) 26741da66f75SEd Tanous { 26753946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 26763946028dSAppaRao Puli // method for security reasons. 26771da66f75SEd Tanous /** 26781da66f75SEd Tanous * Functions triggers appropriate requests on DBus 26791da66f75SEd Tanous */ 26807e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 26817e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 2682ed398213SEd Tanous // This is incorrect, should be. 2683ed398213SEd Tanous //.privileges(redfish::privileges::postLogEntryCollection) 2684432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 26857e860f15SJohn Edward Broadbent .methods( 26867e860f15SJohn Edward Broadbent boost::beast::http::verb:: 26877e860f15SJohn Edward Broadbent get)([](const crow::Request&, 26887e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26897e860f15SJohn Edward Broadbent // Collections don't include the static data added by SubRoute 26907e860f15SJohn Edward Broadbent // because it has a duplicate entry for members 2691e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2692e1f26343SJason M. Bills const boost::system::error_code ec, 26937e860f15SJohn Edward Broadbent const std::vector<std::string>& 26947e860f15SJohn Edward Broadbent resp) { 26951da66f75SEd Tanous if (ec) 26961da66f75SEd Tanous { 26971da66f75SEd Tanous if (ec.value() != 26981da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 26991da66f75SEd Tanous { 27001da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 27011da66f75SEd Tanous << ec.message(); 2702f12894f8SJason M. Bills messages::internalError(asyncResp->res); 27031da66f75SEd Tanous return; 27041da66f75SEd Tanous } 27051da66f75SEd Tanous } 2706e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 27071da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 27080f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2709424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2710424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2711e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2712424c4176SJason M. Bills "Collection of Crashdump Entries"; 27137e860f15SJohn Edward Broadbent nlohmann::json& logEntryArray = 27147e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members"]; 2715e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2716e855dd28SJason M. Bills std::vector<std::string> logIDs; 2717e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2718e855dd28SJason M. Bills // enough to hold them 27191da66f75SEd Tanous for (const std::string& objpath : resp) 27201da66f75SEd Tanous { 2721e855dd28SJason M. Bills // Get the log ID 2722f23b7296SEd Tanous std::size_t lastPos = objpath.rfind('/'); 2723e855dd28SJason M. Bills if (lastPos == std::string::npos) 27241da66f75SEd Tanous { 2725e855dd28SJason M. Bills continue; 27261da66f75SEd Tanous } 2727e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2728e855dd28SJason M. Bills 2729e855dd28SJason M. Bills // Add a space for the log entry to the array 2730e855dd28SJason M. Bills logEntryArray.push_back({}); 2731e855dd28SJason M. Bills } 2732e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2733e855dd28SJason M. Bills size_t index = 0; 2734e855dd28SJason M. Bills for (const std::string& logID : logIDs) 2735e855dd28SJason M. Bills { 2736e855dd28SJason M. Bills // Add the log entry to the array 2737e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 27381da66f75SEd Tanous } 2739e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2740e1f26343SJason M. Bills logEntryArray.size(); 27411da66f75SEd Tanous }; 27421da66f75SEd Tanous crow::connections::systemBus->async_method_call( 27431da66f75SEd Tanous std::move(getLogEntriesCallback), 27441da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 27451da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 27461da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 27475b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 27487e860f15SJohn Edward Broadbent }); 27491da66f75SEd Tanous } 27501da66f75SEd Tanous 27517e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpEntry(App& app) 27521da66f75SEd Tanous { 27533946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 27543946028dSAppaRao Puli // method for security reasons. 27551da66f75SEd Tanous 27567e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 27577e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/") 2758ed398213SEd Tanous // this is incorrect, should be 2759ed398213SEd Tanous // .privileges(redfish::privileges::getLogEntry) 2760432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 27617e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 27627e860f15SJohn Edward Broadbent [](const crow::Request&, 27637e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 27647e860f15SJohn Edward Broadbent const std::string& param) { 27657e860f15SJohn Edward Broadbent const std::string& logID = param; 2766e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 27677e860f15SJohn Edward Broadbent }); 2768e855dd28SJason M. Bills } 2769e855dd28SJason M. Bills 27707e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpFile(App& app) 2771e855dd28SJason M. Bills { 27723946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 27733946028dSAppaRao Puli // method for security reasons. 27747e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 27757e860f15SJohn Edward Broadbent app, 27767e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/") 2777ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 27787e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 2779*ace85d60SEd Tanous [](const crow::Request& req, 27807e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 27817e860f15SJohn Edward Broadbent const std::string& logID, const std::string& fileName) { 2782043a0536SJohnathan Mantey auto getStoredLogCallback = 2783*ace85d60SEd Tanous [asyncResp, logID, fileName, 2784*ace85d60SEd Tanous url(boost::urls::url(req.urlView))]( 2785abf2add6SEd Tanous const boost::system::error_code ec, 2786168e20c1SEd Tanous const std::vector<std::pair< 2787168e20c1SEd Tanous std::string, dbus::utility::DbusVariantType>>& 27887e860f15SJohn Edward Broadbent resp) { 27891da66f75SEd Tanous if (ec) 27901da66f75SEd Tanous { 2791043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2792043a0536SJohnathan Mantey << ec.message(); 2793f12894f8SJason M. Bills messages::internalError(asyncResp->res); 27941da66f75SEd Tanous return; 27951da66f75SEd Tanous } 2796e855dd28SJason M. Bills 2797043a0536SJohnathan Mantey std::string dbusFilename{}; 2798043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2799043a0536SJohnathan Mantey std::string dbusFilepath{}; 2800043a0536SJohnathan Mantey 28017e860f15SJohn Edward Broadbent parseCrashdumpParameters(resp, dbusFilename, 28027e860f15SJohn Edward Broadbent dbusTimestamp, dbusFilepath); 2803043a0536SJohnathan Mantey 2804043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2805043a0536SJohnathan Mantey dbusFilepath.empty()) 28061da66f75SEd Tanous { 2807*ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 28081da66f75SEd Tanous return; 28091da66f75SEd Tanous } 2810e855dd28SJason M. Bills 2811043a0536SJohnathan Mantey // Verify the file name parameter is correct 2812043a0536SJohnathan Mantey if (fileName != dbusFilename) 2813043a0536SJohnathan Mantey { 2814*ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 2815043a0536SJohnathan Mantey return; 2816043a0536SJohnathan Mantey } 2817043a0536SJohnathan Mantey 2818043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2819043a0536SJohnathan Mantey { 2820*ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, url); 2821043a0536SJohnathan Mantey return; 2822043a0536SJohnathan Mantey } 28232d31491bSJason M. Bills std::ifstream ifs(dbusFilepath, 28242d31491bSJason M. Bills std::ios::in | std::ios::binary); 28252d31491bSJason M. Bills asyncResp->res.body() = std::string( 28262d31491bSJason M. Bills std::istreambuf_iterator<char>{ifs}, {}); 2827043a0536SJohnathan Mantey 28287e860f15SJohn Edward Broadbent // Configure this to be a file download when accessed 28297e860f15SJohn Edward Broadbent // from a browser 28307e860f15SJohn Edward Broadbent asyncResp->res.addHeader("Content-Disposition", 28317e860f15SJohn Edward Broadbent "attachment"); 28321da66f75SEd Tanous }; 28331da66f75SEd Tanous crow::connections::systemBus->async_method_call( 28345b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 28355b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 28367e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 28377e860f15SJohn Edward Broadbent crashdumpInterface); 28387e860f15SJohn Edward Broadbent }); 28391da66f75SEd Tanous } 28401da66f75SEd Tanous 28417e860f15SJohn Edward Broadbent inline void requestRoutesCrashdumpCollect(App& app) 28421da66f75SEd Tanous { 28433946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 28443946028dSAppaRao Puli // method for security reasons. 28450fda0f12SGeorge Liu BMCWEB_ROUTE( 28460fda0f12SGeorge Liu app, 28470fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.CollectDiagnosticData/") 2848ed398213SEd Tanous // The below is incorrect; Should be ConfigureManager 2849ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 2850432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 28517e860f15SJohn Edward Broadbent .methods( 28527e860f15SJohn Edward Broadbent boost::beast::http::verb:: 28537e860f15SJohn Edward Broadbent post)([](const crow::Request& req, 28547e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 28558e6c099aSJason M. Bills std::string diagnosticDataType; 28568e6c099aSJason M. Bills std::string oemDiagnosticDataType; 285715ed6780SWilly Tu if (!redfish::json_util::readJsonAction( 28587e860f15SJohn Edward Broadbent req, asyncResp->res, "DiagnosticDataType", 28597e860f15SJohn Edward Broadbent diagnosticDataType, "OEMDiagnosticDataType", 28607e860f15SJohn Edward Broadbent oemDiagnosticDataType)) 28618e6c099aSJason M. Bills { 28628e6c099aSJason M. Bills return; 28638e6c099aSJason M. Bills } 28648e6c099aSJason M. Bills 28658e6c099aSJason M. Bills if (diagnosticDataType != "OEM") 28668e6c099aSJason M. Bills { 28678e6c099aSJason M. Bills BMCWEB_LOG_ERROR 28688e6c099aSJason M. Bills << "Only OEM DiagnosticDataType supported for Crashdump"; 28698e6c099aSJason M. Bills messages::actionParameterValueFormatError( 28708e6c099aSJason M. Bills asyncResp->res, diagnosticDataType, "DiagnosticDataType", 28718e6c099aSJason M. Bills "CollectDiagnosticData"); 28728e6c099aSJason M. Bills return; 28738e6c099aSJason M. Bills } 28748e6c099aSJason M. Bills 287598be3e39SEd Tanous auto collectCrashdumpCallback = [asyncResp, 287698be3e39SEd Tanous payload(task::Payload(req))]( 28777e860f15SJohn Edward Broadbent const boost::system::error_code 28787e860f15SJohn Edward Broadbent ec, 287998be3e39SEd Tanous const std::string&) mutable { 28801da66f75SEd Tanous if (ec) 28811da66f75SEd Tanous { 28827e860f15SJohn Edward Broadbent if (ec.value() == 28837e860f15SJohn Edward Broadbent boost::system::errc::operation_not_supported) 28841da66f75SEd Tanous { 2885f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 28861da66f75SEd Tanous } 28874363d3b2SJason M. Bills else if (ec.value() == 28884363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 28894363d3b2SJason M. Bills { 28904363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 28914363d3b2SJason M. Bills "60"); 28924363d3b2SJason M. Bills } 28931da66f75SEd Tanous else 28941da66f75SEd Tanous { 2895f12894f8SJason M. Bills messages::internalError(asyncResp->res); 28961da66f75SEd Tanous } 28971da66f75SEd Tanous return; 28981da66f75SEd Tanous } 28990fda0f12SGeorge Liu std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 29007e860f15SJohn Edward Broadbent [](boost::system::error_code err, 29017e860f15SJohn Edward Broadbent sdbusplus::message::message&, 290266afe4faSJames Feist const std::shared_ptr<task::TaskData>& taskData) { 290366afe4faSJames Feist if (!err) 290466afe4faSJames Feist { 2905e5d5006bSJames Feist taskData->messages.emplace_back( 2906e5d5006bSJames Feist messages::taskCompletedOK( 2907e5d5006bSJames Feist std::to_string(taskData->index))); 2908831d6b09SJames Feist taskData->state = "Completed"; 290966afe4faSJames Feist } 291032898ceaSJames Feist return task::completed; 291166afe4faSJames Feist }, 29124978b63fSJason M. Bills "type='signal',interface='org.freedesktop.DBus.Properties'," 29130fda0f12SGeorge Liu "member='PropertiesChanged',arg0namespace='com.intel.crashdump'"); 291446229577SJames Feist task->startTimer(std::chrono::minutes(5)); 291546229577SJames Feist task->populateResp(asyncResp->res); 291698be3e39SEd Tanous task->payload.emplace(std::move(payload)); 29171da66f75SEd Tanous }; 29188e6c099aSJason M. Bills 29198e6c099aSJason M. Bills if (oemDiagnosticDataType == "OnDemand") 29208e6c099aSJason M. Bills { 29211da66f75SEd Tanous crow::connections::systemBus->async_method_call( 29228e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 29238e6c099aSJason M. Bills crashdumpPath, crashdumpOnDemandInterface, 29248e6c099aSJason M. Bills "GenerateOnDemandLog"); 29251da66f75SEd Tanous } 29268e6c099aSJason M. Bills else if (oemDiagnosticDataType == "Telemetry") 29276eda7685SKenny L. Ku { 29288e6c099aSJason M. Bills crow::connections::systemBus->async_method_call( 29298e6c099aSJason M. Bills std::move(collectCrashdumpCallback), crashdumpObject, 29308e6c099aSJason M. Bills crashdumpPath, crashdumpTelemetryInterface, 29318e6c099aSJason M. Bills "GenerateTelemetryLog"); 29326eda7685SKenny L. Ku } 29336eda7685SKenny L. Ku else 29346eda7685SKenny L. Ku { 29358e6c099aSJason M. Bills BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: " 29368e6c099aSJason M. Bills << oemDiagnosticDataType; 29378e6c099aSJason M. Bills messages::actionParameterValueFormatError( 29387e860f15SJohn Edward Broadbent asyncResp->res, oemDiagnosticDataType, 29397e860f15SJohn Edward Broadbent "OEMDiagnosticDataType", "CollectDiagnosticData"); 29406eda7685SKenny L. Ku return; 29416eda7685SKenny L. Ku } 29427e860f15SJohn Edward Broadbent }); 29436eda7685SKenny L. Ku } 29446eda7685SKenny L. Ku 2945cb92c03bSAndrew Geissler /** 2946cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2947cb92c03bSAndrew Geissler */ 29487e860f15SJohn Edward Broadbent inline void requestRoutesDBusLogServiceActionsClear(App& app) 2949cb92c03bSAndrew Geissler { 2950cb92c03bSAndrew Geissler /** 2951cb92c03bSAndrew Geissler * Function handles POST method request. 2952cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 2953cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 2954cb92c03bSAndrew Geissler */ 29557e860f15SJohn Edward Broadbent 29560fda0f12SGeorge Liu BMCWEB_ROUTE( 29570fda0f12SGeorge Liu app, 29580fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/") 2959ed398213SEd Tanous .privileges(redfish::privileges::postLogService) 29607e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 29617e860f15SJohn Edward Broadbent [](const crow::Request&, 29627e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2963cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 2964cb92c03bSAndrew Geissler 2965cb92c03bSAndrew Geissler // Process response from Logging service. 29667e860f15SJohn Edward Broadbent auto respHandler = [asyncResp]( 29677e860f15SJohn Edward Broadbent const boost::system::error_code ec) { 29687e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 29697e860f15SJohn Edward Broadbent << "doClearLog resp_handler callback: Done"; 2970cb92c03bSAndrew Geissler if (ec) 2971cb92c03bSAndrew Geissler { 2972cb92c03bSAndrew Geissler // TODO Handle for specific error code 29737e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " 29747e860f15SJohn Edward Broadbent << ec; 2975cb92c03bSAndrew Geissler asyncResp->res.result( 2976cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 2977cb92c03bSAndrew Geissler return; 2978cb92c03bSAndrew Geissler } 2979cb92c03bSAndrew Geissler 29807e860f15SJohn Edward Broadbent asyncResp->res.result( 29817e860f15SJohn Edward Broadbent boost::beast::http::status::no_content); 2982cb92c03bSAndrew Geissler }; 2983cb92c03bSAndrew Geissler 2984cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 2985cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 29862c70f800SEd Tanous respHandler, "xyz.openbmc_project.Logging", 2987cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 2988cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 29897e860f15SJohn Edward Broadbent }); 2990cb92c03bSAndrew Geissler } 2991a3316fc6SZhikuiRen 2992a3316fc6SZhikuiRen /**************************************************** 2993a3316fc6SZhikuiRen * Redfish PostCode interfaces 2994a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 2995a3316fc6SZhikuiRen ******************************************************/ 29967e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesLogService(App& app) 2997a3316fc6SZhikuiRen { 29987e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 2999ed398213SEd Tanous .privileges(redfish::privileges::getLogService) 30000fda0f12SGeorge Liu .methods( 30010fda0f12SGeorge Liu boost::beast::http::verb:: 30020fda0f12SGeorge Liu get)([](const crow::Request&, 30037e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3004a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 30057e860f15SJohn Edward Broadbent {"@odata.id", 30067e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes"}, 3007a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 3008a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 3009a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 3010a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 3011a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 3012a3316fc6SZhikuiRen {"Entries", 30130fda0f12SGeorge Liu {{"@odata.id", 30140fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}}; 30157c8c4058STejas Patil 30167c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 30177c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 30180fda0f12SGeorge Liu asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 30197c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 30207c8c4058STejas Patil redfishDateTimeOffset.second; 30217c8c4058STejas Patil 3022a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 30237e860f15SJohn Edward Broadbent {"target", 30240fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog"}}; 30257e860f15SJohn Edward Broadbent }); 3026a3316fc6SZhikuiRen } 3027a3316fc6SZhikuiRen 30287e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesClear(App& app) 3029a3316fc6SZhikuiRen { 30300fda0f12SGeorge Liu BMCWEB_ROUTE( 30310fda0f12SGeorge Liu app, 30320fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog/") 3033ed398213SEd Tanous // The following privilege is incorrect; It should be ConfigureManager 3034ed398213SEd Tanous //.privileges(redfish::privileges::postLogService) 3035432a890cSEd Tanous .privileges({{"ConfigureComponents"}}) 30367e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 30377e860f15SJohn Edward Broadbent [](const crow::Request&, 30387e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3039a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 3040a3316fc6SZhikuiRen 3041a3316fc6SZhikuiRen // Make call to post-code service to request clear all 3042a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3043a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 3044a3316fc6SZhikuiRen if (ec) 3045a3316fc6SZhikuiRen { 3046a3316fc6SZhikuiRen // TODO Handle for specific error code 3047a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 30487e860f15SJohn Edward Broadbent << "doClearPostCodes resp_handler got error " 30497e860f15SJohn Edward Broadbent << ec; 30507e860f15SJohn Edward Broadbent asyncResp->res.result(boost::beast::http::status:: 30517e860f15SJohn Edward Broadbent internal_server_error); 3052a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3053a3316fc6SZhikuiRen return; 3054a3316fc6SZhikuiRen } 3055a3316fc6SZhikuiRen }, 305615124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 305715124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3058a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 30597e860f15SJohn Edward Broadbent }); 3060a3316fc6SZhikuiRen } 3061a3316fc6SZhikuiRen 3062a3316fc6SZhikuiRen static void fillPostCodeEntry( 30638d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 30646c9a279eSManojkiran Eda const boost::container::flat_map< 30656c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode, 3066a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 3067a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 3068a3316fc6SZhikuiRen { 3069a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 3070a3316fc6SZhikuiRen const message_registries::Message* message = 30714a0bf539SManojkiran Eda message_registries::getMessage("OpenBMC.0.2.BIOSPOSTCode"); 3072a3316fc6SZhikuiRen 3073a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 3074a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 3075a3316fc6SZhikuiRen 3076a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 30776c9a279eSManojkiran Eda for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 30786c9a279eSManojkiran Eda code : postcode) 3079a3316fc6SZhikuiRen { 3080a3316fc6SZhikuiRen currentCodeIndex++; 3081a3316fc6SZhikuiRen std::string postcodeEntryID = 3082a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 3083a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 3084a3316fc6SZhikuiRen 3085a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 3086a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 3087a3316fc6SZhikuiRen 3088a3316fc6SZhikuiRen if (1 == currentCodeIndex) 3089a3316fc6SZhikuiRen { // already incremented 3090a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 3091a3316fc6SZhikuiRen } 3092a3316fc6SZhikuiRen else 3093a3316fc6SZhikuiRen { 3094a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 3095a3316fc6SZhikuiRen } 3096a3316fc6SZhikuiRen 3097a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 3098a3316fc6SZhikuiRen // not fall between top and skip 3099a3316fc6SZhikuiRen if ((codeIndex == 0) && 3100a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 3101a3316fc6SZhikuiRen { 3102a3316fc6SZhikuiRen continue; 3103a3316fc6SZhikuiRen } 3104a3316fc6SZhikuiRen 31054e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 3106a3316fc6SZhikuiRen // currentIndex 3107a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 3108a3316fc6SZhikuiRen { 3109a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 3110a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 3111a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 3112a3316fc6SZhikuiRen continue; 3113a3316fc6SZhikuiRen } 3114a3316fc6SZhikuiRen 3115a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 3116a3316fc6SZhikuiRen // index 3117a3316fc6SZhikuiRen 3118a3316fc6SZhikuiRen // Get the Created time from the timestamp 3119a3316fc6SZhikuiRen std::string entryTimeStr; 31201d8782e7SNan Zhou entryTimeStr = 31211d8782e7SNan Zhou crow::utility::getDateTimeUint(usecSinceEpoch / 1000 / 1000); 3122a3316fc6SZhikuiRen 3123a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 3124a3316fc6SZhikuiRen std::ostringstream hexCode; 3125a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 31266c9a279eSManojkiran Eda << std::get<0>(code.second); 3127a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 3128a3316fc6SZhikuiRen // Set Fixed -Point Notation 3129a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 3130a3316fc6SZhikuiRen // Set precision to 4 digits 3131a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 3132a3316fc6SZhikuiRen // Add double to stream 3133a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3134a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3135a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3136a3316fc6SZhikuiRen 3137a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3138a3316fc6SZhikuiRen std::string msg; 3139a3316fc6SZhikuiRen if (message != nullptr) 3140a3316fc6SZhikuiRen { 3141a3316fc6SZhikuiRen msg = message->message; 3142a3316fc6SZhikuiRen 3143a3316fc6SZhikuiRen // fill in this post code value 3144a3316fc6SZhikuiRen int i = 0; 3145a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3146a3316fc6SZhikuiRen { 3147a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3148a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3149a3316fc6SZhikuiRen if (argPos != std::string::npos) 3150a3316fc6SZhikuiRen { 3151a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3152a3316fc6SZhikuiRen } 3153a3316fc6SZhikuiRen } 3154a3316fc6SZhikuiRen } 3155a3316fc6SZhikuiRen 3156d4342a92STim Lee // Get Severity template from message registry 3157d4342a92STim Lee std::string severity; 3158d4342a92STim Lee if (message != nullptr) 3159d4342a92STim Lee { 3160d4342a92STim Lee severity = message->severity; 3161d4342a92STim Lee } 3162d4342a92STim Lee 3163a3316fc6SZhikuiRen // add to AsyncResp 3164a3316fc6SZhikuiRen logEntryArray.push_back({}); 3165a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 31660fda0f12SGeorge Liu bmcLogEntry = { 31670fda0f12SGeorge Liu {"@odata.type", "#LogEntry.v1_8_0.LogEntry"}, 31680fda0f12SGeorge Liu {"@odata.id", 31690fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3170a3316fc6SZhikuiRen postcodeEntryID}, 3171a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 3172a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 3173a3316fc6SZhikuiRen {"Message", std::move(msg)}, 31744a0bf539SManojkiran Eda {"MessageId", "OpenBMC.0.2.BIOSPOSTCode"}, 3175a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 3176a3316fc6SZhikuiRen {"EntryType", "Event"}, 3177a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 31789c620e21SAsmitha Karunanithi {"Created", entryTimeStr}}; 3179647b3cdcSGeorge Liu if (!std::get<std::vector<uint8_t>>(code.second).empty()) 3180647b3cdcSGeorge Liu { 3181647b3cdcSGeorge Liu bmcLogEntry["AdditionalDataURI"] = 3182647b3cdcSGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" + 3183647b3cdcSGeorge Liu postcodeEntryID + "/attachment"; 3184647b3cdcSGeorge Liu } 3185a3316fc6SZhikuiRen } 3186a3316fc6SZhikuiRen } 3187a3316fc6SZhikuiRen 31888d1b46d7Szhanghch05 static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3189a3316fc6SZhikuiRen const uint16_t bootIndex, 3190a3316fc6SZhikuiRen const uint64_t codeIndex) 3191a3316fc6SZhikuiRen { 3192a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 31936c9a279eSManojkiran Eda [aResp, bootIndex, 31946c9a279eSManojkiran Eda codeIndex](const boost::system::error_code ec, 31956c9a279eSManojkiran Eda const boost::container::flat_map< 31966c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 31976c9a279eSManojkiran Eda postcode) { 3198a3316fc6SZhikuiRen if (ec) 3199a3316fc6SZhikuiRen { 3200a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3201a3316fc6SZhikuiRen messages::internalError(aResp->res); 3202a3316fc6SZhikuiRen return; 3203a3316fc6SZhikuiRen } 3204a3316fc6SZhikuiRen 3205a3316fc6SZhikuiRen // skip the empty postcode boots 3206a3316fc6SZhikuiRen if (postcode.empty()) 3207a3316fc6SZhikuiRen { 3208a3316fc6SZhikuiRen return; 3209a3316fc6SZhikuiRen } 3210a3316fc6SZhikuiRen 3211a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3212a3316fc6SZhikuiRen 3213a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3214a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3215a3316fc6SZhikuiRen }, 321615124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 321715124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3218a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3219a3316fc6SZhikuiRen bootIndex); 3220a3316fc6SZhikuiRen } 3221a3316fc6SZhikuiRen 32228d1b46d7Szhanghch05 static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3223a3316fc6SZhikuiRen const uint16_t bootIndex, 3224a3316fc6SZhikuiRen const uint16_t bootCount, 3225a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 3226a3316fc6SZhikuiRen const uint64_t top) 3227a3316fc6SZhikuiRen { 3228a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3229a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3230a3316fc6SZhikuiRen top](const boost::system::error_code ec, 32316c9a279eSManojkiran Eda const boost::container::flat_map< 32326c9a279eSManojkiran Eda uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& 32336c9a279eSManojkiran Eda postcode) { 3234a3316fc6SZhikuiRen if (ec) 3235a3316fc6SZhikuiRen { 3236a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3237a3316fc6SZhikuiRen messages::internalError(aResp->res); 3238a3316fc6SZhikuiRen return; 3239a3316fc6SZhikuiRen } 3240a3316fc6SZhikuiRen 3241a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3242a3316fc6SZhikuiRen if (!postcode.empty()) 3243a3316fc6SZhikuiRen { 3244a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 3245a3316fc6SZhikuiRen 3246a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3247a3316fc6SZhikuiRen { 3248a3316fc6SZhikuiRen uint64_t thisBootSkip = 3249a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3250a3316fc6SZhikuiRen uint64_t thisBootTop = 3251a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3252a3316fc6SZhikuiRen 3253a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3254a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3255a3316fc6SZhikuiRen } 3256a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3257a3316fc6SZhikuiRen } 3258a3316fc6SZhikuiRen 3259a3316fc6SZhikuiRen // continue to previous bootIndex 3260a3316fc6SZhikuiRen if (bootIndex < bootCount) 3261a3316fc6SZhikuiRen { 3262a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3263a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3264a3316fc6SZhikuiRen } 3265a3316fc6SZhikuiRen else 3266a3316fc6SZhikuiRen { 3267a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 32680fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries?$skip=" + 3269a3316fc6SZhikuiRen std::to_string(skip + top); 3270a3316fc6SZhikuiRen } 3271a3316fc6SZhikuiRen }, 327215124765SJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 327315124765SJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 3274a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3275a3316fc6SZhikuiRen bootIndex); 3276a3316fc6SZhikuiRen } 3277a3316fc6SZhikuiRen 32788d1b46d7Szhanghch05 static void 32798d1b46d7Szhanghch05 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 3280a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3281a3316fc6SZhikuiRen { 3282a3316fc6SZhikuiRen uint64_t entryCount = 0; 32831e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint16_t>( 32841e1e598dSJonathan Doman *crow::connections::systemBus, 32851e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode0", 32861e1e598dSJonathan Doman "/xyz/openbmc_project/State/Boot/PostCode0", 32871e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount", 32881e1e598dSJonathan Doman [aResp, entryCount, skip, top](const boost::system::error_code ec, 32891e1e598dSJonathan Doman const uint16_t bootCount) { 3290a3316fc6SZhikuiRen if (ec) 3291a3316fc6SZhikuiRen { 3292a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3293a3316fc6SZhikuiRen messages::internalError(aResp->res); 3294a3316fc6SZhikuiRen return; 3295a3316fc6SZhikuiRen } 32961e1e598dSJonathan Doman getPostCodeForBoot(aResp, 1, bootCount, entryCount, skip, top); 32971e1e598dSJonathan Doman }); 3298a3316fc6SZhikuiRen } 3299a3316fc6SZhikuiRen 33007e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntryCollection(App& app) 3301a3316fc6SZhikuiRen { 33027e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 33037e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3304ed398213SEd Tanous .privileges(redfish::privileges::getLogEntryCollection) 33057e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 33067e860f15SJohn Edward Broadbent [](const crow::Request& req, 33077e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 3308a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3309a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3310a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3311a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3312a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3313a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3314a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3315a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3316a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3317a3316fc6SZhikuiRen 3318a3316fc6SZhikuiRen uint64_t skip = 0; 3319a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 33208d1b46d7Szhanghch05 if (!getSkipParam(asyncResp, req, skip)) 3321a3316fc6SZhikuiRen { 3322a3316fc6SZhikuiRen return; 3323a3316fc6SZhikuiRen } 33248d1b46d7Szhanghch05 if (!getTopParam(asyncResp, req, top)) 3325a3316fc6SZhikuiRen { 3326a3316fc6SZhikuiRen return; 3327a3316fc6SZhikuiRen } 3328a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 33297e860f15SJohn Edward Broadbent }); 3330a3316fc6SZhikuiRen } 3331a3316fc6SZhikuiRen 3332647b3cdcSGeorge Liu /** 3333647b3cdcSGeorge Liu * @brief Parse post code ID and get the current value and index value 3334647b3cdcSGeorge Liu * eg: postCodeID=B1-2, currentValue=1, index=2 3335647b3cdcSGeorge Liu * 3336647b3cdcSGeorge Liu * @param[in] postCodeID Post Code ID 3337647b3cdcSGeorge Liu * @param[out] currentValue Current value 3338647b3cdcSGeorge Liu * @param[out] index Index value 3339647b3cdcSGeorge Liu * 3340647b3cdcSGeorge Liu * @return bool true if the parsing is successful, false the parsing fails 3341647b3cdcSGeorge Liu */ 3342647b3cdcSGeorge Liu inline static bool parsePostCode(const std::string& postCodeID, 3343647b3cdcSGeorge Liu uint64_t& currentValue, uint16_t& index) 3344647b3cdcSGeorge Liu { 3345647b3cdcSGeorge Liu std::vector<std::string> split; 3346647b3cdcSGeorge Liu boost::algorithm::split(split, postCodeID, boost::is_any_of("-")); 3347647b3cdcSGeorge Liu if (split.size() != 2 || split[0].length() < 2 || split[0].front() != 'B') 3348647b3cdcSGeorge Liu { 3349647b3cdcSGeorge Liu return false; 3350647b3cdcSGeorge Liu } 3351647b3cdcSGeorge Liu 3352ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3353647b3cdcSGeorge Liu const char* start = split[0].data() + 1; 3354ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3355647b3cdcSGeorge Liu const char* end = split[0].data() + split[0].size(); 3356647b3cdcSGeorge Liu auto [ptrIndex, ecIndex] = std::from_chars(start, end, index); 3357647b3cdcSGeorge Liu 3358647b3cdcSGeorge Liu if (ptrIndex != end || ecIndex != std::errc()) 3359647b3cdcSGeorge Liu { 3360647b3cdcSGeorge Liu return false; 3361647b3cdcSGeorge Liu } 3362647b3cdcSGeorge Liu 3363647b3cdcSGeorge Liu start = split[1].data(); 3364ca45aa3cSEd Tanous 3365ca45aa3cSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 3366647b3cdcSGeorge Liu end = split[1].data() + split[1].size(); 3367647b3cdcSGeorge Liu auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue); 3368647b3cdcSGeorge Liu 3369dcf2ebc0SEd Tanous return ptrValue == end && ecValue != std::errc(); 3370647b3cdcSGeorge Liu } 3371647b3cdcSGeorge Liu 3372647b3cdcSGeorge Liu inline void requestRoutesPostCodesEntryAdditionalData(App& app) 3373647b3cdcSGeorge Liu { 33740fda0f12SGeorge Liu BMCWEB_ROUTE( 33750fda0f12SGeorge Liu app, 33760fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/attachment/") 3377647b3cdcSGeorge Liu .privileges(redfish::privileges::getLogEntry) 3378647b3cdcSGeorge Liu .methods(boost::beast::http::verb::get)( 3379647b3cdcSGeorge Liu [](const crow::Request& req, 3380647b3cdcSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3381647b3cdcSGeorge Liu const std::string& postCodeID) { 3382647b3cdcSGeorge Liu if (!http_helpers::isOctetAccepted( 3383647b3cdcSGeorge Liu req.getHeaderValue("Accept"))) 3384647b3cdcSGeorge Liu { 3385647b3cdcSGeorge Liu asyncResp->res.result( 3386647b3cdcSGeorge Liu boost::beast::http::status::bad_request); 3387647b3cdcSGeorge Liu return; 3388647b3cdcSGeorge Liu } 3389647b3cdcSGeorge Liu 3390647b3cdcSGeorge Liu uint64_t currentValue = 0; 3391647b3cdcSGeorge Liu uint16_t index = 0; 3392647b3cdcSGeorge Liu if (!parsePostCode(postCodeID, currentValue, index)) 3393647b3cdcSGeorge Liu { 3394647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, "LogEntry", 3395647b3cdcSGeorge Liu postCodeID); 3396647b3cdcSGeorge Liu return; 3397647b3cdcSGeorge Liu } 3398647b3cdcSGeorge Liu 3399647b3cdcSGeorge Liu crow::connections::systemBus->async_method_call( 3400647b3cdcSGeorge Liu [asyncResp, postCodeID, currentValue]( 3401647b3cdcSGeorge Liu const boost::system::error_code ec, 3402647b3cdcSGeorge Liu const std::vector<std::tuple< 3403647b3cdcSGeorge Liu uint64_t, std::vector<uint8_t>>>& postcodes) { 3404647b3cdcSGeorge Liu if (ec.value() == EBADR) 3405647b3cdcSGeorge Liu { 3406647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3407647b3cdcSGeorge Liu "LogEntry", postCodeID); 3408647b3cdcSGeorge Liu return; 3409647b3cdcSGeorge Liu } 3410647b3cdcSGeorge Liu if (ec) 3411647b3cdcSGeorge Liu { 3412647b3cdcSGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3413647b3cdcSGeorge Liu messages::internalError(asyncResp->res); 3414647b3cdcSGeorge Liu return; 3415647b3cdcSGeorge Liu } 3416647b3cdcSGeorge Liu 3417647b3cdcSGeorge Liu size_t value = static_cast<size_t>(currentValue) - 1; 3418647b3cdcSGeorge Liu if (value == std::string::npos || 3419647b3cdcSGeorge Liu postcodes.size() < currentValue) 3420647b3cdcSGeorge Liu { 3421647b3cdcSGeorge Liu BMCWEB_LOG_ERROR << "Wrong currentValue value"; 3422647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3423647b3cdcSGeorge Liu "LogEntry", postCodeID); 3424647b3cdcSGeorge Liu return; 3425647b3cdcSGeorge Liu } 3426647b3cdcSGeorge Liu 34279eb808c1SEd Tanous const auto& [tID, c] = postcodes[value]; 342846ff87baSEd Tanous if (c.empty()) 3429647b3cdcSGeorge Liu { 3430647b3cdcSGeorge Liu BMCWEB_LOG_INFO << "No found post code data"; 3431647b3cdcSGeorge Liu messages::resourceNotFound(asyncResp->res, 3432647b3cdcSGeorge Liu "LogEntry", postCodeID); 3433647b3cdcSGeorge Liu return; 3434647b3cdcSGeorge Liu } 343546ff87baSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) 343646ff87baSEd Tanous const char* d = reinterpret_cast<const char*>(c.data()); 343746ff87baSEd Tanous std::string_view strData(d, c.size()); 3438647b3cdcSGeorge Liu 3439647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Type", 3440647b3cdcSGeorge Liu "application/octet-stream"); 3441647b3cdcSGeorge Liu asyncResp->res.addHeader("Content-Transfer-Encoding", 3442647b3cdcSGeorge Liu "Base64"); 3443647b3cdcSGeorge Liu asyncResp->res.body() = 3444647b3cdcSGeorge Liu crow::utility::base64encode(strData); 3445647b3cdcSGeorge Liu }, 3446647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode0", 3447647b3cdcSGeorge Liu "/xyz/openbmc_project/State/Boot/PostCode0", 3448647b3cdcSGeorge Liu "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes", 3449647b3cdcSGeorge Liu index); 3450647b3cdcSGeorge Liu }); 3451647b3cdcSGeorge Liu } 3452647b3cdcSGeorge Liu 34537e860f15SJohn Edward Broadbent inline void requestRoutesPostCodesEntry(App& app) 3454a3316fc6SZhikuiRen { 34557e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 34567e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/") 3457ed398213SEd Tanous .privileges(redfish::privileges::getLogEntry) 34587e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 3459*ace85d60SEd Tanous [](const crow::Request& req, 34607e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 34617e860f15SJohn Edward Broadbent const std::string& targetID) { 3462647b3cdcSGeorge Liu uint16_t bootIndex = 0; 3463647b3cdcSGeorge Liu uint64_t codeIndex = 0; 3464647b3cdcSGeorge Liu if (!parsePostCode(targetID, codeIndex, bootIndex)) 3465a3316fc6SZhikuiRen { 3466a3316fc6SZhikuiRen // Requested ID was not found 3467*ace85d60SEd Tanous messages::resourceMissingAtURI(asyncResp->res, req.urlView); 3468a3316fc6SZhikuiRen return; 3469a3316fc6SZhikuiRen } 3470a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3471a3316fc6SZhikuiRen { 3472a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 34737e860f15SJohn Edward Broadbent << targetID; 3474a3316fc6SZhikuiRen } 3475a3316fc6SZhikuiRen 34767e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = 34777e860f15SJohn Edward Broadbent "#LogEntry.v1_4_0.LogEntry"; 3478a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 34790fda0f12SGeorge Liu "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3480a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3481a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3482a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3483a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3484a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3485a3316fc6SZhikuiRen 3486a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 34877e860f15SJohn Edward Broadbent }); 3488a3316fc6SZhikuiRen } 3489a3316fc6SZhikuiRen 34901da66f75SEd Tanous } // namespace redfish 3491